Start converting GUI modules

This commit is contained in:
Cooldude2606
2025-01-15 22:32:49 +00:00
parent 88a47e3edc
commit bd6781b3a0
14 changed files with 88 additions and 144 deletions

View File

@@ -31,9 +31,12 @@ ExpGui.get_top_flow = mod_gui.get_button_flow
ExpGui.get_left_flow = mod_gui.get_frame_flow
--- Get a player from an element or gui event
--- @param input LuaGuiElement | { player_index: uint }
--- @param input LuaGuiElement | { player_index: uint } | { element: LuaGuiElement }
--- @return LuaPlayer
function ExpGui.get_player(input)
if type(input) == "table" and not input.player_index then
return assert(game.get_player(input.element.player_index))
end
return assert(game.get_player(input.player_index))
end

View File

@@ -11,6 +11,12 @@ local elements = {} --- @type table<string, ExpElement>
local buttons_with_left_element = {} --- @type table<string, ExpElement>
local left_elements_with_button = {} --- @type table<string, ExpElement>
ExpGui.on_toolbar_button_toggled = script.generate_event_name()
--- @class EventData.on_toolbar_button_toggled: EventData
--- @field element LuaGuiElement
--- @field state boolean
--- Set the style of a toolbar button
--- @param element LuaGuiElement
--- @param state boolean?
@@ -137,6 +143,10 @@ function ExpGui.create_toolbar_button(options)
local player = ExpGui.get_player(event)
ExpGui.set_left_element_visible(left_element, player, state)
end
script.raise_event(ExpGui.on_toolbar_button_toggled, {
element = event.element,
state = state,
})
end)
end

View File

@@ -7,8 +7,7 @@
"control.lua"
],
"require": [
"core_elements.lua",
"test.lua"
"core_elements.lua"
],
"dependencies": {
"clusterio": "*",

View File

@@ -6,7 +6,7 @@ local GuiIter = require("modules/exp_gui/iter")
--- @class ExpGui_ExpElement
local ExpElement = {
_elements = {},
_elements = {}, --- @type table<string, LuaGuiElement>
}
ExpElement.events = {}
@@ -51,7 +51,7 @@ ExpElement._prototype = {
ExpElement._metatable = {
__call = nil, -- ExpElement._prototype.create
__index = ExpElement._prototype,
__class = "ExpGui",
__class = "ExpElement",
}
--- Used to signal that the property should be the same as the define name

View File

@@ -1,16 +0,0 @@
local ExpGui = require("modules/exp_gui")
local frame = ExpGui.element("test")
:draw{
type = "frame",
caption = "Hello, World",
}
ExpGui.add_left_element(frame, true)
ExpGui.create_toolbar_button{
name = "test-button",
left_element = frame,
caption = "Test",
}