Skip to content

Commit

Permalink
Increase hotbar size to 12. (Inventory size is still the same)
Browse files Browse the repository at this point in the history
Fixes #342
  • Loading branch information
IntegratedQuantum committed May 2, 2024
1 parent a575eda commit e68f49e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/game.zig
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ pub fn update(deltaTime: f64) void {
}
}
}
Player.selectedSlot -%= @bitCast(@as(i32, @intFromFloat(main.Window.scrollOffset)));
Player.selectedSlot %= 8;
const newSlot: i32 = @as(i32, @intCast(Player.selectedSlot)) -% @as(i32, @intFromFloat(main.Window.scrollOffset));
Player.selectedSlot = @intCast(@mod(newSlot, 12));
main.Window.scrollOffset = 0;
}

Expand Down
6 changes: 3 additions & 3 deletions src/gui/windows/hotbar.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ pub var window = GuiWindow {
.{ .attachedToFrame = .{.selfAttachmentPoint = .middle, .otherAttachmentPoint = .middle} },
.{ .attachedToFrame = .{.selfAttachmentPoint = .upper, .otherAttachmentPoint = .upper} },
},
.contentSize = Vec2f{64*8, 64},
.contentSize = Vec2f{64*12, 64},
.isHud = true,
.showTitleBar = false,
.hasBackground = false,
.hideIfMouseIsGrabbed = false,
};

var itemSlots: [8]*ItemSlot = undefined;
var itemSlots: [12]*ItemSlot = undefined;

pub fn tryAddingItems(index: usize, source: *ItemStack, desiredAmount: u16) void {
Player.mutex.lock();
Expand Down Expand Up @@ -70,7 +70,7 @@ const vtable = ItemSlot.VTable {

pub fn onOpen() void {
const list = HorizontalList.init();
for(0..8) |i| {
for(0..12) |i| {
itemSlots[i] = ItemSlot.init(.{0, 0}, Player.inventory__SEND_CHANGES_TO_SERVER.items[i], &vtable, i, .default, .normal);
list.add(itemSlots[i]);
}
Expand Down
15 changes: 7 additions & 8 deletions src/gui/windows/inventory.zig
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub var window = GuiWindow {
.{ .attachedToWindow = .{.reference = &hotbar.window, .selfAttachmentPoint = .middle, .otherAttachmentPoint = .middle} },
.{ .attachedToWindow = .{.reference = &hotbar.window, .selfAttachmentPoint = .upper, .otherAttachmentPoint = .lower} },
},
.contentSize = Vec2f{64*8, 64*4},
.contentSize = Vec2f{64*10, 64*3},
};

const padding: f32 = 8;
Expand All @@ -36,7 +36,7 @@ pub fn deinit() void {
craftingIcon.deinit();
}

var itemSlots: [24]*ItemSlot = undefined;
var itemSlots: [20]*ItemSlot = undefined;

pub fn tryAddingItems(index: usize, source: *ItemStack, desiredAmount: u16) void {
Player.mutex.lock();
Expand Down Expand Up @@ -88,13 +88,12 @@ pub fn onOpen() void {
row.add(Button.initIcon(.{0, 0}, .{24, 24}, craftingIcon, true, gui.openWindowCallback("inventory_crafting")));
list.add(row);
}
// Inventory:
for(1..4) |y| {
for(0..2) |y| {
const row = HorizontalList.init();
for(0..8) |x| {
const index: usize = y*8 + x;
for(0..10) |x| {
const index: usize = 12 + y*10 + x;
const slot = ItemSlot.init(.{0, 0}, Player.inventory__SEND_CHANGES_TO_SERVER.items[index], &vtable, index, .default, .normal);
itemSlots[index - 8] = slot;
itemSlots[index - 12] = slot;
row.add(slot);
}
list.add(row);
Expand All @@ -114,7 +113,7 @@ pub fn onClose() void {
pub fn update() void {
Player.mutex.lock();
defer Player.mutex.unlock();
for(&itemSlots, 8..) |slot, i| {
for(&itemSlots, 12..) |slot, i| {
slot.updateItemStack(Player.inventory__SEND_CHANGES_TO_SERVER.items[i]);
}
}

0 comments on commit e68f49e

Please sign in to comment.