2018-05-23 13:16:01 +02:00
|
|
|
local Gui = require 'utils.gui'
|
|
|
|
|
|
|
|
local close_name = Gui.uid_name()
|
|
|
|
|
|
|
|
local function show_popup(player, message)
|
2018-06-04 21:46:52 +02:00
|
|
|
local frame = player.gui.center.add {type = 'frame', direction = 'vertical', style = 'captionless_frame'}
|
2018-05-25 13:18:19 +02:00
|
|
|
frame.style.minimal_width = 300
|
2018-05-23 13:16:01 +02:00
|
|
|
|
2018-06-04 21:46:52 +02:00
|
|
|
local top_flow = frame.add {type = 'flow', direction = 'horizontal'}
|
2018-05-23 13:16:01 +02:00
|
|
|
|
2018-06-04 21:46:52 +02:00
|
|
|
local title_flow = top_flow.add {type = 'flow'}
|
2018-05-23 13:16:01 +02:00
|
|
|
title_flow.style.align = 'center'
|
2018-06-04 21:46:52 +02:00
|
|
|
title_flow.style.left_padding = 32
|
|
|
|
title_flow.style.top_padding = 8
|
2018-05-23 13:16:01 +02:00
|
|
|
title_flow.style.horizontally_stretchable = true
|
|
|
|
|
|
|
|
local title = title_flow.add {type = 'label', caption = 'Attention!'}
|
|
|
|
title.style.font = 'default-large-bold'
|
|
|
|
|
2018-06-04 21:46:52 +02:00
|
|
|
local close_button_flow = top_flow.add {type = 'flow'}
|
|
|
|
close_button_flow.style.align = 'right'
|
|
|
|
|
|
|
|
local close_button = close_button_flow.add {type = 'button', name = close_name, caption = 'X'}
|
|
|
|
Gui.set_data(close_button, frame)
|
|
|
|
|
|
|
|
local content_flow = frame.add {type = 'flow', direction = 'horizontal'}
|
|
|
|
content_flow.style.top_padding = 16
|
|
|
|
content_flow.style.bottom_padding = 16
|
|
|
|
content_flow.style.left_padding = 24
|
|
|
|
content_flow.style.right_padding = 24
|
|
|
|
content_flow.style.horizontally_stretchable = true
|
|
|
|
|
|
|
|
local sprite_flow = content_flow.add {type = 'flow'}
|
|
|
|
sprite_flow.style.vertical_align = 'center'
|
|
|
|
sprite_flow.style.vertically_stretchable = true
|
2018-05-23 13:16:51 +02:00
|
|
|
|
2018-06-04 21:46:52 +02:00
|
|
|
sprite_flow.add {type = 'sprite', sprite = 'utility/warning_icon'}
|
|
|
|
|
|
|
|
local label_flow = content_flow.add {type = 'flow'}
|
|
|
|
label_flow.style.align = 'left'
|
|
|
|
label_flow.style.top_padding = 10
|
|
|
|
label_flow.style.left_padding = 24
|
|
|
|
|
|
|
|
label_flow.style.horizontally_stretchable = true
|
2018-05-23 13:16:01 +02:00
|
|
|
local label = label_flow.add {type = 'label', caption = message}
|
|
|
|
label.style.single_line = false
|
|
|
|
label.style.font = 'default-large-bold'
|
|
|
|
|
|
|
|
local ok_button_flow = frame.add {type = 'flow'}
|
|
|
|
ok_button_flow.style.horizontally_stretchable = true
|
|
|
|
ok_button_flow.style.align = 'center'
|
|
|
|
|
|
|
|
local ok_button = ok_button_flow.add {type = 'button', name = close_name, caption = 'OK'}
|
|
|
|
Gui.set_data(ok_button, frame)
|
|
|
|
end
|
|
|
|
|
|
|
|
Gui.on_click(
|
|
|
|
close_name,
|
|
|
|
function(event)
|
|
|
|
local frame = Gui.get_data(event.element)
|
|
|
|
|
|
|
|
Gui.remove_data_recursivly(frame)
|
|
|
|
frame.destroy()
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
|
|
|
local function popup(cmd)
|
2018-06-07 22:06:48 +02:00
|
|
|
local player = game.player
|
2018-05-23 13:16:01 +02:00
|
|
|
if player and not player.admin then
|
2018-06-07 22:06:48 +02:00
|
|
|
cant_run(cmd.name)
|
2018-05-23 13:16:01 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local message = cmd.parameter:gsub('\\n', '\n')
|
|
|
|
|
|
|
|
for _, p in ipairs(game.connected_players) do
|
|
|
|
show_popup(p, message)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function popup_update(cmd)
|
2018-06-07 22:06:48 +02:00
|
|
|
local player = game.player
|
2018-05-23 13:16:01 +02:00
|
|
|
if player and not player.admin then
|
2018-06-07 22:06:48 +02:00
|
|
|
cant_run(cmd.name)
|
2018-05-23 13:16:01 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2018-05-25 22:21:32 +02:00
|
|
|
local message = '\nServer updating to ' .. cmd.parameter .. ', back in one minute.'
|
2018-05-23 13:16:01 +02:00
|
|
|
|
|
|
|
for _, p in ipairs(game.connected_players) do
|
|
|
|
show_popup(p, message)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
commands.add_command('popup', '<message> - Shows a popup to all connected players (Admins only)', popup)
|
|
|
|
commands.add_command(
|
|
|
|
'popup-update',
|
|
|
|
'<version> - Shows an update popup to all connected players (Admins only)',
|
|
|
|
popup_update
|
|
|
|
)
|