How to change Right Button click on inventory window?

Started by Gribbler, Mon 05/11/2012 22:54:28

Previous topic - Next topic

Gribbler

Hello!

Scripting basics, animations, sounds, music, variables I have pretty much figured out by now, but GUI scripting and pretty much code at the beginning of the GlobalScript are still a mystery to me. I'm afriad to fiddle with it to this day:) And I believe my next problem applies to this area of the game. Here's the deal: I have a inventory window constantly displayed on the bottem of the screen. I have default cursor modes like Walk, Look, Interact etc. When I move the cursor over the inventory window, RIGHT BUTTON clicks start to serve as LOOK AT function instead of cycling through mouse modes. How do I change this? I want the player to be able to change mouse modes over inventory window (and select eye cursor manually) just like in any part of the screen. I do not want to use right click for looking at all. Now, I tried to apply this:

Code: AGS

 if (button == eMouseRight || button == eMouseWheelSouth){
    mouse.SelectNextMode();
    }


I put this into the "function show_inventory_window" in GlobalScript but with no luck. I keep getting "undefined symbol 'button'" message.
I still do not understand functions so I once again need your help guys...


Khris

This doesn't work because any code of the "whenever X happens, do Y" variety only makes sense in a function that is either called constantly (repeatedly_execute) or every time a relevant game event happens (on_mouse_click, on_event, etc.)

What you need is add the on_event function to the global script:
Code: ags
function on_event(EventType event, int data) {
  if (event == eEventGUIMouseDown) {
    // determine button and wait for release
    int button;
    int i = eMouseLeft;
    while (i <= eMouseMiddle) {
      if (mouse.IsButtonDown(i)) {
        button = i;
        while (mouse.IsButtonDown(i)) {
          Wait(1);
        }
      }
      i++;
    }
    if (GUI.GetAtScreenXY(mouse.x, mouse.y) == gInventory && data == gInventory.ID && button == eMouseRight) mouse.SelectNextMode();
  }
}


This code detects the event "mouse button down over GUI", waits for the release of the button, then checks whether a) the GUI under the mouse at the point of the button being pressed down was gInventory b) the GUI under the mouse still is gInventory and c) the button was the right mouse button.
If so, mouse.SelectNextMode(); is called.
Not tested though!

Calin Leafshade

Not sure but isnt there an eMouseRightInv value for mouse click now?

Khris

Sure, but that only handles the "right click over inventory item" part. Not even clicking on the empty part of an InvWindow triggers on_mouse_click/eMouseLeft/RightInv. So for it to work over the entire GUI, it has to be done like I described.
There is another way using just repeatedly_execute always, mouse.isButtonDown and GUI.GetAtScreenXY, of course.

Gribbler

First of all thank you Khris for your help. I can now cycle through cursor modes over the inventory. Which is great! But right mouse button still serves as "LOOK AT" cursor mode. If I try to cycle through cursor modes when the cursor is over some item "looking at" is being called instead of cycling.

SMF spam blocked by CleanTalk