From 0e04734c688053ad45e5615ff78e24824bc40503 Mon Sep 17 00:00:00 2001 From: IntegratedQuantum Date: Sat, 18 May 2024 18:23:07 +0200 Subject: [PATCH] Adda pause menu. Progress on #100 --- assets/cubyz/ui/pause_icon.png | Bin 0 -> 726 bytes src/gui/windows/_windowlist.zig | 4 +-- src/gui/windows/pause.zig | 33 +++++++++++++++++ src/gui/windows/pause_gear.zig | 61 ++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 assets/cubyz/ui/pause_icon.png create mode 100644 src/gui/windows/pause.zig create mode 100644 src/gui/windows/pause_gear.zig diff --git a/assets/cubyz/ui/pause_icon.png b/assets/cubyz/ui/pause_icon.png new file mode 100644 index 0000000000000000000000000000000000000000..6518176031749c9caad8f7ba040073b674b204c2 GIT binary patch literal 726 zcmV;{0xA88P)EX>4Tx04R}tkv&MmKpe$iTT4YM1??c>kfDl$1yK=4twIqhgj%6h2a`*`ph-iL z;^HW{799LotU9+0Yt2!bCV&JIqBE>hzEl0u6Z503ls?%w0>9pG10C4=2nH!D}v}l1Tz?wn5oZ+VhWz)>mEM7-o<&A_qjhuuaY+z;1h^vnQmCb8^qI_ zmd<&fILbC;;dF`taVTR!f;+&S>`&;AtbSgC5R9pqlPjnun?zJBgI6T_7fidLB}tWOD0zt zj2sK7LWSh`!T;cQw`O5-!c7V%fZ&U5e+&bmU7%UF?eAmTZk_;vXW&X}`>PFL=9Bb# zTZqX-L000?uMObu0Z*6U5Zgc=ca%Ew3 zWn>_CX>@2HM@dakSAh-}00023Nkl@!G{!GRA0IXYj-6S~li2wiq07*qo IM6N<$f~{RW*Z=?k literal 0 HcmV?d00001 diff --git a/src/gui/windows/_windowlist.zig b/src/gui/windows/_windowlist.zig index 94a49457e..1f6ccf373 100644 --- a/src/gui/windows/_windowlist.zig +++ b/src/gui/windows/_windowlist.zig @@ -14,10 +14,10 @@ pub const inventory = @import("inventory.zig"); pub const inventory_crafting = @import("inventory_crafting.zig"); pub const main = @import("main.zig"); pub const multiplayer = @import("multiplayer.zig"); +pub const pause = @import("pause.zig"); +pub const pause_gear = @import("pause_gear.zig"); pub const performance_graph = @import("performance_graph.zig"); pub const save_selection = @import("save_selection.zig"); pub const settings = @import("settings.zig"); pub const sound = @import("sound.zig"); pub const workbench = @import("workbench.zig"); - -// TODO: Add a pause menu. \ No newline at end of file diff --git a/src/gui/windows/pause.zig b/src/gui/windows/pause.zig new file mode 100644 index 000000000..d0a96fd73 --- /dev/null +++ b/src/gui/windows/pause.zig @@ -0,0 +1,33 @@ +const std = @import("std"); + +const main = @import("root"); +const Vec2f = main.vec.Vec2f; + +const gui = @import("../gui.zig"); +const GuiComponent = gui.GuiComponent; +const GuiWindow = gui.GuiWindow; +const Button = @import("../components/Button.zig"); +const VerticalList = @import("../components/VerticalList.zig"); + +pub var window = GuiWindow { + .contentSize = Vec2f{128, 256}, +}; + +const padding: f32 = 8; + +pub fn onOpen() void { + const list = VerticalList.init(.{padding, 16 + padding}, 300, 16); + list.add(Button.initText(.{0, 0}, 128, "Invite Player TODO", .{})); + list.add(Button.initText(.{0, 0}, 128, "Settings", gui.openWindowCallback("settings"))); + list.add(Button.initText(.{0, 0}, 128, "Exit to Menu TODO", .{})); + list.finish(.center); + window.rootComponent = list.toComponent(); + window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @as(Vec2f, @splat(padding)); + gui.updateWindowPositions(); +} + +pub fn onClose() void { + if(window.rootComponent) |*comp| { + comp.deinit(); + } +} \ No newline at end of file diff --git a/src/gui/windows/pause_gear.zig b/src/gui/windows/pause_gear.zig new file mode 100644 index 000000000..4fa2d8b3e --- /dev/null +++ b/src/gui/windows/pause_gear.zig @@ -0,0 +1,61 @@ +const std = @import("std"); + +const main = @import("root"); +const Texture = main.graphics.Texture; +const Vec2f = main.vec.Vec2f; + +const gui = @import("../gui.zig"); +const GuiComponent = gui.GuiComponent; +const GuiWindow = gui.GuiWindow; +const Button = @import("../components/Button.zig"); +const Label = GuiComponent.Label; +const MutexComponent = GuiComponent.MutexComponent; +const TextInput = GuiComponent.TextInput; +const VerticalList = @import("../components/VerticalList.zig"); + +pub var window: GuiWindow = GuiWindow { + .relativePosition = .{ + .{ .attachedToFrame = .{.selfAttachmentPoint = .upper, .otherAttachmentPoint = .upper} }, + .{ .attachedToFrame = .{.selfAttachmentPoint = .upper, .otherAttachmentPoint = .upper} }, + }, + .scale = 0.5, + .contentSize = Vec2f{64, 64}, + .showTitleBar = false, + .hasBackground = false, + .isHud = true, + .hideIfMouseIsGrabbed = true, +}; + +const padding: f32 = 8; +const messageTimeout: i32 = 10000; +const messageFade = 1000; + +var mutexComponent: MutexComponent = .{}; +var history: main.List(*Label) = undefined; +var expirationTime: main.List(i32) = undefined; +var historyStart: u32 = 0; +var fadeOutEnd: u32 = 0; +var input: *TextInput = undefined; +var hideInput: bool = true; + +var pauseIcon: Texture = undefined; + +pub fn init() void { + pauseIcon = Texture.initFromFile("assets/cubyz/ui/pause_icon.png"); +} + +pub fn deinit() void { + pauseIcon.deinit(); +} + +pub fn onOpen() void { + const button = Button.initIcon(.{0, 0}, .{64, 64}, pauseIcon, true, gui.openWindowCallback("pause")); + window.contentSize = button.size; + window.rootComponent = button.toComponent(); +} + +pub fn onClose() void { + if(window.rootComponent) |*comp| { + comp.deinit(); + } +} \ No newline at end of file