Index: binaries/data/mods/mod/gui/common/guitags.js =================================================================== --- binaries/data/mods/mod/gui/common/guitags.js +++ binaries/data/mods/mod/gui/common/guitags.js @@ -1,5 +1,7 @@ /** * Add color to text string. + * Only use this when building the tags for setStringTags is undesirable from a performance point of view + * and the tag can't be created/stored somewhere with less impact. */ function coloredText(text, color) { Index: binaries/data/mods/mod/gui/modmod/modmod.js =================================================================== --- binaries/data/mods/mod/gui/modmod/modmod.js +++ binaries/data/mods/mod/gui/modmod/modmod.js @@ -53,9 +53,10 @@ */ var g_InstalledMods; -var g_ColorNoModSelected = "255 255 100"; -var g_ColorDependenciesMet = "100 255 100"; -var g_ColorDependenciesNotMet = "255 100 100"; +var g_NoModSelectedTextTags = { "color": "255 255 100" }; +var g_DependenciesMetTextTags = { "color": "100 255 100" }; +var g_DependenciesNotMetTextTags = { "color": "255 100 100" }; +var g_ModInstalledTextTags = { "color": "green" }; function init(data, hotloadData) { @@ -146,7 +147,7 @@ folders = folders.filter(filterMod); - listObject.list_name = folders.map(folder => g_Mods[folder].name).map(name => g_InstalledMods.indexOf(name) == -1 ? name : coloredText(name, "green")); + listObject.list_name = folders.map(folder => g_Mods[folder].name).map(name => g_InstalledMods.indexOf(name) == -1 ? name : setStringTags(name, g_ModInstalledTextTags)); listObject.list_folder = folders; listObject.list_label = folders.map(folder => g_Mods[folder].label); listObject.list_url = folders.map(folder => g_Mods[folder].url || ""); @@ -282,14 +283,14 @@ if (isDependencyMet(dependency)) continue; - guiObject.caption = coloredText( + guiObject.caption = setStringTags( sprintf(translate('Dependency not met: %(dep)s'), { "dep": dependency }), - g_ColorDependenciesNotMet); + g_DependenciesNotMetTextTags); return false; } - guiObject.caption = coloredText(translate('All dependencies met'), g_ColorDependenciesMet); + guiObject.caption = setStringTags(translate('All dependencies met'), g_DependenciesMetTextTags); return true; } @@ -377,7 +378,7 @@ Engine.GetGUIObjectByName("globalModDescription").caption = listObject.list[listObject.selected] ? g_Mods[listObject.list[listObject.selected]].description : - '[color="' + g_ColorNoModSelected + '"]' + translate("No mod has been selected.") + '[/color]'; + setStringTags(translate("No mod has been selected."), g_NoModSelectedTextTags); } function visitModWebsite() Index: binaries/data/mods/public/gui/civinfo/civinfo.js =================================================================== --- binaries/data/mods/public/gui/civinfo/civinfo.js +++ binaries/data/mods/public/gui/civinfo/civinfo.js @@ -3,6 +3,13 @@ */ const g_CivData = loadCivData(true, false); +/** + * Font tags of the Name, History and Description. + */ +var g_NameHistoryDescriptionTextTags = { + "name": { "font": "sans-bold-14" } +}; + var g_SelectedCiv = ""; /** @@ -26,7 +33,7 @@ */ function bigFirstLetter(str, size) { - return '[font="sans-bold-' + (size + 6) + '"]' + str[0] + '[/font]' + '[font="sans-bold-' + size + '"]' + str.substring(1) + '[/font]'; + return setStringTags(str[0], { "font": "sans-bold-" + (size + 6) }) + setStringTags(str.substring(1), { "font": "sans-bold-" + size }); } /** @@ -50,7 +57,7 @@ if (word.length && word[0].toLowerCase() != word[0]) textArray[i] = bigFirstLetter(wordCaps, size); else - textArray[i] = '[font="sans-bold-' + size + '"]' + wordCaps + '[/font]'; // TODO: Would not be necessary if we could do nested tags + textArray[i] = setStringTags(wordCaps, { "font": "sans-bold-" + size }); // TODO: Would not be necessary if we could do nested tags } return textArray.join(" "); @@ -76,7 +83,7 @@ { if (!obj.Name) return ""; - let string = '[font="sans-bold-14"]' + obj.Name + '[/font] '; + let string = setStringTags(obj.Name, g_NameHistoryDescriptionTextTags.name); if (obj.History) string += '[icon="iconInfo" tooltip="' + escapeQuotation(obj.History) + '" tooltip_style="civInfoTooltip"]'; if (obj.Description) Index: binaries/data/mods/public/gui/common/color.js =================================================================== --- binaries/data/mods/public/gui/common/color.js +++ binaries/data/mods/public/gui/common/color.js @@ -1,7 +1,12 @@ /** * Used to highlight hotkeys in tooltip descriptions. */ -var g_HotkeyTags = {"color": "255 251 131" }; +var g_HotkeyTextTags = { "color": "255 251 131" }; + +/** + * Used to highlight hotkeys in tooltip descriptions. + */ +var g_IncompatibleTextTags = { "color": "96 96 96" }; /** * Concatenate integer color values to a string (for use in GUI objects) @@ -180,7 +185,7 @@ }); return sprintf(text, { - "hotkey": setStringTags("\\[" + key + "]", g_HotkeyTags) + "hotkey": setStringTags("\\[" + key + "]", g_HotkeyTextTags) }); } @@ -192,7 +197,7 @@ { return sprintf(string || translate("Press %(hotkey)s to autocomplete player names."), { "hotkey": - setStringTags("\\[" + translateWithContext("hotkey", "Tab") + "]", g_HotkeyTags) + setStringTags("\\[" + translateWithContext("hotkey", "Tab") + "]", g_HotkeyTextTags) }); } @@ -201,5 +206,5 @@ */ function compatibilityColor(text, isCompatible) { - return isCompatible ? text : coloredText(text, "96 96 96"); + return isCompatible ? text : setStringTags(text, g_IncompatibleTextTags); } Index: binaries/data/mods/public/gui/common/functions_global_object.js =================================================================== --- binaries/data/mods/public/gui/common/functions_global_object.js +++ binaries/data/mods/public/gui/common/functions_global_object.js @@ -75,7 +75,7 @@ Engine.PushGuiPage("page_msgbox.xml", { "width": 500, "height": 200, - "message": '[font="sans-bold-18"]' + msg + '[/font]', + "message": setStringTags(msg, { "font": "sans-bold-18" }), "title": translate("Loading Aborted"), "mode": 2 }); Index: binaries/data/mods/public/gui/common/gamedescription.js =================================================================== --- binaries/data/mods/public/gui/common/gamedescription.js +++ binaries/data/mods/public/gui/common/gamedescription.js @@ -1,7 +1,12 @@ /** * Highlights the victory condition in the game-description. */ -var g_DescriptionHighlight = "orange"; +var g_DescriptionHighlightTextTags = { "color": "orange" }; + +/** + * Font of the teams. + */ +var g_TeamDescriptionCaptionTextTags = { "font": "sans-bold-14" }; /** * The rating assigned to lobby players who didn't complete a ranked 1v1 yet. @@ -210,14 +215,14 @@ // Translation: Describe players of one team in a selected game, f.e. in the replay- or savegame menu or lobby return sprintf(translate("%(team)s:\n%(playerDescriptions)s"), { - "team": '[font="sans-bold-14"]' + teamCaption + "[/font]", + "team": setStringTags(teamCaption, g_TeamDescriptionCaptionTextTags), "playerDescriptions": playerDescriptions[team].join("\n") }); }); if (playerDescriptions.observer) teamDescription.push(sprintf(translate("%(team)s:\n%(playerDescriptions)s"), { - "team": '[font="sans-bold-14"]' + translatePlural("Observer", "Observers", playerDescriptions.observer.length) + "[/font]", + "team": setStringTags(translatePlural("Observer", "Observers", playerDescriptions.observer.length), g_TeamDescriptionCaptionTextTags), "playerDescriptions": playerDescriptions.observer.join("\n") })); @@ -440,7 +445,7 @@ }); return titles.map(title => sprintf(translate("%(label)s %(details)s"), { - "label": coloredText(title.label, g_DescriptionHighlight), + "label": setStringTags(title.label, g_DescriptionHighlightTextTags), "details": title.value === true ? translateWithContext("gamesetup option", "enabled") : title.value || translateWithContext("gamesetup option", "disabled") Index: binaries/data/mods/public/gui/common/tooltips.js =================================================================== --- binaries/data/mods/public/gui/common/tooltips.js +++ binaries/data/mods/public/gui/common/tooltips.js @@ -5,7 +5,10 @@ "comma": { "font": "sans-12" }, "nameSpecificBig": { "font": "sans-bold-16" }, "nameSpecificSmall": { "font": "sans-bold-12" }, - "nameGeneric": { "font": "sans-bold-16" } + "nameGeneric": { "font": "sans-bold-16" }, + "insufficient": { "font": "sans-bold-13", "color": "red" }, + "armour": { "font": "sans-10" }, + "warning": { "color": "orange" } }; function getCostTypes() @@ -173,11 +176,9 @@ dmgType => sprintf(translate("%(damage)s %(damageType)s %(armorPercentage)s"), { "damage": template.armour[dmgType].toFixed(1), "damageType": unitFont(translateWithContext("damage type", dmgType)), - "armorPercentage": - '[font="sans-10"]' + - sprintf(translate("(%(armorPercentage)s)"), { + "armorPercentage": setStringTags(sprintf(translate("(%(armorPercentage)s)"), { "armorPercentage": armorLevelToPercentageString(template.armour[dmgType]) - }) + '[/font]' + }), g_TooltipTextFormats.armour) }) ).join(commaFont(translate(", "))) }); @@ -711,12 +712,10 @@ let formatted = []; for (let resource in resources) formatted.push(sprintf(translate("%(component)s %(cost)s"), { - "component": '[font="sans-12"]' + resourceIcon(resource) + '[/font]', + "component": resourceIcon(resource), "cost": resources[resource] })); - return coloredText( - '[font="sans-bold-13"]' + translate("Insufficient resources:") + '[/font]', - "red") + " " + + return setStringTags(translate("Insufficient resources:"), g_TooltipTextFormats.insufficient) + " " + formatted.join(" "); } @@ -822,13 +821,11 @@ return setStringTags(template.name.generic, g_TooltipTextFormats.nameSpecificBig); // Translation: Example: "Epibátēs Athēnaîos [font="sans-bold-16"](Athenian Marine)[/font]" - return sprintf(translate("%(specificName)s %(fontStart)s(%(genericName)s)%(fontEnd)s"), { + return sprintf(translate("%(specificName)s (%(genericName)s)"), { "specificName": setStringTags(template.name.specific[0], g_TooltipTextFormats.nameSpecificBig) + setStringTags(template.name.specific.slice(1).toUpperCase(), g_TooltipTextFormats.nameSpecificSmall), - "genericName": template.name.generic, - "fontStart": '[font="' + g_TooltipTextFormats.nameGeneric.font + '"]', - "fontEnd": '[/font]' + "genericName": setStringTags(template.name.generic, g_TooltipTextFormats.nameGeneric) }); } Index: binaries/data/mods/public/gui/gamesetup/gamesetup.js =================================================================== --- binaries/data/mods/public/gui/gamesetup/gamesetup.js +++ binaries/data/mods/public/gui/gamesetup/gamesetup.js @@ -49,7 +49,7 @@ /** * Used for highlighting the sender of chat messages. */ -var g_SenderFontTag = { "font": "sans-bold-13" }; +var g_SenderTextTags = { "font": "sans-bold-13" }; /** * This yields [1, 2, ..., MaxPlayers]. @@ -116,19 +116,19 @@ var g_ReadyData = [ { - "color": g_ColorRegular, + "textTags": { "color": g_ColorRegular }, "chat": translate("* %(username)s is not ready."), "caption": translate("I'm ready"), "tooltip": translate("State that you are ready to play.") }, { - "color": "green", + "textTags": { "color": "green" }, "chat": translate("* %(username)s is ready!"), "caption": translate("Stay ready"), "tooltip": translate("Stay ready even when the game settings change.") }, { - "color": "150 150 250", + "textTags": { "color": "150 150 250" }, "chat": "", "caption": translate("I'm not ready!"), "tooltip": translate("State that you are not ready to play.") @@ -160,7 +160,7 @@ "kicked": (msg, user) => systemMessage(sprintf(translate("%(username)s has been kicked"), { "username": user })), "banned": (msg, user) => systemMessage(sprintf(translate("%(username)s has been banned"), { "username": user })), "chat": (msg, user) => sprintf(translate("%(username)s %(message)s"), { - "username": setStringTags(sprintf(translate("<%(username)s>"), { "username": user }), g_SenderFontTag), + "username": setStringTags(sprintf(translate("<%(username)s>"), { "username": user }), g_SenderTextTags), "message": escapeText(msg.text || "") }), "ready": (msg, user) => sprintf(g_ReadyData[msg.status].chat, { "username": user }), @@ -582,12 +582,12 @@ if (hoverIdx == -1 || popCap * players <= g_PopulationCapacityRecommendation) return translate("Select population limit."); - return coloredText( + return setStringTags( sprintf(translate("Warning: There might be performance issues if all %(players)s players reach %(popCap)s population."), { "players": players, "popCap": popCap }), - "orange"); + g_TooltipTextFormats.warning); }, "labels": () => g_PopulationCapacities.Title, "ids": () => g_PopulationCapacities.Population, @@ -1169,7 +1169,7 @@ let name = translate(pData.Name || g_DefaultPlayerData[playerIdx].Name); if (g_IsNetworked) - name = coloredText(name, g_ReadyData[assignedGUID ? g_PlayerAssignments[assignedGUID].status : 2].color); + name = setStringTags(name, g_ReadyData[assignedGUID ? g_PlayerAssignments[assignedGUID].status : 2].textTags); return name; }, @@ -2574,7 +2574,7 @@ function systemMessage(message) { - return setStringTags(sprintf(translate("== %(message)s"), { "message": message }), g_SenderFontTag); + return setStringTags(sprintf(translate("== %(message)s"), { "message": message }), g_SenderTextTags); } function colorizePlayernameByGUID(guid, username = "") Index: binaries/data/mods/public/gui/loadgame/load.js =================================================================== --- binaries/data/mods/public/gui/loadgame/load.js +++ binaries/data/mods/public/gui/loadgame/load.js @@ -116,7 +116,7 @@ let caption = sprintf(translate("Mods: %(mods)s"), { "mods": modsToString(metadata.mods) }); if (!hasSameMods(metadata.mods, Engine.GetEngineInfo().mods)) - caption = coloredText(caption, "orange"); + caption = setStringTags(caption, g_TooltipTextFormats.warning); Engine.GetGUIObjectByName("savedMods").caption = caption; Engine.GetGUIObjectByName("savedPlayersNames").caption = formatPlayerInfo( Index: binaries/data/mods/public/gui/lobby/lobby.js =================================================================== --- binaries/data/mods/public/gui/lobby/lobby.js +++ binaries/data/mods/public/gui/lobby/lobby.js @@ -29,13 +29,13 @@ const g_LobbyServer = Engine.ConfigDB_GetValue("user", "lobby.server"); /** - * Current games will be listed in these colors. + * Current games will be listed formatted with these tags. */ -var g_GameColors = { - "init": "0 219 0", - "waiting": "255 127 0", - "running": "219 0 0", - "incompatible": "gray" +var g_GameTextTags = { + "init": { "color": "0 219 0" }, + "waiting": { "color": "255 127 0" }, + "running": { "color": "219 0 0" }, + "incompatible": { "color": "gray" } }; /** @@ -47,11 +47,11 @@ * The playerlist will be assembled using these values. */ var g_PlayerStatuses = { - "available": { "color": "0 219 0", "status": translate("Online") }, - "away": { "color": "229 76 13", "status": translate("Away") }, - "playing": { "color": "200 0 0", "status": translate("Busy") }, - "offline": { "color": "0 0 0", "status": translate("Offline") }, - "unknown": { "color": "178 178 178", "status": translateWithContext("lobby presence", "Unknown") } + "available": { "textTags": { "color": "0 219 0" }, "status": translate("Online") }, + "away": { "textTags": { "color": "229 76 13" }, "status": translate("Away") }, + "playing": { "textTags": { "color": "200 0 0" }, "status": translate("Busy") }, + "offline": { "textTags": { "color": "0 0 0" }, "status": translate("Offline") }, + "unknown": { "textTags": { "color": "178 178 178" }, "status": translateWithContext("lobby presence", "Unknown") } }; var g_RoleNames = { @@ -68,17 +68,17 @@ /** * Color for private messages in the chat. */ -var g_PrivateMessageColor = "0 150 0"; +var g_PrivateMessageTextTags = { "color": "0 150 0" }; /** * Used for highlighting the sender of chat messages. */ -var g_SenderFont = "sans-bold-13"; +var g_SenderTextTags = { "font": "sans-bold-13" }; /** * Color to highlight chat commands in the explanation. */ -var g_ChatCommandColor = "200 200 255"; +var g_ChatCommandTextTags = { "color": "200 200 255" }; /** * Indicates if the lobby is opened as a dialog or window. @@ -334,7 +334,7 @@ if (!g_ChatCommands[command].moderatorOnly || isModerator) // Translation: Chat command help format text += "\n" + sprintf(translate("%(command)s - %(description)s"), { - "command": coloredText(command, g_ChatCommandColor), + "command": setStringTags(command, g_ChatCommandTextTags), "description": g_ChatCommands[command].description }); @@ -725,11 +725,10 @@ if (presence == "unknown") warn("Unknown presence:" + player.presence); - let statusColor = g_PlayerStatuses[presence].color; - buddyStatusList.push(player.isBuddy ? coloredText(g_BuddySymbol, statusColor) : ""); + buddyStatusList.push(player.isBuddy ? setStringTags(g_BuddySymbol, g_PlayerStatuses[presence].textTags) : ""); playerList.push(colorPlayerName((player.role == "moderator" ? g_ModeratorPrefix : "") + player.name)); - presenceList.push(coloredText(g_PlayerStatuses[presence].status, statusColor)); - ratingList.push(coloredText(rating, statusColor)); + presenceList.push(setStringTags(g_PlayerStatuses[presence].status, g_PlayerStatuses[presence].textTags)); + ratingList.push(setStringTags(rating, g_PlayerStatuses[presence].textTags)); nickList.push(player.name); } @@ -1059,8 +1058,8 @@ if (game.ip == g_SelectedGameIP && game.port == g_SelectedGamePort) selectedGameIndex = +i; - list_buddy.push(game.hasBuddies ? coloredText(g_BuddySymbol, g_GameColors[game.state]) : ""); - list_name.push(coloredText(gameName, g_GameColors[game.state])); + list_buddy.push(game.hasBuddies ? setStringTags(g_BuddySymbol, g_GameTextTags[game.state]) : ""); + list_name.push(setStringTags(gameName, g_GameTextTags[game.state])); list_mapName.push(translateMapTitle(game.niceMapName)); list_mapSize.push(translateMapSize(game.mapSize)); list_mapType.push(g_MapTypes.Title[mapTypeIdx] || ""); @@ -1330,7 +1329,7 @@ "from": "system", "text": sprintf( translate("The command '%(cmd)s' is not supported."), { - "cmd": coloredText(cmd, g_ChatCommandColor) + "cmd": setStringTags(cmd, g_ChatCommandTextTags) }) }); return false; @@ -1342,7 +1341,7 @@ "from": "system", "text": sprintf( translate("The command '%(cmd)s' is restricted to moderators."), { - "cmd": coloredText(cmd, g_ChatCommandColor) + "cmd": setStringTags(cmd, g_ChatCommandTextTags) }) }); return false; @@ -1426,7 +1425,7 @@ // Translation: IRC message issued using the ‘/me’ command. formattedMessage = sprintf(translate("%(sender)s %(action)s"), { - "sender": senderFont(senderString), + "sender": setStringTags(senderString, g_SenderTextTags), "action": message }); break; @@ -1440,7 +1439,7 @@ // Translation: IRC message. formattedMessage = sprintf(translate("%(sender)s %(message)s"), { - "sender": senderFont(senderString), + "sender": setStringTags(senderString, g_SenderTextTags), "message": message }); break; @@ -1449,9 +1448,9 @@ { if (msg.isSpecial) // Translation: IRC system message. - formattedMessage = senderFont(sprintf(translate("== %(message)s"), { + formattedMessage = setStringTags(sprintf(translate("== %(message)s"), { "message": message - })); + }), g_SenderTextTags); else { // Translation: IRC message prefix. @@ -1461,7 +1460,7 @@ // Translation: IRC message. formattedMessage = sprintf(translate("%(sender)s %(message)s"), { - "sender": senderFont(senderString), + "sender": setStringTags(senderString, g_SenderTextTags), "message": message }); } @@ -1478,7 +1477,7 @@ // Translation: IRC message prefix. if (msg.private) senderString = sprintf(translateWithContext("lobby private message", "(%(private)s) <%(sender)s>"), { - "private": coloredText(translate("Private"), g_PrivateMessageColor), + "private": setStringTags(translate("Private"), g_PrivateMessageTextTags), "sender": coloredFrom }); else @@ -1488,7 +1487,7 @@ // Translation: IRC message. formattedMessage = sprintf(translate("%(sender)s %(message)s"), { - "sender": senderFont(senderString), + "sender": setStringTags(senderString, g_SenderTextTags), "message": msg.text }); } @@ -1555,11 +1554,6 @@ getPlayerColor(playername.replace(g_ModeratorPrefix, ""))); } -function senderFont(text) -{ - return '[font="' + g_SenderFont + '"]' + text + "[/font]"; -} - function formatWinRate(attr) { if (!attr.totalGamesPlayed) Index: binaries/data/mods/public/gui/pregame/SplashscreenHandler.js =================================================================== --- binaries/data/mods/public/gui/pregame/SplashscreenHandler.js +++ binaries/data/mods/public/gui/pregame/SplashscreenHandler.js @@ -42,7 +42,7 @@ 600, 300, "[font=\"sans-bold-16\"]" + sprintf(translate("%(warning)s You appear to be using non-shader (fixed function) graphics. This option will be removed in a future 0 A.D. release, to allow for more advanced graphics features. We advise upgrading your graphics card to a more recent, shader-compatible model."), { - "warning": coloredText("Warning:", "200 20 20") + "warning": setStringTags("Warning:", { "color": "200 20 20" }) }) + "\n\n" + // Translation: This is the second paragraph of a warning. The Index: binaries/data/mods/public/gui/pregame/userreport/userreport.js =================================================================== --- binaries/data/mods/public/gui/pregame/userreport/userreport.js +++ binaries/data/mods/public/gui/pregame/userreport/userreport.js @@ -39,6 +39,8 @@ }) }; +var g_UserReportHeaderTextTags = { "font": "sans-bold-16" }; + function initUserReport() { initTerms(g_TermsUserReport); @@ -78,11 +80,11 @@ Engine.GetGUIObjectByName("userReportText").caption = Engine.IsUserReportEnabled() ? - setStringTags(translate("Thank you for helping improve 0 A.D.!"), { "font": "sans-bold-16" }) + "\n\n" + + setStringTags(translate("Thank you for helping improve 0 A.D.!"), g_UserReportHeaderTextTags) + "\n\n" + translate("Feedback is currently enabled.") + "\n" + sprintf(translate("Status: %(status)s."), { "status": g_UserReportStatusFormat[statusData[0]] ? g_UserReportStatusFormat[statusData[0]](statusData) : translate("unknown") }) : - setStringTags(translate("Help improve 0 A.D.!"), { "font": "sans-bold-16" }) + "\n\n" + + setStringTags(translate("Help improve 0 A.D.!"), g_UserReportHeaderTextTags) + "\n\n" + translate("You can automatically send us feedback that can help us fix bugs, and improve performance and compatibility."); } Index: binaries/data/mods/public/gui/session/menu.js =================================================================== --- binaries/data/mods/public/gui/session/menu.js +++ binaries/data/mods/public/gui/session/menu.js @@ -23,7 +23,7 @@ var STEP = 5; // Shown in the trade dialog. -var g_IdleTraderTextColor = "orange"; +var g_IdleTraderTextTags = { "color": "orange" }; /** * Store civilization code and page (structree or history) opened in civilization info. @@ -937,7 +937,7 @@ "openingTradingString": activeString, "openingGarrisonedString": garrisonedString, "garrisonedString": garrisonedString, - "inactiveString": coloredText(inactiveString, g_IdleTraderTextColor) + "inactiveString": setStringTags(inactiveString, g_IdleTraderTextTags) }); } @@ -985,7 +985,7 @@ return sprintf(message, { "openingTradingString": activeString, - "inactiveString": coloredText(inactiveString, g_IdleTraderTextColor) + "inactiveString": setStringTags(inactiveString, g_IdleTraderTextTags) }); } Index: binaries/data/mods/public/gui/session/messages.js =================================================================== --- binaries/data/mods/public/gui/session/messages.js +++ binaries/data/mods/public/gui/session/messages.js @@ -44,6 +44,11 @@ var g_TutorialNewMessageTags = { "color": "yellow" }; /** + * GUI tags applied to warning tutorial message. + */ +var g_TutorialWarningMessageTags = { "color": "orange" }; + +/** * Handle all netmessage types that can occur. */ var g_NetMessageTypes = { @@ -567,7 +572,7 @@ if (notification.warning) { - Engine.GetGUIObjectByName("tutorialWarning").caption = coloredText(translate(notification.warning), "orange"); + Engine.GetGUIObjectByName("tutorialWarning").caption = setStringTags(translate(notification.warning), g_TutorialWarningMessageTags); return; } Index: binaries/data/mods/public/gui/session/selection_details.js =================================================================== --- binaries/data/mods/public/gui/session/selection_details.js +++ binaries/data/mods/public/gui/session/selection_details.js @@ -191,13 +191,13 @@ if (entState.promotion.curr < entState.promotion.req) Engine.GetGUIObjectByName("experience").tooltip = sprintf(translate("%(experience)s %(current)s / %(required)s"), { - "experience": "[font=\"sans-bold-13\"]" + translate("Experience:") + "[/font]", + "experience": headerFont(translate("Experience:")), "current": Math.floor(entState.promotion.curr), "required": entState.promotion.req }); else Engine.GetGUIObjectByName("experience").tooltip = sprintf(translate("%(experience)s %(current)s"), { - "experience": "[font=\"sans-bold-13\"]" + translate("Experience:") + "[/font]", + "experience": headerFont(translate("Experience:")), "current": Math.floor(entState.promotion.curr) }); } @@ -319,7 +319,7 @@ let iconTooltips = []; if (genericName) - iconTooltips.push("[font=\"sans-bold-16\"]" + genericName + "[/font]"); + iconTooltips.push(setStringTags(genericName, g_TooltipTextFormats.nameGeneric)); iconTooltips = iconTooltips.concat([ getVisibleEntityClassesFormatted, Index: binaries/data/mods/public/gui/session/selection_panels.js =================================================================== --- binaries/data/mods/public/gui/session/selection_panels.js +++ binaries/data/mods/public/gui/session/selection_panels.js @@ -321,7 +321,7 @@ let tooltip = translate(formationInfo.name); if (!formationOk && formationInfo.tooltip) - tooltip += "\n" + coloredText(translate(formationInfo.tooltip), "red"); + tooltip += "\n" + setStringTags(translate(formationInfo.tooltip), g_TooltipTextFormats.insufficient); data.button.tooltip = tooltip; data.button.enabled = formationOk && controlsPlayer(data.player); @@ -580,7 +580,7 @@ let tooltip = getEntityNames(template); if (queuedItem.neededSlots) { - tooltip += "\n" + coloredText(translate("Insufficient population capacity:"), "red"); + tooltip += "\n" + setStringTags(translate("Insufficient population capacity:"), g_TooltipTextFormats.insufficient); tooltip += "\n" + sprintf(translate("%(population)s %(neededSlots)s"), { "population": resourceIcon("population"), "neededSlots": queuedItem.neededSlots @@ -906,8 +906,8 @@ let unitIds = data.unitEntStates.map(state => state.id); data.button.onPress = function() { performStance(unitIds, data.item); }; - data.button.tooltip = getStanceDisplayName(data.item) + "\n" + - "[font=\"sans-13\"]" + getStanceTooltip(data.item) + "[/font]"; + data.button.tooltip = headerFont(getStanceDisplayName(data.item)) + "\n" + + bodyFont(getStanceTooltip(data.item)); data.guiSelection.hidden = !Engine.GuiInterfaceCall("IsStanceSelected", { "ents": unitIds, @@ -965,9 +965,10 @@ data.countDisplay.caption = trainNum > 1 ? trainNum : ""; let tooltips = [ - "[font=\"sans-bold-16\"]" + - colorizeHotkey("%(hotkey)s", "session.queueunit." + (data.i + 1)) + - "[/font]" + " " + getEntityNamesFormatted(template), + setStringTags( + colorizeHotkey("%(hotkey)s", "session.queueunit." + (data.i + 1)), + g_TooltipTextFormats.nameGeneric + ) + " " + getEntityNamesFormatted(template), getVisibleEntityClassesFormatted(template), getAurasTooltip(template), getEntityTooltip(template), Index: binaries/data/mods/public/gui/session/selection_panels_helpers.js =================================================================== --- binaries/data/mods/public/gui/session/selection_panels_helpers.js +++ binaries/data/mods/public/gui/session/selection_panels_helpers.js @@ -101,7 +101,7 @@ }); if (trainEntCount >= trainEntLimit) - text = coloredText(text, "red"); + text = setStringTags(text, g_TooltipTextFormats.insufficient); for (var c in trainEntLimitChangers) { @@ -161,16 +161,14 @@ else batchString = translate("%(action)s to train %(number)s."); - return "[font=\"sans-13\"]" + - setStringTags( + return bodyFont(setStringTags( sprintf(batchString, { - "action": "[font=\"sans-bold-13\"]" + translate("Shift-click") + "[/font]", + "action": headerFont(translate("Shift-click")), "number": totalBatchTrainingCount, "fullBatch": fullBatchesString, "remainderBatch": remainderBatch }), - g_HotkeyTags) + - "[/font]"; + g_HotkeyTextTags)); } /** Index: binaries/data/mods/public/gui/session/session.js =================================================================== --- binaries/data/mods/public/gui/session/session.js +++ binaries/data/mods/public/gui/session/session.js @@ -32,7 +32,7 @@ /** * Seen in the tooltip of the top panel. */ -var g_ResourceTitleFont = "sans-bold-16"; +var g_ResourceTitleTextTags = { "font": "sans-bold-16" }; /** * A random file will be played. TODO: more variety @@ -1069,7 +1069,7 @@ function createPanelEntityTooltip(panelEntState, template) { - let getPanelEntNameTooltip = panelEntState => "[font=\"sans-bold-16\"]" + template.name.specific + "[/font]"; + let getPanelEntNameTooltip = panelEntState => setStringTags(template.name.specific, g_TooltipTextFormats.nameSpecificBig); return [ getPanelEntNameTooltip, @@ -1211,7 +1211,7 @@ let orderHotkeyTooltip = Object.keys(viewablePlayerStates).length <= 1 ? "" : "\n" + sprintf(translate("%(order)s: %(hotkey)s to change order."), { - "hotkey": setStringTags("\\[Click]", g_HotkeyTags), + "hotkey": setStringTags("\\[Click]", g_HotkeyTag), "order": tooltipSort == 0 ? translate("Unordered") : tooltipSort == 1 ? translate("Descending") : translate("Ascending") }); @@ -1224,8 +1224,7 @@ let res = resCodes[r]; - let tooltip = '[font="' + g_ResourceTitleFont + '"]' + - resourceNameFirstWord(res) + '[/font]'; + let tooltip = setStringTags(resourceNameFirstWord(res), g_ResourceTitleTextTags); let descr = g_ResourceData.GetResource(res).description; if (descr) Index: binaries/data/mods/public/gui/session/unit_actions.js =================================================================== --- binaries/data/mods/public/gui/session/unit_actions.js +++ binaries/data/mods/public/gui/session/unit_actions.js @@ -644,7 +644,7 @@ extraCount += entState.garrisonHolder.garrisonedEntitiesCount; if (targetState.garrisonHolder.garrisonedEntitiesCount + extraCount >= targetState.garrisonHolder.capacity) - tooltip = coloredText(tooltip, "orange"); + tooltip = setStringTags(tooltip, g_TooltipTextFormats.warning); if (!MatchesClassList(entState.identity.classes, targetState.garrisonHolder.allowedClasses)) return false; @@ -856,7 +856,7 @@ if (targetState.garrisonHolder.garrisonedEntitiesCount >= targetState.garrisonHolder.capacity) - tooltip = coloredText(tooltip, "orange"); + tooltip = setStringTags(tooltip, g_TooltipTextFormats.warning); } else if (targetState.resourceSupply) { Index: binaries/data/mods/public/gui/summary/counters.js =================================================================== --- binaries/data/mods/public/gui/summary/counters.js +++ binaries/data/mods/public/gui/summary/counters.js @@ -17,8 +17,8 @@ let ret = ""; for (let type in values) - ret += (g_SummaryTypes[type].color ? - coloredText(values[type], g_SummaryTypes[type].color) : + ret += (g_SummaryTypes[type].textTags ? + setStringTags(values[type], g_SummaryTypes[type].textTags) : values[type]) + g_SummaryTypes[type].postfix; return ret; } Index: binaries/data/mods/public/gui/summary/layout.js =================================================================== --- binaries/data/mods/public/gui/summary/layout.js +++ binaries/data/mods/public/gui/summary/layout.js @@ -217,7 +217,7 @@ function getColoredTypeTranslation(type) { return g_SummaryTypes[type].color ? - coloredText(g_SummaryTypes[type].caption, g_SummaryTypes[type].color) : + setStringTags(g_SummaryTypes[type].caption, g_SummaryTypes[type].textTags) : g_SummaryTypes[type].caption; } Index: binaries/data/mods/public/gui/summary/summary.js =================================================================== --- binaries/data/mods/public/gui/summary/summary.js +++ binaries/data/mods/public/gui/summary/summary.js @@ -17,91 +17,91 @@ }; /** - * Colors, captions and format used for units, buildings, etc. types + * Captions and format used for units, buildings, etc. types */ var g_SummaryTypes = { "percent": { - "color": "", + "textTags": "", "caption": "%", "postfix": "%" }, "trained": { - "color": g_TypeColors.green, + "textTags": { "color": g_TypeColors.green }, "caption": translate("Trained"), "postfix": " / " }, "constructed": { - "color": g_TypeColors.green, + "textTags": { "color": g_TypeColors.green }, "caption": translate("Constructed"), "postfix": " / " }, "gathered": { - "color": g_TypeColors.green, + "textTags": { "color": g_TypeColors.green }, "caption": translate("Gathered"), "postfix": " / " }, "sent": { - "color": g_TypeColors.green, + "textTags": { "color": g_TypeColors.green }, "caption": translate("Sent"), "postfix": " / " }, "bought": { - "color": g_TypeColors.green, + "textTags": { "color": g_TypeColors.green }, "caption": translate("Bought"), "postfix": " / " }, "income": { - "color": g_TypeColors.green, + "textTags": { "color": g_TypeColors.green }, "caption": translate("Income"), "postfix": " / " }, "captured": { - "color": g_TypeColors.yellow, + "textTags": { "color": g_TypeColors.yellow }, "caption": translate("Captured"), "postfix": " / " }, "succeeded": { - "color": g_TypeColors.green, + "textTags": { "color": g_TypeColors.green }, "caption": translate("Succeeded"), "postfix": " / " }, "destroyed": { - "color": g_TypeColors.blue, + "textTags": { "color": g_TypeColors.blue }, "caption": translate("Destroyed"), "postfix": "\n" }, "killed": { - "color": g_TypeColors.blue, + "textTags": { "color": g_TypeColors.blue }, "caption": translate("Killed"), "postfix": "\n" }, "lost": { - "color": g_TypeColors.red, + "textTags": { "color": g_TypeColors.red }, "caption": translate("Lost"), "postfix": "" }, "used": { - "color": g_TypeColors.red, + "textTags": { "color": g_TypeColors.red }, "caption": translate("Used"), "postfix": "" }, "received": { - "color": g_TypeColors.red, + "textTags": { "color": g_TypeColors.red }, "caption": translate("Received"), "postfix": "" }, "sold": { - "color": g_TypeColors.red, + "textTags": { "color": g_TypeColors.red }, "caption": translate("Sold"), "postfix": "" }, "outcome": { - "color": g_TypeColors.red, + "textTags": { "color": g_TypeColors.red }, "caption": translate("Outcome"), "postfix": "" }, "failed": { - "color": g_TypeColors.red, + "textTags": { "color": g_TypeColors.red }, "caption": translate("Failed"), "postfix": "" }