mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 12:31:41 +09:00
Added Comments to all gui files
This commit is contained in:
@@ -1,6 +1,24 @@
|
||||
--- Gui class define for silders
|
||||
--[[
|
||||
>>>> Functions
|
||||
Slider.new_slider(name) --- Creates a new slider element define
|
||||
|
||||
Slider._prototype:on_element_update(callback) --- Registers a handler for when an element instance updates
|
||||
Slider._prototype:on_store_update(callback) --- Registers a handler for when the stored value updates
|
||||
|
||||
Slider._prototype:set_range(min,max) --- Sets the range of a slider, if not used will use default values for a slider
|
||||
Slider._prototype:draw_label(element) --- Draws a new label and links its value to the value of this slider, if no store then it will only show one value per player
|
||||
Slider._prototype:enable_auto_draw_label(state) --- Enables auto draw of the label, the label will share the same parent element as the slider
|
||||
|
||||
Other functions present from expcore.gui.core
|
||||
]]
|
||||
local Gui = require './core'
|
||||
local Game = require 'utils.game'
|
||||
|
||||
--- Gets the active lables for a define
|
||||
-- @tparam define table the define to get the labels for
|
||||
-- @tparam element LuaGuiElement the element that will be used to get the category
|
||||
-- @treturn table the table of active instances for the slider lables
|
||||
local function get_labels(define,element)
|
||||
local function cat(e)
|
||||
return e.player_index
|
||||
@@ -19,6 +37,9 @@ local function get_labels(define,element)
|
||||
return instances
|
||||
end
|
||||
|
||||
--- Gets and updates the label values
|
||||
-- @tparam define table the define to get the labels for
|
||||
-- @tparam element LuaGuiElement the element that will be used to get the category
|
||||
local function update_lables(define,element)
|
||||
local instances = get_labels(define,element)
|
||||
local value = element.slider_value
|
||||
@@ -33,6 +54,10 @@ local function update_lables(define,element)
|
||||
end
|
||||
end
|
||||
|
||||
--- Event call for on_value_changed and store update
|
||||
-- @tparam define table the define that this is acting on
|
||||
-- @tparam element LuaGuiElement the element that triggered the event
|
||||
-- @tparam value number the new value for the slider
|
||||
local function event_call(define,element,value)
|
||||
local player = Game.get_player_by_index(element.player_index)
|
||||
|
||||
@@ -40,26 +65,34 @@ local function event_call(define,element,value)
|
||||
local delta = max-min
|
||||
local percent = delta == 0 and 0 or (value-min)/delta
|
||||
|
||||
if define.events.on_change then
|
||||
define.events.on_change(player,element,value,percent)
|
||||
if define.events.on_element_update then
|
||||
define.events.on_element_update(player,element,value,percent)
|
||||
end
|
||||
|
||||
update_lables(define,element)
|
||||
end
|
||||
|
||||
local function store_call(self,element,value)
|
||||
--- Store call for store update
|
||||
-- @tparam define table the define that this is acting on
|
||||
-- @tparam element LuaGuiElement the element that triggered the event
|
||||
-- @tparam value number the new value for the slider
|
||||
local function store_call(define,element,value)
|
||||
element.slider_value = value
|
||||
event_call(self,element,value)
|
||||
event_call(define,element,value)
|
||||
end
|
||||
|
||||
local Slider = {
|
||||
_prototype=Gui._prototype_factory{
|
||||
on_change = Gui._event_factory('on_change'),
|
||||
on_element_update = Gui._event_factory('on_element_update'),
|
||||
on_store_update = Gui._event_factory('on_store_update'),
|
||||
add_store = Gui._store_factory(store_call),
|
||||
add_sync_store = Gui._sync_store_factory(store_call)
|
||||
}
|
||||
}
|
||||
|
||||
--- Creates a new slider element define
|
||||
-- @tparam[opt] name string the optional debug name that can be added
|
||||
-- @treturn table the new slider element define
|
||||
function Slider.new_slider(name)
|
||||
|
||||
local self = Gui._define_factory(Slider._prototype)
|
||||
@@ -112,6 +145,10 @@ function Slider.new_slider(name)
|
||||
return self
|
||||
end
|
||||
|
||||
--- Sets the range of a slider, if not used will use default values for a slider
|
||||
-- @tparam[opt] min number the minimum value that the slider can take
|
||||
-- @tparam[opt] max number the maximum value that the slider can take
|
||||
-- @treturn self the define to allow chaining
|
||||
function Slider._prototype:set_range(min,max)
|
||||
self.min = min
|
||||
self.max = max
|
||||
@@ -127,6 +164,9 @@ function Slider._prototype:set_range(min,max)
|
||||
return self
|
||||
end
|
||||
|
||||
--- Draws a new label and links its value to the value of this slider, if no store then it will only show one value per player
|
||||
-- @tparam element LuaGuiElement the parent element that the lable will be drawn to
|
||||
-- @treturn LuaGuiElement the new label element so that styles can be applied
|
||||
function Slider._prototype:draw_label(element)
|
||||
local name = self.name..'-label'
|
||||
if element[name] then return end
|
||||
@@ -151,6 +191,9 @@ function Slider._prototype:draw_label(element)
|
||||
return new_element
|
||||
end
|
||||
|
||||
--- Enables auto draw of the label, the label will share the same parent element as the slider
|
||||
-- @tparam[opt=true] state boolean when false will disable the auto draw of the label
|
||||
-- @treturn self the define to allow chaining
|
||||
function Slider._prototype:enable_auto_draw_label(state)
|
||||
if state == false then
|
||||
self.auto_label = false
|
||||
|
||||
Reference in New Issue
Block a user