Differential D3243 Diff 16556 ps/trunk/binaries/data/mods/public/gui/gamesetup/Pages/AIConfigPage/Controls/AIDifficulty.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/gamesetup/Pages/AIConfigPage/Controls/AIDifficulty.js
AIGameSettingControls.AIDifficulty = class extends AIGameSettingControlDropdown | AIGameSettingControls.AIDifficulty = class extends AIGameSettingControlDropdown | ||||
{ | { | ||||
constructor(...args) | constructor(...args) | ||||
{ | { | ||||
super(...args); | super(...args); | ||||
this.fixedAIDiff = []; | g_GameSettings.playerAI.watch(() => this.render(), ["values"]); | ||||
this.defaultAIDiff = +Engine.ConfigDB_GetValue("user", this.ConfigDifficulty); | |||||
this.dropdown.list = g_Settings.AIDifficulties.map(AI => AI.Title); | |||||
this.dropdown.list_data = g_Settings.AIDifficulties.map((AI, i) => i); | |||||
} | |||||
onAssignPlayer(source, target) | |||||
{ | |||||
if (source && target.AIDiff !== undefined) | |||||
source.AIDiff = target.AIDiff; | |||||
delete target.AIDiff; | |||||
} | } | ||||
onMapChange(mapData) | render() | ||||
{ | |||||
for (let playerIndex = 0; playerIndex < g_MaxPlayers; ++playerIndex) | |||||
{ | |||||
let mapPData = this.gameSettingsControl.getPlayerData(mapData, playerIndex); | |||||
this.fixedAIDiff[playerIndex] = | |||||
mapPData && mapPData.AI ? | |||||
(mapPData.AIDiff !== undefined ? | |||||
mapPData.AIDiff : | |||||
g_Settings.PlayerDefaults[playerIndex + 1].AIDiff) : | |||||
undefined; | |||||
} | |||||
} | |||||
onGameAttributesChangePlayer(playerIndex) | |||||
{ | |||||
let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, playerIndex); | |||||
if (!pData) | |||||
return; | |||||
if (pData.AI) | |||||
{ | { | ||||
if (this.fixedAIDiff[playerIndex] !== undefined && | this.dropdown.list = g_Settings.AIDifficulties.map(AI => AI.Title); | ||||
(pData.AIDiff === undefined || | this.dropdown.list_data = g_Settings.AIDifficulties.map((AI, i) => i); | ||||
pData.AIDiff !== this.fixedAIDiff[playerIndex])) | |||||
{ | |||||
pData.AIDiff = this.fixedAIDiff[playerIndex]; | |||||
this.gameSettingsControl.updateGameAttributes(); | |||||
} | |||||
else if (pData.AIDiff === undefined) | |||||
{ | |||||
pData.AIDiff = this.defaultAIDiff; | |||||
this.gameSettingsControl.updateGameAttributes(); | |||||
} | |||||
} | |||||
else if (pData.AIDiff !== undefined) | |||||
{ | |||||
delete pData.AIDiff; | |||||
this.gameSettingsControl.updateGameAttributes(); | |||||
} | |||||
} | |||||
updateSelectedValue() | |||||
{ | |||||
let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex); | |||||
this.setHidden(!pData || !pData.AI); | |||||
if (pData && pData.AIDiff !== undefined) | let ai = g_GameSettings.playerAI.get(this.playerIndex); | ||||
this.setSelectedValue(pData.AIDiff); | this.setHidden(!ai); | ||||
if (!!ai) | |||||
this.setSelectedValue(ai.difficulty); | |||||
} | } | ||||
onSelectionChange(itemIdx) | onSelectionChange(itemIdx) | ||||
{ | { | ||||
let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex); | g_GameSettings.playerAI.setDifficulty(this.playerIndex, this.dropdown.list_data[itemIdx]); | ||||
if (!g_IsController || !pData) | |||||
return; | |||||
pData.AIDiff = itemIdx; | |||||
this.gameSettingsControl.updateGameAttributes(); | |||||
this.gameSettingsControl.setNetworkGameAttributes(); | this.gameSettingsControl.setNetworkGameAttributes(); | ||||
} | } | ||||
}; | }; | ||||
AIGameSettingControls.AIDifficulty.prototype.ConfigDifficulty = | AIGameSettingControls.AIDifficulty.prototype.ConfigDifficulty = | ||||
"gui.gamesetup.aidifficulty"; | "gui.gamesetup.aidifficulty"; | ||||
AIGameSettingControls.AIDifficulty.prototype.TitleCaption = | AIGameSettingControls.AIDifficulty.prototype.TitleCaption = | ||||
translate("AI Difficulty"); | translate("AI Difficulty"); |
Wildfire Games · Phabricator