Inventory Right- and Left-Click-BUG

Started by Digital Mosaic Games, Sat 05/06/2010 03:35:38

Previous topic - Next topic

Digital Mosaic Games

Hello AGSers,

I have an anoying problem with my inventorywindow. I can´t figure out wat´s wrong on my code. :(

How it should be:

When I have selected an inventoryitem and my inventory window is still visible.
And in this moment when I make a Right-Click the mouse should turn back to the "normal-Inventory-mouse"(eModeInteract).
But in my case this doesn´t works.


Code: ags
function on_mouse_click(MouseButton button) 
{
  if (button == eMouseLeft) 
  {
    ProcessClick(mouse.x, mouse.y, mouse.Mode);
  }
  else 
  {
     if (button==eMouseRight) 
     {
        if(player.ActiveInventory == null) //no selected Item
        {
        show_inventory_window();
        }
        else
        if(player.ActiveInventory != null) //selected Item
        {
           if(gInventory2.Visible==false) 
           {
              player.ActiveInventory = null;
              //than
              if(Sitting == true) 
              {
              mouse.Mode = eModeSittingGo;
              }
              else 
              {
              mouse.Mode = mouse.Mode;
              }
           }
              else
              if(gInventory2.Visible==true) 
              {
              player.ActiveInventory = null;
              mouse.Mode = eModeInteract;
              }
        }
     }
  }
}


Ryan Timothy B

#1
It's a very annoying feature with the inventory window -- I'm assuming you mean that it doesn't deselect the inventory item only while you're over the inventory window and right click.

You have to do something along the lines of this, put this in the global script:
Code: ags

function on_event(EventType event, int data) {
  if (event == eEventGUIMouseDown) {
    if (mouse.IsButtonDown(eMouseRight)) {
      GUIControl *theControl = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
      if (theControl==InventoryWindow1) {
        InventoryItem *i = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
        if (i==null) { //only if there isn't an inventory item where you're clicking
          player.ActiveInventory = null;   // lose active inventory item
          mouse.Mode=eModeInteract; //or whatever mode it should be
        }
      }
    }
  }
}


The only thing you really should have to change is: InventoryWindow1  to the name of your inventory box.

Digital Mosaic Games

Thanks, Ryan!

Your piece of code makes almost excactly what I wanted.
I reduced it only a bit:

Code: ags
function on_event(EventType event, int data) {
  if (event == eEventGUIMouseDown) {
    if (mouse.IsButtonDown(eMouseRight)) {
          player.ActiveInventory = null;   // lose active inventory item
          mouse.Mode=eModeInteract; //or whatever mode it should be       
      }
    }
}


The only thing what isn´t so good is, when I selected an item and the InventoryWindow is still open and I right-click over an other item I examine it, what should only be possible if I havent selected an item.

Ryan Timothy B

That's because you've reduced my code to work in a totally different way, which yields improper results.  I thought you meant that you couldn't figure out how to deselect an inventory item ONLY while you're hovering the mouse over the inventory window and right clicked.  Which is what my code was for.

Otherwise there is no 'bug' as you've stated, just improper coding.

If it's for regular deselecting of inventory items while right clicking, you don't use this code whatsoever.  

Dualnames

if you want it to look shorter just do this:

Code: ags

function on_event(EventType event, int data) {
  if ((event == eEventGUIMouseDown) && (mouse.IsButtonDown(eMouseRight))) {
       GUIControl *theControl = GUIControl.GetAtScreenXY(mouse.x, mouse.y);
       InventoryItem *i = InventoryItem.GetAtScreenXY(mouse.x, mouse.y);
      if ((theControl==InventoryWindow1) && (i==null)) { //only if there isn't an inventory item where you're clicking
          player.ActiveInventory = null;   // lose active inventory item
          mouse.Mode=eModeInteract; //or whatever mode it should be
       }
  }
}


:-\
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

Ryan Timothy B

#5
I'm not sure why you have:  mouse.Mode = mouse.Mode;  That's like going 1=1;

What are your issues exactly?  Just deselecting items in general (any location of the screen) doesn't work?


Dual, worst thing about condensing that script like that is it gets AGS to check all the Controls at the mouse's X and Y, AND checks all the Inventory objects at the X and Y even if you haven't clicked on the inventory window.  It's not a huge deal in CPU time, I imagine though and it only runs this when you right click.

Truthfully I guess the code should check to see if you even have an inventory item active, otherwise it shouldn't even run.  Like:
Code: ags

if (event == eEventGUIMouseDown && player.ActiveInventory!=null) {
...etc

SMF spam blocked by CleanTalk