Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: KodiakBehr on Sun 09/10/2011 15:04:54

Title: @Overhotspot@ Following Cursor [SOLVED]
Post by: KodiakBehr on Sun 09/10/2011 15:04:54
It's a common thing in AGS games, but it's kicking my a** right now.

Game will be a two-button, one-click interface.  I just want the @OVERHOTSPOT@ label to be present over the object/hotspot, rather than a fixed location.

A lot of topics on this, but consensus appears to be to use SSH's Description v1.06 Module.

http://www.adventuregamestudio.co.uk/yabb/index.php?topic=41265.0

I was hoping it would be beginner-friendly, but I'm getting nowhere with it.  I'm not sure if it's because I'm thick or the module is complex, but after staring at the code for a couple hours, I still have no idea how it works or where to go from here to get it running.
 
Is there an easier way to accomplish the same goals?  Or is anyone familiar enough with this script that they could tell me how to "switch it on"?
Title: Re: @Overhotspot@ Following Cursor
Post by: Khris on Sun 09/10/2011 15:29:21
Creating a simple cursor text is easy enough;

put a label on a GUI, set its text to @OVERHOTSPOT@ and position it in repeatedly_execute.
Usually you'd start with

  int x = mouse.x + 3;
  int y = mouse.y - 9;
  gCursorText.SetPosition(x, y);


which puts the text next to the cursor, then put in a few checks so the GUI isn't displayed partly off-screen.
Title: Re: @Overhotspot@ Following Cursor
Post by: Icey on Sun 09/10/2011 15:35:52
Damn, khris beat me. However I would like to know would this work to?
function room_RepExec()
{
if(mouse.x == #){
 if(mouse.y == #){
   int mouseX
   int mouseY
goverhotspot.visible = true;
 goverhotspot.X = mouseX;
 goverhotspot.Y = mouseY;
 }
}
else if(goverhotspot.visible == true){
 goverhotspot.visible = false;
 
}


}


Title: Re: @Overhotspot@ Following Cursor
Post by: KodiakBehr on Sun 09/10/2011 15:57:42
Thanks, but won't that crash the game when objects/hotspots are on the edges of the screen?
Title: Re: @Overhotspot@ Following Cursor
Post by: Calin Leafshade on Sun 09/10/2011 18:17:14
Well it wont crash the game since mouse.x and mouse.y can never go beyond the screen bounds. so the gui would always be on screen.

However, Khris' solution is not ideal since the text would be mostly off the screen if a hotspot were toward the edge of the screen.

Really you should clamp the guis postition as screenWidth - textWidth (ditto for height) so that the text is always fully on the screen.

I'll post some code once i get to work if no one beats me to it in the next few hours
Title: Re: @Overhotspot@ Following Cursor
Post by: Hernald on Sun 09/10/2011 18:58:16
This is the code I'm using in repeatedly_execute:



// Floating hotspot name
 vhx = mouse.x+15;
 vhy = mouse.y+15;
 if (Mouse.Mode == eModeUseinv) {
   vhx = mouse.x+30;
   vhy = mouse.y+30;
 }
 GUI*gh = gHotSpot;
 if (vhx > 640 - gh.Width) vhx = 640-gh.Width;
 if (vhy > 480 - gh.Height) vhy = 480-gh.Height;
 gh.SetPosition(vhx, vhy);


To switch the text off I use

  if (cEgo.HasInventory(iFlashlightOff)) {
    gHotSpot.Visible = false;
  }
Title: Re: @Overhotspot@ Following Cursor
Post by: Khris on Sun 09/10/2011 19:17:18
Quote from: Studio3 on Sun 09/10/2011 15:35:52
Damn, khris beat me. However I would like to know would this work to?

No.

Trying to 'fix' this:

function room_RepExec()
{
  if(mouse.x == #){  // ???
    if(mouse.y == #){
      int mouseX;   // why the extra variables?
      int mouseY;
      goverhotspot.visible = true;  // first setting the position, then turning it on is better in general
      goverhotspot.X = mouseX;  //   mouseX is 0, so is mouseY
      goverhotspot.Y = mouseY;
    }
  }
  else if(goverhotspot.visible == true){
    goverhotspot.visible = false;
  }
}
Title: Re: @Overhotspot@ Following Cursor
Post by: KodiakBehr on Sun 09/10/2011 19:43:51
Hernald's solution appears to work well.  Thanks to you all.
Title: Re: @Overhotspot@ Following Cursor
Post by: Calin Leafshade on Sun 09/10/2011 22:21:56
I made a module for it:

http://www.mediafire.com/?rlpz2dza9vd7slq

Includes fancy slide in animation and 'springy' motion to stop the label bouncing around all over the place when the mouse is moved a little. (both disableable)

Use the FloatingHotspot object to change stuff, although it works out of the box with no configuration.


managed struct FloatingHotspot
{
  import static void SetMaxWidth(int width); //Max width for the label (default System.ViewportWidth)
  import static void SetFont(FontType font); //set the font of the label (default font0)
  import static void SetColor(int color); // set the colour of the label (default Black)
  import static void SetSlideIn(bool on); // Set the slide in anitmation (default on)
  import static void SetSpring(bool on); // ditto spring effect (default on)
  import static void SetVerticalOffset(int offset); // vertical offset from the mouse (default -5)
};
Title: Re: @Overhotspot@ Following Cursor
Post by: KodiakBehr on Sun 09/10/2011 23:57:39
(http://i510.photobucket.com/albums/s347/KodiakHPS/contact.jpg)

Thank you Calin.  This is extraordinarily useful.

Suggest you add this to the Modules section of the forums.  Finding anything that still works there is a crap-shoot and I'm sure a lot of new members will benefit from how straightforward this is.
Title: Re: @Overhotspot@ Following Cursor
Post by: steptoe on Mon 10/10/2011 03:13:57
Nice Module Calin... very useful.. :=

cheers

steptoe

Title: Re: @Overhotspot@ Following Cursor
Post by: Calin Leafshade on Mon 10/10/2011 05:10:12
oh, remove line 84

Label1.Text = String.Format("movetimer: %f", moveTimer);

thats just for my testing.
Title: Re: @Overhotspot@ Following Cursor
Post by: KodiakBehr on Mon 10/10/2011 14:36:31
Is there a way to change the ZOrder of an overlay?  The floating text ends up hiding behind my inventory screens.
Title: Re: @Overhotspot@ Following Cursor
Post by: Khris on Mon 10/10/2011 14:54:41
GUIs are always on top of overlays.
Title: Re: @Overhotspot@ Following Cursor
Post by: Calin Leafshade on Mon 10/10/2011 19:45:42
Its easy enough to alter the module to work with guis instead of overlays.

I used overlays because they work out of the box, in code.

I didnt think about inventory items.
Title: Re: @Overhotspot@ Following Cursor
Post by: monkey0506 on Mon 10/10/2011 21:15:19
Calin why is that struct write-only?? If I can write to something shouldn't I be able to read it back? Also those functions are so old school. Why not be a cool kid like me and use properties with accessors? :)
Title: Re: @Overhotspot@ Following Cursor
Post by: Calin Leafshade on Mon 10/10/2011 21:18:52
Answer:

Couldn't be arsed.
Title: Re: @Overhotspot@ Following Cursor
Post by: KodiakBehr on Sun 16/10/2011 02:15:11
Quote from: Calin Leafshade on Mon 10/10/2011 19:45:42
Its easy enough to alter the module to work with guis instead of overlays.

Could you point me in the right direction on how to pull this off?

Otherwise, what I might do is disable the code altogether when the inventory box is open.  That could work, after all, the objects in my game world are pretty self-evident, and may not need further explanation.
Title: Re: @Overhotspot@ Following Cursor [SOLVED]
Post by: Calin Leafshade on Sun 16/10/2011 12:45:14
Here you go:

http://www.mediafire.com/?q069g8hzpwp1pv6

now call

FloatingHotspot.UseGui(gGui1);

where gGui1 is the name of a gui.

The module will handle all the positions and sizing stuff but you'll need to make the background color and the border color equal to 0 in the editor.
Title: Re: @Overhotspot@ Following Cursor [SOLVED]
Post by: KodiakBehr on Sun 16/10/2011 16:33:23
Thanks again.