Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Mr Flibble on Tue 02/01/2007 21:04:37

Title: Middle mouse button and clicks over GUI. [SOLVED]
Post by: Mr Flibble on Tue 02/01/2007 21:04:37
Edit: Thought I'd save a mod some work, and add in my own Solved tags.  :)

Alright, here's the thing. I have a GUI that I want to display with a middle button click. This works fine and dandy. But I also want to be able to middle click again to close the GUI. This doesn't work.

The debug console tells me that the click is registering as a click over a GUI, so I made a button in the centre of the GUI (where the cursor would be) and set it to close the GUI if it received a middle click. But it still doesn't work. Can anyone help me with this? I just want the middle click to toggle the GUI being open or closed..

Notes:
Any help would be GREATLY appreciated, because I've been tussling with this one for ages now..


#sectionstart on_mouse_click  // DO NOT EDIT OR REMOVE THIS LINE
function on_mouse_click(MouseButton button) // called when a mouse button is clicked. button is either LEFT or RIGHT
  {
  if (IsGamePaused() == 1) // Game is paused, so do nothing (ie. don't allow mouse click)
    {
    }
  else if (button == eMouseLeft)
    {
    ProcessClick(mouse.x,mouse.y, mouse.Mode);
    }
  else if (button == eMouseMiddle) // MIDDLE..
    {   
    if (gVerbwheel.Visible== true) {
      gVerbwheel.Visible=false;
      }
      else if (gVerbwheel.Visible== false) {
        gVerbwheel.Visible=true;
    }
    }
  else if (button == eMouseWheelNorth)
      {
     if ((GetGlobalInt(1)==0)) {
        SetGlobalInt(1,  1);
        }
      else if((GetGlobalInt (1) ==  1)) {
        SetGlobalInt(1,  2);
        }
      else if((GetGlobalInt(1) == 2)) {
        SetGlobalInt(1,  3);
        }
      else if((GetGlobalInt(1) == 3)) {
        SetGlobalInt(1,  4);
        }
      else if((GetGlobalInt(1) == 4)) {
        SetGlobalInt(1,  0);
        }
      }
  else if (button == eMouseWheelSouth)
       {
      if ((GetGlobalInt(1)==0)) {
         SetGlobalInt(1,  4);
         }
else if ((GetGlobalInt(1)==4)) {
   SetGlobalInt(1,  3);
   }
       else if ((GetGlobalInt(1) ==3)) {
SetGlobalInt(1,  2);
}
else if ((GetGlobalInt(1)==2)) {
         SetGlobalInt(1,  1);
         }
       else if ((GetGlobalInt(1)==1)) {
         SetGlobalInt(1,  0);
         }
       
         
}
}

   
 
#sectionend on_mouse_click  // DO NOT EDIT OR REMOVE THIS LINE


#sectionstart interface_click  // DO NOT EDIT OR REMOVE THIS LINE
function interface_click(int interface, int button)
  {
  if (interface == VERBWHEEL) {
   if (button==0) {
     if (button==eMouseMiddle) {
    gVerbwheel.Visible=false;
  }
}
else {
   gVerbwheel.Visible=false;
   }
}
}
#sectionend interface_click  // DO NOT EDIT OR REMOVE THIS LINE


Oh, and this may be useful too.

#sectionstart repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE
function repeatedly_execute()
  {
  int mousexpos= mouse.x;
  int mouseypos= mouse.y;
  if (gVerbwheel.Visible==true) {
  gVerbwheel.SetPosition(mousexpos-22,mouseypos-21);
  }
  // put anything you want to happen every game cycle here
  }
#sectionend repeatedly_execute  // DO NOT EDIT OR REMOVE THIS LINE


Thanks in advance for any hints you can offer.
Title: Re: Middle mouse button and clicks over GUI.
Post by: Khris on Tue 02/01/2007 23:03:41
Add this to the rep_ex:

  if (mouse.IsButtonDown(eMouseMiddle) && gVerbwheel.Visible) {
    gVerbwheel.Visible=false;
    while (mouse.IsButtonDown(eMouseMiddle)) {
      Wait(1);
    }
  }
Title: Re: Middle mouse button and clicks over GUI.
Post by: Mr Flibble on Tue 02/01/2007 23:30:27
I was really happy that the solution might be so simple.

But I just got an error message when the game started, IsButtonDown only works with left and right clicks.

So what now? Is there an alternate way to fix this problem? I'd really like to use the middle button for this GUI, I think it will be really intuitive and easy to use. It's just the idea I had.. I want to make this work. I guess I could change it to the right button, but that's more of a last resort.

During my research I noticed that AGS's middle button support isn't heavily enforced, and it isnt AGS's fault. But.. I know this can be made to work!  :)
Title: Re: Middle mouse button and clicks over GUI.
Post by: GarageGothic on Wed 03/01/2007 00:08:21
Well, you're checking for IsGamePaused() at the beginning of the function. If the GUI is set to pop-up modal, the game WILL be paused while it's displayed so the function won't run and thus the button click doesn't register.
Title: Re: Middle mouse button and clicks over GUI.
Post by: Mr Flibble on Wed 03/01/2007 00:22:32
The GUI is set to Normal. I did check if I had set it to Popup Modal (I do love it when a simple solution comes) but.. no luck.
Thanks anyway, man.

The IsGamePaused is in there by default, if I recall.
Title: Re: Middle mouse button and clicks over GUI.
Post by: GarageGothic on Wed 03/01/2007 00:54:54
Too bad, I like easy solutions too :). It's still the only sensible solution I can see (since you're saying that it doesn't make any difference if you insert eMouseRight instead). Are you sure the game isn't paused for one reason or another? What if you move the "if (button == eMouseMiddle)" code to the very top of on_mouse_click?

For the sake of debugging, I would remove the interface_click code at least. It shouldn't be necessary to perform the action you want and may be contributing to the problem.
Title: Re: Middle mouse button and clicks over GUI.
Post by: Khris on Wed 03/01/2007 01:30:23
Here's the easy solution:
Set the GUI's Clickable property to "No".

If you need AGS to distuingish between middle clicks to the room and middle clicks to the GUI, leave Clickable set to "Yes", double click the GUI's On click property and click Ok (to accept the proposed name of the function). Now double click the GUI itself in the editor; this will open the global script at the newly created function which you should edit to look like this:
#sectionstart gVerbwheel_Click  // DO NOT EDIT OR REMOVE THIS LINE
function gVerbwheel_Click(GUI *theGui, MouseButton button) {
  if (button==eMouseMiddle) theGui.Visible=false; 
}
#sectionend gVerbwheel_Click  // DO NOT EDIT OR REMOVE THIS LINE
Title: Re: Middle mouse button and clicks over GUI.
Post by: GarageGothic on Wed 03/01/2007 01:36:06
But isn't on_mouse_click called whether the GUI is clickable or not? Why even distinguish between whether the mouse is over the gui or not? When the gui is visible, it's always moved so that it's under the cursor as far as I can tell from the repeatedly execute script.

If it works, cool. But I'd still like to know why the original code wasn't.
Title: Re: Middle mouse button and clicks over GUI.
Post by: Mr Flibble on Wed 03/01/2007 01:44:48
Excellent.. with KrisMuc's latest version it works.

It didn't at first, but then I had the prescence of mind to delete the button which I had created aaaages ago (as referenced in original code snippets).

I also removed the interface_click stuff like you said Garage, to be on the safe side.

Anyway, once I had made these changes.. it worked beautifully! Thanks so much guys!
Title: Re: Middle mouse button and clicks over GUI. [SOLVED]
Post by: Khris on Wed 03/01/2007 03:37:52
GG:
Seems like any clickable GUI under the mouse will intercept the call to on_mouse_click. And this makes sense, too, because that way one can concentrate on handling room clicks in on_mouse_click.

It wasn't necessary to distinguish between whether the mouse is over the gui or not in this case, true, but it might be for another interface, so I mentioned it for future reference.