Differential D1461 Diff 15205 ps/trunk/binaries/data/mods/public/gui/session/chat/ChatMessageFormatSimulation.js
Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/session/chat/ChatMessageFormatSimulation.js
/** | /** | ||||
* These classes construct a chat message from simulation events initiated from the GuiInterface PushNotification method. | * These classes construct a chat message from simulation events initiated from the GuiInterface PushNotification method. | ||||
*/ | */ | ||||
class ChatMessageFormatSimulation | class ChatMessageFormatSimulation | ||||
{ | { | ||||
} | } | ||||
ChatMessageFormatSimulation.attack = class | ChatMessageFormatSimulation.attack = class | ||||
{ | { | ||||
parse(msg) | parse(msg) | ||||
{ | { | ||||
if (msg.player != g_ViewedPlayer) | if (msg.player != g_ViewedPlayer) | ||||
return ""; | return ""; | ||||
let message = msg.targetIsDomesticAnimal ? | let message = msg.targetIsDomesticAnimal ? | ||||
translate("Your livestock has been attacked by %(attacker)s!") : | translate("%(icon)sYour livestock has been attacked by %(attacker)s!") : | ||||
translate("You have been attacked by %(attacker)s!"); | translate("%(icon)sYou have been attacked by %(attacker)s!"); | ||||
return sprintf(message, { | return { | ||||
"text": sprintf(message, { | |||||
"icon": '[icon="icon_focusattacked"]', | |||||
"attacker": colorizePlayernameByID(msg.attacker) | "attacker": colorizePlayernameByID(msg.attacker) | ||||
}); | }), | ||||
"callback": ((entityId, position) => function() { | |||||
if (GetEntityState(entityId)) | |||||
setCameraFollow(entityId); | |||||
else | |||||
Engine.SetCameraTarget(position.x, position.y, position.z); | |||||
})(msg.target, msg.position), | |||||
"tooltip": translate("Click to focus on the attacked unit.") | |||||
}; | |||||
} | } | ||||
}; | }; | ||||
ChatMessageFormatSimulation.barter = class | ChatMessageFormatSimulation.barter = class | ||||
{ | { | ||||
parse(msg) | parse(msg) | ||||
{ | { | ||||
if (!g_IsObserver || Engine.ConfigDB_GetValue("user", "gui.session.notifications.barter") != "true") | if (!g_IsObserver || Engine.ConfigDB_GetValue("user", "gui.session.notifications.barter") != "true") | ||||
return ""; | return ""; | ||||
let amountGiven = {}; | let amountGiven = {}; | ||||
amountGiven[msg.resourceGiven] = msg.amountGiven; | amountGiven[msg.resourceGiven] = msg.amountGiven; | ||||
let amountGained = {}; | let amountGained = {}; | ||||
amountGained[msg.resourceGained] = msg.amountGained; | amountGained[msg.resourceGained] = msg.amountGained; | ||||
return sprintf(translate("%(player)s bartered %(amountGiven)s for %(amountGained)s."), { | return { | ||||
"text": sprintf(translate("%(player)s bartered %(amountGiven)s for %(amountGained)s."), { | |||||
"player": colorizePlayernameByID(msg.player), | "player": colorizePlayernameByID(msg.player), | ||||
"amountGiven": getLocalizedResourceAmounts(amountGiven), | "amountGiven": getLocalizedResourceAmounts(amountGiven), | ||||
"amountGained": getLocalizedResourceAmounts(amountGained) | "amountGained": getLocalizedResourceAmounts(amountGained) | ||||
}); | }) | ||||
}; | |||||
} | } | ||||
}; | }; | ||||
ChatMessageFormatSimulation.diplomacy = class | ChatMessageFormatSimulation.diplomacy = class | ||||
{ | { | ||||
parse(msg) | parse(msg) | ||||
{ | { | ||||
let messageType; | let messageType; | ||||
if (g_IsObserver) | if (g_IsObserver) | ||||
messageType = "observer"; | messageType = "observer"; | ||||
else if (Engine.GetPlayerID() == msg.sourcePlayer) | else if (Engine.GetPlayerID() == msg.sourcePlayer) | ||||
messageType = "active"; | messageType = "active"; | ||||
else if (Engine.GetPlayerID() == msg.targetPlayer) | else if (Engine.GetPlayerID() == msg.targetPlayer) | ||||
messageType = "passive"; | messageType = "passive"; | ||||
else | else | ||||
return ""; | return ""; | ||||
return sprintf(translate(this.strings[messageType][msg.status]), { | return { | ||||
"text": sprintf(translate(this.strings[messageType][msg.status]), { | |||||
"player": colorizePlayernameByID(messageType == "active" ? msg.targetPlayer : msg.sourcePlayer), | "player": colorizePlayernameByID(messageType == "active" ? msg.targetPlayer : msg.sourcePlayer), | ||||
"player2": colorizePlayernameByID(messageType == "active" ? msg.sourcePlayer : msg.targetPlayer) | "player2": colorizePlayernameByID(messageType == "active" ? msg.sourcePlayer : msg.targetPlayer) | ||||
}); | }) | ||||
}; | |||||
} | } | ||||
}; | }; | ||||
ChatMessageFormatSimulation.diplomacy.prototype.strings = { | ChatMessageFormatSimulation.diplomacy.prototype.strings = { | ||||
"active": { | "active": { | ||||
"ally": markForTranslation("You are now allied with %(player)s."), | "ally": markForTranslation("You are now allied with %(player)s."), | ||||
"enemy": markForTranslation("You are now at war with %(player)s."), | "enemy": markForTranslation("You are now at war with %(player)s."), | ||||
"neutral": markForTranslation("You are now neutral with %(player)s.") | "neutral": markForTranslation("You are now neutral with %(player)s.") | ||||
Show All 24 Lines | if (notifyPhase == "all") | ||||
if (msg.phaseState == "started") | if (msg.phaseState == "started") | ||||
message = translate("%(player)s is advancing to the %(phaseName)s."); | message = translate("%(player)s is advancing to the %(phaseName)s."); | ||||
else if (msg.phaseState == "aborted") | else if (msg.phaseState == "aborted") | ||||
message = translate("The %(phaseName)s of %(player)s has been aborted."); | message = translate("The %(phaseName)s of %(player)s has been aborted."); | ||||
} | } | ||||
if (msg.phaseState == "completed") | if (msg.phaseState == "completed") | ||||
message = translate("%(player)s has reached the %(phaseName)s."); | message = translate("%(player)s has reached the %(phaseName)s."); | ||||
return sprintf(message, { | return { | ||||
"text": sprintf(message, { | |||||
"player": colorizePlayernameByID(msg.player), | "player": colorizePlayernameByID(msg.player), | ||||
"phaseName": getEntityNames(GetTechnologyData(msg.phaseName, g_Players[msg.player].civ)) | "phaseName": getEntityNames(GetTechnologyData(msg.phaseName, g_Players[msg.player].civ)) | ||||
}); | }) | ||||
}; | |||||
} | } | ||||
}; | }; | ||||
ChatMessageFormatSimulation.playerstate = class | ChatMessageFormatSimulation.playerstate = class | ||||
{ | { | ||||
parse(msg) | parse(msg) | ||||
{ | { | ||||
if (!msg.message.pluralMessage) | if (!msg.message.pluralMessage) | ||||
return sprintf(translate(msg.message), { | return { | ||||
"text": sprintf(translate(msg.message), { | |||||
"player": colorizePlayernameByID(msg.players[0]) | "player": colorizePlayernameByID(msg.players[0]) | ||||
}); | }) | ||||
}; | |||||
let mPlayers = msg.players.map(playerID => colorizePlayernameByID(playerID)); | let mPlayers = msg.players.map(playerID => colorizePlayernameByID(playerID)); | ||||
let lastPlayer = mPlayers.pop(); | let lastPlayer = mPlayers.pop(); | ||||
return sprintf(translatePlural(msg.message.message, msg.message.pluralMessage, msg.message.pluralCount), { | return { | ||||
"text": sprintf(translatePlural(msg.message.message, msg.message.pluralMessage, msg.message.pluralCount), { | |||||
// Translation: This comma is used for separating first to penultimate elements in an enumeration. | // Translation: This comma is used for separating first to penultimate elements in an enumeration. | ||||
"players": mPlayers.join(translate(", ")), | "players": mPlayers.join(translate(", ")), | ||||
"lastPlayer": lastPlayer | "lastPlayer": lastPlayer | ||||
}); | }) | ||||
}; | |||||
} | } | ||||
}; | }; | ||||
/** | /** | ||||
* Optionally show all tributes sent in observer mode and tributes sent between allied players. | * Optionally show all tributes sent in observer mode and tributes sent between allied players. | ||||
* Otherwise, only show tributes sent directly to us, and tributes that we send. | * Otherwise, only show tributes sent directly to us, and tributes that we send. | ||||
*/ | */ | ||||
ChatMessageFormatSimulation.tribute = class | ChatMessageFormatSimulation.tribute = class | ||||
{ | { | ||||
parse(msg) | parse(msg) | ||||
{ | { | ||||
let message = ""; | let message = ""; | ||||
if (msg.targetPlayer == Engine.GetPlayerID()) | if (msg.targetPlayer == Engine.GetPlayerID()) | ||||
message = translate("%(player)s has sent you %(amounts)s."); | message = translate("%(player)s has sent you %(amounts)s."); | ||||
else if (msg.sourcePlayer == Engine.GetPlayerID()) | else if (msg.sourcePlayer == Engine.GetPlayerID()) | ||||
message = translate("You have sent %(player2)s %(amounts)s."); | message = translate("You have sent %(player2)s %(amounts)s."); | ||||
else if (Engine.ConfigDB_GetValue("user", "gui.session.notifications.tribute") == "true" && | else if (Engine.ConfigDB_GetValue("user", "gui.session.notifications.tribute") == "true" && | ||||
(g_IsObserver || g_GameAttributes.settings.LockTeams && | (g_IsObserver || g_GameAttributes.settings.LockTeams && | ||||
g_Players[msg.sourcePlayer].isMutualAlly[Engine.GetPlayerID()] && | g_Players[msg.sourcePlayer].isMutualAlly[Engine.GetPlayerID()] && | ||||
g_Players[msg.targetPlayer].isMutualAlly[Engine.GetPlayerID()])) | g_Players[msg.targetPlayer].isMutualAlly[Engine.GetPlayerID()])) | ||||
message = translate("%(player)s has sent %(player2)s %(amounts)s."); | message = translate("%(player)s has sent %(player2)s %(amounts)s."); | ||||
return sprintf(message, { | return { | ||||
"text": sprintf(message, { | |||||
"player": colorizePlayernameByID(msg.sourcePlayer), | "player": colorizePlayernameByID(msg.sourcePlayer), | ||||
"player2": colorizePlayernameByID(msg.targetPlayer), | "player2": colorizePlayernameByID(msg.targetPlayer), | ||||
"amounts": getLocalizedResourceAmounts(msg.amounts) | "amounts": getLocalizedResourceAmounts(msg.amounts) | ||||
}); | }) | ||||
}; | |||||
} | } | ||||
}; | }; |
Wildfire Games · Phabricator