mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Start converting GUI modules
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
"control.lua"
|
||||
],
|
||||
"require": [
|
||||
"core_elements.lua",
|
||||
"test.lua"
|
||||
"core_elements.lua"
|
||||
],
|
||||
"dependencies": {
|
||||
"clusterio": "*",
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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",
|
||||
}
|
||||
Reference in New Issue
Block a user