2018-05-23 13:16:01 +02:00
|
|
|
local Gui = require 'utils.gui'
|
2018-11-26 03:07:03 +02:00
|
|
|
local Utils = require 'utils.core'
|
2018-11-20 12:46:32 +02:00
|
|
|
local Game = require 'utils.game'
|
2019-01-25 18:18:02 +02:00
|
|
|
local Command = require 'utils.command'
|
2019-01-30 05:52:43 +02:00
|
|
|
local Ranks = require 'resources.ranks'
|
2018-05-23 13:16:01 +02:00
|
|
|
|
|
|
|
local close_name = Gui.uid_name()
|
|
|
|
|
2019-01-25 18:05:12 +02:00
|
|
|
local icons = {
|
2019-01-25 20:31:21 +02:00
|
|
|
"utility/ammo_icon", -- 1
|
|
|
|
"utility/danger_icon", -- 2
|
|
|
|
"utility/destroyed_icon", -- 3
|
|
|
|
"utility/warning_icon", -- 4
|
|
|
|
"utility/electricity_icon", -- 5
|
|
|
|
"utility/electricity_icon_unplugged", -- 6
|
|
|
|
"utility/fluid_icon", -- 7
|
|
|
|
"utility/fuel_icon", -- 8
|
|
|
|
"utility/no_building_material_icon", -- 9
|
|
|
|
"utility/no_storage_space_icon", -- 10
|
|
|
|
"utility/not_enough_construction_robots_icon", -- 11
|
|
|
|
"utility/not_enough_repair_packs_icon", -- 12
|
|
|
|
"utility/recharge_icon", -- 13
|
|
|
|
"utility/too_far_from_roboport_icon" -- 14
|
2019-01-25 18:05:12 +02:00
|
|
|
}
|
|
|
|
|
2019-02-01 23:11:02 +02:00
|
|
|
local function show_popup(player, message, title_text, sprite_path, popup_name)
|
2019-01-25 18:05:12 +02:00
|
|
|
--Default title and icon
|
2019-01-31 01:05:53 +02:00
|
|
|
title_text = (title_text ~= nil) and title_text or 'NOTICE!'
|
2019-01-25 20:31:21 +02:00
|
|
|
if type(sprite_path) == 'number' then
|
|
|
|
sprite_path = (sprite_path ~= nil) and icons[sprite_path] or icons[4]
|
|
|
|
else
|
|
|
|
sprite_path = (sprite_path ~= nil) and sprite_path or icons[4]
|
|
|
|
end
|
2019-02-01 23:11:02 +02:00
|
|
|
|
|
|
|
local frame
|
|
|
|
if popup_name ~= nil then
|
|
|
|
local center = player.gui.center
|
|
|
|
local popup = center['Popup.' .. popup_name]
|
|
|
|
if (popup) then
|
|
|
|
Gui.destroy(popup)
|
|
|
|
end
|
|
|
|
frame = player.gui.center.add {name = 'Popup.' .. popup_name, type = 'frame', direction = 'vertical', style = 'captionless_frame'}
|
|
|
|
else
|
|
|
|
frame = player.gui.center.add {type = 'frame', direction = 'vertical', style = 'captionless_frame'}
|
|
|
|
end
|
|
|
|
|
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'}
|
2019-02-27 16:49:57 +02:00
|
|
|
top_flow.style.horizontal_align = 'center'
|
|
|
|
top_flow.style.horizontally_stretchable = true
|
2018-05-23 13:16:01 +02:00
|
|
|
|
2018-06-04 21:46:52 +02:00
|
|
|
local title_flow = top_flow.add {type = 'flow'}
|
2019-02-26 19:36:20 +02:00
|
|
|
title_flow.style.horizontal_align = 'center'
|
2018-06-04 21:46:52 +02:00
|
|
|
title_flow.style.left_padding = 32
|
|
|
|
title_flow.style.top_padding = 8
|
2019-02-27 16:49:57 +02:00
|
|
|
title_flow.style.horizontally_stretchable = false
|
2018-05-23 13:16:01 +02:00
|
|
|
|
2019-01-31 01:15:09 +02:00
|
|
|
local title = title_flow.add {type = 'label', caption = title_text}
|
2018-05-23 13:16:01 +02:00
|
|
|
title.style.font = 'default-large-bold'
|
|
|
|
|
2018-06-04 21:46:52 +02:00
|
|
|
local close_button_flow = top_flow.add {type = 'flow'}
|
2019-02-26 19:36:20 +02:00
|
|
|
close_button_flow.style.horizontal_align = 'right'
|
2018-06-04 21:46:52 +02:00
|
|
|
|
|
|
|
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
|
2019-02-27 16:49:57 +02:00
|
|
|
content_flow.style.horizontally_stretchable = false
|
2018-06-04 21:46:52 +02:00
|
|
|
|
|
|
|
local sprite_flow = content_flow.add {type = 'flow'}
|
|
|
|
sprite_flow.style.vertical_align = 'center'
|
2019-02-27 16:49:57 +02:00
|
|
|
sprite_flow.style.vertically_stretchable = false
|
2018-05-23 13:16:51 +02:00
|
|
|
|
2019-01-25 20:31:21 +02:00
|
|
|
sprite_flow.add {type = 'sprite', sprite = sprite_path}
|
2018-06-04 21:46:52 +02:00
|
|
|
|
|
|
|
local label_flow = content_flow.add {type = 'flow'}
|
2019-02-26 19:36:20 +02:00
|
|
|
label_flow.style.horizontal_align = 'left'
|
2018-06-04 21:46:52 +02:00
|
|
|
label_flow.style.top_padding = 10
|
|
|
|
label_flow.style.left_padding = 24
|
|
|
|
|
2019-02-27 16:49:57 +02:00
|
|
|
label_flow.style.horizontally_stretchable = false
|
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'}
|
2019-02-27 18:03:56 +02:00
|
|
|
ok_button_flow.style.horizontally_stretchable = true
|
2019-02-26 19:36:20 +02:00
|
|
|
ok_button_flow.style.horizontal_align = 'center'
|
2018-05-23 13:16:01 +02:00
|
|
|
|
|
|
|
local ok_button = ok_button_flow.add {type = 'button', name = close_name, caption = 'OK'}
|
|
|
|
Gui.set_data(ok_button, frame)
|
|
|
|
end
|
|
|
|
|
|
|
|
Gui.on_click(
|
2019-01-25 18:18:02 +02:00
|
|
|
close_name,
|
|
|
|
function(event)
|
|
|
|
local frame = Gui.get_data(event.element)
|
2018-05-23 13:16:01 +02:00
|
|
|
|
2019-01-25 18:18:02 +02:00
|
|
|
Gui.remove_data_recursively(frame)
|
|
|
|
frame.destroy()
|
|
|
|
end
|
2018-05-23 13:16:01 +02:00
|
|
|
)
|
|
|
|
|
2018-11-18 13:59:52 +02:00
|
|
|
-- Creates a popup dialog for all players
|
2019-01-25 18:18:02 +02:00
|
|
|
local function popup(args)
|
|
|
|
local message = args.message:gsub('\\n', '\n')
|
2018-05-23 13:16:01 +02:00
|
|
|
|
|
|
|
for _, p in ipairs(game.connected_players) do
|
|
|
|
show_popup(p, message)
|
|
|
|
end
|
2018-11-18 13:59:52 +02:00
|
|
|
|
2018-11-23 19:07:44 +02:00
|
|
|
Game.player_print('Popup sent')
|
2019-01-25 18:18:02 +02:00
|
|
|
Utils.print_admins(Utils.get_actor() .. ' sent a popup to all players', nil)
|
2018-05-23 13:16:01 +02:00
|
|
|
end
|
|
|
|
|
2018-11-18 13:59:52 +02:00
|
|
|
-- Creates a popup dialog for all players, specifically for the server upgrading factorio versions
|
2019-01-25 18:18:02 +02:00
|
|
|
local function popup_update(args)
|
|
|
|
local message = 'Server is updating to ' .. args.version .. '\nWe will be back in a minute'
|
2018-05-23 13:16:01 +02:00
|
|
|
|
|
|
|
for _, p in ipairs(game.connected_players) do
|
2019-01-25 18:05:12 +02:00
|
|
|
show_popup(p, message, "Incoming update!", 11)
|
2018-05-23 13:16:01 +02:00
|
|
|
end
|
2018-11-18 13:59:52 +02:00
|
|
|
|
2018-11-23 19:07:44 +02:00
|
|
|
Game.player_print('Popup sent')
|
2019-01-25 18:18:02 +02:00
|
|
|
Utils.print_admins(Utils.get_actor() .. ' sent a popup to all players', nil)
|
2018-05-23 13:16:01 +02:00
|
|
|
end
|
|
|
|
|
2018-11-18 13:59:52 +02:00
|
|
|
-- Creates a popup dialog for the specifically targetted player
|
2019-01-25 18:18:02 +02:00
|
|
|
local function popup_player(args)
|
|
|
|
local target_name = args.player
|
2018-10-08 00:22:03 +02:00
|
|
|
local target = game.players[target_name]
|
|
|
|
if not target then
|
2018-11-06 13:55:52 +02:00
|
|
|
Game.player_print('Player ' .. target_name .. ' not found.')
|
2018-10-08 00:22:03 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2019-01-25 18:18:02 +02:00
|
|
|
local message = args.message:gsub('\\n', '\n')
|
2018-10-08 00:22:03 +02:00
|
|
|
|
|
|
|
show_popup(target, message)
|
2018-11-23 19:07:44 +02:00
|
|
|
Game.player_print('Popup sent')
|
2018-10-08 00:22:03 +02:00
|
|
|
end
|
|
|
|
|
2019-01-25 18:18:02 +02:00
|
|
|
Command.add(
|
2019-01-02 17:34:17 +02:00
|
|
|
'popup',
|
|
|
|
{
|
2019-03-04 00:13:56 +02:00
|
|
|
description = {'command_description.popup'},
|
2019-01-02 17:34:17 +02:00
|
|
|
arguments = {'message'},
|
2019-01-30 05:52:43 +02:00
|
|
|
required_rank = Ranks.admin,
|
2019-01-02 17:34:17 +02:00
|
|
|
capture_excess_arguments = true,
|
|
|
|
allowed_by_server = true
|
|
|
|
},
|
|
|
|
popup
|
2019-01-25 18:18:02 +02:00
|
|
|
)
|
2018-10-08 00:22:03 +02:00
|
|
|
|
2019-01-25 18:18:02 +02:00
|
|
|
Command.add(
|
2018-05-23 13:16:01 +02:00
|
|
|
'popup-update',
|
2019-01-02 17:34:17 +02:00
|
|
|
{
|
2019-03-04 00:13:56 +02:00
|
|
|
description = {'command_description.popup_update'},
|
2019-01-02 17:34:17 +02:00
|
|
|
arguments = {'version'},
|
2019-01-30 05:52:43 +02:00
|
|
|
required_rank = Ranks.admin,
|
2019-01-02 17:34:17 +02:00
|
|
|
capture_excess_arguments = true,
|
|
|
|
allowed_by_server = true
|
|
|
|
},
|
2018-05-23 13:16:01 +02:00
|
|
|
popup_update
|
|
|
|
)
|
2018-10-08 00:22:03 +02:00
|
|
|
|
2019-01-25 18:18:02 +02:00
|
|
|
Command.add(
|
2019-01-02 17:34:17 +02:00
|
|
|
'popup-player',
|
|
|
|
{
|
2019-03-04 00:13:56 +02:00
|
|
|
description = {'command_description.popup_player'},
|
2019-01-02 17:34:17 +02:00
|
|
|
arguments = {'player', 'message'},
|
2019-01-30 05:52:43 +02:00
|
|
|
required_rank = Ranks.admin,
|
2019-01-02 17:34:17 +02:00
|
|
|
capture_excess_arguments = true,
|
|
|
|
allowed_by_server = true
|
|
|
|
},
|
|
|
|
popup_player
|
2019-01-25 18:18:02 +02:00
|
|
|
)
|
2018-10-08 00:22:03 +02:00
|
|
|
|
|
|
|
local Public = {}
|
|
|
|
|
|
|
|
--[[--
|
|
|
|
Shows a popup dialog.
|
|
|
|
|
|
|
|
@param player LuaPlayer
|
|
|
|
@param message string
|
2019-02-01 23:11:02 +02:00
|
|
|
@param title string
|
|
|
|
@param sprite_path string, see format in icons table
|
|
|
|
@param popup_name string, assign to have a popup only exist once.
|
2018-10-08 00:22:03 +02:00
|
|
|
]]
|
2019-02-01 23:11:02 +02:00
|
|
|
function Public.player(player, message, title, sprite_path, popup_name)
|
|
|
|
show_popup(player, message, title, sprite_path, popup_name)
|
2019-01-25 18:18:02 +02:00
|
|
|
end
|
2018-10-08 00:22:03 +02:00
|
|
|
|
|
|
|
--[[--
|
|
|
|
Shows a popup dialog to all connected players.
|
|
|
|
|
|
|
|
@param message string
|
2019-02-01 23:11:02 +02:00
|
|
|
@param title string
|
|
|
|
@param sprite_path string, see format in icons table
|
|
|
|
@param popup_name string, assign to have a popup only exist once.
|
2018-10-08 00:22:03 +02:00
|
|
|
]]
|
2019-02-01 23:11:02 +02:00
|
|
|
function Public.all_online(message, title, sprite_path, popup_name)
|
2018-10-08 00:22:03 +02:00
|
|
|
for _, p in ipairs(game.connected_players) do
|
2019-02-01 23:11:02 +02:00
|
|
|
show_popup(p, message, title, sprite_path, popup_name)
|
2018-10-08 00:22:03 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
--[[--
|
|
|
|
Shows a popup dialog to all players.
|
|
|
|
|
|
|
|
@param message string
|
2019-02-01 23:11:02 +02:00
|
|
|
@param title string
|
|
|
|
@param sprite_path string, see format in icons table
|
|
|
|
@param popup_name string, assign to have a popup only exist once.
|
2018-10-08 00:22:03 +02:00
|
|
|
]]
|
2019-02-01 23:11:02 +02:00
|
|
|
function Public.all(message, title, sprite_path, popup_name)
|
2018-10-08 00:22:03 +02:00
|
|
|
for _, p in pairs(game.players) do
|
2019-02-01 23:11:02 +02:00
|
|
|
show_popup(p, message, title, sprite_path, popup_name)
|
2018-10-08 00:22:03 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return Public
|