Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Mel_O_Die on Fri 10/11/2006 21:44:30

Title: hotspot name following mouse going off the screen
Post by: Mel_O_Die on Fri 10/11/2006 21:44:30
Hi!

I have made a gui with a label who displays the object/hotspot/character name when the mouse is over it, and that gui appears at the mouse coordinates

that works fine, but my problem is that the GUI position is exactly my mouse.x and mouse.y and when the mouse is at the bottom of the screen or at the right, some part of the text is out of screen.

how can i do to have the text not going off the screen?

the only solution i found is to make 2 Gui, one with label text aligned on left, and the other aligned on right and switch between them at certain mouse coordinates. but this isn't smooth and natural, there is a more easy way to do that?

thanks!

(i hope you understand what i mean :d:d)
Title: Re: hotspot name following mouse going off the screen
Post by: Rui 'Trovatore' Pires on Fri 10/11/2006 21:46:28
No need. Make a check in rep_execute, and whenever the GUI's X pos is, say, higher than mouse.x+GUI.width, make it so that the GUI's X position locks as being mouse.x+GUI.width. Ditto for Y coordinates.
Title: Re: hotspot name following mouse going off the screen
Post by: Ashen on Fri 10/11/2006 21:57:57
Quote
mouse.x+GUI.width

Shouldn't that be "Screen Width - GUI Width"? Something like:

if (mouse.x < (System.ViewportWidth - gGuiname.Width)) gGuiname.Y = mouse.x;
else gGuiname.X = (System.ViewportWidth - gGuiname.Width);

if (mouse.y < (System.ViewportHeight - gGuiname.Height)) gGuiname.Y = mouse.y;
else gGuiname.Y = (System.ViewportHeight - gGuiname.Height);
Title: Re: hotspot name following mouse going off the screen
Post by: Rui 'Trovatore' Pires on Fri 10/11/2006 22:00:57
Doh. Accourse it should. Thanks for pointing it out. :) You know how it is, you take things for granted in your head and your fingers don't get the message at time of typing. 's why I have to debug so many, many, many, many, many, many, many, many, many, many, many, many, many, many, many, many, many, many, many, many time.
Title: Re: hotspot name following mouse going off the screen
Post by: Mel_O_Die on Sat 11/11/2006 12:54:53
i tryed that and it doesn't do what i want it to :d

sorry for my explaination, but my english is not much good and i try to do my best :)

my problem is very hard to explain, so i made a little screenshot to show you where is the problem

(http://emma.roide.free.fr/emmaproblem.jpg)
(1) is the fully showed label, with the name of the object, the GUI & label are 100 width to allow long names (bed is only 3 characters, and television are 10 and some others will be more long)
i think i can't made a gui and label who fit automatically the name even the number of characters it contains

(2) the name "television" is at the border right of the screen, we can read it easy, but the mouse are far from the border

(3) the mouse is close to the border and we can now read only the 3 first letters of "TELevision"

the thing i want to do is to lock the gui & label at the right (like it's position in (2)) and let the mouse goes to the right

if i use gui.width, it's 100 so if i change "television" name to "tv" the "tv" will be locked at 100pix from the border right, whereas I would like to have the "V" (from "TV") locked on the border (like the "n" in "television" in case (2) )

i hope you will see what i mean :d

thanks!

(that's why i originally not post this message in beginner's topicÃ,  :-\)
Title: Re: hotspot name following mouse going off the screen
Post by: Rui 'Trovatore' Pires on Sat 11/11/2006 12:58:02
In that case, you can, IN ADDITION to the code used above, resize your GUI every time the label gets written on. Meaning, every time you output something to the label, multiply the text's number of characters by, say, 5 (fiddle with this number a bit) and resize the GUI's width to that.
Title: Re: hotspot name following mouse going off the screen
Post by: Mel_O_Die on Sat 11/11/2006 13:03:28
thanks!

but how can i "get" the numbers of characters on the label ?
Title: Re: hotspot name following mouse going off the screen
Post by: Ashen on Sat 11/11/2006 13:08:34
Yes, right, sorry...
I understood your problem perfectly, it wasn't your English it was my brain not quite working properly. The code I gave is pretty much directly copied (and updated for 2.72) from code I've used before - BUT I had something in repeatedly_execute that changed the GUI width to match the label (like Rui suggested), so it worked fine.
Since you DON'T have that, you'll probably need to check against the String width instead:

Screen.ViewportWidth - GetTextWidth(lblWhatever.Text, lblWhatever.Font)

(Or you can use GetTextWidth to change the GUI width, of course.)

And it's still pretty much a Beginners Tech question, becasue you could've found the necessary commands by reading the manual.

(Was typing when you posted, but posted anyway...)
Title: Re: hotspot name following mouse going off the screen
Post by: Rui 'Trovatore' Pires on Sat 11/11/2006 13:10:37
Ashen makes my suggestion obsolete by making a better one, but for future reference:

QuoteLength property
(Formerly known as global function StrLen, which is now obsolete)

readonly int String.Length;

Returns the length of the string, in characters.
Example:

String text = "This is my string.";
Display("Length: %d", text.Length);

will display "Length: 18".
Title: Re: hotspot name following mouse going off the screen
Post by: Mel_O_Die on Mon 13/11/2006 22:08:16
thanks so much! it works fine!

i have again an other little problem  ;D

when the mouse is over an hotspot and the name is displayed, for example if we use a look at action, the character will say something, but the label is still visible, and sometimes over the text (depends of the position of the character) so the text can't be read fully because of the name

exemple: it's the door of my room

become: it's the dDOORf my room

you see what i mean ?

and the other if when i change room, the last text in label is still active in the former position of the mouse (example for a "corridor" exit, the name "corridor" is still dispayed shorty when we are in the corridor)

how can i do to set automatically remove this text when text is displayed and when i exit a room ?
Title: Re: hotspot name following mouse going off the screen
Post by: Khris on Mon 13/11/2006 22:21:06
Add this to the label part of the rep_ex:
  if (player.Speaking) gGuiname.Visible=false;
  else gGuiname.Visible=true;


and this to the global script:
on_event (EventType event, int data) {
  if (event==eEventEnterRoomBeforeFadein) {
    gGuiname.Visible=false;
  }
}


Untested, just try if it works. Might need some refining.
Title: Re: hotspot name following mouse going off the screen
Post by: Ashen on Mon 13/11/2006 22:45:39
Quote from: KhrisMUC
Add this to the label part of the rep_ex:

I think it'd need to be rep_ex_always, wouldn't it? Since speech is blocking, the normal rep_ex won't run and nothing will happen.
Title: Re: hotspot name following mouse going off the screen
Post by: Mel_O_Die on Mon 13/11/2006 23:37:48
awww so dumb i am  ::) ::)

it was evident! sorry for these last questions  ::)

it works fine now! thanks very much that's cool!


(hope you will enjoy my game/demo! i working hard on it to release it the soonest i can!)
Title: Re: hotspot name following mouse going off the screen
Post by: Khris on Tue 14/11/2006 10:01:46
Ashen: True, thanks.

Mel: Glad it worked :)