@Overhotspot@ Following Cursor [SOLVED]

Started by KodiakBehr, Sun 09/10/2011 15:04:54

Previous topic - Next topic

KodiakBehr

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"?

Khris

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

Code: ags
  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.

Icey

Damn, khris beat me. However I would like to know would this work to?
Code: ags
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;
  
}


}



KodiakBehr

Thanks, but won't that crash the game when objects/hotspots are on the edges of the screen?

Calin Leafshade

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

Hernald

#5
This is the code I'm using in repeatedly_execute:


Code: ags

// 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
Code: ags

  if (cEgo.HasInventory(iFlashlightOff)) {
    gHotSpot.Visible = false;
  }

Khris

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:

Code: ags
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;
  }
}

KodiakBehr

Hernald's solution appears to work well.  Thanks to you all.

Calin Leafshade

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.

Code: ags

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)
};

KodiakBehr



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.

steptoe

Nice Module Calin... very useful.. :=

cheers

steptoe

It's not over until the fat lady sings..

Calin Leafshade

oh, remove line 84

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

thats just for my testing.

KodiakBehr

Is there a way to change the ZOrder of an overlay?  The floating text ends up hiding behind my inventory screens.

Khris

GUIs are always on top of overlays.

Calin Leafshade

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.

monkey0506

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? :)

Calin Leafshade


KodiakBehr

#17
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.

Calin Leafshade

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.

KodiakBehr


SMF spam blocked by CleanTalk