Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/gui/components/ItemSlot.zig
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ const Mode = enum {
immutable,
};

const Style = enum {
normal,
unfocused,
};

pos: Vec2f,
size: Vec2f = @splat(sizeWithBorder),
inventory: ClientInventory,
Expand All @@ -36,6 +41,7 @@ pressed: bool = false,
renderFrame: bool = true,
texture: ?Texture,
mode: Mode,
style: Style,

var defaultTexture: Texture = undefined;
var immutableTexture: Texture = undefined;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion src/gui/windows/workbench.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/items.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading