Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup for support of generated changelogs #6473

Draft
wants to merge 13 commits into
base: develop
Choose a base branch
from
2 changes: 1 addition & 1 deletion lua/system/import.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ __module_metatable = {
---@field OnReload? fun(newmod: Module)

-- these values can be adjusted by hooking into this file
local informDevOfLoad = false
local informDevOfLoad = true

---Load a module
---@param module Module
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
--******************************************************************************************************
--** Copyright (c) 2024 FAForever
--**
--** Permission is hereby granted, free of charge, to any person obtaining a copy
--** of this software and associated documentation files (the "Software"), to deal
--** in the Software without restriction, including without limitation the rights
--** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
--** copies of the Software, and to permit persons to whom the Software is
--** furnished to do so, subject to the following conditions:
--**
--** The above copyright notice and this permission notice shall be included in all
--** copies or substantial portions of the Software.
--**
--** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
--** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
--** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
--** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
--** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
--** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
--** SOFTWARE.
--******************************************************************************************************

local EscapeHandler = import("/lua/ui/dialogs/eschandler.lua")
local LayoutHelpers = import("/lua/maui/layouthelpers.lua")
local Prefs = import("/lua/user/prefs.lua")
Expand All @@ -7,23 +29,34 @@ local Bitmap = import("/lua/maui/bitmap.lua").Bitmap
local Group = import("/lua/maui/group.lua").Group
local ItemList = import("/lua/maui/itemlist.lua").ItemList

local data = import("/lua/ui/lobby/changelogdata.lua")
local ChangelogOverview = import("/lua/ui/lobby/changelog/generated/overview.lua")

--- Test if we should display the changelog of the new game version.
---@return boolean
function OpenChangelog()
local LastChangelogVersion = Prefs.GetFromCurrentProfile('LobbyChangelog') or 0
return LastChangelogVersion < data.last_version
end
local PreferenceKeys = {
GameVersion = "ChangelogGameVersion",
}

---@class UIChangelogOverview
---@field Changelogs UIChangelogMetadata[]

---@class UIChangelogMetadata
---@field Version number
---@field Path string
---@field URL string
---@field Name string

---@class UIChangelogData
---@field Version number
---@field Name string
---@field Description string[]

--- A set of preference keys that are used.
PreferenceKeys = {
GameVersion = "ChangelogGameVersion",
}

--- Toggles the debug interface that shows the various groups that are used to divide the dialog
local debugInterface = false

--- A bit of a hack, but allows us to keep track of whether the changelog is open or not. The lobby
-- is (almost aggressively) trying to keep control of the keyboard on the chat box to prevent hotkeys
-- from working :sad:
isOpen = false

---@alias PatchNotesType "Hotfix"|"Developers patch"|"Balance patch"

---@class PatchNotes
Expand All @@ -35,7 +68,10 @@ isOpen = false
---@field descriptionRU string[] # Russian translation
---@field description string[] # Default changelog in English

---@class UIChangelog : Group
---@type TrashBag
local ModuleTrash = TrashBag()

---@class UIChangelogDialog : Group
---@field Debug Group
---@field CommonUI Group
---@field Border Border
Expand All @@ -59,9 +95,9 @@ isOpen = false
---@field ContentPatchesDebug Bitmap
---@field ContentDivider Bitmap
---@field ContentPatchesList ItemList
Changelog = ClassUI(Group) {
local ChangelogDialog = ClassUI(Group) {

---@param self UIChangelog
---@param self UIChangelogDialog
---@param parent Control
__init = function(self, parent)
Group.__init(self, parent)
Expand All @@ -73,7 +109,6 @@ Changelog = ClassUI(Group) {

-- allow us to use escape to quickly get out

isOpen = true
EscapeHandler.PushEscapeHandler(
function()
self:Close()
Expand Down Expand Up @@ -245,10 +280,14 @@ Changelog = ClassUI(Group) {
end,

--- Populates the dialog with the given patch
---@param self UIChangelog
---@param self UIChangelogDialog
---@param index number
PopulateWithPatch = function(self, index)
local patch = data.gamePatches[index + 1]
---@type UIChangelogMetadata
local changelog = ChangelogOverview.Overview.Changelogs[index + 1]

---@type UIChangelogData
local patch = import(changelog.Path).Changelog

if patch then

Expand All @@ -271,11 +310,11 @@ Changelog = ClassUI(Group) {
end

self.ContentPatchesList:SetSelection(index)
self.HeaderSubtitle:SetText(patch.name)
self.HeaderSubtitle:SetText(patch.Name)
self.ContentNotesList:DeleteAllItems()

local altDescription = LOC("<LOC ChangelogDescriptionIdentifier>")
for k, line in patch[altDescription] or patch.description do
for k, line in patch[altDescription] or patch.Description do
self.ContentNotesList:AddItem(line)
end
else
Expand All @@ -285,25 +324,95 @@ Changelog = ClassUI(Group) {
end,

--- Populates the list of patches
---@param self UIChangelog
---@param self UIChangelogDialog
PopulatePatchList = function(self)
self.ContentPatchesList:DeleteAllItems()
for k, patch in data.gamePatches do
self.ContentPatchesList:AddItem(patch.version .. " - " .. patch.name)
for _, patch in pairs(ChangelogOverview.Overview.Changelogs) do
self.ContentPatchesList:AddItem(patch.Version .. " - " .. patch.Name)
end
end,

--- Destroys the dialog
---@param self UIChangelog
---@param self UIChangelogDialog
Close = function(self)

local version, gametype, commit = import("/lua/version.lua").GetVersionData()

-- prevent the dialog from popping up again
Prefs.SetToCurrentProfile('LobbyChangelog', data.last_version)
Prefs.SetToCurrentProfile(PreferenceKeys.GameVersion, version)

isOpen = false
EscapeHandler.PopEscapeHandler()

-- go into oblivion
self:Destroy()
CloseChangelogDialog()
end,
}

---@type UIChangelogDialog | false
ChangelogInstance = false

--- Closes the dialog. Function is idempotent.
CloseChangelogDialog = function()
ModuleTrash:Destroy()
ChangelogInstance = false
end

--- Opens the changelog dialog. Function is idempotent.
---@param parent Control
---@return UIChangelogDialog
CreateChangelogDialog = function(parent)
CloseChangelogDialog()

---@type UIChangelogDialog
ChangelogInstance = ChangelogDialog(parent)
ModuleTrash:Add(ChangelogInstance)
return ChangelogInstance
end

--- Returns iff the changelog is open.
---@return boolean
IsOpen = function()
if not ChangelogInstance then
return false
end

if IsDestroyed(ChangelogInstance) then
return false
end

return true
end

--- Returns true iff we should open the changelog.
---@return boolean
function ShouldOpenChangelog()
local version, gametype, commit = import("/lua/version.lua").GetVersionData()

local LastChangelogVersion = Prefs.GetFromCurrentProfile(PreferenceKeys.GameVersion) or 0
return LastChangelogVersion < version
end

-------------------------------------------------------------------------------
--#region Debugging

--- Called by the module manager when this module becomes dirty
function __moduleinfo.OnDirty()
-- keep track of whether the changelog was open
local openAgain = IsOpen()

-- clear all trash related to the dialog, including the dialog itself
CloseChangelogDialog()

-- if the dialog was open, wait a second and then automatically re-open it
if openAgain then
ForkThread(
function()
WaitSeconds(1.0)
local module = import(__moduleinfo.name)
module.CreateChangelogDialog(GetFrame(0))
end
)
end
end

--#endregion
11 changes: 11 additions & 0 deletions lua/ui/lobby/changelog/generated/3000-dummy.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

Changelog = {
Name = "Developers patch",
Version = 3000,
Description = {
"# XYZ (Month Day, Year)",
"",
"This is a template changelog and should be replaced by real changelogs upon deploying.",
"Other unique content",
}
}
11 changes: 11 additions & 0 deletions lua/ui/lobby/changelog/generated/3001-dummy.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

Changelog = {
Name = "Balance patch",
Version = 3001,
Description = {
"# XYZ (Month Day, Year)",
"",
"This is a template changelog and should be replaced by real changelogs upon deploying.",
"Some unique content",
}
}
18 changes: 18 additions & 0 deletions lua/ui/lobby/changelog/generated/overview.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

---@type UIChangelogOverview
Overview = {
Changelogs = {
{
Version = 3000,
Name = "Developers patch",
URL = "http://faforever.github.io/fa/",
Path = "/lua/ui/lobby/changelog/generated/3000-dummy.lua"
},
{
Version = 3001,
Name = "Balance patch",
URL = "http://faforever.github.io/fa/",
Path = "/lua/ui/lobby/changelog/generated/3001-dummy.lua"
}
}
}
Loading