[SOLVED] Clicking on empty space in inventory does not run mouse event

Started by Crimson Wizard, Fri 30/10/2009 16:57:29

Previous topic - Next topic

Crimson Wizard

I mean on_mouse_click.
It doesn't, even though I have "Handle inventory clicks in script" set on.

Why is it bad?
For example, imagine I want to make RMB make active inventory removed (like cancel using item). Then, when in inventory, you can only click RMB on other items to make it work, but if you click on empty space nothing happen.

tzachs

Just a thought, but maybe the GUI that's holding the inventory is marked as clickable? Have you tried switching it?

Calin Leafshade

You can probably use IsMouseDown in Rep exec as a workaround.

GarageGothic

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).

monkey0506

Quote from: Crimson Wizard on Fri 30/10/2009 16:57:29I mean on_mouse_click.

Which is actually the behaviour I would expect. You're clicking on an InvWindow not an InventoryItem. An InvWindow is of course a GUIControl. No clicks on a GUIControl are processed by on_mouse_click. Ever.*
*Unless of course both the GUIControl (and any controls which may be hiding behind it) and the owning GUI are non-Clickable.
Quote from: GarageGothic on Fri 30/10/2009 17:13:54Hmm, 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).

Indeed.


monkey0506

Don't sweat it. The on_event code should look like this:

Code: ags
function on_event(EventType event, int data) {
  if (event == eEventGUIMouseDown) {
    if (data == invInventory.OwningGUI.ID) { // clicked on GUI containing InvWindow
      GUIControl *gcat = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
      if ((gcat == null) || (gcat.AsInvWindow != invInventory)) return; // didn't click on InvWindow
      // otherwise we clicked on the InvWindow
      // NOTE: This will be called even if we clicked on an inventory item
      // do some stuff hereeeeee...
    }
  }
}


By the way, which MouseButton would you expect on_mouse_click to be called with? eMouseRight or eMouseRightInv? Because you're not clicking on an inventory item...anyway you could just call on_mouse_click from within this function with whichever mouse mode you were expecting...problem solved! ;)

Edit: Just to clarify to those reading, invInventory in the above script is a placeholder for the script name of your InvWindow. Just in case anybody missed that... ::)

Edit Mark II: The For-Posterity Edition! Between Ben304 and myself we've discovered that on_event is in fact called with eEventGUIMouseDown even if you clicked on an InventoryItem. So I've updated the commentation in the above code to denote this fact. If you want to make sure that you didn't click on an inventory item, you could just do:

Code: ags
      InventoryItem *iat = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
      if (iat != null) return;


Or you could do whatever you wanted with the inventory item, but that should be getting handled in your on_mouse_click event already. ;)

SMF spam blocked by CleanTalk