From f3d9a903d207c4bd9a73c8bd8f7e80f110affb68 Mon Sep 17 00:00:00 2001 From: jyelon Date: Mon, 13 Apr 2026 16:08:23 -0400 Subject: [PATCH] Fixed hotkey up/down handling --- Content/Widgets/WB_Hotkey_Image.uasset | 4 +- Content/Widgets/WB_Hotkeys.uasset | 4 +- luprex/lua/hotkeys.lua | 102 +++++++++++-------------- luprex/lua/login.lua | 44 ++--------- 4 files changed, 58 insertions(+), 96 deletions(-) diff --git a/Content/Widgets/WB_Hotkey_Image.uasset b/Content/Widgets/WB_Hotkey_Image.uasset index 0171198f..acda467b 100644 --- a/Content/Widgets/WB_Hotkey_Image.uasset +++ b/Content/Widgets/WB_Hotkey_Image.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:5437cb06ec6b2d6509de6d4049d30c69e35745502d650c03b34d0d2f22ba7baf -size 101565 +oid sha256:4885d6b537c7a1201235b79a02236d8df9b6b0226d225011f188552c91112c97 +size 93841 diff --git a/Content/Widgets/WB_Hotkeys.uasset b/Content/Widgets/WB_Hotkeys.uasset index 2a3a7852..892ec115 100644 --- a/Content/Widgets/WB_Hotkeys.uasset +++ b/Content/Widgets/WB_Hotkeys.uasset @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:602a372b5e164a5a33e06090523e4de6261699a7c46b5d1c4705ea3c549c8545 -size 260266 +oid sha256:1c07761aa894113030bda3d0883719044b02a9b1b61705e36183c33f3826344d +size 323810 diff --git a/luprex/lua/hotkeys.lua b/luprex/lua/hotkeys.lua index 28db88d5..cf81f353 100644 --- a/luprex/lua/hotkeys.lua +++ b/luprex/lua/hotkeys.lua @@ -4,77 +4,67 @@ -- be adding a function 'lookhotkeys' to the appropriate class, -- like this: -- --- function brickoven.lookhotkeys(keys) --- keys:add("X", "Light Oven", function () ... end) --- keys:add("A", "Add Fuel", function () ... end) +-- function brickoven.lookhotkeys(add) +-- add("X", "Light Oven", function () ... end) +-- add("A", "Add Fuel", function () ... end) -- end -- -- This function will get called twice: once in a 'probe' when -- Unreal wants to know what hotkeys exist, and a second time in --- an 'invoke' to find the right closure. +-- an 'invoke' to find the right closure. The 'add' function +-- which is passed in can therefore be one of two functions. -- --- When the probe happens, we construct a "hotkeylist" to hold --- the complete list of hotkeys. We populate this hotkeylist as --- follows: +-- In probe mode, the goal is to build up an array that looks +-- like this: -- --- local keys = hotkeylist.create() --- brickoven.lookhotkeys(keys) --- --- At this point, if you were to pprint(keys), the output would --- look like this: +-- {"X", "Light Oven", "A", "Add Fuel"} -- --- { "X", "Light Oven", "A", "Add Fuel" } +-- So therefore, in probe mode, the 'add' function is a closure +-- that adds the hotkey and the action to the array. -- --- Notice that a hotkeylist doesn't store the closures, they are --- silently ignored. The resulting array is in a format that can --- be returned directly to Unreal. --- --- Later, when the user presses a key, such as the "Light Oven" key, --- we will construct a "hotkeypress" object whose job is to record --- the name of the hotkey that was pressed, and the closure that --- goes with it. We populate this object as follows: --- --- local keys = hotkeypress.create("Light Oven") --- brickoven.lookhotkeys(keys) --- --- So as you can see, we're using the same 'brickoven.lookhotkeys' --- function, but this time, we've passed in a parameter of class --- hotkeypress instead of a parameter of class hotkeylist. This --- changes the behavior of the 'add' method: the add function of --- a hotkeylist stores all the hotkeys into the list. But the 'add' --- function of a hotkeypress only stores the one closure that --- we are interested in. If you were to pprint(keys), the result --- would look like this: --- --- { pressed="Light Oven", closure= } --- --- So the only data stored by a 'hotkeypress' object is the name --- of the pressed hotkey, and the closure that goes with it. +-- In invoke mode, the goal is to find the right closure. So +-- therefore, in invoke mode, the 'add' function is a closure +-- that compares the action to the button which was already +-- pressed. If there's a match, it records the closure. -- ---------------------------------------------------------------- -makeclass("hotkeylist") -makeclass("hotkeypress") +makeclass('engio') -function hotkeylist.create() - local result = {} - setmetatable(result, hotkeylist) - return result +function engio.gethotkeys() + local class = tangible.getclass(place) + + -- if the tangible doesn't have a 'lookhotkeys' function, do nothing + if class == nil or class.lookhotkeys == nil then + return {} + end + + local keys = {} + local add = function(key, action, closure) + table.insert(keys, key) + table.insert(keys, action) + end + class.lookhotkeys(add) + return keys end -function hotkeylist.add(self, key, action, closure) - table.insert(self, key) - table.insert(self, action) -end +function engio.presshotkey(pressed) + local class = tangible.getclass(place) -function hotkeypress.create(key) - local result = { pressed=key } - setmetatable(result, hotkeypress) - return result -end + -- if the tangible doesn't have a 'lookhotkeys' function, do nothing + if class == nil or class.lookhotkeys == nil then + return + end -function hotkeypress.add(self, key, action, closure) - if action == self.pressed then - self.closure = closure + local result = nil + local add = function(key, action, closure) + if (action == pressed) then + result = closure + end + end + class.lookhotkeys(add) + if result ~= nil then + result() end end + diff --git a/luprex/lua/login.lua b/luprex/lua/login.lua index 3fa28283..0857b939 100644 --- a/luprex/lua/login.lua +++ b/luprex/lua/login.lua @@ -33,16 +33,16 @@ function moveto(x, y) tangible.animate{tan=actor, anim={action="moveto", xyz={x, y, z}, facing=math.auto}} end -function cube.lookhotkeys(keys) - keys:add("Z", "Cube Hi", function () dprint("Doing Cube Hi") end) - keys:add("X", "Cube Bye", function () dprint("Doing Cube Bye") end) - keys:add("C", "Cube Yo", function () dprint("Doing Cube Yo") end) +function cube.lookhotkeys(add) + add("Z", "Cube Hi", function () dprint("Doing Cube Hi") end) + add("X", "Cube Bye", function () dprint("Doing Cube Bye") end) + add("C", "Cube Yo", function () dprint("Doing Cube Yo") end) end -function sphere.lookhotkeys(keys) - keys:add("Z", "Sphere Hi", function () dprint("Doing Sphere Hi") end) - keys:add("X", "Sphere Bye", function () dprint("Doing Sphere Bye") end) - keys:add("C", "Sphere Yo", function () dprint("Doing Sphere Yo") end) +function sphere.lookhotkeys(add) + add("Z", "Sphere Hi", function () dprint("Doing Sphere Hi") end) + add("X", "Sphere Bye", function () dprint("Doing Sphere Bye") end) + add("C", "Sphere Yo", function () dprint("Doing Sphere Yo") end) end @@ -69,35 +69,7 @@ function engio.getlookat() return "" end -function engio.gethotkeys() - local class = tangible.getclass(place) - -- if the tangible doesn't have a 'lookhotkeys' function, do nothing - if class == nil or class.lookhotkeys == nil then - return {} - end - - local keys = hotkeylist.create() - class.lookhotkeys(keys) - setmetatable(keys, nil) - return keys -end - -function engio.presshotkey(action) - local class = tangible.getclass(place) - - -- if the tangible doesn't have a 'lookhotkeys' function, do nothing - if class == nil or class.lookhotkeys == nil then - return - end - - local press = hotkeypress.create(action) - class.lookhotkeys(press) - local closure = press.closure - if closure ~= nil then - closure() - end -end function jp3() tangible.animate{tan=actor, anim={action="play", seq="jump"}}