updated notification

This commit is contained in:
Chr1Z93 2023-04-18 20:25:29 +02:00
parent 93971f3434
commit f2b59a5c7b
4 changed files with 80 additions and 114 deletions

View File

@ -44,6 +44,7 @@ local MOD_VERSION = "3.1.0"
local SOURCE_REPO = 'https://raw.githubusercontent.com/chr1z93/loadable-objects/main'
local library, requestObj
local dontNotify = {}
local modMeta
---------------------------------------------------------
-- data for tokens
@ -1060,61 +1061,67 @@ function compareVersion(request)
modMeta = JSON.decode(request.text)
-- stop here if on latest version or "don't show again" was clicked
if MOD_VERSION == modMeta["latestVersion"] then return end
--if MOD_VERSION == modMeta["latestVersion"] then return end
if dontNotify[modMeta["latestVersion"]] then return end
local releaseNotes = modMeta["releaseNotes"][modMeta["latestVersion"]]
if releaseNotes == nil then
-- end here if no release notes are found
if modMeta["releaseNotes"][modMeta["latestVersion"]] == nil then
log("Release notes for latest version not found!")
else
-- updating the XML notification
local ui = UI.getXmlTable()
-- update the headers
local header = find_tag_with_id(ui, 'notificationHeader')
header.value = "New Version available: " .. modMeta["latestVersion"] .. " (current: " .. MOD_VERSION .. ")"
local header2 = find_tag_with_id(ui, 'versionHeader')
header2.value = "Release Notes for " .. modMeta["latestVersion"]
-- update the release notes
local releaseNoteWrapper = find_tag_with_id(ui, 'releaseNoteWrapper')
releaseNoteWrapper.children = {}
for _, entry in pairs(releaseNotes["Details"]) do
table.insert(releaseNoteWrapper.children,
{ tag = 'Row',
attributes = { class="releaseNote" },
children =
{ tag = 'Cell',
attributes = { class="releaseNote" },
children =
{ tag = 'Text',
attributes = { class="releaseNote" },
value = "• " .. entry,
}
}
})
end
UI.setXmlTable(ui)
updateNotificationLoading()
-- small delay to avoid lagging
Wait.time(function() UI.show("updateNotification") end, 1)
end
end
-- close / don't show again buttons on the XML use this
function onClick_notification(_, parameter)
if parameter == "dontNotify" then
-- this variable tracks if "don't show again" was pressed for a version before
dontNotify[modMeta["latestVersion"]] = true
elseif parameter == "details" then
UI.show("releaseNotes")
return
-- updates the XML update notification based on the mod metadata
function updateNotificationLoading()
-- grab data
local highlights = modMeta["releaseNotes"][modMeta["latestVersion"]]["Highlights"]
local ui = UI.getXmlTable()
-- update the header
local header = find_tag_with_id(ui, 'notificationHeader')
header.value = header.value .. modMeta["latestVersion"]
-- update the release highlights
local releaseHighlightWrapper = find_tag_with_id(ui, 'releaseHighlightWrapper')
releaseHighlightWrapper.children = {}
for _, entry in pairs(highlights) do
table.insert(releaseHighlightWrapper.children,
{ tag = 'Row',
attributes = { class="releaseHighlight" },
children =
{ tag = 'Cell',
attributes = { class="releaseHighlight" },
children =
{ tag = 'Text',
attributes = { class="releaseHighlight" },
value = "• " .. entry,
}
}
}
)
end
UI.hide("updateNotification")
-- set height for amount of highlights
local highlightRow = find_tag_with_id(ui, 'highlightRow')
highlightRow.attributes.preferredHeight = 50*#highlights
local window = find_tag_with_id(ui, 'updateNotification')
window.attributes.height = highlightRow.attributes.preferredHeight + 100
-- update the XML UI
UI.setXmlTable(ui)
end
function onClick_releaseNotes()
UI.hide("releaseNotes")
-- close / don't show again buttons on the update notification
function onClick_notification(_, parameter)
if parameter == "dontNotify" then
-- this variable tracks if "don't show again" was pressed for a version
dontNotify[modMeta["latestVersion"]] = true
end
UI.hide("updateNotification")
end

View File

@ -123,4 +123,3 @@
<Include src="OptionPanel.xml"/>
<Include src="UpdateNotification.xml"/>
<Include src="ReleaseNotes.xml"/>

View File

@ -1,65 +0,0 @@
<Defaults>
<!-- table entries -->
<Text class="releaseNote"
fontSize="16"/>
<Row class="releaseNote"
preferredHeight="50"/>
<Cell class="releaseNote"
color="#333333"/>
</Defaults>
<TableLayout id="releaseNotes"
active="false"
color="#000000"
outlineSize="2 2"
outline="grey"
showAnimation="Grow"
hideAnimation="Shrink"
animationDuration="0.2"
rectAlignment="MiddleCenter"
height="300"
width="450">
<!-- Header -->
<Row preferredHeight="50">
<Cell>
<Panel padding="10 0 0 0">
<Text id="versionHeader"
font="font_teutonic-arkham"
fontSize="30"
alignment="MiddleCenter">Release Notes for </Text>
</Panel>
</Cell>
</Row>
<!-- Scrollable part with release notes -->
<Row preferredHeight="200">
<Cell>
<VerticalScrollView horizontalScrollbarVisibility="AutohideAndExpandViewport">
<!-- this part will be updated via script -->
<TableLayout id="releaseNoteWrapper"
autoCalculateHeight="1"
cellPadding="10 15 5 5">
<Row class="releaseNote">
<Cell class="releaseNote">
<Text class="releaseNote">Placeholder</Text>
</Cell>
</Row>
</TableLayout>
</VerticalScrollView>
</Cell>
</Row>
<!-- Buttons: "Close" -->
<Row preferredHeight="50">
<Cell>
<HorizontalLayout minHeight="55"
flexibleHeight="0"
padding="10 10 5 10"
spacing="100">
<Button class="bottomButtons"
onClick="onClick_releaseNotes">Close</Button>
</HorizontalLayout>
</Cell>
</Row>
</TableLayout>

View File

@ -1,5 +1,15 @@
<!-- Default formatting inherented from OptionPanel! -->
<!-- Default formatting partly inherented from OptionPanel! -->
<Defaults>
<!-- table entries -->
<Text class="releaseHighlight"
fontSize="16"/>
<Row class="releaseHighlight"
preferredHeight="50"/>
<Cell class="releaseHighlight"
color="#333333"/>
</Defaults>
<!-- Window with release highlights -->
<TableLayout id="updateNotification"
active="false"
color="#000000"
@ -10,8 +20,8 @@
animationDuration="0.2"
rectAlignment="UpperLeft"
offsetXY="60 -5"
height="100"
width="500">
height="200"
width="350">
<!-- Header -->
<Row preferredHeight="50">
@ -25,6 +35,23 @@
</Cell>
</Row>
<!-- patch highlights -->
<Row id="highlightRow"
preferredHeight="100">
<Cell>
<!-- this part will be updated via script -->
<TableLayout id="releaseHighlightWrapper"
autoCalculateHeight="1"
cellPadding="10 15 5 5">
<Row class="releaseHighlight">
<Cell class="releaseHighlight">
<Text class="releaseHighlight">Placeholder</Text>
</Cell>
</Row>
</TableLayout>
</Cell>
</Row>
<!-- Buttons: "Don't show again", "Details" and "Close" -->
<Row preferredHeight="50">
<Cell>
@ -34,8 +61,6 @@
spacing="10">
<Button class="bottomButtons"
onClick="onClick_notification(dontNotify)">Don't show again</Button>
<Button class="bottomButtons"
onClick="onClick_notification(details)">Show details</Button>
<Button class="bottomButtons"
onClick="onClick_notification(close)">Close</Button>
</HorizontalLayout>