Gui Looks Nice

This commit is contained in:
Cooldude2606
2018-04-08 13:29:46 +01:00
parent bab8a8042d
commit 5b10126c44
3 changed files with 52 additions and 35 deletions

View File

@@ -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 = {}

View File

@@ -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

View File

@@ -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