From d4072abc2bc65e5c7abd64eef9e2be6166b32ec4 Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Sun, 19 Nov 2023 10:51:45 +0200 Subject: [PATCH] lua: add edicts menu with 'move to' feature progress #96 --- Misc/qs_pak/scripts/menus.lua | 58 +++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/Misc/qs_pak/scripts/menus.lua b/Misc/qs_pak/scripts/menus.lua index 76ac299c..be15aaa7 100644 --- a/Misc/qs_pak/scripts/menus.lua +++ b/Misc/qs_pak/scripts/menus.lua @@ -123,3 +123,61 @@ function menu.listpage() onkeypress = listpage_keypress, } end + + +local vec3origin = vec3.new() +local foreach = edicts.foreach +local isfree = edicts.isfree +local getname = 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: ', 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