This repository has been archived by the owner on Jun 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: reduce code footprint for chat messages
replace the resource name with an icon
- Loading branch information
1 parent
5bdcacf
commit b8731af
Showing
6 changed files
with
131 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 2 additions & 3 deletions
5
gui/gamesetup/Pages/GameSetupPage/Panels/Chat/ChatMessages/ClientReady~boongui.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
ChatMessageEvents.ClientReady.prototype.ReadyMessage = [ | ||
translate("--- %(username)s is not ready."), | ||
translate("+++ %(username)s is ready!") | ||
translate("* %(username)s is not ready.").replace(/^\*/, "---"), | ||
translate("* %(username)s is ready!").replace(/^\*/, "+++") | ||
]; | ||
|
||
ChatMessageEvents.ClientReady.prototype.MessageTags = { | ||
"font": "sans-stroke-14" | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
100 changes: 100 additions & 0 deletions
100
gui/session/chat/ChatMessageFormatSimulation~boongui.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Remove the last "period" in some messages, ".slice(0, -1)" would work too, but regex is safer | ||
const Regex_Period = /\.$/; | ||
|
||
ChatMessageFormatSimulation.attack.prototype.parse = function(msg) | ||
{ | ||
if (msg.player != g_ViewedPlayer) | ||
return ""; | ||
|
||
const message = msg.targetIsDomesticAnimal ? | ||
translate("%(icon)sYour livestock has been attacked by %(attacker)s!") : | ||
translate("%(icon)sYou have been attacked by %(attacker)s!"); | ||
|
||
return { | ||
"text": sprintf(message, { | ||
"icon": '[icon="icon_focusattacked" displace="0 1"]', | ||
"attacker": colorizePlayernameByID(msg.attacker) | ||
}), | ||
"callback": ((target, position) => function() { | ||
focusAttack({ target, position }); | ||
})(msg.target, msg.position), | ||
"tooltip": translate("Click to focus on the attacked unit.") | ||
}; | ||
}; | ||
|
||
ChatMessageFormatSimulation.phase.prototype.parse = function(msg) | ||
{ | ||
const notifyPhase = Engine.ConfigDB_GetValue("user", "gui.session.notifications.phase"); | ||
if (notifyPhase == "none" || msg.player != g_ViewedPlayer && !g_IsObserver && !g_Players[msg.player].isMutualAlly[g_ViewedPlayer]) | ||
return ""; | ||
|
||
let message = ""; | ||
if (notifyPhase == "all") | ||
{ | ||
if (msg.phaseState == "started") | ||
message = translate("%(player)s is advancing to the %(phaseName)s."); | ||
else if (msg.phaseState == "aborted") | ||
message = translate("The %(phaseName)s of %(player)s has been aborted."); | ||
} | ||
if (msg.phaseState == "completed") | ||
message = translate("%(player)s has reached the %(phaseName)s."); | ||
|
||
if (!message) | ||
return ""; | ||
message = `%(time)s ${message}`; | ||
return { | ||
"text": coloredText(sprintf(message.replace(Regex_Period, ""), { | ||
"time": Engine.FormatMillisecondsIntoDateStringLocal(g_SimState.timeElapsed, translate("m:ss")), | ||
"player": colorizePlayernameByID(msg.player), | ||
"phaseName": getEntityNames(GetTechnologyData(msg.phaseName, g_Players[msg.player])) | ||
}), brightenedColor(rgbToGuiColor(g_DiplomacyColors.displayedPlayerColors[msg.player]))) | ||
}; | ||
}; | ||
|
||
ChatMessageFormatSimulation.barter.prototype.parse = function(msg) | ||
{ | ||
if (!g_IsObserver || Engine.ConfigDB_GetValue("user", "gui.session.notifications.barter") != "true") | ||
return ""; | ||
|
||
const amountGiven = {}; | ||
amountGiven[msg.resourceGiven] = msg.amountGiven; | ||
|
||
const amountGained = {}; | ||
amountGained[msg.resourceGained] = msg.amountGained; | ||
|
||
return { | ||
"text": sprintf(translate("%(player)s bartered %(amountGiven)s for %(amountGained)s.").replace(Regex_Period, ""), { | ||
"player": colorizePlayernameByID(msg.player), | ||
"amountGiven": getLocalizedResourceAmounts(amountGiven, "200 0 0"), | ||
"amountGained": getLocalizedResourceAmounts(amountGained, "0 200 0") | ||
}) | ||
}; | ||
}; | ||
|
||
ChatMessageFormatSimulation.tribute.prototype.parse = function(msg) | ||
{ | ||
let message, color; | ||
if (msg.targetPlayer == Engine.GetPlayerID()) | ||
{ | ||
message = translate("%(player)s has sent you %(amounts)s."); | ||
color = "green"; | ||
} | ||
else if (msg.sourcePlayer == Engine.GetPlayerID()) | ||
{ | ||
message = translate("You have sent %(player2)s %(amounts)s."); | ||
color = "red"; | ||
} | ||
else if (Engine.ConfigDB_GetValue("user", "gui.session.notifications.tribute") == "true" && | ||
(g_IsObserver || g_InitAttributes.settings.LockTeams && | ||
g_Players[msg.sourcePlayer].isMutualAlly[Engine.GetPlayerID()] && | ||
g_Players[msg.targetPlayer].isMutualAlly[Engine.GetPlayerID()])) | ||
message = translate("%(player)s has sent %(player2)s %(amounts)s."); | ||
|
||
return { | ||
"text": sprintf(message.replace(Regex_Period, ""), { | ||
"player": colorizePlayernameByID(msg.sourcePlayer), | ||
"player2": colorizePlayernameByID(msg.targetPlayer), | ||
"amounts": getLocalizedResourceAmounts(msg.amounts, color) | ||
}) | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters