Mouse-over hotspot label in text-window gui.

Started by markbilly, Tue 04/05/2010 20:37:35

Previous topic - Next topic

markbilly

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
 

Khris

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:
Code: ags
  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
Code: ags
  l = (l/8+1)*8;

immediately after GetTextWidth.

markbilly

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

markbilly

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.
 

Ryan Timothy B

One solution I know of is, in the Rep Ex Always, do this:

Code: ags

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


or just simply

Code: ags

  theGui.visible=(IsInterfaceEnabled());  //if it's true, it'll set it as true, or if it's false it will set to false.

markbilly

No luck with that, plus it makes the mouse disappear all the time the label isn't visible. I tried it with just:

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


But still no cigar. :S
 

tzachs

Try combining Ryan's code with Khris's code.
In Khris's code, replace the following line:
Code: ags

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


With:
Code: ags

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

markbilly

I got this working in the end. Dunno why it didn't at first... :S
 

Calin Leafshade

Even though this is solved, this is something I always have in my code.

Code: ags


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.)

Ryan Timothy B

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.

SMF spam blocked by CleanTalk