1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-10 00:43:27 +02:00
ComfyFactorio/modules/map_info.lua

111 lines
3.1 KiB
Lua
Raw Normal View History

2020-12-14 20:36:37 +02:00
local Event = require 'utils.event'
2019-10-28 18:38:36 +02:00
local Global = require 'utils.global'
2022-04-05 19:28:08 +02:00
local Gui = require 'utils.gui'
local Token = require 'utils.token'
2022-04-05 19:28:08 +02:00
local module_name = Gui.uid_name()
2019-10-28 18:38:36 +02:00
local map_info = {
2020-07-07 23:42:44 +02:00
localised_category = false,
2020-07-14 21:50:56 +02:00
main_caption = nil,
2020-07-07 23:42:44 +02:00
main_caption_color = {r = 0.6, g = 0.3, b = 0.99},
2020-07-14 21:50:56 +02:00
sub_caption = nil,
2020-07-07 23:42:44 +02:00
sub_caption_color = {r = 0.2, g = 0.9, b = 0.2},
2020-07-14 21:50:56 +02:00
text = nil
2019-10-28 18:38:36 +02:00
}
Global.register(
2020-07-07 23:42:44 +02:00
map_info,
function(tbl)
map_info = tbl
end
2019-10-28 18:38:36 +02:00
)
local Public = {}
function Public.Pop_info()
2020-07-07 23:42:44 +02:00
return map_info
2019-10-28 18:38:36 +02:00
end
local function create_map_intro(data)
local frame = data.frame
2020-07-07 23:42:44 +02:00
frame.clear()
frame.style.padding = 4
frame.style.margin = 0
local t = frame.add {type = 'table', column_count = 1}
local line = t.add {type = 'line'}
line.style.top_margin = 4
line.style.bottom_margin = 4
2020-07-14 21:50:56 +02:00
local caption = map_info.main_caption or {map_info.localised_category .. '.map_info_main_caption'}
local sub_caption = map_info.sub_caption or {map_info.localised_category .. '.map_info_sub_caption'}
local text = map_info.text or {map_info.localised_category .. '.map_info_text'}
2020-07-07 23:42:44 +02:00
if map_info.localised_category then
2020-07-14 21:50:56 +02:00
map_info.main_caption = caption
map_info.sub_caption = sub_caption
map_info.text = text
2020-07-07 23:42:44 +02:00
end
local l = t.add {type = 'label', caption = map_info.main_caption}
l.style.font = 'heading-1'
l.style.font_color = map_info.main_caption_color
l.style.minimal_width = 780
l.style.horizontal_align = 'center'
l.style.vertical_align = 'center'
local l_2 = t.add {type = 'label', caption = map_info.sub_caption}
l_2.style.font = 'heading-2'
l_2.style.font_color = map_info.sub_caption_color
l_2.style.minimal_width = 780
l_2.style.horizontal_align = 'center'
l_2.style.vertical_align = 'center'
local line_2 = t.add {type = 'line'}
line_2.style.top_margin = 4
line_2.style.bottom_margin = 4
local scroll_pane =
frame.add {
type = 'scroll-pane',
name = 'scroll_pane',
direction = 'vertical',
horizontal_scroll_policy = 'never',
vertical_scroll_policy = 'auto'
}
scroll_pane.style.maximal_height = 320
scroll_pane.style.minimal_height = 320
local l_3 = scroll_pane.add {type = 'label', caption = map_info.text}
l_3.style.font = 'heading-2'
l_3.style.single_line = false
l_3.style.font_color = {r = 0.85, g = 0.85, b = 0.88}
l_3.style.minimal_width = 780
l_3.style.horizontal_align = 'center'
l_3.style.vertical_align = 'center'
end
local create_map_intro_token = Token.register(create_map_intro)
2019-10-05 18:29:19 +02:00
2019-10-28 18:38:36 +02:00
local function on_player_joined_game(event)
2020-07-07 23:42:44 +02:00
local player = game.players[event.player_index]
if player.online_time == 0 then
2022-04-05 19:28:08 +02:00
Gui.call_existing_tab(player, 'Map Info')
2020-07-07 23:42:44 +02:00
end
2019-10-05 18:29:19 +02:00
end
2022-04-05 19:28:08 +02:00
Gui.add_tab_to_gui({name = module_name, caption = 'Map Info', id = create_map_intro_token, admin = false})
2022-02-14 00:32:57 +02:00
2022-04-05 19:28:08 +02:00
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
2022-02-14 00:32:57 +02:00
2022-04-05 19:28:08 +02:00
Gui.on_click(
module_name,
function(event)
local player = event.player
Gui.reload_active_tab(player)
2020-07-07 23:42:44 +02:00
end
2022-04-05 19:28:08 +02:00
)
2019-10-28 18:38:36 +02:00
2020-07-07 23:42:44 +02:00
return Public