Initial menu system by claude

This commit is contained in:
2026-04-14 02:05:15 -04:00
parent 07b90ced1a
commit 49331773bf
10 changed files with 149 additions and 14 deletions

View File

@@ -33,10 +33,10 @@ function moveto(x, y)
tangible.animate{tan=actor, anim={action="moveto", xyz={x, y, z}, facing=math.auto}}
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)
function cube.lookmenu(add)
add("Cube Hi", function () dprint("Doing Cube Hi") end)
add("Cube Bye", function () dprint("Doing Cube Bye") end)
add("Cube Yo", function () dprint("Doing Cube Yo") end)
end
function sphere.lookhotkeys(add)
@@ -60,6 +60,12 @@ function engio.getlookat()
return "hotkeys"
end
-- if the class has a function 'lookmenu', then the correct
-- look-at widget is 'menu'.
if class.lookmenu ~= nil then
return "menu"
end
-- otherwise, if the class has a function 'getlookat', use that.
if class.getlookat ~= nil then
return class.getlookat()

68
luprex/lua/menu.lua Normal file
View File

@@ -0,0 +1,68 @@
----------------------------------------------------------------
--
-- To add a menu to an object (such as a Brick Oven), you will
-- be adding a function 'lookmenu' to the appropriate class,
-- like this:
--
-- function brickoven.lookmenu(add)
-- add("Light Oven", function () ... end)
-- add("Add Fuel", function () ... end)
-- end
--
-- This function will get called twice: once in a 'probe' when
-- Unreal wants to know what menu items exist, and a second time
-- in an 'invoke' to find the right closure. The 'add' function
-- which is passed in can therefore be one of two functions.
--
-- In probe mode, the goal is to build up an array that looks
-- like this:
--
-- {"Light Oven", "Add Fuel"}
--
-- So therefore, in probe mode, the 'add' function is a closure
-- that adds the label to the array.
--
-- 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 label to the menu item which was already
-- selected. If there's a match, it records the closure.
--
----------------------------------------------------------------
makeclass('engio')
function engio.getmenu()
local class = tangible.getclass(place)
-- if the tangible doesn't have a 'lookmenu' function, do nothing
if class == nil or class.lookmenu == nil then
return {}
end
local items = {}
local add = function(label, closure)
table.insert(items, label)
end
class.lookmenu(add)
return items
end
function engio.pressmenu(label)
local class = tangible.getclass(place)
-- if the tangible doesn't have a 'lookmenu' function, do nothing
if class == nil or class.lookmenu == nil then
return
end
local result = nil
local add = function(lbl, closure)
if (lbl == label) then
result = closure
end
end
class.lookmenu(add)
if result ~= nil then
result()
end
end