Skip to content

Commit

Permalink
Adda pause menu.
Browse files Browse the repository at this point in the history
Progress on PixelGuys#100
  • Loading branch information
IntegratedQuantum committed May 18, 2024
1 parent a47b685 commit 0e04734
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 2 deletions.
Binary file added assets/cubyz/ui/pause_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/gui/windows/_windowlist.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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.
33 changes: 33 additions & 0 deletions src/gui/windows/pause.zig
Original file line number Diff line number Diff line change
@@ -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();
}
}
61 changes: 61 additions & 0 deletions src/gui/windows/pause_gear.zig
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit 0e04734

Please sign in to comment.