mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-31 13:01:39 +09:00
Added some elements to expstyle
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
local Gui = require 'expcore.gui.core'
|
local Gui = require 'expcore.gui.core'
|
||||||
|
|
||||||
--[[-- A piece of text.
|
--[[-- A piece of text.
|
||||||
@element frame
|
@element label
|
||||||
|
|
||||||
@tparam ?string|Concepts.LocalisedString caption the caption that will show in the label
|
@tparam ?string|Concepts.LocalisedString caption the caption that will show in the label
|
||||||
@tparam ?string|Concepts.LocalisedString description the description that will show on the label
|
@tparam ?string|Concepts.LocalisedString description the description that will show on the label
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ end
|
|||||||
Gui.require_concept('expgaming') --- @dep Gui.style.frame
|
Gui.require_concept('expgaming') --- @dep Gui.style.frame
|
||||||
]]
|
]]
|
||||||
function Gui.require_style(style_name)
|
function Gui.require_style(style_name)
|
||||||
require('expcore.gui.styles.'..style_name)
|
require('expcore.gui.styles.'..style_name..'.index')
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[-- Gets a gui concept from name, id, or its self
|
--[[-- Gets a gui concept from name, id, or its self
|
||||||
|
|||||||
@@ -417,6 +417,7 @@ end
|
|||||||
|
|
||||||
--[[-- Calls all the draw functions in order to create this concept in game; will also store and sync the instance if stores are used
|
--[[-- Calls all the draw functions in order to create this concept in game; will also store and sync the instance if stores are used
|
||||||
@tparam LuaGuiElement parent_element the element that the concept will use as a base
|
@tparam LuaGuiElement parent_element the element that the concept will use as a base
|
||||||
|
@tparam[opt] string override_name when given this will be the name of the element rather than the concept id
|
||||||
@treturn LuaGuiElement the element that was created and then passed though and returned by the draw functions
|
@treturn LuaGuiElement the element that was created and then passed though and returned by the draw functions
|
||||||
@usage-- Drawing the custom button concept
|
@usage-- Drawing the custom button concept
|
||||||
local custom_button =
|
local custom_button =
|
||||||
@@ -425,10 +426,12 @@ Gui.get_concept('CustomButton')
|
|||||||
-- Note that the draw function from button was cloned, so unless we want to alter the base button we dont need a new draw define
|
-- Note that the draw function from button was cloned, so unless we want to alter the base button we dont need a new draw define
|
||||||
custom_button:draw(game.player.gui.left)
|
custom_button:draw(game.player.gui.left)
|
||||||
]]
|
]]
|
||||||
function Prototype:draw(parent_element,...)
|
function Prototype:draw(parent_element,override_name,...)
|
||||||
|
local old_name = self.properties.name
|
||||||
local parent = parent_element
|
local parent = parent_element
|
||||||
local element
|
local element
|
||||||
|
|
||||||
|
if override_name then self.properties.name = override_name end
|
||||||
-- Loop over all the draw defines, element is updated when a value is returned
|
-- Loop over all the draw defines, element is updated when a value is returned
|
||||||
for _,draw_callback in pairs(self.draw_callbacks) do
|
for _,draw_callback in pairs(self.draw_callbacks) do
|
||||||
local success, _element, _parent = pcall(draw_callback,self.properties,parent,element,...)
|
local success, _element, _parent = pcall(draw_callback,self.properties,parent,element,...)
|
||||||
@@ -436,10 +439,14 @@ function Prototype:draw(parent_element,...)
|
|||||||
if _element then element = _element end
|
if _element then element = _element end
|
||||||
if _parent then parent = _parent end
|
if _parent then parent = _parent end
|
||||||
elseif not success then
|
elseif not success then
|
||||||
|
self.properties.name = old_name
|
||||||
error('Gui draw handler error with '..self.debug_name..':\n\t'.._element)
|
error('Gui draw handler error with '..self.debug_name..':\n\t'.._element)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Return the name back to its previous value
|
||||||
|
self.properties.name = old_name
|
||||||
|
|
||||||
-- Adds the instance if instance store is used
|
-- Adds the instance if instance store is used
|
||||||
if self.add_instance then
|
if self.add_instance then
|
||||||
self.add_instance(element)
|
self.add_instance(element)
|
||||||
|
|||||||
47
expcore/gui/styles/expstyle/alignment.lua
Normal file
47
expcore/gui/styles/expstyle/alignment.lua
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
--[[-- Core Module - ExpStyle
|
||||||
|
@module ExpStyle
|
||||||
|
]]
|
||||||
|
|
||||||
|
local Gui = require 'expcore.gui' --- @dep expcore.gui
|
||||||
|
|
||||||
|
Gui.require_concept 'flow' --- @dep gui.concept.flow
|
||||||
|
|
||||||
|
--[[-- A flow which can be used to align text and other elements
|
||||||
|
@element alignment
|
||||||
|
@usage-- Concept Structure
|
||||||
|
-- Root
|
||||||
|
--> [alignment] - the alignment area
|
||||||
|
Gui.new_concept('alignment')
|
||||||
|
:set_horizontal_align('center')
|
||||||
|
]]
|
||||||
|
|
||||||
|
Gui.new_concept('flow')
|
||||||
|
:save_as('alignment')
|
||||||
|
|
||||||
|
:new_property('horizontal_align',nil,'right')
|
||||||
|
:new_property('vertical_align',nil,'center')
|
||||||
|
:new_property('width')
|
||||||
|
:new_property('height')
|
||||||
|
|
||||||
|
:define_draw(function(properties,parent,element)
|
||||||
|
local style = element.style
|
||||||
|
Gui.set_padding(element,1,1,2,2)
|
||||||
|
|
||||||
|
-- Set the alignment of the flow
|
||||||
|
style.horizontal_align = properties.horizontal_align
|
||||||
|
style.vertical_align = properties.vertical_align
|
||||||
|
|
||||||
|
-- Set the stretchablity based on the alignment
|
||||||
|
style.horizontally_stretchable = style.horizontal_align ~= 'center'
|
||||||
|
style.vertically_stretchable = style.vertical_align ~= 'center'
|
||||||
|
|
||||||
|
-- Set the width if given
|
||||||
|
local width = properties.width
|
||||||
|
if width then style.width = width end
|
||||||
|
|
||||||
|
-- Set the hieght if given
|
||||||
|
local height = properties.height
|
||||||
|
if height then style.height = height end
|
||||||
|
|
||||||
|
return element
|
||||||
|
end)
|
||||||
36
expcore/gui/styles/expstyle/container.lua
Normal file
36
expcore/gui/styles/expstyle/container.lua
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
--[[-- Core Module - ExpStyle
|
||||||
|
@module ExpStyle
|
||||||
|
]]
|
||||||
|
|
||||||
|
local Gui = require 'expcore.gui' --- @dep expcore.gui
|
||||||
|
|
||||||
|
Gui.require_concept 'frame' --- @dep gui.concept.frame
|
||||||
|
|
||||||
|
--[[-- A container frame that can be used to add a boader around your content
|
||||||
|
@element container
|
||||||
|
@usage-- Concept Structure
|
||||||
|
-- Root
|
||||||
|
--> [container] - the outer frame
|
||||||
|
-->> container - the content area
|
||||||
|
Gui.new_concept('container')
|
||||||
|
]]
|
||||||
|
|
||||||
|
Gui.new_concept('frame')
|
||||||
|
:save_as('container')
|
||||||
|
:define_draw(function(properties,parent,element)
|
||||||
|
-- Update the outter frame padding
|
||||||
|
element.style.padding = 2
|
||||||
|
|
||||||
|
-- Add the inner frame
|
||||||
|
element = element.add{
|
||||||
|
name = 'container',
|
||||||
|
type = 'frame',
|
||||||
|
direction = properties.direction,
|
||||||
|
style = 'window_content_frame_packed'
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Update the inner frame padding
|
||||||
|
element.style.padding = 0
|
||||||
|
|
||||||
|
return element
|
||||||
|
end)
|
||||||
49
expcore/gui/styles/expstyle/header.lua
Normal file
49
expcore/gui/styles/expstyle/header.lua
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
--[[-- Core Module - ExpStyle
|
||||||
|
@module ExpStyle
|
||||||
|
]]
|
||||||
|
|
||||||
|
local Gui = require 'expcore.gui' --- @dep expcore.gui
|
||||||
|
|
||||||
|
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
|
||||||
|
@element header
|
||||||
|
@tparam string tooltip the tooltip to show on the title
|
||||||
|
@usage-- 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('frame')
|
||||||
|
:save_as('header')
|
||||||
|
:new_property('tooltip')
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
:define_draw(function(properties,parent,element)
|
||||||
|
-- Update the table style
|
||||||
|
Gui.set_padding(element,2,2,4,4)
|
||||||
|
element.style = 'subheader_frame'
|
||||||
|
element.caption = nil
|
||||||
|
|
||||||
|
local style = element.style
|
||||||
|
style.horizontally_stretchable = true
|
||||||
|
style.use_header_filler = false
|
||||||
|
|
||||||
|
-- Add the caption to the frame
|
||||||
|
element.add{
|
||||||
|
type = 'label',
|
||||||
|
name = 'header_caption',
|
||||||
|
caption = properties.title,
|
||||||
|
tooltip = properties.tooltip
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Add the right align area
|
||||||
|
local align = right_align:draw(element,'header_content')
|
||||||
|
|
||||||
|
return align
|
||||||
|
end)
|
||||||
13
expcore/gui/styles/expstyle/index.lua
Normal file
13
expcore/gui/styles/expstyle/index.lua
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
--[[-- Core Module - ExpStyle
|
||||||
|
@core ExpStyle
|
||||||
|
]]
|
||||||
|
|
||||||
|
local function r(name)
|
||||||
|
require('expcore.gui.styles.expstyle.'..name)
|
||||||
|
end
|
||||||
|
|
||||||
|
r 'container'
|
||||||
|
r 'alignment'
|
||||||
|
r 'header'
|
||||||
|
r 'scroll_table'
|
||||||
|
r 'time_label'
|
||||||
56
expcore/gui/styles/expstyle/scroll_table.lua
Normal file
56
expcore/gui/styles/expstyle/scroll_table.lua
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
--[[-- Core Module - ExpStyle
|
||||||
|
@module ExpStyle
|
||||||
|
]]
|
||||||
|
|
||||||
|
local Gui = require 'expcore.gui' --- @dep expcore.gui
|
||||||
|
|
||||||
|
Gui.require_concept 'table' --- @dep gui.concept.table
|
||||||
|
Gui.require_concept 'scroll' --- @dep gui.concept.scroll
|
||||||
|
|
||||||
|
local scroll_area =
|
||||||
|
Gui.new_concept('scroll')
|
||||||
|
:set_vertical_scroll('auto-and-reserve-space')
|
||||||
|
:set_horizontal_scroll('never')
|
||||||
|
|
||||||
|
--[[-- A table that is inside a vertical scroll area
|
||||||
|
@element scroll_table
|
||||||
|
@tparam number hight the max hight of the scroll area
|
||||||
|
@usage-- Concept Structure
|
||||||
|
-- Root
|
||||||
|
--> [scroll_table] - the scroll area
|
||||||
|
-->> table - the table area
|
||||||
|
]]
|
||||||
|
|
||||||
|
Gui.new_concept('table')
|
||||||
|
:save_as('scroll_table')
|
||||||
|
:new_property('hight',nil,100)
|
||||||
|
|
||||||
|
-- Add a scroll before the table is drawn
|
||||||
|
:define_pre_draw(function(properties,parent,element)
|
||||||
|
local scroll = scroll_area:draw(parent,properties.name)
|
||||||
|
|
||||||
|
-- Set the scroll style
|
||||||
|
Gui.set_padding(scroll,1,1,2,2)
|
||||||
|
scroll.style.horizontally_stretchable = true
|
||||||
|
scroll.style.maximal_height = properties.hight
|
||||||
|
|
||||||
|
-- Change the name of the element to table before it is drawn
|
||||||
|
properties.name = 'table'
|
||||||
|
|
||||||
|
return element, scroll
|
||||||
|
end)
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
:define_draw(function(properties,parent,element)
|
||||||
|
-- Update the table style
|
||||||
|
local style = element.style
|
||||||
|
style.padding = 0
|
||||||
|
style.horizontally_stretchable = true
|
||||||
|
style.vertical_align = 'center'
|
||||||
|
style.cell_padding = 0
|
||||||
|
|
||||||
|
-- Change the stored name back to the actual name
|
||||||
|
properties.name = element.parent.name
|
||||||
|
|
||||||
|
return element
|
||||||
|
end)
|
||||||
86
expcore/gui/styles/expstyle/time_label.lua
Normal file
86
expcore/gui/styles/expstyle/time_label.lua
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
--[[-- Core Module - ExpStyle
|
||||||
|
@module ExpStyle
|
||||||
|
]]
|
||||||
|
|
||||||
|
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
|
||||||
|
local function get_format(properties,time)
|
||||||
|
local caption, tooltip
|
||||||
|
|
||||||
|
-- Check if a custom format is wanted
|
||||||
|
if properties.time_format then
|
||||||
|
-- Get the caption
|
||||||
|
local format = table.deep_copy(properties.time_format)
|
||||||
|
caption = format_time(time,format)
|
||||||
|
|
||||||
|
-- Get the tooltip, always long format
|
||||||
|
format.long = true
|
||||||
|
tooltip = format_time(time,format)
|
||||||
|
|
||||||
|
else
|
||||||
|
-- Get the caption
|
||||||
|
caption = format_time(time,{
|
||||||
|
hours = properties.use_hours,
|
||||||
|
minutes = true,
|
||||||
|
seconds = true
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Get the tooltip, same as the caption but long format
|
||||||
|
tooltip = format_time(time,{
|
||||||
|
hours = properties.use_hours,
|
||||||
|
minutes = true,
|
||||||
|
seconds = true,
|
||||||
|
long = true
|
||||||
|
})
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
return caption, tooltip
|
||||||
|
end
|
||||||
|
|
||||||
|
--[[-- A label that show time in a nice, user friendly way
|
||||||
|
@element time_label
|
||||||
|
@tparam number time the time to display in tick
|
||||||
|
@usage-- Concept Structure
|
||||||
|
-- Root
|
||||||
|
--> [time_label] - the label with the time
|
||||||
|
]]
|
||||||
|
|
||||||
|
local time_label =
|
||||||
|
Gui.new_concept()
|
||||||
|
:save_as('time_label')
|
||||||
|
|
||||||
|
-- Properties
|
||||||
|
:new_property('time')
|
||||||
|
:new_property('use_hours',nil,false)
|
||||||
|
:new_property('time_format')
|
||||||
|
|
||||||
|
-- Draw
|
||||||
|
:define_draw(function(properties,parent,element,time)
|
||||||
|
-- Get the caption and tooltip
|
||||||
|
local caption, tooltip = get_format(properties,time or properties.time)
|
||||||
|
|
||||||
|
-- Draw a label
|
||||||
|
element = parent.add{
|
||||||
|
name = properties.name,
|
||||||
|
type = 'label',
|
||||||
|
caption = caption,
|
||||||
|
tooltip = tooltip
|
||||||
|
}
|
||||||
|
|
||||||
|
return element
|
||||||
|
end)
|
||||||
|
|
||||||
|
--[[-- Updates the time that is on a label
|
||||||
|
@tparam LuaGuiElement element the label that you want to update
|
||||||
|
@tparam number time the number of tick you want it to show
|
||||||
|
@usage-- Update the time to show game time
|
||||||
|
time_label:update_time(element,game.time)
|
||||||
|
]]
|
||||||
|
function time_label:update_time(element,time)
|
||||||
|
local caption, tooltip = get_format(self.properties,time)
|
||||||
|
element.caption = caption
|
||||||
|
element.tooltip = tooltip
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user