mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-08-03 19:28:49 -04:00
Refactor: Limit window components to one. Also use better formatting for tooltips.
This commit is contained in:
parent
58d1428392
commit
9fdfa04734
@ -55,7 +55,7 @@ spacing: f32 = 0,
|
|||||||
relativePosition: [2]RelativePosition = .{.{.ratio = 0.5}, .{.ratio = 0.5}},
|
relativePosition: [2]RelativePosition = .{.{.ratio = 0.5}, .{.ratio = 0.5}},
|
||||||
title: []const u8 = "",
|
title: []const u8 = "",
|
||||||
id: []const u8,
|
id: []const u8,
|
||||||
components: []GuiComponent = &.{},
|
rootComponent: ?GuiComponent = null,
|
||||||
showTitleBar: bool = true,
|
showTitleBar: bool = true,
|
||||||
titleBarExpanded: bool = false,
|
titleBarExpanded: bool = false,
|
||||||
hasBackground: bool = true,
|
hasBackground: bool = true,
|
||||||
@ -125,15 +125,11 @@ pub fn mainButtonPressed(self: *const GuiWindow, mousePosition: Vec2f) void {
|
|||||||
grabPosition = mousePosition;
|
grabPosition = mousePosition;
|
||||||
selfPositionWhenGrabbed = self.pos;
|
selfPositionWhenGrabbed = self.pos;
|
||||||
} else {
|
} else {
|
||||||
var selectedComponent: ?*GuiComponent = null;
|
if(self.rootComponent) |*component| {
|
||||||
for(self.components) |*component| {
|
|
||||||
if(GuiComponent.contains(component.pos(), component.size(), scaledMousePos)) {
|
if(GuiComponent.contains(component.pos(), component.size(), scaledMousePos)) {
|
||||||
selectedComponent = component;
|
component.mainButtonPressed(scaledMousePos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(selectedComponent) |component| {
|
|
||||||
component.mainButtonPressed(scaledMousePos);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +171,7 @@ pub fn mainButtonReleased(self: *GuiWindow, mousePosition: Vec2f) void {
|
|||||||
}
|
}
|
||||||
grabPosition = null;
|
grabPosition = null;
|
||||||
grabbedWindow = undefined;
|
grabbedWindow = undefined;
|
||||||
for(self.components) |*component| {
|
if(self.rootComponent) |*component| {
|
||||||
component.mainButtonReleased((mousePosition - self.pos)/@splat(2, self.scale));
|
component.mainButtonReleased((mousePosition - self.pos)/@splat(2, self.scale));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -335,20 +331,16 @@ pub fn updateSelected(self: *GuiWindow, mousePosition: Vec2f) !void {
|
|||||||
self.pos = @min(self.pos, windowSize - self.size);
|
self.pos = @min(self.pos, windowSize - self.size);
|
||||||
gui.updateWindowPositions();
|
gui.updateWindowPositions();
|
||||||
};
|
};
|
||||||
for(self.components) |*component| {
|
if(self.rootComponent) |*component| {
|
||||||
component.updateSelected();
|
component.updateSelected();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn updateHovered(self: *GuiWindow, mousePosition: Vec2f) !void {
|
pub fn updateHovered(self: *GuiWindow, mousePosition: Vec2f) !void {
|
||||||
try self.updateHoveredFn();
|
try self.updateHoveredFn();
|
||||||
var i: usize = self.components.len;
|
if(self.rootComponent) |component| {
|
||||||
while(i != 0) {
|
|
||||||
i -= 1;
|
|
||||||
const component = &self.components[i];
|
|
||||||
if(GuiComponent.contains(component.pos(), component.size(), (mousePosition - self.pos)/@splat(2, self.scale))) {
|
if(GuiComponent.contains(component.pos(), component.size(), (mousePosition - self.pos)/@splat(2, self.scale))) {
|
||||||
component.updateHovered((mousePosition - self.pos)/@splat(2, self.scale));
|
component.updateHovered((mousePosition - self.pos)/@splat(2, self.scale));
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -455,7 +447,7 @@ pub fn render(self: *const GuiWindow, mousePosition: Vec2f) !void {
|
|||||||
draw.customShadedRect(windowUniforms, .{0, 0}, self.size/@splat(2, self.scale));
|
draw.customShadedRect(windowUniforms, .{0, 0}, self.size/@splat(2, self.scale));
|
||||||
}
|
}
|
||||||
try self.renderFn();
|
try self.renderFn();
|
||||||
for(self.components) |*component| {
|
if(self.rootComponent) |*component| {
|
||||||
try component.render((mousePosition - self.pos)/@splat(2, self.scale));
|
try component.render((mousePosition - self.pos)/@splat(2, self.scale));
|
||||||
}
|
}
|
||||||
if(self.showTitleBar) {
|
if(self.showTitleBar) {
|
||||||
|
@ -13,12 +13,10 @@ const Label = @import("../components/Label.zig");
|
|||||||
const TextInput = @import("../components/TextInput.zig");
|
const TextInput = @import("../components/TextInput.zig");
|
||||||
const VerticalList = @import("../components/VerticalList.zig");
|
const VerticalList = @import("../components/VerticalList.zig");
|
||||||
|
|
||||||
var components: [1]GuiComponent = undefined;
|
|
||||||
pub var window = GuiWindow {
|
pub var window = GuiWindow {
|
||||||
.contentSize = Vec2f{128, 256},
|
.contentSize = Vec2f{128, 256},
|
||||||
.id = "cubyz:change_name",
|
.id = "cubyz:change_name",
|
||||||
.title = "Change Name",
|
.title = "Change Name",
|
||||||
.components = &components,
|
|
||||||
};
|
};
|
||||||
var textComponent: *TextInput = undefined;
|
var textComponent: *TextInput = undefined;
|
||||||
|
|
||||||
@ -57,13 +55,13 @@ pub fn onOpen() Allocator.Error!void {
|
|||||||
try list.add(textComponent);
|
try list.add(textComponent);
|
||||||
try list.add(try Button.init(.{0, 0}, 100, "Apply", &apply));
|
try list.add(try Button.init(.{0, 0}, 100, "Apply", &apply));
|
||||||
list.finish(.center);
|
list.finish(.center);
|
||||||
components[0] = list.toComponent();
|
window.rootComponent = list.toComponent();
|
||||||
window.contentSize = components[0].pos() + components[0].size() + @splat(2, @as(f32, padding));
|
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @splat(2, @as(f32, padding));
|
||||||
gui.updateWindowPositions();
|
gui.updateWindowPositions();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn onClose() void {
|
pub fn onClose() void {
|
||||||
for(&components) |*comp| {
|
if(window.rootComponent) |*comp| {
|
||||||
comp.deinit();
|
comp.deinit();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -13,12 +13,10 @@ const MutexComponent = GuiComponent.MutexComponent;
|
|||||||
const TextInput = GuiComponent.TextInput;
|
const TextInput = GuiComponent.TextInput;
|
||||||
const VerticalList = @import("../components/VerticalList.zig");
|
const VerticalList = @import("../components/VerticalList.zig");
|
||||||
|
|
||||||
var components: [1]GuiComponent = undefined;
|
|
||||||
pub var window: GuiWindow = GuiWindow {
|
pub var window: GuiWindow = GuiWindow {
|
||||||
.contentSize = Vec2f{128, 256},
|
.contentSize = Vec2f{128, 256},
|
||||||
.id = "cubyz:chat",
|
.id = "cubyz:chat",
|
||||||
.title = "Chat",
|
.title = "Chat",
|
||||||
.components = &components,
|
|
||||||
.showTitleBar = false,
|
.showTitleBar = false,
|
||||||
.hasBackground = false,
|
.hasBackground = false,
|
||||||
.isHud = true,
|
.isHud = true,
|
||||||
@ -36,11 +34,11 @@ var fadeOutEnd: u32 = 0;
|
|||||||
var input: *TextInput = undefined;
|
var input: *TextInput = undefined;
|
||||||
var hideInput: bool = true;
|
var hideInput: bool = true;
|
||||||
|
|
||||||
fn refresh(deleteOld: bool) Allocator.Error!void {
|
fn refresh() Allocator.Error!void {
|
||||||
std.debug.assert(!mutexComponent.mutex.tryLock()); // mutex must be locked!
|
std.debug.assert(!mutexComponent.mutex.tryLock()); // mutex must be locked!
|
||||||
if(deleteOld) {
|
if(window.rootComponent) |old| {
|
||||||
components[0].mutexComponent.child.verticalList.children.clearRetainingCapacity();
|
old.mutexComponent.child.verticalList.children.clearRetainingCapacity();
|
||||||
components[0].deinit();
|
old.deinit();
|
||||||
}
|
}
|
||||||
var list = try VerticalList.init(.{padding, 16 + padding}, 300, 0);
|
var list = try VerticalList.init(.{padding, 16 + padding}, 300, 0);
|
||||||
for(history.items[if(hideInput) historyStart else 0 ..]) |msg| {
|
for(history.items[if(hideInput) historyStart else 0 ..]) |msg| {
|
||||||
@ -54,8 +52,8 @@ fn refresh(deleteOld: bool) Allocator.Error!void {
|
|||||||
list.finish(.center);
|
list.finish(.center);
|
||||||
list.scrollBar.currentState = 1;
|
list.scrollBar.currentState = 1;
|
||||||
try mutexComponent.updateInner(list);
|
try mutexComponent.updateInner(list);
|
||||||
components[0] = mutexComponent.toComponent();
|
window.rootComponent = mutexComponent.toComponent();
|
||||||
window.contentSize = components[0].pos() + components[0].size() + @splat(2, @as(f32, padding));
|
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @splat(2, @as(f32, padding));
|
||||||
gui.updateWindowPositions();
|
gui.updateWindowPositions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +64,7 @@ pub fn onOpen() Allocator.Error!void {
|
|||||||
input = try TextInput.init(.{0, 0}, 256, 32, "", &sendMessage);
|
input = try TextInput.init(.{0, 0}, 256, 32, "", &sendMessage);
|
||||||
mutexComponent.mutex.lock();
|
mutexComponent.mutex.lock();
|
||||||
defer mutexComponent.mutex.unlock();
|
defer mutexComponent.mutex.unlock();
|
||||||
try refresh(false);
|
try refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn onClose() void {
|
pub fn onClose() void {
|
||||||
@ -78,8 +76,9 @@ pub fn onClose() void {
|
|||||||
history.deinit();
|
history.deinit();
|
||||||
expirationTime.deinit();
|
expirationTime.deinit();
|
||||||
input.deinit();
|
input.deinit();
|
||||||
components[0].mutexComponent.child.verticalList.children.clearRetainingCapacity();
|
window.rootComponent.?.mutexComponent.child.verticalList.children.clearRetainingCapacity();
|
||||||
components[0].deinit();
|
window.rootComponent.?.deinit();
|
||||||
|
window.rootComponent = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update() Allocator.Error!void {
|
pub fn update() Allocator.Error!void {
|
||||||
@ -92,14 +91,14 @@ pub fn update() Allocator.Error!void {
|
|||||||
if(@truncate(i32, std.time.milliTimestamp()) -% time >= messageFade) {
|
if(@truncate(i32, std.time.milliTimestamp()) -% time >= messageFade) {
|
||||||
historyStart += 1;
|
historyStart += 1;
|
||||||
hideInput = main.Window.grabbed;
|
hideInput = main.Window.grabbed;
|
||||||
try refresh(true);
|
try refresh();
|
||||||
} else {
|
} else {
|
||||||
label.alpha = 1.0 - @intToFloat(f32, @truncate(i32, std.time.milliTimestamp()) -% time)/@intToFloat(f32, messageFade);
|
label.alpha = 1.0 - @intToFloat(f32, @truncate(i32, std.time.milliTimestamp()) -% time)/@intToFloat(f32, messageFade);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(hideInput != main.Window.grabbed) {
|
if(hideInput != main.Window.grabbed) {
|
||||||
hideInput = main.Window.grabbed;
|
hideInput = main.Window.grabbed;
|
||||||
try refresh(true);
|
try refresh();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +114,7 @@ pub fn addMessage(message: []const u8) Allocator.Error!void {
|
|||||||
defer mutexComponent.mutex.unlock();
|
defer mutexComponent.mutex.unlock();
|
||||||
try history.append(try Label.init(.{0, 0}, 256, message, .left));
|
try history.append(try Label.init(.{0, 0}, 256, message, .left));
|
||||||
try expirationTime.append(@truncate(i32, std.time.milliTimestamp()) +% messageTimeout);
|
try expirationTime.append(@truncate(i32, std.time.milliTimestamp()) +% messageTimeout);
|
||||||
try refresh(true);
|
try refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sendMessage() void {
|
pub fn sendMessage() void {
|
||||||
|
@ -12,12 +12,10 @@ const HorizontalList = @import("../components/HorizontalList.zig");
|
|||||||
const Label = @import("../components/Label.zig");
|
const Label = @import("../components/Label.zig");
|
||||||
const VerticalList = @import("../components/VerticalList.zig");
|
const VerticalList = @import("../components/VerticalList.zig");
|
||||||
|
|
||||||
var components: [1]GuiComponent = undefined;
|
|
||||||
pub var window = GuiWindow {
|
pub var window = GuiWindow {
|
||||||
.contentSize = Vec2f{128, 256},
|
.contentSize = Vec2f{128, 256},
|
||||||
.id = "cubyz:controls",
|
.id = "cubyz:controls",
|
||||||
.title = "Controls",
|
.title = "Controls",
|
||||||
.components = &components,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const padding: f32 = 8;
|
const padding: f32 = 8;
|
||||||
@ -58,13 +56,13 @@ pub fn onOpen() Allocator.Error!void {
|
|||||||
try list.add(row);
|
try list.add(row);
|
||||||
}
|
}
|
||||||
list.finish(.center);
|
list.finish(.center);
|
||||||
components[0] = list.toComponent();
|
window.rootComponent = list.toComponent();
|
||||||
window.contentSize = components[0].pos() + components[0].size() + @splat(2, @as(f32, padding));
|
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @splat(2, @as(f32, padding));
|
||||||
gui.updateWindowPositions();
|
gui.updateWindowPositions();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn onClose() void {
|
pub fn onClose() void {
|
||||||
for(&components) |*comp| {
|
if(window.rootComponent) |*comp| {
|
||||||
comp.deinit();
|
comp.deinit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,12 +14,10 @@ const HorizontalList = GuiComponent.HorizontalList;
|
|||||||
const VerticalList = GuiComponent.VerticalList;
|
const VerticalList = GuiComponent.VerticalList;
|
||||||
const ItemSlot = GuiComponent.ItemSlot;
|
const ItemSlot = GuiComponent.ItemSlot;
|
||||||
|
|
||||||
var components: [1]GuiComponent = undefined;
|
|
||||||
pub var window = GuiWindow {
|
pub var window = GuiWindow {
|
||||||
.contentSize = Vec2f{64*8, 64*4},
|
.contentSize = Vec2f{64*8, 64*4},
|
||||||
.title = "Creative Inventory",
|
.title = "Creative Inventory",
|
||||||
.id = "cubyz:creative_inventory",
|
.id = "cubyz:creative_inventory",
|
||||||
.components = &components,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const padding: f32 = 8;
|
const padding: f32 = 8;
|
||||||
@ -47,13 +45,13 @@ pub fn onOpen() Allocator.Error!void {
|
|||||||
try list.add(row);
|
try list.add(row);
|
||||||
}
|
}
|
||||||
list.finish(.center);
|
list.finish(.center);
|
||||||
components[0] = list.toComponent();
|
window.rootComponent = list.toComponent();
|
||||||
window.contentSize = components[0].pos() + components[0].size() + @splat(2, padding);
|
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @splat(2, padding);
|
||||||
gui.updateWindowPositions();
|
gui.updateWindowPositions();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn onClose() void {
|
pub fn onClose() void {
|
||||||
for(&components) |*comp| {
|
if(window.rootComponent) |*comp| {
|
||||||
comp.deinit();
|
comp.deinit();
|
||||||
}
|
}
|
||||||
itemStacks.deinit();
|
itemStacks.deinit();
|
||||||
|
@ -13,12 +13,10 @@ const CheckBox = @import("../components/CheckBox.zig");
|
|||||||
const Slider = @import("../components/Slider.zig");
|
const Slider = @import("../components/Slider.zig");
|
||||||
const VerticalList = @import("../components/VerticalList.zig");
|
const VerticalList = @import("../components/VerticalList.zig");
|
||||||
|
|
||||||
var components: [1]GuiComponent = undefined;
|
|
||||||
pub var window = GuiWindow {
|
pub var window = GuiWindow {
|
||||||
.contentSize = Vec2f{128, 256},
|
.contentSize = Vec2f{128, 256},
|
||||||
.id = "cubyz:graphics",
|
.id = "cubyz:graphics",
|
||||||
.title = "Graphics",
|
.title = "Graphics",
|
||||||
.components = &components,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const padding: f32 = 8;
|
const padding: f32 = 8;
|
||||||
@ -50,13 +48,13 @@ pub fn onOpen() Allocator.Error!void {
|
|||||||
try list.add(try CheckBox.init(.{0, 0}, 128, "Bloom", settings.bloom, &bloomCallback));
|
try list.add(try CheckBox.init(.{0, 0}, 128, "Bloom", settings.bloom, &bloomCallback));
|
||||||
try list.add(try CheckBox.init(.{0, 0}, 128, "Vertical Synchronization", settings.vsync, &vsyncCallback));
|
try list.add(try CheckBox.init(.{0, 0}, 128, "Vertical Synchronization", settings.vsync, &vsyncCallback));
|
||||||
list.finish(.center);
|
list.finish(.center);
|
||||||
components[0] = list.toComponent();
|
window.rootComponent = list.toComponent();
|
||||||
window.contentSize = components[0].pos() + components[0].size() + @splat(2, @as(f32, padding));
|
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @splat(2, @as(f32, padding));
|
||||||
gui.updateWindowPositions();
|
gui.updateWindowPositions();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn onClose() void {
|
pub fn onClose() void {
|
||||||
for(&components) |*comp| {
|
if(window.rootComponent) |*comp| {
|
||||||
comp.deinit();
|
comp.deinit();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,12 +11,10 @@ const GuiWindow = gui.GuiWindow;
|
|||||||
const HorizontalList = GuiComponent.HorizontalList;
|
const HorizontalList = GuiComponent.HorizontalList;
|
||||||
const ItemSlot = GuiComponent.ItemSlot;
|
const ItemSlot = GuiComponent.ItemSlot;
|
||||||
|
|
||||||
var components: [1]GuiComponent = undefined;
|
|
||||||
pub var window = GuiWindow {
|
pub var window = GuiWindow {
|
||||||
.contentSize = Vec2f{64*8, 64},
|
.contentSize = Vec2f{64*8, 64},
|
||||||
.title = "Hotbar",
|
.title = "Hotbar",
|
||||||
.id = "cubyz:hotbar",
|
.id = "cubyz:hotbar",
|
||||||
.components = &components,
|
|
||||||
.isHud = true,
|
.isHud = true,
|
||||||
.showTitleBar = false,
|
.showTitleBar = false,
|
||||||
.hasBackground = false,
|
.hasBackground = false,
|
||||||
@ -28,13 +26,13 @@ pub fn onOpen() Allocator.Error!void {
|
|||||||
try list.add(try ItemSlot.init(.{0, 0}, &Player.inventory__SEND_CHANGES_TO_SERVER.items[i]));
|
try list.add(try ItemSlot.init(.{0, 0}, &Player.inventory__SEND_CHANGES_TO_SERVER.items[i]));
|
||||||
}
|
}
|
||||||
list.finish(.{0, 0}, .center);
|
list.finish(.{0, 0}, .center);
|
||||||
components[0] = list.toComponent();
|
window.rootComponent = list.toComponent();
|
||||||
window.contentSize = components[0].size();
|
window.contentSize = window.rootComponent.?.size();
|
||||||
gui.updateWindowPositions();
|
gui.updateWindowPositions();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn onClose() void {
|
pub fn onClose() void {
|
||||||
for(&components) |*comp| {
|
if(window.rootComponent) |*comp| {
|
||||||
comp.deinit();
|
comp.deinit();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -12,12 +12,10 @@ const HorizontalList = GuiComponent.HorizontalList;
|
|||||||
const VerticalList = GuiComponent.VerticalList;
|
const VerticalList = GuiComponent.VerticalList;
|
||||||
const ItemSlot = GuiComponent.ItemSlot;
|
const ItemSlot = GuiComponent.ItemSlot;
|
||||||
|
|
||||||
var components: [1]GuiComponent = undefined;
|
|
||||||
pub var window = GuiWindow {
|
pub var window = GuiWindow {
|
||||||
.contentSize = Vec2f{64*8, 64*4},
|
.contentSize = Vec2f{64*8, 64*4},
|
||||||
.title = "Inventory",
|
.title = "Inventory",
|
||||||
.id = "cubyz:inventory",
|
.id = "cubyz:inventory",
|
||||||
.components = &components,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const padding: f32 = 8;
|
const padding: f32 = 8;
|
||||||
@ -34,13 +32,13 @@ pub fn onOpen() Allocator.Error!void {
|
|||||||
try list.add(row);
|
try list.add(row);
|
||||||
}
|
}
|
||||||
list.finish(.center);
|
list.finish(.center);
|
||||||
components[0] = list.toComponent();
|
window.rootComponent = list.toComponent();
|
||||||
window.contentSize = components[0].pos() + components[0].size() + @splat(2, padding);
|
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @splat(2, padding);
|
||||||
gui.updateWindowPositions();
|
gui.updateWindowPositions();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn onClose() void {
|
pub fn onClose() void {
|
||||||
for(&components) |*comp| {
|
if(window.rootComponent) |*comp| {
|
||||||
comp.deinit();
|
comp.deinit();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,11 +10,9 @@ const GuiWindow = gui.GuiWindow;
|
|||||||
const Button = @import("../components/Button.zig");
|
const Button = @import("../components/Button.zig");
|
||||||
const VerticalList = @import("../components/VerticalList.zig");
|
const VerticalList = @import("../components/VerticalList.zig");
|
||||||
|
|
||||||
var components: [1]GuiComponent = undefined;
|
|
||||||
pub var window = GuiWindow {
|
pub var window = GuiWindow {
|
||||||
.contentSize = Vec2f{128, 256},
|
.contentSize = Vec2f{128, 256},
|
||||||
.id = "cubyz:main",
|
.id = "cubyz:main",
|
||||||
.components = &components,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub fn buttonCallbackTest() void {
|
pub fn buttonCallbackTest() void {
|
||||||
@ -30,13 +28,13 @@ pub fn onOpen() Allocator.Error!void {
|
|||||||
try list.add(try Button.init(.{0, 0}, 128, "Settings", gui.openWindowFunction("cubyz:settings")));
|
try list.add(try Button.init(.{0, 0}, 128, "Settings", gui.openWindowFunction("cubyz:settings")));
|
||||||
try list.add(try Button.init(.{0, 0}, 128, "Exit TODO", &buttonCallbackTest));
|
try list.add(try Button.init(.{0, 0}, 128, "Exit TODO", &buttonCallbackTest));
|
||||||
list.finish(.center);
|
list.finish(.center);
|
||||||
components[0] = list.toComponent();
|
window.rootComponent = list.toComponent();
|
||||||
window.contentSize = components[0].pos() + components[0].size() + @splat(2, @as(f32, padding));
|
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @splat(2, @as(f32, padding));
|
||||||
gui.updateWindowPositions();
|
gui.updateWindowPositions();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn onClose() void {
|
pub fn onClose() void {
|
||||||
for(&components) |*comp| {
|
if(window.rootComponent) |*comp| {
|
||||||
comp.deinit();
|
comp.deinit();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -14,12 +14,10 @@ const Label = @import("../components/Label.zig");
|
|||||||
const TextInput = @import("../components/TextInput.zig");
|
const TextInput = @import("../components/TextInput.zig");
|
||||||
const VerticalList = @import("../components/VerticalList.zig");
|
const VerticalList = @import("../components/VerticalList.zig");
|
||||||
|
|
||||||
var components: [1]GuiComponent = undefined;
|
|
||||||
pub var window = GuiWindow {
|
pub var window = GuiWindow {
|
||||||
.contentSize = Vec2f{128, 256},
|
.contentSize = Vec2f{128, 256},
|
||||||
.id = "cubyz:multiplayer",
|
.id = "cubyz:multiplayer",
|
||||||
.title = "Multiplayer",
|
.title = "Multiplayer",
|
||||||
.components = &components,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var ipAddressLabel: *Label = undefined;
|
var ipAddressLabel: *Label = undefined;
|
||||||
@ -95,8 +93,8 @@ pub fn onOpen() Allocator.Error!void {
|
|||||||
try list.add(try TextInput.init(.{0, 0}, width, 32, settings.lastUsedIPAddress, &join));
|
try list.add(try TextInput.init(.{0, 0}, width, 32, settings.lastUsedIPAddress, &join));
|
||||||
try list.add(try Button.init(.{0, 0}, 100, "Join", &join));
|
try list.add(try Button.init(.{0, 0}, 100, "Join", &join));
|
||||||
list.finish(.center);
|
list.finish(.center);
|
||||||
components[0] = list.toComponent();
|
window.rootComponent = list.toComponent();
|
||||||
window.contentSize = components[0].pos() + components[0].size() + @splat(2, @as(f32, padding));
|
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @splat(2, @as(f32, padding));
|
||||||
gui.updateWindowPositions();
|
gui.updateWindowPositions();
|
||||||
|
|
||||||
thread = std.Thread.spawn(.{}, discoverIpAddressFromNewThread, .{}) catch |err| blk: {
|
thread = std.Thread.spawn(.{}, discoverIpAddressFromNewThread, .{}) catch |err| blk: {
|
||||||
@ -120,7 +118,7 @@ pub fn onClose() void {
|
|||||||
ipAddress = "";
|
ipAddress = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
for(&components) |*comp| {
|
if(window.rootComponent) |*comp| {
|
||||||
comp.deinit();
|
comp.deinit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,12 +10,10 @@ const GuiWindow = gui.GuiWindow;
|
|||||||
const Button = @import("../components/Button.zig");
|
const Button = @import("../components/Button.zig");
|
||||||
const VerticalList = @import("../components/VerticalList.zig");
|
const VerticalList = @import("../components/VerticalList.zig");
|
||||||
|
|
||||||
var components: [1]GuiComponent = undefined;
|
|
||||||
pub var window: GuiWindow = GuiWindow {
|
pub var window: GuiWindow = GuiWindow {
|
||||||
.contentSize = Vec2f{128, 256},
|
.contentSize = Vec2f{128, 256},
|
||||||
.id = "cubyz:settings",
|
.id = "cubyz:settings",
|
||||||
.title = "Settings",
|
.title = "Settings",
|
||||||
.components = &components,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const padding: f32 = 8;
|
const padding: f32 = 8;
|
||||||
@ -27,13 +25,13 @@ pub fn onOpen() Allocator.Error!void {
|
|||||||
try list.add(try Button.init(.{0, 0}, 128, "Controls", gui.openWindowFunction("cubyz:controls")));
|
try list.add(try Button.init(.{0, 0}, 128, "Controls", gui.openWindowFunction("cubyz:controls")));
|
||||||
try list.add(try Button.init(.{0, 0}, 128, "Change Name", gui.openWindowFunction("cubyz:change_name")));
|
try list.add(try Button.init(.{0, 0}, 128, "Change Name", gui.openWindowFunction("cubyz:change_name")));
|
||||||
list.finish(.center);
|
list.finish(.center);
|
||||||
components[0] = list.toComponent();
|
window.rootComponent = list.toComponent();
|
||||||
window.contentSize = components[0].pos() + components[0].size() + @splat(2, @as(f32, padding));
|
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @splat(2, @as(f32, padding));
|
||||||
gui.updateWindowPositions();
|
gui.updateWindowPositions();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn onClose() void {
|
pub fn onClose() void {
|
||||||
for(&components) |*comp| {
|
if(window.rootComponent) |*comp| {
|
||||||
comp.deinit();
|
comp.deinit();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,12 +10,10 @@ const GuiWindow = gui.GuiWindow;
|
|||||||
const Button = @import("../components/Button.zig");
|
const Button = @import("../components/Button.zig");
|
||||||
const VerticalList = @import("../components/VerticalList.zig");
|
const VerticalList = @import("../components/VerticalList.zig");
|
||||||
|
|
||||||
var components: [1]GuiComponent = undefined;
|
|
||||||
pub var window = GuiWindow {
|
pub var window = GuiWindow {
|
||||||
.contentSize = Vec2f{128, 256},
|
.contentSize = Vec2f{128, 256},
|
||||||
.id = "cubyz:sound",
|
.id = "cubyz:sound",
|
||||||
.title = "Sound TODO",
|
.title = "Sound TODO",
|
||||||
.components = &components,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const padding: f32 = 8;
|
const padding: f32 = 8;
|
||||||
@ -24,13 +22,13 @@ pub fn onOpen() Allocator.Error!void {
|
|||||||
var list = try VerticalList.init(.{padding, 16 + padding}, 300, 16);
|
var list = try VerticalList.init(.{padding, 16 + padding}, 300, 16);
|
||||||
// TODO
|
// TODO
|
||||||
list.finish(.center);
|
list.finish(.center);
|
||||||
components[0] = list.toComponent();
|
window.rootComponent = list.toComponent();
|
||||||
window.contentSize = components[0].pos() + components[0].size() + @splat(2, @as(f32, padding));
|
window.contentSize = window.rootComponent.?.pos() + window.rootComponent.?.size() + @splat(2, @as(f32, padding));
|
||||||
gui.updateWindowPositions();
|
gui.updateWindowPositions();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn onClose() void {
|
pub fn onClose() void {
|
||||||
for(&components) |*comp| {
|
if(window.rootComponent) |*comp| {
|
||||||
comp.deinit();
|
comp.deinit();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1048,7 +1048,7 @@ const Tool = struct {
|
|||||||
if(self.tooltip) |tooltip| return tooltip;
|
if(self.tooltip) |tooltip| return tooltip;
|
||||||
self.tooltip = try std.fmt.allocPrint(
|
self.tooltip = try std.fmt.allocPrint(
|
||||||
main.globalAllocator,
|
main.globalAllocator,
|
||||||
\\Time to swing: {} s
|
\\Time to swing: {d:.2} s
|
||||||
\\Pickaxe power: {} %
|
\\Pickaxe power: {} %
|
||||||
\\Axe power: {} %
|
\\Axe power: {} %
|
||||||
\\Shover power: {} %
|
\\Shover power: {} %
|
||||||
|
Loading…
x
Reference in New Issue
Block a user