mirror of
https://github.com/PHIDIAS0303/ExpCluster.git
synced 2025-12-27 11:35:22 +09:00
Add the toolbar manager
This commit is contained in:
@@ -18,6 +18,7 @@ local credits = {{
|
||||
}}
|
||||
local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end
|
||||
--Please Only Edit Below This Line-----------------------------------------------------------
|
||||
require("mod-gui")
|
||||
credit_loop(require("locale/StdLib/event"))
|
||||
credit_loop(require("locale/file-header"))
|
||||
|
||||
|
||||
@@ -60,6 +60,7 @@ function give_rank(player,rank,by_player)
|
||||
local by_player = by_player or 'system'
|
||||
local rank = string_to_rank(rank) or rank or string_to_rank('Guest')
|
||||
local old_rank = get_rank(player)
|
||||
--messaging
|
||||
local message = 'demoted'
|
||||
if rank.power <= old_rank.power then message = 'promoted' end
|
||||
if by_player.name then
|
||||
@@ -67,8 +68,11 @@ function give_rank(player,rank,by_player)
|
||||
else
|
||||
rank_print(player.name..' was '..message..' to '..rank.name..' by <system>','Guest')
|
||||
end
|
||||
player.print('You Have Been Given The '..rank.name..' Rank!')
|
||||
--if for some reason the tag is diffrent to the deafult
|
||||
if player.tag ~= old_rank.tag then player.print('Your Tag Was Reset Due To A Rank Change') end
|
||||
--rank change
|
||||
player.permission_group = game.permissions.get_group(rank.name)
|
||||
if player.tag:find('-') then player.print('Your Custom Tag Was Reset Due To A Rank Change') end
|
||||
player.tag = get_rank(player).tag
|
||||
if old_rank.name ~= 'Jail' then global.old_ranks[player.index]=old_rank.name end
|
||||
script.raise_event(Event.rank_change, {player=player, by_player=by_player, new_rank=rank, old_rank=old_rank})
|
||||
|
||||
@@ -12,7 +12,7 @@ local credits = {{
|
||||
name='Gui Input Handler',
|
||||
owner='Explosive Gaming',
|
||||
dev='Cooldude2606',
|
||||
description='Just A File Header To Organise Code',
|
||||
description='Handles all gui inputs',
|
||||
factorio_version='0.15.23',
|
||||
show=false
|
||||
}}
|
||||
@@ -22,17 +22,21 @@ local add_input = ExpGui.add_input
|
||||
local inputs = ExpGui.inputs
|
||||
--allows defining of new buttons;;name how to call button;;default_display what is showen on the button;;default_tooltip the tooltip display;;event function(player,element) that runs on click
|
||||
function add_input.button(name,default_display,default_tooltip,event)
|
||||
if not name then error('Button requires a name') end
|
||||
table.insert(inputs.buttons,{name,default_display,default_tooltip,event})
|
||||
end
|
||||
--allows defining of text box inputs;;name how to call button;;default_display what is showen on the button;;event function(player,element) that runs on text change
|
||||
function add_input.text(name,default_display,event)
|
||||
if not name then error('Text Filed requires a name') end
|
||||
table.insert(inputs.text,{name,default_display,event})
|
||||
end
|
||||
--draws the button into a gui;;frame the frame to draw to;;name name of button to draw;;display(opptinal) overides the default;;tooltip(opptinal) overides the default
|
||||
function add_input.draw_button(frame,name,display,tooltip)
|
||||
if not frame or not frame.valid then error('No frame to draw to') end
|
||||
if not name then error('No button to draw') end
|
||||
for _,btn in pairs(inputs.buttons) do
|
||||
if btn[1] == name then
|
||||
local display = display or btn[2]
|
||||
local display = display or btn[2] or btn[1]
|
||||
local tooltip = tooltip or btn[3]
|
||||
if frame.gui.is_valid_sprite_path(display) then
|
||||
frame.add{name=name, type = "sprite-button", sprite=display, tooltip=tooltip, style = mod_gui.button_style}
|
||||
@@ -43,10 +47,12 @@ function add_input.draw_button(frame,name,display,tooltip)
|
||||
end
|
||||
end
|
||||
--draws the text into a gui;;frame the frame to draw to;;name name of button to draw;;display(opptinal) overides the default;;tooltip(opptinal) overides the default
|
||||
function add_input.draw_button(frame,name,display)
|
||||
function add_input.draw_text(frame,name,display)
|
||||
if not frame or not frame.valid then error('No frame to draw to') end
|
||||
if not name then error('No text filed to draw') end
|
||||
for _,text in pairs(inputs.text) do
|
||||
if text[1] == name then
|
||||
local display = display or text[2]
|
||||
local display = display or text[2] or text[1]
|
||||
frame.add{name=name, type='textfield', text=display}
|
||||
break
|
||||
end
|
||||
|
||||
@@ -31,6 +31,7 @@ ExpGui = {
|
||||
--draw_text
|
||||
},
|
||||
toolbar={
|
||||
buttons={}
|
||||
--draw
|
||||
--add_button
|
||||
},
|
||||
|
||||
@@ -9,15 +9,36 @@ Discord: https://discord.gg/XSsBV6b
|
||||
The credit below may be used by another script do not remove.
|
||||
]]
|
||||
local credits = {{
|
||||
name='File Header - ExpGaming-Core-GUI',
|
||||
name='A Very Useful Toolbar',
|
||||
owner='Explosive Gaming',
|
||||
dev='Cooldude2606',
|
||||
description='Just A File Header To Organise Code',
|
||||
description='Some simple functions that help to control the toolbar',
|
||||
factorio_version='0.15.23',
|
||||
show=false
|
||||
}}
|
||||
local function credit_loop(reg) for _,cred in pairs(reg) do table.insert(credits,cred) end end
|
||||
--Please Only Edit Below This Line-----------------------------------------------------------
|
||||
|
||||
local toolbar = ExpGui.toolbar
|
||||
--similar to ExpGui.add_input.button but it also accepts a restriction and button is drawn to the toolbar
|
||||
function toolbar.add_button(name,default_display,default_tooltip,restriction,event)
|
||||
local restriction = restriction or 0
|
||||
if not name then error('Button requires a name') end
|
||||
table.insert(toolbar.buttons,{name,restriction})
|
||||
ExpGui.add_input.button(name,default_display,default_tooltip,event)
|
||||
end
|
||||
--draw the toolbar to the player only showing buttons within their restriction
|
||||
function toolbar.draw(player)
|
||||
if not player then error('Need a player to draw to') end
|
||||
local toolbar_frame = player.gui.top.toolbar or player.gui.top.add{name='toolbar',type='flow'}
|
||||
toolbar_frame.clear()
|
||||
for _,btn in pairs(toolbar.buttons) do
|
||||
local rank = get_rank(player)
|
||||
if btn[2] >= rank.power then
|
||||
ExpGui.add_input.draw_button(toolbar_frame,btn[1])
|
||||
end
|
||||
end
|
||||
end
|
||||
--auto redraw toolbar after new rank is given
|
||||
Event.register(Event.rank_change,function(event) toolbar.draw(event.player) end)
|
||||
--Please Only Edit Above This Line-----------------------------------------------------------
|
||||
return credits
|
||||
Reference in New Issue
Block a user