Exemple #1
0
 private void checkSlotName(string name)
 {
     if (!SlotNames.Contains(name))
     {
         throw new ArgumentException(string.Format("Invalid slot name '{0}'", name), "name");
     }
 }
Exemple #2
0
            /// <summary>
            ///     Creates a grid container filled with slot buttons loaded from an inventory template
            /// </summary>
            public void CreateInventory(Inventory inventory)
            {
                Columns = inventory.Columns;

                IndexedSlots = new List <Slots>(inventory.SlotMasks);

                foreach (var slot in IndexedSlots)
                {
                    var newButton = new InventoryButton(slot);

                    if (slot == Slots.NONE)
                    {
                        //TODO: Re-enable when godot grid container maintains grid with invisible elements
                        //newbutton.Visible = false;
                    }
                    else
                    {
                        // Store slot button and give it the default onpress behavior for empty elements
                        newButton.GetChild <Button>("Button").OnPressed += AddToInventory;
                        InventorySlots.Add(slot, newButton);
                    }

                    if (SlotNames.ContainsKey(slot))
                    {
                        var button = newButton.GetChild <Button>("Button");
                        button.Text = button.ToolTip = SlotNames[slot];
                    }

                    AddChild(newButton);
                }
            }
Exemple #3
0
            /// <summary>
            /// Creates a grid container filled with slot buttons loaded from an inventory template
            /// </summary>
            /// <param name="TemplateName"></param>
            public void CreateInventory(string TemplateName)
            {
                Type      type      = AppDomain.CurrentDomain.GetAssemblyByName("Content.Shared").GetType("Content.Shared.GameObjects." + TemplateName);
                Inventory inventory = (Inventory)Activator.CreateInstance(type);

                elements_x = inventory.Columns;

                GridContainer         = (GridContainer)Contents.GetChild("PanelContainer").GetChild("CenterContainer").GetChild("GridContainer");
                GridContainer.Columns = elements_x;
                IndexedSlots          = new List <Slots>(inventory.SlotMasks);

                foreach (Slots slot in IndexedSlots)
                {
                    InventoryButton newbutton = new InventoryButton(slot);

                    if (slot == Slots.NONE)
                    {
                        //TODO: Re-enable when godot grid container maintains grid with invisible elements
                        //newbutton.Visible = false;
                    }
                    else
                    {
                        //Store slot button and give it the default onpress behavior for empty elements
                        newbutton.GetChild <Button>("Button").OnPressed += AddToInventory;
                        InventorySlots.Add(slot, newbutton);
                    }

                    if (SlotNames.ContainsKey(slot))
                    {
                        newbutton.GetChild <Button>("Button").Text = SlotNames[slot];
                    }

                    GridContainer.AddChild(newbutton);
                }
            }