hotspot name following mouse going off the screen

Started by Mel_O_Die, Fri 10/11/2006 21:44:30

Previous topic - Next topic

Mel_O_Die

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)
----( )----
Click to see "In Production" Topic!
[/color][/b][/url]

Rui 'Trovatore' Pires

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.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Ashen

Quote
mouse.x+GUI.width

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

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);
I know what you're thinking ... Don't think that.

Rui 'Trovatore' Pires

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.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Mel_O_Die

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


(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Ã,  :-\)
----( )----
Click to see "In Production" Topic!
[/color][/b][/url]

Rui 'Trovatore' Pires

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.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Mel_O_Die

thanks!

but how can i "get" the numbers of characters on the label ?
----( )----
Click to see "In Production" Topic!
[/color][/b][/url]

Ashen

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

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...)
I know what you're thinking ... Don't think that.

Rui 'Trovatore' Pires

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".
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Mel_O_Die

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 ?
----( )----
Click to see "In Production" Topic!
[/color][/b][/url]

Khris

Add this to the label part of the rep_ex:
Code: ags
  if (player.Speaking) gGuiname.Visible=false;
  else gGuiname.Visible=true;


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


Untested, just try if it works. Might need some refining.

Ashen

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.
I know what you're thinking ... Don't think that.

Mel_O_Die

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!)
----( )----
Click to see "In Production" Topic!
[/color][/b][/url]

Khris


SMF spam blocked by CleanTalk