mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Convert rocket info and autofill
This commit is contained in:
@@ -138,7 +138,7 @@ local function ensure_elements(player, element_defines, elements, parent)
|
|||||||
local done = {}
|
local done = {}
|
||||||
for define, visible in pairs(element_defines) do
|
for define, visible in pairs(element_defines) do
|
||||||
local element = elements[define.name]
|
local element = elements[define.name]
|
||||||
if not element then
|
if not element or not element.valid then
|
||||||
element = define(parent)
|
element = define(parent)
|
||||||
elements[define.name] = element
|
elements[define.name] = element
|
||||||
assert(element, "Element define did not return an element: " .. define.name)
|
assert(element, "Element define did not return an element: " .. define.name)
|
||||||
@@ -200,7 +200,7 @@ local function on_gui_opened(event)
|
|||||||
if visible then
|
if visible then
|
||||||
event.element = element
|
event.element = element
|
||||||
--- @diagnostic disable-next-line invisible
|
--- @diagnostic disable-next-line invisible
|
||||||
define:_raise_event(event)
|
define:raise_event(event)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -13,12 +13,14 @@ elements.aligned_flow = ExpGui.element("aligned_flow")
|
|||||||
}
|
}
|
||||||
:style(function(def, element, parent, opts)
|
:style(function(def, element, parent, opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
|
local vertical_align = opts.vertical_align or "center"
|
||||||
|
local horizontal_align = opts.horizontal_align or "right"
|
||||||
return {
|
return {
|
||||||
padding = { 1, 2 },
|
padding = { 1, 2 },
|
||||||
vertical_align = opts.vertical_align or "center",
|
vertical_align = vertical_align,
|
||||||
horizontal_align = opts.horizontal_align or "right",
|
horizontal_align = horizontal_align,
|
||||||
vertically_stretchable = opts.vertical_align and opts.vertical_align ~= "center",
|
vertically_stretchable = vertical_align ~= "center",
|
||||||
horizontally_stretchable = opts.horizontal_align and opts.horizontal_align ~= "center",
|
horizontally_stretchable = horizontal_align ~= "center",
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ ExpElement.events = {}
|
|||||||
--- @alias ExpElement.DrawCallback fun(def: ExpElement, parent: LuaGuiElement, ...): LuaGuiElement?, function?
|
--- @alias ExpElement.DrawCallback fun(def: ExpElement, parent: LuaGuiElement, ...): LuaGuiElement?, function?
|
||||||
--- @alias ExpElement.PostDrawCallback fun(def: ExpElement, element: LuaGuiElement?, parent: LuaGuiElement, ...): table?
|
--- @alias ExpElement.PostDrawCallback fun(def: ExpElement, element: LuaGuiElement?, parent: LuaGuiElement, ...): table?
|
||||||
--- @alias ExpElement.PostDrawCallbackAdder fun(self: ExpElement, definition: table | ExpElement.PostDrawCallback): ExpElement
|
--- @alias ExpElement.PostDrawCallbackAdder fun(self: ExpElement, definition: table | ExpElement.PostDrawCallback): ExpElement
|
||||||
--- @alias ExpElement.OnEventAdder<E> fun(self: ExpElement, handler: fun(def: ExpElement, event: E)): ExpElement
|
--- @alias ExpElement.OnEventAdder<E> fun(self: ExpElement, handler: fun(def: ExpElement, event: E, element: LuaGuiElement)): ExpElement
|
||||||
|
|
||||||
--- @class ExpElement._debug
|
--- @class ExpElement._debug
|
||||||
--- @field defined_at string
|
--- @field defined_at string
|
||||||
@@ -343,7 +343,7 @@ function ExpElement._prototype:unlink_element(element)
|
|||||||
assert(self._has_handlers, "Element has no event handlers")
|
assert(self._has_handlers, "Element has no event handlers")
|
||||||
local element_tags = element.tags
|
local element_tags = element.tags
|
||||||
if not element_tags then
|
if not element_tags then
|
||||||
element_tags = {}
|
return element, ExpElement._prototype.unlink_element
|
||||||
end
|
end
|
||||||
|
|
||||||
local event_tags = element_tags["ExpGui"]
|
local event_tags = element_tags["ExpGui"]
|
||||||
@@ -371,24 +371,24 @@ local function event_handler(event)
|
|||||||
for _, define_name in ipairs(event_tags) do
|
for _, define_name in ipairs(event_tags) do
|
||||||
local define = ExpElement._elements[define_name]
|
local define = ExpElement._elements[define_name]
|
||||||
if define then
|
if define then
|
||||||
define:_raise_event(event)
|
define:raise_event(event)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Raise all handlers for an event on this definition
|
--- Raise all handlers for an event on this definition
|
||||||
--- @param event EventData
|
--- @param event EventData | { element: LuaGuiElement }
|
||||||
function ExpElement._prototype:_raise_event(event)
|
function ExpElement._prototype:raise_event(event)
|
||||||
local handlers = self._events[event.name]
|
local handlers = self._events[event.name]
|
||||||
if not handlers then return end
|
if not handlers then return end
|
||||||
for _, handler in ipairs(handlers) do
|
for _, handler in ipairs(handlers) do
|
||||||
handler(self, event)
|
handler(self, event, event.element)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Add an event handler
|
--- Add an event handler
|
||||||
--- @param event defines.events
|
--- @param event defines.events
|
||||||
--- @param handler fun(def: ExpElement, event: EventData)
|
--- @param handler fun(def: ExpElement, event: EventData, element: LuaGuiElement)
|
||||||
--- @return ExpElement
|
--- @return ExpElement
|
||||||
function ExpElement._prototype:on_event(event, handler)
|
function ExpElement._prototype:on_event(event, handler)
|
||||||
ExpElement.events[event] = event_handler
|
ExpElement.events[event] = event_handler
|
||||||
|
|||||||
@@ -44,9 +44,9 @@ return {
|
|||||||
|
|
||||||
--- GUI
|
--- GUI
|
||||||
"modules.gui.readme",
|
"modules.gui.readme",
|
||||||
--"modules.gui.rocket-info",
|
"modules.gui.rocket-info",
|
||||||
"modules.gui.science-info",
|
"modules.gui.science-info",
|
||||||
--"modules.gui.autofill",
|
"modules.gui.autofill",
|
||||||
--"modules.gui.task-list",
|
--"modules.gui.task-list",
|
||||||
--"modules.gui.warp-list",
|
--"modules.gui.warp-list",
|
||||||
--"modules.gui.player-list",
|
--"modules.gui.player-list",
|
||||||
|
|||||||
@@ -4,10 +4,10 @@
|
|||||||
@alias autofill
|
@alias autofill
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
local Storage = require("modules/exp_util/storage")
|
||||||
local FlyingText = require("modules/exp_util/flying_text")
|
local FlyingText = require("modules/exp_util/flying_text")
|
||||||
local Gui = require("modules.exp_legacy.expcore.gui") -- @dep expcore.gui
|
local Gui = require("modules/exp_gui")
|
||||||
local Roles = require("modules.exp_legacy.expcore.roles") -- @dep expcore.gui
|
local Roles = require("modules.exp_legacy.expcore.roles") -- @dep expcore.gui
|
||||||
local Storage = require("modules/exp_util/storage") -- @dep utils.global
|
|
||||||
local config = require("modules.exp_legacy.config.gui.autofill") -- @dep config.gui.autofill
|
local config = require("modules.exp_legacy.config.gui.autofill") -- @dep config.gui.autofill
|
||||||
local Event = require("modules/exp_legacy/utils/event") -- @dep utils.event
|
local Event = require("modules/exp_legacy/utils/event") -- @dep utils.event
|
||||||
|
|
||||||
@@ -25,17 +25,19 @@ end
|
|||||||
|
|
||||||
--- Toggle entity section visibility
|
--- Toggle entity section visibility
|
||||||
-- @element toggle_item_button
|
-- @element toggle_item_button
|
||||||
local toggle_section =
|
local toggle_section = Gui.element("autofill_toggle_section")
|
||||||
Gui.element{
|
:draw{
|
||||||
type = "sprite-button",
|
type = "sprite-button",
|
||||||
sprite = "utility/expand",
|
sprite = "utility/expand",
|
||||||
tooltip = { "autofill.toggle-section-tooltip" },
|
tooltip = { "autofill.toggle-section-tooltip" },
|
||||||
style = "frame_action_button",
|
style = "frame_action_button",
|
||||||
name = Gui.unique_static_name,
|
name = Gui.property_from_name,
|
||||||
}
|
}
|
||||||
:style(Gui.sprite_style(20))
|
:style(Gui.styles.sprite{
|
||||||
:on_click(function(_, element, _)
|
size = 20
|
||||||
local header_flow = element.parent
|
})
|
||||||
|
:on_click(function(def, event, element)
|
||||||
|
local header_flow = assert(element.parent)
|
||||||
local flow_name = header_flow.caption
|
local flow_name = header_flow.caption
|
||||||
local flow = header_flow.parent.parent[flow_name]
|
local flow = header_flow.parent.parent[flow_name]
|
||||||
if Gui.toggle_visible_state(flow) then
|
if Gui.toggle_visible_state(flow) then
|
||||||
@@ -50,8 +52,8 @@ local toggle_section =
|
|||||||
--- Toggle enitity button, used for toggling autofill for the specific entity
|
--- Toggle enitity button, used for toggling autofill for the specific entity
|
||||||
-- All entity autofill settings will be ignored if its disabled
|
-- All entity autofill settings will be ignored if its disabled
|
||||||
-- @element entity_toggle
|
-- @element entity_toggle
|
||||||
local entity_toggle =
|
local entity_toggle = Gui.element("entity_toggle")
|
||||||
Gui.element(function(_, parent, entity_name)
|
:draw(function(_, parent, entity_name)
|
||||||
return parent.add{
|
return parent.add{
|
||||||
type = "sprite-button",
|
type = "sprite-button",
|
||||||
sprite = "utility/confirm_slot",
|
sprite = "utility/confirm_slot",
|
||||||
@@ -59,8 +61,11 @@ local entity_toggle =
|
|||||||
style = "shortcut_bar_button_green",
|
style = "shortcut_bar_button_green",
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
:style(Gui.sprite_style(22))
|
:style(Gui.styles.sprite{
|
||||||
:on_click(function(player, element, _)
|
size = 22
|
||||||
|
})
|
||||||
|
:on_click(function(def, event, element)
|
||||||
|
local player = Gui.get_player(event)
|
||||||
local entity_name = string.match(element.parent.parent.name, "(.*)%-header")
|
local entity_name = string.match(element.parent.parent.name, "(.*)%-header")
|
||||||
if not autofill_player_settings[player.name] then return end
|
if not autofill_player_settings[player.name] then return end
|
||||||
local setting = autofill_player_settings[player.name][entity_name]
|
local setting = autofill_player_settings[player.name][entity_name]
|
||||||
@@ -75,7 +80,7 @@ local entity_toggle =
|
|||||||
element.style = "shortcut_bar_button_green"
|
element.style = "shortcut_bar_button_green"
|
||||||
end
|
end
|
||||||
-- Correct the button size
|
-- Correct the button size
|
||||||
local style = element.style --[[@as LuaStyle]]
|
local style = element.style
|
||||||
style.padding = -2
|
style.padding = -2
|
||||||
style.height = 22
|
style.height = 22
|
||||||
style.width = 22
|
style.width = 22
|
||||||
@@ -83,18 +88,17 @@ local entity_toggle =
|
|||||||
|
|
||||||
--- Draw a section header and main scroll
|
--- Draw a section header and main scroll
|
||||||
-- @element autofill_section_container
|
-- @element autofill_section_container
|
||||||
local section =
|
local section = Gui.element("autofill_section")
|
||||||
Gui.element(function(definition, parent, section_name, table_size)
|
:draw(function(def, parent, section_name, table_size)
|
||||||
-- Draw the header for the section
|
-- Draw the header for the section
|
||||||
local header = Gui.header(
|
local header = Gui.elements.header(parent, {
|
||||||
parent,
|
name = section_name .. "-header",
|
||||||
{ "autofill.toggle-section-caption", rich_img("item", section_name), { "entity-name." .. section_name } },
|
caption = { "autofill.toggle-section-caption", rich_img("item", section_name), { "entity-name." .. section_name } },
|
||||||
{ "autofill.toggle-section-tooltip" },
|
tooltip = { "autofill.toggle-section-tooltip" },
|
||||||
true,
|
label_name = "label",
|
||||||
section_name .. "-header"
|
})
|
||||||
)
|
|
||||||
|
|
||||||
definition:triggers_events(header.parent.header_label)
|
def:link_element(header.parent.label)
|
||||||
|
|
||||||
-- Right aligned button to toggle the section
|
-- Right aligned button to toggle the section
|
||||||
header.caption = section_name
|
header.caption = section_name
|
||||||
@@ -109,17 +113,17 @@ local section =
|
|||||||
|
|
||||||
section_table.visible = false
|
section_table.visible = false
|
||||||
|
|
||||||
return definition:no_events(section_table)
|
return def:unlink_element(section_table)
|
||||||
end)
|
end)
|
||||||
:on_click(function(_, element, event)
|
:on_click(function(def, event, element)
|
||||||
event.element = element.parent.alignment[toggle_section.name]
|
event.element = element.parent.alignment[toggle_section.name]
|
||||||
toggle_section:raise_event(event)
|
toggle_section:raise_event(event)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--- Toggle item button, used for toggling autofill for the specific item
|
--- Toggle item button, used for toggling autofill for the specific item
|
||||||
-- @element toggle_item_button
|
-- @element toggle_item_button
|
||||||
local toggle_item_button =
|
local toggle_item_button = Gui.element("toggle_item_button")
|
||||||
Gui.element(function(_, parent, item)
|
:draw(function(_, parent, item)
|
||||||
return parent.add{
|
return parent.add{
|
||||||
type = "sprite-button",
|
type = "sprite-button",
|
||||||
sprite = "item/" .. item.name,
|
sprite = "item/" .. item.name,
|
||||||
@@ -127,8 +131,12 @@ local toggle_item_button =
|
|||||||
style = "shortcut_bar_button_red",
|
style = "shortcut_bar_button_red",
|
||||||
}
|
}
|
||||||
end)
|
end)
|
||||||
:style(Gui.sprite_style(32, nil, { right_margin = -3 }))
|
:style(Gui.styles.sprite{
|
||||||
:on_click(function(player, element)
|
size = 32,
|
||||||
|
right_margin = -3,
|
||||||
|
})
|
||||||
|
:on_click(function(def, event, element)
|
||||||
|
local player = Gui.get_player(event)
|
||||||
local item_name = element.parent.tooltip
|
local item_name = element.parent.tooltip
|
||||||
local entity_name = element.parent.parent.parent.name
|
local entity_name = element.parent.parent.parent.name
|
||||||
if not autofill_player_settings[player.name] then return end
|
if not autofill_player_settings[player.name] then return end
|
||||||
@@ -144,7 +152,7 @@ local toggle_item_button =
|
|||||||
element.style = "shortcut_bar_button_green"
|
element.style = "shortcut_bar_button_green"
|
||||||
end
|
end
|
||||||
-- Correct the button size
|
-- Correct the button size
|
||||||
local style = element.style --[[@as LuaStyle]]
|
local style = element.style
|
||||||
style.right_margin = -3
|
style.right_margin = -3
|
||||||
style.padding = -2
|
style.padding = -2
|
||||||
style.height = 32
|
style.height = 32
|
||||||
@@ -153,8 +161,8 @@ local toggle_item_button =
|
|||||||
|
|
||||||
--- Amount text field for a autofill item
|
--- Amount text field for a autofill item
|
||||||
-- @element amount_textfield
|
-- @element amount_textfield
|
||||||
local amount_textfield =
|
local amount_textfield = Gui.element("amount_textfield")
|
||||||
Gui.element(function(_, parent, item)
|
:draw(function(_, parent, item)
|
||||||
return parent.add{
|
return parent.add{
|
||||||
type = "textfield",
|
type = "textfield",
|
||||||
text = item.amount,
|
text = item.amount,
|
||||||
@@ -170,9 +178,10 @@ local amount_textfield =
|
|||||||
height = 31,
|
height = 31,
|
||||||
padding = -2,
|
padding = -2,
|
||||||
}
|
}
|
||||||
:on_text_changed(function(player, element, _)
|
:on_text_changed(function(def, event, element)
|
||||||
local value = tonumber(element.text)
|
local value = tonumber(element.text)
|
||||||
if not value then value = 0 end
|
if not value then value = 0 end
|
||||||
|
local player = Gui.get_player(event)
|
||||||
local clamped = math.clamp(value, 0, 1000)
|
local clamped = math.clamp(value, 0, 1000)
|
||||||
local item_name = element.parent.tooltip
|
local item_name = element.parent.tooltip
|
||||||
local entity_name = element.parent.parent.parent.name
|
local entity_name = element.parent.parent.parent.name
|
||||||
@@ -183,7 +192,7 @@ local amount_textfield =
|
|||||||
if not item then return end
|
if not item then return end
|
||||||
item.amount = clamped
|
item.amount = clamped
|
||||||
if clamped ~= value then
|
if clamped ~= value then
|
||||||
element.text = clamped
|
element.text = tostring(clamped)
|
||||||
player.print{ "autofill.invalid", item.amount, rich_img("item", item.name), rich_img("entity", entity_name) }
|
player.print{ "autofill.invalid", item.amount, rich_img("item", item.name), rich_img("entity", entity_name) }
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@@ -191,8 +200,8 @@ local amount_textfield =
|
|||||||
|
|
||||||
--- Autofill setting, contains a button and a textbox
|
--- Autofill setting, contains a button and a textbox
|
||||||
-- @element add_autofill_setting
|
-- @element add_autofill_setting
|
||||||
local add_autofill_setting =
|
local add_autofill_setting = Gui.element("add_autofill_setting")
|
||||||
Gui.element(function(_, parent, item)
|
:draw(function(_, parent, item)
|
||||||
local toggle_flow = parent.add{ type = "flow", name = "toggle-setting-" .. item.name, tooltip = item.name }
|
local toggle_flow = parent.add{ type = "flow", name = "toggle-setting-" .. item.name, tooltip = item.name }
|
||||||
local amount_flow = parent.add{ type = "flow", name = "amount-setting-" .. item.name, tooltip = item.name }
|
local amount_flow = parent.add{ type = "flow", name = "amount-setting-" .. item.name, tooltip = item.name }
|
||||||
toggle_flow.style.padding = 0
|
toggle_flow.style.padding = 0
|
||||||
@@ -203,8 +212,8 @@ local add_autofill_setting =
|
|||||||
|
|
||||||
--- Autofill setting empty, contains filler button and textfield gui elements
|
--- Autofill setting empty, contains filler button and textfield gui elements
|
||||||
-- @element add_empty_autofill_setting
|
-- @element add_empty_autofill_setting
|
||||||
local add_empty_autofill_setting =
|
local add_empty_autofill_setting = Gui.element("add_empty_autofill_setting")
|
||||||
Gui.element(function(_, parent)
|
:draw(function(_, parent)
|
||||||
local toggle_element = parent.add{
|
local toggle_element = parent.add{
|
||||||
type = "sprite-button",
|
type = "sprite-button",
|
||||||
}
|
}
|
||||||
@@ -223,19 +232,19 @@ local add_empty_autofill_setting =
|
|||||||
|
|
||||||
--- Main gui container for the left flow
|
--- Main gui container for the left flow
|
||||||
-- @element autofill_container
|
-- @element autofill_container
|
||||||
autofill_container =
|
autofill_container = Gui.element("autofill_container")
|
||||||
Gui.element(function(definition, parent)
|
:draw(function(def, parent)
|
||||||
-- Draw the internal container
|
-- Draw the internal container
|
||||||
local container = Gui.container(parent, definition.name)
|
local container = Gui.elements.container(parent)
|
||||||
-- Draw the scroll container
|
-- Draw the scroll container
|
||||||
local scroll_table = Gui.scroll_table(container, 400, 1, "autofill-scroll-table")
|
local scroll_table = Gui.elements.scroll_table(container, 400, 1, "autofill-scroll-table")
|
||||||
-- Set the scroll panel to always show the scrollbar (not doing this will result in a changing gui size)
|
-- Set the scroll panel to always show the scrollbar (not doing this will result in a changing gui size)
|
||||||
scroll_table.parent.vertical_scroll_policy = "always"
|
scroll_table.parent.vertical_scroll_policy = "always"
|
||||||
-- Scroll panel has by default padding
|
-- Scroll panel has by default padding
|
||||||
scroll_table.parent.style.padding = 0
|
scroll_table.parent.style.padding = 0
|
||||||
-- Remove the default gap that is added in a table between elements
|
-- Remove the default gap that is added in a table between elements
|
||||||
scroll_table.style.vertical_spacing = 0
|
scroll_table.style.vertical_spacing = 0
|
||||||
-- Center the first collumn in the table
|
-- Center the first column in the table
|
||||||
scroll_table.style.column_alignments[1] = "center"
|
scroll_table.style.column_alignments[1] = "center"
|
||||||
-- Loop over each default entity config
|
-- Loop over each default entity config
|
||||||
for _, setting in pairs(config.default_entities) do
|
for _, setting in pairs(config.default_entities) do
|
||||||
@@ -245,7 +254,7 @@ autofill_container =
|
|||||||
local entity_table = section(scroll_table, setting.entity, 3)
|
local entity_table = section(scroll_table, setting.entity, 3)
|
||||||
-- Add some padding around the table
|
-- Add some padding around the table
|
||||||
entity_table.style.padding = 3
|
entity_table.style.padding = 3
|
||||||
-- Make sure each collumn is alignment top center
|
-- Make sure each column is alignment top center
|
||||||
entity_table.style.column_alignments[1] = "top-center"
|
entity_table.style.column_alignments[1] = "top-center"
|
||||||
entity_table.style.column_alignments[2] = "top-center"
|
entity_table.style.column_alignments[2] = "top-center"
|
||||||
entity_table.style.column_alignments[3] = "top-center"
|
entity_table.style.column_alignments[3] = "top-center"
|
||||||
@@ -284,14 +293,18 @@ autofill_container =
|
|||||||
-- Return the external container
|
-- Return the external container
|
||||||
return container.parent
|
return container.parent
|
||||||
end)
|
end)
|
||||||
:static_name(Gui.unique_static_name)
|
|
||||||
:add_to_left_flow()
|
|
||||||
|
|
||||||
--- Button on the top flow used to toggle autofill container
|
--- Add the element to the left flow with a toolbar button
|
||||||
-- @element autofill_toggle
|
Gui.add_left_element(autofill_container, false)
|
||||||
Gui.left_toolbar_button(config.icon, { "autofill.main-tooltip" }, autofill_container, function(player)
|
Gui.create_toolbar_button{
|
||||||
|
name = "autofill_toggle",
|
||||||
|
left_element = autofill_container,
|
||||||
|
sprite = config.icon,
|
||||||
|
tooltip = { "autofill.main-tooltip" },
|
||||||
|
visible = function(player, element)
|
||||||
return Roles.player_allowed(player, "gui/autofill")
|
return Roles.player_allowed(player, "gui/autofill")
|
||||||
end)
|
end
|
||||||
|
}
|
||||||
|
|
||||||
--- When a player is created make sure they have the default autofill settings
|
--- When a player is created make sure they have the default autofill settings
|
||||||
Event.add(defines.events.on_player_created, function(event)
|
Event.add(defines.events.on_player_created, function(event)
|
||||||
@@ -321,6 +334,7 @@ local function entity_build(event)
|
|||||||
-- Get the inventory of the player
|
-- Get the inventory of the player
|
||||||
local player_inventory = player.get_main_inventory() --- @cast player_inventory -nil
|
local player_inventory = player.get_main_inventory() --- @cast player_inventory -nil
|
||||||
|
|
||||||
|
local offset = { x = 0, y = 0 }
|
||||||
-- Loop over all possible items to insert into the entity
|
-- Loop over all possible items to insert into the entity
|
||||||
for _, item in pairs(entity_settings.items) do
|
for _, item in pairs(entity_settings.items) do
|
||||||
-- Check if the item is enabled or goto next item
|
-- Check if the item is enabled or goto next item
|
||||||
@@ -330,28 +344,30 @@ local function entity_build(event)
|
|||||||
local entity_inventory = entity.get_inventory(item.inv)
|
local entity_inventory = entity.get_inventory(item.inv)
|
||||||
if not entity_inventory then goto end_item end
|
if not entity_inventory then goto end_item end
|
||||||
|
|
||||||
local preferd_amount = item.amount
|
local preferred_amount = item.amount
|
||||||
local item_amount = player_inventory.get_item_count(item.name)
|
local item_amount = player_inventory.get_item_count(item.name)
|
||||||
if item_amount ~= 0 then
|
if item_amount ~= 0 then
|
||||||
local inserted
|
local inserted
|
||||||
local color = { r = 0, g = 255, b = 0, a = 1 }
|
local color = { r = 0, g = 255, b = 0, a = 255 }
|
||||||
if item_amount >= preferd_amount then
|
if item_amount >= preferred_amount then
|
||||||
-- Can item be inserted? no, goto next item!
|
-- Can item be inserted? no, goto next item!
|
||||||
if not entity_inventory.can_insert{ name = item.name, count = preferd_amount } then
|
if not entity_inventory.can_insert{ name = item.name, count = preferred_amount } then
|
||||||
goto end_item
|
goto end_item
|
||||||
end
|
end
|
||||||
inserted = entity_inventory.insert{ name = item.name, count = preferd_amount }
|
inserted = entity_inventory.insert{ name = item.name, count = preferred_amount }
|
||||||
else
|
else
|
||||||
inserted = entity_inventory.insert{ name = item.name, count = item_amount }
|
inserted = entity_inventory.insert{ name = item.name, count = item_amount }
|
||||||
color = { r = 255, g = 165, b = 0, a = 1 }
|
color = { r = 255, g = 165, b = 0, a = 255 }
|
||||||
end
|
end
|
||||||
player_inventory.remove{ name = item.name, count = inserted }
|
player_inventory.remove{ name = item.name, count = inserted }
|
||||||
FlyingText.create_above_entity{
|
FlyingText.create_above_entity{
|
||||||
target_entity = entity,
|
target_entity = entity,
|
||||||
text = { "autofill.inserted", inserted, rich_img("item", item.name), rich_img("entity", entity.name) },
|
text = { "autofill.inserted", inserted, rich_img("item", item.name), rich_img("entity", entity.name) },
|
||||||
|
offset = offset,
|
||||||
player = player,
|
player = player,
|
||||||
color = color,
|
color = color,
|
||||||
}
|
}
|
||||||
|
offset.y = offset.y - 0.33
|
||||||
end
|
end
|
||||||
::end_item::
|
::end_item::
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -441,11 +441,11 @@ local readme = Gui.element("readme")
|
|||||||
local button = Gui.get_top_element(readme_toggle, player)
|
local button = Gui.get_top_element(readme_toggle, player)
|
||||||
Gui.set_toolbar_button_style(button, true)
|
Gui.set_toolbar_button_style(button, true)
|
||||||
end)
|
end)
|
||||||
:on_closed(function(def, event)
|
:on_closed(function(def, event, element)
|
||||||
local player = Gui.get_player(event)
|
local player = Gui.get_player(event)
|
||||||
local button = Gui.get_top_element(readme_toggle, player)
|
local button = Gui.get_top_element(readme_toggle, player)
|
||||||
Gui.set_toolbar_button_style(button, false)
|
Gui.set_toolbar_button_style(button, false)
|
||||||
Gui.destroy_if_valid(event.element)
|
Gui.destroy_if_valid(element)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--- Toggle button for the readme gui
|
--- Toggle button for the readme gui
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
]]
|
]]
|
||||||
|
|
||||||
local ExpUtil = require("modules/exp_util")
|
local ExpUtil = require("modules/exp_util")
|
||||||
local Gui = require("modules.exp_legacy.expcore.gui") --- @dep expcore.gui
|
local Gui = require("modules/exp_gui")
|
||||||
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
|
local Roles = require("modules.exp_legacy.expcore.roles") --- @dep expcore.roles
|
||||||
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
local Event = require("modules/exp_legacy/utils/event") --- @dep utils.event
|
||||||
local config = require("modules.exp_legacy.config.gui.rockets") --- @dep config.gui.rockets
|
local config = require("modules.exp_legacy.config.gui.rockets") --- @dep config.gui.rockets
|
||||||
@@ -39,15 +39,17 @@ end
|
|||||||
|
|
||||||
--- Button to toggle the auto launch on a rocket silo
|
--- Button to toggle the auto launch on a rocket silo
|
||||||
-- @element toggle_launch
|
-- @element toggle_launch
|
||||||
local toggle_launch =
|
local toggle_launch = Gui.element("toggle_launch")
|
||||||
Gui.element{
|
:draw{
|
||||||
type = "sprite-button",
|
type = "sprite-button",
|
||||||
sprite = "utility/play",
|
sprite = "utility/play",
|
||||||
tooltip = { "rocket-info.toggle-rocket-tooltip" },
|
tooltip = { "rocket-info.toggle-rocket-tooltip" },
|
||||||
name = Gui.unique_static_name,
|
name = Gui.property_from_name,
|
||||||
}
|
}
|
||||||
:style(Gui.sprite_style(16))
|
:style(Gui.styles.sprite{
|
||||||
:on_click(function(_, element, _)
|
size = 16,
|
||||||
|
})
|
||||||
|
:on_click(function(def, event, element)
|
||||||
local rocket_silo_name = element.parent.name:sub(8)
|
local rocket_silo_name = element.parent.name:sub(8)
|
||||||
local rocket_silo = Rockets.get_silo_entity(rocket_silo_name)
|
local rocket_silo = Rockets.get_silo_entity(rocket_silo_name)
|
||||||
if rocket_silo.auto_launch then
|
if rocket_silo.auto_launch then
|
||||||
@@ -61,30 +63,10 @@ local toggle_launch =
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--- Button to remotely launch a rocket from a silo
|
|
||||||
-- @element launch_rocket
|
|
||||||
local launch_rocket =
|
|
||||||
Gui.element{
|
|
||||||
type = "sprite-button",
|
|
||||||
sprite = "utility/center",
|
|
||||||
tooltip = { "rocket-info.launch-tooltip" },
|
|
||||||
name = Gui.unique_static_name,
|
|
||||||
}
|
|
||||||
:style(Gui.sprite_style(16, -1))
|
|
||||||
:on_click(function(player, element, _)
|
|
||||||
local rocket_silo_name = element.parent.name:sub(8)
|
|
||||||
local silo_data = Rockets.get_silo_data_by_name(rocket_silo_name)
|
|
||||||
if silo_data.entity.launch_rocket() then
|
|
||||||
element.enabled = false
|
|
||||||
else
|
|
||||||
player.print({ "rocket-info.launch-failed" }, Colors.orange_red)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
--- XY cords that allow zoom to map when pressed
|
--- XY cords that allow zoom to map when pressed
|
||||||
-- @element silo_cords
|
-- @element silo_cords
|
||||||
local silo_cords =
|
local silo_cords = Gui.element("silo_cords")
|
||||||
Gui.element(function(definition, parent, silo_data)
|
:draw(function(definition, parent, silo_data)
|
||||||
local silo_name = silo_data.silo_name
|
local silo_name = silo_data.silo_name
|
||||||
local pos = silo_data.position
|
local pos = silo_data.position
|
||||||
local tooltip = config.progress.allow_zoom_to_map and { "rocket-info.progress-label-tooltip" } or nil
|
local tooltip = config.progress.allow_zoom_to_map and { "rocket-info.progress-label-tooltip" } or nil
|
||||||
@@ -120,11 +102,12 @@ local silo_cords =
|
|||||||
}
|
}
|
||||||
|
|
||||||
if config.progress.allow_zoom_to_map then
|
if config.progress.allow_zoom_to_map then
|
||||||
definition:triggers_events(label_x)
|
definition:link_element(label_x)
|
||||||
definition:triggers_events(label_y)
|
definition:link_element(label_y)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
:on_click(function(player, element, _)
|
:on_click(function(def, event, element)
|
||||||
|
local player = Gui.get_player(event)
|
||||||
local rocket_silo_name = element.parent.caption
|
local rocket_silo_name = element.parent.caption
|
||||||
local rocket_silo = Rockets.get_silo_entity(rocket_silo_name)
|
local rocket_silo = Rockets.get_silo_entity(rocket_silo_name)
|
||||||
player.set_controller{ type = defines.controllers.remote, position = rocket_silo.position, surface = rocket_silo.surface }
|
player.set_controller{ type = defines.controllers.remote, position = rocket_silo.position, surface = rocket_silo.surface }
|
||||||
@@ -132,10 +115,10 @@ local silo_cords =
|
|||||||
|
|
||||||
--- Base element for each rocket in the progress list
|
--- Base element for each rocket in the progress list
|
||||||
-- @element rocket_entry
|
-- @element rocket_entry
|
||||||
local rocket_entry =
|
local rocket_entry = Gui.element("rocket_entry")
|
||||||
Gui.element(function(_, parent, silo_data)
|
:draw(function(_, parent, silo_data)
|
||||||
local silo_name = silo_data.silo_name
|
local silo_name = silo_data.silo_name
|
||||||
local player = Gui.get_player_from_element(parent)
|
local player = Gui.get_player(parent)
|
||||||
|
|
||||||
-- Add the toggle auto launch if the player is allowed it
|
-- Add the toggle auto launch if the player is allowed it
|
||||||
-- Auto launch was removed from the api and no 2.0 equivalent was added
|
-- Auto launch was removed from the api and no 2.0 equivalent was added
|
||||||
@@ -148,18 +131,11 @@ local rocket_entry =
|
|||||||
button.sprite = silo_data.toggle_sprite]]
|
button.sprite = silo_data.toggle_sprite]]
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Add the remote launch if the player is allowed it
|
|
||||||
if check_player_permissions(player, "remote_launch") then
|
|
||||||
local flow = parent.add{ type = "flow", name = "launch-" .. silo_name }
|
|
||||||
local button = launch_rocket(flow)
|
|
||||||
button.enabled = silo_data.allow_launch
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Draw the silo cords element
|
-- Draw the silo cords element
|
||||||
silo_cords(parent, silo_data)
|
silo_cords(parent, silo_data)
|
||||||
|
|
||||||
-- Add a progress label
|
-- Add a progress label
|
||||||
local alignment = Gui.alignment(parent, silo_name)
|
local alignment = Gui.elements.aligned_flow(parent, { name = silo_name })
|
||||||
local element =
|
local element =
|
||||||
alignment.add{
|
alignment.add{
|
||||||
type = "label",
|
type = "label",
|
||||||
@@ -174,8 +150,8 @@ local rocket_entry =
|
|||||||
|
|
||||||
--- Data label which contains a name and a value label pair
|
--- Data label which contains a name and a value label pair
|
||||||
-- @element data_label
|
-- @element data_label
|
||||||
local data_label =
|
local data_label = Gui.element("data_label")
|
||||||
Gui.element(function(_, parent, label_data)
|
:draw(function(_, parent, label_data)
|
||||||
local data_name = label_data.name
|
local data_name = label_data.name
|
||||||
local data_subname = label_data.subname
|
local data_subname = label_data.subname
|
||||||
local data_fullname = data_subname and data_name .. data_subname or data_name
|
local data_fullname = data_subname and data_name .. data_subname or data_name
|
||||||
@@ -190,7 +166,7 @@ local data_label =
|
|||||||
name_label.style.padding = { 0, 2 }
|
name_label.style.padding = { 0, 2 }
|
||||||
|
|
||||||
--- Right aligned label to store the data
|
--- Right aligned label to store the data
|
||||||
local alignment = Gui.alignment(parent, data_fullname)
|
local alignment = Gui.elements.aligned_flow(parent, { name = data_fullname })
|
||||||
local element =
|
local element =
|
||||||
alignment.add{
|
alignment.add{
|
||||||
type = "label",
|
type = "label",
|
||||||
@@ -305,13 +281,6 @@ local function update_build_progress(parent, progress_data)
|
|||||||
toggle_button.tooltip = silo_data.toggle_tooltip
|
toggle_button.tooltip = silo_data.toggle_tooltip
|
||||||
toggle_button.sprite = silo_data.toggle_sprite
|
toggle_button.sprite = silo_data.toggle_sprite
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Update the launch button
|
|
||||||
local launch_button = parent["launch-" .. silo_name]
|
|
||||||
if launch_button then
|
|
||||||
launch_button = launch_button[launch_rocket.name]
|
|
||||||
launch_button.enabled = silo_data.allow_launch
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -424,18 +393,20 @@ end
|
|||||||
|
|
||||||
-- Button to toggle a section dropdown
|
-- Button to toggle a section dropdown
|
||||||
-- @element toggle_section
|
-- @element toggle_section
|
||||||
local toggle_section =
|
local toggle_section = Gui.element("rocket_info_toggle_section")
|
||||||
Gui.element{
|
:draw{
|
||||||
type = "sprite-button",
|
type = "sprite-button",
|
||||||
sprite = "utility/expand",
|
sprite = "utility/expand",
|
||||||
hovered_sprite = "utility/expand",
|
hovered_sprite = "utility/expand",
|
||||||
tooltip = { "rocket-info.toggle-section-tooltip" },
|
tooltip = { "rocket-info.toggle-section-tooltip" },
|
||||||
style = "frame_action_button",
|
style = "frame_action_button",
|
||||||
name = Gui.unique_static_name,
|
name = Gui.property_from_name,
|
||||||
}
|
}
|
||||||
:style(Gui.sprite_style(20))
|
:style(Gui.styles.sprite{
|
||||||
:on_click(function(_, element, _)
|
size = 20,
|
||||||
local header_flow = element.parent
|
})
|
||||||
|
:on_click(function(def, event, element)
|
||||||
|
local header_flow = assert(element.parent)
|
||||||
local flow_name = header_flow.caption
|
local flow_name = header_flow.caption
|
||||||
local flow = header_flow.parent.parent[flow_name]
|
local flow = header_flow.parent.parent[flow_name]
|
||||||
if Gui.toggle_visible_state(flow) then
|
if Gui.toggle_visible_state(flow) then
|
||||||
@@ -449,46 +420,46 @@ local toggle_section =
|
|||||||
|
|
||||||
-- Draw a section header and main scroll
|
-- Draw a section header and main scroll
|
||||||
-- @element rocket_list_container
|
-- @element rocket_list_container
|
||||||
local section =
|
local section = Gui.element("rocket_info_section")
|
||||||
Gui.element(function(definition, parent, section_name, table_size)
|
:draw(function(definition, parent, section_name, table_size)
|
||||||
-- Draw the header for the section
|
-- Draw the header for the section
|
||||||
local header = Gui.header(
|
local header = Gui.elements.header(parent, {
|
||||||
parent,
|
name = section_name .. "-header",
|
||||||
{ "rocket-info.section-caption-" .. section_name },
|
caption = { "rocket-info.section-caption-" .. section_name },
|
||||||
{ "rocket-info.section-tooltip-" .. section_name },
|
tooltip = { "rocket-info.section-tooltip-" .. section_name },
|
||||||
true,
|
label_name = "label",
|
||||||
section_name .. "-header"
|
})
|
||||||
)
|
|
||||||
definition:triggers_events(header.parent.header_label)
|
definition:link_element(header.parent.label)
|
||||||
|
|
||||||
-- Right aligned button to toggle the section
|
-- Right aligned button to toggle the section
|
||||||
header.caption = section_name
|
header.caption = section_name
|
||||||
toggle_section(header)
|
toggle_section(header)
|
||||||
|
|
||||||
-- Table used to store the data
|
-- Table used to store the data
|
||||||
local scroll_table = Gui.scroll_table(parent, 215, table_size, section_name)
|
local scroll_table = Gui.elements.scroll_table(parent, 215, table_size, section_name)
|
||||||
scroll_table.parent.visible = false
|
scroll_table.parent.visible = false
|
||||||
|
|
||||||
-- Return the flow table
|
-- Return the flow table
|
||||||
return definition:no_events(scroll_table)
|
return definition:unlink_element(scroll_table)
|
||||||
end)
|
end)
|
||||||
:on_click(function(_, element, event)
|
:on_click(function(def, event, element)
|
||||||
event.element = element.parent.alignment[toggle_section.name]
|
event.element = element.parent.alignment[toggle_section.name]
|
||||||
toggle_section:raise_event(event)
|
toggle_section:raise_event(event)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--- Main gui container for the left flow
|
--- Main gui container for the left flow
|
||||||
-- @element rocket_list_container
|
-- @element rocket_list_container
|
||||||
local rocket_list_container =
|
local rocket_list_container = Gui.element("rocket_list_container")
|
||||||
Gui.element(function(definition, parent)
|
:draw(function(definition, parent)
|
||||||
-- Draw the internal container
|
-- Draw the internal container
|
||||||
local container = Gui.container(parent, definition.name, 200)
|
local container = Gui.elements.container(parent, 200)
|
||||||
|
|
||||||
-- Set the container style
|
-- Set the container style
|
||||||
local style = container.style
|
local style = container.style
|
||||||
style.padding = 0
|
style.padding = 0
|
||||||
|
|
||||||
local player = Gui.get_player_from_element(parent)
|
local player = Gui.get_player(parent)
|
||||||
local force_name = player.force.name
|
local force_name = player.force.name
|
||||||
-- Draw stats section
|
-- Draw stats section
|
||||||
if config.stats.show_stats then
|
if config.stats.show_stats then
|
||||||
@@ -503,7 +474,6 @@ local rocket_list_container =
|
|||||||
-- Draw build progress list
|
-- Draw build progress list
|
||||||
if config.progress.show_progress then
|
if config.progress.show_progress then
|
||||||
local col_count = 3
|
local col_count = 3
|
||||||
if check_player_permissions(player, "remote_launch") then col_count = col_count + 1 end
|
|
||||||
if check_player_permissions(player, "toggle_active") then col_count = col_count + 1 end
|
if check_player_permissions(player, "toggle_active") then col_count = col_count + 1 end
|
||||||
local progress = section(container, "progress", col_count)
|
local progress = section(container, "progress", col_count)
|
||||||
-- Label used when there are no active silos
|
-- Label used when there are no active silos
|
||||||
@@ -516,19 +486,23 @@ local rocket_list_container =
|
|||||||
update_build_progress(progress, get_progress_data(force_name))
|
update_build_progress(progress, get_progress_data(force_name))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Return the exteral container
|
-- Return the external container
|
||||||
return container.parent
|
return container.parent
|
||||||
end)
|
end)
|
||||||
:static_name(Gui.unique_static_name)
|
|
||||||
:add_to_left_flow(function(player)
|
|
||||||
return player.force.rockets_launched > 0 and Roles.player_allowed(player, "gui/rocket-info")
|
|
||||||
end)
|
|
||||||
|
|
||||||
--- Button on the top flow used to toggle the container
|
--- Add the element to the left flow with a toolbar button
|
||||||
-- @element toggle_rocket_info
|
Gui.add_left_element(rocket_list_container, function(player, element)
|
||||||
Gui.left_toolbar_button("item/rocket-silo", { "rocket-info.main-tooltip" }, rocket_list_container, function(player)
|
return player.force.rockets_launched > 0 and Roles.player_allowed(player, "gui/rocket-info")
|
||||||
return Roles.player_allowed(player, "gui/rocket-info")
|
|
||||||
end)
|
end)
|
||||||
|
Gui.create_toolbar_button{
|
||||||
|
name = "rocket_list_toggle",
|
||||||
|
left_element = rocket_list_container,
|
||||||
|
sprite = "item/rocket-silo",
|
||||||
|
tooltip = { "rocket-info.main-tooltip" },
|
||||||
|
visible = function(player, element)
|
||||||
|
return Roles.player_allowed(player, "gui/rocket-info")
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
--- Update the gui for all players on a force
|
--- Update the gui for all players on a force
|
||||||
local function update_rocket_gui_all(force_name)
|
local function update_rocket_gui_all(force_name)
|
||||||
@@ -536,11 +510,11 @@ local function update_rocket_gui_all(force_name)
|
|||||||
local milestones = get_milestone_data(force_name)
|
local milestones = get_milestone_data(force_name)
|
||||||
local progress = get_progress_data(force_name)
|
local progress = get_progress_data(force_name)
|
||||||
for _, player in pairs(game.forces[force_name].players) do
|
for _, player in pairs(game.forces[force_name].players) do
|
||||||
local frame = Gui.get_left_element(player, rocket_list_container)
|
local container = Gui.get_left_element(rocket_list_container, player)
|
||||||
local container = frame.container
|
local frame = container.frame
|
||||||
update_data_labels(container.stats.table, stats)
|
update_data_labels(frame.stats.table, stats)
|
||||||
update_data_labels(container.milestones.table, milestones)
|
update_data_labels(frame.milestones.table, milestones)
|
||||||
update_build_progress(container.progress.table, progress)
|
update_build_progress(frame.progress.table, progress)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -553,10 +527,10 @@ end)
|
|||||||
--- Update only the progress gui for a force
|
--- Update only the progress gui for a force
|
||||||
local function update_rocket_gui_progress(force_name)
|
local function update_rocket_gui_progress(force_name)
|
||||||
local progress = get_progress_data(force_name)
|
local progress = get_progress_data(force_name)
|
||||||
for _, player in pairs(game.forces[force_name].players) do
|
for _, player in pairs(game.forces[force_name].connected_players) do
|
||||||
local frame = Gui.get_left_element(player, rocket_list_container)
|
local container = Gui.get_left_element(rocket_list_container, player)
|
||||||
local container = frame.container
|
local frame = container.frame
|
||||||
update_build_progress(container.progress.table, progress)
|
update_build_progress(frame.progress.table, progress)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -590,12 +564,11 @@ Event.add(defines.events.on_robot_built_entity, on_built)
|
|||||||
local function role_update_event(event)
|
local function role_update_event(event)
|
||||||
if not config.progress.show_progress then return end
|
if not config.progress.show_progress then return end
|
||||||
local player = game.players[event.player_index]
|
local player = game.players[event.player_index]
|
||||||
local container = Gui.get_left_element(player, rocket_list_container).container
|
local container = Gui.get_left_element(rocket_list_container, player)
|
||||||
local progress_scroll = container.progress
|
local progress_scroll = container.frame.progress
|
||||||
Gui.destroy_if_valid(progress_scroll.table)
|
Gui.destroy_if_valid(progress_scroll.table)
|
||||||
|
|
||||||
local col_count = 3
|
local col_count = 3
|
||||||
if check_player_permissions(player, "remote_launch") then col_count = col_count + 1 end
|
|
||||||
if check_player_permissions(player, "toggle_active") then col_count = col_count + 1 end
|
if check_player_permissions(player, "toggle_active") then col_count = col_count + 1 end
|
||||||
local progress = progress_scroll.add{
|
local progress = progress_scroll.add{
|
||||||
type = "table",
|
type = "table",
|
||||||
|
|||||||
@@ -36,16 +36,18 @@ end
|
|||||||
|
|
||||||
--- @class FlyingText.create_above_entity_param:FlyingText.create_param
|
--- @class FlyingText.create_above_entity_param:FlyingText.create_param
|
||||||
--- @field target_entity? LuaEntity The entity to create the text above
|
--- @field target_entity? LuaEntity The entity to create the text above
|
||||||
|
--- @field offset? { x: number, y: number } Offset to move the text by
|
||||||
|
|
||||||
--- Create flying above an entity, overrides the position option of FlyingText.create
|
--- Create flying above an entity, overrides the position option of FlyingText.create
|
||||||
--- @param options FlyingText.create_above_entity_param
|
--- @param options FlyingText.create_above_entity_param
|
||||||
function FlyingText.create_above_entity(options)
|
function FlyingText.create_above_entity(options)
|
||||||
local entity = assert(options.target_entity, "A target entity is required")
|
local entity = assert(options.target_entity, "A target entity is required")
|
||||||
local size_y = entity.bounding_box.left_top.y - entity.bounding_box.right_bottom.y
|
local size_y = entity.bounding_box.left_top.y - entity.bounding_box.right_bottom.y
|
||||||
|
local offset = options.offset or { x = 0, y = 0 }
|
||||||
|
|
||||||
options.position = {
|
options.position = {
|
||||||
x = entity.position.x,
|
x = offset.x + entity.position.x,
|
||||||
y = entity.position.y - size_y * 0.25,
|
y = offset.y + entity.position.y + size_y * 0.25,
|
||||||
}
|
}
|
||||||
|
|
||||||
FlyingText.create(options)
|
FlyingText.create(options)
|
||||||
@@ -53,6 +55,7 @@ end
|
|||||||
|
|
||||||
--- @class FlyingText.create_above_player_param:FlyingText.create_param
|
--- @class FlyingText.create_above_player_param:FlyingText.create_param
|
||||||
--- @field target_player? LuaPlayer The player to create the text above
|
--- @field target_player? LuaPlayer The player to create the text above
|
||||||
|
--- @field offset? { x: number, y: number } Offset to move the text by
|
||||||
|
|
||||||
--- Create flying above a player, overrides the position option of FlyingText.create
|
--- Create flying above a player, overrides the position option of FlyingText.create
|
||||||
--- @param options FlyingText.create_above_player_param
|
--- @param options FlyingText.create_above_player_param
|
||||||
@@ -60,10 +63,11 @@ function FlyingText.create_above_player(options)
|
|||||||
local player = assert(options.target_player, "A target player is required")
|
local player = assert(options.target_player, "A target player is required")
|
||||||
local entity = player.character; if not entity then return end
|
local entity = player.character; if not entity then return end
|
||||||
local size_y = entity.bounding_box.left_top.y - entity.bounding_box.right_bottom.y
|
local size_y = entity.bounding_box.left_top.y - entity.bounding_box.right_bottom.y
|
||||||
|
local offset = options.offset or { x = 0, y = 0 }
|
||||||
|
|
||||||
options.position = {
|
options.position = {
|
||||||
x = entity.position.x,
|
x = offset.x + entity.position.x,
|
||||||
y = entity.position.y - size_y * 0.25,
|
y = offset.y + entity.position.y + size_y * 0.25,
|
||||||
}
|
}
|
||||||
|
|
||||||
FlyingText.create(options)
|
FlyingText.create(options)
|
||||||
@@ -71,6 +75,7 @@ end
|
|||||||
|
|
||||||
--- @class FlyingText.create_as_player_param:FlyingText.create_param
|
--- @class FlyingText.create_as_player_param:FlyingText.create_param
|
||||||
--- @field target_player? LuaPlayer The player to create the text above
|
--- @field target_player? LuaPlayer The player to create the text above
|
||||||
|
--- @field offset? { x: number, y: number } Offset to move the text by
|
||||||
|
|
||||||
--- Create flying above a player, overrides the position and color option of FlyingText.create
|
--- Create flying above a player, overrides the position and color option of FlyingText.create
|
||||||
--- @param options FlyingText.create_as_player_param
|
--- @param options FlyingText.create_as_player_param
|
||||||
@@ -78,11 +83,12 @@ function FlyingText.create_as_player(options)
|
|||||||
local player = assert(options.target_player, "A target player is required")
|
local player = assert(options.target_player, "A target player is required")
|
||||||
local entity = player.character; if not entity then return end
|
local entity = player.character; if not entity then return end
|
||||||
local size_y = entity.bounding_box.left_top.y - entity.bounding_box.right_bottom.y
|
local size_y = entity.bounding_box.left_top.y - entity.bounding_box.right_bottom.y
|
||||||
|
local offset = options.offset or { x = 0, y = 0 }
|
||||||
|
|
||||||
options.color = player.chat_color
|
options.color = player.chat_color
|
||||||
options.position = {
|
options.position = {
|
||||||
x = entity.position.x,
|
x = offset.x + entity.position.x,
|
||||||
y = entity.position.y - size_y * 0.25,
|
y = offset.y + entity.position.y + size_y * 0.25,
|
||||||
}
|
}
|
||||||
|
|
||||||
FlyingText.create(options)
|
FlyingText.create(options)
|
||||||
|
|||||||
Reference in New Issue
Block a user