From be0406df092157344203241d8b8f66c4befe5688 Mon Sep 17 00:00:00 2001 From: IntegratedQuantum Date: Thu, 4 Jul 2024 10:47:46 +0200 Subject: [PATCH] Hotbar shortcut keys fixes #343 --- src/main.zig | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/main.zig b/src/main.zig index d4f4cb70..d063f39c 100644 --- a/src/main.zig +++ b/src/main.zig @@ -288,6 +288,13 @@ fn toggleNetworkDebugOverlay() void { fn toggleAdvancedNetworkDebugOverlay() void { gui.toggleWindow("debug_network_advanced"); } +fn setHotbarSlot(i: comptime_int) *const fn() void { + return &struct { + fn set() void { + game.Player.selectedSlot = i - 1; + } + }.set; +} pub const KeyBoard = struct { const c = Window.c; @@ -331,6 +338,20 @@ pub const KeyBoard = struct { .{.name = "textCut", .key = c.GLFW_KEY_X, .repeatAction = &gui.textCallbacks.cut}, .{.name = "textNewline", .key = c.GLFW_KEY_ENTER, .repeatAction = &gui.textCallbacks.newline}, + // Hotbar shortcuts: + .{.name = "Hotbar 1", .key = c.GLFW_KEY_1, .releaseAction = setHotbarSlot(1)}, + .{.name = "Hotbar 2", .key = c.GLFW_KEY_2, .releaseAction = setHotbarSlot(2)}, + .{.name = "Hotbar 3", .key = c.GLFW_KEY_3, .releaseAction = setHotbarSlot(3)}, + .{.name = "Hotbar 4", .key = c.GLFW_KEY_4, .releaseAction = setHotbarSlot(4)}, + .{.name = "Hotbar 5", .key = c.GLFW_KEY_5, .releaseAction = setHotbarSlot(5)}, + .{.name = "Hotbar 6", .key = c.GLFW_KEY_6, .releaseAction = setHotbarSlot(6)}, + .{.name = "Hotbar 7", .key = c.GLFW_KEY_7, .releaseAction = setHotbarSlot(7)}, + .{.name = "Hotbar 8", .key = c.GLFW_KEY_8, .releaseAction = setHotbarSlot(8)}, + .{.name = "Hotbar 9", .key = c.GLFW_KEY_9, .releaseAction = setHotbarSlot(9)}, + .{.name = "Hotbar 10", .key = c.GLFW_KEY_0, .releaseAction = setHotbarSlot(10)}, + .{.name = "Hotbar 11", .key = c.GLFW_KEY_MINUS, .releaseAction = setHotbarSlot(11)}, + .{.name = "Hotbar 12", .key = c.GLFW_KEY_EQUAL, .releaseAction = setHotbarSlot(12)}, + // debug: .{.name = "hideMenu", .key = c.GLFW_KEY_F1, .releaseAction = &toggleHideGui}, .{.name = "debugOverlay", .key = c.GLFW_KEY_F3, .releaseAction = &toggleDebugOverlay},