Custom inventory trick? (SOLVED)

Started by edmundito, Sun 08/05/2005 01:32:42

Previous topic - Next topic

edmundito

I have this inventory where there are no buttons. I want the user to right-click to select the cursor mode, Sierra style. I can get it to right click on the GUI itself and on top of a inventory item, but on top of the inventory box nothing happens! Can anyone offer a solution to this? (2.7 solution is fine).

While we're at it, when you handle custom inventory clicks in script, how do you set the cursor mode to active inventory? I have:

Code: ags
else if (button == eMouseLeftInv) {
  if(mouse.Mode == eModeInteract) player.ActiveInventory = inventory[game.inv_activated];
  else inventory[game.inv_activated].RunInteraction(mouse.Mode);
}


... on my on_mouse_click, but that's not doing the trick.

Rui 'Trovatore' Pires

Hmmm, I had that problem once... now what did CJ tell me to try?

...hmm, well, whatever it is it's a workaround. I think it might be using the GUI_MDOWN on_event function to capture the clicking. That was before 2.7, but if the new way doesn't cut it, give this a try. Put the on_event function before the mouse_click function and if GUI_MDOWN and {assorted checks to see if it's the right place} then on_mouse_click(eMouseButtonRight). Or something of the sort, of course, I'm going by memory here.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

Ashen

What I think Rui means is:
Code: ags

function on_event(EventType event, int data) {
  if (event == eEventGUIMouseDown) {
    if (data == gInventory.ID) {
      if (mouse.IsButtonDown(eMouseRight)) Mouse.SelectNextMode();
    }
  }
}

(adapted from 2.62, but tested in 2.7, so it SHOULD work.)
I know what you're thinking ... Don't think that.

edmundito

Hey, that worked! Now, why is it it that I can't click on inventory items yet?

strazer

If you want the default right mouse click action to be possible from everywhere, you could do:

Code: ags

function on_event(EventType event, int data) {
  //...

  if (event == eEventGUIMouseDown) {
      if (mouse.IsButtonDown(eMouseRight)) on_mouse_click(eMouseRight);
  }

  //...
}


The on_event function has to be located after the on_mouse_click function for this to work.
Then, in on_mouse_click, I have something like this:

Code: ags

  //...

  if (button == eMouseRight) {
    if (mouse.Mode != eModePointer) mouse.SelectNextMode();
  }

  //...


This way, to disable the right click, I just have to set the mouse mode to Pointer.

edmundito

well, it works just fine, but my question is why is left clicking not working when I left click on an inventory item?

strazer

#6
Oh, you mean you can't LEFT-click.
Do you have "Handle inventory clicks in scripts" activated in the General settings?
If so, you have to add a check for eMouseLeftInv in your on_mouse_click and handle inventory clicks yourself.

Edit:

For example:

Code: ags

//...

  if (button == eMouseLeftInv) {
    player.ActiveInventory = inventory[game.inv_activated]; // activate the clicked item
  }

//...

Ash-n

Quote from: netmonkey's first postI have:

Code: ags

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

... on my on_mouse_click, but that's not doing the trick.

The only thing I can see is, it should be Mouse.Mode - I'm not sure how case-sensitive it is about these things

strazer

#8
Nope, the struct is named Mouse, but its instance is indeed called mouse.

Edit:

Hm, both seem to work. I'm confused now.

Rui 'Trovatore' Pires

Just wanted to point out that reply #4, Strazer's, is exactly what I meant.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

edmundito

oh, I had it right, but the problem was with old code I added and forgot about:

else if (button == eMouseLeft || button == eMouseLeftInv ) {
  //...
}
else if (button == eMouseLeftInv) {
  //...
}

Pumaman

Quote from: strazer on Sun 08/05/2005 20:22:13
Nope, the struct is named Mouse, but its instance is indeed called mouse.

Hm, both seem to work. I'm confused now.

static functions can be called on instances too, so in this case Mouse and mouse will both work

SMF spam blocked by CleanTalk