Inventory item events with Handle Inv Clicks enabled.

Started by Absentia, Wed 22/07/2009 01:43:22

Previous topic - Next topic

Absentia

This is a fairly simple question. I am developing a minimalistic system almost exactly the same as Beneath A Steel Sky - ie:

LMB = examine, walk, and use selected inv. item
RMB = interact, select item from inventory, and cancel selected inventory item.

I've got nearly all of that working (albeit with messy noobish code) but I want to be able to use LMB to look at inventory items, however I can't seem to use the prebuilt inventory item events because I've set it to handle inventory clicks in the script.  I was using ProcessClick to simulate a Lookat mode click on the item, but it doesnt trigger the event. Is there another way to trigger the Look event of an inventory item just through script?  That is, without playing around with strings and having to add "_Look" or something onto a function call.

Thanks.

Ghost

To use left/right clicks on inventory, you need you test against MouseRightInv/LeftInv. Many people try to use eMouseLeft/eMouseRight, which does work on everything BUT inventory items.

One simple way is to have

Code: ags

InventoryItem *tInv;


at the top of your global script, and in the on_mouse_click event, write something like:

Code: ags

  if (button == eMouseLeftInv)
  {
      tInv = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
      if (tInv.IsInteractionAvailable(eModeLookat))
      {
        tInv.RunInteraction(eModeLookat);
      }
      else
      {
        player.Say("I see nothing of interest.");
      }
    }    
  }

Absentia

Aah thanks!  :)
I had a feeling it was to do with RunInteraction but I wasn't quite sure how it worked. I was already familiar with eModeRightInv from the inventory item selection with RMB

monkey0506

Quote from: Ghost on Wed 22/07/2009 02:27:44Many people try to use eMouseLeft/eMouseRight, which does work on everything BUT inventory items.

It's actually important to note here that on_mouse_click is NEVER called with eMouseLeft or eMouseRight when clicking on a GUI/GUIControl (Button, Textbox, Label, Slider, etc.). So eMouseLeft/eMouseRight work for "everything BUT inventory items and GUIs and GUIControls." :P

Any clicks on a GUI/GUIControl are passed through that item's specific "OnClick" event handler. If it was a click on a GUIControl of the InvWindow variety then of course on_mouse_click will be called with either eMouseLeftInv or eMouseRightInv as you've said. These clicks will also all register in on_event with the EventType of eEventGUIMouseDown (when the mouse is clicked) as well as eEventGUIMouseUp (when the mouse is released). The DATA parameter for on_event will be the ID property of the GUI or OwningGUI of a control. You can check if it was a control by using GUIControl.GetAtScreenXY.

As far as your slight confusion there Absentia what InventoryItem.RunInteraction does is it simulates a mouse-click on the inventory item. For example "iKey.RunInteraction(eModeLookat);" would do the exact same thing as actually clicking on the iKey inventory item with the eModeLookat mouse cursor mode.

If you want to simulate a click on something other than an InventoryItem (say a Hotspot, Object, or Character) you would instead use the function ProcessClick which just simulates a mouse-click. Actually, when you click the mouse it just calls on_mouse_click (or a GUI/GUIControl event handler) which is why on_mouse_click generally places a call to ProcessClick which in turn actually sends the click through to the processing functions (i.e., the hotspot's event handlers). So if you want to simulate any additional functionality you might have in your on_mouse_click functions then just calling ProcessClick wouldn't work. To clarify what it does is it just immediately sends through the interaction.

Now I'm worrying myself that I'm just making things more confusing...but I was trying to clarify a few things for you (and for posterity's sake of course :)).

Galen

Disregard this, I'm retarded and posted this in the wrong topic. Damn you multiple-tabs! >:(

Absentia

Thanks monkey, that wasn't confusing and it's helpful to know about how the GUIs react to mouse clicks - because removing code from the default was too tedious I actually decided to start from an empty template, and while it makes it far easier to script it does mean I have to build the GUI from scratch too.


Quote from: Crazy on Wed 22/07/2009 20:08:52
I'm really not sure what your problem with the display is, I upped the resolution and replaced the background and it ran just fine for me... :/

As for being able to right click on the inventory window, it simply isn't possible without checking for mouse clicks every frame (which in my eyes is just too complicated to warrant bothering).

Don't understand your comment about the display... I can't see how what I said could be misconstrued like that, but nevermind =P
Also, checking for right clicks on the inventory is possible - unless you mean the whole "inventory list" part of the GUI, which doesn't have a click event, but I actually meant an inventory *item* which is achieved just using eModeRightinv.

Don't know why I'm still dragging this thread out, the issue was fixed and cleared up!
Cheers again guys.

SMF spam blocked by CleanTalk