mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 04:21:41 +09:00
More spelling fixes
This commit is contained in:
@@ -70,7 +70,7 @@
|
||||
nb: if you do not return reject after you call it then you are still returning nil so there will be a duplicate message
|
||||
|
||||
It should be noted that if you want to expand on an existing parse you can use Commands.parse(type,input,player,reject)
|
||||
and this value will either return a new value for the input or nil, if it is nil you should return nil to prevent dobble
|
||||
and this value will either return a new value for the input or nil, if it is nil you should return nil to prevent double
|
||||
messages to the user:
|
||||
input = Commands.parse('number-int',input,player,reject)
|
||||
if not input then return end -- nil check
|
||||
@@ -159,7 +159,7 @@
|
||||
Commands.print(any,colour[opt]) -- this will return any value value to the user including if it is ran through rcon console
|
||||
Commands.error(message[opt]) -- this returns a warning to the user, aka an error that does not prevent execution of the command
|
||||
return Commands.error(message[opt]) -- this returns an error to the user, and will halt the command execution, ie no success message is returned
|
||||
Commands.success(message[opt]) -- used to return a success message however dont use this method see below
|
||||
Commands.success(message[opt]) -- used to return a success message however don't use this method see below
|
||||
return Commands.success(message[opt]) -- will return the success message to the user and your given message, halts execution
|
||||
return <any> if any value is returned then it will be returned to the player via a Commands.success call
|
||||
|
||||
@@ -390,7 +390,7 @@ end
|
||||
|
||||
--- Intended to be used within other parse functions, runs a parse and returns success and new value
|
||||
-- @tparam string name the name of the parse to call, must be registered and cant be a function
|
||||
-- @tparam string input string the input to pass to the parse, will always be a but might not be the orginal input
|
||||
-- @tparam string input string the input to pass to the parse, will always be a but might not be the original input
|
||||
-- @tparam LuaPlayer player the player that is calling using the command
|
||||
-- @tparam function reject the reject function that was passed by the command hander
|
||||
-- @treturn any the new value for the input, may be nil, if nil then either there was an error or input was nil
|
||||
@@ -497,7 +497,7 @@ function Commands._prototype:add_alias(...)
|
||||
end
|
||||
|
||||
--- Enables auto concatenation of any params on the end so quotes are not needed for last param
|
||||
-- nb: this will disable max param checking as they will be concated onto the end of that last param
|
||||
-- nb: this will disable max param checking as they will be concatenated onto the end of that last param
|
||||
-- this can be useful for reasons or longs text, can only have one per command
|
||||
-- @treturn Commands._prototype pass through to allow more functions to be called
|
||||
function Commands._prototype:enable_auto_concat()
|
||||
@@ -628,7 +628,7 @@ function Commands.run_command(command_event)
|
||||
local no_quotes = w:sub(2,-2)
|
||||
quote_params[no_spaces]=no_quotes
|
||||
if command_data.auto_concat then
|
||||
-- if auto concat then dont remove quotes as it should be included later
|
||||
-- if auto concat then don't remove quotes as it should be included later
|
||||
quote_params[no_spaces]=w
|
||||
end
|
||||
return no_spaces
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
Common.print_grid_value(value, surface, position, scale, offset, immutable) --- Prints a colored value on a location.
|
||||
Common.print_colored_grid_value(value, surface, position, offset, immutable,
|
||||
color_value, base_color, delta_color, under_bound, over_bound) --- Prints a colored value on a location. with extra settings.
|
||||
Common.clear_flying_text(surface) --- Clears all flying text entites on a surface
|
||||
Common.clear_flying_text(surface) --- Clears all flying text entities on a surface
|
||||
|
||||
Common.string_contains(s, contains) --- Tests if a string contains a given substring.
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
Common.table_keys(tbl) --- Returns all the keys of a table
|
||||
Common.table_values(tbl) --- Returns all the values of a table
|
||||
Common.table_alphanumsort(tbl) --- Returns the list is a sorted way that would be expected by people (this is by key)
|
||||
Common.table_keysort(tbl) --- Returns the list is a sorted way that would be expected by people (this is by key) (faster alterative than above)
|
||||
Common.table_keysort(tbl) --- Returns the list is a sorted way that would be expected by people (this is by key) (faster alternative than above)
|
||||
|
||||
Common.format_chat_colour(message,color) --- Returns a message with valid chat tags to change its colour
|
||||
Common.format_chat_colour_localized(message,color) --- Returns a message with valid chat tags to change its colour, using localization
|
||||
@@ -262,7 +262,7 @@ function Common.move_items(items,surface,position,radius,chest_type)
|
||||
local entities = surface.find_entities_filtered{area={{p.x-r,p.y-r},{p.x+r,p.y+r}},name=chest_type} or {}
|
||||
local count = #entities
|
||||
local current = 1
|
||||
-- Makes a new emtpy chest when it is needed
|
||||
-- Makes a new empty chest when it is needed
|
||||
local function make_new_chest()
|
||||
local pos = surface.find_non_colliding_position(chest_type,position,32,1)
|
||||
local chest = surface.create_entity{name=chest_type,position=pos,force='neutral'}
|
||||
@@ -437,7 +437,7 @@ function Common.print_colored_grid_value(value, surface, position, offset, immut
|
||||
}.active = false
|
||||
end
|
||||
|
||||
--- Clears all flying text entites on a surface
|
||||
--- Clears all flying text entities on a surface
|
||||
-- @tparam LuaSurface surface the surface to clear
|
||||
function Common.clear_flying_text(surface)
|
||||
local entities = surface.find_entities_filtered{name ='flying-text'}
|
||||
@@ -598,7 +598,7 @@ function Common.table_alphanumsort(tbl)
|
||||
return _tbl
|
||||
end
|
||||
|
||||
--- Returns the list is a sorted way that would be expected by people (this is by key) (faster alterative than above)
|
||||
--- Returns the list is a sorted way that would be expected by people (this is by key) (faster alternative than above)
|
||||
-- @tparam table tbl the table to be sorted
|
||||
-- @treturn table the sorted table
|
||||
function Common.table_keysort(tbl)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
--- This file is used to require all the different elements of the gui module
|
||||
-- each module has an outline here but for more details see their seperate files in ./gui
|
||||
-- each module has an outline here but for more details see their separate files in ./gui
|
||||
|
||||
local Gui = require 'expcore.gui.core'
|
||||
--[[
|
||||
@@ -13,11 +13,11 @@ local Gui = require 'expcore.gui.core'
|
||||
Gui.categorize_by_surface(element) --- A categorize function to be used with add_store, each surface has its own value
|
||||
|
||||
Gui.toggle_enabled(element) --- Will toggle the enabled state of an element
|
||||
Gui.toggle_visible(element) --- Will toggle the visiblity of an element
|
||||
Gui.toggle_visible(element) --- Will toggle the visibility of an element
|
||||
Gui.set_padding(element,up,down,left,right) --- Sets the padding for a gui element
|
||||
Gui.set_padding_style(style,up,down,left,right) --- Sets the padding for a gui style
|
||||
Gui.create_alignment(element,flow_name) --- Allows the creation of a right align flow to place elements into
|
||||
Gui.destory_if_valid(element) --- Destroies an element but tests for it being present and valid first
|
||||
Gui.destroy_if_valid(element) --- Destroys an element but tests for it being present and valid first
|
||||
Gui.create_scroll_table(element,table_size,maximal_height,name) --- Creates a scroll area with a table inside, table can be any size
|
||||
Gui.create_header(element,caption,tooltip,right_align,name) --- Creates a header section with a label and button area
|
||||
|
||||
@@ -35,7 +35,7 @@ local Gui = require 'expcore.gui.core'
|
||||
Prototype:set_caption(value) --- Sets the caption for the element define
|
||||
Prototype:set_tooltip(value) --- Sets the tooltip for the element define
|
||||
Prototype:set_style(style,callback) --- Sets the style for the element define
|
||||
Prototype:set_embeded_flow(state) --- Sets the element to be drawn inside a nameless flow, can be given a name using a function
|
||||
Prototype:set_embedded_flow(state) --- Sets the element to be drawn inside a nameless flow, can be given a name using a function
|
||||
|
||||
Prototype:set_pre_authenticator --- Sets an authenticator that blocks the draw function if check fails
|
||||
Prototype:set_post_authenticator --- Sets an authenticator that disables the element if check fails
|
||||
@@ -55,7 +55,7 @@ Gui.add_instance = Instances.get_elements
|
||||
Gui.update_instances = Instances.apply_to_elements
|
||||
Gui.classes.instances = Instances
|
||||
--[[
|
||||
Instances.has_categories(name) --- Returns if a instnace group has a categorise function; must be registerd
|
||||
Instances.has_categories(name) --- Returns if a instance group has a categorise function; must be registered
|
||||
Instances.is_registered(name) --- Returns if the given name is a registered instance group
|
||||
Instances.register(name,categorise) --- Registers the name of an instance group to allow for storing element instances
|
||||
|
||||
@@ -77,12 +77,12 @@ Gui.classes.button = Button
|
||||
Button._prototype:on_left_click(player,element) --- Registers a handler for when the button is clicked with the left mouse button
|
||||
Button._prototype:on_right_click(player,element) --- Registers a handler for when the button is clicked with the right mouse button
|
||||
|
||||
Button._prototype:set_sprites(sprite,hovered_sprite,clicked_sprite) --- Adds sprites to a button making it a spirte button
|
||||
Button._prototype:set_sprites(sprite,hovered_sprite,clicked_sprite) --- Adds sprites to a button making it a sprite button
|
||||
Button._prototype:set_click_filter(filter,...) --- Adds a click / mouse button filter to the button
|
||||
Button._prototype:set_key_filter(filter,...) --- Adds a control key filter to the button
|
||||
]]
|
||||
|
||||
local Checkbox = require 'expcore.gui.elements.checkboxs'
|
||||
local Checkbox = require 'expcore.gui.elements.checkbox'
|
||||
Gui.new_checkbox = Checkbox.new_checkbox
|
||||
Gui.new_radiobutton = Checkbox.new_radiobutton
|
||||
Gui.new_radiobutton_option_set = Checkbox.new_option_set
|
||||
@@ -98,10 +98,10 @@ Gui.classes.checkbox = Checkbox
|
||||
Checkbox._prototype_radiobutton:on_store_update(callback) --- Registers a handler for when the stored value updates
|
||||
Checkbox._prototype_radiobutton:add_as_option(option_set,option_name) --- Adds this radiobutton to be an option in the given option set (only one can be true at a time)
|
||||
|
||||
Checkbox.new_option_set(name,callback,categorize) --- Registers a new option set that can be linked to radiobutotns (only one can be true at a time)
|
||||
Checkbox.new_option_set(name,callback,categorize) --- Registers a new option set that can be linked to radiobuttons (only one can be true at a time)
|
||||
Checkbox.draw_option_set(name,element) --- Draws all radiobuttons that are part of an option set at once (Gui.draw will not work)
|
||||
|
||||
Checkbox.reset_radiobutton(element,exclude,recursive) --- Sets all radiobutotn in a element to false (unless excluded) and can act recursivly
|
||||
Checkbox.reset_radiobutton(element,exclude,recursive) --- Sets all radiobuttons in a element to false (unless excluded) and can act recursively
|
||||
]]
|
||||
|
||||
local Dropdown = require 'expcore.gui.elements.dropdown'
|
||||
@@ -176,7 +176,7 @@ Gui.classes.progressbar = ProgressBar
|
||||
--[[
|
||||
ProgressBar.set_maximum(element,amount,count_down) --- Sets the maximum value that represents the end value of the progress bar
|
||||
ProgressBar.increment(element,amount) --- Increases the value of the progressbar, if a define is given all of its instances are incremented
|
||||
ProgressBar.decrement(element,amount) --- Decreases the value of the progressbar, if a define is given all of its instances are decresed
|
||||
ProgressBar.decrement(element,amount) --- Decreases the value of the progressbar, if a define is given all of its instances are decreased
|
||||
|
||||
ProgressBar.new_progressbar(name) --- Creates a new progressbar element define
|
||||
ProgressBar._prototype:set_maximum(amount,count_down) --- Sets the maximum value that represents the end value of the progress bar
|
||||
@@ -188,10 +188,10 @@ Gui.classes.progressbar = ProgressBar
|
||||
ProgressBar._prototype:add_element(element,maximum) --- Adds an element into the list of instances that will are waiting to complete, does not work with store
|
||||
ProgressBar._prototype:reset_element(element) --- Resets an element, or its store, to be back at the start, either 1 or 0
|
||||
|
||||
ProgressBar._prototype:on_complete(callback) --- Triggers when a progress bar element compeltes (hits 0 or 1)
|
||||
ProgressBar._prototype:on_complete(callback) --- Triggers when a progress bar element completes (hits 0 or 1)
|
||||
ProgressBar._prototype:on_complete(callback) --- Triggers when a store value completes (hits 0 or 1)
|
||||
ProgressBar._prototype:event_counter(filter) --- Event handler factory that counts up by 1 every time the event triggeres, can filter which elements are incremented
|
||||
ProgressBar._prototype:event_countdown(filter) --- Event handler factory that counts down by 1 every time the event triggeres, can filter which elements are decremented
|
||||
ProgressBar._prototype:event_counter(filter) --- Event handler factory that counts up by 1 every time the event triggers, can filter which elements are incremented
|
||||
ProgressBar._prototype:event_countdown(filter) --- Event handler factory that counts down by 1 every time the event triggers, can filter which elements are decremented
|
||||
]]
|
||||
|
||||
local Toolbar = require 'expcore.gui.concepts.toolbar'
|
||||
@@ -214,16 +214,16 @@ Gui.classes.left_frames = LeftFrames
|
||||
LeftFrames.get_flow(player) --- Gets the left frame flow for a player
|
||||
LeftFrames.get_frame(name,player) --- Gets one frame from the left flow by its name
|
||||
LeftFrames.get_open(player) --- Gets all open frames for a player, if non are open it will remove the close all button
|
||||
LeftFrames.toggle_frame(name,player,state) --- Toggles the visiblty of a left frame, or sets its visiblty state
|
||||
LeftFrames.toggle_frame(name,player,state) --- Toggles the visibility of a left frame, or sets its visibility state
|
||||
|
||||
LeftFrames.new_frame(permision_name) --- Creates a new left frame define
|
||||
LeftFrames.new_frame(permission_name) --- Creates a new left frame define
|
||||
LeftFrames._prototype:set_open_by_default(state) --- Sets if the frame is visible when a player joins, can also be a function to return a boolean
|
||||
LeftFrames._prototype:set_direction(direction) --- Sets the direction of the frame, either vertical or horizontal
|
||||
LeftFrames._prototype:get_frame(player) --- Gets the frame for this define from the left frame flow
|
||||
LeftFrames._prototype:is_open(player) --- Returns if the player currently has this define visible
|
||||
LeftFrames._prototype:toggle(player) --- Toggles the visiblty of the left frame
|
||||
LeftFrames._prototype:toggle(player) --- Toggles the visibility of the left frame
|
||||
|
||||
LeftFrames._prototype:update(player) --- Updates the contents of the left frame, first tries update callback, oter wise will clear and redraw
|
||||
LeftFrames._prototype:update(player) --- Updates the contents of the left frame, first tries update callback, other wise will clear and redraw
|
||||
LeftFrames._prototype:update_all(update_offline) --- Updates the frame for all players, see update
|
||||
LeftFrames._prototype:redraw(player) --- Redraws the frame by calling on_draw, will always clear the frame
|
||||
LeftFrames._prototype:redraw_all(update_offline) --- Redraws the frame for all players, see redraw
|
||||
@@ -245,10 +245,10 @@ Gui.classes.center_frames = CenterFrames
|
||||
CenterFrames.get_flow(player) --- Gets the center flow for a player
|
||||
CenterFrames.clear_flow(player) --- Clears the center flow for a player
|
||||
CenterFrames.draw_frame(player,name) --- Draws the center frame for a player, if already open then will do nothing
|
||||
CenterFrames.redraw_frame(player,name) --- Draws the center frame for a player, if already open then will destory it and redraw
|
||||
CenterFrames.redraw_frame(player,name) --- Draws the center frame for a player, if already open then will destroy it and redraw
|
||||
CenterFrames.toggle_frame(player,name,state) --- Toggles if the frame is currently open or not, will open if closed and close if open
|
||||
|
||||
CenterFrames.new_frame(permision_name) --- Sets the frame to be the current active gui when opened and closes all other frames
|
||||
CenterFrames.new_frame(permission_name) --- Sets the frame to be the current active gui when opened and closes all other frames
|
||||
CenterFrames._prototype:on_draw(player,frame) --- Use to draw your elements onto the new frame
|
||||
CenterFrames._prototype:set_auto_focus(state) --- Sets the frame to be the current active gui when opened and closes all other frames
|
||||
CenterFrames._prototype:draw_frame(player) --- Draws this frame to the player, if already open does nothing (will call on_draw to draw to the frame)
|
||||
@@ -266,7 +266,7 @@ Gui.classes.popup_frames = PopupFrames
|
||||
PopupFrames.get_flow(player) --- Gets the left flow that contains the popup frames
|
||||
PopupFrames.open(define_name,player,open_time,...) --- Opens a popup for the player, can give the amount of time it is open as well as params for the draw function
|
||||
|
||||
PopupFrames.close_progress --- Progress bar which when depleaded will close the popup frame
|
||||
PopupFrames.close_progress --- Progress bar which when depleted will close the popup frame
|
||||
PopupFrames.close_button --- A button which can be used to close the gui before the timer runs out
|
||||
|
||||
PopupFrames.new_popup(name) --- Creates a new popup frame define
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
CenterFrames.redraw_frame(player,name) --- Draws the center frame for a player, if already open then will destroy it and redraw
|
||||
CenterFrames.toggle_frame(player,name,state) --- Toggles if the frame is currently open or not, will open if closed and close if open
|
||||
|
||||
CenterFrames.new_frame(permision_name) --- Sets the frame to be the current active gui when opened and closes all other frames
|
||||
CenterFrames.new_frame(permission_name) --- Sets the frame to be the current active gui when opened and closes all other frames
|
||||
CenterFrames._prototype:on_draw(player,frame) --- Use to draw your elements onto the new frame
|
||||
CenterFrames._prototype:set_auto_focus(state) --- Sets the frame to be the current active gui when opened and closes all other frames
|
||||
CenterFrames._prototype:draw_frame(player) --- Draws this frame to the player, if already open does nothing (will call on_draw to draw to the frame)
|
||||
@@ -87,10 +87,10 @@ function CenterFrames.toggle_frame(player,name,state)
|
||||
end
|
||||
|
||||
--- Creates a new center frame define
|
||||
-- @tparam string permision_name the name that can be used with the permision system
|
||||
-- @tparam string permission_name the name that can be used with the permission system
|
||||
-- @treturn table the new center frame define
|
||||
function CenterFrames.new_frame(permision_name)
|
||||
local self = Toolbar.new_button(permision_name)
|
||||
function CenterFrames.new_frame(permission_name)
|
||||
local self = Toolbar.new_button(permission_name)
|
||||
|
||||
self:on_click(function(player,element)
|
||||
self:toggle_frame(player)
|
||||
|
||||
@@ -29,16 +29,16 @@
|
||||
LeftFrames.get_flow(player) --- Gets the left frame flow for a player
|
||||
LeftFrames.get_frame(name,player) --- Gets one frame from the left flow by its name
|
||||
LeftFrames.get_open(player) --- Gets all open frames for a player, if non are open it will remove the close all button
|
||||
LeftFrames.toggle_frame(name,player,state) --- Toggles the visiblty of a left frame, or sets its visiblty state
|
||||
LeftFrames.toggle_frame(name,player,state) --- Toggles the visibility of a left frame, or sets its visibility state
|
||||
|
||||
LeftFrames.new_frame(permision_name) --- Creates a new left frame define
|
||||
LeftFrames.new_frame(permission_name) --- Creates a new left frame define
|
||||
LeftFrames._prototype:set_open_by_default(state) --- Sets if the frame is visible when a player joins, can also be a function to return a boolean
|
||||
LeftFrames._prototype:set_direction(direction) --- Sets the direction of the frame, either vertical or horizontal
|
||||
LeftFrames._prototype:get_frame(player) --- Gets the frame for this define from the left frame flow
|
||||
LeftFrames._prototype:is_open(player) --- Returns if the player currently has this define visible
|
||||
LeftFrames._prototype:toggle(player) --- Toggles the visiblty of the left frame
|
||||
LeftFrames._prototype:toggle(player) --- Toggles the visibility of the left frame
|
||||
|
||||
LeftFrames._prototype:update(player) --- Updates the contents of the left frame, first tries update callback, oter wise will clear and redraw
|
||||
LeftFrames._prototype:update(player) --- Updates the contents of the left frame, first tries update callback, other wise will clear and redraw
|
||||
LeftFrames._prototype:update_all(update_offline) --- Updates the frame for all players, see update
|
||||
LeftFrames._prototype:redraw(player) --- Redraws the frame by calling on_draw, will always clear the frame
|
||||
LeftFrames._prototype:redraw_all(update_offline) --- Redraws the frame for all players, see redraw
|
||||
@@ -106,11 +106,11 @@ function LeftFrames.get_open(player)
|
||||
return open
|
||||
end
|
||||
|
||||
--- Toggles the visiblty of a left frame, or sets its visiblty state
|
||||
--- Toggles the visibility of a left frame, or sets its visibility state
|
||||
-- @tparam string name the name of the gui frame to toggle
|
||||
-- @tparam LuaPlayer player the player to get the frame of
|
||||
-- @tparam[opt] boolean state when given will be the state that the visiblty is set to
|
||||
-- @treturn boolean the new state of the visiblity
|
||||
-- @tparam[opt] boolean state when given will be the state that the visibility is set to
|
||||
-- @treturn boolean the new state of the visibility
|
||||
function LeftFrames.toggle_frame(name,player,state)
|
||||
local define = LeftFrames.frames[name]
|
||||
if not define then
|
||||
@@ -130,10 +130,10 @@ function LeftFrames.toggle_frame(name,player,state)
|
||||
end
|
||||
|
||||
--- Creates a new left frame define
|
||||
-- @tparam string permision_name the name that can be used with the permision system
|
||||
-- @tparam string permission_name the name that can be used with the permission system
|
||||
-- @treturn table the new left frame define
|
||||
function LeftFrames.new_frame(permision_name)
|
||||
local self = Toolbar.new_button(permision_name)
|
||||
function LeftFrames.new_frame(permission_name)
|
||||
local self = Toolbar.new_button(permission_name)
|
||||
|
||||
local mt = getmetatable(self)
|
||||
mt.__index = LeftFrames._prototype
|
||||
@@ -151,7 +151,7 @@ function LeftFrames.new_frame(permision_name)
|
||||
end
|
||||
|
||||
--- Sets if the frame is visible when a player joins, can also be a function to return a boolean
|
||||
-- @tparam[opt=true] ?boolean|function state the default state of the visiblty, can be a function
|
||||
-- @tparam[opt=true] ?boolean|function state the default state of the visibility, can be a function
|
||||
-- state param - player LuaPlayer - the player that has joined the game
|
||||
-- state param - define_name string - the define name for the frame
|
||||
-- state return - boolean - false will hide the frame
|
||||
@@ -167,7 +167,7 @@ function LeftFrames._prototype:set_open_by_default(state)
|
||||
end
|
||||
|
||||
--- Sets the direction of the frame, either vertical or horizontal
|
||||
-- @tparam string direction the direction to have the elements be added to thef frame
|
||||
-- @tparam string direction the direction to have the elements be added to the frame
|
||||
function LeftFrames._prototype:set_direction(direction)
|
||||
self.direction = direction
|
||||
return self
|
||||
@@ -221,9 +221,9 @@ function LeftFrames._prototype:is_open(player)
|
||||
return frame and frame.visible or false
|
||||
end
|
||||
|
||||
--- Toggles the visiblty of the left frame
|
||||
--- Toggles the visibility of the left frame
|
||||
-- @tparam LuaPlayer player the player to toggle the frame of
|
||||
-- @treturn boolean the new state of the visiblity
|
||||
-- @treturn boolean the new state of the visibility
|
||||
function LeftFrames._prototype:toggle(player)
|
||||
local frame = self:get_frame(player)
|
||||
Gui.toggle_visible(frame)
|
||||
@@ -231,7 +231,7 @@ function LeftFrames._prototype:toggle(player)
|
||||
return frame.visible
|
||||
end
|
||||
|
||||
--- Updates the contents of the left frame, first tries update callback, oter wise will clear and redraw
|
||||
--- Updates the contents of the left frame, first tries update callback, other wise will clear and redraw
|
||||
-- @tparam LuaPlayer player the player to update the frame of
|
||||
function LeftFrames._prototype:update(player)
|
||||
local frame = self:get_frame(player)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
PopupFrames.get_flow(player) --- Gets the left flow that contains the popup frames
|
||||
PopupFrames.open(define_name,player,open_time,...) --- Opens a popup for the player, can give the amount of time it is open as well as params for the draw function
|
||||
|
||||
PopupFrames.close_progress --- Progress bar which when depleaded will close the popup frame
|
||||
PopupFrames.close_progress --- Progress bar which when depleted will close the popup frame
|
||||
PopupFrames.close_button --- A button which can be used to close the gui before the timer runs out
|
||||
|
||||
PopupFrames.new_popup(name) --- Creates a new popup frame define
|
||||
@@ -34,17 +34,17 @@ Global.register(PopupFrames.paused_popups,function(tbl)
|
||||
PopupFrames.paused_popups = tbl
|
||||
end)
|
||||
|
||||
--- Sets the state of the element in the pasued list, nil or true
|
||||
--- Sets the state of the element in the paused list, nil or true
|
||||
-- @tparam LuaGuiElement element the element to set the state of
|
||||
-- @tparam[opt] boolean state the state to set it to, true will pause the the progress bar
|
||||
local function set_pasued_state(element,state)
|
||||
local function set_paused_state(element,state)
|
||||
local name = element.player_index..':'..element.index
|
||||
PopupFrames.paused_popups[name] = state
|
||||
end
|
||||
|
||||
--- Gets the state of the element in the pasued list, nil or true
|
||||
--- Gets the state of the element in the paused list, nil or true
|
||||
-- @tparam LuaGuiElement element the element to get the state of
|
||||
local function get_pasued_state(element)
|
||||
local function get_paused_state(element)
|
||||
local name = element.player_index..':'..element.index
|
||||
return PopupFrames.paused_popups[name]
|
||||
end
|
||||
@@ -75,11 +75,11 @@ end
|
||||
local function close_popup(element)
|
||||
local frame = element.parent.parent.parent
|
||||
if not frame or not frame.valid then return end
|
||||
set_pasued_state(element.parent[PopupFrames.close_progress:uid()])
|
||||
set_paused_state(element.parent[PopupFrames.close_progress:uid()])
|
||||
frame.destroy()
|
||||
end
|
||||
|
||||
--- Progress bar which when depleaded will close the popup frame
|
||||
--- Progress bar which when depleted will close the popup frame
|
||||
PopupFrames.close_progress =
|
||||
ProgressBar.new_progressbar()
|
||||
:use_count_down()
|
||||
@@ -100,20 +100,20 @@ end)
|
||||
--- When the progress bar is clicked it will pause its progress, or resume if previously paused
|
||||
Gui.on_click(PopupFrames.close_progress:uid(),function(event)
|
||||
local element = event.element
|
||||
if get_pasued_state(element) then
|
||||
set_pasued_state(element)
|
||||
if get_paused_state(element) then
|
||||
set_paused_state(element)
|
||||
else
|
||||
set_pasued_state(element,true)
|
||||
set_paused_state(element,true)
|
||||
end
|
||||
end)
|
||||
|
||||
--- When the parent flow of the progress bar is clicked it will pause its progress, or resume if previously paused
|
||||
Gui.on_click(PopupFrames.close_frame_name,function(event)
|
||||
local element = event.element[PopupFrames.close_progress:uid()]
|
||||
if get_pasued_state(element) then
|
||||
set_pasued_state(element)
|
||||
if get_paused_state(element) then
|
||||
set_paused_state(element)
|
||||
else
|
||||
set_pasued_state(element,true)
|
||||
set_paused_state(element,true)
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -214,9 +214,9 @@ Event.add(defines.events.on_player_created,function(event)
|
||||
}
|
||||
end)
|
||||
|
||||
--- Every tick any, not pasued, progress bars will go down by one tick
|
||||
--- Every tick any, not paused, progress bars will go down by one tick
|
||||
Event.add(defines.events.on_tick,PopupFrames.close_progress:event_countdown(function(element)
|
||||
return not get_pasued_state(element)
|
||||
return not get_paused_state(element)
|
||||
end))
|
||||
|
||||
return PopupFrames
|
||||
@@ -22,17 +22,17 @@ local Game = require 'utils.game'
|
||||
local mod_gui = require 'mod-gui'
|
||||
|
||||
local Toolbar = {
|
||||
permisison_names = {},
|
||||
permission_names = {},
|
||||
buttons = {}
|
||||
}
|
||||
|
||||
function Toolbar.allowed(player,define_name)
|
||||
local permisison_name = Toolbar.permisison_names[define_name] or define_name
|
||||
return Roles.player_allowed(player,permisison_name)
|
||||
local permission_name = Toolbar.permission_names[define_name] or define_name
|
||||
return Roles.player_allowed(player,permission_name)
|
||||
end
|
||||
|
||||
function Toolbar.permission_alias(define_name,permisison_name)
|
||||
Toolbar.permisison_names[define_name] = permisison_name
|
||||
function Toolbar.permission_alias(define_name,permission_name)
|
||||
Toolbar.permission_names[define_name] = permission_name
|
||||
end
|
||||
|
||||
--- Adds a new button to the toolbar
|
||||
|
||||
@@ -125,7 +125,7 @@
|
||||
Gui.set_padding(element,up,down,left,right) --- Sets the padding for a gui element
|
||||
Gui.set_padding_style(style,up,down,left,right) --- Sets the padding for a gui style
|
||||
Gui.create_alignment(element,flow_name) --- Allows the creation of a right align flow to place elements into
|
||||
Gui.destory_if_valid(element) --- Destroies an element but tests for it being present and valid first
|
||||
Gui.destroy_if_valid(element) --- Destroies an element but tests for it being present and valid first
|
||||
Gui.create_scroll_table(element,table_size,maximal_height,name) --- Creates a scroll area with a table inside, table can be any size
|
||||
Gui.create_header(element,caption,tooltip,right_align,name) --- Creates a header section with a label and button area
|
||||
]]
|
||||
@@ -288,7 +288,7 @@ end
|
||||
--- Destroies an element but tests for it being present and valid first
|
||||
-- @tparam LuaGuiElement element the element to be destroied
|
||||
-- @treturn boolean true if it was destoried
|
||||
function Gui.destory_if_valid(element)
|
||||
function Gui.destroy_if_valid(element)
|
||||
if element and element.valid then
|
||||
element.destroy()
|
||||
return true
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
Button._prototype:on_left_click(player,element) --- Registers a handler for when the button is clicked with the left mouse button
|
||||
Button._prototype:on_right_click(player,element) --- Registers a handler for when the button is clicked with the right mouse button
|
||||
|
||||
Button._prototype:set_sprites(sprite,hovered_sprite,clicked_sprite) --- Adds sprites to a button making it a spirte button
|
||||
Button._prototype:set_sprites(sprite,hovered_sprite,clicked_sprite) --- Adds sprites to a button making it a sprite button
|
||||
Button._prototype:set_click_filter(filter,...) --- Adds a click / mouse button filter to the button
|
||||
Button._prototype:set_key_filter(filter,...) --- Adds a control key filter to the button
|
||||
|
||||
@@ -66,7 +66,7 @@ function Button.new_button(name)
|
||||
return self
|
||||
end
|
||||
|
||||
--- Adds sprites to a button making it a spirte button
|
||||
--- Adds sprites to a button making it a sprite button
|
||||
-- @tparam SpritePath sprite the sprite path for the default sprite for the button
|
||||
-- @tparam[opt] SpritePath hovered_sprite the sprite path for the sprite when the player hovers over the button
|
||||
-- @tparam[opt] SpritePath clicked_sprite the sprite path for the sprite when the player clicks the button
|
||||
@@ -103,7 +103,7 @@ end
|
||||
|
||||
--- Adds a control key filter to the button
|
||||
-- @tparam table filter ?string|table either a of control keys or the first control keys to filter, with a table true means allowed
|
||||
-- @tparam[opt] table ... when filter is not a you can add the control keyss one after each other
|
||||
-- @tparam[opt] table ... when filter is not a you can add the control keys one after each other
|
||||
-- @treturn self returns the button define to allow chaining
|
||||
function Button._prototype:set_key_filter(filter,...)
|
||||
if type(filter) == 'string' then
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
--- Gui class define for checkboxs and radiobuttons
|
||||
--- Gui class define for checkbox and radiobuttons
|
||||
--[[
|
||||
>>>> Using an option set
|
||||
An option set is a set of radio buttons where only one of them can be active at a time, this means that when one
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
Note that these radiobuttons can still have on_element_update events but this may result in a double trigger of events as
|
||||
the option set update is always triggered; also add_store cant be used as the option set acts as the store however get
|
||||
and set store will still work but will effect the option set rather than the indivual radiobuttons.
|
||||
and set store will still work but will effect the option set rather than the individual radiobuttons.
|
||||
|
||||
>>>> Functions
|
||||
Checkbox.new_checkbox(name) --- Creates a new checkbox element define
|
||||
@@ -38,10 +38,10 @@
|
||||
Checkbox._prototype_radiobutton:on_store_update(callback) --- Registers a handler for when the stored value updates
|
||||
Checkbox._prototype_radiobutton:add_as_option(option_set,option_name) --- Adds this radiobutton to be an option in the given option set (only one can be true at a time)
|
||||
|
||||
Checkbox.new_option_set(name,callback,categorize) --- Registers a new option set that can be linked to radiobutotns (only one can be true at a time)
|
||||
Checkbox.new_option_set(name,callback,categorize) --- Registers a new option set that can be linked to radiobutton (only one can be true at a time)
|
||||
Checkbox.draw_option_set(name,element) --- Draws all radiobuttons that are part of an option set at once (Gui.draw will not work)
|
||||
|
||||
Checkbox.reset_radiobutton(element,exclude,recursive) --- Sets all radiobutotn in a element to false (unless excluded) and can act recursivly
|
||||
Checkbox.reset_radiobutton(element,exclude,recursive) --- Sets all radiobutton in a element to false (unless excluded) and can act recursively
|
||||
|
||||
Other functions present from expcore.gui.core
|
||||
]]
|
||||
@@ -131,7 +131,7 @@ end
|
||||
|
||||
--- Adds this radiobutton to be an option in the given option set (only one can be true at a time)
|
||||
-- @tparam string option_set the name of the option set to add this element to
|
||||
-- @tparam string option_name the name of this option that will be used to idenitife it
|
||||
-- @tparam string option_name the name of this option that will be used to identify it
|
||||
-- @treturn self the define to allow chaining
|
||||
function Checkbox._prototype_radiobutton:add_as_option(option_set,option_name)
|
||||
self.option_set = option_set
|
||||
@@ -166,9 +166,9 @@ function Checkbox._prototype_radiobutton:set_store(category,value,internal)
|
||||
return Store.set(location,category,value)
|
||||
end
|
||||
|
||||
--- Registers a new option set that can be linked to radiobutotns (only one can be true at a time)
|
||||
--- Registers a new option set that can be linked to radiobuttons (only one can be true at a time)
|
||||
-- @tparam string name the name of the option set, must be unique
|
||||
-- @tparam function callback the update callback when the value of the option set chagnes
|
||||
-- @tparam function callback the update callback when the value of the option set changes
|
||||
-- callback param - value string - the new selected option for this option set
|
||||
-- callback param - category string - the category that updated if categorize was used
|
||||
-- @tparam function categorize the function used to convert an element into a string
|
||||
@@ -208,7 +208,7 @@ function Checkbox.draw_option_set(name,element)
|
||||
|
||||
end
|
||||
|
||||
--- Sets all radiobutotn in a element to false (unless excluded) and can act recursivly
|
||||
--- Sets all radiobutton in a element to false (unless excluded) and can act recursively
|
||||
-- @tparam LuaGuiElement element the root gui element to start setting radio buttons from
|
||||
-- @tparam[opt] table exclude ?string|table the name of the radiobutton to exclude or a of radiobuttons where true will set the state true
|
||||
-- @tparam[opt=false] ?number|boolean recursive if true will recur as much as possible, if a will recur that number of times
|
||||
@@ -1,4 +1,4 @@
|
||||
--- Gui class define for dropdowns and list boxs
|
||||
--- Gui class define for dropdowns and list box
|
||||
--[[
|
||||
>>>> Functions
|
||||
Dropdown.new_dropdown(name) --- Creates a new dropdown element define
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
--- Gui element define for progess bars
|
||||
--- Gui element define for progress bars
|
||||
--[[
|
||||
>>>> Functions
|
||||
ProgressBar.set_maximum(element,amount,count_down) --- Sets the maximum value that represents the end value of the progress bar
|
||||
ProgressBar.increment(element,amount) --- Increases the value of the progressbar, if a define is given all of its instances are incremented
|
||||
ProgressBar.decrement(element,amount) --- Decreases the value of the progressbar, if a define is given all of its instances are decresed
|
||||
ProgressBar.increment(element,amount) --- Increases the value of the progressbar, if a define is given all of its instances have incremented
|
||||
ProgressBar.decrement(element,amount) --- Decreases the value of the progressbar, if a define is given all of its instances have decremented
|
||||
|
||||
ProgressBar.new_progressbar(name) --- Creates a new progressbar element define
|
||||
ProgressBar._prototype:set_maximum(amount,count_down) --- Sets the maximum value that represents the end value of the progress bar
|
||||
@@ -15,10 +15,10 @@
|
||||
ProgressBar._prototype:add_element(element,maximum) --- Adds an element into the list of instances that will are waiting to complete, does not work with store
|
||||
ProgressBar._prototype:reset_element(element) --- Resets an element, or its store, to be back at the start, either 1 or 0
|
||||
|
||||
ProgressBar._prototype:on_complete(callback) --- Triggers when a progress bar element compeltes (hits 0 or 1)
|
||||
ProgressBar._prototype:on_complete(callback) --- Triggers when a progress bar element completes (hits 0 or 1)
|
||||
ProgressBar._prototype:on_complete(callback) --- Triggers when a store value completes (hits 0 or 1)
|
||||
ProgressBar._prototype:event_counter(filter) --- Event handler factory that counts up by 1 every time the event triggeres, can filter which elements are incremented
|
||||
ProgressBar._prototype:event_countdown(filter) --- Event handler factory that counts down by 1 every time the event triggeres, can filter which elements are decremented
|
||||
ProgressBar._prototype:event_counter(filter) --- Event handler factory that counts up by 1 every time the event triggers, can filter which elements have incremented
|
||||
ProgressBar._prototype:event_countdown(filter) --- Event handler factory that counts down by 1 every time the event triggers, can filter which elements have decremented
|
||||
]]
|
||||
local Gui = require 'expcore.gui.core'
|
||||
local Prototype = require 'expcore.gui.prototype'
|
||||
@@ -52,7 +52,7 @@ end
|
||||
|
||||
local ProgressBar = {
|
||||
unregistered={}, -- elements with no callbacks
|
||||
independent={}, -- elements with a link to a deinfe
|
||||
independent={}, -- elements with a link to a define
|
||||
_prototype=Prototype.extend{
|
||||
on_complete = Prototype.event,
|
||||
on_store_complete = Prototype.event,
|
||||
@@ -84,7 +84,7 @@ end
|
||||
|
||||
--- Gets the element data, used when there is no define
|
||||
-- @tparam LuaGuiElement element the element to get the data of
|
||||
-- @treturn table the element data simialr to define
|
||||
-- @treturn table the element data similar to define
|
||||
local function get_element(element)
|
||||
if not element.valid then return end
|
||||
local name = element.player_index..':'..element.index
|
||||
@@ -102,7 +102,7 @@ function ProgressBar.set_maximum(element,amount)
|
||||
|
||||
local define = get_define(element)
|
||||
if define then
|
||||
define:set_deafult_maximum(amount)
|
||||
define:set_default_maximum(amount)
|
||||
|
||||
else
|
||||
local element_data = get_element(element)
|
||||
@@ -122,7 +122,7 @@ function ProgressBar.set_maximum(element,amount)
|
||||
end
|
||||
end
|
||||
|
||||
--- Increases the value of the progressbar, if a define is given all of its instances are incremented
|
||||
--- Increases the value of the progressbar, if a define is given all of its instances have incremented
|
||||
-- @tparam ?LuaGuiElement|string element either a gui element or a registered define
|
||||
-- @tparam[opt=1] number amount the amount to increase the progressbar by
|
||||
function ProgressBar.increment(element,amount)
|
||||
@@ -149,7 +149,7 @@ function ProgressBar.increment(element,amount)
|
||||
end
|
||||
end
|
||||
|
||||
--- Decreases the value of the progressbar, if a define is given all of its instances are decresed
|
||||
--- Decreases the value of the progressbar, if a define is given all of its instances have decremented
|
||||
-- @tparam ?LuaGuiElement|string element either a gui element or a registered define
|
||||
-- @tparam[opt=1] number amount the amount to decrease the progressbar by
|
||||
function ProgressBar.decrement(element,amount)
|
||||
@@ -178,7 +178,7 @@ end
|
||||
|
||||
--- Creates a new progressbar element define
|
||||
-- @tparam[opt] string name the optional debug name that can be added
|
||||
-- @treturn table the new progressbar elemente define
|
||||
-- @treturn table the new progressbar element define
|
||||
function ProgressBar.new_progressbar(name)
|
||||
|
||||
local self = Gui.new_define(ProgressBar._prototype,name)
|
||||
@@ -349,8 +349,8 @@ function ProgressBar._prototype:reset_element(element)
|
||||
end
|
||||
end
|
||||
|
||||
--- Event handler factory that counts up by 1 every time the event triggeres, can filter which elements are incremented
|
||||
-- @tparam[opt] function filter when given will use filtered incerement
|
||||
--- Event handler factory that counts up by 1 every time the event triggers, can filter which elements have incremented
|
||||
-- @tparam[opt] function filter when given will use filtered increment
|
||||
-- @treturn function the event handler
|
||||
function ProgressBar._prototype:event_counter(filter)
|
||||
if type(filter) == 'function' then
|
||||
@@ -364,8 +364,8 @@ function ProgressBar._prototype:event_counter(filter)
|
||||
end
|
||||
end
|
||||
|
||||
--- Event handler factory that counts down by 1 every time the event triggeres, can filter which elements are decremented
|
||||
-- @tparam[opt] function filter when given will use filtered decerement
|
||||
--- Event handler factory that counts down by 1 every time the event triggers, can filter which elements have decremented
|
||||
-- @tparam[opt] function filter when given will use filtered decrement
|
||||
-- @treturn function the event handler
|
||||
function ProgressBar._prototype:event_countdown(filter)
|
||||
if type(filter) == 'function' then
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
--- Gui class define for silders
|
||||
--- Gui class define for sliders
|
||||
--[[
|
||||
>>>> Functions
|
||||
Slider.new_slider(name) --- Creates a new slider element define
|
||||
@@ -128,7 +128,7 @@ function Slider._prototype:set_range(min,max)
|
||||
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 LuaGuiElement element the parent element that the lable will be drawn to
|
||||
-- @tparam LuaGuiElement element the parent element that the label 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'
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
--- Gui class define for text fields and text boxs
|
||||
--- Gui class define for text fields and text boxes
|
||||
--[[
|
||||
>>>> Functions
|
||||
Text.new_text_field(name) --- Creates a new text field element define
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
--- This file is a breakout from core which forcues on instance management of defines
|
||||
--[[
|
||||
>>>> Using registered instance groups
|
||||
The main use of this module is to register a group of elements refered here as "instances of an element define" in which
|
||||
The main use of this module is to register a group of elements referred here as "instances of an element define" in which
|
||||
is meant that you define the name of a group of drawn elements that are really just multiple versions of a single element.
|
||||
For example this might be that you have one label in multiple places (either for one player or many) and you want to update
|
||||
the caption of all of them at once; this is where this module comes it.
|
||||
|
||||
First you must register the way that the intances are stored and under what name, using Instances.register you will give the
|
||||
name of the collective group of instances followed by an optional categorise function which allows varients to be stored under one
|
||||
First you must register the way that the instances are stored and under what name, using Instances.register you will give the
|
||||
name of the collective group of instances followed by an optional categorise function which allows variants to be stored under one
|
||||
name (like one for each force or player)
|
||||
|
||||
-- categorise works in the same way as store categorise
|
||||
-- so the function will worl here but no value is stored only gui elements
|
||||
-- so the function will world here but no value is stored only gui elements
|
||||
Instances.register('score',Gui.categorize_by_force)
|
||||
|
||||
Then when you draw the new element to a gui you will want to add the element to the group:
|
||||
@@ -26,13 +26,13 @@
|
||||
element.caption = 0
|
||||
end)
|
||||
|
||||
Note that if you dont give a categorise function then you dont need to give a category when getting the elements.
|
||||
Note that if you don't give a categorise function then you don't need to give a category when getting the elements.
|
||||
|
||||
>>>> Using unregistered instance groups
|
||||
When using a registered group and the functions that go with them it is much simpler to use and more importantly includes error checking
|
||||
for valid instance group names; the down side is that the group must be registered which can only be done during startup and not during runtime.
|
||||
To counter this there are two functions simlair to those above in order to add and get instances but may lead to errors not being noticed due to
|
||||
the error interal error checking being skiped to allow it to work.
|
||||
for valid instance group names; the down side is that the group must be registered which can only be done during start-up and not during runtime.
|
||||
To counter this there are two functions similar to those above in order to add and get instances but may lead to errors not being noticed due to
|
||||
the error internal error checking being skipped to allow it to work.
|
||||
|
||||
The main difference between the two groups of functions is that the category must always be present even if is nil; example below shows how a
|
||||
instance group would work when registered vs unregistered:
|
||||
@@ -50,7 +50,7 @@
|
||||
element.caption = '0'
|
||||
end) -- gets all instances from the player force and sets the caption to 0
|
||||
|
||||
-- Registered without category; note that category can just be igroned
|
||||
-- Registered without category; note that category can just be ignored
|
||||
Instances.register('score') -- all instances will be under one group with no categories
|
||||
Instances.add_element('score',new_element) -- adds the new element to the instance list
|
||||
Instances.apply_to_elements('score',function(element)
|
||||
@@ -64,7 +64,7 @@
|
||||
end) -- gets all instances and sets the element caption to 0
|
||||
|
||||
>>>> Functions
|
||||
Instances.has_categories(name) --- Returns if a instnace group has a categorise function; must be registerd
|
||||
Instances.has_categories(name) --- Returns if a instance group has a categorise function; must be registered
|
||||
Instances.is_registered(name) --- Returns if the given name is a registered instance group
|
||||
Instances.register(name,categorise) --- Registers the name of an instance group to allow for storing element instances
|
||||
|
||||
@@ -85,7 +85,7 @@ Global.register(Instances.data,function(tbl)
|
||||
Instances.data = tbl
|
||||
end)
|
||||
|
||||
--- Returns if a instnace group has a categorise function; must be registerd
|
||||
--- Returns if a instance group has a categorise function; must be registered
|
||||
-- @tparam string name the name of the instance group
|
||||
-- @treturn boolean true if there is a categorise function
|
||||
function Instances.has_categories(name)
|
||||
@@ -104,7 +104,7 @@ end
|
||||
-- @tparam[opt] function categorise function used to turn the element into a string
|
||||
-- categorise param - element LuaGuiElement - the gui element to be turned into a string
|
||||
-- categorise return - string - the category that the element will be added to like the player's name or force's name
|
||||
-- @treturn string the name that was added so it can be used as a varible
|
||||
-- @treturn string the name that was added so it can be used as a variable
|
||||
function Instances.register(name,categorise)
|
||||
if _LIFECYCLE ~= _STAGE.control then
|
||||
return error('Can only be called during the control stage', 2)
|
||||
@@ -127,7 +127,7 @@ end
|
||||
-- @tparam LuaGuiElement element the element to add the the instance group
|
||||
function Instances.add_element(name,element)
|
||||
if not Instances.categorise[name] then
|
||||
return error('Inavlid name for instance group: '..name,2)
|
||||
return error('Invalid name for instance group: '..name,2)
|
||||
end
|
||||
|
||||
if Instances.has_categories(name) then
|
||||
@@ -145,7 +145,7 @@ end
|
||||
-- @treturn table the table of element instances of which some may be invalid
|
||||
function Instances.get_elements_raw(name,category)
|
||||
if not Instances.categorise[name] then
|
||||
return error('Inavlid name for instance group: '..name,2)
|
||||
return error('Invalid name for instance group: '..name,2)
|
||||
end
|
||||
|
||||
if Instances.has_categories(name) then
|
||||
@@ -158,12 +158,12 @@ end
|
||||
--- Gets all valid element instances and has the option of running a callback on those that are valid
|
||||
-- @tparam string name the name of the instance group to get the instances of
|
||||
-- @tparam[opt] string category the category to get the instances of, not needed when no categorise function
|
||||
-- @tparan[opt] callback function when given the callback will be ran on all valid elements
|
||||
-- @tparam[opt] callback function when given the callback will be ran on all valid elements
|
||||
-- callback param - element LuaGuiElement - the current valid element
|
||||
-- @treturn table the table of element instances with all invalid ones removed
|
||||
function Instances.get_valid_elements(name,category,callback)
|
||||
if not Instances.categorise[name] then
|
||||
return error('Inavlid name for instance group: '..name,2)
|
||||
return error('Invalid name for instance group: '..name,2)
|
||||
end
|
||||
|
||||
category = category or callback
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
Prototype:set_caption(value) --- Sets the caption for the element define
|
||||
Prototype:set_tooltip(value) --- Sets the tooltip for the element define
|
||||
Prototype:set_style(style,callback) --- Sets the style for the element define
|
||||
Prototype:set_embeded_flow(state) --- Sets the element to be drawn inside a nameless flow, can be given a name using a function
|
||||
Prototype:set_embedded_flow(state) --- Sets the element to be drawn inside a nameless flow, can be given a name using a function
|
||||
|
||||
Prototype:set_pre_authenticator --- Sets an authenticator that blocks the draw function if check fails
|
||||
Prototype:set_post_authenticator --- Sets an authenticator that disables the element if check fails
|
||||
@@ -80,10 +80,10 @@ end
|
||||
function Constructor.store(sync,callback)
|
||||
--- Adds a store for the define that is shared between all instances of the define in the same category, categorize is a function that returns a string
|
||||
-- @tparam self table the gui define being acted on
|
||||
-- @tparam[opt] string location a unique location identifier, when omited a uid location will be used, use when sync is set to true
|
||||
-- @tparam[opt] function categorize function used to determine the category of a LuaGuiElement, when omited all share one single category
|
||||
-- @tparam[opt] string location a unique location identifier, when omitted a uid location will be used, use when sync is set to true
|
||||
-- @tparam[opt] function categorize function used to determine the category of a LuaGuiElement, when omitted all share one single category
|
||||
-- categorize param - LuaGuiElement element - the element that needs to be converted
|
||||
-- categorize return - string - a determistic string that referses to a category such as player name or force name
|
||||
-- categorize return - string - a deterministic string that references to a category such as player name or force name
|
||||
-- @treturn self the element define to allow chaining
|
||||
return function(self,location,categorize)
|
||||
if self.store then return end
|
||||
@@ -134,8 +134,8 @@ function Constructor.setter(value_type,key,second_key)
|
||||
end
|
||||
|
||||
return function(self,value)
|
||||
local vtype = type(value)
|
||||
if vtype ~= value_type and (not locale or vtype ~= 'string') then
|
||||
local v_type = type(value)
|
||||
if v_type ~= value_type and (not locale or v_type ~= 'string') then
|
||||
error(display_message,2)
|
||||
end
|
||||
|
||||
@@ -213,11 +213,11 @@ end
|
||||
--- Sets the element to be drawn inside a nameless flow, can be given a name using a function
|
||||
-- @tparam state ?boolean|function when true a padless flow is created to contain the element
|
||||
-- @treturn self the element define to allow chaining
|
||||
function Prototype:set_embeded_flow(state)
|
||||
function Prototype:set_embedded_flow(state)
|
||||
if state == false or type(state) == 'function' then
|
||||
self.embeded_flow = state
|
||||
self.embedded_flow = state
|
||||
else
|
||||
self.embeded_flow = true
|
||||
self.embedded_flow = true
|
||||
end
|
||||
return self
|
||||
end
|
||||
@@ -249,12 +249,12 @@ function Prototype:draw_to(element,...)
|
||||
if not self.pre_authenticator(player,self.name) then return end
|
||||
end
|
||||
|
||||
if self.embeded_flow then
|
||||
local embeded_name
|
||||
if type(self.embeded_flow) == 'function' then
|
||||
embeded_name = self.embeded_flow(element,...)
|
||||
if self.embedded_flow then
|
||||
local embedded_name
|
||||
if type(self.embedded_flow) == 'function' then
|
||||
embedded_name = self.embedded_flow(element,...)
|
||||
end
|
||||
element = element.add{type='flow',name=embeded_name}
|
||||
element = element.add{type='flow',name=embedded_name}
|
||||
element.style.padding = 0
|
||||
end
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
--- This file creates a teste gui that is used to test every input method
|
||||
-- note that this does not cover every permutation only features in indepentance
|
||||
--- This file creates a test gui that is used to test every input method
|
||||
-- note that this does not cover every permutation only features in independence
|
||||
-- for example store in most cases is just by player name, but other store methods are tested with checkbox
|
||||
local Gui = require 'expcore.gui'
|
||||
local format_chat_colour,table_keys = ext_require('expcore.common','format_chat_colour','table_keys')
|
||||
@@ -223,7 +223,7 @@ end)
|
||||
|
||||
local checkbox_force =
|
||||
Gui.new_checkbox('test-checkbox-store-force')
|
||||
:set_tooltip('Checkboc store force')
|
||||
:set_tooltip('Checkbox store force')
|
||||
:set_caption('Checkbox Store Force')
|
||||
:add_store(Gui.categorize_by_force)
|
||||
:on_element_update(function(player,element,state)
|
||||
@@ -239,7 +239,7 @@ Gui.new_checkbox('test-checkbox-store-player')
|
||||
player.print('Checkbox store player: '..tostring(state))
|
||||
end)
|
||||
|
||||
tests.Checkboxs = {
|
||||
tests.Checkboxes = {
|
||||
['Local']=checkbox_local,
|
||||
['Game store']=checkbox_game,
|
||||
['Force store']=checkbox_force,
|
||||
@@ -425,7 +425,7 @@ Gui.new_list_box('test-list-box-store')
|
||||
player.print('Dropdown store: '..tostring(value))
|
||||
end)
|
||||
|
||||
tests["List Boxs"] = {
|
||||
tests["List Boxes"] = {
|
||||
['Local']=list_box_local,
|
||||
['Player']=list_box_player
|
||||
}
|
||||
@@ -442,7 +442,7 @@ tests["List Boxs"] = {
|
||||
|
||||
local slider_local_default =
|
||||
Gui.new_slider('test-slider-local-default')
|
||||
:set_tooltip('Silder local default')
|
||||
:set_tooltip('Slider local default')
|
||||
:on_element_update(function(player,element,value,percent)
|
||||
player.print('Slider local default: '..tostring(math.round(value))..' '..tostring(math.round(percent,1)))
|
||||
end)
|
||||
@@ -450,7 +450,7 @@ end)
|
||||
|
||||
local slider_player_default =
|
||||
Gui.new_slider('test-slider-store-default')
|
||||
:set_tooltip('Silder store default')
|
||||
:set_tooltip('Slider store default')
|
||||
:add_store(Gui.categorize_by_player)
|
||||
:on_element_update(function(player,element,value,percent)
|
||||
player.print('Slider store default: '..tostring(math.round(value))..' '..tostring(math.round(percent,1)))
|
||||
@@ -458,7 +458,7 @@ end)
|
||||
|
||||
local slider_static =
|
||||
Gui.new_slider('test-slider-static-range')
|
||||
:set_tooltip('Silder static range')
|
||||
:set_tooltip('Slider static range')
|
||||
:set_range(5,50)
|
||||
:on_element_update(function(player,element,value,percent)
|
||||
player.print('Slider static range: '..tostring(math.round(value))..' '..tostring(math.round(percent,1)))
|
||||
@@ -466,7 +466,7 @@ end)
|
||||
|
||||
local slider_dynamic =
|
||||
Gui.new_slider('test-slider-dynamic-range')
|
||||
:set_tooltip('Silder dynamic range')
|
||||
:set_tooltip('Slider dynamic range')
|
||||
:set_range(function(player,element)
|
||||
return player.index - 5
|
||||
end,function(player,element)
|
||||
@@ -478,7 +478,7 @@ end)
|
||||
|
||||
local label_slider_local =
|
||||
Gui.new_slider('test-slider-local-label')
|
||||
:set_tooltip('Silder local label')
|
||||
:set_tooltip('Slider local label')
|
||||
:enable_auto_draw_label()
|
||||
:on_element_update(function(player,element,value,percent)
|
||||
player.print('Slider local label: '..tostring(math.round(value))..' '..tostring(math.round(percent,1)))
|
||||
@@ -486,7 +486,7 @@ end)
|
||||
|
||||
local label_slider_player =
|
||||
Gui.new_slider('test-slider-store-label')
|
||||
:set_tooltip('Silder store label')
|
||||
:set_tooltip('Slider store label')
|
||||
:enable_auto_draw_label()
|
||||
:add_store(Gui.categorize_by_player)
|
||||
:on_element_update(function(player,element,value,percent)
|
||||
@@ -610,7 +610,7 @@ tests["Elem Buttons"] = {
|
||||
Progress bar tests
|
||||
> Simple -- Progress bar that fills every 2 seconds
|
||||
> Store -- Progress bar that fills every 5 seconds with synced value
|
||||
> Reverce -- Progress bar that decreases every 2 seconds
|
||||
> Reverse -- Progress bar that decreases every 2 seconds
|
||||
]]
|
||||
|
||||
local progressbar_one =
|
||||
@@ -651,5 +651,5 @@ end)
|
||||
tests["Progress Bars"] = {
|
||||
['Simple']=progressbar_one,
|
||||
['Store']=progressbar_two,
|
||||
['Reverce']=progressbar_three
|
||||
['Reverse']=progressbar_three
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
-- here we will create an admin group however we do not want them to use the map editor or mess with the permission groups
|
||||
Permission_Groups.new_group('Admin') -- this defines a new group called "Admin"
|
||||
:allow_all() -- this makes the default to allow any input action unless set other wise
|
||||
:disallow{ -- here we disallow the input action we dont want them to use
|
||||
:disallow{ -- here we disallow the input action we don't want them to use
|
||||
'add_permission_group',
|
||||
'delete_permission_group',
|
||||
'import_permissions_string',
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
...extras...
|
||||
:set_allow_all()
|
||||
|
||||
If you dont do this want this as i would advise you do then you will want to define what the role can do; this comes with
|
||||
If you don't do this want this as i would advise you do then you will want to define what the role can do; this comes with
|
||||
an optional inheritance system if you like those sort of things in which case disallow may also be of some use to you:
|
||||
Roles.new_role('Administrator','Admin')
|
||||
...extras...
|
||||
@@ -88,7 +88,7 @@
|
||||
|
||||
>>>>Example System Define:
|
||||
Once all roles are defined these steps must be done to ensure the system is ready to use, this includes setting a default
|
||||
role, assigning a root (all permission) role that the server/system will use and the linier order that the roles fall into:
|
||||
role, assigning a root (all permission) role that the server/system will use and the linear order that the roles fall into:
|
||||
|
||||
Roles.set_default('Guest')
|
||||
Roles.set_root('System')
|
||||
@@ -145,7 +145,7 @@
|
||||
Roles._prototype:set_custom_color(color) --- Sets a custom colour for the role, can be accessed by other code
|
||||
Roles._prototype:set_permission_group(name,use_factorio_api) --- Sets the permission group for this role, players will be moved to the group of they highest role
|
||||
Roles._prototype:set_parent(role) --- Sets the parent for a role, any action not in allow or disallow will be looked for in its parents
|
||||
Roles._prototype:set_auto_promote_condition(callback) --- Sets an auto promote condition that is checked every 5 seconds, if true is returned then the player will recive the role
|
||||
Roles._prototype:set_auto_promote_condition(callback) --- Sets an auto promote condition that is checked every 5 seconds, if true is returned then the player will receive the role
|
||||
Roles._prototype:set_block_auto_promote(state) --- Sets the role to not allow players to have auto promote effect them, useful to keep people locked to a punishment
|
||||
|
||||
Roles._prototype:add_player(player,skip_check,skip_event) --- Adds a player to this role, players can have more than one role at a time, used internally see Roles.assign
|
||||
@@ -295,7 +295,7 @@ function Roles.get_role_by_name(name)
|
||||
end
|
||||
|
||||
--- Get a role with the given order index
|
||||
-- @tparam number index the place in the oder list of the role to get
|
||||
-- @tparam number index the place in the order list of the role to get
|
||||
-- @treturn Roles._prototype the role with that index in the order list or nil
|
||||
function Roles.get_role_by_order(index)
|
||||
local name = Roles.config.order[index]
|
||||
@@ -307,13 +307,13 @@ end
|
||||
-- @tparam ?number|string|table any the value used to find the role
|
||||
-- @treturn Roles._prototype the role that was found or nil see above
|
||||
function Roles.get_role_from_any(any)
|
||||
local tany = type(any)
|
||||
if tany == 'number' or tonumber(any) then
|
||||
local t_any = type(any)
|
||||
if t_any == 'number' or tonumber(any) then
|
||||
any = tonumber(any)
|
||||
return Roles.get_role_by_order(any)
|
||||
elseif tany == 'string' then
|
||||
elseif t_any == 'string' then
|
||||
return Roles.get_role_by_name(any)
|
||||
elseif tany == 'table' then
|
||||
elseif t_any == 'table' then
|
||||
return Roles.get_role_by_name(any.name)
|
||||
end
|
||||
end
|
||||
@@ -621,7 +621,7 @@ function Roles._prototype:set_parent(role)
|
||||
return self
|
||||
end
|
||||
|
||||
--- Sets an auto promote condition that is checked every 5 seconds, if true is returned then the player will recive the role
|
||||
--- Sets an auto promote condition that is checked every 5 seconds, if true is returned then the player will receive the role
|
||||
-- nb: this is one way, failing false after already gaining the role will not revoke the role
|
||||
-- @tparam function callback receives only one param which is player to promote, return true to promote the player
|
||||
-- @treturn Roles._prototype allows chaining
|
||||
|
||||
@@ -7,38 +7,38 @@
|
||||
This may be useful when storing config values and when they get set you want to make sure it is taken care of, or maybe you want
|
||||
to have a value that you can trigger an update of from different places.
|
||||
|
||||
-- this will register a new location called 'scenario.dificutly'
|
||||
-- this will register a new location called 'scenario.difficulty'
|
||||
-- note that setting a start value is optional and we could take nil to mean normal
|
||||
Store.register('scenario.dificutly',function(value)
|
||||
game.print('The scenario dificulty has be set to: '..value)
|
||||
Store.register('scenario.difficulty',function(value)
|
||||
game.print('The scenario difficulty has be set to: '..value)
|
||||
end)
|
||||
|
||||
-- this will set the value in the store to 'hard' and will trigger the update callback which will print a message to the game
|
||||
Store.set('scenario.dificutly','hard')
|
||||
Store.set('scenario.difficulty','hard')
|
||||
|
||||
-- this will return 'hard'
|
||||
Store.get('scenario.dificutly')
|
||||
Store.get('scenario.difficulty')
|
||||
|
||||
>>>> Using Children
|
||||
One limitation of store is that all lcoations must be registered to avoid desyncs, to get round this issue "children" can be used.
|
||||
When you set the value of a child it does not have its own update callback so rather the "parent" location which has been registerd
|
||||
One limitation of store is that all locations must be registered to avoid desyncs, to get round this issue "children" can be used.
|
||||
When you set the value of a child it does not have its own update callback so rather the "parent" location which has been registered
|
||||
will have its update value called with a second param of the name of that child.
|
||||
|
||||
This may be useful when you want a value of each player or force and since you cant regisier every player at the start you must use
|
||||
This may be useful when you want a value of each player or force and since you cant register every player at the start you must use
|
||||
the players name as the child name.
|
||||
|
||||
-- this will register the lcoation 'scenario.score' where we plan to use force names as the child
|
||||
-- this will register the location 'scenario.score' where we plan to use force names as the child
|
||||
Store.register('scenario.score',function(value,child)
|
||||
game.print(child..' now has a score of '..value)
|
||||
end)
|
||||
|
||||
-- this will return nil, but will not error as children dont need to be registerd
|
||||
-- this will return nil, but will not error as children don't need to be registered
|
||||
Store.get('scenario.score','player')
|
||||
|
||||
-- this will set 'player' to have a value of 10 for 'scenario.score' and trigger the game message print
|
||||
Store.set('scenario.score','player',10)
|
||||
|
||||
-- this would be the silliar to Store.get however this will return the names of all the children
|
||||
-- this would be the similar to Store.get however this will return the names of all the children
|
||||
Store.get_children('scenario.score')
|
||||
|
||||
>>>> Using Sync
|
||||
@@ -49,16 +49,16 @@
|
||||
This may be useful when you want to have a value change effect multiple instances or even if you just want a database to store values so
|
||||
you can sync data between map resets.
|
||||
|
||||
-- this example will register the location 'stastics.total-play-time' where we plan to use plan names as the child
|
||||
-- this example will register the location 'statistics.total-play-time' where we plan to use plan names as the child
|
||||
-- note that the location must be the same across instances
|
||||
Store.register('stastics.total-play-time',true,function(value,child)
|
||||
Store.register('statistics.total-play-time',true,function(value,child)
|
||||
game.print(child..' now has now played for '..value)
|
||||
end)
|
||||
|
||||
-- use of set and are all the same as non synced but you should include from_sync as true
|
||||
|
||||
>>>> Alternative method
|
||||
Some people may prefer to use a varible rather than a string for formating reasons here is an example. Also for any times when
|
||||
Some people may prefer to use a variable rather than a string for formating reasons here is an example. Also for any times when
|
||||
there will be little external input Store.uid_location() can be used to generate non conflicting locations, uid_location will also
|
||||
be used if you give a nil location.
|
||||
|
||||
@@ -94,15 +94,15 @@ local function error_not_table(value)
|
||||
end
|
||||
end
|
||||
|
||||
--- Check for if a lcoation is registered
|
||||
--- Check for if a location is registered
|
||||
-- @tparam string location the location to test for
|
||||
-- @treturn boolean true if registered
|
||||
function Store.is_registered(location)
|
||||
return Store.registered[location]
|
||||
end
|
||||
|
||||
--- Returns a unqiue name that can be used for a store
|
||||
-- @treturn string a unqiue name
|
||||
--- Returns a unique name that can be used for a store
|
||||
-- @treturn string a unique name
|
||||
function Store.uid_location()
|
||||
return tostring(Token.uid())
|
||||
end
|
||||
@@ -111,7 +111,7 @@ end
|
||||
-- @tparam[opt] string location string a unique that points to the data, string used rather than token to allow migration
|
||||
-- @tparam[opt] boolean synced when true will output changes to a file so it can be synced
|
||||
-- @tparam[opt] function callback when given the callback will be automatically registered to the update of the value
|
||||
-- @treturn string the lcoation that is being used
|
||||
-- @treturn string the location that is being used
|
||||
function Store.register(location,synced,callback)
|
||||
if _LIFECYCLE ~= _STAGE.control then
|
||||
return error('Can only be called during the control stage', 2)
|
||||
@@ -231,13 +231,13 @@ end
|
||||
--- Gets all non nil children at a location, children can be added and removed during runtime
|
||||
-- this is similar to Store.get but will always return a table even if it is empty
|
||||
-- @tparam string location the location to get the children of
|
||||
-- @treturn table a table containg all the children names
|
||||
-- @treturn table a table containing all the children names
|
||||
function Store.get_children(location)
|
||||
local data = Store.get(location)
|
||||
return type(data) == 'table' and table_keys(data) or {}
|
||||
end
|
||||
|
||||
-- Handels syncing
|
||||
-- Handles syncing
|
||||
Event.add(Store.events.on_value_update,function(event)
|
||||
if Store.callbacks[event.location] then
|
||||
Store.callbacks[event.location](event.value,event.child)
|
||||
|
||||
@@ -12,11 +12,11 @@
|
||||
-- here we give sudo access to the function under the name "make-admin"
|
||||
Sudo.register('make-admin',make_admin)
|
||||
|
||||
-- this will allow us to bypass this by runing one tick later outside of any player scope
|
||||
-- this will allow us to bypass this by running one tick later outside of any player scope
|
||||
Sudo.run('make-admin',game.player)
|
||||
|
||||
>>>> Functions
|
||||
Sudo.register(name,callback) --- Registers a new callback under the given name, used to avoid desynces
|
||||
Sudo.register(name,callback) --- Registers a new callback under the given name, used to avoid desyncs
|
||||
Sudo.get(name) --- Gets the function that is registered under the given name
|
||||
Sudo.run(name,...) --- Runs the function that is registered under the given name, you may supply any number of params as needed
|
||||
]]
|
||||
@@ -33,7 +33,7 @@ Token.register(function(params)
|
||||
func(unpack(params.params))
|
||||
end)
|
||||
|
||||
--- Registers a new callback under the given name, used to avoid desynces
|
||||
--- Registers a new callback under the given name, used to avoid desyncs
|
||||
-- @tparam string name the name that will be used to call this function
|
||||
-- @tparam function callback the function that will be called by this name
|
||||
function Sudo.register(name,callback)
|
||||
|
||||
Reference in New Issue
Block a user