Merge pull request #263 from argonui/modversion

update notification
This commit is contained in:
Chr1Z 2023-04-20 10:33:07 +02:00 committed by GitHub
commit b1b384c1a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 180 additions and 19 deletions

View File

@ -203,5 +203,10 @@
"Name": "TitleGradient",
"Type": 0,
"URL": "https://i.imgur.com/Mdjm349.png"
},
{
"Name": "FinnIcon",
"Type": 0,
"URL": "http://cloud-3.steamusercontent.com/ugc/2037357792052848566/5DA900C430E97D3DFF2C9B8A3DB1CB2271791FC7/"
}
]

View File

@ -1 +1 @@
{"optionPanel":{"playAreaSnapTags":true,"showAttachmentHelper":false,"showChaosBagManager":false,"showCleanUpHelper":false,"showCustomPlaymatImages":false,"showCYOA":false,"showDisplacementTool":false,"showDrawButton":false,"showHandHelper":[],"showNavigationOverlay":false,"showSearchAssistant":[],"showTitleSplash":true,"showTokenArranger":false,"useClueClickers":false,"useSnapTags":true}}
{"acknowledgedUpgradeVersions":[],"optionPanel":{"playAreaSnapTags":true,"showAttachmentHelper":false,"showChaosBagManager":false,"showCleanUpHelper":false,"showCustomPlaymatImages":false,"showCYOA":false,"showDisplacementTool":false,"showDrawButton":false,"showHandHelper":[],"showNavigationOverlay":false,"showSearchAssistant":[],"showTitleSplash":true,"showTokenArranger":false,"useClueClickers":false,"useSnapTags":true}}

View File

@ -39,6 +39,12 @@ local mythosAreaApi = require("core/MythosAreaApi")
local tokenArrangerApi = require("accessories/TokenArrangerApi")
local blessCurseManagerApi = require("chaosbag/BlessCurseManagerApi")
-- online functionality related variables
local MOD_VERSION = "3.1.0"
local SOURCE_REPO = 'https://raw.githubusercontent.com/chr1z93/loadable-objects/main'
local library, requestObj, modMeta, notificationVisible
local acknowledgedUpgradeVersions = {}
---------------------------------------------------------
-- data for tokens
---------------------------------------------------------
@ -98,12 +104,13 @@ local tokenDrawingStats = {
---------------------------------------------------------
-- saving state of optionPanel to restore later
function onSave() return JSON.encode({ optionPanel = optionPanel }) end
function onSave() return JSON.encode({ optionPanel = optionPanel, acknowledgedUpgradeVersions = acknowledgedUpgradeVersions }) end
function onLoad(savedData)
if savedData then
loadedData = JSON.decode(savedData)
optionPanel = loadedData.optionPanel
acknowledgedUpgradeVersions = loadedData.acknowledgedUpgradeVersions
updateOptionPanelState()
else
print("Saved state could not be found!")
@ -114,6 +121,7 @@ function onLoad(savedData)
if obj ~= nil then obj.interactable = false end
end
getModVersion()
math.randomseed(os.time())
end
@ -614,21 +622,17 @@ end
-- Content Importing and XML functions
---------------------------------------------------------
local source_repo = 'https://raw.githubusercontent.com/chr1z93/loadable-objects/main'
local library = nil
local request_obj
function onClick_refreshList()
local request = WebRequest.get(source_repo .. '/library.json', completed_list_update)
request_obj = request
local request = WebRequest.get(SOURCE_REPO .. '/library.json', completed_list_update)
requestObj = request
startLuaCoroutine(Global, 'downloadCoroutine')
end
function onClick_select(player, params)
params = JSON.decode(urldecode(params))
local url = source_repo .. '/' .. params.url
local url = SOURCE_REPO .. '/' .. params.url
local request = WebRequest.get(url, function (request) complete_obj_download(request, params) end )
request_obj = request
requestObj = request
startLuaCoroutine(Global, 'downloadCoroutine')
end
@ -657,8 +661,8 @@ function onClick_toggleUi(_, title)
end
function downloadCoroutine()
while request_obj do
UI.setAttribute('download_progress', 'percentage', request_obj.download_progress * 100)
while requestObj do
UI.setAttribute('download_progress', 'percentage', requestObj.download_progress * 100)
coroutine.yield(0)
end
return 1
@ -732,7 +736,7 @@ function complete_obj_download(request, params)
end
end
request_obj = nil
requestObj = nil
UI.setAttribute('download_progress', 'percentage', 100)
end
@ -756,7 +760,7 @@ function completed_list_update(request)
end
end
request_obj = nil
requestObj = nil
UI.setAttribute('download_progress', 'percentage', 100)
end
@ -1035,3 +1039,75 @@ function titleSplash(scenarioName)
soundCubeApi.playSoundByName("Deep Bell")
end
end
---------------------------------------------------------
-- Update notification related functionality
---------------------------------------------------------
-- grabs the latest mod version and release notes from GitHub (called onLoad())
function getModVersion()
WebRequest.get(SOURCE_REPO .. '/modversion.json', compareVersion)
end
-- compares the modversion with GitHub and possibly shows the update notification
function compareVersion(request)
if request.is_error then
log(request.error)
return
end
-- global variable to make it accessible for other functions
modMeta = JSON.decode(request.text)
-- stop here if on latest version
if MOD_VERSION == modMeta["latestVersion"] then return end
-- stop here if "don't show again" was clicked for this version before
if acknowledgedUpgradeVersions[modMeta["latestVersion"]] then return end
updateNotificationLoading()
-- delay to avoid lagging during onLoad()
Wait.time(function() UI.show("FinnIcon") end, 1)
end
-- updates the XML update notification based on the mod metadata
function updateNotificationLoading()
-- grab data
local highlights = modMeta["releaseHighlights"]
-- concatenate the release highlights
local highlightText = "• " .. highlights[1]
for i, entry in pairs(highlights) do
if i ~= 1 then
highlightText = highlightText .. "\n• " .. entry
end
end
-- update the XML UI
UI.setValue("notificationHeader", "New version available: ".. modMeta["latestVersion"])
UI.setValue("releaseHighlightText", highlightText)
UI.setAttribute("highlightRow", "preferredHeight", 20*#highlights)
UI.setAttribute("updateNotification", "height", 20*#highlights + 125)
end
-- triggered by clicking on the Finn Icon
function onClick_FinnIcon()
if notificationVisible then
UI.hide("updateNotification")
notificationVisible = false
else
UI.show("updateNotification")
notificationVisible = true
end
end
-- close / don't show again buttons on the update notification
function onClick_notification(_, parameter)
if parameter == "dontShowAgain" then
-- this variable tracks if "don't show again" was pressed for a version
acknowledgedUpgradeVersions[modMeta["latestVersion"]] = true
end
UI.hide("FinnIcon")
UI.hide("updateNotification")
end

View File

@ -98,16 +98,14 @@
</VerticalLayout>
<!-- Title Splash when starting a scenario -->
<Panel
id="title_splash"
<Panel id="title_splash"
height="220"
position="0 250 0"
showAnimation="FadeIn"
hideAnimation="FadeOut"
active="false"
animationDuration="2">
<Image
id="title_gradient"
<Image id="title_gradient"
height="220"
image="TitleGradient" />
<Text id="title_splash_text"
@ -122,4 +120,6 @@
horizontalOverflow="Overflow">
</Text>
</Panel>
<Include src="OptionPanel.xml"/>
<Include src="UpdateNotification.xml"/>

View File

@ -20,7 +20,7 @@
outline="grey"
showAnimation="SlideIn_Right"
hideAnimation="SlideOut_Right"
animationDuration="0.1" />
animationDuration="0.2" />
<!-- group headers -->
<Row class="group-header"

View File

@ -0,0 +1,80 @@
<!-- Default formatting inherented from OptionPanel! -->
<!-- Icon with Finn, which can be clicked -->
<Image id="FinnIcon"
active="false"
showAnimation="SlideIn_Top"
hideAnimation="SlideOut_Top"
animationDuration="0.2"
rectAlignment="UpperLeft"
offsetXY="420 -5"
height="90"
width="90"
onClick="onClick_FinnIcon"
image="FinnIcon"
tooltip="Update notification"
tooltipBackgroundColor="rgba(0,0,0,0.8)"/>
<!-- main notification window -->
<TableLayout id="updateNotification"
active="false"
color="#000000"
outlineSize="2 2"
outline="grey"
showAnimation="SlideIn_Top"
hideAnimation="SlideOut_Top"
animationDuration="0.2"
rectAlignment="UpperLeft"
offsetXY="60 -5"
height="225"
width="350">
<!-- Header -->
<Row preferredHeight="50">
<Cell>
<Panel padding="10 10 0 0">
<!-- this part will be updated via script -->
<Text id="notificationHeader"
font="font_teutonic-arkham"
fontSize="30"
alignment="MiddleCenter">Placeholder</Text>
</Panel>
</Cell>
</Row>
<!-- patch highlights -->
<Row id="highlightRow"
preferredHeight="100">
<Cell>
<Panel padding="15 15 0 7">
<!-- this part will be updated via script -->
<Text id="releaseHighlightText"
resizeTextForBestFit="true">Placeholder</Text>
</Panel>
</Cell>
</Row>
<!-- explanation -->
<Row preferredHeight="25">
<Cell>
<Panel padding="15 15 0 7">
<Text resizeTextForBestFit="true">Visit the usual place to receive this update.</Text>
</Panel>
</Cell>
</Row>
<!-- Buttons: "Don't show again" and "Close" -->
<Row preferredHeight="50">
<Cell>
<HorizontalLayout minHeight="55"
flexibleHeight="0"
padding="10 10 5 10"
spacing="10">
<Button class="bottomButtons"
onClick="onClick_notification(dontShowAgain)">Don't show again</Button>
<Button class="bottomButtons"
onClick="onClick_notification(close)">Close</Button>
</HorizontalLayout>
</Cell>
</Row>
</TableLayout>