Author Topic: Mouse Mode In Inventory  (Read 226 times)

Mouse Mode In Inventory
« on: 12 Sep 2018, 13:25 »
Hello.

I'd like for my game to cycle through the mouse modes when you right click. So walk, look, interact and talk. Unless you are in the inventory, which is opened by moving the mouse to the top of the screen and then the inventory pops down. Upon opening the inventory I would like it to switch to the pointer so you can select an item to use, and if you right click to switch to look, and to cycle between just those two. Everything is fine, except changing the mode upon opening the inventory. Here is the code.

Code: Adventure Game Studio
  1. function gInventory_OnClick(GUI *theGui, MouseButton button)
  2. {
  3.   if (button == eMouseRight)
  4.     {
  5.       if (mouse.Mode == eModePointer)
  6.         {
  7.         mouse.Mode = eModeLookat;
  8.         }
  9.       else if (mouse.Mode == eModeLookat)
  10.         {
  11.         mouse.Mode = eModePointer;
  12.         }
  13.     }
  14. }
  15.  

So right now, when you open the inventory, the cursor will change to the pointer, but the mode you were in stays as it was. So if I am not in look mode I am unable to change the mode, but if I am in look when I open it, then I can change the mode by right clicking to eModePointer, and then back to look (This time with the right cursor image) but then it stays at look and I cannot change it again via right clicking.

What I need is when the inventory opens, the mouse mode should change to eModePointer, not just the image and to then cycle between that mode and image, and those for looking at things. I cannot find where I can change this though. There is the show_inventory_window function but it does nothing when I change it. I think it doesn't trigger unless called by it being put in the event for clicking a button, right? I've gone through the whole code and commented out anything related to changing the mode or cursor image that isn't part of what I want to happen as it relates to this specific thing.
« Last Edit: 16 Sep 2018, 10:28 by Wedge »

Ghost

  • AGS Baker
  • Rottwheelers
  • Nerf on!
    • Ghost worked on a game that was nominated for an AGS Award!
      Ghost worked on a game that won an AGS Award!
Re: Mouse Mode In Inventory
« Reply #1 on: 12 Sep 2018, 18:12 »
My coding's a bit rusty but IIRC the problem is that you attempt to change a cursor mode ON clicking. AGS is a bit finniky in tht respect: You are in a mode when clicking and then you change to another mode which is then not processed because you already clicked and triggered the event.

Instead of setting the mouse.mode, try the command ProcessClick(mode), where mode would be eModeLookAt or eModeUseInv. The latter actually selects the inventory item. Should work alright.
« Last Edit: 12 Sep 2018, 19:56 by Ghost »

Khris

  • having to deal with what games are going through
    • Lifetime Achievement Award Winner
    •  
    • I can help with play testing
    •  
    • I can help with scripting
    •  
    • I can help with translating
    •  
    • Khris worked on a game that was nominated for an AGS Award!
Re: Mouse Mode In Inventory
« Reply #2 on: 12 Sep 2018, 22:49 »
AFAIK, the mouse cursor changing to the pointer graphic is hardcoded for PopupY GUIs, meaning the current cursor mode is retained.
The alternative is to implement the PopupY behavior yourself. Switch the GUI's visibility to "Normal, initially off", and use this:
Code: Adventure Game Studio
  1. int prevMode;
  2.  
  3.   // the following inside repeatedly_execute
  4.   if (mouse.y < 10 && !gInventory.Visible) {
  5.     gInventory.Visible = true;
  6.     prevMove = mouse.Mode;
  7.     mouse.Mode = eModePointer;
  8.   }
  9.   else if (gInventory.Visible && mouse.y > gInventory.Height) {
  10.     if (mouse.Mode == eModePointer) mouse.Mode = prevMode;
  11.     gInventory.Visible = false;
  12.   }

Re: Mouse Mode In Inventory
« Reply #3 on: 13 Sep 2018, 18:33 »
OK great. Thanks frens.