Increase hotbar size to 12. (Inventory size is still the same)

Fixes #342
This commit is contained in:
IntegratedQuantum 2024-05-02 20:39:26 +02:00
parent a575edae45
commit e68f49ed89
3 changed files with 12 additions and 13 deletions

View File

@ -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;
}

View File

@ -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();
@ -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]);
}

View File

@ -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;
@ -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();
@ -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);
@ -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]);
}
}