mirror of
https://github.com/PixelGuys/Cubyz.git
synced 2025-08-04 03:37:59 -04:00
Title bars can now be revealed by pressing a button in the pause menu.
This removes the ugly triangle from the top left of all windows and makes it harder to accidentally move around windows. fixes #536
This commit is contained in:
parent
4d7192c2fe
commit
669ab890cc
Binary file not shown.
Before Width: | Height: | Size: 2.1 KiB |
@ -55,7 +55,6 @@ relativePosition: [2]RelativePosition = .{.{.ratio = 0.5}, .{.ratio = 0.5}},
|
|||||||
id: []const u8 = undefined,
|
id: []const u8 = undefined,
|
||||||
rootComponent: ?GuiComponent = null,
|
rootComponent: ?GuiComponent = null,
|
||||||
showTitleBar: bool = true,
|
showTitleBar: bool = true,
|
||||||
titleBarExpanded: bool = false,
|
|
||||||
hasBackground: bool = true,
|
hasBackground: bool = true,
|
||||||
hideIfMouseIsGrabbed: bool = true, // TODO: Allow the user to change this with a button, to for example leave the inventory open while playing.
|
hideIfMouseIsGrabbed: bool = true, // TODO: Allow the user to change this with a button, to for example leave the inventory open while playing.
|
||||||
closeIfMouseIsGrabbed: bool = false,
|
closeIfMouseIsGrabbed: bool = false,
|
||||||
@ -85,7 +84,6 @@ var titleTexture: Texture = undefined;
|
|||||||
var closeTexture: Texture = undefined;
|
var closeTexture: Texture = undefined;
|
||||||
var zoomInTexture: Texture = undefined;
|
var zoomInTexture: Texture = undefined;
|
||||||
var zoomOutTexture: Texture = undefined;
|
var zoomOutTexture: Texture = undefined;
|
||||||
var expandTitleBarTexture: Texture = undefined;
|
|
||||||
var shader: Shader = undefined;
|
var shader: Shader = undefined;
|
||||||
var windowUniforms: struct {
|
var windowUniforms: struct {
|
||||||
screen: c_int,
|
screen: c_int,
|
||||||
@ -119,7 +117,6 @@ pub fn __init() void {
|
|||||||
closeTexture = Texture.initFromFile("assets/cubyz/ui/window_close.png");
|
closeTexture = Texture.initFromFile("assets/cubyz/ui/window_close.png");
|
||||||
zoomInTexture = Texture.initFromFile("assets/cubyz/ui/window_zoom_in.png");
|
zoomInTexture = Texture.initFromFile("assets/cubyz/ui/window_zoom_in.png");
|
||||||
zoomOutTexture = Texture.initFromFile("assets/cubyz/ui/window_zoom_out.png");
|
zoomOutTexture = Texture.initFromFile("assets/cubyz/ui/window_zoom_out.png");
|
||||||
expandTitleBarTexture = Texture.initFromFile("assets/cubyz/ui/window_expand.png");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn __deinit() void {
|
pub fn __deinit() void {
|
||||||
@ -132,7 +129,7 @@ pub fn defaultFunction() void {}
|
|||||||
|
|
||||||
pub fn mainButtonPressed(self: *const GuiWindow, mousePosition: Vec2f) void {
|
pub fn mainButtonPressed(self: *const GuiWindow, mousePosition: Vec2f) void {
|
||||||
const scaledMousePos = (mousePosition - self.pos)/@as(Vec2f, @splat(self.scale));
|
const scaledMousePos = (mousePosition - self.pos)/@as(Vec2f, @splat(self.scale));
|
||||||
if(scaledMousePos[1] < 16 and (self.showTitleBar or self.titleBarExpanded or (!main.Window.grabbed and scaledMousePos[0] < 16))) {
|
if(scaledMousePos[1] < 16 and (self.showTitleBar or gui.reorderWindows)) {
|
||||||
grabbedWindow = self;
|
grabbedWindow = self;
|
||||||
grabPosition = mousePosition;
|
grabPosition = mousePosition;
|
||||||
selfPositionWhenGrabbed = self.pos;
|
selfPositionWhenGrabbed = self.pos;
|
||||||
@ -147,12 +144,7 @@ pub fn mainButtonPressed(self: *const GuiWindow, mousePosition: Vec2f) void {
|
|||||||
|
|
||||||
pub fn mainButtonReleased(self: *GuiWindow, mousePosition: Vec2f) void {
|
pub fn mainButtonReleased(self: *GuiWindow, mousePosition: Vec2f) void {
|
||||||
if(grabPosition != null and @reduce(.And, grabPosition.? == mousePosition) and grabbedWindow == self) {
|
if(grabPosition != null and @reduce(.And, grabPosition.? == mousePosition) and grabbedWindow == self) {
|
||||||
if(!self.showTitleBar) {
|
if(self.showTitleBar or gui.reorderWindows) {
|
||||||
if(mousePosition[0] - self.pos[0] < 16*self.scale) {
|
|
||||||
self.titleBarExpanded = !self.titleBarExpanded;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(self.showTitleBar or self.titleBarExpanded) {
|
|
||||||
if(mousePosition[0] - self.pos[0] > self.size[0] - 48*self.scale) {
|
if(mousePosition[0] - self.pos[0] > self.size[0] - 48*self.scale) {
|
||||||
if(mousePosition[0] - self.pos[0] > self.size[0] - 32*self.scale) {
|
if(mousePosition[0] - self.pos[0] > self.size[0] - 32*self.scale) {
|
||||||
if(mousePosition[0] - self.pos[0] > self.size[0] - 16*self.scale) {
|
if(mousePosition[0] - self.pos[0] > self.size[0] - 16*self.scale) {
|
||||||
@ -327,7 +319,7 @@ pub fn update(self: *GuiWindow) void {
|
|||||||
pub fn updateSelected(self: *GuiWindow, mousePosition: Vec2f) void {
|
pub fn updateSelected(self: *GuiWindow, mousePosition: Vec2f) void {
|
||||||
self.updateSelectedFn();
|
self.updateSelectedFn();
|
||||||
const windowSize = main.Window.getWindowSize()/@as(Vec2f, @splat(gui.scale));
|
const windowSize = main.Window.getWindowSize()/@as(Vec2f, @splat(gui.scale));
|
||||||
if(self == grabbedWindow and (self.titleBarExpanded or self.showTitleBar)) if(grabPosition) |_grabPosition| {
|
if(self == grabbedWindow and (gui.reorderWindows or self.showTitleBar)) if(grabPosition) |_grabPosition| {
|
||||||
self.relativePosition[0] = .{.ratio = undefined};
|
self.relativePosition[0] = .{.ratio = undefined};
|
||||||
self.relativePosition[1] = .{.ratio = undefined};
|
self.relativePosition[1] = .{.ratio = undefined};
|
||||||
self.pos = (mousePosition - _grabPosition) + selfPositionWhenGrabbed;
|
self.pos = (mousePosition - _grabPosition) + selfPositionWhenGrabbed;
|
||||||
@ -466,36 +458,20 @@ pub fn render(self: *const GuiWindow, mousePosition: Vec2f) void {
|
|||||||
if(self.rootComponent) |*component| {
|
if(self.rootComponent) |*component| {
|
||||||
component.render((mousePosition - self.pos)/@as(Vec2f, @splat(self.scale)));
|
component.render((mousePosition - self.pos)/@as(Vec2f, @splat(self.scale)));
|
||||||
}
|
}
|
||||||
if(self.showTitleBar) {
|
if(self.showTitleBar or gui.reorderWindows) {
|
||||||
shader.bind();
|
shader.bind();
|
||||||
titleTexture.bindTo(0);
|
titleTexture.bindTo(0);
|
||||||
draw.setColor(0xff000000);
|
draw.setColor(0xff000000);
|
||||||
draw.customShadedRect(windowUniforms, .{0, 0}, .{self.size[0]/self.scale, 18});
|
draw.customShadedRect(windowUniforms, .{0, 0}, .{self.size[0]/self.scale, 18});
|
||||||
self.drawIcons();
|
self.drawIcons();
|
||||||
} else if(!main.Window.grabbed) {
|
|
||||||
if(self.titleBarExpanded) {
|
|
||||||
shader.bind();
|
|
||||||
titleTexture.bindTo(0);
|
|
||||||
draw.setColor(0xff000000);
|
|
||||||
draw.customShadedRect(windowUniforms, .{0, 0}, .{self.size[0]/self.scale, 18});
|
|
||||||
self.drawIcons();
|
|
||||||
expandTitleBarTexture.render(.{0, 0}, .{18, 18});
|
|
||||||
} else {
|
|
||||||
shader.bind();
|
|
||||||
titleTexture.bindTo(0);
|
|
||||||
draw.setColor(0xff000000);
|
|
||||||
draw.customShadedRect(windowUniforms, .{0, 0}, .{18, 18});
|
|
||||||
draw.setColor(0xffffffff);
|
|
||||||
expandTitleBarTexture.render(.{0, 0}, .{18, 18});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if(self.hasBackground or (!main.Window.grabbed and self.titleBarExpanded)) {
|
if(self.hasBackground or (!main.Window.grabbed and gui.reorderWindows)) {
|
||||||
draw.setColor(0xff1d1d1d);
|
draw.setColor(0xff1d1d1d);
|
||||||
draw.rectBorder(.{-2, -2}, self.size/@as(Vec2f, @splat(self.scale)) + Vec2f{4, 4}, 2.0);
|
draw.rectBorder(.{-2, -2}, self.size/@as(Vec2f, @splat(self.scale)) + Vec2f{4, 4}, 2.0);
|
||||||
}
|
}
|
||||||
draw.restoreTranslation(oldTranslation);
|
draw.restoreTranslation(oldTranslation);
|
||||||
draw.restoreScale(oldScale);
|
draw.restoreScale(oldScale);
|
||||||
if(self == grabbedWindow and (self.titleBarExpanded or self.showTitleBar) and grabPosition != null) {
|
if(self == grabbedWindow and (gui.reorderWindows or self.showTitleBar) and grabPosition != null) {
|
||||||
self.drawOrientationLines();
|
self.drawOrientationLines();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -29,6 +29,7 @@ pub var openWindows: List(*GuiWindow) = undefined;
|
|||||||
var selectedWindow: ?*GuiWindow = null;
|
var selectedWindow: ?*GuiWindow = null;
|
||||||
pub var selectedTextInput: ?*TextInput = null;
|
pub var selectedTextInput: ?*TextInput = null;
|
||||||
var hoveredAWindow: bool = false;
|
var hoveredAWindow: bool = false;
|
||||||
|
pub var reorderWindows: bool = false;
|
||||||
|
|
||||||
pub var scale: f32 = undefined;
|
pub var scale: f32 = undefined;
|
||||||
|
|
||||||
@ -341,6 +342,7 @@ pub fn openHud() void {
|
|||||||
openWindowFromRef(window);
|
openWindowFromRef(window);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
reorderWindows = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn openWindowCallbackFunction(windowPtr: usize) void {
|
fn openWindowCallbackFunction(windowPtr: usize) void {
|
||||||
@ -563,6 +565,7 @@ pub fn toggleGameMenu() void {
|
|||||||
i += 1;
|
i += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
reorderWindows = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,9 +25,9 @@ pub var window = GuiWindow {
|
|||||||
pub fn render() void {
|
pub fn render() void {
|
||||||
draw.setColor(0xffffffff);
|
draw.setColor(0xffffffff);
|
||||||
var y: f32 = 0;
|
var y: f32 = 0;
|
||||||
draw.print(" fps: {d:.0} Hz{s}", .{1.0/main.lastFrameTime.load(.monotonic), if(main.settings.vsync) @as([]const u8, " (vsync)") else ""}, 0, y, 8, .left);
|
draw.print("fps: {d:.0} Hz{s}", .{1.0/main.lastFrameTime.load(.monotonic), if(main.settings.vsync) @as([]const u8, " (vsync)") else ""}, 0, y, 8, .left);
|
||||||
y += 8;
|
y += 8;
|
||||||
draw.print(" frameTime: {d:.1} ms", .{main.lastFrameTime.load(.monotonic)*1000.0}, 0, y, 8, .left);
|
draw.print("frameTime: {d:.1} ms", .{main.lastFrameTime.load(.monotonic)*1000.0}, 0, y, 8, .left);
|
||||||
y += 8;
|
y += 8;
|
||||||
draw.print("window size: {}×{}", .{main.Window.width, main.Window.height}, 0, y, 8, .left);
|
draw.print("window size: {}×{}", .{main.Window.width, main.Window.height}, 0, y, 8, .left);
|
||||||
y += 8;
|
y += 8;
|
||||||
|
@ -15,6 +15,9 @@ pub var window = GuiWindow {
|
|||||||
|
|
||||||
const padding: f32 = 8;
|
const padding: f32 = 8;
|
||||||
|
|
||||||
|
fn reorderHudCallbackFunction(_: usize) void {
|
||||||
|
gui.reorderWindows = !gui.reorderWindows;
|
||||||
|
}
|
||||||
fn exitMenuCallbackFunction(_: usize) void {
|
fn exitMenuCallbackFunction(_: usize) void {
|
||||||
if(main.game.world) |world| {
|
if(main.game.world) |world| {
|
||||||
world.deinit();
|
world.deinit();
|
||||||
@ -28,6 +31,7 @@ pub fn onOpen() void {
|
|||||||
list.add(Button.initText(.{0, 0}, 128, "Invite Player", gui.openWindowCallback("invite")));
|
list.add(Button.initText(.{0, 0}, 128, "Invite Player", gui.openWindowCallback("invite")));
|
||||||
}
|
}
|
||||||
list.add(Button.initText(.{0, 0}, 128, "Settings", gui.openWindowCallback("settings")));
|
list.add(Button.initText(.{0, 0}, 128, "Settings", gui.openWindowCallback("settings")));
|
||||||
|
list.add(Button.initText(.{0, 0}, 128, "Reorder HUD", .{.callback = &reorderHudCallbackFunction}));
|
||||||
list.add(Button.initText(.{0, 0}, 128, "Exit to Menu TODO", .{
|
list.add(Button.initText(.{0, 0}, 128, "Exit to Menu TODO", .{
|
||||||
.callback = &exitMenuCallbackFunction,
|
.callback = &exitMenuCallbackFunction,
|
||||||
}));
|
}));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user