Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Innsmouthian on Thu 07/02/2019 15:43:36

Title: Can't get "popup" GUI to work properly. Possible to hide only a part of it?
Post by: Innsmouthian on Thu 07/02/2019 15:43:36
Hello everybody!

First of all, I want to thank Chris Jones for creating and keeping AGS, such a wonderful invention. And secondly, thanks to this community for providing support and tips on projects.

I'd like to clarify that, although I've surfed this forum (also, of course, read the manual), I haven't found an answer to my question.

I'm using AGS 3.4.1

The thing is that I want to implement a show/hide "popup" GUI that contains both action buttons and the inventory (kind of a SCUMM-type). The GUI is intended to be placed in the bottom left corner. But I'm facing two problems:

- The first one is that I'm not able to even get the basic version of my purpose. Whenever I try to use the option "When mouse moves to top of screen", setting the "PopupYPos" in 1060 (the project resolution is 1920x1080), the only thing I get is a stuck GUI showing always and avoiding to interact with the rest of the game (the GUI itself works, however).

- The second problem, which I don't know if it's possible to resolve, is that I'd like to make the GUI hide in the bottom but not completely: 1/3 of it should be permanently visible, and once the mouse is over this area, the complete GUI would show up (pop up). I've found nothing in this regard in the manual nor in the forums.

This is a preview of the GUI -which is not yet definitive- showing the part that should keep visible on the bottom over the discontinued line.

(https://i.ibb.co/TR5Bf1n/gui.jpg) (https://ibb.co/TR5Bf1n)

Solvable or not, thanks in advance for any help or tip! :smiley:
Title: Re: Can't get "popup" GUI to work properly. Possible to hide only a part of it?
Post by: Snarky on Thu 07/02/2019 17:21:05
Computers count Y coordinate down from the top of the screen, so setting the threshold to 1060 means almost at the bottom of the screen. Try 20 instead
Title: Re: Can't get "popup" GUI to work properly. Possible to hide only a part of it?
Post by: Crimson Wizard on Thu 07/02/2019 17:43:31
Quote from: Innsmouthian on Thu 07/02/2019 15:43:36
The thing is that I want to implement a show/hide "popup" GUI that contains both action buttons and the inventory (kind of a SCUMM-type). The GUI is intended to be placed in the bottom left corner. But I'm facing two problems:

- The first one is that I'm not able to even get the basic version of my purpose. Whenever I try to use the option "When mouse moves to top of screen",

As name of the option hints, this only works reliably for GUI that are placed on top of the screen. This is a quick way to replicate classic Sierra interface.
For any other variant you'd need to script GUI behavior on your own.

For example, following is taken from one of the templates:
Link: https://github.com/adventuregamestudio/ags-template-source/blob/master/BASS/TwoClickHandler.asc#L148
Code (ags) Select

function repeatedly_execute()
{
  // Inventory GUI:
  if (interface_inv == null)
  {
    // pass
  }
  else if (interface_inv.Visible && mouse.y > interface_inv.Height)
  {
    interface_inv.Visible = false;
  }
  else if (!IsGamePaused() && !interface_inv.Visible && mouse.y <= INVENTORY_POPUP_POSITION)
  {
    // make visible when the game is not paused and the cursor is within the popup position
    interface_inv.Visible = true;
  }
}


You will have to adjust these conditions for your case. For further customization you may also check mouse.x coordinate along with mouse.y if you need that, or make GUI "slide" out of the screen border instead of popping up instantly.


Quote from: Snarky on Thu 07/02/2019 17:21:05
Computers count Y coordinate down from the top of the screen

I have to disagree, computers count as they are told to :). It's AGS in particular that counts Y coordinate down. Other engines may have Y axis upwards.
Title: Re: Can't get "popup" GUI to work properly. Possible to hide only a part of it?
Post by: Innsmouthian on Thu 07/02/2019 17:57:48
Thank you both for your answers!

I already had tried what Snarky proposes, but had no effect.

I'll start trying with your solution, Crimson Wizard. I'm a completely beginner with scripting as you may already have guessed but I assume it's the proper way to do things in AGS.

Title: Re: Can't get "popup" GUI to work properly. Possible to hide only a part of it?
Post by: Khris on Thu 07/02/2019 18:40:04
Put this at the top of GlobalScript.asc:

Code (ags) Select
bool mouseWasOverMainGUI = false;
float gY, targetY;

void handleGUI() {
  GUI* g = gMainGUI; // your gui's name here
  int y_full = 900;  // y coord when GUI is shown in full
  int y_down = 1020; // y coord when only top 1/3 of GUI is shown
  bool mouseIsOverMainGUI = GUI.GetAtScreenXY(mouse.x, mouse.y) == g;

  if (gY == 0.0) { gY = IntToFloat(g.Y); targetY = gY; }
  if (mouseIsOverMainGUI && !mouseWasOverMainGUI) {
    // mouse moved over GUI
    targetY = IntToFloat(y_full);
  }
  else if (!mouseIsOverMainGUI && mouseWasOverMainGUI) {
    // mouse moved away from GUI
    targetY = IntToFloat(y_down);
  }

  gY += (targetY - gY) * 0.4;
  g.Y = FloatToInt(gY, eRoundNearest);
  mouseWasOverMainGUI = mouseIsOverMainGUI;
}


Now find the function called repeatedly_execute and add handleGUI(); to it.

Edit: Code fixed.
Title: Re: Can't get "popup" GUI to work properly. Possible to hide only a part of it?
Post by: Innsmouthian on Thu 07/02/2019 19:35:00
Thanks a lot Khris!

I was having a bit of trouble implementing Crimson Wizard's script.

I used your code and now the GUI movement is there, with a nice fast-scrolling effect. But the Full GUI appears way upper in the screen, on the top left corner instead of the bottom left. When I move the mouse over it, it starts "bouncing" crazy between the bottom and its full position.

I guess I'm missing the way to tell the script the Y position of the full GUI, but, I'll do my best to understand the meaning of all the instructions so I can manage to put it back to its original position.  :grin:

In any case, the X position is correct.

EDIT: I've tried modyfing the values in y_full and y_down, but the only thing I get is a different "bouncing". Guess the problem has to be with the 'default' position of the GUI. Also tried changing the "Top" value in the GUI properties but no luck.

Cheers
Title: Re: Can't get "popup" GUI to work properly. Possible to hide only a part of it?
Post by: Snarky on Thu 07/02/2019 21:02:34
Quote from: Crimson Wizard on Thu 07/02/2019 17:43:31
Quote from: Snarky on Thu 07/02/2019 17:21:05
Computers count Y coordinate down from the top of the screen

I have to disagree, computers count as they are told to :). It's AGS in particular that counts Y coordinate down. Other engines may have Y axis upwards.

It's not worth arguing over, really, but although you can of course define your coordinate system however you like (on a computer or elsewhere), in a computer context the Y axis is by convention almost always oriented downwards, stemming from the way video memory is addressed (or at least, was addressed back in the day) on the hardware level, which in turn was arranged to match the way the electron beam used to scan CRT screens. It seems probable that the CRT scan pattern (top-down, left-to-right) was influenced by the Western writing order.
Title: Re: Can't get "popup" GUI to work properly. Possible to hide only a part of it?
Post by: Khris on Thu 07/02/2019 22:10:23
I was way too optimistic about that int code :P

It's fixed now.
Title: Re: Can't get "popup" GUI to work properly. Possible to hide only a part of it?
Post by: Innsmouthian on Thu 07/02/2019 22:34:31
Incredible! Now it works and looks really the way I was looking for it to do!.  8-0

I had to delete the last line due to a compiling error, but once done it started fine. What was it for, though?.

Thank you very much. I see it's kind of a complex code (at least for me), but I'll keep it like it was gold now.

Just to be touchy :-D, would there be a way to "activate" the full GUI only in case the mouse went to the left bottom of the screen, not just by getting over the GUI, but reaching the, like, 1060 line?. In my desing, that would allow the player to use the action buttons without displaying the inventory every time.

But maybe it's enough for today. Sincerely, thanks again.
Title: Re: Can't get "popup" GUI to work properly. Possible to hide only a part of it?
Post by: Khris on Fri 08/02/2019 05:17:21
Yeah, that last line was for debugging and I forgot to remove it :-D

You can easily change the condition that makes the GUI appear, just try this:

Code (ags) Select
  bool mouseIsOverMainGUI = GUI.GetAtScreenXY(mouse.x, mouse.y) == g && mouse.y > 1060;

Btw, the speed at which the GUI moves can be adjusted by changing the 0.4; smaller values make it move slower. Don't go above 1.0 though.
Title: Re: Can't get "popup" GUI to work properly. Possible to hide only a part of it?
Post by: Innsmouthian on Fri 08/02/2019 16:26:27
Quote from: Khris on Fri 08/02/2019 05:17:21
Yeah, that last line was for debugging and I forgot to remove it :-D

You can easily change the condition that makes the GUI appear, just try this:

Code (ags) Select
  bool mouseIsOverMainGUI = GUI.GetAtScreenXY(mouse.x, mouse.y) == g && mouse.y > 1060;

Btw, the speed at which the GUI moves can be adjusted by changing the 0.4; smaller values make it move slower. Don't go above 1.0 though.

I was trying yesterday to mess up a bit with that line (something told me the option was there), but hadn't been able to get anything. Now with this, the GUI does exactly what I was asking. I just hope to gradually learn how to work with the code...as your help is being huge.

Now the GUI is almost perfect. What I'd like to add (I'm already trying to get it :-[) is an order to specify that, while it is full deployed, it keeps opened as long as you're interacting with it. I don't know if I'm explaining myself well: while with the first code you provided, it already worked that way, it had the inconvenient that it scrolled up as soon as the mouse was over the GUI. Now it deploys only when you go down, but the problem is that as soon as you move the mouse over the 1060 line, it goes down again, preventing the player to interact with the inventory, which is in the hidden part of the GUI.

Or in short: Would there be a way to get the GUI shown only when the mouse is at the bottom, as it does now with your last contribution, BUT not to hide again unless the mouse goes, say, to the 650 line? (which is the line where the full GUI 'ends').

I don't want to sound irritating, as I appreciate what you've already gave me should be more-than-enough for a persistent beginner like me.

So, thank you again Khris!  :)
Title: Re: Can't get "popup" GUI to work properly. Possible to hide only a part of it?
Post by: Khris on Fri 08/02/2019 17:55:44
Replace the quotes line with this:

Code (ags) Select
  bool mouseIsOverMainGUI = GUI.GetAtScreenXY(mouse.x, mouse.y) == g && mouse.y > 1060;
  if (!mouseIsOverMainGUI && mouseWasOverMainGUI && mouse.y > 650) mouseIsOverMainGUI = true;


Not tested!

Also, no worries, I actually like finding elegant solutions to problems like this :)
Title: Re: Can't get "popup" GUI to work properly. Possible to hide only a part of it?
Post by: Innsmouthian on Fri 08/02/2019 19:06:41
Yep! That did the trick, now it's completely functional for the game's purposes.

I had to change the "mouse.x > 650" in the second line for "mouse.y" but it's working flawlessly. Now I feel like I can overtake the project; thanks a lot! ;-D

For the final brushstroke... would it be possible to start the game with the GUI down? :=
Title: Re: Can't get "popup" GUI to work properly. Possible to hide only a part of it?
Post by: Khris on Fri 08/02/2019 21:24:28
Right, I keep writing .x for some reason.

As for the initial position, I tried to set up my code in a way that it uses the position set in the GUI editor (line 10 in the snippet). Did you set the top property accordingly, or does that not suffice?
Title: Re: Can't get "popup" GUI to work properly. Possible to hide only a part of it?
Post by: Innsmouthian on Sat 09/02/2019 12:47:55
Quote from: Khris on Fri 08/02/2019 21:24:28
Right, I keep writing .x for some reason.

As for the initial position, I tried to set up my code in a way that it uses the position set in the GUI editor (line 10 in the snippet). Did you set the top property accordingly, or does that not suffice?

Yeah, I changed it in the Propierties tab of the GUI and now it starts down. This is awesome.  :cheesy: