From daada92a82a1a2b882ddc526a7edb4c0e769e194 Mon Sep 17 00:00:00 2001 From: Angen Date: Sun, 20 Feb 2022 07:34:11 +0000 Subject: [PATCH] Fix not selectable civilisations not showing if defined by the map Fix displaying unknow civilisation when civilisation defined by map is not selectable but exists by switching two lists based on if selection is locked or not. Differential revision: D4429 Fixes: #6145 Reviewed by: @bb This was SVN commit r26438. --- .../PerPlayer/Dropdowns/PlayerCiv.js | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/PerPlayer/Dropdowns/PlayerCiv.js b/binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/PerPlayer/Dropdowns/PlayerCiv.js index d754c883b0..949cb54ff7 100644 --- a/binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/PerPlayer/Dropdowns/PlayerCiv.js +++ b/binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/PerPlayer/Dropdowns/PlayerCiv.js @@ -4,13 +4,13 @@ PlayerSettingControls.PlayerCiv = class PlayerCiv extends GameSettingControlDrop { super(...args); - this.values = prepareForDropdown(this.getItems()); + g_GameSettings.playerCiv.watch(() => this.rebuild(), ["values", "locked"]); - this.dropdown.list = this.values.name; - this.dropdown.list_data = this.values.civ; + this.items = this.getItems(false); + this.allItems = this.getItems(true); + this.wasLocked = undefined; - g_GameSettings.playerCiv.watch(() => this.render(), ["values", "locked"]); - this.render(); + this.rebuild(); } setControl() @@ -24,18 +24,36 @@ PlayerSettingControls.PlayerCiv = class PlayerCiv extends GameSettingControlDrop this.dropdown.tooltip = this.values && this.values.tooltip[this.dropdown.hovered] || this.Tooltip; } + rebuild() + { + const isLocked = g_GameSettings.playerCiv.locked[this.playerIndex]; + if (this.wasLocked !== isLocked) + { + this.wasLocked = isLocked; + this.values = prepareForDropdown(isLocked ? this.allItems : this.items); + + this.dropdown.list = this.values.name; + this.dropdown.list_data = this.values.civ; + + // If not locked, reset selection, else we can end up with empty label. + if (!isLocked && g_IsController && g_GameSettings.playerCiv.values[this.playerIndex]) + this.onSelectionChange(0); + } + this.render(); + } + render() { this.setEnabled(!g_GameSettings.playerCiv.locked[this.playerIndex]); this.setSelectedValue(g_GameSettings.playerCiv.values[this.playerIndex]); } - getItems() + getItems(allItems) { let values = []; for (let civ in g_CivData) - if (g_CivData[civ].SelectableInGameSetup) + if (allItems || g_CivData[civ].SelectableInGameSetup) values.push({ "name": g_CivData[civ].Name, "autocomplete": g_CivData[civ].Name,