Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
12 changes: 12 additions & 0 deletions src/gui/components/ItemSlot.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub const sizeWithBorder = 32 + 2*border;
const Mode = enum {
normal,
takeOnly,
unfocused,
immutable,
};
Comment on lines 21 to 25

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

normal, takeOnly, and immutable actually represent logic behavior changes, whereas unfocused only affects rendering behavior. So I don't think unfocused fits here.

One example where this can shoot you in the foot is that the item slots in the creative window are takeOnly, and therefore aren't affected by your logic. Even though it would be nice if they were.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, it now applies the logic by inventory source instead of item slot mode. Though maybe the creative inventory should have it's own inventory source type instead of using .other?


Expand Down Expand Up @@ -136,6 +137,13 @@ pub fn render(self: *ItemSlot, _: Vec2f) void {
draw.boundImage(self.pos, self.size);
}
const item = self.inventory.getItem(self.itemSlot);
const isValidMaterial = item == .null or (item == .baseItem and item.baseItem.material() != null);
if (self.mode == .normal and gui.isWindowOpen("workbench") and !isValidMaterial) {
self.mode = .unfocused;
} else if (self.mode == .unfocused and (!gui.isWindowOpen("workbench") or isValidMaterial)) {
self.mode = .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 +157,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.mode == .unfocused and self.renderFrame) {
const oldColor = draw.setColor(0x600f0f0f);
defer draw.restoreColor(oldColor);
draw.rect(self.pos, self.size);
}
}
}
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