1
0
forked from 0ad/0ad

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.
This commit is contained in:
Angen 2022-02-20 07:34:11 +00:00
parent 26644da270
commit daada92a82

View File

@ -4,13 +4,13 @@ PlayerSettingControls.PlayerCiv = class PlayerCiv extends GameSettingControlDrop
{ {
super(...args); super(...args);
this.values = prepareForDropdown(this.getItems()); g_GameSettings.playerCiv.watch(() => this.rebuild(), ["values", "locked"]);
this.dropdown.list = this.values.name; this.items = this.getItems(false);
this.dropdown.list_data = this.values.civ; this.allItems = this.getItems(true);
this.wasLocked = undefined;
g_GameSettings.playerCiv.watch(() => this.render(), ["values", "locked"]); this.rebuild();
this.render();
} }
setControl() setControl()
@ -24,18 +24,36 @@ PlayerSettingControls.PlayerCiv = class PlayerCiv extends GameSettingControlDrop
this.dropdown.tooltip = this.values && this.values.tooltip[this.dropdown.hovered] || this.Tooltip; 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() render()
{ {
this.setEnabled(!g_GameSettings.playerCiv.locked[this.playerIndex]); this.setEnabled(!g_GameSettings.playerCiv.locked[this.playerIndex]);
this.setSelectedValue(g_GameSettings.playerCiv.values[this.playerIndex]); this.setSelectedValue(g_GameSettings.playerCiv.values[this.playerIndex]);
} }
getItems() getItems(allItems)
{ {
let values = []; let values = [];
for (let civ in g_CivData) for (let civ in g_CivData)
if (g_CivData[civ].SelectableInGameSetup) if (allItems || g_CivData[civ].SelectableInGameSetup)
values.push({ values.push({
"name": g_CivData[civ].Name, "name": g_CivData[civ].Name,
"autocomplete": g_CivData[civ].Name, "autocomplete": g_CivData[civ].Name,