diff --git a/expcore/Gui/core.lua b/expcore/Gui/core.lua index 16c9fe5a..07d7e8f7 100644 --- a/expcore/Gui/core.lua +++ b/expcore/Gui/core.lua @@ -278,8 +278,8 @@ function Gui._define_factory(prototype) } },{ __index=prototype, - __call=function(self,element) - return self:draw_to(element) + __call=function(self,element,...) + return self:draw_to(element,...) end }) Gui.defines[define.name] = define @@ -350,7 +350,7 @@ end -- the data with in the draw_data is set up through the use of all the other functions -- @tparam element LuaGuiElement the element that the define will draw a copy of its self onto -- @treturn LuaGuiElement the new element that was drawn so styles can be applied -function Gui._prototype:draw_to(element) +function Gui._prototype:draw_to(element,...) if element[self.name] then return end local player = Game.get_player_by_index(element.player_index) @@ -368,7 +368,7 @@ function Gui._prototype:draw_to(element) Instances.add_element(self.name,new_element) end - if self.post_draw then self.post_draw(new_element) end + if self.post_draw then self.post_draw(new_element,...) end return new_element end @@ -469,9 +469,9 @@ end -- @tparam name ?string|table the uid, debug name or define for the element define to draw -- @tparam element LuaGuiEelement the parent element that it the define will be drawn to -- @treturn LuaGuiElement the new element that was created -function Gui.draw(name,element) +function Gui.draw(name,element,...) local define = Gui.get_define(name,true) - return define:draw_to(element) + return define:draw_to(element,...) end --- Will toggle the enabled state of an element @@ -496,4 +496,18 @@ function Gui.toggle_visible(element) end end +--- Sets the padding for a gui element +-- @tparam element LuaGuiElement the element to set the padding for +-- @tparam[opt=0] up number the amount of padding on the top +-- @tparam[opt=0] down number the amount of padding on the bottom +-- @tparam[opt=0] left number the amount of padding on the left +-- @tparam[opt=0] right number the amount of padding on the right +function Gui.set_padding(element,up,down,left,right) + local style = element.style + style.top_padding = up or 0 + style.bottom_padding = down or 0 + style.left_padding = left or 0 + style.right_padding = right or 0 +end + return Gui \ No newline at end of file diff --git a/expcore/Gui/instances.lua b/expcore/Gui/instances.lua index c1abecd0..7e0fde9f 100644 --- a/expcore/Gui/instances.lua +++ b/expcore/Gui/instances.lua @@ -206,8 +206,8 @@ end -- @treturn table the table of element instances with all invalid ones removed function Instances.unregistered_get_elements(name,category,callback) local elements = Instances.data[name] - if category then - elements = Instances.data[name][category] + if elements and category then + elements = elements[category] end if not elements then return {} end diff --git a/expcore/Gui/left.lua b/expcore/Gui/left.lua index 45fb3bad..da7f37e4 100644 --- a/expcore/Gui/left.lua +++ b/expcore/Gui/left.lua @@ -253,13 +253,11 @@ Event.add(defines.events.on_player_created,function(event) local player = Game.get_player_by_index(event.player_index) local flow = LeftFrames.get_flow(player) - local style = LeftFrames.toggle_button(flow).style + local close_button = LeftFrames.toggle_button(flow) + Gui.set_padding(close_button) + local style = close_button.style style.width = 18 style.height = 36 - style.left_padding = 0 - style.top_padding = 0 - style.right_padding = 0 - style.bottom_padding = 0 style.font = 'default-small-bold' for _,define in pairs(LeftFrames.frames) do diff --git a/expcore/Gui/popups.lua b/expcore/Gui/popups.lua new file mode 100644 index 00000000..fa0c0668 --- /dev/null +++ b/expcore/Gui/popups.lua @@ -0,0 +1,228 @@ +--- Gui structure define for popup gui +--[[ +>>>> Functions + 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_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 + PopupFrames._prototype:set_default_open_time(amount) --- Sets the default open time for the popup, will be used if non is provided with open + PopupFrames._prototype:open(player,open_time,...) --- Opens this define for a player, can be given open time and any other params for the draw function +]] +local Gui = require 'expcore.gui.core' +local Game = require 'utils.game' +local Event = require 'utils.event' +local ProgressBar = require 'expcore.gui.progress-bar' +local Button = require 'expcore.gui.buttons' +local mod_gui = require 'mod-gui' +local Color = require 'resources.color_presets' +local Global = require 'utils.global' + +local PopupFrames = { + paused_popups={}, + popup_flow_name = Gui.uid_name(), + main_frame_name = Gui.uid_name(), + close_frame_name = Gui.uid_name(), + _prototype = Gui._prototype_factory{ + on_draw = Gui._event_factory('on_draw') + } +} +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 +-- @tparam element LuaGuiElement the element to set the state of +-- @tparam[opt] state boolean the state to set it to, true will pause the the progress bar +local function set_pasued_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 +-- @tparam element LuaGuiElement the element to get the state of +local function get_pasued_state(element) + local name = element.player_index..':'..element.index + return PopupFrames.paused_popups[name] +end + +--- Gets the left flow that contains the popup frames +-- @tparam player LuaPlayer the player to get the flow for +-- @treturn LuaGuiElement the left flow that contains the popup frames +function PopupFrames.get_flow(player) + player = Game.get_player_from_any(player) + local flow = mod_gui.get_frame_flow(player) + return flow[PopupFrames.popup_flow_name] +end + +--- Opens a popup for the player, can give the amount of time it is open as well as params for the draw function +-- @tparam define_name string the name of the define that you want to open for the player +-- @tparam player LuaPlayer the player to open the popup for +-- @tparam[opt] open_time number the minimum number of ticks you want the popup open for, 0 means no limit, nil will take default +-- @tparam ... any the other params that you want to pass to your on_draw event +-- @treturn LuaGuiElement the frame that was drawn, the inner gui flow which contains the content +function PopupFrames.open(define_name,player,open_time,...) + local define = Gui.get_define(define_name,true) + player = Game.get_player_from_any(player) + return define:open(player,open_time,...) +end + +--- Closes the popup, is called by progress bar and close button +-- @tparam element LuaGuiElement either the progress bar or the close button +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()]) + frame.destroy() +end + +--- Progress bar which when depleaded will close the popup frame +PopupFrames.close_progress = +ProgressBar.new_progressbar() +:use_count_down() +:set_tooltip('Pause/Resume Auto-close') +:on_complete(function(player,element) + close_popup(element) +end) + +--- A button which can be used to close the gui before the timer runs out +PopupFrames.close_button = +Button.new_button() +:set_sprites('utility/close_white') +:set_tooltip('Close Popup') +:on_click(function(player,element) + close_popup(element) +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) + else + set_pasued_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) + else + set_pasued_state(element,true) + end +end) + +--- Creates a new popup frame define +-- @tparam[opt] name string the optional debug name that can be added +-- @treturn table the new popup frame define +function PopupFrames.new_popup(name) + local self = Gui._define_factory(PopupFrames._prototype) + self.draw_data.type = 'flow' + self.draw_data.direction = 'vertical' + + if name then + self:debug_name(name) + end + + local mt = getmetatable(self) + mt.__call = function(tbl,player,open_time,...) + return tbl:open(player,open_time,...) + end + + self.post_draw = function(element,maximum,...) + -- main content frame + local frame = element.add{ + type='flow', + name=PopupFrames.main_frame_name + } + frame.style.horizontally_stretchable = true + + -- flow for progress bar and close button + local close_flow = element.add{ + type='flow', + name=PopupFrames.close_frame_name + } + close_flow.style.horizontally_stretchable = true + + -- progress bar, when 0 then a static full one is drawn + local progress_style + if maximum == 0 then + progress_style = close_flow.add{ + type='progressbar', + tooltip='No Auto-close', + value=1 + }.style + else + progress_style = PopupFrames.close_progress(close_flow,maximum).style + end + progress_style.top_padding = 6 + progress_style.bottom_padding = 3 + progress_style.height = 11 + progress_style.color = Color.grey + + -- close button, will close the popup when clicked + local close_button = PopupFrames.close_button(close_flow) + Gui.set_padding(close_button) + local close_button_style = close_button.style + close_button_style.width = 20 + close_button_style.height = 20 + + -- event trigger to draw the gui content + if self.events.on_draw then + local player = Game.get_player_by_index(element.player_index) + self.events.on_draw(player,frame,...) + end + end + + return self +end + +--- Sets the default open time for the popup, will be used if non is provided with open +-- @tparam amount number the number of ticks, by default, the popup will be open for +-- @treturn table the define to allow for chaining +function PopupFrames._prototype:set_default_open_time(amount) + self.default_open_time = amount + return self +end + +--- Opens this define for a player, can be given open time and any other params for the draw function +-- @tparam player LuaPlayer the player to open the popup for +-- @tparam[opt] open_time number the minimum number of ticks you want the popup open for, 0 means no limit, nil will take default +-- @tparam ... any the other params that you want to pass to your on_draw event +-- @treturn LuaGuiElement the frame that was drawn, the inner gui flow which contains the content +function PopupFrames._prototype:open(player,open_time,...) + open_time = open_time or self.default_open_time or 0 + player = Game.get_player_from_any(player) + + local flow = PopupFrames.get_flow(player) + local frame = flow.add{ + type='frame', + style='blurry_frame' + } + + Gui.set_padding(frame,3,3,4,4) + return self:draw_to(frame,open_time,...)[PopupFrames.main_frame_name] +end + +--- When player is first created the popup flow is added to they left flow +Event.add(defines.events.on_player_created,function(event) + local player = Game.get_player_by_index(event.player_index) + local flow = mod_gui.get_frame_flow(player) + + flow.add{ + type='flow', + direction='vertical', + name=PopupFrames.popup_flow_name + } +end) + +--- Every tick any, not pasued, 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) +end)) + +return PopupFrames \ No newline at end of file diff --git a/expcore/Gui/progress-bar.lua b/expcore/Gui/progress-bar.lua index f5799fb4..6944fb8e 100644 --- a/expcore/Gui/progress-bar.lua +++ b/expcore/Gui/progress-bar.lua @@ -1,21 +1,24 @@ --- Gui element define for progess bars --[[ >>>> Functions - ProgressBar.set_maximum(element,amount,start_full) --- Sets the maximum value that represents the end value of the progress bar + 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.new_progressbar(name) --- Creates a new progressbar element define - ProgressBar._prototype:set_maximum(amount,start_full) --- Sets the maximum value that represents the end value of the progress bar + ProgressBar._prototype:set_maximum(amount,count_down) --- Sets the maximum value that represents the end value of the progress bar + ProgressBar._prototype:use_count_down(state) --- Will set the progress bar to start at 1 and trigger when it hits 0 ProgressBar._prototype:increment(amount,category) --- Increases the value of the progressbar + ProgressBar._prototype:increment_filtered(amount,filter) --- Increases the value of the progressbar, if the filter condition is met, does not work with store ProgressBar._prototype:decrement(amount,category) --- Decreases the value of the progressbar - ProgressBar._prototype:add_element(element) --- Adds an element into the list of instances that will are waiting to complete, does not work with store + ProgressBar._prototype:decrement_filtered(amount,filter) --- Decreases the value of the progressbar, if the filter condition is met, does not work with store + 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() --- Triggers when a progress bar element compeltes (hits 0 or 1) - ProgressBar._prototype:on_complete() --- Triggers when a store value completes (hits 0 or 1) - ProgressBar._prototype:event_counter() --- Event handler factory that counts up by 1 every time the event triggeres - ProgressBar._prototype:event_countdown() --- Event handler factory that counts down by 1 every time the event triggeres + ProgressBar._prototype:on_complete(callback) --- Triggers when a progress bar element compeltes (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 ]] local Gui = require 'expcore.gui.core' local Global = require 'utils.global' @@ -39,15 +42,18 @@ end -- @tparam define table the define that this is acting on -- @tparam element LuaGuiElement the element that triggered the event local function store_call(define,element,value) - element.value = value - if define.start_full and value <= 0 or not define.start_full and value >= 1 then - event_call(define,element) + if value then + element.value = value + if define.count_down and value <= 0 + or not define.count_down and value >= 1 then + event_call(define,element) + end end end local ProgressBar = { - unregistered={}, - independent={}, + unregistered={}, -- elements with no callbacks + independent={}, -- elements with a link to a deinfe _prototype=Gui._prototype_factory{ -- note both events will recive a reset function that can be used to reset the progress of the element/store on_complete = Gui._event_factory('on_complete'), @@ -86,36 +92,32 @@ local function get_element(element) if ProgressBar.unregistered[name] then return ProgressBar.unregistered[name] - - else - ProgressBar.unregistered[name] = { - element=element, - maximum=1 - } - return ProgressBar.unregistered[name] - end end --- Sets the maximum value that represents the end value of the progress bar -- @tparam element ?LuaGuiElement|string either a gui element or a registered define -- @tparam amount number the amount to have set as the maximum --- @tparam[opt=false] start_full boolean when true the bar will start filled, to be used with decrease -function ProgressBar.set_maximum(element,amount,start_full) +function ProgressBar.set_maximum(element,amount) amount = amount > 0 and amount or error('amount must be greater than 0') local define = get_define(element) if define then - define:set_maximum(amount,start_full) + define:set_deafult_maximum(amount) else local element_data = get_element(element) if element_data then element_data.maximum = amount - if start_full then - element.value = 1 - end + + else + local name = element.player_index..':'..element.index + ProgressBar.unregistered[name] = { + element=element, + maximum=amount or 1 + } + end end @@ -135,11 +137,12 @@ function ProgressBar.increment(element,amount) local element_data = get_element(element) if element_data then - local max = element_data.maximum > 0 and element_data.maximum or 1 - local real_amount = amount/max + local real_amount = amount/element_data.maximum element.value = element.value + real_amount if element.value >= 1 then + local name = element.player_index..':'..element.index + ProgressBar.unregistered[name] = nil return true end end @@ -161,11 +164,12 @@ function ProgressBar.decrement(element,amount) local element_data = get_element(element) if element_data then - local max = element_data.maximum > 0 and element_data.maximum or 1 - local real_amount = amount/max + local real_amount = amount/element_data.maximum element.value = element.value - real_amount if element.value <= 0 then + local name = element.player_index..':'..element.index + ProgressBar.unregistered[name] = nil return true end end @@ -184,26 +188,29 @@ function ProgressBar.new_progressbar(name) self:debug_name(name) end - self.post_draw = function(element) + self.post_draw = function(element,maximum) if self.store then local category = self.categorize and self.categorize(element) or nil local value = self:get_store(category) if not value then - value = self.start_full and 1 or 0 + value = self.count_down and 1 or 0 self:set_store(category,value) end element.value = value else - if self.start_full then - self.value = 1 + if self.count_down then + element.value = 1 end if not ProgressBar.independent[self.name] then ProgressBar.independent[self.name] = {} end - table.insert(ProgressBar.independent[self.name],element) + table.insert(ProgressBar.independent[self.name],{ + element = element, + maximum = maximum + }) end @@ -214,36 +221,46 @@ end --- Sets the maximum value that represents the end value of the progress bar -- @tparam amount number the amount to have set as the maximum --- @tparam[opt=false] start_full boolean when true the bar will start filled, to be used with decrease -function ProgressBar._prototype:set_maximum(amount,start_full) +-- @treturn table the define to allow chaining +function ProgressBar._prototype:set_default_maximum(amount) amount = amount > 0 and amount or error('amount must be greater than 0') - self.maximum = amount - if start_full then - self.start_full = true - else - self.start_full = false - end + self.default_maximum = amount return self end +--- Will set the progress bar to start at 1 and trigger when it hits 0 +-- @tparam[opt=true] state boolean when true the bar will start filled, to be used with decrease +-- @treturn table the define to allow chaining +function ProgressBar._prototype:use_count_down(state) + if state == false then + self.count_down = false + else + self.count_down = true + end + return self +end + --- Main logic for changing the value of a progress bar, this only applies when its a registered define -- @tparam self table the define that is being changed -- @tparam amount number the amount which it is being changed by, may be negative -- @tparam[opt] category string the category to use with store -local function change_value_prototype(self,amount,category) +local function change_value_prototype(self,amount,category,filter) local function reset_store() - local value = self.start_full and 1 or 0 + local value = self.count_down and 1 or 0 local _category = category or value self:set_store(_category,value) end if self.store then - local value = self:get_store(category) or self.start_full and 1 or 0 - local new_value = value + amount + local value = self:get_store(category) or self.count_down and 1 or 0 + local maximum = self.default_maximum or 1 + local new_value = value + (amount/maximum) - if self.start_full and value <= 0 or not self.start_full and value >= 1 then + if self.count_down and new_value <= 0 + or not self.count_down and new_value >= 1 then self:set_store(category) + if self.events.on_store_complete then category = category or reset_store self.events.on_store_complete(category,reset_store) @@ -252,19 +269,28 @@ local function change_value_prototype(self,amount,category) category = category or new_value self:set_store(category,new_value) + + return end if ProgressBar.independent[self.name] then - for key,element in pairs(ProgressBar.independent[self.name]) do + for key,element_data in pairs(ProgressBar.independent[self.name]) do + local element = element_data.element if not element or not element.valid then ProgressBar.independent[self.name][key] = nil - else - element.value = element.value + amount - if self.start_full and element.value <= 0 or not self.start_full and element.value >= 1 then - ProgressBar.independent[self.name][key] = nil - event_call(self,element) + else + if not filter or filter(element) then + local maximum = element_data.maximum or self.default_maximum or 1 + element.value = element.value + (amount/maximum) + + if self.count_down and element.value <= 0 + or not self.count_down and element.value >= 1 then + ProgressBar.independent[self.name][key] = nil + event_call(self,element) + end end + end end end @@ -276,10 +302,15 @@ end -- @tparam[opt] category string the category that is used with a store function ProgressBar._prototype:increment(amount,category) amount = type(amount) == 'number' and amount or 1 - local max = self.maximum > 0 and self.maximum or 1 - local real_amount = amount/max + change_value_prototype(self,amount,category) +end - change_value_prototype(self,real_amount,category) +--- Increases the value of the progressbar, if the filter condition is met, does not work with store +-- @tparam[opt=1] amount number the amount to increase the progressbar by +-- @tparam[opt] category string the category that is used with a store +function ProgressBar._prototype:increment_filtered(amount,filter) + amount = type(amount) == 'number' and amount or 1 + change_value_prototype(self,amount,nil,filter) end --- Decreases the value of the progressbar @@ -287,28 +318,37 @@ end -- @tparam[opt] category string the category that is used with a store function ProgressBar._prototype:decrement(amount,category) amount = type(amount) == 'number' and amount or 1 - local max = self.maximum > 0 and self.maximum or 1 - local real_amount = amount/max + change_value_prototype(self,-amount,category) +end - change_value_prototype(self,-real_amount,category) +--- Decreases the value of the progressbar, if the filter condition is met, does not work with store +-- @tparam[opt=1] amount number the amount to decrease the progressbar by +-- @tparam[opt] category string the category that is used with a store +function ProgressBar._prototype:decrement_filtered(amount,filter) + amount = type(amount) == 'number' and amount or 1 + change_value_prototype(self,-amount,nil,filter) end --- Adds an element into the list of instances that will are waiting to complete, does not work with store -- note use store if you want persistent data, this only stores the elements not the values which they have -- @tparam element LuaGuiElement the element that you want to add into the waiting to complete list -function ProgressBar._prototype:add_element(element) +-- @tparam[opt] maximum number the maximum for this element if not given the default for this define is used +function ProgressBar._prototype:add_element(element,maximum) if self.store then return end if not ProgressBar.independent[self.name] then ProgressBar.independent[self.name] = {} end - table.insert(ProgressBar.independent[self.name],element) + table.insert(ProgressBar.independent[self.name],{ + element = element, + maximum = maximum + }) end --- Resets an element, or its store, to be back at the start, either 1 or 0 -- @tparam element LuaGuiElement the element that you want to reset the progress of function ProgressBar._prototype:reset_element(element) if not element or not element.valid then return end - local value = self.start_full and 1 or 0 + local value = self.count_down and 1 or 0 if self.store then local category = self.categorize and self.categorize(element) or value self:set_store(category,value) @@ -317,19 +357,33 @@ function ProgressBar._prototype:reset_element(element) end end ---- Event handler factory that counts up by 1 every time the event triggeres +--- Event handler factory that counts up by 1 every time the event triggeres, can filter which elements are incremented +-- @tparam[opt] filter function when given will use filtered incerement -- @treturn function the event handler -function ProgressBar._prototype:event_counter() - return function() - self:increment() +function ProgressBar._prototype:event_counter(filter) + if type(filter) == 'function' then + return function() + self:increment_filtered(1,filter) + end + else + return function() + self:increment() + end end end ---- Event handler factory that counts down by 1 every time the event triggeres +--- Event handler factory that counts down by 1 every time the event triggeres, can filter which elements are decremented +-- @tparam[opt] filter function when given will use filtered decerement -- @treturn function the event handler -function ProgressBar._prototype:event_countdown() - return function() - self:decrement() +function ProgressBar._prototype:event_countdown(filter) + if type(filter) == 'function' then + return function() + self:decrement_filtered(1,filter) + end + else + return function() + self:decrement() + end end end diff --git a/expcore/Gui/slider.lua b/expcore/Gui/slider.lua index c0182369..7c0df3ee 100644 --- a/expcore/Gui/slider.lua +++ b/expcore/Gui/slider.lua @@ -6,6 +6,7 @@ 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:use_notches(state) --- Adds notches to the slider 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 @@ -114,6 +115,17 @@ function Slider.new_slider(name) return self end +--- Adds notches to the slider +-- @tparam[opt] state boolean when true will draw notches onto the slider +function Slider._prototype:use_notches(state) + if state == false then + self.draw_data.style = nil + else + self.draw_data.style = 'notched_slider' + end + 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 diff --git a/expcore/Gui/test.lua b/expcore/Gui/test.lua index d227d10c..a4e7701f 100644 --- a/expcore/Gui/test.lua +++ b/expcore/Gui/test.lua @@ -116,6 +116,33 @@ end) Event.add(defines.events.on_player_joined_game,left_frame 'update_all') Event.add(defines.events.on_player_left_game,left_frame 'update_all') +--[[ + Popup Test + > Allows opening a popup which contains the players name and tick it was opened +]] + +local test_popup = +Gui.new_popup('test-popup') +:on_draw(function(player,frame) + frame.add{ + type='label', + caption=player.name + } + frame.add{ + type='label', + caption=game.tick + } +end) + +Gui.new_toolbar_button('test-popup-open') +:set_caption('Test Popup') +:set_post_authenticator(function(player,button_name) + return global.show_test_gui +end) +:on_click(function(player,element) + test_popup(player,300) +end) + --[[ Button Tests > No display - Simple button which has no display @@ -403,6 +430,7 @@ tests["List Boxs"] = { --[[ Slider Tests > Local default -- Simple slider with default range + > Local notched -- Simple slider with notches > Store default -- Slider with default range that stores value between re-draws > Static range -- Simple slider with a static range > Dynamic range -- Slider with a dynamic range @@ -417,6 +445,14 @@ Gui.new_slider('test-slider-local-default') player.print('Slider local default: '..tostring(math.round(value))..' '..tostring(math.round(percent,1))) end) +local slider_notched_default = +Gui.new_slider('test-slider-notched-default') +:set_tooltip('Silder notched default') +:use_notches() +:on_element_update(function(player,element,value,percent) + player.print('Slider notched default: '..tostring(math.round(value))..' '..tostring(math.round(percent,1))) +end) + local slider_player_default = Gui.new_slider('test-slider-store-default') :set_tooltip('Silder store default') @@ -464,6 +500,7 @@ end) tests.Sliders = { ['Local default']=slider_local_default, + ['Local notched']=slider_notched_default, ['Player default']=slider_player_default, ['Static range']=slider_static, ['Dynamic range']=slider_dynamic, @@ -584,14 +621,14 @@ tests["Elem Buttons"] = { local progressbar_one = Gui.new_progressbar('test-prog-one') -:set_maximum(120) +:set_default_maximum(120) :on_complete(function(player,element,reset_element) reset_element() end) local progressbar_two = Gui.new_progressbar('test-prog-one') -:set_maximum(300) +:set_default_maximum(300) :add_store(Gui.force_store) :on_complete(function(player,element,reset_element) reset_element() @@ -602,7 +639,8 @@ end) local progressbar_three = Gui.new_progressbar('test-prog-one') -:set_maximum(120,true) +:set_default_maximum(120) +:use_count_down() :on_complete(function(player,element,reset_element) reset_element() end) diff --git a/expcore/gui.lua b/expcore/gui.lua index 09363b24..5831acf8 100644 --- a/expcore/gui.lua +++ b/expcore/gui.lua @@ -108,6 +108,7 @@ Gui.classes.slider = Slider 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:use_notches(state) --- Adds notches to the slider 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 @@ -148,22 +149,26 @@ Gui.new_progressbar = ProgressBar.new_progressbar Gui.set_progressbar_maximum = ProgressBar.set_maximum Gui.increment_progressbar = ProgressBar.increment Gui.decrement_progressbar = ProgressBar.decrement +Gui.classes.progressbar = ProgressBar --[[ - ProgressBar.set_maximum(element,amount,start_full) --- Sets the maximum value that represents the end value of the progress bar + 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.new_progressbar(name) --- Creates a new progressbar element define - ProgressBar._prototype:set_maximum(amount,start_full) --- Sets the maximum value that represents the end value of the progress bar + ProgressBar._prototype:set_maximum(amount,count_down) --- Sets the maximum value that represents the end value of the progress bar + ProgressBar._prototype:use_count_down(state) --- Will set the progress bar to start at 1 and trigger when it hits 0 ProgressBar._prototype:increment(amount,category) --- Increases the value of the progressbar + ProgressBar._prototype:increment_filtered(amount,filter) --- Increases the value of the progressbar, if the filter condition is met, does not work with store ProgressBar._prototype:decrement(amount,category) --- Decreases the value of the progressbar - ProgressBar._prototype:add_element(element) --- Adds an element into the list of instances that will are waiting to complete, does not work with store + ProgressBar._prototype:decrement_filtered(amount,filter) --- Decreases the value of the progressbar, if the filter condition is met, does not work with store + 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() --- Triggers when a progress bar element compeltes (hits 0 or 1) - ProgressBar._prototype:on_complete() --- Triggers when a store value completes (hits 0 or 1) - ProgressBar._prototype:event_counter() --- Event handler factory that counts up by 1 every time the event triggeres - ProgressBar._prototype:event_countdown() --- Event handler factory that counts down by 1 every time the event triggeres + ProgressBar._prototype:on_complete(callback) --- Triggers when a progress bar element compeltes (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 ]] local Toolbar = require 'expcore.gui.toolbar' @@ -227,4 +232,21 @@ Gui.classes.center_frames = CenterFrames CenterFrames._prototype:event_handler(action) --- Creates an event handler that will trigger one of its functions, use with Event.add ]] +local PopupFrames = require 'expcore.gui.popups' +Gui.get_popup_flow = PopupFrames.get_flow +Gui.open_popup = PopupFrames.open +Gui.new_popup = PopupFrames.new_popup +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_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 + PopupFrames._prototype:set_default_open_time(amount) --- Sets the default open time for the popup, will be used if non is provided with open + PopupFrames._prototype:open(player,open_time,...) --- Opens this define for a player, can be given open time and any other params for the draw function +]] + return Gui \ No newline at end of file