mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-30 20:41:41 +09:00
Added Left Gui
This commit is contained in:
111
ExpCore/GuiParts/popup.lua
Normal file
111
ExpCore/GuiParts/popup.lua
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
--[[
|
||||||
|
Explosive Gaming
|
||||||
|
|
||||||
|
This file can be used with permission but this and the credit below must remain in the file.
|
||||||
|
Contact a member of management on our discord to seek permission to use our code.
|
||||||
|
Any changes that you may make to the code are yours but that does not make the script yours.
|
||||||
|
Discord: https://discord.gg/r6dC2uK
|
||||||
|
]]
|
||||||
|
|
||||||
|
local popup = {}
|
||||||
|
popup._popup = {}
|
||||||
|
|
||||||
|
function popup._load()
|
||||||
|
popup._popup.close = Gui.inputs.add{
|
||||||
|
type='button',
|
||||||
|
name='popup-close',
|
||||||
|
caption='utility/set_bar_slot',
|
||||||
|
tooltip='Close This Popup'
|
||||||
|
}:on_event('click',function(event)
|
||||||
|
local frame = event.element.parent
|
||||||
|
if frame and frame.valid then frame.destroy() end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Used to add a popup gui style
|
||||||
|
-- @usage Gui.left.add{name='foo',caption='Foo',draw=function}
|
||||||
|
-- @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
|
||||||
|
function popup.add(obj)
|
||||||
|
if not is_type(obj,'table') then return end
|
||||||
|
if not is_type(obj.name,'string') then return end
|
||||||
|
setmetatable(obj,{__index=popup._popup})
|
||||||
|
local name = obj.name; obj.name = nil
|
||||||
|
Gui._add_data('popup',name,obj)
|
||||||
|
obj.name = name
|
||||||
|
return obj
|
||||||
|
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'}
|
||||||
|
return flow
|
||||||
|
end
|
||||||
|
|
||||||
|
--- Use to open a popup for these players
|
||||||
|
-- @usage Gui.popup.open('ban',nil,{player=1,reason='foo'})
|
||||||
|
-- @tparam string style this is the name you gave to the popup when added
|
||||||
|
-- @param data this is the data that is sent to the draw function
|
||||||
|
-- @tparam[opt=game.connected_players] table players the players to open the popup for
|
||||||
|
function popup.open(style,data,players)
|
||||||
|
local _popup = Gui._get_data('popup')[style]
|
||||||
|
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
|
||||||
|
local flow = popup.flow(player)
|
||||||
|
local _frame = flow.add{
|
||||||
|
type='frame',
|
||||||
|
direction='horizontal',
|
||||||
|
style=mod_gui.frame_style
|
||||||
|
}
|
||||||
|
local frame = _frame.add{
|
||||||
|
type='frame',
|
||||||
|
name='inner_frame',
|
||||||
|
direction='vertical',
|
||||||
|
style=mod_gui.frame_style
|
||||||
|
}
|
||||||
|
_popup.close:draw(_frame)
|
||||||
|
if is_type(_popup.draw,'function') then
|
||||||
|
local success, err = pcall(_popup.draw,frame,data)
|
||||||
|
if not success then error(err) end
|
||||||
|
else error('No Draw On Popup '.._popup.name) end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
Server.new_thread{
|
||||||
|
data={players=players,popup=_popup,data=data}
|
||||||
|
}:on_event('tick',function(thread)
|
||||||
|
if #thread.data.players == 0 then thread:close() return end
|
||||||
|
local player = table.remove(thread.data.players,1)
|
||||||
|
local flow = popup.flow(player)
|
||||||
|
local _frame = flow.add{
|
||||||
|
type='frame',
|
||||||
|
direction='horizontal',
|
||||||
|
style=mod_gui.frame_style
|
||||||
|
}
|
||||||
|
local frame = _frame.add{
|
||||||
|
type='frame',
|
||||||
|
name='inner_frame',
|
||||||
|
direction='vertical',
|
||||||
|
style=mod_gui.frame_style
|
||||||
|
}
|
||||||
|
thread.data.popup.close:draw(_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
|
||||||
|
else error('No Draw On Popup '..thread.data.popup.name) end
|
||||||
|
end):open()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function popup._popup:add_left(obj)
|
||||||
|
obj.name = obj.name or self.name
|
||||||
|
self.left = Gui.left.add(obj)
|
||||||
|
end
|
||||||
|
|
||||||
|
Event.register(defines.events.on_player_joined_game,popup.flow)
|
||||||
|
|
||||||
|
return popup
|
||||||
@@ -93,7 +93,7 @@ end)
|
|||||||
local function test_gui(event)
|
local function test_gui(event)
|
||||||
if not game.player and not event.player_index then return end
|
if not game.player and not event.player_index then return end
|
||||||
local player = game.player or Game.get_player(event)
|
local player = game.player or Game.get_player(event)
|
||||||
if player.gui.top['gui-test'] then player.gui.top['gui-test'].destroy() end
|
if mod_gui.get_frame_flow(player)['gui-test'] thenmod_gui.get_frame_flow(player)['gui-test'].destroy() end
|
||||||
local frame = mod_gui.get_frame_flow(player).add{type='frame',name='gui-test',direction='vertical'}
|
local frame = mod_gui.get_frame_flow(player).add{type='frame',name='gui-test',direction='vertical'}
|
||||||
gui_tset_close:draw(frame)
|
gui_tset_close:draw(frame)
|
||||||
caption_test:draw(frame)
|
caption_test:draw(frame)
|
||||||
@@ -137,6 +137,34 @@ Gui.left.add{
|
|||||||
can_open=function(player) return player.index == 1 or global.open_test_on_all_left_guis end
|
can_open=function(player) return player.index == 1 or global.open_test_on_all_left_guis end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local text_popup = Gui.inputs.add_text('test-popup-text',true,'Message To Send',function(player,text,element)
|
||||||
|
element.text = text
|
||||||
|
end)
|
||||||
|
local send_popup = Gui.inputs.add{
|
||||||
|
type='button',
|
||||||
|
name='test-popup-send',
|
||||||
|
caption='Send Message'
|
||||||
|
}: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})
|
||||||
|
end)
|
||||||
|
Gui.popup.add{
|
||||||
|
name='test-popup',
|
||||||
|
caption='Gui Popup',
|
||||||
|
draw=function(frame,data)
|
||||||
|
frame.add{type='label',caption='Opened by: '..data.player}
|
||||||
|
frame.add{type='label',caption='Message: '..data.message}
|
||||||
|
end
|
||||||
|
}:add_left{
|
||||||
|
caption='Gui Left w/ Popup',
|
||||||
|
tooltip='Send a message',
|
||||||
|
draw=function(frame)
|
||||||
|
text_popup:draw(frame)
|
||||||
|
send_popup:draw(frame)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
|
||||||
return test_gui
|
return test_gui
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ StdExpCoreLib.Gui:_load_parts{
|
|||||||
'toolbar',
|
'toolbar',
|
||||||
'center',
|
'center',
|
||||||
'left',
|
'left',
|
||||||
--'popup'
|
'popup'
|
||||||
}
|
}
|
||||||
|
|
||||||
return function(rtn)
|
return function(rtn)
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ _G.discord_emit = nil -- un-comment this line if you are not using the json.data
|
|||||||
Ranking, Server, Gui = require('/ExpCore/load'){'Ranking','Server','Gui'}
|
Ranking, Server, Gui = require('/ExpCore/load'){'Ranking','Server','Gui'}
|
||||||
local success,err = pcall(require,'/ExpCore/GuiParts/test')
|
local success,err = pcall(require,'/ExpCore/GuiParts/test')
|
||||||
if success then Gui.test = err end
|
if success then Gui.test = err end
|
||||||
|
if Gui.popup then Gui.popup._load() end
|
||||||
-- this loads the ranks that Ranking uses
|
-- this loads the ranks that Ranking uses
|
||||||
require('/ExpCore/ranks')
|
require('/ExpCore/ranks')
|
||||||
-- this loads any edits that are not need in core pcall as file may not be preset
|
-- this loads any edits that are not need in core pcall as file may not be preset
|
||||||
|
|||||||
Reference in New Issue
Block a user