mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-29 12:16:37 +09:00
Most bugs caught
This commit is contained in:
@@ -13,10 +13,21 @@ local Color = require('FactorioStdLib.Color')
|
||||
local Role -- this is optional and is hanndled by it being present, it is loaded on init
|
||||
local mod_gui = require("mod-gui")
|
||||
local Gui = Gui -- this is to force gui to remain in the ENV
|
||||
local order_config = order_config
|
||||
|
||||
local left = {}
|
||||
left._prototype = {}
|
||||
|
||||
left.hide = Gui.inputs{
|
||||
name='gui-left-hide',
|
||||
type='button',
|
||||
caption='<'
|
||||
}:on_event('click',function(event)
|
||||
for _,child in pairs(event.element.parent.children) do
|
||||
if child.name ~= 'popups' then child.style.visible = false end
|
||||
end
|
||||
end)
|
||||
|
||||
-- used for debugging
|
||||
function left.override_open(state)
|
||||
global.over_ride_left_can_open = state
|
||||
@@ -63,9 +74,7 @@ function left.update(frame,players)
|
||||
data={player=player,frames=thread.data.frames}
|
||||
}:on_event('resolve',function(thread)
|
||||
for name,left in pairs(thread.data.frames) do
|
||||
if left then
|
||||
left:first_open(thread.data.player)
|
||||
end
|
||||
if left then left:first_open(thread.data.player) end
|
||||
end
|
||||
end):queue()
|
||||
end):open()
|
||||
@@ -119,20 +128,26 @@ end
|
||||
-- @usage left:open(player)
|
||||
-- @tparam luaPlayer player the player to open the gui for
|
||||
function left._prototype:open(player)
|
||||
local player = Game.get_player(event)
|
||||
local player = Game.get_player(player)
|
||||
if not player then error('Invalid Player') end
|
||||
local left_flow = mod_gui.get_frame_flow(player)
|
||||
if not left_flow[_left.name] then self:first_open(player) end
|
||||
left_flow[_left.name].style.visible = true
|
||||
if not left_flow[self.name] then self:first_open(player) end
|
||||
left_flow[self.name].style.visible = true
|
||||
left_flow['gui-left-hide'].style.visible = true
|
||||
end
|
||||
|
||||
--- Used to force the gui closed for the player
|
||||
-- @usage left:open(player)
|
||||
-- @tparam luaPlayer player the player to close the gui for
|
||||
function left._prototype:close(player)
|
||||
local player = Game.get_player(event)
|
||||
local player = Game.get_player(player)
|
||||
if not player then error('Invalid Player') end
|
||||
local left_flow = mod_gui.get_frame_flow(player)
|
||||
if not left_flow[_left.name] then self:first_open(player) end
|
||||
left_flow[_left.name].style.visible = false
|
||||
if not left_flow[self.name] then self:first_open(player) end
|
||||
left_flow[self.name].style.visible = false
|
||||
local count = 0
|
||||
for _,child in pairs(left_flow.children) do if child.style.visible then count = count+1 end if count > 1 then break end end
|
||||
if count == 1 then left_flow['gui-left-hide'].style.visible = false end
|
||||
end
|
||||
|
||||
--- When the gui is first made or is updated this function is called, used by the script
|
||||
@@ -149,9 +164,9 @@ function left._prototype:first_open(player)
|
||||
else
|
||||
frame = left_flow.add{type='frame',name=self.name,style=mod_gui.frame_style,caption=self.caption,direction='vertical'}
|
||||
frame.style.visible = false
|
||||
if is_type(self.open_on_join,'boolean') then frame.style.visible = self.open_on_join end
|
||||
if is_type(self.open_on_join,'boolean') then frame.style.visible = self.open_on_join left_flow['gui-left-hide'].style.visible = true end
|
||||
end
|
||||
if is_type(self.draw,'function') then self.draw(frame) else frame.style.visible = false error('No Callback On '.._left.name) end
|
||||
if is_type(self.draw,'function') then self.draw(frame) else frame.style.visible = false error('No Callback On '..self.name) end
|
||||
return frame
|
||||
end
|
||||
|
||||
@@ -162,29 +177,33 @@ end
|
||||
function left._prototype:toggle(player)
|
||||
local player = Game.get_player(player)
|
||||
local left_flow = mod_gui.get_frame_flow(player)
|
||||
if not left_flow[_left.name] then _left:first_open(player) end
|
||||
local left = left_flow[_left.name]
|
||||
if not left_flow[self.name] then self:first_open(player) end
|
||||
local left = left_flow[self.name]
|
||||
local open = false
|
||||
if is_type(_left.can_open,'function') then
|
||||
local success, err = pcall(_left.can_open,player)
|
||||
if is_type(self.can_open,'function') then
|
||||
local success, err = pcall(self.can_open,player)
|
||||
if not success then error(err)
|
||||
elseif err == true then open = true
|
||||
elseif global.over_ride_left_can_open then
|
||||
if is_type(Role,'table') then
|
||||
if Role.allowed(player,_left.name) then open = true
|
||||
if Role.allowed(player,self.name) then open = true
|
||||
else open = {'ExpGamingCore_Gui.unauthorized'} end
|
||||
else open = true end
|
||||
else open = err end
|
||||
else
|
||||
if is_type(Role,'table') then
|
||||
if Role.allowed(player,_left.name) then open = true
|
||||
if Role.allowed(player,self.name) then open = true
|
||||
else open = {'ExpGamingCore_Gui.unauthorized'} end
|
||||
else open = true end
|
||||
end
|
||||
if open == true and left.style.visible ~= true then
|
||||
left.style.visible = true
|
||||
left_flow['gui-left-hide'].style.visible = true
|
||||
else
|
||||
left.style.visible = false
|
||||
local count = 0
|
||||
for _,child in pairs(left_flow.children) do if child.style.visible then count = count+1 end if count > 1 then break end end
|
||||
if count == 1 then left_flow['gui-left-hide'].style.visible = false end
|
||||
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
|
||||
@@ -195,8 +214,17 @@ left.on_player_joined_game = function(event)
|
||||
-- draws the left guis when a player first joins, fake_event is just because i am lazy
|
||||
local player = Game.get_player(event)
|
||||
local frames = Gui.data.left or {}
|
||||
left.hide(mod_gui.get_frame_flow(player)).style.maximal_width=15
|
||||
local done = {}
|
||||
for _,name in pairs(order_config) do
|
||||
local left = Gui.data.left[name]
|
||||
if left then
|
||||
done[name] = true
|
||||
left:first_open(player)
|
||||
end
|
||||
end
|
||||
for name,left in pairs(frames) do
|
||||
left:first_open(player)
|
||||
if not done[name] then left:first_open(player) end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -22,7 +22,8 @@ function popup.load()
|
||||
tooltip='Close This Popup'
|
||||
}:on_event('click',function(event)
|
||||
local frame = event.element.parent
|
||||
if frame and frame.valid then frame.destroy() end
|
||||
local parent = frame.parent
|
||||
if frame and frame.valid then frame.destroy() if #parent.children == 0 then parent.style.visible = false end end
|
||||
end)
|
||||
end
|
||||
|
||||
@@ -45,7 +46,9 @@ end
|
||||
-- this is used by the script to find the popup flow
|
||||
function popup.flow(player)
|
||||
local player = Game.get_player(player)
|
||||
local flow = mod_gui.get_frame_flow(player).popups or mod_gui.get_frame_flow(player).add{name='popups',type='flow',direction='vertical'}
|
||||
if not player then error('Invalid Player',2) end
|
||||
local flow = mod_gui.get_frame_flow(player).popups
|
||||
if not flow then flow = mod_gui.get_frame_flow(player).add{name='popups',type='flow',direction='vertical'} flow.style.visible=false end
|
||||
return flow
|
||||
end
|
||||
|
||||
@@ -59,10 +62,11 @@ function popup.open(style,data,players)
|
||||
local players = players or game.connected_players
|
||||
local data = data or {}
|
||||
if not _popup then return end
|
||||
if _popup.left then Gui.left.close(_popup.left.name) end
|
||||
if not Server or not Server._thread then
|
||||
for _,player in pairs(players) do
|
||||
if _popup.left then _popup.left:close(player) end
|
||||
local flow = popup.flow(player)
|
||||
flow.style.visible=true
|
||||
local _frame = flow.add{
|
||||
type='frame',
|
||||
direction='horizontal',
|
||||
@@ -86,7 +90,9 @@ function popup.open(style,data,players)
|
||||
}:on_event('tick',function(thread)
|
||||
if #thread.data.players == 0 then thread:close() return end
|
||||
local player = table.remove(thread.data.players,1)
|
||||
if _popup.left then _popup.left:close(player) end
|
||||
local flow = popup.flow(player)
|
||||
flow.style.visible=true
|
||||
local _frame = flow.add{
|
||||
type='frame',
|
||||
direction='horizontal',
|
||||
|
||||
@@ -161,7 +161,7 @@ local send_popup = Gui.inputs{
|
||||
}:on_event('click',function(event)
|
||||
local player = Game.get_player(event)
|
||||
local message = event.element.parent['test-popup-text'].text
|
||||
Gui.popup.open('test-popup',{player=player.name,message=message})
|
||||
Gui.popup.open('test-popup',{message=message,player=player.name})
|
||||
end)
|
||||
Gui.popup{
|
||||
name='test-popup',
|
||||
|
||||
@@ -11,9 +11,28 @@ local Game = require('FactorioStdLib.Game')
|
||||
local Role -- this is optional and is hanndled by it being present, it is loaded on init
|
||||
local mod_gui = require("mod-gui")
|
||||
local Gui = Gui -- this is to force gui to remain in the ENV
|
||||
local order_config = order_config
|
||||
|
||||
local toolbar = {}
|
||||
|
||||
toolbar.hide = Gui.inputs{
|
||||
name='gui-toolbar-hide',
|
||||
type='button',
|
||||
caption='<'
|
||||
}:on_event('click',function(event)
|
||||
if event.element.caption == '<' then
|
||||
event.element.caption = '>'
|
||||
for _,child in pairs(event.element.parent.children) do
|
||||
if child.name ~= event.element.name then child.style.visible = false end
|
||||
end
|
||||
else
|
||||
event.element.caption = '<'
|
||||
for _,child in pairs(event.element.parent.children) do
|
||||
if child.name ~= event.element.name then child.style.visible = true end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
--- Add a button to the toolbar, ranks need to be allowed to use these buttons if ranks is preset
|
||||
-- @usage toolbar.add('foo','Foo','Test',function() game.print('test') end)
|
||||
-- @tparam string name the name of the button
|
||||
@@ -38,12 +57,27 @@ function toolbar.draw(player)
|
||||
local toolbar_frame = mod_gui.get_button_flow(player)
|
||||
toolbar_frame.clear()
|
||||
if not Gui.data.toolbar then return end
|
||||
toolbar.hide(toolbar_frame).style.maximal_width = 15
|
||||
local done = {}
|
||||
for _,name in pairs(order_config) do
|
||||
local button = Gui.data.toolbar[name]
|
||||
if button then
|
||||
done[name] = true
|
||||
if is_type(Role,'table') then
|
||||
if Role.allowed(player,name) then
|
||||
button(toolbar_frame)
|
||||
end
|
||||
else button(toolbar_frame) end
|
||||
end
|
||||
end
|
||||
for name,button in pairs(Gui.data.toolbar) do
|
||||
if is_type(Role,'table') then
|
||||
if Role.allowed(player,name) then
|
||||
button(toolbar_frame)
|
||||
end
|
||||
else button(toolbar_frame) end
|
||||
if not done[name] then
|
||||
if is_type(Role,'table') then
|
||||
if Role.allowed(player,name) then
|
||||
button(toolbar_frame)
|
||||
end
|
||||
else button(toolbar_frame) end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user