1
0
mirror of https://github.com/Refactorio/RedMew.git synced 2025-01-18 03:21:47 +02:00

Extra features for popup gui

Added 13 new icons to the popup gui
Added the ability to change title

Updated popup-update commands wording, title and icon.
This commit is contained in:
SimonFlapse 2019-01-25 17:05:12 +01:00
parent 8204f280f6
commit c40412d871

View File

@ -4,7 +4,28 @@ local Game = require 'utils.game'
local close_name = Gui.uid_name()
local function show_popup(player, message)
local icons = {
"ammo_icon", -- 1
"danger_icon", -- 2
"destroyed_icon", -- 3
"warning_icon", -- 4
"electricity_icon", -- 5
"electricity_icon_unplugged", -- 6
"fluid_icon", -- 7
"fuel_icon", -- 8
"no_building_material_icon", -- 9
"no_storage_space_icon", -- 10
"not_enough_construction_robots_icon", -- 11
"not_enough_repair_packs_icon", -- 12
"recharge_icon", -- 13
"too_far_from_roboport_icon" -- 14
}
local function show_popup(player, message, title, icon_id)
--Default title and icon
local title = (title ~= nil) and title or 'NOTICE!'
local icon_id = (icon_id ~= nil) and icon_id or 4
local frame = player.gui.center.add {type = 'frame', direction = 'vertical', style = 'captionless_frame'}
frame.style.minimal_width = 300
@ -16,15 +37,12 @@ local function show_popup(player, message)
title_flow.style.top_padding = 8
title_flow.style.horizontally_stretchable = true
local title = title_flow.add {type = 'label', caption = 'Attention!'}
local title = title_flow.add {type = 'label', caption = title}
title.style.font = 'default-large-bold'
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
@ -36,7 +54,7 @@ local function show_popup(player, message)
sprite_flow.style.vertical_align = 'center'
sprite_flow.style.vertically_stretchable = true
sprite_flow.add {type = 'sprite', sprite = 'utility/warning_icon'}
sprite_flow.add {type = 'sprite', sprite = 'utility/'..icons[icon_id]}
local label_flow = content_flow.add {type = 'flow'}
label_flow.style.align = 'left'
@ -98,10 +116,14 @@ local function popup_update(cmd)
return
end
local message = '\nServer updating to ' .. cmd.parameter .. ', back in one minute.'
if not cmd.parameter then
Game.player_print('Usage: /popup-update <factorio_version>')
return
end
local message = 'Server is updating to ' .. cmd.parameter .. '\nWe will be back in a minute'
for _, p in ipairs(game.connected_players) do
show_popup(p, message)
show_popup(p, message, "Incoming update!", 11)
end
Game.player_print('Popup sent')
@ -160,18 +182,18 @@ local Public = {}
@param player LuaPlayer
@param message string
]]
function Public.player(player, message)
show_popup(player, message)
end
function Public.player(player, message, title, icon_id)
show_popup(player, message, title, icon_id)
end
--[[--
Shows a popup dialog to all connected players.
@param message string
]]
function Public.all_online(message)
function Public.all_online(message, title, icon_id)
for _, p in ipairs(game.connected_players) do
show_popup(p, message)
show_popup(p, message, title, icon_id)
end
end
@ -180,9 +202,9 @@ end
@param message string
]]
function Public.all(message)
function Public.all(message, title, icon_id)
for _, p in pairs(game.players) do
show_popup(p, message)
show_popup(p, message, title, icon_id)
end
end