Index: ps/trunk/binaries/data/mods/public/gui/gamesetup/Pages/MapBrowserPage/MapBrowserPage.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/gamesetup/Pages/MapBrowserPage/MapBrowserPage.js (revision 27903) +++ ps/trunk/binaries/data/mods/public/gui/gamesetup/Pages/MapBrowserPage/MapBrowserPage.js (revision 27904) @@ -1,48 +1,48 @@ SetupWindowPages.MapBrowserPage = class extends MapBrowser { constructor(setupWindow) { super(setupWindow.controls.mapCache, setupWindow.controls.mapFilters, setupWindow); this.mapBrowserPage.hidden = true; this.gameSettingsController = setupWindow.controls.gameSettingsController; } onSubmitMapSelection(map, type, filter) { if (!g_IsController) return; if (type) g_GameSettings.map.setType(type); if (filter) this.gameSettingsController.guiData.mapFilter.filter = filter; if (map) g_GameSettings.map.selectMap(map); this.gameSettingsController.setNetworkInitAttributes(); } openPage() { - super.openPage(); + super.openPage(g_IsController); this.controls.MapFiltering.select( this.gameSettingsController.guiData.mapFilter.filter, g_GameSettings.map.type || g_MapTypes.Name[g_MapTypes.Default] ); if (g_GameSettings.map.map) this.gridBrowser.select(g_GameSettings.map.map); this.mapBrowserPage.hidden = false; } closePage() { super.closePage(); this.mapBrowserPage.hidden = true; } }; Index: ps/trunk/binaries/data/mods/public/gui/maps/mapbrowser/MapBrowser.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/maps/mapbrowser/MapBrowser.js (revision 27903) +++ ps/trunk/binaries/data/mods/public/gui/maps/mapbrowser/MapBrowser.js (revision 27904) @@ -1,67 +1,72 @@ class MapBrowser { constructor(mapCache, mapFilters, setupWindow = undefined) { this.openPageHandlers = new Set(); this.closePageHandlers = new Set(); this.mapCache = mapCache; this.mapFilters = mapFilters; this.mapBrowserPage = Engine.GetGUIObjectByName("mapBrowserPage"); this.mapBrowserPageDialog = Engine.GetGUIObjectByName("mapBrowserPageDialog"); this.gridBrowser = new MapGridBrowser(this, setupWindow); this.controls = new MapBrowserPageControls(this, this.gridBrowser); this.open = false; } submitMapSelection() { + if (!this.allowSelection) + return; + let file = this.gridBrowser.getSelected(); let type = this.controls.MapFiltering.getSelectedMapType(); let filter = this.controls.MapFiltering.getSelectedMapFilter(); if (file) { type = file.mapType; filter = file.filter; file = file.file; } this.onSubmitMapSelection( file, type, filter ); this.closePage(); } // TODO: this is mostly gamesetup specific stuff. registerOpenPageHandler(handler) { this.openPageHandlers.add(handler); } registerClosePageHandler(handler) { 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; } closePage() { if (!this.open) return; for (let handler of this.closePageHandlers) handler(); this.open = false; } } Index: ps/trunk/binaries/data/mods/public/gui/maps/mapbrowser/MapBrowserPage.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/maps/mapbrowser/MapBrowserPage.js (revision 27903) +++ ps/trunk/binaries/data/mods/public/gui/maps/mapbrowser/MapBrowserPage.js (revision 27904) @@ -1,17 +1,14 @@ /** * 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() { let cache = new MapCache(); 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"); } Index: ps/trunk/binaries/data/mods/public/gui/maps/mapbrowser/controls/MapBrowserControls.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/maps/mapbrowser/controls/MapBrowserControls.js (revision 27903) +++ ps/trunk/binaries/data/mods/public/gui/maps/mapbrowser/controls/MapBrowserControls.js (revision 27904) @@ -1,57 +1,68 @@ class MapBrowserPageControls { constructor(mapBrowserPage, gridBrowser) { for (let name in this) this[name] = new this[name](mapBrowserPage, gridBrowser); this.mapBrowserPage = mapBrowserPage; this.gridBrowser = gridBrowser; this.setupButtons(); } 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); this.gridBrowser.goToPageOfSelected(); }; this.select = Engine.GetGUIObjectByName("mapBrowserPageSelect"); 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; } onSelect() { 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.") + } + }; } Index: ps/trunk/binaries/data/mods/public/gui/maps/mapbrowser/controls/MapBrowserControls.xml =================================================================== --- ps/trunk/binaries/data/mods/public/gui/maps/mapbrowser/controls/MapBrowserControls.xml (revision 27903) +++ ps/trunk/binaries/data/mods/public/gui/maps/mapbrowser/controls/MapBrowserControls.xml (revision 27904) @@ -1,57 +1,55 @@ + Search Map: Map Type: Map Filter: Pick Random Map - - Cancel - + Select Index: ps/trunk/binaries/data/mods/public/gui/maps/mapbrowser/grid/MapGridBrowserItem.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/maps/mapbrowser/grid/MapGridBrowserItem.js (revision 27903) +++ ps/trunk/binaries/data/mods/public/gui/maps/mapbrowser/grid/MapGridBrowserItem.js (revision 27904) @@ -1,63 +1,62 @@ class MapGridBrowserItem extends GridBrowserItem { constructor(mapBrowserPage, mapGridBrowser, imageObject, itemIndex) { super(mapGridBrowser, imageObject, itemIndex); this.mapBrowserPage = mapBrowserPage; this.mapCache = mapBrowserPage.mapCache; this.mapPreview = Engine.GetGUIObjectByName("mapPreview[" + itemIndex + "]"); 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() { this.updateSprite(); } onGridResize() { super.onGridResize(); this.updateMapAssignment(); this.updateSprite(); } updateSprite() { this.imageObject.sprite = this.gridBrowser.selected == this.itemIndex + this.gridBrowser.currentPage * this.gridBrowser.itemsPerRow ? this.SelectedSprite : ""; } updateMapAssignment() { let map = this.gridBrowser.mapList[ this.itemIndex + this.gridBrowser.currentPage * this.gridBrowser.itemsPerRow] || undefined; if (!map) return; this.mapPreview.caption = map.name; this.imageObject.tooltip = map.description + "\n" + this.gridBrowser.container.tooltip; this.mapPreview.sprite = this.mapCache.getMapPreview(this.mapBrowserPage.controls.MapFiltering.getSelectedMapType(), map.file); } onMouseLeftDoubleClick() { this.mapBrowserPage.submitMapSelection(); } } MapGridBrowserItem.prototype.SelectedSprite = "color: 120 0 0 255";