Drop inventory items in empty space and switch items?

Started by tilapisha, Fri 10/03/2023 17:35:05

Previous topic - Next topic

tilapisha

#20
I tried adding in the code accordant to the opened ticket. But, I need to turn override built-in inventory window click handling to True, and then write my own code for all of the other on_click events?


Code: ags
function on_event(EventType event, int data)
{
  if (event == eEventEnterRoomBeforeFadein)
  {
    CursorMode mode = mouse.Mode;
    if (mode == eModeWalkto) mouse.SelectNextMode();
    mouse.DisableMode(eModeWalkto);
    mouse.Mode = mode;
  }
  
  if (event == eEventGUIMouseDown &&
    data == gIconbar.ID &&
    GUIControl.GetAtScreenXY(mouse.x, mouse.y) == InventoryWindow1 &&
    InventoryItem.GetAtScreenXY(mouse.x, mouse.y) == null &&
    mouse.IsButtonDown(eMouseLeft)) {
      cGoby.ActiveInventory = null;
      }

}

Khris

Afaik overriding built-in inventory click handling is only necessary for handling eMouseLeftInv and eMouseRightInv inside on_mouse_click, but this is about detecting a click on an empty spot of the inv window, which requires on_event code instead.

So the code should work without overriding it.
Can you do some debugging? As in: add Display calls to see which parts run and which ones don't.

Like
Code: ags
  if (event == eEventGUIMouseDown && data == gIconbar.ID) {
    int mx = mouse.x, my = mouse.y;
    bool leftButton = mouse.IsButtonDown(eMouseLeft);
    Display("click on iconbar");
    if (GUIControl.GetAtScreenXY(mx, my) == InventoryWindow1) {
      Display("click on inv window");
      if (InventoryItem.GetAtScreenXY(mx, my) == null) {
        Display("click on empty spot");
        if (leftButton) {
          Display("left button was used");
          cGoby.ActiveInventory = null;
        }
      }
    }
  }

Edit: I tested the above code and it works as it should. The only remaining issue is a cosmetic one: hovering over the top bar with an active inventory item will change the mouse cursor  back to the pointer sprite. Which makes sense for the buttons on the right but not the "place item back into inventory" part.

Btw: I've noticed you've set GUI 7 as text window, but there is no GUI 7, therefore calling Display() causes a crash. Replace the 7 with a 0 in General settings -> Text display to use the default box.

tilapisha

#22
Yes, thank you!!! Now to changing the mouse graphic back to the inventory item.

I;m going to try and override the pointer in repeatedly execute with one of the mouth functions.

SMF spam blocked by CleanTalk