Skip to content

YoYoGames/pfb-Inventory

Repository files navigation

Set Up

Full Setup

This will allow you to see how all of the UI Layers are laid out and make any changes that you wish to, such as adding/removing Inventory Slots, changing slot size, or changing the order in which they are filled.

  1. Add the following UI Layers to your project, so that they appear in this order within your UI Folder in rooms:
    • UI
    • Tooltip
    • Inventory
    • Templates
  2. Go to the first room in your project and open the Instance Creation Order.
    • Ensure that oInventory is above/before any oSlot objects.
  3. Add some oItem objects to your room

Minimal Setup

This is the minimum you need to add from the Prefab to be able to use it. All of the required UI Layers and their content (sprites, text, and objects) will be added as a result and you will be able to use the Inventory with the default size and layout.

  1. Add the following Object to your project
    • oInventory
  2. Add some oItem objects to your room

Usage

  • Left Click the bag icon to open the inventory
  • Left Click an oItem instance in the room to add it to the inventory
  • Left Click and Release on an item in the inventory to use it (default no action, override on oInventory)
  • Left Click and Drag to move an item in the inventory to another slot
  • Right Click and Drag to pick up a single item (from a stack or the singular item from a slot)
    • Release over a slot containing other copies of the same stackable item to add it to the stack
    • Release over an empty slot to place that single item in that slot
    • Release over a slot containing a different item to swap the entire stack with the other item (same as Left Click and dragging over an occupied slot)
  • Left Click and Drag out of the inventory to put the item back in the room
  • Hover over an item to display a tooltip for the item

Extending

You can expand on the inventory in multiple ways to fit it into your game and make it your own.

Overrides

oInventory

  • Number of slots - How many slots the Inventory has, default is 6.
  • Show Tooltips - Display the tooltip when a slot is hovered over.
  • Use Item - What happens when you click on/use an item.
  • Remove Item - What happens when you remove an item from the inventory.
  • Build Tooltip - Dynamically populates the tooltip when hovered.

oItem

  • Name - The name of the item
  • Sprite - The sprite to use for the item
  • Strength - Stat 1
  • Agility - Stat 2
  • Intellect - Stat 3
  • Stamina - Stat 4

Layout

The inventory is constructed primarily from UI Layers. You can customise the majority of visual aspects of the inventory without modifying the code but there are some elements that may not function without some code customisation.

  • UI - This layer holds the Inventory object and is what you interact with to open/close the inventory.
    • This can be positioned anywhere that you wish.
    • Defaults to the bottom right of the screen.
  • Inventory - This layer contains the slots that the inventory has in it.
    • Contains a frame and an array of slots
    • Slots are filled from the bottom right
    • Making the frame wider will increase the number of slot columns
  • Tooltip - This is the tooltip that will be displayed when a slot is hovered over.
    • Contains a frame, item name, and an array of stats
    • Frame size is automatically adjusted based on length of item name/stats.
    • Stats array is filled based of the function specified in oInventory
  • Templates - This contains a variety of template flexpanels that are used to dynamically build some elements of the UI, we do this so that you don't need to customise these multiple times.
    • Slot - the layout to use for slots in the inventory
    • ItemStat - the layout used for stats in the tooltip

Making your own items

In order to ensure that any object you want to add to the Inventory as an item will show information in the Inventory tooltip, can be returned to the room, and can also be used from the Inventory there is a minimum amount of information that your Item would need to have.

Tooltip Values

In order to display information in the tooltip, you can choose to have values for any of the following:

  • name - The text that will be shown at the top of the tooltip
  • description - The text that will be shown in the tooltip below the name

The tooltip will also display any stats that you pass, this is covered below.

Making an 'Item'

Within oInventory there is a constuctor for an Item, you can define an item and store it within your existing object by calling

new oInventory.Item(... passing the following values:

Value Default Value Description
name Name of this Item (used in Tooltip)
description "" Description of this Item (used in Tooltip)
sprite Sprite that should be shown in the Inventory Slot
stats undefined Numerical values that define the item and will be shown in the tooltip, you can have as many of as few as you would like
stack_size_max 1 The maximum number of this item that should be shown in a single Inventory Slot
stack_size 1 The number of this Item that should be added to the Inventory
use_function undefined The function that should be called when the item is clicked on in the Inventory
object oItem The object that should be spawned in the room if this Item is removed from the Inventory Slot, usually this would be the object that the item was created from
Example Usage (within your object)

Initialising values

name = "Hammer"
description = "Used for Hammering"

// Stats
statStruct = {
	Strength: irandom_range(-1,10),
	Agility: irandom_range(-1,10),
	Intellect: irandom_range(-1,10),
	Stamina: irandom_range(-1,10)
}

Creating an 'item' and adding it to the Inventory

var _item = new oInventory.Item(
	other.name,
	other.description,
	other.sprite_index,
	other.statStruct,
	2,
	1,
	UseItem,
	other.object_index);
// If we have successfully added the item to the inventory	
if(oInventory.AddItem(_item))
{
	// Destroy this instance
	instance_destroy();
}

About

Prefab collection for basic inventory system

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors