Differential D2483 Diff 10698 binaries/data/mods/public/gui/gamesetup/GameSettings/PerPlayer/PlayerName.js
Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/gamesetup/GameSettings/PerPlayer/PlayerName.js
- This file was added.
Property | Old Value | New Value |
---|---|---|
svn:eol-style | null | native \ No newline at end of property |
// TODO: There should be an indication which player is not ready yet | |||||
// The color does not indicate it's meaning and is insufficient to inform many players. | |||||
class PlayerName | |||||
{ | |||||
constructor(playerIndex, netMessages, gameSettingsControl, playerAssignmentsControl) | |||||
{ | |||||
this.playerIndex = playerIndex; | |||||
this.gameSettingsControl = gameSettingsControl; | |||||
this.playerName = Engine.GetGUIObjectByName("playerName[" + playerIndex + "]"); | |||||
this.displayedName = undefined; | |||||
this.guid = undefined; | |||||
gameSettingsControl.registerGameAttributesChangeHandler(this.onGameAttributesChange.bind(this)); | |||||
gameSettingsControl.registerMapChangeHandler(this.onMapChange.bind(this)); | |||||
playerAssignmentsControl.registerPlayerAssignmentsChangeHandler(this.onPlayerAssignmentsChange.bind(this)); | |||||
} | |||||
onMapChange(mapData) | |||||
{ | |||||
let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex); | |||||
let mapPData = this.gameSettingsControl.getPlayerData(mapData, this.playerIndex); | |||||
if (!pData) | |||||
return; | |||||
pData.Name = mapPData && mapPData.Name || g_Settings.PlayerDefaults[this.playerIndex + 1].Name; | |||||
this.gameSettingsControl.updateGameAttributes(); | |||||
} | |||||
onGameAttributesChange() | |||||
{ | |||||
let pData = this.gameSettingsControl.getPlayerData(g_GameAttributes, this.playerIndex); | |||||
if (!pData) | |||||
return; | |||||
if (!pData.Name) | |||||
pData.Name = g_Settings.PlayerDefaults[this.playerIndex + 1].Name; | |||||
this.displayedName = g_IsNetworked ? pData.Name : translate(pData.Name); | |||||
this.rebuild(); | |||||
} | |||||
onPlayerAssignmentsChange() | |||||
{ | |||||
this.guid = undefined; | |||||
for (let guid in g_PlayerAssignments) | |||||
if (g_PlayerAssignments[guid].player == this.playerIndex + 1) | |||||
{ | |||||
this.guid = guid; | |||||
break; | |||||
} | |||||
this.rebuild(); | |||||
} | |||||
rebuild() | |||||
{ | |||||
let name = this.displayedName; | |||||
if (!name) | |||||
return; | |||||
if (g_IsNetworked) | |||||
{ | |||||
let status = this.guid ? g_PlayerAssignments[this.guid].status : this.ReadyTags.length - 1; | |||||
name = setStringTags(this.displayedName, this.ReadyTags[status]); | |||||
} | |||||
this.playerName.caption = name; | |||||
} | |||||
} | |||||
PlayerName.prototype.ReadyTags = [ | |||||
{ | |||||
"color": "white", | |||||
}, | |||||
{ | |||||
"color": "green", | |||||
}, | |||||
{ | |||||
"color": "150 150 250", | |||||
} | |||||
]; |
Wildfire Games · Phabricator