Make modio.js a module

Actions in xml files only has access to the global scope, not the module
scope. So define them in the js file.

Refs: #8081
This commit is contained in:
phosit 2026-07-27 12:23:43 +02:00
parent 8918cfb0a7
commit 2c4f7d85b6
No known key found for this signature in database
GPG key ID: C9430B600671C268
2 changed files with 23 additions and 18 deletions

View file

@ -1,4 +1,4 @@
var g_ModsAvailableOnline = [];
let g_ModsAvailableOnline = [];
/**
* Indicates if we have encountered an error in one of the network-interaction attempts.
@ -8,7 +8,7 @@ var g_ModsAvailableOnline = [];
* Set to `true` by showErrorMessageBox
* Set to `false` by init, updateModList, downloadFile, and cancelRequest
*/
var g_Failure;
let g_Failure;
/**
* Indicates if the user has cancelled a request.
@ -19,11 +19,11 @@ var g_Failure;
* Set to `true` by cancelRequest
* Set to `false` by updateModList, and downloadFile
*/
var g_RequestCancelled;
let g_RequestCancelled;
var g_RequestStartTime;
let g_RequestStartTime;
var g_ModIOState = {
const g_ModIOState = {
/**
* Finished status indicators
*/
@ -142,7 +142,7 @@ var g_ModIOState = {
}
};
function init(data)
export function init(data)
{
const promise = progressDialog(
translate("Initializing mod.io interface."),
@ -153,6 +153,21 @@ function init(data)
g_Failure = false;
Engine.ModIoStartGetGameId();
Object.assign(Engine.GetGUIObjectByName("modFilter"), {
"onPress": displayMods,
"onTextEdit": displayMods
});
Object.assign(Engine.GetGUIObjectByName("modsAvailableList"), {
"onSelectionChange": showModDescription,
"onSelectionColumnChange": displayMods,
"onMouseLeftDoubleClickItem": downloadMod
});
Engine.GetGUIObjectByName("compatibilityFilter").onPress = displayMods;
Engine.GetGUIObjectByName("refreshButton").onPress = updateModList;
Engine.GetGUIObjectByName("downloadButton").onPress = downloadMod;
return Promise.race([
promise,
new Promise(closePageCallback =>

View file

@ -3,7 +3,7 @@
<objects>
<script directory="gui/common/"/>
<script directory="gui/modio/"/>
<script module="gui/modio/modio.js"/>
<object type="image" sprite="ModernFade"/>
@ -25,8 +25,6 @@
style="ModernInput"
size="16 0 200 24"
>
<action on="Press">displayMods();</action>
<action on="TextEdit">displayMods();</action>
<translatableAttribute id="placeholder_text" context="placeholder text for input field to filter mods">Filter</translatableAttribute>
</object>
@ -39,10 +37,6 @@
selected_column_order="1"
font="sans-stroke-13"
>
<action on="SelectionChange">showModDescription();</action>
<action on="SelectionColumnChange">displayMods();</action>
<action on="MouseLeftDoubleClickItem">downloadMod();</action>
<!-- List headers -->
<!-- Keep in sync with mod property names -->
<column id="name_id" textcolor="255 255 255" width="20%">
@ -69,9 +63,7 @@
<!-- Right Panel: Compatibility Filter-->
<object name="rightPanel" size="100%-250 20 100%-10 40" >
<!-- Compatibility Filter Checkbox -->
<object name="compatibilityFilter" type="checkbox" checked="true" style="ModernTickBox" size="0 4 20 100%">
<action on="Press">displayMods();</action>
</object>
<object name="compatibilityFilter" type="checkbox" checked="true" style="ModernTickBox" size="0 4 20 100%" />
<!-- Compatibility Filter Label -->
<object type="text" size="20 2 100% 100%" text_align="left" textcolor="white">
<translatableAttribute id="caption">Filter valid mods</translatableAttribute>
@ -85,12 +77,10 @@
<object name="refreshButton" type="button" style="ModernButtonRed" size="100%-368 100%-44 100%-188 100%-16" enabled="false">
<translatableAttribute id="caption">Refresh List</translatableAttribute>
<action on="Press">updateModList();</action>
</object>
<object name="downloadButton" type="button" style="ModernButtonRed" size="100%-184 100%-44 100%-16 100%-16" enabled="false">
<translatableAttribute id="caption">Download</translatableAttribute>
<action on="Press">downloadMod();</action>
</object>
</object>