1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-08 00:39:30 +02:00

Add changelog module to the panel

This commit is contained in:
Eric Anderson 2022-03-13 21:18:42 -07:00
parent c737a8a679
commit 87a9c5de43

125
modules/changelog.lua Normal file
View File

@ -0,0 +1,125 @@
local Event = require 'utils.event'
local Global = require 'utils.global'
local Tabs = require 'comfy_panel.main'
local SpamProtection = require 'utils.spam_protection'
local Token = require 'utils.token'
local module_name = 'Changelog'
local changelog = {
versions = {}
}
local Public = {}
function Public.SetVersions(versions)
for i = 1, #versions do
local v = versions[i]
if v.ver == nil or v.date == nil or v.desc == nil then
log('ERROR in changelog.SetVersions missing ver, date or desc from version#' .. i .. ' got:\n' .. serpent.line(v))
return
end
end
changelog.versions = versions
end
local function create_changelog(data)
local frame = data.frame
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
local scroll_pane =
frame.add {
type = 'scroll-pane',
name = 'scroll_pane',
direction = 'vertical',
horizontal_scroll_policy = 'never',
vertical_scroll_policy = 'auto'
}
for i = 1, #changelog.versions do
local v = changelog.versions[i]
local l = t.add {type = 'label', caption = 'Version ' .. v.ver .. ' -- ' .. v.date}
l.style.font = 'heading-1'
l.style.font_color = {r = 0.2, g = 0.9, b = 0.2}
l.style.minimal_width = 780
l.style.horizontal_align = 'center'
l.style.vertical_align = 'center'
local c = t.add {type = 'label', caption = v.desc}
c.style.font = 'heading-2'
c.style.single_line = false
c.style.font_color = {r = 0.85, g = 0.85, b = 0.88}
c.style.minimal_width = 780
c.style.horizontal_align = 'left'
c.style.vertical_align = 'center'
local line_v = t.add {type = 'line'}
line_v.style.top_margin = 4
line_v.style.bottom_margin = 4
end
-- 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'
local b = frame.add {type = 'button', caption = 'CLOSE', name = 'close_changelog'}
b.style.font = 'heading-2'
b.style.padding = 2
b.style.top_margin = 3
b.style.left_margin = 333
b.style.horizontal_align = 'center'
b.style.vertical_align = 'center'
end
local create_changelog_token = Token.register(create_changelog)
local function on_gui_click(event)
if not event or not event.element or not event.element.valid then
return
end
local player = game.get_player(event.player_index)
if not (player and player.valid) then
return
end
local name = event.element.name
if not name then
return
end
if name == 'tab_' .. module_name then
if SpamProtection.is_spamming(player, nil, 'Changelog Main Button') then
return
end
end
if name == 'close_map_intro' then
if SpamProtection.is_spamming(player, nil, 'Changelog Close Button') then
return
end
player.gui.left.comfy_panel.destroy()
return
end
end
Tabs.add_tab_to_gui({name = module_name, id = create_changelog_token, admin = false})
Event.add(defines.events.on_gui_click, on_gui_click)
return Public