Differential D3243 Diff 16284 binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/PerPlayer/Dropdowns/PlayerCiv.js
Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/PerPlayer/Dropdowns/PlayerCiv.js
PlayerSettingControls.PlayerCiv = class extends GameSettingControlDropdown | PlayerSettingControls.PlayerCiv = class extends GameSettingControlDropdown | ||||
{ | { | ||||
constructor(...args) | constructor(...args) | ||||
{ | { | ||||
super(...args); | super(...args); | ||||
this.fixedCiv = undefined; | |||||
this.values = prepareForDropdown(this.getItems()); | this.values = prepareForDropdown(this.getItems()); | ||||
this.dropdown.list = this.values.name; | this.dropdown.list = this.values.name; | ||||
this.dropdown.list_data = this.values.civ; | this.dropdown.list_data = this.values.civ; | ||||
g_NewGameSettings.playerCiv.watch(() => this.render(), ["values", "locked"]); | |||||
this.render(); | |||||
} | } | ||||
setControl() | setControl() | ||||
{ | { | ||||
this.label = Engine.GetGUIObjectByName("playerCivText[" + this.playerIndex + "]"); | this.label = Engine.GetGUIObjectByName("playerCivText[" + this.playerIndex + "]"); | ||||
this.dropdown = Engine.GetGUIObjectByName("playerCiv[" + this.playerIndex + "]"); | this.dropdown = Engine.GetGUIObjectByName("playerCiv[" + this.playerIndex + "]"); | ||||
} | } | ||||
onHoverChange() | onHoverChange() | ||||
{ | { | ||||
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; | ||||
} | } | ||||
onMapChange(mapData) | render() | ||||
{ | |||||
let mapPData = this.gameSettingsControl.getPlayerData(mapData, this.playerIndex); | |||||
this.fixedCiv = mapPData && mapPData.Civ || undefined; | |||||
} | |||||
onAssignPlayer(source, target) | |||||
{ | |||||
if (g_GameAttributes.mapType != "scenario" && source && target) | |||||
[source.Civ, target.Civ] = [target.Civ, source.Civ]; | |||||
} | |||||
onGameAttributesChange() | |||||
{ | |||||
let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex); | |||||
if (!pData || !g_GameAttributes.mapType) | |||||
return; | |||||
if (this.fixedCiv) | |||||
{ | { | ||||
if (!pData.Civ || this.fixedCiv != pData.Civ) | this.setEnabled(!g_NewGameSettings.playerCiv.locked[this.playerIndex]); | ||||
{ | this.setSelectedValue(g_NewGameSettings.playerCiv.values[this.playerIndex]); | ||||
pData.Civ = this.fixedCiv; | |||||
this.gameSettingsControl.updateGameAttributes(); | |||||
} | |||||
} | |||||
else if (this.values.civ.indexOf(pData.Civ || undefined) == -1) | |||||
{ | |||||
pData.Civ = | |||||
g_GameAttributes.mapType == "scenario" ? | |||||
g_Settings.PlayerDefaults[this.playerIndex + 1].Civ : | |||||
this.RandomCivId; | |||||
this.gameSettingsControl.updateGameAttributes(); | |||||
} | |||||
} | |||||
onGameAttributesBatchChange() | |||||
{ | |||||
let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex); | |||||
if (!pData || !g_GameAttributes.mapType) | |||||
return; | |||||
this.setEnabled(!this.fixedCiv); | |||||
this.setSelectedValue(pData.Civ); | |||||
} | } | ||||
getItems() | getItems() | ||||
{ | { | ||||
let values = []; | let values = []; | ||||
for (let civ in g_CivData) | for (let civ in g_CivData) | ||||
if (g_CivData[civ].SelectableInGameSetup) | if (g_CivData[civ].SelectableInGameSetup) | ||||
Show All 18 Lines | PlayerSettingControls.PlayerCiv = class extends GameSettingControlDropdown | ||||
getAutocompleteEntries() | getAutocompleteEntries() | ||||
{ | { | ||||
return this.values.autocomplete; | return this.values.autocomplete; | ||||
} | } | ||||
onSelectionChange(itemIdx) | onSelectionChange(itemIdx) | ||||
{ | { | ||||
let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex); | g_NewGameSettings.playerCiv.setValue(this.playerIndex, this.values.civ[itemIdx]); | ||||
pData.Civ = this.values.civ[itemIdx]; | |||||
this.gameSettingsControl.updateGameAttributes(); | |||||
this.gameSettingsControl.setNetworkGameAttributes(); | this.gameSettingsControl.setNetworkGameAttributes(); | ||||
} | } | ||||
onPickRandomItems() | |||||
{ | |||||
let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex); | |||||
if (!pData || pData.Civ != this.RandomCivId) | |||||
return; | |||||
// Get a unique array of selectable cultures | |||||
let cultures = Object.keys(g_CivData).filter(civ => g_CivData[civ].SelectableInGameSetup).map(civ => g_CivData[civ].Culture); | |||||
cultures = cultures.filter((culture, index) => cultures.indexOf(culture) === index); | |||||
// Pick a random civ of a random culture | |||||
let culture = pickRandom(cultures); | |||||
pData.Civ = pickRandom(Object.keys(g_CivData).filter(civ => | |||||
g_CivData[civ].Culture == culture && g_CivData[civ].SelectableInGameSetup)); | |||||
this.gameSettingsControl.updateGameAttributes(); | |||||
this.gameSettingsControl.pickRandomItems(); | |||||
} | |||||
}; | }; | ||||
PlayerSettingControls.PlayerCiv.prototype.Tooltip = | PlayerSettingControls.PlayerCiv.prototype.Tooltip = | ||||
translate("Choose the civilization for this player."); | translate("Choose the civilization for this player."); | ||||
PlayerSettingControls.PlayerCiv.prototype.RandomCivCaption = | PlayerSettingControls.PlayerCiv.prototype.RandomCivCaption = | ||||
translateWithContext("civilization", "Random"); | translateWithContext("civilization", "Random"); | ||||
PlayerSettingControls.PlayerCiv.prototype.RandomCivId = | PlayerSettingControls.PlayerCiv.prototype.RandomCivId = | ||||
"random"; | "random"; | ||||
PlayerSettingControls.PlayerCiv.prototype.RandomCivTooltip = | PlayerSettingControls.PlayerCiv.prototype.RandomCivTooltip = | ||||
translate("Picks one civilization at random when the game starts."); | translate("Picks one civilization at random when the game starts."); | ||||
PlayerSettingControls.PlayerCiv.prototype.AutocompleteOrder = 90; | PlayerSettingControls.PlayerCiv.prototype.AutocompleteOrder = 90; |
Wildfire Games · Phabricator