Arrow key operation of a GUI: Sloved

Started by Scarab, Sat 03/10/2009 10:38:50

Previous topic - Next topic

Scarab

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

monkey0506

#1
By default the on_key_press function has this line:

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

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

Scarab

Code: ags

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

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

discordance

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?

NsMn

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!

Scarab

New Code:
Code: ags

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

Problem[2].soved = True

Scarab

SMF spam blocked by CleanTalk