Skip to content

Commit

Permalink
lua: add edicts menu with 'move to' feature
Browse files Browse the repository at this point in the history
progress #96
  • Loading branch information
alexey-lysiuk committed Nov 19, 2023
1 parent eb50c64 commit d4072ab
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions Misc/qs_pak/scripts/menus.lua
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,61 @@ function menu.listpage()
onkeypress = listpage_keypress,
}
end


local vec3origin <const> = vec3.new()
local foreach <const> = edicts.foreach
local isfree <const> = edicts.isfree
local getname <const> = edicts.getname


local function edictspage_keypress(page, keycode)
if keycode == key_enter then
local location = page.entries[page.cursor].location

if location ~= vec3origin then
player.safemove(location)
menu.poppage()
end
else
listpage_keypress(page, keycode)
end
end

function menu.edictspage()
local page = menu.listpage()
page.title = 'Edicts'
page.cursor = 1
page.onkeypress = edictspage_keypress

local function addedict(edict, current)
local text, location

if isfree(edict) then
text = string.format('%i: <FREE>', current)
location = vec3origin
else
local origin = edict.origin or vec3origin
local min = edict.absmin or vec3origin
local max = edict.absmax or vec3origin

location = origin == vec3origin and vec3.mid(min, max) or origin
text = string.format('%i: %s at %s', current, getname(edict), location)
end

local entry = { text = text, location = location }
page.entries[#page.entries + 1] = entry

return current + 1
end

edicts.foreach(addedict)

return page
end


function console.menu_edicts()
menu.clearpages()
menu.pushpage(menu.edictspage())
end

0 comments on commit d4072ab

Please sign in to comment.