From f3a197f6d4c8f1ce99c6b32e42598e8061e54733 Mon Sep 17 00:00:00 2001 From: IntegratedQuantum Date: Sun, 15 Oct 2023 22:26:02 +0200 Subject: [PATCH] Default gui positions Resolves #131 --- src/audio.zig | 2 +- src/gui/GuiWindow.zig | 2 +- src/gui/gui.zig | 1 + src/gui/windows/chat.zig | 5 +++++ src/gui/windows/creative_inventory.zig | 4 ++++ src/gui/windows/debug.zig | 4 ++++ src/gui/windows/gpu_performance_measuring.zig | 4 ++++ src/gui/windows/healthbar.zig | 7 +++++++ src/gui/windows/hotbar.zig | 4 ++++ src/gui/windows/inventory.zig | 6 ++++++ src/gui/windows/inventory_crafting.zig | 6 ++++++ src/gui/windows/performance_graph.zig | 6 ++++++ src/gui/windows/workbench.zig | 5 +++++ 13 files changed, 54 insertions(+), 2 deletions(-) diff --git a/src/audio.zig b/src/audio.zig index f8e464bc..717e1fbb 100644 --- a/src/audio.zig +++ b/src/audio.zig @@ -153,7 +153,7 @@ pub fn init() !void { 0, // input channels 2, // stereo output c.paFloat32, - sampleRate, // TODO: There must be some target dependant value to put here. + sampleRate, c.paFramesPerBufferUnspecified, &patestCallback, null diff --git a/src/gui/GuiWindow.zig b/src/gui/GuiWindow.zig index 82f2c5a1..181b7c5d 100644 --- a/src/gui/GuiWindow.zig +++ b/src/gui/GuiWindow.zig @@ -316,7 +316,7 @@ fn positionRelativeToConnectedWindow(self: *GuiWindow, other: *GuiWindow, i: usi .otherAttachmentPoint = .upper, }}; } else { - self.relativePosition[i] = .{.relativeToWindow = .{ + relPos.* = .{.relativeToWindow = .{ .reference = other, .ratio = (self.pos[i] + self.size[i]/2 - other.pos[i])/otherSize[i] }}; diff --git a/src/gui/gui.zig b/src/gui/gui.zig index 48639e53..cb747996 100644 --- a/src/gui/gui.zig +++ b/src/gui/gui.zig @@ -235,6 +235,7 @@ fn load() !void { for(windowList.items) |window| { const windowJson = json.getChild(window.id); + if(windowJson == .JsonNull) continue; for(&window.relativePosition, 0..) |*relPos, i| { const relPosJson = windowJson.getChild(([_][]const u8{"relPos0", "relPos1"})[i]); const typ = relPosJson.get([]const u8, "type", "ratio"); diff --git a/src/gui/windows/chat.zig b/src/gui/windows/chat.zig index 28a8b052..dd7c133b 100644 --- a/src/gui/windows/chat.zig +++ b/src/gui/windows/chat.zig @@ -14,6 +14,11 @@ const TextInput = GuiComponent.TextInput; const VerticalList = @import("../components/VerticalList.zig"); pub var window: GuiWindow = GuiWindow { + .relativePosition = .{ + .{ .attachedToFrame = .{.selfAttachmentPoint = .lower, .otherAttachmentPoint = .lower} }, + .{ .attachedToFrame = .{.selfAttachmentPoint = .upper, .otherAttachmentPoint = .upper} }, + }, + .scale = 0.75, .contentSize = Vec2f{128, 256}, .id = "chat", .showTitleBar = false, diff --git a/src/gui/windows/creative_inventory.zig b/src/gui/windows/creative_inventory.zig index ea637d41..db8da05e 100644 --- a/src/gui/windows/creative_inventory.zig +++ b/src/gui/windows/creative_inventory.zig @@ -15,6 +15,10 @@ const VerticalList = GuiComponent.VerticalList; const ItemSlot = GuiComponent.ItemSlot; pub var window = GuiWindow { + .relativePosition = .{ + .{ .attachedToFrame = .{.selfAttachmentPoint = .lower, .otherAttachmentPoint = .lower} }, + .{ .attachedToFrame = .{.selfAttachmentPoint = .middle, .otherAttachmentPoint = .middle} }, + }, .contentSize = Vec2f{64*8, 64*4}, .id = "creative_inventory", }; diff --git a/src/gui/windows/debug.zig b/src/gui/windows/debug.zig index 50710c4e..f78c0259 100644 --- a/src/gui/windows/debug.zig +++ b/src/gui/windows/debug.zig @@ -12,6 +12,10 @@ const GuiWindow = gui.GuiWindow; const GuiComponent = gui.GuiComponent; pub var window = GuiWindow { + .relativePosition = .{ + .{ .attachedToFrame = .{.selfAttachmentPoint = .lower, .otherAttachmentPoint = .lower} }, + .{ .attachedToFrame = .{.selfAttachmentPoint = .lower, .otherAttachmentPoint = .lower} }, + }, .contentSize = Vec2f{128, 16}, .id = "debug", .isHud = false, diff --git a/src/gui/windows/gpu_performance_measuring.zig b/src/gui/windows/gpu_performance_measuring.zig index 1247c9e7..9f0176d4 100644 --- a/src/gui/windows/gpu_performance_measuring.zig +++ b/src/gui/windows/gpu_performance_measuring.zig @@ -77,6 +77,10 @@ pub fn stopQuery() void { } pub var window = GuiWindow { + .relativePosition = .{ + .{ .attachedToFrame = .{.selfAttachmentPoint = .upper, .otherAttachmentPoint = .upper} }, + .{ .attachedToFrame = .{.selfAttachmentPoint = .lower, .otherAttachmentPoint = .lower} }, + }, .contentSize = Vec2f{256, 16}, .id = "gpu_performance_measuring", .isHud = false, diff --git a/src/gui/windows/healthbar.zig b/src/gui/windows/healthbar.zig index 64aa7ed0..8f6c96df 100644 --- a/src/gui/windows/healthbar.zig +++ b/src/gui/windows/healthbar.zig @@ -11,7 +11,14 @@ const gui = @import("../gui.zig"); const GuiWindow = gui.GuiWindow; const GuiComponent = gui.GuiComponent; +const hotbar = @import("hotbar.zig"); + pub var window = GuiWindow { + .scale = 0.75, + .relativePosition = .{ + .{ .attachedToWindow = .{.reference = &hotbar.window, .selfAttachmentPoint = .upper, .otherAttachmentPoint = .upper} }, + .{ .attachedToWindow = .{.reference = &hotbar.window, .selfAttachmentPoint = .upper, .otherAttachmentPoint = .lower} }, + }, .contentSize = Vec2f{128, 16}, .id = "healthbar", .isHud = true, diff --git a/src/gui/windows/hotbar.zig b/src/gui/windows/hotbar.zig index 2c9476e2..4230b69f 100644 --- a/src/gui/windows/hotbar.zig +++ b/src/gui/windows/hotbar.zig @@ -15,6 +15,10 @@ const ItemSlot = GuiComponent.ItemSlot; const Icon = GuiComponent.Icon; pub var window = GuiWindow { + .relativePosition = .{ + .{ .attachedToFrame = .{.selfAttachmentPoint = .middle, .otherAttachmentPoint = .middle} }, + .{ .attachedToFrame = .{.selfAttachmentPoint = .upper, .otherAttachmentPoint = .upper} }, + }, .contentSize = Vec2f{64*8, 64}, .id = "hotbar", .isHud = true, diff --git a/src/gui/windows/inventory.zig b/src/gui/windows/inventory.zig index 9851f450..3f676630 100644 --- a/src/gui/windows/inventory.zig +++ b/src/gui/windows/inventory.zig @@ -15,7 +15,13 @@ const HorizontalList = GuiComponent.HorizontalList; const VerticalList = GuiComponent.VerticalList; const ItemSlot = GuiComponent.ItemSlot; +const hotbar = @import("hotbar.zig"); + pub var window = GuiWindow { + .relativePosition = .{ + .{ .attachedToWindow = .{.reference = &hotbar.window, .selfAttachmentPoint = .middle, .otherAttachmentPoint = .middle} }, + .{ .attachedToWindow = .{.reference = &hotbar.window, .selfAttachmentPoint = .upper, .otherAttachmentPoint = .lower} }, + }, .contentSize = Vec2f{64*8, 64*4}, .id = "inventory", }; diff --git a/src/gui/windows/inventory_crafting.zig b/src/gui/windows/inventory_crafting.zig index 4d063424..c620fc33 100644 --- a/src/gui/windows/inventory_crafting.zig +++ b/src/gui/windows/inventory_crafting.zig @@ -19,7 +19,13 @@ const Icon = GuiComponent.Icon; const CraftingResultSlot = GuiComponent.CraftingResultSlot; const ImmutableItemSlot = GuiComponent.ImmutableItemSlot; +const inventory = @import("inventory.zig"); + pub var window = GuiWindow { + .relativePosition = .{ + .{ .attachedToWindow = .{.reference = &inventory.window, .selfAttachmentPoint = .lower, .otherAttachmentPoint = .upper} }, + .{ .attachedToWindow = .{.reference = &inventory.window, .selfAttachmentPoint = .middle, .otherAttachmentPoint = .middle} }, + }, .contentSize = Vec2f{64*8, 64*4}, .id = "inventory_crafting", }; diff --git a/src/gui/windows/performance_graph.zig b/src/gui/windows/performance_graph.zig index 5bd270fb..9589f2a5 100644 --- a/src/gui/windows/performance_graph.zig +++ b/src/gui/windows/performance_graph.zig @@ -11,8 +11,14 @@ const gui = @import("../gui.zig"); const GuiWindow = gui.GuiWindow; const GuiComponent = gui.GuiComponent; +const chat = @import("chat.zig"); + pub var window = GuiWindow { .contentSize = Vec2f{128, 64}, + .relativePosition = .{ + .{ .attachedToFrame = .{.selfAttachmentPoint = .lower, .otherAttachmentPoint = .lower} }, + .{ .attachedToWindow = .{.reference = &chat.window, .selfAttachmentPoint = .upper, .otherAttachmentPoint = .lower} }, + }, .id = "performance_graph", .isHud = false, .showTitleBar = false, diff --git a/src/gui/windows/workbench.zig b/src/gui/windows/workbench.zig index 5bcc8b80..55731143 100644 --- a/src/gui/windows/workbench.zig +++ b/src/gui/windows/workbench.zig @@ -22,9 +22,14 @@ const ItemSlot = GuiComponent.ItemSlot; const CraftingResultSlot = GuiComponent.CraftingResultSlot; const ImmutableItemSlot = GuiComponent.ImmutableItemSlot; +const inventory = @import("inventory.zig"); const inventory_crafting = @import("inventory_crafting.zig"); pub var window = GuiWindow { + .relativePosition = .{ + .{ .attachedToWindow = .{.reference = &inventory.window, .selfAttachmentPoint = .middle, .otherAttachmentPoint = .middle} }, + .{ .attachedToWindow = .{.reference = &inventory.window, .selfAttachmentPoint = .upper, .otherAttachmentPoint = .lower} }, + }, .contentSize = Vec2f{64*8, 64*4}, .id = "workbench", };