-- Concept Structure
+-- Root
+--> [data_label] - the static label
+--> [properties.data_name] - the data label which can be updated
+Gui.new_concept('data_label')
+:set_data_label_name('game_ticks')
+:set_data_caption('0')
+:set_data_format(function(concept,element,data,...)
+ -- This is used with update_data_element and update_from_parent
+local caption = tostirng('data')
+ local tooltip = 'This game has beeing running for: '..caption..' ticks'
+ return caption, tooltip
+end)
-- Concept Structure
+-- Root
+--> [footer] - the footer frame
+-->> footer_caption - the lable with the title in it
+-->> footer_content - the area to contain butons
+Gui.new_concept('footer')
+:set_title('Example Footer')
-- Concept Structure
+-- Root
+--> [header] - the header frame
+-->> header_caption - the lable with the title in it
+-->> header_content - the area to contain butons
+Gui.new_concept('header')
+:set_title('Example Header')
-- Concept Structure
+-- Root
+--> [scroll_table] - the scroll area
+-->> table - the table area
+Gui.new_concept('scroll_table')
+:set_height(200)
+:set_column_count(2)
-- Concept Structure
+-- Root
+--> [unit_label] - the static label
+--> [properties.data_name] - the data label which can be updated
+--> [properties.data_name..'_unit'] - the data label unit which can be updated
+Gui.new_concept('unit_label')
+:set_data_label_name('game_ticks')
+:set_data_caption('0')
+:set_data_unit('ticks')
+:set_data_format(function(concept,element,data,...)
+ -- This is used with update_data_element and update_from_parent
+local caption = tostirng(data)
+ local unit = data > 1and'ticks'or'tick'
+ local tooltip = 'This game has beeing running for: '..caption..' ticks'
+ return caption, unit, tooltip
+end)
-- Concept Structure
+-- Root
+--> [data_label] - the static label
+--> [properties.data_name] - the data label which can be updated
+Gui.new_concept('data_label')
+:set_data_label_name('game_ticks')
+:set_data_caption('0')
+:set_data_format(function(concept,element,data,...)
+ -- This is used with update_data_element and update_from_parent
+local caption = tostirng('data')
+ local tooltip = 'This game has beeing running for: '..caption..' ticks'
+ return caption, tooltip
+end)
-- Concept Structure
+-- Root
+--> [footer] - the footer frame
+-->> footer_caption - the lable with the title in it
+-->> footer_content - the area to contain butons
+Gui.new_concept('footer')
+:set_title('Example Footer')
-- Concept Structure
+-- Root
+--> [header] - the header frame
+-->> header_caption - the lable with the title in it
+-->> header_content - the area to contain butons
+Gui.new_concept('header')
+:set_title('Example Header')
-- Concept Structure
+-- Root
+--> [scroll_table] - the scroll area
+-->> table - the table area
+Gui.new_concept('scroll_table')
+:set_height(200)
+:set_column_count(2)
-- Concept Structure
+-- Root
+--> [unit_label] - the static label
+--> [properties.data_name] - the data label which can be updated
+--> [properties.data_name..'_unit'] - the data label unit which can be updated
+Gui.new_concept('unit_label')
+:set_data_label_name('game_ticks')
+:set_data_caption('0')
+:set_data_unit('ticks')
+:set_data_format(function(concept,element,data,...)
+ -- This is used with update_data_element and update_from_parent
+local caption = tostirng(data)
+ local unit = data > 1and'ticks'or'tick'
+ local tooltip = 'This game has beeing running for: '..caption..' ticks'
+ return caption, unit, tooltip
+end)
@@ -334,7 +335,7 @@
generated by LDoc
diff --git a/expcore/gui/core.lua b/expcore/gui/core.lua
index 5365d54a..23b13a5b 100644
--- a/expcore/gui/core.lua
+++ b/expcore/gui/core.lua
@@ -139,6 +139,45 @@ function Gui.destroy(element)
return false
end
+--[[-- Finds and returns a gui element if it is valid from a long chain of element names or concepts
+@tparam LuaGuiElement element the root element to start checking from
+@tparam ?string|table ... element names or element concepts that point to your element
+@treturn[1] boolean if the element was found, failed
+@treturn[1] string the path of the element that the search stoped at
+@treturn[2] boolean if the element was found, found
+@treturn[2] LuaGuiElement the element that was found
+@usage-- Getting the center gui
+local exists, center = Gui.find(player,'gui','center')
+]]
+function Gui.find(element,...)
+ local path = tostring(element.name)
+ for _,next_element_name in pairs{...} do
+ if type(next_element_name) == 'table' then
+ next_element_name = next_element_name.name
+ end
+
+ element = element[next_element_name]
+ path = path..'.'..tostring(next_element_name)
+ if not Gui.valid(element) then
+ return false, path
+ end
+ end
+ return true, element
+end
+
+--[[-- Checks if a gui element exists or not, returns it if found else the path where it failed
+@see Gui.find
+@tparam LuaGuiElement element the root element to start checking from
+@tparam ?string|table ... element names or element concepts that point to your element
+@treturn[1] boolean if the element was found, failed
+@treturn[1] string the path of the element that the search stoped at
+@treturn[2] boolean if the element was found, found
+@treturn[2] LuaGuiElement the element that was found
+@usage-- Getting the center gui
+local exists, center = Gui.exists(player,'gui','center')
+]]
+Gui.exists = Gui.find
+
--[[-- Toggles the enabled state of an element
@tparam LuaGuiElement element the element that you want to toggle the enabled state of
@treturn boolean the new enabled state of the element
diff --git a/expcore/gui/styles/expstyle/alignment.lua b/expcore/gui/styles/expstyle/alignment.lua
index 23477684..80c44f8a 100644
--- a/expcore/gui/styles/expstyle/alignment.lua
+++ b/expcore/gui/styles/expstyle/alignment.lua
@@ -1,13 +1,14 @@
--[[-- Core Module - ExpStyle
- @module ExpStyle
+ @core ExpStyle
+ @alias expstyle
]]
-local Gui = require 'expcore.gui' --- @dep expcore.gui
+local Gui = require 'expcore.gui' -- @dep expcore.gui
-Gui.require_concept 'flow' --- @dep gui.concept.flow
+Gui.require_concept 'flow' -- @dep gui.concept.flow
--[[-- A flow which can be used to align text and other elements
-@see flow
+@see Gui.flow
@element alignment
@usage-- Concept Structure
-- Root
diff --git a/expcore/gui/styles/expstyle/container.lua b/expcore/gui/styles/expstyle/container.lua
index ca1a62bb..00ac52ac 100644
--- a/expcore/gui/styles/expstyle/container.lua
+++ b/expcore/gui/styles/expstyle/container.lua
@@ -2,12 +2,12 @@
@module ExpStyle
]]
-local Gui = require 'expcore.gui' --- @dep expcore.gui
+local Gui = require 'expcore.gui' -- @dep expcore.gui
-Gui.require_concept 'frame' --- @dep gui.concept.frame
+Gui.require_concept 'frame' -- @dep gui.concept.frame
--[[-- A container frame that can be used to add a boader around your content
-@see frame
+@see Gui.frame
@element container
@usage-- Concept Structure
-- Root
diff --git a/expcore/gui/styles/expstyle/data_label.lua b/expcore/gui/styles/expstyle/data_label.lua
index c6ca002c..62c39e73 100644
--- a/expcore/gui/styles/expstyle/data_label.lua
+++ b/expcore/gui/styles/expstyle/data_label.lua
@@ -2,15 +2,15 @@
@module ExpStyle
]]
-local Gui = require 'expcore.gui' --- @dep expcore.gui
+local Gui = require 'expcore.gui' -- @dep expcore.gui
-Gui.require_concept 'label' --- @dep gui.concept.frame
+Gui.require_concept 'label' -- @dep gui.concept.frame
local right_align =
Gui.new_concept('alignment')
--[[-- A label pair which has a static label and a data label which can be changed
-@see label
+@see Gui.label
@element data_label
@usage-- Concept Structure
-- Root
@@ -64,6 +64,12 @@ end)
return data_label_element
end)
+--[[-- Updates the caption and tooltip of the data label using the data format function
+@tparam LuaGuiElement element the data label element that you want to update
+@tparam any data the data that you want to pass to the format function
+@usage-- Updating the data to the current game tick
+data_label:update_data_element(element,game.tick)
+]]
function data_label:update_data_element(element,data,...)
local caption, tooltip = self.properties.data_format(self,element,data,...)
if caption then
@@ -74,6 +80,12 @@ function data_label:update_data_element(element,data,...)
end
end
+--[[-- Updates the caption and tooltip of the data label using the data format function, given the parent of the data label
+@tparam LuaGuiElement parent the parent element to the data label element that you want to update
+@tparam any data the data that you want to pass to the format function
+@usage-- Updating the data to the current game tick
+data_label:update_from_parent(parent,game.tick)
+]]
function data_label:update_from_parent(parent,data,...)
local properties = self.properties
local data_name = properties.data_label_name or properties.name..'_data'
diff --git a/expcore/gui/styles/expstyle/footer.lua b/expcore/gui/styles/expstyle/footer.lua
index 3497832b..2ca0a762 100644
--- a/expcore/gui/styles/expstyle/footer.lua
+++ b/expcore/gui/styles/expstyle/footer.lua
@@ -2,15 +2,15 @@
@module ExpStyle
]]
-local Gui = require 'expcore.gui' --- @dep expcore.gui
+local Gui = require 'expcore.gui' -- @dep expcore.gui
-Gui.require_concept 'frame' --- @dep gui.concept.table
+Gui.require_concept 'frame' -- @dep gui.concept.table
local right_align =
Gui.new_concept('alignment')
--[[-- A frame that acts as a footer to a section of content
-@see frame
+@see Gui.frame
@element footer
@tparam string tooltip the tooltip to show on the title
@usage-- Concept Structure
diff --git a/expcore/gui/styles/expstyle/header.lua b/expcore/gui/styles/expstyle/header.lua
index 94991865..f570442e 100644
--- a/expcore/gui/styles/expstyle/header.lua
+++ b/expcore/gui/styles/expstyle/header.lua
@@ -2,15 +2,15 @@
@module ExpStyle
]]
-local Gui = require 'expcore.gui' --- @dep expcore.gui
+local Gui = require 'expcore.gui' -- @dep expcore.gui
-Gui.require_concept 'frame' --- @dep gui.concept.table
+Gui.require_concept 'frame' -- @dep gui.concept.table
local right_align =
Gui.new_concept('alignment')
--[[-- A frame that acts as a header to a section of content
-@see frame
+@see Gui.frame
@element header
@tparam string tooltip the tooltip to show on the title
@usage-- Concept Structure
diff --git a/expcore/gui/styles/expstyle/index.lua b/expcore/gui/styles/expstyle/index.lua
index aa8afa39..6d773cfb 100644
--- a/expcore/gui/styles/expstyle/index.lua
+++ b/expcore/gui/styles/expstyle/index.lua
@@ -1,7 +1,18 @@
--[[-- Core Module - ExpStyle
- @core ExpStyle
+ @module ExpStyle
+ @alias expstyle
]]
+--- @dep expcore.gui
+
+--- @dep gui.concept.frame
+
+--- @dep gui.concept.flow
+
+--- @dep gui.concept.table
+
+--- @dep gui.concept.scroll
+
local function r(name)
require('expcore.gui.styles.expstyle.'..name)
end
@@ -9,5 +20,9 @@ end
r 'container'
r 'alignment'
r 'header'
+r 'footer'
r 'scroll_table'
-r 'time_label'
\ No newline at end of file
+r 'time_label'
+r 'data_label'
+r 'unit_label'
+r 'toggle_button'
\ No newline at end of file
diff --git a/expcore/gui/styles/expstyle/scroll_table.lua b/expcore/gui/styles/expstyle/scroll_table.lua
index 411851b7..cd48ff0a 100644
--- a/expcore/gui/styles/expstyle/scroll_table.lua
+++ b/expcore/gui/styles/expstyle/scroll_table.lua
@@ -2,10 +2,10 @@
@module ExpStyle
]]
-local Gui = require 'expcore.gui' --- @dep expcore.gui
+local Gui = require 'expcore.gui' -- @dep expcore.gui
-Gui.require_concept 'table' --- @dep gui.concept.table
-Gui.require_concept 'scroll' --- @dep gui.concept.scroll
+Gui.require_concept 'table' -- @dep gui.concept.table
+Gui.require_concept 'scroll' -- @dep gui.concept.scroll
local scroll_area =
Gui.new_concept('scroll')
@@ -13,7 +13,7 @@ Gui.new_concept('scroll')
:set_horizontal_scroll('never')
--[[-- A table that is inside a vertical scroll area
-@see table
+@see Gui.table
@element scroll_table
@tparam number hight the max hight of the scroll area
@usage-- Concept Structure
diff --git a/expcore/gui/styles/expstyle/time_label.lua b/expcore/gui/styles/expstyle/time_label.lua
index 64f5f6b7..3fc4b004 100644
--- a/expcore/gui/styles/expstyle/time_label.lua
+++ b/expcore/gui/styles/expstyle/time_label.lua
@@ -2,7 +2,7 @@
@module ExpStyle
]]
-local Gui = require 'expcore.gui' --- @dep expcore.gui
+local Gui = require 'expcore.gui' -- @dep expcore.gui
local format_time = ext_require('expcore.common','format_time') --- @dep expcore.common
--- Converts a tick into string format with workds and symbols
diff --git a/expcore/gui/styles/expstyle/toggle_button.lua b/expcore/gui/styles/expstyle/toggle_button.lua
index 06adc602..00a894c5 100644
--- a/expcore/gui/styles/expstyle/toggle_button.lua
+++ b/expcore/gui/styles/expstyle/toggle_button.lua
@@ -2,12 +2,12 @@
@module ExpStyle
]]
-local Gui = require 'expcore.gui' --- @dep expcore.gui
+local Gui = require 'expcore.gui' -- @dep expcore.gui
-Gui.require_concept 'button' --- @dep gui.concept.table
+Gui.require_concept 'button' -- @dep gui.concept.table
--[[-- A button that will toggle its caption each time it is pressed
-@see button
+@see Gui.button
@element toggle_button
@tparam string alt_caption the caption to show on the button in its true state
@tparam string alt_tooltip the tooltip to show on the button in its true state
diff --git a/expcore/gui/styles/expstyle/unit_label.lua b/expcore/gui/styles/expstyle/unit_label.lua
index 3295997a..50bdd4b5 100644
--- a/expcore/gui/styles/expstyle/unit_label.lua
+++ b/expcore/gui/styles/expstyle/unit_label.lua
@@ -2,15 +2,15 @@
@module ExpStyle
]]
-local Gui = require 'expcore.gui' --- @dep expcore.gui
+local Gui = require 'expcore.gui' -- @dep expcore.gui
-Gui.require_concept 'label' --- @dep gui.concept.frame
+Gui.require_concept 'label' -- @dep gui.concept.frame
local right_align =
Gui.new_concept('alignment')
--[[-- A label triplet which has a static label, a data label which can be changed, and a unit label
-@see label
+@see Gui.label
@see data_label
@element unit_label
@usage-- Concept Structure
@@ -60,6 +60,12 @@ end)
return element
end)
+--[[-- Updates the caption and tooltip and unit of the data label using the data format function
+@tparam LuaGuiElement element the unit label element that you want to update
+@tparam any data the data that you want to pass to the format function
+@usage-- Updating the data to the current game tick
+unit_label:update_data_element(element,game.tick)
+]]
function unit_label:update_data_element(element,data,...)
local caption, unit, tooltip = self.properties.data_format(self,element,data,...)
local unit_element = element.parent.parent[element.name..'_unit']
@@ -75,6 +81,12 @@ function unit_label:update_data_element(element,data,...)
end
end
+--[[-- Updates the caption and tooltip and unit of the unit label using the data format function, given the parent of the unit label
+@tparam LuaGuiElement parent the parent element to the unit label element that you want to update
+@tparam any data the data that you want to pass to the format function
+@usage-- Updating the data to the current game tick
+unit_label:update_from_parent(parent,game.tick)
+]]
function unit_label:update_from_parent(parent,data,...)
local properties = self.properties
local data_name = properties.data_label_name or properties.name..'_data'