Script for the default inventory

Started by EnoRed, Wed 21/04/2010 16:29:23

Previous topic - Next topic

EnoRed

Could someone tell me where I can find the code for the default AGS inventory? I mean, after I enable "Handle inventory clicks in script", how do I script it so that it works exactly the same as the default inventory with this option disabled?

I know it sounds like a pretty pointless thing to ask, but I want to make some small modifications to it that I can't make while the inventory is essentially being dealt with automatically. Can anyone help me out?

Khris

You can handle clicks on inventory items by adding "else if (button = eMouseLeftInv) { ... }" to on_mouse_click in the global script. The other two are eMouseRightInv and eMouseMiddleInv, afaik.

Note that these only work over an actual Inv item; to catch clicks over the GUI itself, add an OnClick handler to the it.

EnoRed

Okay, I got that far, but I'm not sure what I put in the {...} after that in order to perform the following:

Left click: Select an item and use the item on other inventory items when selected.
Right click on item: Examine the item (I think this works automatically anyway, but still)
Right click with item already selected as current cursor: Deselect the item and return cursor to normal.

Could you explain the "OnClick handler" part a bit to me as well? There's a lot of stuff I can't really find (or at least don't know where to look for) in the AGS manual and wiki... Are there any other resources I could use that explain this sort of thing a bit more in depth?

Khris

Something like this should work:

Code: ags
// first line inside on_mouse_click()
  InventoryItem*i = inventory[game.inv_activated];  // store the inv item under mouse at time of click in Pointer i

  // handling clicks
  ...
  else if (button == eMouseLeftInv) {
    if (mouse.Mode == eModeInteract) player.ActiveInventory = i; // set inv under mouse as active
    else i.RunInteraction(mouse.Mode);  // usual behavior 
  }
  else if (button == eMouseRightInv) {
    if (mouse.Mode == eModeUseinv) player.ActiveInventory = null;   // loose active inv
    else i.RunInteraction(eModeLookat);  // look at inv under mouse
  }


About the handler: if you select the GUI itself in the editor and click the lightning bolt icon, you'll get a list of possible events, in this case, only "OnClick". Select it and hit the ellipses button.

Btw, later versions of AGS don't have a hard-coded default inventory GUI, it's a standard GUI included in the default template. So you should be able to make changes to it without having to recreate it first.

Dualnames

Quote from: EnoRed on Thu 22/04/2010 11:10:31
Could you explain the "OnClick handler" part a bit to me as well? There's a lot of stuff I can't really find (or at least don't know where to look for) in the AGS manual and wiki... Are there any other resources I could use that explain this sort of thing a bit more in depth?

I suggest searching the forums. I still do this, up to this day, when I'm having a scripting problem.

Code: ags

if ((button==eMouseLeftInv) && (player.ActiveInventory==null)) {
     mouse.Mode=eModeUseInv;
     player.ActiveInventory=InventoryItem.GetAtScreen(mouse.x,mouse.y);//perhaps replacing to game.inv_activated will work better, but not 100% sure on that.
}

if ((button==eMouseRightInv) && (player.ActiveInventory==null)) {
     InventoryItem*mouseover;
     mouseover=InventoryItem.GetAtScreen(mouse.x,mouse.y);
     mouseover.RunInteraction(eModeLookAt);
}

if ((button==eMouseRight) && (player.ActiveInventory!=null)) {
     player.ActiveInventory=null;
     mouse.Mode=eModeWalkTo;
}


EDIT: I didn't see Khris reply, so I suggest you stick into his.
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)

EnoRed

I tried DualNames's code, and it appears to work perfectly... Except right clicking doesn't work when clicking on the inventory window part (the bit that actually has the inventory items in it, not the surrounding border with the other inventory GUI buttons on it). Is it possible to change that at all? If not, it's no big deal since I've altered the inventory system so it'd be easy enough for the player to move their mouse cursor away from it and right click anyway.

Dualnames

Quote from: EnoRed on Sat 24/04/2010 00:02:23
I tried DualNames's code, and it appears to work perfectly... Except right clicking doesn't work when clicking on the inventory window part (the bit that actually has the inventory items in it, not the surrounding border with the other inventory GUI buttons on it). Is it possible to change that at all? If not, it's no big deal since I've altered the inventory system so it'd be easy enough for the player to move their mouse cursor away from it and right click anyway.


Code: ags

if ((button==eMouseLeftInv) && (player.ActiveInventory==null)) {
     mouse.Mode=eModeUseInv;
     player.ActiveInventory=InventoryItem.GetAtScreen(mouse.x,mouse.y);//perhaps replacing to game.inv_activated will work better, but not 100% sure on that.
}

if (button==eMouseRightInv)  {
if (player.ActiveInventory==null)){
     InventoryItem*mouseover;
     mouseover=InventoryItem.GetAtScreen(mouse.x,mouse.y);
     mouseover.RunInteraction(eModeLookAt);
}
if (player.ActiveInventory!=null)){
      player.ActiveInventory=null;
     mouse.Mode=eModeWalkTo;
}
}

if ((button==eMouseRight) && (player.ActiveInventory!=null)) {
     player.ActiveInventory=null;
     mouse.Mode=eModeWalkTo;
}


That should do it.
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)

SMF spam blocked by CleanTalk