Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/session/DiplomacyColors.js
/** | /** | ||||
* This class determines the player colors to be displayed. | * This class determines the player colors to be displayed. | ||||
* If diplomacy color mode is disabled, it picks the player color chosen by the map or the players. | * If diplomacy color mode is disabled, it picks the player color chosen by the map or the players. | ||||
* If diplomacy color mode is enabled, it choses the player chosen color based on diplomatic stance. | * If diplomacy color mode is enabled, it choses the player chosen color based on diplomatic stance. | ||||
* Observers that didn't chose a specific player perspective see each team in one representative color. | * Observers that didn't chose a specific player perspective see each team in one representative color. | ||||
*/ | */ | ||||
class DiplomacyColors | class DiplomacyColors | ||||
{ | { | ||||
constructor() | constructor() | ||||
{ | { | ||||
this.enabled = false; | this.enabled = false; | ||||
// The array of displayed player colors (either the diplomacy color or regular color for each player). | // The array of displayed player colors (either the diplomacy color or regular color for each player). | ||||
this.displayedPlayerColors = undefined; | this.displayedPlayerColors = undefined; | ||||
this.diplomacyColorsChangeHandlers = []; | |||||
registerPlayersInitHandler(this.onPlayersInit.bind(this)); | |||||
} | |||||
registerDiplomacyColorsChangeHandler(handler) | |||||
{ | |||||
this.diplomacyColorsChangeHandlers.push(handler); | |||||
} | } | ||||
onPlayerInit() | onPlayersInit() | ||||
{ | { | ||||
this.computeTeamColors(); | this.computeTeamColors(); | ||||
} | } | ||||
onDiplomacyChange() | onDiplomacyChange() | ||||
{ | { | ||||
if (this.enabled) | if (this.enabled) | ||||
this.updateDisplayedPlayerColors(); | this.updateDisplayedPlayerColors(); | ||||
Show All 30 Lines | updateDisplayedPlayerColors() | ||||
Engine.GuiInterfaceCall("UpdateDisplayedPlayerColors", { | Engine.GuiInterfaceCall("UpdateDisplayedPlayerColors", { | ||||
"displayedPlayerColors": this.displayedPlayerColors, | "displayedPlayerColors": this.displayedPlayerColors, | ||||
"displayDiplomacyColors": this.enabled, | "displayDiplomacyColors": this.enabled, | ||||
"showAllStatusBars": g_ShowAllStatusBars, | "showAllStatusBars": g_ShowAllStatusBars, | ||||
"selected": g_Selection.toList() | "selected": g_Selection.toList() | ||||
}); | }); | ||||
updateGUIObjects(); | for (let handler of this.diplomacyColorsChangeHandlers) | ||||
handler(this.enabled); | |||||
} | } | ||||
computeTeamColors() | computeTeamColors() | ||||
{ | { | ||||
if (!this.enabled) | if (!this.enabled) | ||||
{ | { | ||||
this.displayedPlayerColors = g_Players.map(player => player.color); | this.displayedPlayerColors = g_Players.map(player => player.color); | ||||
return; | return; | ||||
Show All 29 Lines |
Wildfire Games · Phabricator