Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: ThreeOhFour on Fri 30/10/2009 10:45:37

Title: Two GUI Questions [Solved]
Post by: ThreeOhFour on Fri 30/10/2009 10:45:37
I haven't really done much playing around with GUIs, and today I finally got around to building the GUI for a game and thus have 2 little non urgent questions:

1. I'm not quite sure how, but I want to make it so that when over the inventory with the mouse mode as eModeUseInv a right click deselects instead of looking. I've thought about maybe trying to tie the on_mouse_click function to the repeatedly_execute_always function but can't think of how and am sure this is not the correct manner to approach it in. Any thoughts?

2. I've put in a GUI.GetAtScreenXY function. Usually I'd write a GetAtScreenXY (ie, for a character) function like:


function repeatedly_execute_always()
{
 if (GUI.GetAtScreenXY != gInventory)
 {
   gInventory.Visible = false;
 }
}


But this doesn't seem to work with a gui, and I had to jump into the manual which suggested I do this:


function repeatedly_execute_always()
{
 GUI *theGui = GUI.GetAtScreenXY(mouse.x, mouse.y);
 {
 if (theGui != gInventory)
   {
     gInventory.Visible = false;
   }
 }
}


This is no problem - it does exactly what I want, however I'd like to know why I can't use the other method (if anyone knows) and what purpose the GUI *theGui (this seems to be setting a variable?) serves.

Thanks for your help :)
Title: Re: Two GUI Questions
Post by: Scarab on Fri 30/10/2009 10:52:57
Hmm, I'm not too familiar with this function, but could it have something to do with the parameters of GetAtScreenXY?
Title: Re: Two GUI Questions
Post by: ThreeOhFour on Fri 30/10/2009 10:58:27
Gosh dang it.

Now I feel like a stupid, I swear I had those mouse.x and mouse.y coordinates in before  :-[

Ignore the second question, I am tired and stupid  ;D
Title: Re: Two GUI Questions
Post by: Khris on Fri 30/10/2009 11:38:07
I'm curious why the compiler didn't complain about the missing coords?

As for 1.:
Set "handle inv clicks in script" to true, then process inv clicks in your on_mouse_click.
Since eMouseLeft/RightInv get triggered over inv items only, you could do this:

void inv_click(MouseButton button) {
  if (button == eMouseLeftInv) {
    inventory[game.inv_activated].RunInteraction(Mouse.Mode);
  }
  if (button == eMouseRight && player.ActiveInventory != null) player.ActiveInventory = null;
  if (button == eMouseRightInv) {
    if (player.ActiveInventory != null) player.ActiveInventory = null;
    else inventory[game.inv_activated].RunInteraction(eModeLook);
  }
}

function on_mouse_click(MouseButton button) {
  if (GUIControl.GetAtScreenXY(mouse.x, mouse.y) == InvWindow) {
    inv_click(button);
    return;
  }
  // rest here
}


This should catch inventory window clicks and handle them depending on whether the click was above an item or empty space.
Title: Re: Two GUI Questions
Post by: ThreeOhFour on Fri 30/10/2009 12:15:11
Khris, this seems perfect, awesome! It took a little bit of fiddling but it seems to work fine save for one confusing thing: It deselects just fine over other inventory items, but not when over a blank part of the inventory (Ie, space in the inventory that hasn't got an item in it). Am I missing something?

Thanks for your help so far  :D
Title: Re: Two GUI Questions
Post by: Khris on Fri 30/10/2009 14:10:19
I didn't test it, this line should take care of that:
  if (button == eMouseRight && player.ActiveInventory != null) player.ActiveInventory = null;
Not sure why it doesn't work :-\
Try adding some debugging lines as in
  if (button == eMouseRight) Display("right click");
Title: Re: Two GUI Questions
Post by: ThreeOhFour on Fri 30/10/2009 14:18:00
Just tried it, doesn't display the message.

Like I said, it isn't a big issue, just a minor annoyance, so if we can't get around it I am not going to be too upset.

If you're interested I can PM you the source (although I haven't bothered keeping my script very tidy this time, so it's a bit all over the place  :-[)
Title: Re: Two GUI Questions
Post by: Crimson Wizard on Fri 30/10/2009 16:49:08
Quote from: Ben304 on Fri 30/10/2009 12:15:11
Khris, this seems perfect, awesome! It took a little bit of fiddling but it seems to work fine save for one confusing thing: It deselects just fine over other inventory items, but not when over a blank part of the inventory (Ie, space in the inventory that hasn't got an item in it). Am I missing something?

That's actually an issue I am having for maybe 3rd time already when making a game :)
So I am interested in getting an answer too.

EDIT: I tried to set breakpoints in on_mouse_click function and know what? It does not even run this event when clicking on empty inventory space.
I consider that's rather an AGS bug...
Title: Re: Two GUI Questions
Post by: Crimson Wizard on Fri 30/10/2009 18:42:13
Meh, I got the answer as soon as I wrote that it is a bug (which is actually wrong) :P

Quote from: GarageGothic on Fri 30/10/2009 17:13:54
Hmm, if I remember correctly the Inventory handles clicks differently depending on whether you click on an item or in the surrounding window. You may need to split your code between on_mouse_click() and the on_event for eEventGUIMouseDown (for clicks outside inventory items).

Title: Re: Two GUI Questions
Post by: ThreeOhFour on Sun 01/11/2009 05:58:45
After referring to the thread CW started in the Tech forum and annoying monkey for help, this all works perfectly. Big thanks guys, I really appreciate your help!  :D