diff --git a/src/gui/components/ItemSlot.zig b/src/gui/components/ItemSlot.zig index 9407c860ac..d9763ec173 100644 --- a/src/gui/components/ItemSlot.zig +++ b/src/gui/components/ItemSlot.zig @@ -24,6 +24,11 @@ const Mode = enum { immutable, }; +const Style = enum { + normal, + unfocused, +}; + pos: Vec2f, size: Vec2f = @splat(sizeWithBorder), inventory: ClientInventory, @@ -36,6 +41,7 @@ pressed: bool = false, renderFrame: bool = true, texture: ?Texture, mode: Mode, +style: Style, var defaultTexture: Texture = undefined; var immutableTexture: Texture = undefined; @@ -81,6 +87,7 @@ pub fn init(pos: Vec2f, inventory: ClientInventory, itemSlot: u32, texture: Text .lastItemAmount = amount, .texture = texture.value(), .mode = mode, + .style = Style.normal, }; self.textSize = self.text.calculateLineBreaks(8, self.size[0] - 2*border); return self; @@ -136,6 +143,16 @@ pub fn render(self: *ItemSlot, _: Vec2f) void { draw.boundImage(self.pos, self.size); } const item = self.inventory.getItem(self.itemSlot); + const inventorySource = self.inventory.super.source; + + const isValidMaterial = item == .null or (item == .baseItem and item.baseItem.material() != null); + const applyWorkbenchFocus = gui.isWindowOpen("workbench") and (inventorySource == .playerInventory or inventorySource == .other); + if (self.style == .normal and applyWorkbenchFocus and !isValidMaterial) { + self.style = .unfocused; + } else if (self.style == .unfocused and (!applyWorkbenchFocus or isValidMaterial)) { + self.style = .normal; + } + if (item != .null) { item.render(self.pos, self.size, border); const shouldRenderStackSizeText = item.stackSize() > 1 and self.inventory.type != .creative; @@ -149,6 +166,10 @@ pub fn render(self: *ItemSlot, _: Vec2f) void { const oldColor = draw.setColor(0x300000ff); defer draw.restoreColor(oldColor); draw.rect(self.pos, self.size); + } else if (self.style == .unfocused and self.renderFrame) { + const oldColor = draw.setColor(0x800f0f0f); + defer draw.restoreColor(oldColor); + draw.rect(self.pos, self.size); } } } diff --git a/src/gui/windows/workbench.zig b/src/gui/windows/workbench.zig index 3c11d77072..a6c89cb13d 100644 --- a/src/gui/windows/workbench.zig +++ b/src/gui/windows/workbench.zig @@ -62,7 +62,7 @@ fn updateResult(_: main.items.Inventory.Source) void { fn openInventory() void { craftingGridInv = ClientInventory.init(main.globalAllocator, 25, .serverShared, .{.workbench = .{.playerId = main.game.Player.id, .proceduralItemIndex = proceduralItemTypes.items[currentProceduralItemType]}}, .{.onUpdateCallback = &updateResult, .canPutInto = items.ProceduralItem.canPutIntoWorkbenchCallback}); - craftingResultInv = ClientInventory.init(main.globalAllocator, 1, .{.workbenchResult = craftingGridInv.super.id}, .other, .{}); + craftingResultInv = ClientInventory.init(main.globalAllocator, 1, .{.workbenchResult = craftingGridInv.super.id}, .{.workbench = .{.playerId = main.game.Player.id, .proceduralItemIndex = proceduralItemTypes.items[currentProceduralItemType]}}, .{}); const list = HorizontalList.init(); { // crafting grid const grid = VerticalList.init(.{0, 0}, 300, 0); diff --git a/src/items.zig b/src/items.zig index 1be05698df..5a01aa53ec 100644 --- a/src/items.zig +++ b/src/items.zig @@ -1486,7 +1486,7 @@ pub fn registerProceduralItem(assetFolder: []const u8, id: []const u8, zon: ZonE } for (zon.getChild("optional").toSlice(), 0..) |zonDisabled, i| { if (i >= 25) { - std.log.err("disabled array of {s} has too many entries", .{id}); + std.log.err("optional array of {s} has too many entries", .{id}); break; } slotInfos[i].optional = (zonDisabled.as(usize) orelse 0) != 0;