Weird problem with right-mouse "disable" and inventory

Started by Knox, Wed 23/09/2009 03:26:55

Previous topic - Next topic

Knox

In my on_mouse_click I deleted everything for the eMouseRight to debug something with my inventory:

Code: ags

  else if (button == eMouseRight) 
  {

  }


Basically, by putting nothing there I figure right clicks are now diabled...What I dont understand is when Im in pointer mode, I can still right-click on icons in my iconbar, and right-clicks work in my inventory, even though in my on_mouse_click there is nothing "set" for the right-click (?)...is this something to do with the "pointer mode" overriding something? Or is it one of those "aww man, thats simply stupid, just do this" kinda things?

How can I totally disable the right click when Im in my inventory? Something like this I figure:

Code: ags

if (gInventory.Visible=true)
{
     *disable mouse right-clicks code here*
}


I tried this without any luck:

Code: ags

if (gInventory.Visible=true)
{
       if (mouse.IsButtonDown(eMouseRight))
      {
        //do nothing, please, for God's sake, do nothing
      }
}


Whats up with this?
--All that is necessary for evil to triumph is for good men to do nothing.

Gilbert

I haven't read much of the codes, but try this instead:
Code: ags

if (gInventory.Visible=true)
{
       if (mouse.IsButtonDown(eMouseRight))
      {
        //do nothing, please, for God's sake, do nothing
      } else {
     //Put everything that's supposed to be done when the LMB is  clicked here
   }
}


monkey0506

There's two reasons that simply putting the empty braces in the on_mouse_click function for eMouseRight won't completely disable the right mouse button.

1) GUI and GUIControl event handlers are separate and individual functions from on_mouse_click.

This means that no matter what you do in on_mouse_click, if the user is clicking on a GUI or GUIControl (Button, ListBox, etc.) that on_mouse_click isn't getting called. The event handler is. Unless of course that particular object has its Clickable property set to false. But then it would fall through to whatever's behind it. So from the control it would fall through to the GUI. From the GUI it would finally fall through to the rest of the screen in which case on_mouse_click would get called.

2) Inventory item clicks are considered as separate mouse buttons from "normal" mouse clicks.

When you left-click on an inventory item on_mouse_click does not get called for eMouseLeft. It gets called for eMouseLeftInv. The right mouse button of course uses eMouseRightInv.




The way around this isn't that hard. For #1 it could involve a lot of code duplication if you're using different handlers for each control/GUI (which is the default behavior, and thereby is actually to be expected).

Code: ags
function btnMyButton_Click(GUIControl *control, MouseButton button) {
  if (button == eMouseRight) return; // we clicked on a button so there's no need to check for inventory here
  // blah
}


As for #2 you just need to make sure you also check eMouseRightInv:

Code: ags
  else if ((button == eMouseRight) || (button == eMouseRightInv)) {
  }

Knox

Hi,

Thanks for your posts...and for explaining things to me, it helps to understand!

Ok, well I tried option 2, but placed a display text to be sure (to debug):

Code: ags

  else if (button == eMouseRight)
  {
    mouse.SelectNextMode();
  }
  else if (button == eMouseRightInv)
  {
   Display("Right-Click in Inventory");
  }


So basically, according to this script, everytime I right-click in my inventory, I should see that text displayed...however, sadly, I dont see that text pop up at all.

Here is what I have as script when I click on my Inventory Icon in my IconBar (Im using GUIAnimation/Tween) :

Code: ags

function ShowInventory()
{
  invCustomInv.TopItem = 0;
  
  gInventory.Transparency = 100;
  gInventory.StopAllTweens();
  gInventory.TweenTransparency(0.1, 0, eEaseInTween);
  
  mouse.Mode = eModeInteract;
  mouse.UseModeGraphic(eModePointer); 

}


When I right-click on an empty space in my Inventory (set to Clickable), I dont get that diplay message I placed in my on_mouse_click.

As for the Option 1...that works, only problem is the button still displays its pressed-down graphic even though the right-click now calls nothing.
--All that is necessary for evil to triumph is for good men to do nothing.

Khris

Like monkey said, on_mouse_click gets called with Left/RightClickInv only if the mouse is above an InventoryItem. Not if it's over an empty portion of the inv window, let alone another part of the GUI.

Knox

Hey Khris,

Ok, well even if I right-click on an item in the inventory, I still dont get that display message...so its like it doesnt read eMouseRightInv at all.

To debug, I removed everything from the item in the inventory that could interfere...its just the default ikey item with standard settings (no events, nothing...I just wanted to test if I right-click on it if it would display this message:
Code: ags

else if (button == eMouseRightInv)
  {
   Display("Right-Click in Inventory");
  }


So the mouse is above an InventoryItem, and on_mouse_click is set to display a message when eMouseRightInv is pressed...but I get no message.
--All that is necessary for evil to triumph is for good men to do nothing.

monkey0506

#6
I forgot to mention that "Handle inventory clicks in script" must be set to true in the General Settings pane for eMouseLeftInv/eMouseRightInv to be called. Otherwise on_mouse_click isn't called and it's handled internally.

Quote from: general_knox on Wed 23/09/2009 18:14:44As for the Option 1...that works, only problem is the button still displays its pressed-down graphic even though the right-click now calls nothing.

Try this:

Code: ags
// top of global script
Button *lastButton; // last button mouse was over
int lastButtonGraphic = -1; // pushed graphic of last button

// on_mouse_click
  else if (button == eMouseRight) { // right mouse click
    GUIControl *gcat = GUIControl.GetAtScreen(mouse.x, mouse.y);
    if ((gcat == null) || (gcat.AsButton == null)) return; // if no button
    if ((lastButton != null) && (lastButtonGraphic != -1)) { // if the last button wasn't released yet
      lastButton.PushedGraphic = lastButtonGraphic; // restore the last button's pushed graphic
    }
    lastButton = gcat.AsButton; // store this button
    lastButtonGraphic = lastButton.PushedGraphic; // store this button's pushed graphic
    lastButton.PushedGraphic = lastButton.MouseOverGraphic; // use this button's mouse-over graphic
  }

// rep_ex_always
  if ((lastButton != null) && (lastButtonGraphic != -1) && (!mouse.IsButtonDown(eMouseRight))) {
    // right mouse released, last button still stored
    lastButton.PushedGraphic = lastButtonGraphic; // restore the pushed graphic
    lastButtonGraphic = -1; // clear our variables
    lastButton = null;
    return;
  }
  // otherwise, check if the player moved over a different button
  GUIControl *gcat = GUIControl.GetAtScreen(mouse.x, mouse.y);
  // no button, the right mouse isn't held, or the same button
  if ((gcat == null) || (gcat.AsButton == null) || (!mouse.IsButtonDown(eMouseRight)) ||
    ((lastButton != null) && (gcat.AsButton == lastButton))) return;
  // otherwise, we've got a different button, update THAT button as the last
  if ((lastButton != null) && (lastButtonGraphic != -1)) { // if the previous 'last' button wasn't restored yet
    lastButton.PushedGraphic = lastButtonGraphic; // restore the last button
  }
  lastButton = gcat.AsButton; // store the new last button
  lastButtonGraphic = lastButton.PushedGraphic;
  lastButton.PushedGraphic = lastButton.MouseOverGraphic;


I didn't test it, and I claim no responsibility for any consequence whatsoever which may occur as a result (whether direct, indirect, or otherwise) as a result of using this code!!! :P

Knox

Hey Monkey!

Thanks for the tip on handling inventory clicks being set to true...mine was set to false.

Here is what I did and everything works fine! (Its not complete, but I now understand the basics so I can continue on my way):

Code: ags

  else if (button == eMouseLeftInv)
  { 
    if ((mouse.Mode==eModeInteract) && (mouse.UseModeGraphic(eModePointer))) 
    { 
        player.ActiveInventory = inventory[ game.inv_activated ];
    }
    else 
    { 
         inventory[ game.inv_activated ].RunInteraction( mouse.Mode );
    }
  }


Im going to try out the "option 1" solution right now, Ill keep you posted.

:)
--All that is necessary for evil to triumph is for good men to do nothing.

monkey0506

Mouse.UseModeGraphic doesn't have a return type defined, so you probably shouldn't be using it as part of your condition. Although you said it's working, it's not strictly speaking correct.

Other than that it looks good on your inventory script.

Knox

hey Monkey!

I removed the useModeGraphic and it still works! Better that way...I want it to be "correct"! :)

...btw, you're a great help to me, I want you to know I really appreciate your explanations pal



Ive got another one fer yah: ;D

Now Ive got all my custom cursors set up properly...in my iconbar for the inventory, when I click on the icons, I get the right icon graphic for that cursor mode. I have trouble however getting items to work with those cursors. For example, Ive got a watch called iWatch. When I had the default cursors, I used the look mode, no prob...when you click on the watch, it displays this text:

Code: ags

function iWatch_Look()
{ 
   DisplayAt(284, 140, 600, "Its your watch .");  
}


However, now I use a custom mode only for inventory items..."eModeExamine":

Code: ags

function btnInvExamine_OnClick(GUIControl *control, MouseButton button)
{
  if (button == eMouseRight) 
  {
    return;
  }
  else
  {   
    mouse.Mode = eModeExamine;
    mouse.UseModeGraphic(eModeExamine);
  }
}


When I go into Events for iWatch, I have "interact, Look, Other, Question, Use"...how can I "add" a new event into this item, so I would have "Examine"...?

Ive looked in the manual for adding events in the inventory items properties without luck.

???
--All that is necessary for evil to triumph is for good men to do nothing.

Khris

I guess you have to use the Other click event, then check for the mouse.Mode.

Knox

You guessed right...So I did this and each click (depending on what mode cursor Im in) displays the right message:

Code: ags

function iWatch_OtherClick()
{
  if (mouse.Mode==eModeSelectInv)
  {
    Display("Select Inventory Mode");
  }  
  else if(mouse.Mode==eModeExamine)
  {
     Display("Examine Inventory Mode"); 
  }
  else if (mouse.Mode==eModeManipInv)
  {
    Display("Manipulate Inventory Item Mode");    
  }
  else if (mouse.Mode==eModeUseItemOn)
  {
    Display("Use Item On Mode");    
  }  
  else if (mouse.Mode==eModeDiscard)
  {
    Display("Discard Inventory Item Mode");    
  }   
}


Now all I have to do is check the manual how to simulate eModeUseInv and eModeInteract (I dont want to use those cause I disabled those modes so I wont scroll through them with my rightmouse click).

Thanks Khris... :-*
--All that is necessary for evil to triumph is for good men to do nothing.

SMF spam blocked by CleanTalk