Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: on Thu 21/05/2015 08:47:35

Title: How to script Technobabylon's slide out GUI?
Post by: on Thu 21/05/2015 08:47:35
I can't figure out how to script the sliding inventory GUI like the one in Technobabylon, please help. I've searched this forum and there was no other thread explaining it.
Title: Re: How to script Technobabylon's slide out GUI?
Post by: LostTrainDude on Thu 21/05/2015 09:35:43
Sorry if this is a cheap answer :)

Just off the top of my head, I think that it may be using the great Tween Module (http://www.adventuregamestudio.co.uk/forums/index.php?topic=51820) which works fine also on GUIs, as far as I can remember and tell from the documentation (http://ags-tween.readthedocs.org/en/v2.0.0/scripting/generaltweens/). :D

I don't remember right now if the Inventory GUI it's just "sliding out" or "unraveling" like a carpet.

In the first case, this should be the reference code that should be implemented whenever you want it to happen:
Code (ags) Select
GUI.TweenPosition(float timing, int toX, int toY, optional TweenEasingType, optional TweenStyle, optional startDelay, optional timingType)

In the latter, I think that the GUI may have a "tiled background" so that it doesn't "break" when tweening is applied to increase its width.
Code (ags) Select
GUI.TweenSize(float timing, int toWidth, int toHeight, optional TweenEasingType, optional TweenStyle, optional startDelay, optional timingType)

The module lets you change sizes and position of every element in the GUI - Label, Button, TextBox, ListBox, Slider and InvWindow - so probably it's just a matter of prototyping until you get what you're looking for. Nothing that's necessarily hard to do.
Title: Re: How to script Technobabylon's slide out GUI?
Post by: Khris on Thu 21/05/2015 10:44:10
The basic idea is to track whether the mouse is over the GUI in repeatedly_execute. When the mouse moves on top of the GUI (which is only showing it's left edge at the bottom right corner), it's supposed to move over; when the mouse leaves the GUI, it's supposed to slide back.

GUI* wasUnderMouse;
int guiTargetX = 305;

void handleInvGUI() {
  GUI* isUnderMouse = GUI.GetAtScreenXY(mouse.x, mouse.y);

  if (wasUnderMouse == null && isUnderMouse == gInventory) {
    // mouse moved on top of it, slide in
    guiTargetX = 10;
  }
  else if (wasUnderMouse == gInventory && isUnderMouse == null) {
    // mouse moved off, slide out
    guiTargetX = 305;
  }

  // move GUI
  int dx = guiTargetX - gInventory.X;
  if (dx) {
    if (dx < -5 || dx > 5) dx = dx / 2;
    gInventory.X += dx;
  }
 
  wasUnderMouse = isUnderMouse; // track for next game loop
}

// add this to repeatedly_execute:
  handleInvGUI();
Title: Re: How to script Technobabylon's slide out GUI?
Post by: on Sat 27/06/2015 09:10:26
So I don't need to install any module or plugin? I can just type in the code for the GUI?
Title: Re: How to script Technobabylon's slide out GUI?
Post by: Khris on Sat 27/06/2015 13:46:09
No. Yes.
Title: Re: How to script Technobabylon's slide out GUI?
Post by: on Sat 27/06/2015 21:13:07
Thanks! I'll try it and come back if I need more help.