Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: edmundito on Sun 08/05/2005 01:32:42

Title: Custom inventory trick? (SOLVED)
Post by: edmundito on Sun 08/05/2005 01:32:42
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:

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.
Title: Re: Custom inventory trick?
Post by: Rui 'Trovatore' Pires on Sun 08/05/2005 01:41:59
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.
Title: Re: Custom inventory trick?
Post by: Ashen on Sun 08/05/2005 13:10:13
What I think Rui means is:

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.)
Title: Re: Custom inventory trick?
Post by: edmundito on Sun 08/05/2005 17:04:19
Hey, that worked! Now, why is it it that I can't click on inventory items yet?
Title: Re: Custom inventory trick?
Post by: strazer on Sun 08/05/2005 19:23:19
If you want the default right mouse click action to be possible from everywhere, you could do:


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:


  //...

  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.
Title: Re: Custom inventory trick?
Post by: edmundito on Sun 08/05/2005 19:37:15
well, it works just fine, but my question is why is left clicking not working when I left click on an inventory item?
Title: Re: Custom inventory trick?
Post by: strazer on Sun 08/05/2005 19:41:47
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:


//...

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

//...
Title: Re: Custom inventory trick?
Post by: on Sun 08/05/2005 19:57:19
Quote from: netmonkey's first postI have:


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
Title: Re: Custom inventory trick?
Post by: strazer on Sun 08/05/2005 20:22:13
Nope, the struct is named Mouse, but its instance is indeed called mouse.

Edit:

Hm, both seem to work. I'm confused now.
Title: Re: Custom inventory trick?
Post by: Rui 'Trovatore' Pires on Sun 08/05/2005 20:55:22
Just wanted to point out that reply #4, Strazer's, is exactly what I meant.
Title: Re: Custom inventory trick?
Post by: edmundito on Sun 08/05/2005 21:42:30
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) {
  //...
}
Title: Re: Custom inventory trick? (SOLVED)
Post by: Pumaman on Mon 09/05/2005 18:56:36
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