Empeld
Empeld plugin documentation.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events
essentials.action.ItemFramework.Interactive.UI.InventoryHotbar Class Reference

A UI to display a hotbar at the bottom of the screen More...

Static Public Member Functions

static InventoryHotbar BindTo (IInventory inventory)
 
static InventoryHotbar BindTo (ISelectableInventory inventory, bool bindKeys=true)
 
static IBoundInput CreateInputBinding (ISelectableInventory inventory)
 

Protected Member Functions

 InventoryHotbar (int width)
 

Protected Attributes

IBuiScreen Screen
 
IResourceResolver ResourceResolver
 

Properties

bool Visible [get, set]
 

Detailed Description

A UI to display a hotbar at the bottom of the screen

Constructor & Destructor Documentation

essentials.action.ItemFramework.Interactive.UI.InventoryHotbar.InventoryHotbar ( int  width)
protected
31  {
32  this.InjectDependencies();
33  _ui = this.Screen.AddControl(this.ResourceResolver.Resolve("items/ui/hotbar.xml"));
34  _ui.Invoke("SetDimensions", width, 1);
35  }
void Invoke(string name, params object[] args)
Invoke the specified method name with optional arguments
IResourceResolver ResourceResolver
Definition: InventoryHotbar.cs:20
string Resolve(string resource)
Resolves the data.
IBuiControl AddControl(string filename)
Add a control by filename
IBuiScreen Screen
Definition: InventoryHotbar.cs:17

Member Function Documentation

static InventoryHotbar essentials.action.ItemFramework.Interactive.UI.InventoryHotbar.BindTo ( IInventory  inventory)
static

Attribute: i

);

38  {
39  var hotbar = new InventoryHotbar(inventory.Capacity);
40  inventory.ItemChanged += (idx, item) => hotbar._ui.Invoke("SetItem", idx, item);
41 
42  //Setup
43  for (int i=0; i<inventory.Capacity; ++i)
44  {
45  hotbar._ui.Invoke("SetItem", i, inventory[i]);
46  }
47 
48  return hotbar;
49  }
int Capacity
Gets or sets the capacity.
Definition: IInventory.cs:26
InventoryHotbar(int width)
Definition: InventoryHotbar.cs:30
ItemEvent ItemChanged
Occurs when item changed in the inventory
Definition: IInventory.cs:15
static InventoryHotbar essentials.action.ItemFramework.Interactive.UI.InventoryHotbar.BindTo ( ISelectableInventory  inventory,
bool  bindKeys = true 
)
static
52  {
53  var hotbar = BindTo((IInventory)inventory);
54  inventory.SelectedIndexChanged += (idx, item) => {
55  hotbar._ui.Invoke("SetSelection", idx);
56  };
57 
58  if (bindKeys)
59  {
60  var input = CreateInputBinding(inventory);
61  input.Pinned = true;
62  input.StartListening();
63  }
64 
65  return hotbar;
66  }
ItemEvent SelectedIndexChanged
Occurs when selected index changed. Will not fire if item that the index is currently selected change...
Definition: ISelectableInventory.cs:18
static InventoryHotbar BindTo(IInventory inventory)
Definition: InventoryHotbar.cs:37
static IBoundInput CreateInputBinding(ISelectableInventory inventory)
Definition: InventoryHotbar.cs:68
Inventory class representation Implemented primarily by InventorySync
Definition: IInventory.cs:10
static IBoundInput essentials.action.ItemFramework.Interactive.UI.InventoryHotbar.CreateInputBinding ( ISelectableInventory  inventory)
static
69  {
70  var input = inventory.GetDependency<IInputManager>().GetBinding(typeof(InventoryHotbar));
71  input.Description = "Inventory hotbar";
72 
73  for (int i=0; i<Math.Min(10, inventory.Capacity); ++i)
74  {
75  int idx = MExt.mmod(i - 1, 10);
76  input.Bind("Select-" + i, Key.Number0 + i, () => inventory.SelectedIndex = idx);
77  }
78 
79  if (inventory.Capacity > 10)
80  {
81  input.Bind("Next", Key.Plus, () => inventory.SelectedIndex++);
82  input.Bind("Prev", Key.Minus, () => inventory.SelectedIndex--);
83  }
84 
85  return input;
86  }
int Capacity
Gets or sets the capacity.
Definition: IInventory.cs:26
Class that handles routing and key binds for all user input
Definition: IInputManager.cs:11
InventoryHotbar(int width)
Definition: InventoryHotbar.cs:30
Math extensions
Definition: MathExtensions.cs:7
int SelectedIndex
Gets the selected index
Definition: ISelectableInventory.cs:30
static int mmod(int i, int m)
Mod the way every other language does with negative numbers
Definition: MathExtensions.cs:35

Member Data Documentation

IResourceResolver essentials.action.ItemFramework.Interactive.UI.InventoryHotbar.ResourceResolver
protected

Attribute: Dependency

IBuiScreen essentials.action.ItemFramework.Interactive.UI.InventoryHotbar.Screen
protected

Attribute: Dependency

Property Documentation

bool essentials.action.ItemFramework.Interactive.UI.InventoryHotbar.Visible
getset

The documentation for this class was generated from the following file: