Jibble

Author Topic: Custom Inventory GUI  (Read 16425 times)

Darth Mandarb

  • Evil Sith Lord
  • Mittens Vassal
  • AGS Baker
    • Lifetime Achievement Award Winner
    • Darth Mandarb worked on one or more games that won an AGS Award!
    •  
    • Darth Mandarb worked on one or more games that was nominated for an AGS Award!
Custom Inventory GUI
« on: 13 Jan 2004, 04:26 »
I have scoured the AGS help file ...

I have searched the forums ...

I have read through countless tutorial pages ...

I have searched the knowledge base ...


I can't find anything about making Sierra style Custom Inventory GUIs!

And I thought, "There must be others, besides myself, who would find this information useful right?"

I am interested to know how AGS handles inventory and how to interact with it.  I can find little bits and pieces about this from various sources, but nothing that helps me piece it all together.

This is my inventory window.  The inventory will display, but can't be interacted (selected or ?) with.

So here's my question(s) about Inventory:
- How does AGS handle inventory items? (meaning how do I refer to inventory while scripting)
- How do you script interactions with the displayed items?
- How do you make scrolling?

I thought it would be a good idea for others, if they have Inventory questions, to add them to this thread and we can build a vault of helpful information about making Custom Inventory GUIs!

So ... I humbly call upon the Gods of AGS scripting to throw down some lightning bolts of Inventory wisdom upon this thread :)




Disclaimer :: If I missed something obvious (threads,
Help file info, FAQ, or anything) please slap me with
a moist trout!  I really did a thorough search ... I swear!!

Re:Custom Inventory GUI
« Reply #1 on: 13 Jan 2004, 07:11 »
The one I made for my game is a fairly simple one where I'm able to have any interactions with items and scroll up and down.

This is the script for the inventory:

where
gui/interface 0 is the inventory gui
object 0 is the inventory window
button 1 = look
button 2 = use
button 3 = ok
button 4 = up arrow
button 5 = down arrow
-----------------------------------------------------

if (interface == 0) {

if (button == 1) SetCursorMode (1);
if (button == 2) SetCursorMode (2);

if (button == 3) {
GUIOff(0);
GUIOn(1); //this just turns back on my top menu
SetDefaultCursor();
}

if (button == 4) {
if (game.top_inv_item > 0) game.top_inv_item = game.top_inv_item-game.items_per_line;
}

if (button == 5) {
if (game.top_inv_item < game.num_inv_items-game.num_inv_displayed)
game.top_inv_item = game.top_inv_item+game.items_per_line;
}
}
---------------------------------------------------------------------------------
This is the gui in the editor:


This is the gui with items that are scrollable, it only is possible to scroll when you have more items than fit in the window


you can also set the inventory dimensions with

SetInvDimensions(30,40);

in the global game start


I'm not sure if this will help for what you want but it's a simple gui that works perfectly.

But I recommend RickJ's Blue Gui which you can find in here somewhere http://www.gaia-spa.com/blusoft/

Re:Custom Inventory GUI
« Reply #2 on: 13 Jan 2004, 09:02 »
Timosity's explanations are good, but in this case the "use" button is for selecting the object, so if someday you'll need the "interact button" in your inventory, you can find my tutorial here

http://www.digitalmindstudio.ch/script.php?id=4&langue=en

Darth Mandarb

  • Evil Sith Lord
  • Mittens Vassal
  • AGS Baker
    • Lifetime Achievement Award Winner
    • Darth Mandarb worked on one or more games that won an AGS Award!
    •  
    • Darth Mandarb worked on one or more games that was nominated for an AGS Award!
Re:Custom Inventory GUI
« Reply #3 on: 13 Jan 2004, 16:27 »
Timosity - Thanks!  You got me started in the understanding process!

Dorcan - That site just rocks!!  It's the best tutorials site I've seen yet!  Awesome!

If anybody else has questions and/or wisdom to share please do so!  

Thanks guys!

])]V[

Pet Terry

  • Mittens Vassal
  • Sunshine.
    • I can help with making music
    • Pet Terry worked on one or more games that won an AGS Award!
    •  
    • Pet Terry worked on one or more games that was nominated for an AGS Award!
Re:Custom Inventory GUI
« Reply #4 on: 13 Jan 2004, 18:03 »
I've done inventory in which you have only one mouse cursor mode to use and you either left click, right click or double left click items to select, interact or examine them. It's bit more complex to do (couldn't script it without help :P ) but I may post it here someday, if I remember.

At the moment only thing it needs are those arrows you use to scroll it, but I think I now know how they work...
<SSH> heavy pettering
Screen 7

Darth Mandarb

  • Evil Sith Lord
  • Mittens Vassal
  • AGS Baker
    • Lifetime Achievement Award Winner
    • Darth Mandarb worked on one or more games that won an AGS Award!
    •  
    • Darth Mandarb worked on one or more games that was nominated for an AGS Award!
Re:Custom Inventory GUI
« Reply #5 on: 14 Jan 2004, 23:11 »
I am now bald.

Because I've pulled all my hair out trying to get this to work.

Here's my script:


// The Inventory GUI
{
if (interface == 4)
   if (button==0) { // Close Button
   GUIOff(4);
   SetDefaultCursor();
   } else
   if (button==1) { // Use Button
   SetCursorMode(3);
   SetMouseCursor(2);
   } else
   if (button==2) { // Select Button
   SetCursorMode(2);
   SetMouseCursor(6);
   } else
   if (button==5) { // UP arrow
    if (game.top_inv_item>0)
    game.top_inv_item=game.top_inv_item-game.items_per_line;
   } else
   if (button==6) { // DOWN arrow
    if (game.top_inv_item < game.num_inv_items-game.num_inv_displayed)
     game.top_inv_item=game.top_inv_item+game.items_per_line;
   }
}
// END INVENTORY GUI

** I have also added the SetInvDimensions in the game_start script. **

PROBLEMS:
I still can't actually select the inventory, even though I can see them.

What am I doing wrong?

])]V[
« Last Edit: 14 Jan 2004, 23:13 by Darth Mandarb »

Scorpiorus

  • 100101101010b
    • Scorpiorus worked on one or more games that won an AGS Award!
    •  
    • Scorpiorus worked on one or more games that was nominated for an AGS Award!
Re:Custom Inventory GUI
« Reply #6 on: 14 Jan 2004, 23:38 »
See haven't you handle inventory click in script option ticked somehow.

If not, you should be able to select an item in MODE_USE (#2) mode. Place a Display() function inside:
...
if (button==2) { // Select Button
   Display("MODE_USE");
   SetCursorMode(2);
   SetMouseCursor(6);
} else
...
to check if the mode is set at all.

Another thing is that SetInvDimensions() affects items clickable area. What if you temporarily remove it (adjust the values)?


EDIT: maybe its a copy/paste issue but the script should be:

if (interface == 4) {
   if (button==0) { // Close Button
   GUIOff(4);
   SetDefaultCursor();
   } else
   if (button==1) { // Use Button
   SetCursorMode(3);
   SetMouseCursor(2);
   } else
   if (button==2) { // Select Button
   SetCursorMode(2);
   SetMouseCursor(6);
   } else
   if (button==5) { // UP arrow
    if (game.top_inv_item>0)
    game.top_inv_item=game.top_inv_item-game.items_per_line;
   } else
   if (button==6) { // DOWN arrow
    if (game.top_inv_item < game.num_inv_items-game.num_inv_displayed)
    game.top_inv_item=game.top_inv_item+game.items_per_line;
   }
}
« Last Edit: 14 Jan 2004, 23:41 by Scorpiorus »

Darth Mandarb

  • Evil Sith Lord
  • Mittens Vassal
  • AGS Baker
    • Lifetime Achievement Award Winner
    • Darth Mandarb worked on one or more games that won an AGS Award!
    •  
    • Darth Mandarb worked on one or more games that was nominated for an AGS Award!
Re:Custom Inventory GUI
« Reply #7 on: 15 Jan 2004, 00:27 »
Scorpiorus you have saved my sanity (and my hair is growing back).

I had, for some reason, ticked the Handle inventory click in script ... not sure why.

But it's working now!

1,000,000 thanks!!
« Last Edit: 15 Jan 2004, 04:48 by Darth Mandarb »

Darth Mandarb

  • Evil Sith Lord
  • Mittens Vassal
  • AGS Baker
    • Lifetime Achievement Award Winner
    • Darth Mandarb worked on one or more games that won an AGS Award!
    •  
    • Darth Mandarb worked on one or more games that was nominated for an AGS Award!
Inventory GUI ** NEW PROBLEM **
« Reply #8 on: 22 Jan 2004, 22:08 »
I've made some changes in my game and now my inventory GUI isn't functioning properly.

Here's what I changed:
- New main GUI which is popped-up by the mouse.x location.
(If the mouse.x < 5 the gui pops up.  Then if the mouse.x > 80 (the width of the GUI) and the GUI is on, it shuts the gui off and changes the cursor back.)
- I have removed 'Talk' from the 'Standard Cursors'.

Okay ...  here's my INVENTORY GUI script:
[color=000055]
// The Inventory GUI
if (interface == 4)
{
  if (button == 0) { // Close Button
   GUIOff(4) & SetDefaultCursor();
   } else
  if (button == 1) { // USE
   SetCursorMode(3);
   SetMouseCursor(6);
   } else
  if (button == 3) { // SELECT
   SetCursorMode(2);
   SetMouseCursor(6);
   } else
  if (button == 4) { // DETAILS
   SetCursorMode(1);
   SetMouseCursor(6);
   } else
  if (button == 5) { // UP arrow
    if (game.top_inv_item>0)
    game.top_inv_item=game.top_inv_item-game.items_per_line;
   } else
  if (button == 6) { // DOWN arrow
    if (game.top_inv_item < game.num_inv_items-game.num_inv_displayed)
     game.top_inv_item=game.top_inv_item+game.items_per_line;
   }
  }
// END INVENTORY GUI
[/color]
Problems
- When I click the up arrow it changes the cursor mode to 5 (Take).  The arrow functions (scrolls), but the cursor changes and I can't figure out why.
- Button 3, it changes to CursorMode(1) (look) and not mode 2 (and doesn't use the SetMouseCursor)
- Button 4, it changes to CursorMode(2) (interact) and not mode 1 (and doesn't use the SetMouseCursor)

I thought that by taking out a Standard Cursor that these were somehow -1 each or so.  So I tried adding 1, subtracting 1, and just switching them around.  All to no avail.

Any why on earth would the up arrow change to 'Talk' ...

I'm clueless. :(

Re:Custom Inventory GUI
« Reply #9 on: 22 Jan 2004, 23:48 »
Hum :
GUIOff(4) & SetDefaultCursor();
should be
GUIOff(4);
SetDefaultCursor();

no ?

I don't see any other errors... Maybe you could export your gui and let us download it, it would be easier to find a solution

Darth Mandarb

  • Evil Sith Lord
  • Mittens Vassal
  • AGS Baker
    • Lifetime Achievement Award Winner
    • Darth Mandarb worked on one or more games that won an AGS Award!
    •  
    • Darth Mandarb worked on one or more games that was nominated for an AGS Award!
Re:Custom Inventory GUI
« Reply #10 on: 23 Jan 2004, 02:17 »
Here is the uploaded file:
GUIProblem ZIP (~1.2MB)
(that was as small as I could make it!)

Here's the GUI:


Here's the problem:
Use Item - this button functions as it should
Select Item - this button is currently set to 'Set Cursor Mode' and does what it should, but I want it to 'Run Script' and do what is in the GUI script.
Item Details - same as above ...
Up Arrow - does what it should, but the cursor for some reason becomes the 'Take' cursor.  (and I checked ... it's actually setting that cursor mode, not just the cursor graphic)
Down Arrow - functions as it should.
Close - Does what it should.

NOTE : This build is just the ground floor and if you try to go up or down or out (upstairs, basement, or garage) it'll crash out on you!  

I wasn't sure how to export just the GUI, so this is everything (but I deleted all but 1 of the rooms!).

Thanks for any help you can give fellas!!

Re:Custom Inventory GUI
« Reply #11 on: 23 Jan 2004, 03:55 »
Yep, here's  the problem :

if (interface == 8)
{
   if (button == 2) // The WALK button
     SetCursorMode(0) & GUIOff(7) & GUIOff(8);}{
   if (button == 3) // The LOOK button
     SetCursorMode(1) & GUIOff(7) & GUIOff(8);
   if (button == 4) // The INTERACT button
     SetCursorMode(2) & GUIOff(7) & GUIOff(8);
   if (button == 5) // The TAKE button
     SetCursorMode(5) & GUIOff(7) & GUIOff(8);
   if (button == 6) // The POCKETS button
     GUIOff(7) & GUIOff(8) & GUIOn(4);
   if (button == 7) // The SAVE button
     GUIOff(7) & GUIOff(8) & SetDefaultCursor();
   if (button == 8) // The LOAD button
     GUIOff(7) & GUIOff(8) & SetDefaultCursor();
   if (button == 9) // The QUIT button
     GUIOff(7) & GUIOff(8) & GUIOn(0) & SetMouseCursor(6);
   if (button == 10) // The ABOUT button
     GUIOff(7) & GUIOff(8) & SetDefaultCursor();

   }
// END OF MAIN GUI
}

As you can guess, the code in blue is executed everytime a gui button is clicked, even if it isn't on the interface 8...
So just remove the red brackets and the problem will be resolved.

If I can suggest you something, don't add unuseful brackets hehe  :P

Btw, really cool effect when walls fade in or out ;)
« Last Edit: 23 Jan 2004, 03:59 by Dorcan »

Darth Mandarb

  • Evil Sith Lord
  • Mittens Vassal
  • AGS Baker
    • Lifetime Achievement Award Winner
    • Darth Mandarb worked on one or more games that won an AGS Award!
    •  
    • Darth Mandarb worked on one or more games that was nominated for an AGS Award!
Re:Custom Inventory GUI
« Reply #12 on: 23 Jan 2004, 05:18 »
That did the trick!

Thank you so much!

You have just earned a spot in the credits ;)

])]V[

PS
If you think the fading in the groundfloor is cool, wait till you see the upstairs!! ;)

monkey0506

  • SEND PIZZA.
    • Best Innovation Award Winner 2017, for his work to help AGS games reach the widest possible audience - through popular distribution platforms (Steam, Galaxy) as well as other operating systems (Android, Linux)
    • monkey0506 worked on one or more games that won an AGS Award!
    •  
    • monkey0506 worked on one or more games that was nominated for an AGS Award!
Re: Custom Inventory GUI
« Reply #13 on: 04 Mar 2005, 16:49 »
I have some questions in regard to the lines like:

Code: [Select]
   if (button == 3) // The LOOK button
     SetCursorMode(1) & GUIOff(7) & GUIOff(8);

Is the use of the '&' operator legal here?  If so, has it always been like this, or is it just like that in 2.7?  In any case, is this considered good scripting, or would it be better and/or easier to read if brackets had been used, i.e.:

Code: [Select]
   if (button == 3) { // The LOOK button
     SetCursorMode(1);
     GUIOff(7);
     GUIOff(8);
     }

Scorpiorus

  • 100101101010b
    • Scorpiorus worked on one or more games that won an AGS Award!
    •  
    • Scorpiorus worked on one or more games that was nominated for an AGS Award!
Re: Custom Inventory GUI
« Reply #14 on: 05 Mar 2005, 19:03 »
Yes, it would work and it worked in all versions. But as a general rule it is better to use braces as you pointed out.

Re: Custom Inventory GUI
« Reply #15 on: 05 Mar 2005, 20:40 »
Is it possible to change the space between two inventory objects? My sprites are about 30x30 but the space between them is almost the double size. Due to that I only get 3 or 4 objects in a row and that doesn't look very good.
Night of Fire - Thread

I control, I am in charge of
Everyones future, red button is mine

Scorpiorus

  • 100101101010b
    • Scorpiorus worked on one or more games that won an AGS Award!
    •  
    • Scorpiorus worked on one or more games that was nominated for an AGS Award!
Re: Custom Inventory GUI
« Reply #16 on: 05 Mar 2005, 21:46 »
Yes, take a look at the SetInvDimensions function in the manual. Experiment passing less/greater values than the default ones: 40 x 22. The function changes item cell size, not the item sprite size so it should do the trick.

Re: Custom Inventory GUI
« Reply #17 on: 18 Apr 2005, 03:52 »
I have a problem. When I interact with an inventory item, it picks the item up, but the item doesn't appear in the box in the iconbar. What do I have to do to make it appear in the iconbar?
Story Catcher Mike (Founder of Knights Creations)
Upcoming AGS game by me: Sir Tilean and the Way of the Knight (Game Total = 5%)

Re: Custom Inventory GUI
« Reply #18 on: 18 Apr 2005, 04:21 »
Manual: Tutorial -> Setting up the game -> Inventory -> 3rd to last paragraph.
(INVSHR) should do the trick.

Re: Custom Inventory GUI
« Reply #19 on: 18 Apr 2005, 15:58 »
Manual: Tutorial -> Setting up the game -> Inventory -> 3rd to last paragraph.
(INVSHR) should do the trick.
Thanks, man, that helped. I guess I forgot to look in the manual for that. Thanks for the help.
Story Catcher Mike (Founder of Knights Creations)
Upcoming AGS game by me: Sir Tilean and the Way of the Knight (Game Total = 5%)