From f9079be9cafedb4bd8ab6288049b5b51c86b3154 Mon Sep 17 00:00:00 2001 From: IntegratedQuantum Date: Mon, 9 Sep 2024 21:11:59 +0200 Subject: [PATCH] T to open chat. extracted from #412 fixes the first half of #428 --- src/gui/components/TextInput.zig | 8 ++++++++ src/gui/windows/chat.zig | 2 +- src/main.zig | 7 +++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/gui/components/TextInput.zig b/src/gui/components/TextInput.zig index 9dea21c8..ec619560 100644 --- a/src/gui/components/TextInput.zig +++ b/src/gui/components/TextInput.zig @@ -134,6 +134,14 @@ pub fn mainButtonReleased(self: *TextInput, mousePosition: Vec2f) void { } } +pub fn select(self: *TextInput) void { + gui.setSelectedTextInput(self); + self.pressed = false; + self.selectionStart = null; + if(self.cursor == null) + self.cursor = @intCast(self.currentString.items.len); +} + pub fn deselect(self: *TextInput) void { self.cursor = null; self.selectionStart = null; diff --git a/src/gui/windows/chat.zig b/src/gui/windows/chat.zig index fcd94a9f..56585d9d 100644 --- a/src/gui/windows/chat.zig +++ b/src/gui/windows/chat.zig @@ -36,7 +36,7 @@ var messageQueue: main.List([]const u8) = undefined; var expirationTime: main.List(i32) = undefined; var historyStart: u32 = 0; var fadeOutEnd: u32 = 0; -var input: *TextInput = undefined; +pub var input: *TextInput = undefined; var hideInput: bool = true; fn refresh() void { diff --git a/src/main.zig b/src/main.zig index 05610b0a..bce8039b 100644 --- a/src/main.zig +++ b/src/main.zig @@ -268,6 +268,12 @@ fn openCreativeInventory() void { gui.toggleGameMenu(); gui.openWindow("creative_inventory"); } +fn openChat() void { + if(game.world == null) return; + ungrabMouse(); + gui.openWindow("chat"); + gui.windowlist.chat.input.select(); +} fn takeBackgroundImageFn() void { if(game.world == null) return; renderer.MenuBackGround.takeBackgroundImage(); @@ -324,6 +330,7 @@ pub const KeyBoard = struct { // MARK: KeyBoard .{.name = "escape", .key = c.GLFW_KEY_ESCAPE, .releaseAction = &escape}, .{.name = "openInventory", .key = c.GLFW_KEY_E, .releaseAction = &openInventory}, .{.name = "openCreativeInventory(aka cheat inventory)", .key = c.GLFW_KEY_C, .releaseAction = &openCreativeInventory}, + .{.name = "openChat", .key = c.GLFW_KEY_T, .releaseAction = &openChat}, .{.name = "mainGuiButton", .mouseButton = c.GLFW_MOUSE_BUTTON_LEFT, .pressAction = &gui.mainButtonPressed, .releaseAction = &gui.mainButtonReleased}, .{.name = "secondaryGuiButton", .mouseButton = c.GLFW_MOUSE_BUTTON_RIGHT, .pressAction = &gui.secondaryButtonPressed, .releaseAction = &gui.secondaryButtonReleased}, // text: