mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-29 12:16:37 +09:00
Start converting GUI modules
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
local Event = require("modules/exp_legacy/utils/event")
|
||||
local Storage = require("modules/exp_util/storage")
|
||||
local Gui = require("modules.exp_legacy.utils.gui")
|
||||
local Model = require("modules.exp_legacy.modules.gui.debug.model")
|
||||
|
||||
@@ -21,6 +22,11 @@ local checkbox_name = Gui.uid_name()
|
||||
local filter_name = Gui.uid_name()
|
||||
local clear_filter_name = Gui.uid_name()
|
||||
|
||||
local storage = {}
|
||||
Storage.register(storage, function(tbl)
|
||||
storage = tbl
|
||||
end)
|
||||
|
||||
-- storage tables
|
||||
local enabled = {}
|
||||
local last_events = {}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
local Gui = require("modules.exp_legacy.utils.gui") --- @dep utils.gui
|
||||
local ExpGui = require("modules.exp_legacy.expcore.gui")
|
||||
local ExpElement = require("modules/exp_gui/prototype")
|
||||
local Color = require("modules/exp_util/include/color")
|
||||
|
||||
local Gui = require("modules.exp_legacy.utils.gui") --- @dep utils.gui
|
||||
local Model = require("modules.exp_legacy.modules.gui.debug.model") --- @dep modules.gui.debug.model
|
||||
|
||||
local dump = Model.dump
|
||||
@@ -24,9 +25,10 @@ function Public.show(container)
|
||||
local left_panel_style = left_panel.style
|
||||
left_panel_style.width = 300
|
||||
|
||||
for element_id, file_path in pairs(ExpGui.file_paths) do
|
||||
local header = left_panel.add{ type = "flow" }.add{ type = "label", name = header_name, caption = element_id .. " - " .. file_path }
|
||||
Gui.set_data(header, element_id)
|
||||
--- @diagnostic disable-next-line invisible
|
||||
for element_name in pairs(ExpElement._elements) do
|
||||
local header = left_panel.add{ type = "flow" }.add{ type = "label", name = header_name, caption = element_name }
|
||||
Gui.set_data(header, element_name)
|
||||
end
|
||||
|
||||
local right_flow = main_flow.add{ type = "flow", direction = "vertical" }
|
||||
@@ -70,7 +72,7 @@ Gui.on_click(
|
||||
header_name,
|
||||
function(event)
|
||||
local element = event.element
|
||||
local element_id = Gui.get_data(element)
|
||||
local element_name = Gui.get_data(element)
|
||||
|
||||
local left_panel = element.parent.parent
|
||||
local data = Gui.get_data(left_panel)
|
||||
@@ -85,10 +87,11 @@ Gui.on_click(
|
||||
element.style.font_color = Color.orange
|
||||
data.selected_header = element
|
||||
|
||||
input_text_box.text = concat{ "Gui.defines[", element_id, "]" }
|
||||
input_text_box.text = concat{ "ExpElement._elements[", element_name, "]" }
|
||||
input_text_box.style.font_color = Color.black
|
||||
|
||||
local content = dump(ExpGui.debug_info[element_id]) or "nil"
|
||||
--- @diagnostic disable-next-line invisible
|
||||
local content = dump(ExpElement._elements[element_name]) or "nil"
|
||||
right_panel.text = content
|
||||
end
|
||||
)
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
local Gui = require("modules.exp_legacy.utils.gui") --- @dep utils.gui
|
||||
local ExpUtil = require("modules/exp_util")
|
||||
|
||||
local gui_names = Gui.names
|
||||
local type = type
|
||||
local concat = table.concat
|
||||
local inspect = table.inspect
|
||||
local pcall = pcall
|
||||
@@ -10,76 +9,7 @@ local rawset = rawset
|
||||
|
||||
local Public = {}
|
||||
|
||||
local LuaObject = { "{", nil, ", name = '", nil, "'}" }
|
||||
local LuaPlayer = { "{LuaPlayer, name = '", nil, "', index = ", nil, "}" }
|
||||
local LuaEntity = { "{LuaEntity, name = '", nil, "', unit_number = ", nil, "}" }
|
||||
local LuaGuiElement = { "{LuaGuiElement, name = '", nil, "'}" }
|
||||
|
||||
local function get(obj, prop)
|
||||
return obj[prop]
|
||||
end
|
||||
|
||||
local function get_name_safe(obj)
|
||||
local s, r = pcall(get, obj, "name")
|
||||
if not s then
|
||||
return "nil"
|
||||
else
|
||||
return r or "nil"
|
||||
end
|
||||
end
|
||||
|
||||
local function get_lua_object_type_safe(obj)
|
||||
local s, r = pcall(get, obj, "help")
|
||||
|
||||
if not s then
|
||||
return
|
||||
end
|
||||
|
||||
return r():match("Lua%a+")
|
||||
end
|
||||
|
||||
local function inspect_process(item)
|
||||
if type(item) ~= "table" or type(item.__self) ~= "userdata" then
|
||||
return item
|
||||
end
|
||||
|
||||
local suc, valid = pcall(get, item, "valid")
|
||||
if not suc then
|
||||
-- no 'valid' property
|
||||
return get_lua_object_type_safe(item) or "{NoHelp LuaObject}"
|
||||
end
|
||||
|
||||
if not valid then
|
||||
return "{Invalid LuaObject}"
|
||||
end
|
||||
|
||||
local obj_type = get_lua_object_type_safe(item)
|
||||
if not obj_type then
|
||||
return "{NoHelp LuaObject}"
|
||||
end
|
||||
|
||||
if obj_type == "LuaPlayer" then
|
||||
LuaPlayer[2] = item.name or "nil"
|
||||
LuaPlayer[4] = item.index or "nil"
|
||||
|
||||
return concat(LuaPlayer)
|
||||
elseif obj_type == "LuaEntity" then
|
||||
LuaEntity[2] = item.name or "nil"
|
||||
LuaEntity[4] = item.unit_number or "nil"
|
||||
|
||||
return concat(LuaEntity)
|
||||
elseif obj_type == "LuaGuiElement" then
|
||||
local name = item.name
|
||||
LuaGuiElement[2] = gui_names and gui_names[name] or name or "nil"
|
||||
|
||||
return concat(LuaGuiElement)
|
||||
else
|
||||
LuaObject[2] = obj_type
|
||||
LuaObject[4] = get_name_safe(item)
|
||||
|
||||
return concat(LuaObject)
|
||||
end
|
||||
end
|
||||
local inspect_process = ExpUtil.safe_value
|
||||
|
||||
local inspect_options = { process = inspect_process }
|
||||
function Public.dump(data)
|
||||
|
||||
Reference in New Issue
Block a user