1
0
forked from 0ad/0ad

Remove two globals from MapBrowserPage.js

Comments By: @sera, @elexis
Differential Revision: https://code.wildfiregames.com/D5165
This was SVN commit r27904.
This commit is contained in:
phosit 2023-10-28 11:32:37 +00:00
parent 261d606c25
commit c90aeee2b3
6 changed files with 38 additions and 28 deletions

View File

@ -27,7 +27,7 @@ SetupWindowPages.MapBrowserPage = class extends MapBrowser
openPage()
{
super.openPage();
super.openPage(g_IsController);
this.controls.MapFiltering.select(
this.gameSettingsController.guiData.mapFilter.filter,

View File

@ -19,6 +19,9 @@ class MapBrowser
submitMapSelection()
{
if (!this.allowSelection)
return;
let file = this.gridBrowser.getSelected();
let type = this.controls.MapFiltering.getSelectedMapType();
let filter = this.controls.MapFiltering.getSelectedMapFilter();
@ -47,12 +50,14 @@ class MapBrowser
this.closePageHandlers.add(handler);
}
openPage()
openPage(allowSelection)
{
if (this.open)
return;
for (let handler of this.openPageHandlers)
handler();
handler(allowSelection);
this.allowSelection = allowSelection;
this.open = true;
}

View File

@ -1,10 +1,7 @@
/**
* TODO: better global state handling in the GUI.
* In particular a bunch of those shadow gamesetup/gamesettings stuff.
*/
const g_IsController = false;
const g_MapTypes = prepareForDropdown(g_Settings && g_Settings.MapTypes);
var g_SetupWindow;
function init()
{
@ -12,6 +9,6 @@ function init()
let filters = new MapFilters(cache);
let browser = new MapBrowser(cache, filters);
browser.registerClosePageHandler(() => Engine.PopGuiPage());
browser.openPage();
browser.openPage(false);
browser.controls.MapFiltering.select("default", "skirmish");
}

View File

@ -14,8 +14,6 @@ class MapBrowserPageControls
setupButtons()
{
this.pickRandom = Engine.GetGUIObjectByName("mapBrowserPagePickRandom");
if (!g_IsController)
this.pickRandom.hidden = true;
this.pickRandom.onPress = () => {
let index = randIntInclusive(0, this.gridBrowser.itemCount - 1);
this.gridBrowser.setSelectedIndex(index);
@ -26,25 +24,24 @@ class MapBrowserPageControls
this.select.onPress = () => this.onSelect();
this.close = Engine.GetGUIObjectByName("mapBrowserPageClose");
if (g_SetupWindow)
this.close.tooltip = colorizeHotkey(
translate("%(hotkey)s: Close map browser and discard the selection."), "cancel");
else
{
this.close.caption = translate("Close");
this.close.tooltip = colorizeHotkey(
translate("%(hotkey)s: Close map browser."), "cancel");
}
this.close.onPress = () => this.mapBrowserPage.closePage();
this.select.hidden = !g_IsController;
if (!g_IsController)
this.close.size = this.select.size;
this.mapBrowserPage.registerOpenPageHandler(this.onOpenPage.bind(this));
this.gridBrowser.registerSelectionChangeHandler(() => this.onSelectionChange());
}
onOpenPage(allowSelection)
{
this.pickRandom.hidden = !allowSelection;
this.select.hidden = !allowSelection;
const usedCaptions = allowSelection ? MapBrowserPageControls.Captions.cancel :
MapBrowserPageControls.Captions.close;
this.close.caption = usedCaptions.caption;
this.close.tooltip = colorizeHotkey(usedCaptions.tooltip, "cancel");
}
onSelectionChange()
{
this.select.enabled = this.gridBrowser.selected != -1;
@ -54,4 +51,18 @@ class MapBrowserPageControls
{
this.mapBrowserPage.submitMapSelection();
}
static Captions =
{
"close":
{
"caption": translate("Close"),
"tooltip": translate("%(hotkey)s: Close map browser.")
},
"cancel":
{
"caption": translate("Cancel"),
"tooltip": translate("%(hotkey)s: Close map browser and discard the selection.")
}
};
}

View File

@ -47,9 +47,7 @@
<object name="mapBrowserPagePickRandom" type="button" style="ModernButtonRed" size="0 100%-60 100% 100%-30">
<translatableAttribute id="caption">Pick Random Map</translatableAttribute>
</object>
<object name="mapBrowserPageClose" type="button" style="ModernButtonRed" hotkey="cancel" size="0 100%-30 50% 100%">
<translatableAttribute id="caption">Cancel</translatableAttribute>
</object>
<object name="mapBrowserPageClose" type="button" style="ModernButtonRed" hotkey="cancel" size="0 100%-30 50% 100%"/>
<object name="mapBrowserPageSelect" type="button" style="ModernButtonRed" size="50% 100%-30 100% 100%">
<translatableAttribute id="caption" context="map selection dialog">Select</translatableAttribute>
</object>

View File

@ -12,8 +12,7 @@ class MapGridBrowserItem extends GridBrowserItem
mapGridBrowser.registerSelectionChangeHandler(this.onSelectionChange.bind(this));
mapGridBrowser.registerPageChangeHandler(this.onGridResize.bind(this));
if (g_IsController)
this.imageObject.onMouseLeftDoubleClick = this.onMouseLeftDoubleClick.bind(this);
this.imageObject.onMouseLeftDoubleClick = this.onMouseLeftDoubleClick.bind(this);
}
onSelectionChange()