cursors switch unusable in inventory

Started by lafouine88, Fri 23/10/2020 12:09:35

Previous topic - Next topic

lafouine88

Hi guys!
So, I've spent many hours on this and now I am on the verge of letting it go... Why the hell don't my cursors switch the usual way in the inventory mode.
I know the inventory pauses the game and could break the command, but even when I unpause it to try ("normal" mode instead of "pause game when shown"), nothing changes.

Here is my on click command :
Code: ags

function on_mouse_click(MouseButton button)
{ 
  
 if (button == eMouseLeft)
{
    // if it is walk-to command
    if (mouse.Mode == eModeWalkto)
    {
      // if there's a hotspot under mouse cursor
      if (GetLocationType(mouse.x, mouse.y) == eLocationHotspot)
      {
        if(IsInteractionAvailable(mouse.x, mouse.y, eModeLookat)==0){
         //then fire "interact" event
        Room.ProcessClick(mouse.x,mouse.y, eModeInteract);}
        
      }
    }
    
    if (GetLocationType(mouse.x, mouse.y) == eLocationHotspot||GetLocationType(mouse.x, mouse.y) == eLocationObject)////if cursor not over hotspot, walk there whatever it is
      {
            Room.ProcessClick(mouse.x,mouse.y, mouse.Mode);
            }
        else{Room.ProcessClick(mouse.x,mouse.y, eModeWalkto);}

  }
  else // right-click, so cycle cursor
  {   
    mouse.SelectNextMode();
  }
}





lines 9 to 14 are just a way I made out to exit maps without having to switch 'interact' so don't mind them(Exit hotspots dont have a "lookat" function so it automatically triggers the interact without needing to change).
I also removed the "if gamepaused" condition in case that was the problem. It seems it isn't, but I still haven't put it back yet.

What is weird is that the mouse 3 button of my mouse (the wheel) makes the switch, but not the right click. So I suppose there is hope, but I can't find the thing.

Thanks a lot.

arj0n

darn, clicked quote instead of edit...

arj0n

#2
Code: ags

function on_mouse_click(MouseButton button)
{
  if (IsGamePaused())
  {
    // game is paused, so do nothing (i.e. don't process mouse clicks)
  }
  else if (button == eMouseLeft)
  {
    if (mouse.Mode == eModeWalkto) // if it is walk-to command
    {
      if ((GetLocationType(mouse.x, mouse.y) == eLocationHotspot) && (IsInteractionAvailable(mouse.x, mouse.y, eModeLookat) == 0)) Room.ProcessClick(mouse.x,mouse.y, eModeInteract); // if there's a hotspot under mouse cursor then fire "interact" event
      else Room.ProcessClick(mouse.x,mouse.y, eModeWalkto);
    }
    else Room.ProcessClick(mouse.x,mouse.y, mouse.Mode);
  }
  else if ((button == eMouseRight || button == eMouseWheelSouth) || (button == eMouseMiddle) || (button == eMouseWheelNorth)) mouse.SelectNextMode(); // right-click, so cycle cursor
}


remove eMouse... options from line 16 if needed.

lafouine88

Hi Arjon. thanks for your reply. I think I actually based my own script on one that is similar to yours. I just changed a few details. But either one still don't work in the inventory.
Does it work in your own game?
Did you override the built in inventory window click handling ?
Maybe there is another line somewhere in my script that overrides the normal behaviour of the mouse.

arj0n

Sorry, totally missed that inventory part of your question.

Code: ags

//when clicking on inventory gui outside the inventory box:
function gInventory_OnClick(GUI *theGui, MouseButton button)
{
  if (mouse.IsButtonDown(eMouseLeft)) 
  {
    //do nothing
  }
  else if (mouse.IsButtonDown(eMouseRight)) 
  {
    if (!player.ActiveInventory == null)  player.ActiveInventory = null;   // lose active inventory item
    else if (player.ActiveInventory == null)  mouse.SelectNextMode(); // cycle cursor
  }
}


line 10 can be removed if not needed of course (and, in that case, also remove the " else if" of line 11)

lafouine88

Ok thanks that seems cool .But how do you apply it in the script ? I tried just pasting it in the global script, didn't work. But I need to define the inventory click (else than item) and I don't get how to do that.

Sorry, I'm doing a lot of things without having to get too much into details about scripts so I'm pretty lame about it.

Thanks again.

arj0n

The global script is the correct place.

First make sure the correct giu name is set in the code snippet youve pasted:
in line 2 of the example make sure "gMyInventory_OnClick" uses the name of your inventory gui.
So if for example your inventory gui is named gMyInventory, than line 2 needs to become this:

function gMyInventory_OnClick(GUI *theGui, MouseButton button)

Secondly:
Make sure the giu event is linked to the code:
- Open your Inventory gui
- Now on the properties pane, click the Events icon (the lightning icon)
- In the Events list you'll see an Onclick item.
- Here you click the 3 dots at the right-hand side and the link to the global script code (you've pasted) will be used

gInventory_OnClick (or whatever your giu is named) will now be set as link name.

Now save and re-run your game to check if all works correct.

lafouine88

Yes, that's right, I forgot to define the onclick button in the gui. Seemed obvious but when you only use buttons it doesn't come straight to themind^^

So, It does work , but, not exactly as I wished.
Here is the link of the inventory :
https://ibb.co/sCHq8kx
(It's the sam and max one if you know the game or want to check how the orignal works you can check https://www.youtube.com/watch?v=LvjqHbF9zR0 at 39'15''. Or you can try this awesome game).

So problem is, the switch works but only in the green area. When I'm over the action buttons, it still is blocked, and same goes when over the inventory list, which is 70% of the window. Does the mouse really need to change it's behaviour ? Can't it just work the same it does inGame, and only trigger the gui buttons ?

Anyway, I think we're getting closer so thanks a million arj0n for your time :)

arj0n

the action buttons and inventory list can have their own events, codewise just like the one you now used.

lafouine88

Yes, I can see how I could apply the same thing to the action buttons. Nice.
But the inventory list doesn't have an event button. I hope it's the last time I annoy you, but could you tell me how you would apply the same function to the inventorylist ? :)

Thanks again

arj0n

#10
in this example 'invCustomInv' = the name of the inventorylistbox:

Code: ags

//when clicking on inventory box on an item on:
function on_event(EventType event, int data) {
  if (event == eEventGUIMouseDown) 
  {
    if (mouse.IsButtonDown(eMouseRight)) 
    {
      GUIControl *theControl = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
      //right-mouse click on inventory box:
      if (theControl==invCustomInv) 
      {
        if (player.ActiveInventory != null)
        {
          player.ActiveInventory = null;   // lose active inventory item
          mouse.Mode=eModeInteract; //set whatever mode it should be
        }
        else if (player.ActiveInventory == null)
        {
          InventoryItem *i = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
          if (i!=null) //only if there isn't an inventory item where you're clicking
          {
            mouse.SelectNextMode(); // cycle cursor
          }
        }
      }
    }
  }
}


You might want to adjust this because it is not per see exactly what you wanted.
You can place this code under the previous code you've put in your global script.

lafouine88

Ok i ll try that tomorrow and let you guys know but it seems very good. Thanks a lot

Khris

If you enable overriding the built-in inventory click handling, you need to add blocks for eMouseLeftInv and eMouseRightInv to your global on_mouse_click.
Something like:

Code: ags
  else if (button == eMouseLeftInv) {
    InventoryItem *i = inventory[game.inv_activated];
    if (mouse.Mode == eModeInteract) player.ActiveInventory = i; // pick up item
    else i.RunInteraction(mouse.mode); // look at item, use other item on it
  }
  else if (button == eMouseRightInv) {
    mouse.SelectNextMode();
  }


Note that these clicks are only triggered above items; clicking an empty spot can only be detected using on_event and eGuiMouseDown/Up

lafouine88

Hey guys, juste a quick update about my issue.

The on event code works really well. thanks again. I still have some minor issues at the moment (the left and right click don't yet work the same as the rest when over a cursor GUI button), but I think I have all I need now to make everything right.

So thanks for your help and see you :)

SMF spam blocked by CleanTalk