Problem with GUI [solved]

Started by HaReL, Mon 13/08/2007 16:38:20

Previous topic - Next topic

HaReL

I'm using the Alarcost template (AGS left and right..), but i notice that the problem is happening in the defaults tamplate.
(link to the Alarcost tamplate:
http://www.lumpcity.co.uk/~skimbleshanks/templates/Alarcost.zip )

So, what i'm trying to do, is to move the ICONBAR from the top of the screen, to the bottom.
This wasn't the problem, I just changed the Y-Position. But then I want change the popup YPos, so the positon will match to the position of the ICONBAR.
If I change the value of the YPos to 173 (for example), then he think that I mean to 0-173, and the ICONBAR is always show up (because 0-173 is the whole screen).

My question is:
How do I do that the YPos will be from the bottom?

Thank's a lot.

p.s.,
If there are some good tutorial for GUI, I'll be glad to know them. ;)

monkey0506

#1
I think you would have to script that yourself...

Code: ags
// repeatedly_execute
gIconbar.Visible = (mouse.y >= 173);


That would simply turn the ICONBAR GUI on/off depending on whether the mouse is at y-pos 173 or greater. If you want it to slide up from the bottom of the screen, you could try something like this:

Code: ags
// repeatedly_execute
if (mouse.y >= 173) {
  gIconbar.Visible = true;
  if (gIconbar.Y > 173) gIconbar.Y -= 1; // change 1 to a higher value to increase speed
  }
else if (gIconbar.Visible) {
  if (gIconbar.Y < (System.ViewportHeight - 1)) gIconbar.Y += 1; // change to a higher value to increase speed
  else gIconbar.Visible = false;
  }


[EDIT:]

Thanks Gilbot for correcting the slide-down code. And yes, as you mentioned, you'll want to set your GUI to Popup Modal or Normal mode, not YPos.

HaReL

Thank's, the first one is working well (I had to change it to Popup Modal). But the second, when you move the mouse to the bottom, the Iconbar appear (not sliding in), and when I took the mouse off - it slide down, and an Error appear : "GUI.Y : co-ordinates specified are out of range".

What is that mean?

Gilbert

Try changing the related line to:
Code: ags

  if (gIconbar.Y < System.ViewportHeight-1) gIconbar.Y += 1; // change to a higher 


I think the acceptable Y coordinates for a GUI cannot exceed ViewpoetHeight-1.

HaReL

Yes, thats work perfectly. And now its slide up either. :)
Thank you very much! ;)

monkey0506

Oops. My mistake. Thanks Gilbot. Glad to hear you got it working. 8)

HaReL

Now I have another Question...
Is it possible to give to the player to choose between:
1)The GUI will stay all the time
2)The GUI will hide and when the mouse is in the place (like the code you gave me), just then he will show up?


monkey0506

It would be possible to script this. First set up a button on your GUI with the image of an checked check-box with the text next to it "Auto-hide". Then you can script the change like this:

Code: ags
// global script
bool autohideGUI = true;

// btnCheckBox_Click, i.e., the button's "Click" function
if (autohideGUI) btnCheckBox.NormalGraphic = UNCHECKED_GRAPHIC;
else btnCheckBox.NormalGraphic = CHECKED_GRAPHIC;
autohideGUI = !autohideGUI; // this inverts the variable

// repeatedly_execute
if (autohideGUI) {
  // put the code from above
  }
else {
  gIconbar.Y = 173;
  gIconbar.Visible = true;
  }


btnCheckBox is the name of your button, and UNCHECKED_ and CHECKED_GRAPHIC correspond to the unchecked and checked sprite slots (respectively).

HaReL

thanks, but I didnt understand everything...
the first line - i put in the global script.
the line that begin with : "if (autohideGUI)...." I put in repeatedly_execute.

but where do I put this ? :
Quote from: monkey_05_06 on Thu 16/08/2007 04:31:24
Code: ags

// btnCheckBox_Click, i.e., the button's "Click" function
if (autohideGUI) btnCheckBox.NormalGraphic = UNCHECKED_GRAPHIC;
else btnCheckBox.NormalGraphic = CHECKED_GRAPHIC;
autohideGUI = !autohideGUI; // this inverts the variable

And second thing,
How do I call to the sprite that I import UNCHECKED_ & CHECKED_GRAPHIC ?

monkey0506

Sorry if I wasn't clear. I wasn't exactly sure off the top of my head of the exact procedure to create the button's click function, so now I'll check.

In the GUI editor select your button. Then in the GUI Properties pane, set the following: the button's "Script name" to "btnCheckBox", change "Left click" to "Run Script", and then finally set "Click" to "btnCheckBox_Click". Now if you double-click on your GUI button it will take you to the new function in the script. This is the function that gets called when you click on your GUI button.

What I meant was that you simply need to replace UNCHECKED_GRAPHIC and CHECKED_GRAPHIC with the sprite slot numbers. For example, if the unchecked graphic is sprite 22 and the checked graphic is sprite 23, then you would replace them with 22 and 23 respectively.

HaReL

Thanks,
It looks like it work fine, but when I press on the "btnCheckBox", not only the the GUI that I mean to control on him is show,  but the main GUI is showing either!

I've got 4 GUI.
1 - STATUSLINE (always on)
2 - ICONBAR - the main GUI
3 - INVENTORY - ...
4 - SLINVEN - another inventory. He is the on that slide from the bottom.

in the begining - the SLINVEN is the only one that show's up. When i press the btnCheckBox - the ICONBAR is showing up either - and even not in his place!
I've got in the game_start the line:   gIconbar.Centre();
and when I press the button for some reason it's show in the bottom of the screen!

Why is that happening!?

Thank's Again... ;)

Gilbert

Try not to put the GUI centering code in the game_start(). Try putting it in one of the "player enters room" script of the first room loaded instead.

In game_start() no room is loaded into memory yet, so the engine doesn't know the resolution of your game, centering the GUI at this time may just cause unexpected effect.

HaReL

No, it doesnt help...
before I added the script
Code: ags
// btnCheckBox_Click, i.e., the button's "Click" function
if (autohideGUI) btnCheckBox.NormalGraphic = UNCHECKED_GRAPHIC;
else btnCheckBox.NormalGraphic = CHECKED_GRAPHIC;
autohideGUI = !autohideGUI; // this inverts the variable

the "gIconbar.Centre(); "  was centerd it to the right place, and it still if I dont use the script above. But if I press the button that supposed to decide if it slide or not - the GUI suddenly appear in the bottom...

Gilbert

Can you post your part of codes about the autohide part?

My thought was that you probably just copied monkey's codes directly without changing them to suit your own need, as seen in his codes:
Code: ags

else {
  gIconbar.Y = 173;
  gIconbar.Visible = true;
  }

that operates on the ICONBAR gui, which according to you, IS the main GUI.
If the gui you want to have this effect is not that gui you have to modify it yourself, like SLINVEN that you're referring to, so you need to change gIconbar to something like gSlinven.

HaReL

right, thanks...  ;)
I missed that line... :P
In the first line's - I changed it, but here I forget.

Thanks again. :)

monkey0506

I was just basing the code on the information given. Glad to hear you got it sorted (and thanks to Gilbot catching the cause).

monkey

SMF spam blocked by CleanTalk