Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Scarab on Sat 03/10/2009 10:38:50

Title: Arrow key operation of a GUI: Sloved
Post by: Scarab on Sat 03/10/2009 10:38:50
Hello.
In the game I'm making atm, I'm trying to completely eliminate use of the mouse, and this is going quite well with the character movement, but I'm having trouble with the GUIs.

The plan is: to  create a menu which opens with the enter key, pausing the game, and has the options of Save, Load, Inventory, etc. of which each can be highlighted, one at a time, using the up/down arrow keys, activated with the "z" key.

Currently I have a menu with 8 options which opens on 'Enter', and an int that is flows one through eight as the up/down keys are pressed. When 'Z' is pressed, the gui corresponding to the int is opened.
The 8 options are simply painted on to the GUI graphic currently.

The main things I'm struggling with at the moment are:
    1. Getting the game to pause when the GUIs are up (whenever I run PauseGame(), the arrow keys don't work)
    2. Finding some way to indicate which option is highlighted at the moment, such as a little arrow next to the option.

Any help/suggestions are appreciated
Peace 8)
Scarab
Title: Re: Arrow key operation of a GUI
Post by: monkey0506 on Sat 03/10/2009 13:57:17
By default the on_key_press function has this line:

if (IsGamePaused() == 1) keycode=0;  // game paused, so don't react to keypresses

Either remove that line completely (which would then interpret all keypresses even when the game is paused, or just make sure that the checks for the arrow keys are above that line inside the function. ;)

So, for example:

function on_key_press(eKeyCode keycode) {
  if (keycode == eKeyUpArrow) {
    // do this
  }
  else if (keycode == eKeyDownArrow) {
    // do that
  }
  else if (IsGamePaused() == 1) keycode = 0; // game is paused, ignore other key presses
  // BLAH
}
Title: Re: Arrow key operation of a GUI
Post by: Scarab on Sun 04/10/2009 04:43:38

Problem [1].solved = True;

Thanks Monkey ;D

As for problem 2, I have created a workaround, locking and bounding (binding?) the mouse to the necessary co-ordinates for a given value of 'activebutton[0]' (I have had to make this an array, as I need a different one for each GUI)

function repeatedly_execute() {
if ((gStartMenu.Visible == true) && (mouse.Mode != eModePointer))
  {mouse.Mode = eModePointer;}
     if (activebutton[0] == 1) {mouse.SetPosition(263,024); mouse.SetBounds(263, 024, 263, 24);}
else if (activebutton[0] == 2) {mouse.SetPosition(263,040); mouse.SetBounds(263, 040, 263, 40);}
else if (activebutton[0] == 3) {mouse.SetPosition(263,056); mouse.SetBounds(263, 056, 263, 56);}
else if (activebutton[0] == 4) {mouse.SetPosition(263,072); mouse.SetBounds(263, 072, 263, 72);}
else if (activebutton[0] == 5) {mouse.SetPosition(263,088); mouse.SetBounds(263, 088, 263, 88);}
else if (activebutton[0] == 6) {mouse.SetPosition(263,104); mouse.SetBounds(263, 104, 263,104);}
else if (activebutton[0] == 7) {mouse.SetPosition(263,120); mouse.SetBounds(263, 120, 263,120);}
else if (activebutton[0] == 8) {mouse.SetPosition(263,136); mouse.SetBounds(263, 136, 263,136);}
}


This works for now, but I was really hoping to be able to get a non mouse dependant interface.
I basically need a way to draw an my arrow of slot 355 onto a given screen co-ordinate. Is this possible with the DrawingSurface commands?
cheers
Scarab
Title: Re: Arrow key operation of a GUI
Post by: discordance on Sun 04/10/2009 08:25:32
Maybe I don't fully understand what you're doing here, but wouldn't it be easier to just use a GUI button for the highlighting arrow?
Title: Re: Arrow key operation of a GUI
Post by: NsMn on Sun 04/10/2009 08:56:33
He is. Since he sets the Bounds and the position of the mouse cursor to coordinates ON a certain button, it automatically gets highlighted. Clever!
Title: Re: Arrow key operation of a GUI
Post by: Scarab on Sun 04/10/2009 09:22:33
New Code:

Button1.Visible=false;
Button2.Visible=false;
Button3.Visible=false;
Button4.Visible=false;
Button5.Visible=false;
Button6.Visible=false;
Button7.Visible=false;
Button8.Visible=false;

     if (activebutton[0] == 1) {Button1.Visible=true;}
else if (activebutton[0] == 2) {Button2.Visible=true;}
else if (activebutton[0] == 3) {Button3.Visible=true;}
else if (activebutton[0] == 4) {Button4.Visible=true;}
else if (activebutton[0] == 5) {Button5.Visible=true;}
else if (activebutton[0] == 6) {Button6.Visible=true;}
else if (activebutton[0] == 7) {Button7.Visible=true;}
else if (activebutton[0] == 8) {Button8.Visible=true;}


I feel this is much cleaner, as although the other code 'worked', it locked up the mouse, causing small inconveniences, like not being able to close the window.
I had actually thought of using buttons first, but I was going about it the wrong way (Using invisible butons to process clicks, before I had the activebutton[] array)

Thanks for the hint Discordance, sometimes the simplest soluton is right under my nose :P

Problem[2].soved = True

Scarab