Differential D4183 Diff 18333 ps/trunk/binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/PerPlayer/Dropdowns/PlayerColor.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/gamesetup/Pages/GameSetupPage/GameSettings/PerPlayer/Dropdowns/PlayerColor.js
Show All 14 Lines | setControl() | ||||
this.playerColorHeading = Engine.GetGUIObjectByName("playerColorHeading"); | this.playerColorHeading = Engine.GetGUIObjectByName("playerColorHeading"); | ||||
} | } | ||||
render() | render() | ||||
{ | { | ||||
if (g_GameSettings.playerCount.nbPlayers < this.playerIndex + 1) | if (g_GameSettings.playerCount.nbPlayers < this.playerIndex + 1) | ||||
return; | return; | ||||
let hidden = !g_IsController || g_GameSettings.map.type == "scenario"; | const hidden = !g_IsController || g_GameSettings.map.type == "scenario"; | ||||
this.dropdown.hidden = hidden; | this.dropdown.hidden = hidden; | ||||
this.playerColorHeading.hidden = hidden; | this.playerColorHeading.hidden = hidden; | ||||
let value = g_GameSettings.playerColor.get(this.playerIndex); | const value = g_GameSettings.playerColor.get(this.playerIndex); | ||||
this.setSelectedValue(value); | |||||
this.playerBackgroundColor.sprite = "color:" + rgbToGuiColor(value, 100); | this.playerBackgroundColor.sprite = "color:" + rgbToGuiColor(value, 100); | ||||
this.values = g_GameSettings.playerColor.available; | this.values = g_GameSettings.playerColor.available; | ||||
this.dropdown.list = this.values.map(color => coloredText(this.ColorIcon, rgbToGuiColor(color))); | this.dropdown.list = this.values.map(color => coloredText(this.ColorIcon, rgbToGuiColor(color))); | ||||
this.dropdown.list_data = this.values.map((color, i) => i); | this.dropdown.list_data = this.values.map((color, i) => i); | ||||
this.setSelectedValue(this.values.map((color, i) => { | |||||
if (color.r === value.r && color.g === value.g && color.b === value.b) | |||||
return i; | |||||
return undefined; | |||||
}).filter(x => x !== undefined)?.[0] ?? -1); | |||||
} | } | ||||
onSelectionChange(itemIdx) | onSelectionChange(itemIdx) | ||||
{ | { | ||||
g_GameSettings.playerColor.setColor(this.playerIndex, this.values[itemIdx]); | g_GameSettings.playerColor.setColor(this.playerIndex, this.values[itemIdx]); | ||||
this.gameSettingsController.setNetworkInitAttributes(); | this.gameSettingsController.setNetworkInitAttributes(); | ||||
} | } | ||||
}; | }; | ||||
PlayerSettingControls.PlayerColor.prototype.Tooltip = | PlayerSettingControls.PlayerColor.prototype.Tooltip = | ||||
translate("Pick a color."); | translate("Pick a color."); | ||||
PlayerSettingControls.PlayerColor.prototype.ColorIcon = | PlayerSettingControls.PlayerColor.prototype.ColorIcon = | ||||
"■"; | "■"; |
Wildfire Games · Phabricator