public HumanInventoryWindow(ILocalizationManager loc, IResourceCache resourceCache) { Title = loc.GetString("Your Inventory"); Resizable = false; var buttonDict = new Dictionary <Slots, ItemSlotButton>(); Buttons = buttonDict; const int width = ButtonSize * 4 + ButtonSeparation * 3 + RightSeparation; const int height = ButtonSize * 4 + ButtonSeparation * 3; var windowContents = new LayoutContainer { CustomMinimumSize = (width, height) }; Contents.AddChild(windowContents); void AddButton(Slots slot, string textureName, Vector2 position) { var texture = resourceCache.GetTexture($"/Textures/Interface/Inventory/{textureName}.png"); var storageTexture = resourceCache.GetTexture("/Textures/Interface/Inventory/back.png"); var button = new ItemSlotButton(texture, storageTexture); LayoutContainer.SetPosition(button, position); windowContents.AddChild(button); buttonDict.Add(slot, button); } const int sizep = (ButtonSize + ButtonSeparation); // Left column. AddButton(Slots.EYES, "glasses", (0, 0)); AddButton(Slots.NECK, "neck", (0, sizep)); AddButton(Slots.INNERCLOTHING, "uniform", (0, 2 * sizep)); // Middle column. AddButton(Slots.HEAD, "head", (sizep, 0)); AddButton(Slots.MASK, "mask", (sizep, sizep)); AddButton(Slots.OUTERCLOTHING, "suit", (sizep, 2 * sizep)); AddButton(Slots.SHOES, "shoes", (sizep, 3 * sizep)); // Right column AddButton(Slots.EARS, "ears", (2 * sizep, 0)); AddButton(Slots.IDCARD, "id", (2 * sizep, sizep)); AddButton(Slots.EXOSUITSLOT1, "suit_storage", (2 * sizep, 2 * sizep)); AddButton(Slots.POCKET1, "pocket", (2 * sizep, 3 * sizep)); // Far right column. AddButton(Slots.BACKPACK, "back", (3 * sizep, 0)); AddButton(Slots.BELT, "belt", (3 * sizep, sizep)); AddButton(Slots.GLOVES, "gloves", (3 * sizep, 2 * sizep)); AddButton(Slots.POCKET2, "pocket", (3 * sizep, 3 * sizep)); } }
public HumanInventoryWindow(IGameHud gameHud) { Title = Loc.GetString("human-inventory-window-title"); Resizable = false; var buttonDict = new Dictionary <Slots, ItemSlotButton>(); Buttons = buttonDict; const int width = ButtonSize * 4 + ButtonSeparation * 3 + RightSeparation; const int height = ButtonSize * 4 + ButtonSeparation * 3; var windowContents = new LayoutContainer { MinSize = (width, height) }; Contents.AddChild(windowContents); void AddButton(Slots slot, string textureName, Vector2 position) { var texture = gameHud.GetHudTexture($"{textureName}.png"); var storageTexture = gameHud.GetHudTexture("back.png"); var button = new ItemSlotButton(texture, storageTexture, textureName); LayoutContainer.SetPosition(button, position); windowContents.AddChild(button); buttonDict.Add(slot, button); } const int sizep = (ButtonSize + ButtonSeparation); // Left column. AddButton(Slots.EYES, "glasses", (0, 0)); AddButton(Slots.NECK, "neck", (0, sizep)); AddButton(Slots.INNERCLOTHING, "uniform", (0, 2 * sizep)); AddButton(Slots.POCKET1, "pocket", (0, 3 * sizep)); // Middle column. AddButton(Slots.HEAD, "head", (sizep, 0)); AddButton(Slots.MASK, "mask", (sizep, sizep)); AddButton(Slots.OUTERCLOTHING, "suit", (sizep, 2 * sizep)); AddButton(Slots.SHOES, "shoes", (sizep, 3 * sizep)); // Right column AddButton(Slots.EARS, "ears", (2 * sizep, 0)); AddButton(Slots.IDCARD, "id", (2 * sizep, sizep)); AddButton(Slots.GLOVES, "gloves", (2 * sizep, 2 * sizep)); AddButton(Slots.POCKET2, "pocket", (2 * sizep, 3 * sizep)); // Far right column. AddButton(Slots.BACKPACK, "back", (3 * sizep, 0)); AddButton(Slots.BELT, "belt", (3 * sizep, sizep)); } }
public override void Initialize() { base.Initialize(); _window = new HumanInventoryWindow(_resourceCache); _window.OnClose += () => GameHud.InventoryButtonDown = false; foreach (var(slot, button) in _window.Buttons) { button.OnPressed = (e) => AddToInventory(e, slot); button.OnStoragePressed = (e) => OpenStorage(e, slot); button.OnHover = (e) => RequestItemHover(slot); _inventoryButtons.Add(slot, new List <ItemSlotButton> { button }); } void AddButton(out ItemSlotButton variable, Slots slot, string textureName) { var texture = _resourceCache.GetTexture($"/Textures/Interface/Inventory/{textureName}.png"); var storageTexture = _resourceCache.GetTexture("/Textures/Interface/Inventory/back.png"); variable = new ItemSlotButton(texture, storageTexture) { OnPressed = (e) => AddToInventory(e, slot), OnStoragePressed = (e) => OpenStorage(e, slot), OnHover = (e) => RequestItemHover(slot) }; _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, } }; }
public bool SetItemSlot(ItemSlotButton button, IEntity?entity) { if (entity == null) { button.SpriteView.Sprite = null; button.StorageButton.Visible = false; } else { if (!entity.TryGetComponent(out ISpriteComponent? sprite)) { return(false); } button.ClearHover(); button.SpriteView.Sprite = sprite; button.StorageButton.Visible = entity.HasComponent <ClientStorageComponent>(); } return(true); }
public void HoverInSlot(ItemSlotButton button, IEntity?entity, bool fits) { if (entity == null || !button.MouseIsHovering) { button.ClearHover(); return; } if (!entity.HasComponent <SpriteComponent>()) { return; } // Set green / red overlay at 50% transparency var hoverEntity = _entityManager.SpawnEntity("hoverentity", MapCoordinates.Nullspace); var hoverSprite = hoverEntity.GetComponent <SpriteComponent>(); hoverSprite.CopyFrom(entity.GetComponent <SpriteComponent>()); hoverSprite.Color = fits ? new Color(0, 255, 0, 127) : new Color(255, 0, 0, 127); button.HoverSpriteView.Sprite = hoverSprite; }
private void ClearButton(ItemSlotButton button, Slots slot) { button.OnPressed = (e) => AddToInventory(e, slot); _itemSlotManager.SetItemSlot(button, null); }