Eddit To ExpGamingCore.Gui and Added ExpGamingPlayer.Polls

This commit is contained in:
Cooldude2606
2018-10-09 18:49:40 +01:00
parent 8dffc99642
commit 6df973eb5c
42 changed files with 205 additions and 163 deletions

View File

@@ -1,4 +1,4 @@
[gui]
[ExpGamingCore_Gui]
unauthorized=401 - Unbefugt: Du hast keinen Zugriff auf diese Befehle!
cant-open=Du kannst dieses Menü nicht öffnen, Grund: __1__
cant-open-no-reason=Du kannst dieses Menü gerade nicht öffnen.

View File

@@ -1,4 +1,4 @@
[gui]
[ExpGamingCore_Gui]
unauthorized=401 - Unauthorized: Access is denied due to invalid credentials
cant-open=You can't open this panel right now, reason: __1__
cant-open-no-reason=You can't open this panel right now

View File

@@ -1,4 +1,4 @@
[gui]
[ExpGamingCore_Gui]
unauthorized=401 - Unauthorized: Access is denied due to invalid credentials
cant-open=You can not open this panel right now, reason: __1__
cant-open-no-reason=You can not open this panel right now

View File

@@ -1,4 +1,4 @@
[gui]
[ExpGamingCore_Gui]
unauthorized=401 - Onbevoegd: toegang wordt geweigerd vanwege ongeldige inloggegevens
cant-open=Je kan dit momenteel niet openen. Reden: __1__
cant-open-no-reason=Je kan dit momenteel niet openen.

View File

@@ -1,4 +1,4 @@
[gui]
[ExpGamingCore_Gui]
unauthorized=401 -Otillåten: Tillgång nekas på grund av otillräcklig säkerhetsprövning.
cant-open=Du kan inte öppna den här panelen just nu, orsak: __1__
cant-open-no-reason=Du kan inte öppna den här panelen just nu

View File

@@ -13,17 +13,18 @@ local mod_gui = require("mod-gui")
local Gui = Gui -- this is to force gui to remain in the ENV
local center = {}
center._center = {}
center._prototype = {}
--- Adds a new obj to the center gui
-- @usage Gui.center.add{name='foo',caption='Foo',tooltip='Testing',draw=function}
-- @usage return_value(player) -- opens the center gui for that player
-- @param obj contains the new object, needs name, fraw is opt and is function(root_frame)
-- @return the object made, used to add tabs
-- @return the object made, used to add tabs, calling the returned value will open the center for the given player
function center.add(obj)
if not is_type(obj,'table') then return end
if not is_type(obj.name,'string') then return end
verbose('Created Center Gui: '..obj.name)
setmetatable(obj,{__index=center._center})
setmetatable(obj,{__index=center._prototype,__call=function(self,...) center.open(player,self.name) end})
obj.tabs = {}
obj._tabs = {}
Gui.data('center',obj.name,obj)
@@ -86,7 +87,7 @@ end
-- used on the button press when the toolbar button is press, can be overriden
-- not recomented for direct use see Gui.center.open
function center._center.open(event)
function center._prototype.open(event)
local player = Game.get_player(event)
local _center = Gui.data.center[event.element.name]
local center_flow = center.get_flow(player)
@@ -109,7 +110,7 @@ end
-- this is the default draw function if one is not provided, can be overriden
-- not recomented for direct use see Gui.center.open
function center._center:draw(frame)
function center._prototype:draw(frame)
Gui.bar(frame,510)
local tab_bar = frame.add{
type='frame',
@@ -161,7 +162,7 @@ function center._center:draw(frame)
local first_tab = nil
for name,button in pairs(self.tabs) do
first_tab = first_tab or name
button:draw(tab_bar_scroll_flow).style.font_color = defines.color.white
button(tab_bar_scroll_flow).style.font_color = defines.color.white
end
self._tabs[self.name..'_'..first_tab](tab_scroll_flow)
tab_bar_scroll_flow.children[1].style.font_color = defines.color.orange
@@ -175,7 +176,7 @@ end
-- @tparam[opt] string tooltip the tooltip that is on the button
-- @tparam function callback this is called when button is pressed with function(root_frame)
-- @return self to allow chaining of _center:add_tab
function center._center:add_tab(name,caption,tooltip,callback)
function center._prototype:add_tab(name,caption,tooltip,callback)
verbose('Created Tab: '..self.name..'/'..name)
self._tabs[self.name..'_'..name] = callback
self.tabs[name] = Gui.inputs.add{
@@ -210,4 +211,5 @@ center._events = {[defines.events.on_gui_closed]=function(event)
end}
center.on_role_change = center.clear
return center
-- calling will attempt to add a new gui
return setmetatable(center,{__call=function(self,...) self.add(...) end})

View File

@@ -13,7 +13,7 @@ local mod_gui = require("mod-gui")
local Gui = Gui -- this is to force gui to remain in the ENV
local inputs = {}
inputs._input = {}
inputs._prototype = {}
-- these are just so you can have short cuts to this
inputs.events = {
error='error',
@@ -30,7 +30,7 @@ inputs.events = {
-- @param event the event to raise callback on | can be number of the event | can be a key of inputs.events
-- @tparam function callback the function you want to run on the event
-- @treturn table returns self so you can chain together
function inputs._input:on_event(event,callback)
function inputs._prototype:on_event(event,callback)
if not is_type(callback,'function') then return self end
if inputs.events[event] then event = inputs.events[event] end
if event == 'error' then self._error = callback return self end
@@ -42,7 +42,7 @@ end
-- @usage button:draw(frame)
-- @param root the element you want to add the input to
-- @return returns the element that was added
function inputs._input:draw(root)
function inputs._prototype:draw(root)
local player = Game.get_player(root.player_index)
if is_type(self.draw_data.caption,'string') and player.gui.is_valid_sprite_path(self.draw_data.caption) then
local data = table.deepcopy(self.draw_data)
@@ -89,8 +89,9 @@ end
--- Add a new input, this is the same as doing frame.add{} but returns a diffrent object
-- @usage Gui.inputs.add{type='button',name='test',caption='Test'}
-- @usage return_value(frame) -- draws the button onto that frame
-- @tparam table obj the new element to add if caption is a sprite path then sprite is used
-- @treturn table the custom input object
-- @treturn table the custom input object, calling the returned calue will draw the button
function inputs.add(obj)
if not is_type(obj,'table') then return end
if not is_type(obj.type,'string') then return end
@@ -110,7 +111,7 @@ function inputs.add(obj)
obj.draw_data = table.deepcopy(obj)
obj.data = {}
obj.events = {}
setmetatable(obj,{__index=inputs._input})
setmetatable(obj,{__index=inputs._prototype,__call=function(self,...) self:draw(...) end})
Gui.data('inputs_'..type,obj.name,obj)
return obj
end
@@ -378,7 +379,7 @@ function inputs.add_drop_down(name,items,index,callback)
return drop_down
end
-- second return is join event and third is rank change event
return inputs
-- calling will attempt to add a new input
return setmetatable(inputs,{__call=function(self,...) self.add(...) end})
-- to see examples look at GuiParts/test.lua

View File

@@ -15,7 +15,7 @@ local mod_gui = require("mod-gui")
local Gui = Gui -- this is to force gui to remain in the ENV
local left = {}
left._left = {}
left._prototype = {}
-- used for debugging
function left.override_open(state)
@@ -23,13 +23,14 @@ function left.override_open(state)
end
--- Used to add a left gui frame
-- @usage Gui.left.add{name='foo',caption='Foo',tooltip='just testing',open_on_join=true,can_open=function,draw=function}
-- @usage return_value(player) -- toggles visiblity for that player, if no player then updates for all players
-- @param obj this is what will be made, needs a name and a draw function(root_frame), open_on_join can be used to set the deaful state true/false, can_open is a test to block it from opening but is not needed
-- @return the object that is made to... well idk but for the future
-- @return the object that is made, calling the returned value with out a param will update the gui, else will toggle visiblity for that player
function left.add(obj)
if not is_type(obj,'table') then return end
if not is_type(obj.name,'string') then return end
verbose('Created Left Gui: '..obj.name)
setmetatable(obj,{__index=left._left})
setmetatable(obj,{__index=left._prototype,__call=function(self,player) if player then self:toggle{player=player,element={name=self.name}} else left.update(self.name) end end})
Gui.data('left',obj.name,obj)
Gui.toolbar.add(obj.name,obj.caption,obj.tooltip,obj.toggle)
return obj
@@ -122,7 +123,7 @@ function left.close(left_name)
end
-- this is used to draw the gui for the first time (these guis are never destoryed), used by the script
function left._left.open(event)
function left._prototype.open(event)
local player = Game.get_player(event)
local _left = Gui.data.left[event.element.name]
local left_flow = mod_gui.get_frame_flow(player)
@@ -139,7 +140,7 @@ function left._left.open(event)
end
-- this is called when the toolbar button is pressed
function left._left.toggle(event)
function left._prototype.toggle(event)
local player = Game.get_player(event)
local _left = Gui.data.left[event.element.name]
local left_flow = mod_gui.get_frame_flow(player)
@@ -167,8 +168,8 @@ function left._left.toggle(event)
else
left.style.visible = false
end
if open == false then player_return({'gui.cant-open-no-reason'},defines.textcolor.crit,player) player.play_sound{path='utility/cannot_build'}
elseif open ~= true then player_return({'gui.cant-open',open},defines.textcolor.crit,player) player.play_sound{path='utility/cannot_build'} end
if open == false then player_return({'ExpGamingCore_Gui.cant-open-no-reason'},defines.textcolor.crit,player) player.play_sound{path='utility/cannot_build'}
elseif open ~= true then player_return({'ExpGamingCore_Gui.cant-open',open},defines.textcolor.crit,player) player.play_sound{path='utility/cannot_build'} end
end
left.on_player_joined_game = function(event)
@@ -185,4 +186,5 @@ function left:on_init()
if loaded_modules['ExpGamingCore.Role'] then Role = require('ExpGamingCore.Role') end
end
return left
-- calling will attempt to add a new gui
return setmetatable(left,{__call=function(self,...) self.add(...) end})

View File

@@ -12,10 +12,10 @@ local mod_gui = require("mod-gui")
local Gui = Gui -- this is to force gui to remain in the ENV
local popup = {}
popup._popup = {}
popup._prototype = {}
function popup.load()
popup._popup.close = Gui.inputs.add{
popup._prototype.close = Gui.inputs.add{
type='button',
name='popup-close',
caption='utility/set_bar_slot',
@@ -28,13 +28,14 @@ end
--- Used to add a popup gui style
-- @usage Gui.left.add{name='foo',caption='Foo',draw=function}
-- @usage return_value(data,player) -- opens popup for one player use popup.open to open for more than one player
-- @param obj this is what will be made, needs a name and a draw function(root_frame,data)
-- @return the object that is made to... well idk but for the future
-- @return the object that is made, calling the returned value will open the popup for that player
function popup.add(obj)
if not is_type(obj,'table') then return end
if not is_type(obj.name,'string') then return end
verbose('Created Popup Gui: '..obj.name)
setmetatable(obj,{__index=popup._popup})
setmetatable(obj,{__index=popup._prototype,__call=function(self,data,player) local players = player and {player} or nil popup.open(self.name,data,players) end})
local name = obj.name; obj.name = nil
Gui.data('popup',name,obj)
obj.name = name
@@ -73,7 +74,7 @@ function popup.open(style,data,players)
direction='vertical',
style='image_frame'
}
_popup.close:draw(_frame)
_popup.close(_frame)
if is_type(_popup.draw,'function') then
local success, err = pcall(_popup.draw,frame,data)
if not success then error(err) end
@@ -97,7 +98,7 @@ function popup.open(style,data,players)
direction='vertical',
style='image_frame'
}
thread.data.popup.close:draw(_frame)
thread.data.popup.close(_frame)
if is_type(thread.data.popup.draw,'function') then
local success, err = pcall(thread.data.popup.draw,frame,thread.data.data)
if not success then error(err) end
@@ -106,11 +107,12 @@ function popup.open(style,data,players)
end
end
function popup._popup:add_left(obj)
function popup._prototype:add_left(obj)
obj.name = obj.name or self.name
self.left = Gui.left.add(obj)
end
popup.on_player_joined_game = popup.flow
return popup
-- calling will attempt to add a new popup style
return setmetatable(popup,{__call=function(self,...) self.add(...) end})

View File

@@ -20,7 +20,7 @@ local toolbar = {}
-- @tparam string caption can be a sprite path or text to show
-- @tparam string tooltip the help to show for the button
-- @tparam function callback the function which is called on_click
-- @treturn table the button object that was made
-- @treturn table the button object that was made, calling the returned value will draw the toolbar button added
function toolbar.add(name,caption,tooltip,callback)
verbose('Created Toolbar Button: '..name)
local button = Gui.inputs.add{type='button',name=name,caption=caption,tooltip=tooltip}
@@ -41,9 +41,9 @@ function toolbar.draw(player)
for name,button in pairs(Gui.data.toolbar) do
if is_type(Role,'table') then
if Role.allowed(player,name) then
button:draw(toolbar_frame)
button(toolbar_frame)
end
else button:draw(toolbar_frame) end
else button(toolbar_frame) end
end
end
@@ -53,4 +53,5 @@ end
toolbar.on_role_change = toolbar.draw
toolbar.on_player_joined_game = toolbar.draw
return toolbar
-- calling with only a player will draw the toolbar for that player, more params will attempt to add a button
return setmetatable(toolbar,{__call=function(self,player,extra,...) if extra then self.add(player,extra,...) else self.draw(player) end end})