Question about mouse clicks in inventory handling

Started by bx83, Mon 29/07/2019 04:11:28

Previous topic - Next topic

bx83

The game will not respond to middle click in the inventory.
General Settings -> Inventory -> Override built-in inventory window click handling is set to False.
(though if I write it as True, nothing happens on_mouse_click(), so I'll stay away from that)

Basically, I want to have:
MouseWheelNorth - go up in inventory (works)
MouseWheelSouth - go down in inventory (works)
LeftClick - work's opposite way, it Uses
RightClick - work's opposite way, it LooksAt
MiddleClick - I want deselect the currently selected item (not totally sure how to do this either). It Uses whatever invitem it's over. Display code is ignored completely.

When I make General Settings -> Inventory -> Override built-in inventory window click handling set to True, it does nothing at all with any mouse click.

Code: ags

function on_mouse_click(MouseButton button)
{

// Game paused?

  if (IsGamePaused() == 1) {                                            // do nothing if paused
  } else

  if (gInventory.Visible) {                                             // if inventory is visible...
    
    
    
    //move up and down throught inventory with mouse wheel:
    if (button == eMouseWheelNorth) {
      invCustomInv.ScrollUp();
    }
    
    if (button == eMouseWheelSouth) {
      invCustomInv.ScrollDown();
    }
  
    //left click look, right click use
    if (button == eMouseLeft) {
      mouse.Mode=eModeLookat;
    }
    
    if (button == eMouseRight) {
      mouse.Mode=eModeInteract;
    }
    
    if (mouse.IsButtonDown(eMouseMiddle) || button==eMouseMiddle) {
      Display("thasth");           //NEVER DISPLAYS
    }

bx83

Tried putting them in gInventory_OnClick(), same situation. Turned off 'override built-in inventory settings', it just did nothing when clicking in the inventory.

bx83


bx83

More experimenting, I've set 'General Settings -> Inventory -> Override built-in inventory window click handling' to True, and used on_event() to capture the mouse button presses.
This is finally working, though not sure how to get father than this:

Code: ags

 
  if (gInventory.Visible) {
    
    //move up and down throught inventory with mouse wheel:
    if (event==eEventGUIMouseUp) {      <-- works
      invCustomInv.ScrollUp();
    }
    
    if (event==eEventGUIMouseDown) {      <-- works
      invCustomInv.ScrollDown();
    }

    //left click look, right click use
    if (mouse.Click(eMouseLeft)) {           <-- does nothing
      mouse.Mode=eModeLookat;
    }
    
    if (mouse.Click(eMouseRight)) {           <-- does nothing
      mouse.Mode=eModeInteract;
    }
    
    if (mouse.Click(eMouseMiddle)) {           <-- does work sometimes
      Display("thasth");
    }
  }

bx83

Okay, well, tried everything in every function and nothing works, or responds. I've spent all day on this, reading the forums and documentation.
So, I'm off to kill myself (j/k), but if anyone wants tell me where to capture: right-click, middle and left-click; and how to go about that (left click, lookat; right click, interact; middle click, get rid of activeinventory and go back to pointer) I would be eternally, eternally grateful.

Khris

Overriding the default handling means you need to add a block for  eMouseLeftinv  and  eMouseRightinv  to  on_mouse_click.
There's also  eMouseMiddleInv  but there are people out there that don't have a middle mouse button. Using the right button is preferable (after a click, check  if (player.ActiveInventory == null)  and act accordingly).

bx83

Thankyou, I'll try this.
What is mouseleftinv and is it better than mouseleft?

Laura Hunt

Quote from: bx83 on Mon 29/07/2019 10:33:10
Thankyou, I'll try this.
What is mouseleftinv and is it better than mouseleft?

It's not "better", it's simply the event you need to use in order to process mouse clicks in your inventory, since when the mouse is over an inventory window, AGS simply ignores eMouseLeft or eMouseRight and expects eMouseLeftInv/eMouseRightInv instead.

(And if I'm wrong about this please someone correct me! Sometimes I don't want to reply in case I'm giving misleading info but I think/hope it's not the case here :) )

Khris

It's not better.

When the user left clicks on the room, AGS calls  on_mouse_click(eMouseLeft);.
When default inv handling is overridden and the user clicks on an inventory item with the left mouse button, AGS calls  on_mouse_click(eMouseLeftinv);.

bx83

Code: ags

    //move up and down throught inventory with mouse wheel:
    if (button == eMouseWheelNorth) {
      invCustomInv.ScrollUp();
    }
    
    if (button == eMouseWheelSouth) {
      invCustomInv.ScrollDown();
    }

    //left click look, right click use
    if (button == eMouseLeftInv) {
      mouse.Mode=eModeLookat;
    }
    
   
    if (button == eMouseRightInv) {
      mouse.Mode=eModeInteract;
    }
    
    if (button == eMouseMiddleInv) {
      if (player.ActiveInventory!=null) mouse.Mode=eModeInteract;
    }


The above doesn't actually *work* - it changes mode graphic, but it doesn't do 'interact with item' ie. useinv; or 'look at item'.

bx83

Adding:

Code: ags

Room.ProcessClick(mouse.x, mouse.y, eModeLookat/eModeInteract);


doesn't work either.

Laura Hunt

#11
Quote from: bx83 on Mon 29/07/2019 10:46:42
Code: ags

    //move up and down throught inventory with mouse wheel:
    if (button == eMouseWheelNorth) {
      invCustomInv.ScrollUp();
    }
    
    if (button == eMouseWheelSouth) {
      invCustomInv.ScrollDown();
    }

    //left click look, right click use
    if (button == eMouseLeftInv) {
      mouse.Mode=eModeLookat;
    }
    
   
    if (button == eMouseRightInv) {
      mouse.Mode=eModeInteract;
    }
    
    if (button == eMouseMiddleInv) {
      if (player.ActiveInventory!=null) mouse.Mode=eModeInteract;
    }


The above doesn't actually *work* - it changes mode graphic, but it doesn't do 'interact with item' ie. useinv; or 'look at item'.

It doesn't work because you're not telling it what to do. Or more precisely, you're only telling it to change the mouse mode, and nothing else.

Where you have:

Code: ags
if (button == eMouseLeftInv) {
   mouse.Mode=eModeLookat;
}


Try using instead:

Code: ags
if (button == eMouseLeftInv) {
   inventory[game.inv_activated].RunInteraction(eModeLookat);
}



(doing this from memory, so I hope I'm not omitting anything, but that's the idea anyway)

bx83

Okay will try this.
I've goth this:
Code: ags

function on_mouse_click(MouseButton button)
{

...

    InventoryItem *tInv;
   
    if (button == eMouseRightInv) {
      tInv = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
      if (player.ActiveInventory==null) {
        if (tInv.IsInteractionAvailable(eModeInteract)) {
          tInv.RunInteraction(eModeInteract);
        }
      } else if (player.ActiveInventory!=null) {
        player.ActiveInventory==null;
      }
    }
   
    if (button == eMouseLeftInv) {
      tInv = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
      
      if (tInv.IsInteractionAvailable(eModeLookat)) {
        tInv.RunInteraction(eModeLookat);
      }
    } 


...but there's an error on line 15: GlobalScript.asc(1708): Error (line 1708): PE04: parse error at 'player'
Works in if, but not on it's own.



Laura Hunt

Quote from: bx83 on Mon 29/07/2019 11:47:22
...but there's an error on line 15: GlobalScript.asc(1708): Error (line 1708): PE04: parse error at 'player'
Works in if, but not on it's own.

That's because you're using "==" there instead of "=" (comparing vs. assigning values).

bx83

Oh woops :P

Okay well now left mouse button works (look at).
But the right mouse button does nothing. At all.

Laura Hunt

Quote from: bx83 on Mon 29/07/2019 11:53:32
Oh woops :P

Okay well now left mouse button works (look at).
But the right mouse button does nothing. At all.

The only thing that comes to mind that might be screwing with your script is this line:

Code: ags
      } else if (player.ActiveInventory!=null) {


Maybe try putting the else if statement in another line, not immediately after the previous closing bracket? (no idea if this is actually a problem or not, I always start a new line for these things but maybe it just doesn't matter.)

If this doesn't work, then here is where my knowledge ends, I have no idea what might be happening and it's time for someone more knowledgeable to take over  :-D

bx83

But why don't the lines:
Code: ags

      if (player.ActiveInventory==null) {
        if (tInv.IsInteractionAvailable(eModeInteract)) {
          tInv.RunInteraction(eModeInteract);

do anything? Surely they should make the inventory item you just right-clicked on the ActiveInventory?

morganw

You should use:
Code: ags
tInv = inventory[game.inv_activated];


...because checking what is under the mouse isn't 100% reliable (I'm not sure that is the issue here though)

Quote from: bx83 on Mon 29/07/2019 12:10:51
But why don't the lines:
Code: ags

      if (player.ActiveInventory==null) {
        if (tInv.IsInteractionAvailable(eModeInteract)) {
          tInv.RunInteraction(eModeInteract);

do anything? Surely they should make the inventory item you just right-clicked on the ActiveInventory?

At a guess, you aren't ever setting player.ActiveInventory to anything. If you are handling the clicks yourself you need specifically set it.

Laura Hunt

Quote from: bx83 on Mon 29/07/2019 12:10:51
But why don't the lines:
Code: ags

      if (player.ActiveInventory==null) {
        if (tInv.IsInteractionAvailable(eModeInteract)) {
          tInv.RunInteraction(eModeInteract);

do anything? Surely they should make the inventory item you just right-clicked on the ActiveInventory?

Wait, so what you want to do is make the inventory item you right-clicked on the active inventory item, not trigger an interaction for that item?

In that case, you need to do

Code: ags
if (player.ActiveInventory==null) player.ActiveInventory = inventory[game.inv_activated];


Again, apologies if there are any typos!

bx83

The game now works, except right clicking something in the inventory (when activeitem==null) will cause the cursor to change to the inventory item cursor graphic, and then disappear .5 of a second later. It still runs UseInv on whatever else you click in the inventory; but the mouse cursor is nothing until you get out of inventory.

on_mouse_click:
Code: ags

function on_mouse_click(MouseButton button)
{

// Game paused?

  if (IsGamePaused() == 1) {                                            // do nothing if paused
 
  
  } else
  if (gInventory.Visible) {                                             // if inventory is visible...
    
    //move up through inventory with mouse wheel
    if (button == eMouseWheelNorth) {
      invCustomInv.ScrollUp();
    }
    
    //move down through inventory with mouse wheel
    if (button == eMouseWheelSouth) {
      invCustomInv.ScrollDown();
    }
    
    InventoryItem *tInv;
    tInv = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
    
    if (button == eMouseRightInv) {
      if (player.ActiveInventory==null) {
        player.ActiveInventory=inventory[game.inv_activated];
      } else {
        tInv.RunInteraction(eModeUseinv);
      }
    }
   
    if (button == eMouseLeftInv) {
      mouse.Mode=eModeLookat;
      player.ActiveInventory=null;
      tInv.RunInteraction(eModeLookat);
    }


UpdateMouseGraphic (which I call whenever the mouse moves):
Code: ags

function UpdateMouseGraphic()
{
  int newGraphic;                                               // = 2054;
  int lt = GetLocationType(mouse.x, mouse.y);

  if (gInventory.Visible)
  {
    if (mouse.y >= 175 && (mouse.x <= 140 || mouse.x >= 1200))
    {
      gInventory.Visible = false;
      mouse.Mode = PreviousMouseModeOutsideInventory;
      return;
    }
    
    if (mouse.Mode == eModeLookat) {                            // LOOKAT
      newGraphic = 105;                                         // eye close
      InventoryItem* inve = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);

      if (inve != null) {
        newGraphic = 2056;                                    // eye open
      }
    }
    
    
    if (mouse.Mode==eModeInteract) {                             // INTERACTION
      newGraphic = 2;                                           // interact off
      InventoryItem* inve = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);

      if (inve != null) {
        newGraphic = 286;                                      // interact on
      }
    }

  } else {


The only other place that mentions UseInv is:
Code: ags

function btnIconCurInv_Click(GUIControl* control, MouseButton button)
{
  if (player.ActiveInventory != null) mouse.Mode = eModeUseinv;
}


Basically, I want to know why running ModeUseInv or loading the .CursorGraphic (as the cursor) of the target inventory item would make it *not have any mouse graphic at all*.


SMF spam blocked by CleanTalk