Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: markbilly on Tue 04/05/2010 20:37:35

Title: Mouse-over hotspot label in text-window gui.
Post by: markbilly on Tue 04/05/2010 20:37:35
Mouse-over hotspot label in text-window gui. How would I do this?

Basically, at the moment I have a label that appears at the bottom, in the middle of the screen when a hotspot/object is moused-over. Standard fare. How do I do this so that the label text has a border i.e. is using a text-window GUI?

The solution is probably really simple but my simple code-brain can't handle it... :P
Title: Re: Mouse-over hotspot label in text-window gui.
Post by: Khris on Tue 04/05/2010 23:54:05
I assume that only the GUI's width is going to change, so you can achieve this using only four buttons.
Use two for the left and right sides (including the respective top and bottom corners).
Then use another two for the top and bottom sides. Their images need to be quite wide, use the screen's width to be on the safe side. Then set their .ClipImage properties to "true".

I'll also assume you're currently using "@OVERHOTSPOT@"?
A replacement is necessary to determine the width of the label's text:
  String a = GetLocationName(mouse.x, mouse.y);
  int l;
  if (String.IsNullOrEmpty(a)) gHotspotgui.Visible = false;
  else {
    l = GetTextWidth(a, lblHotspot.Font);
    gHotspotgui.Width = l + 20;   // change this depending on the width of the side borders
    gHotspotgui.X = (System.ViewportWidth - gHotspotgui.Width)/2;  // center GUI
    lblHotspot.Text = a;
    lblHotspot.Width = l+2;  // compensate for outline
    bHotspotTop.Width = l;
    bHotspotBottom.Width = l;
    bHotspotRight.X = gHotspotgui.Width - 10;
    gHotspotgui.Visible = true;
  }


All this should be pretty self-explanatory.

If you plan to use some intricate pattern, you're probably gonna use tiles for the top and bottom borders. In this case you can make sure that the button's width is a multiple of e.g. 8 using
  l = (l/8+1)*8;
immediately after GetTextWidth.
Title: Re: Mouse-over hotspot label in text-window gui.
Post by: markbilly on Wed 05/05/2010 15:42:47
I think I've got all that - I've created all the buttons. Where does the lump of code go, though?

And what do I replace @OVERHOTSPOT@ with?

EDIT: No worries. I worked it out. Thanks for the help, Kris.
Title: Re: Mouse-over hotspot label in text-window gui.
Post by: markbilly on Sun 16/05/2010 01:28:29
Sorry to dig this up but it's better than starting a new thread, right?

I have one problem with: when you click on the object/hotspot, the GUI stays on the screen (when the player talks, for example). Obviously I want it to disappear. I've done IsPauseGamed and set the visibility but that doesn't seem to help. Ideas?

Thanks.
Title: Re: Mouse-over hotspot label in text-window gui.
Post by: Ryan Timothy B on Sun 16/05/2010 01:31:39
One solution I know of is, in the Rep Ex Always, do this:


if (IsInterfaceEnabled()) theGui.visible=true;
 else theGUI.visible=false;


or just simply


  theGui.visible=(IsInterfaceEnabled());  //if it's true, it'll set it as true, or if it's false it will set to false.
Title: Re: Mouse-over hotspot label in text-window gui.
Post by: markbilly on Sun 16/05/2010 09:35:11
No luck with that, plus it makes the mouse disappear all the time the label isn't visible. I tried it with just:

  if (IsInterfaceEnabled() == 0) {
      gMouselabel.Visible = false;
  }


But still no cigar. :S
Title: Re: Mouse-over hotspot label in text-window gui.
Post by: tzachs on Sun 16/05/2010 12:19:05
Try combining Ryan's code with Khris's code.
In Khris's code, replace the following line:

if (String.IsNullOrEmpty(a)) gHotspotgui.Visible = false;


With:

if (String.IsNullOrEmpty(a) || !IsInterfaceEnabled()) gHotspotgui.Visible = false;
Title: Re: Mouse-over hotspot label in text-window gui.
Post by: markbilly on Sun 16/05/2010 15:19:12
I got this working in the end. Dunno why it didn't at first... :S
Title: Re: Mouse-over hotspot label in text-window gui.
Post by: Calin Leafshade on Mon 17/05/2010 08:30:55
Even though this is solved, this is something I always have in my code.



function repeatedly_excute_always(){
blocking = true;
}

function repeatedly_execute(){
blocking = false;
}


since rep ex always is run first this gives me an easy way to know if the script is currently being blocked or not (I generally use it for the hotspot gui fade in things like hope and EU but it has other uses.)
Title: Re: Mouse-over hotspot label in text-window gui.
Post by: Ryan Timothy B on Mon 17/05/2010 17:56:18
Yeah, that's what I used to do Calin until I discovered IsInterfaceEnabled(), which I believe does the exact same thing without the need of a boolean.