Custom Inventory GUI

Started by Darth Mandarb, Tue 13/01/2004 04:26:23

Previous topic - Next topic

Darth Mandarb

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!!

Timosity

#1
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/

Dorcan

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

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

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

#5
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[

Scorpiorus

#6
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;
  }
}

Darth Mandarb

#7
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!!

Darth Mandarb

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. :(

Dorcan

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

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!!

Dorcan

#11
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 ;)

Darth Mandarb

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

I have some questions in regard to the lines like:

Code: ags
   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: ags
   if (button == 3) { // The LOOK button
     SetCursorMode(1);
     GUIOff(7);
     GUIOff(8);
     }

Scorpiorus

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.

Mr. Mozzarella

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

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.

storycatchermike

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%)

strazer

Manual: Tutorial -> Setting up the game -> Inventory -> 3rd to last paragraph.
(INVSHR) should do the trick.

storycatchermike

Quote from: strazer on Mon 18/04/2005 04:21:04
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%)

SMF spam blocked by CleanTalk