updated script
This commit is contained in:
parent
5884cfdea0
commit
b879335dce
@ -42,8 +42,9 @@ local hideTitleSplashWaitFunctionId = nil
|
|||||||
-- online functionality related variables
|
-- online functionality related variables
|
||||||
local MOD_VERSION = "4.0.0"
|
local MOD_VERSION = "4.0.0"
|
||||||
local SOURCE_REPO = "https://github.com/Chr1Z93/SCED-downloads/releases/latest/download/"
|
local SOURCE_REPO = "https://github.com/Chr1Z93/SCED-downloads/releases/latest/download/"
|
||||||
local library, requestObj, modMeta
|
local library, requestObj, modMeta, searchFilter, authorFilter
|
||||||
local acknowledgedUpgradeVersions = {}
|
local acknowledgedUpgradeVersions = {}
|
||||||
|
local authorList = {}
|
||||||
local contentToShow = "campaign"
|
local contentToShow = "campaign"
|
||||||
local currentListItem = 1
|
local currentListItem = 1
|
||||||
local tabIdTable = {
|
local tabIdTable = {
|
||||||
@ -959,22 +960,54 @@ end
|
|||||||
-- Content Importing and XML functions
|
-- Content Importing and XML functions
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
|
|
||||||
function onSearchValueChanged(a, b, c)
|
-- callback function for the search field in the download menu
|
||||||
log(a)
|
function onSearchValueSubmit(_, value)
|
||||||
log(b)
|
-- this event seems to be called 5x at once, so we use this flag to just execute it once
|
||||||
log(c)
|
if ignoreSubmit then return end
|
||||||
|
ignoreSubmit = true
|
||||||
|
|
||||||
-- TODO: some kind of wait
|
-- store input value in global var
|
||||||
|
if value == "" then
|
||||||
|
searchFilter = nil
|
||||||
|
else
|
||||||
|
searchFilter = value
|
||||||
|
end
|
||||||
|
|
||||||
|
-- update XML so that the settings persists
|
||||||
|
UI.setAttribute("searchField", "text", value)
|
||||||
|
|
||||||
|
-- turn off flag after 0.1s
|
||||||
|
Wait.time(function() ignoreSubmit = false end, 0.1)
|
||||||
|
|
||||||
|
-- update list (including new filter setting)
|
||||||
updateDownloadItemList(true)
|
updateDownloadItemList(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
function onAuthorFilterChanged(a, b, c)
|
-- callback function for the "author" dropdown in the download menu
|
||||||
log(a)
|
function onAuthorFilterChanged(_, value)
|
||||||
log(b)
|
-- store input value in global var
|
||||||
log(c)
|
if value == "All authors" then
|
||||||
|
authorFilter = nil
|
||||||
|
else
|
||||||
|
authorFilter = value
|
||||||
|
end
|
||||||
|
|
||||||
|
-- update XML so that the settings persists
|
||||||
|
UI.setAttribute("authorDropdown", "value", returnAuthorId(value))
|
||||||
|
|
||||||
|
-- update list (including new filter setting)
|
||||||
updateDownloadItemList(true)
|
updateDownloadItemList(true)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- helper function to get the ID of the dropdown selection
|
||||||
|
function returnAuthorId(name)
|
||||||
|
for index, optionName in ipairs(authorList) do
|
||||||
|
if optionName == name then
|
||||||
|
return index
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- forwards the requested content type to the update function and sets highlight to clicked tab
|
-- forwards the requested content type to the update function and sets highlight to clicked tab
|
||||||
---@param tabId string Id of the clicked tab
|
---@param tabId string Id of the clicked tab
|
||||||
function onClick_tab(_, _, tabId)
|
function onClick_tab(_, _, tabId)
|
||||||
@ -987,6 +1020,12 @@ function onClick_tab(_, _, tabId)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
currentListItem = 1
|
currentListItem = 1
|
||||||
|
|
||||||
|
-- reset filters
|
||||||
|
authorFilter, searchFilter = nil, nil
|
||||||
|
UI.setAttribute("searchField", "text", "")
|
||||||
|
UI.setAttribute("authorDropdown", "value", 0)
|
||||||
|
|
||||||
updateDownloadItemList()
|
updateDownloadItemList()
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -1358,11 +1397,22 @@ function updateDownloadItemList(skipAuthorUpdate)
|
|||||||
local globalXml = UI.getXmlTable()
|
local globalXml = UI.getXmlTable()
|
||||||
local contentList = getXmlTableElementById(globalXml, 'contentList')
|
local contentList = getXmlTableElementById(globalXml, 'contentList')
|
||||||
|
|
||||||
|
-- reset the list of authors unless skipping
|
||||||
|
if not skipAuthorUpdate then
|
||||||
|
authorList = {}
|
||||||
|
end
|
||||||
|
|
||||||
contentList.children = {}
|
contentList.children = {}
|
||||||
for i, v in ipairs(library[contentToShow]) do
|
for i, v in ipairs(library[contentToShow]) do
|
||||||
-- TODO: filter here
|
-- if there's a filter, apply it (both for name and author)
|
||||||
|
if (searchFilter == nil or string.contains(string.lower(v.name), searchFilter)) and
|
||||||
|
(authorFilter == nil or v.author == authorFilter) then
|
||||||
|
|
||||||
|
-- start collecting authors unless skipping
|
||||||
|
if not skipAuthorUpdate then
|
||||||
|
table.insert(authorList, v.author)
|
||||||
|
end
|
||||||
|
|
||||||
-- TODO: store authors here
|
|
||||||
table.insert(contentList.children,
|
table.insert(contentList.children,
|
||||||
{
|
{
|
||||||
tag = "Panel",
|
tag = "Panel",
|
||||||
@ -1378,14 +1428,19 @@ function updateDownloadItemList(skipAuthorUpdate)
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
contentList.attributes.height = #contentList.children * 27
|
contentList.attributes.height = #contentList.children * 27
|
||||||
|
|
||||||
-- TODO: maybe update authors
|
-- populate the author dropdown with options unless skipping
|
||||||
if not skipAuthorUpdate then
|
if not skipAuthorUpdate then
|
||||||
|
authorList = removeDuplicatesAndSort(authorList)
|
||||||
|
|
||||||
local authorDropdown = getXmlTableElementById(globalXml, 'authorDropdown')
|
local authorDropdown = getXmlTableElementById(globalXml, 'authorDropdown')
|
||||||
|
authorDropdown.children = { { tag = "Option", value = "All authors" } }
|
||||||
|
for _, author in ipairs(authorList) do
|
||||||
|
table.insert(authorDropdown.children, { tag = "Option", value = author })
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
updateGlobalXml(globalXml)
|
updateGlobalXml(globalXml)
|
||||||
@ -2684,3 +2739,19 @@ function deepCopy(data)
|
|||||||
end
|
end
|
||||||
return copiedList
|
return copiedList
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function removeDuplicatesAndSort(t)
|
||||||
|
local seen = {}
|
||||||
|
local result = {}
|
||||||
|
|
||||||
|
for _, value in ipairs(t) do
|
||||||
|
if not seen[value] then
|
||||||
|
seen[value] = true
|
||||||
|
table.insert(result, value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
table.sort(result)
|
||||||
|
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
@ -83,10 +83,11 @@
|
|||||||
textColor="Black"
|
textColor="Black"
|
||||||
textOffset="5 5 5 5"
|
textOffset="5 5 5 5"
|
||||||
font="font_teutonic-arkham"
|
font="font_teutonic-arkham"
|
||||||
onValueChanged="onSearchValueChanged"/>
|
onSubmit="onSearchValueSubmit"/>
|
||||||
<Dropdown id="authorDropdown"
|
<Dropdown id="authorDropdown"
|
||||||
preferredWidth="290"
|
preferredWidth="290"
|
||||||
fontSize="22"
|
fontSize="22"
|
||||||
|
scrollSensitivity="22"
|
||||||
font="font_teutonic-arkham"
|
font="font_teutonic-arkham"
|
||||||
onValueChanged="onAuthorFilterChanged">
|
onValueChanged="onAuthorFilterChanged">
|
||||||
<Option>All Authors</Option>
|
<Option>All Authors</Option>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user