示例#1
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);
                }
            }
            public HumanInventoryWindow(ILocalizationManager loc, IResourceCache resourceCache)
            {
                Title     = loc.GetString("Your Inventory");
                Resizable = false;

                var buttonDict = new Dictionary <Slots, InventoryButton>();

                Buttons = buttonDict;

                const int width  = ButtonSize * 4 + ButtonSeparation * 3 + RightSeparation;
                const int height = ButtonSize * 4 + ButtonSeparation * 3;

                var windowContents = new Control {
                    CustomMinimumSize = (width, height)
                };

                Contents.AddChild(windowContents);

                void AddButton(Slots slot, string textureName, Vector2 position)
                {
                    var texture        = resourceCache.GetTexture($"/Textures/UserInterface/Inventory/{textureName}.png");
                    var storageTexture = resourceCache.GetTexture("/Textures/UserInterface/Inventory/back.png");
                    var button         = new InventoryButton(slot, texture, storageTexture)
                    {
                        Position = position
                    };

                    windowContents.AddChild(button);
                    buttonDict.Add(slot, button);
                }

                const int size = ButtonSize;
                const int sep  = ButtonSeparation;
                const int rSep = RightSeparation;

                // Left column.
                AddButton(Slots.EYES, "glasses", (0, size + sep));
                AddButton(Slots.INNERCLOTHING, "uniform", (0, 2 * (size + sep)));
                AddButton(Slots.EXOSUITSLOT1, "suit_storage", (0, 3 * (size + sep)));

                // Middle column.
                AddButton(Slots.HEAD, "head", (size + sep, 0));
                AddButton(Slots.MASK, "mask", (size + sep, size + sep));
                AddButton(Slots.OUTERCLOTHING, "suit", (size + sep, 2 * (size + sep)));
                AddButton(Slots.SHOES, "shoes", (size + sep, 3 * (size + sep)));

                // Right column
                AddButton(Slots.EARS, "ears", (2 * (size + sep), 0));
                AddButton(Slots.IDCARD, "id", (2 * (size + sep), size + sep));
                AddButton(Slots.GLOVES, "gloves", (2 * (size + sep), 2 * (size + sep)));

                // Far right column.
                AddButton(Slots.BACKPACK, "back", (rSep + 3 * (size + sep), 0));
                AddButton(Slots.BELT, "belt", (rSep + 3 * (size + sep), size + sep));
                AddButton(Slots.POCKET1, "pocket", (rSep + 3 * (size + sep), 2 * (size + sep)));
                AddButton(Slots.POCKET2, "pocket", (rSep + 3 * (size + sep), 3 * (size + sep)));

                Size = CombinedMinimumSize;
            }
        }
示例#3
0
            /// <summary>
            /// Adds the item we have equipped to the slot texture and prepares the slot button for removal
            /// </summary>
            /// <param name="message"></param>
            public void AddToSlot(ServerInventoryMessage message)
            {
                InventoryButton button = InventorySlots[message.Inventoryslot];
                var             entity = IoCManager.Resolve <IEntityManager>().GetEntity(message.EntityUid);

                button.EntityUid = message.EntityUid;
                var container = button.GetChild("CenterContainer");

                button.GetChild <Button>("Button").OnPressed += RemoveFromInventory;
                button.GetChild <Button>("Button").OnPressed -= AddToInventory;

                //Gets entity sprite and assigns it to button texture
                if (entity.TryGetComponent(out IconComponent sprite))
                {
                    var tex = sprite.Icon.Default;

                    var rect = button.GetChild("CenterContainer").GetChild <TextureRect>("TextureRect");

                    if (tex != null)
                    {
                        rect.Texture = tex;
                        rect.Scale   = new Vector2(Math.Min(CalculateMinimumSize().X, 32) / tex.Height, Math.Min(CalculateMinimumSize().Y, 32) / tex.Height);
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
            }
示例#4
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);
                }
            }
示例#5
0
            /// <summary>
            /// Remove element from the UI and update its button to blank texture and prepare for insertion again
            /// </summary>
            /// <param name="message"></param>
            public void RemoveFromSlot(ServerInventoryMessage message)
            {
                InventoryButton button = InventorySlots[message.Inventoryslot];

                button.GetChild("CenterContainer").GetChild <TextureRect>("TextureRect").Texture = null;
                button.EntityUid = EntityUid.Invalid;
                button.GetChild <Button>("Button").OnPressed -= RemoveFromInventory;
                button.GetChild <Button>("Button").OnPressed += AddToInventory;
            }
示例#6
0
        public override void Initialize()
        {
            base.Initialize();

            _window          = new HumanInventoryWindow(_loc, _resourceCache);
            _window.OnClose += () => GameHud.InventoryButtonDown = false;
            foreach (var(slot, button) in _window.Buttons)
            {
                button.OnPressed        = AddToInventory;
                button.OnStoragePressed = OpenStorage;
                _inventoryButtons.Add(slot, new List <InventoryButton> {
                    button
                });
            }

            void AddButton(out InventoryButton variable, Slots slot, string textureName)
            {
                var texture        = _resourceCache.GetTexture($"/Textures/UserInterface/Inventory/{textureName}.png");
                var storageTexture = _resourceCache.GetTexture("/Textures/UserInterface/Inventory/back.png");

                variable = new InventoryButton(slot, texture, storageTexture)
                {
                    OnPressed        = AddToInventory,
                    OnStoragePressed = OpenStorage
                };
                _inventoryButtons[slot].Add(variable);
            }

            AddButton(out _hudButtonPocket1, Slots.POCKET1, "pocket");
            AddButton(out _hudButtonPocket2, Slots.POCKET2, "pocket");
            AddButton(out _hudButtonBack, Slots.BACKPACK, "back");
            AddButton(out _hudButtonBelt, Slots.BELT, "belt");
            AddButton(out _hudButtonId, Slots.IDCARD, "id");

            _quickButtonsContainer = new HBoxContainer
            {
                Children =
                {
                    _hudButtonId,
                    _hudButtonBelt,
                    _hudButtonBack,
                    _hudButtonPocket1,
                    _hudButtonPocket2,
                }
            };
        }
 private void ClearButton(InventoryButton button)
 {
     button.SpriteView.Sprite     = null;
     button.OnPressed             = AddToInventory;
     button.StorageButton.Visible = false;
 }