From 5b10126c4482ca3dd6caa4cc5fbfe702aeb9567a Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sun, 8 Apr 2018 13:29:46 +0100 Subject: [PATCH] Gui Looks Nice --- ExpCore/load.lua | 2 +- ExpCore/sync.lua | 84 ++++++++++++++++++++++++++++-------------------- control.lua | 1 + 3 files changed, 52 insertions(+), 35 deletions(-) diff --git a/ExpCore/load.lua b/ExpCore/load.lua index 1eebd179..e4af77dd 100644 --- a/ExpCore/load.lua +++ b/ExpCore/load.lua @@ -20,7 +20,6 @@ local StdExpCoreLib = {} require '/commands' StdExpCoreLib.Server = require '/server' StdExpCoreLib.Ranking = require '/ranking' -StdExpCoreLib.Sync = require '/sync' StdExpCoreLib.Gui = require '/gui' StdExpCoreLib.Gui:_load_parts{ 'inputs', @@ -29,6 +28,7 @@ StdExpCoreLib.Gui:_load_parts{ 'left', 'popup' } +StdExpCoreLib.Sync = require '/sync' return function(rtn) local _return = {} diff --git a/ExpCore/sync.lua b/ExpCore/sync.lua index 7a8c944d..b393b28e 100644 --- a/ExpCore/sync.lua +++ b/ExpCore/sync.lua @@ -241,42 +241,58 @@ function Sync.add_to_gui(element,...) if is_type(element,'function') then table.insert(Sync_gui_functions,{'function',element,...}) elseif is_type(element,'table') then - if element.draw then - table.insert(Sync_gui_functions,{'gui',element}) - else - table.insert(Sync_gui_functions,{'table',element}) - end - else - table.insert(Sync_gui_functions,{'string',element}) - end + if element.draw then table.insert(Sync_gui_functions,{'gui',element}) + else table.insert(Sync_gui_functions,{'table',element}) end + else table.insert(Sync_gui_functions,{'string',element}) end end -Gui.center.add{ - name='server-info', - caption='Server Info', - tooltip='Basic info about the current server', - draw=function(self,frame) - local info = Sync.info() - Gui.bar(frame,200) - frame.add{type='lable',caption='Welcome To '..info.server_name,style='caption_label'} - if info.description then frame.add{type='lable',caption=info.description,style='description_label'} end - Gui.bar(frame,200) - local text_flow = frame.add{type='flow',direction='vertical'} - local button_flow = frame.add{type='table',column_count=3} - for _,element in pairs(Sync_gui_functions) do - local type = table.remove(element,1) - if type == 'function' then - local success, err = pcall(table.remove(element,1),unpack(element)) - if not success then error(err) else - if is_type(err,'table') then - if element.draw then element:draw(button_flow) - else text_flow.add{type='lable',caption=table.to_string(element)} end - else text_flow.add{type='lable',caption=tostring(element)} end - end - elseif type == 'gui' then element:draw(button_flow) - elseif type == 'string' then text_flow.add{type='lable',caption=tostring(element)} - elseif type == 'table' then text_flow.add{type='lable',caption=table.to_string(element)} end - end +function Sync._load() + Gui.center.add{ + name='server-info', + caption='Server Info', + tooltip='Basic info about the current server', + draw=function(self,frame) + local info = Sync.info() + local frame = frame.add{type='flow',direction='vertical'} + local _flow = frame.add{type='flow'} + Gui.bar(_flow,200) + _flow.add{type='label',caption='Welcome To '..info.server_name,style='caption_label'}.style.width = 185 + Gui.bar(_flow,200) + if info.description then frame.add{type='label',caption=info.description,style='description_label'} end + Gui.bar(frame,600) + local text_flow = frame.add{type='flow',direction='vertical'} + local button_flow = frame.add{type='table',column_count=3} + for _,element in pairs(Sync_gui_functions) do + local type = table.remove(element,1) + if type == 'function' then + local success, err = pcall(table.remove(element,1),unpack(element)) + if not success then error(err) else + if is_type(err,'table') then + if element.draw then element:draw(button_flow) + else text_flow.add{type='label',caption=table.to_string(element)} end + else text_flow.add{type='label',caption=tostring(element)} end + end + elseif type == 'gui' then element:draw(button_flow) + elseif type == 'string' then text_flow.add{type='label',caption=tostring(element)} + elseif type == 'table' then text_flow.add{type='label',caption=table.to_string(element)} end + end + end} +end + +Event.register(defines.events.on_player_joined_game,function(event) + local player = Game.get_player(event) + if not player.admin and player.online_time < 60 then + script.raise_event(defines.events.on_gui_click,{ + name=defines.events.on_gui_click, + tick=event.tick, + element=mod_gui.get_button_flow(player)['server-info'], + player_index=player.index, + button=defines.mouse_button_type.left, + alt=false, + control=false, + shift=false + }) + end end) return Sync \ No newline at end of file diff --git a/control.lua b/control.lua index 3fa53e8b..71954015 100644 --- a/control.lua +++ b/control.lua @@ -48,6 +48,7 @@ Ranking, Sync, Server, Gui = require('/ExpCore/load'){'Ranking','Sync','Server', local success,err = pcall(require,'/ExpCore/GuiParts/test') if success then Gui.test = err end if Gui.popup then Gui.popup._load() end +if Sync._load then Sync._load() end -- this loads the ranks that Ranking uses require('/ExpCore/ranks') -- this loads any edits that are not need in core pcall as file may not be preset