Index: ps/trunk/binaries/data/mods/mod/gui/common/guitags.js =================================================================== --- ps/trunk/binaries/data/mods/mod/gui/common/guitags.js +++ ps/trunk/binaries/data/mods/mod/gui/common/guitags.js @@ -0,0 +1,9 @@ +/** + * Add color to text string. + */ +function coloredText(text, color) +{ + return '[color="' + color + '"]' + text + '[/color]'; +} + +//TODO: font setter Index: ps/trunk/binaries/data/mods/mod/gui/modmod/modmod.js =================================================================== --- ps/trunk/binaries/data/mods/mod/gui/modmod/modmod.js +++ ps/trunk/binaries/data/mods/mod/gui/modmod/modmod.js @@ -249,19 +249,14 @@ if (isDependencyMet(dependency)) continue; - guiObject.caption = - '[color="' + g_ColorDependenciesNotMet + '"]' + - sprintf(translate('Dependency not met: %(dep)s'), { "dep": dependency }) + - '[/color]'; + guiObject.caption = coloredText( + sprintf(translate('Dependency not met: %(dep)s'), { "dep": dependency }), + g_ColorDependenciesNotMet); return false; } - guiObject.caption = - '[color="' + g_ColorDependenciesMet + '"]' + - translate('All dependencies met') + - '[/color]'; - + guiObject.caption = coloredText(translate('All dependencies met'), g_ColorDependenciesMet); return true; } Index: ps/trunk/binaries/data/mods/public/gui/civinfo/civinfo.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/civinfo/civinfo.js +++ ps/trunk/binaries/data/mods/public/gui/civinfo/civinfo.js @@ -71,13 +71,12 @@ { if (!obj.Name) return ""; - let string = '[color="white"][font="sans-bold-14"]' + obj.Name + '[/font] '; + let string = '[font="sans-bold-14"]' + obj.Name + '[/font] '; if (obj.History) string += '[icon="iconInfo" tooltip="' + escapeQuotation(obj.History) + '" tooltip_style="civInfoTooltip"]'; if (obj.Description) string += '\n ' + obj.Description; - string += '\n[/color]'; - return string; + return coloredText(string + "\n", "white"); } /** Index: ps/trunk/binaries/data/mods/public/gui/common/color.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/common/color.js +++ ps/trunk/binaries/data/mods/public/gui/common/color.js @@ -149,10 +149,7 @@ return ""; return sprintf(text, { - "hotkey": - "[color=\"" + g_HotkeyColor + "\"]" + - "\\[" + key + "]" + - "[/color]" + "hotkey": coloredText("\\[" + key + "]", g_HotkeyColor) }); } @@ -164,9 +161,7 @@ { return sprintf(string || translate("Press %(hotkey)s to autocomplete playernames."), { "hotkey": - "[color=\"" + g_HotkeyColor + "\"]" + - "\\[" + translateWithContext("hotkey", "Tab") + "]" + - "[/color]" + coloredText("\\[" + translateWithContext("hotkey", "Tab") + "]", g_HotkeyColor) }); } @@ -175,5 +170,5 @@ */ function compatibilityColor(text, isCompatible) { - return isCompatible ? text : '[color="96 96 96"]' + text + '[/color]'; + return isCompatible ? text : coloredText(text, "96 96 96"); } Index: ps/trunk/binaries/data/mods/public/gui/common/gamedescription.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/common/gamedescription.js +++ ps/trunk/binaries/data/mods/public/gui/common/gamedescription.js @@ -154,14 +154,12 @@ playerDescriptions[teamIdx].push(sprintf(playerDescription, { "playerName": - '[color="' + + coloredText( + (g_Buddies.indexOf(splitRatingFromNick(playerData.Name)[0]) != -1 ? g_BuddySymbol + " " : "") + + escapeText(playerData.Name), (typeof getPlayerColor == 'function' ? (isAI ? "white" : getPlayerColor(playerData.Name)) : - rgbToGuiColor(playerData.Color || g_Settings.PlayerDefaults[playerIdx].Color)) + - '"]' + - (g_Buddies.indexOf(splitRatingFromNick(playerData.Name)[0]) != -1 ? g_BuddySymbol + " " : "") + - escapeText(playerData.Name) + - "[/color]", + rgbToGuiColor(playerData.Color || g_Settings.PlayerDefaults[playerIdx].Color))), "civ": !playerData.Civ ? @@ -402,7 +400,7 @@ } return titles.map(title => sprintf(translate("%(label)s %(details)s"), { - "label": "[color=\"" + g_DescriptionHighlight + "\"]" + title.label + ":" + "[/color]", + "label": coloredText(title.label, g_DescriptionHighlight), "details": title.value === true ? translateWithContext("gamesetup option", "enabled") : title.value || translateWithContext("gamesetup option", "disabled") Index: ps/trunk/binaries/data/mods/public/gui/common/tooltips.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/common/tooltips.js +++ ps/trunk/binaries/data/mods/public/gui/common/tooltips.js @@ -596,10 +596,9 @@ "component": '[font="sans-12"]' + resourceIcon(resource) + '[/font]', "cost": resources[resource] })); - - return '[font="sans-bold-13"][color="red"]' + - translate("Insufficient resources:") + - '[/color][/font]' + " " + + return coloredText( + '[font="sans-bold-13"]' + translate("Insufficient resources:") + '[/font]', + "red") + " " + formatted.join(" "); } Index: ps/trunk/binaries/data/mods/public/gui/gamesetup/gamesetup.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/gamesetup/gamesetup.js +++ ps/trunk/binaries/data/mods/public/gui/gamesetup/gamesetup.js @@ -517,11 +517,12 @@ if (hoverIdx == -1 || popCap * players <= g_PopulationCapacityRecommendation) return translate("Select population limit."); - return '[color="orange"]' + + return coloredText( sprintf(translate("Warning: There might be performance issues if all %(players)s players reach %(popCap)s population."), { "players": players, "popCap": popCap - }) + '[/color]'; + }), + "orange"); }, "labels": () => g_PopulationCapacities.Title, "ids": () => g_PopulationCapacities.Population, @@ -941,10 +942,7 @@ let name = translate(pData.Name || g_DefaultPlayerData[playerIdx].Name); if (g_IsNetworked) - name = - '[color="' + - g_ReadyData[assignedGUID ? g_PlayerAssignments[assignedGUID].status : 2].color + - '"]' + name + '[/color]'; + name = coloredText(name, g_ReadyData[assignedGUID ? g_PlayerAssignments[assignedGUID].status : 2].color); return name; }, @@ -1134,7 +1132,7 @@ dropdown.list = data.labels(playerIdx).map((label, id) => data.colors && data.colors(playerIdx) ? - '[color="' + data.colors(playerIdx)[id] + '"]' + label + "[/color]" : + coloredText(label, data.colors(playerIdx)[id]) : label); dropdown.list_data = data.ids(playerIdx); @@ -2245,7 +2243,7 @@ color = rgbToGuiColor({ "r": r, "g": g, "b": b }); } - return '[color="' + color + '"]' + username + '[/color]'; + return coloredText(username, color); } function addChatMessage(msg) Index: ps/trunk/binaries/data/mods/public/gui/loadgame/load.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/loadgame/load.js +++ ps/trunk/binaries/data/mods/public/gui/loadgame/load.js @@ -116,7 +116,7 @@ let caption = sprintf(translate("Mods: %(mods)s"), { "mods": metadata.mods.join(translate(", ")) }); if (!hasSameMods(metadata, Engine.GetEngineInfo())) - caption = "[color=\"orange\"]" + caption + "[/color]"; + caption = coloredText(caption, "orange"); Engine.GetGUIObjectByName("savedMods").caption = caption; Engine.GetGUIObjectByName("savedPlayersNames").caption = formatPlayerInfo( Index: ps/trunk/binaries/data/mods/public/gui/lobby/lobby.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/lobby/lobby.js +++ ps/trunk/binaries/data/mods/public/gui/lobby/lobby.js @@ -334,7 +334,7 @@ if (!g_ChatCommands[command].moderatorOnly || isModerator) // Translation: Chat command help format text += "\n" + sprintf(translate("%(command)s - %(description)s"), { - "command": '[color="' + g_ChatCommandColor + '"]' + command + '[/color]', + "command": coloredText(command, g_ChatCommandColor), "description": g_ChatCommands[command].description }); @@ -657,14 +657,10 @@ warn("Unknown presence:" + player.presence); let statusColor = g_PlayerStatuses[presence].color; - let coloredName = colorPlayerName((player.role == "moderator" ? g_ModeratorPrefix : "") + player.name); - let coloredPresence = '[color="' + statusColor + '"]' + g_PlayerStatuses[presence].status + "[/color]"; - let coloredRating = '[color="' + statusColor + '"]' + rating + "[/color]"; - - buddyStatusList.push(player.isBuddy ? '[color="' + statusColor + '"]' + g_BuddySymbol + '[/color]' : ""); - playerList.push(coloredName); - presenceList.push(coloredPresence); - ratingList.push(coloredRating); + buddyStatusList.push(player.isBuddy ? coloredText(g_BuddySymbol, statusColor) : ""); + playerList.push(colorPlayerName((player.role == "moderator" ? g_ModeratorPrefix : "") + player.name)); + presenceList.push(coloredText(g_PlayerStatuses[presence].status, statusColor)); + ratingList.push(coloredText(rating, statusColor)); nickList.push(player.name); } @@ -985,8 +981,8 @@ if (game.ip == g_SelectedGameIP && game.port == g_SelectedGamePort) selectedGameIndex = +i; - list_buddy.push(game.hasBuddies ? '[color="' + g_GameColors[game.state] + '"]' + g_BuddySymbol + '[/color]' : ""); - list_name.push('[color="' + g_GameColors[game.state] + '"]' + gameName); + list_buddy.push(game.hasBuddies ? coloredText(g_BuddySymbol, g_GameColors[game.state]) : ""); + list_name.push(coloredText(gameName, g_GameColors[game.state])); list_mapName.push(translateMapTitle(game.niceMapName)); list_mapSize.push(translateMapSize(game.mapSize)); list_mapType.push(g_MapTypes.Title[mapTypeIdx] || ""); @@ -1240,7 +1236,7 @@ "from": "system", "text": sprintf( translate("The command '%(cmd)s' is not supported."), { - "cmd": '[color="' + g_ChatCommandColor + '"]' + cmd + '[/color]' + "cmd": coloredText(cmd, g_ChatCommandColor) }) }); return false; @@ -1252,7 +1248,7 @@ "from": "system", "text": sprintf( translate("The command '%(cmd)s' is restricted to moderators."), { - "cmd": '[color="' + g_ChatCommandColor + '"]' + cmd + '[/color]' + "cmd": coloredText(cmd, g_ChatCommandColor) }) }); return false; @@ -1382,8 +1378,7 @@ // Translation: IRC message prefix. if (msg.private) senderString = sprintf(translateWithContext("lobby private message", "(%(private)s) <%(sender)s>"), { - "private": '[color="' + g_PrivateMessageColor + '"]' + - translate("Private") + '[/color]', + "private": coloredText(translate("Private"), g_PrivateMessageColor), "sender": coloredFrom }); else @@ -1450,13 +1445,14 @@ */ function colorPlayerName(playername, rating) { - return '[color="' + getPlayerColor(playername.replace(g_ModeratorPrefix, "")) + '"]' + + return coloredText( (rating ? sprintf( translate("%(nick)s (%(rating)s)"), { "nick": playername, "rating": rating }) : playername - ) + '[/color]'; + ), + getPlayerColor(playername.replace(g_ModeratorPrefix, ""))); } function senderFont(text) Index: ps/trunk/binaries/data/mods/public/gui/pregame/mainmenu.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/pregame/mainmenu.js +++ ps/trunk/binaries/data/mods/public/gui/pregame/mainmenu.js @@ -143,9 +143,8 @@ messageBox( 600, 300, "[font=\"sans-bold-16\"]" + - sprintf(translate("%(startWarning)sWarning:%(endWarning)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."), { - "startWarning": "[color=\"200 20 20\"]", - "endWarning": "[/color]" + 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") }) + "\n\n" + // Translation: This is the second paragraph of a warning. The Index: ps/trunk/binaries/data/mods/public/gui/session/menu.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/session/menu.js +++ ps/trunk/binaries/data/mods/public/gui/session/menu.js @@ -922,7 +922,7 @@ "openingTradingString": activeString, "openingGarrisonedString": garrisonedString, "garrisonedString": garrisonedString, - "inactiveString": "[color=\"" + g_IdleTraderTextColor + "\"]" + inactiveString + "[/color]" + "inactiveString": coloredText(inactiveString, g_IdleTraderTextColor) }); } @@ -970,7 +970,7 @@ return sprintf(message, { "openingTradingString": activeString, - "inactiveString": "[color=\"" + g_IdleTraderTextColor + "\"]" + inactiveString + "[/color]" + "inactiveString": coloredText(inactiveString, g_IdleTraderTextColor) }); } Index: ps/trunk/binaries/data/mods/public/gui/session/messages.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/session/messages.js +++ ps/trunk/binaries/data/mods/public/gui/session/messages.js @@ -546,7 +546,7 @@ if (notification.warning) { - Engine.GetGUIObjectByName("tutorialWarning").caption = '[color="orange"]' + translate(notification.warning) + '[/color]'; + Engine.GetGUIObjectByName("tutorialWarning").caption = coloredText(translate(notification.warning), "orange"); return; } @@ -554,9 +554,7 @@ tutorialText.caption = tutorialText.caption.replace('[color="yellow"]', '').replace('[/color]', '') + (tutorialText.caption ? "\n" : "") + - '[color="yellow"]' + - notification.instructions.reduce((instructions, item) => instructions + translate(item), "") + - '[/color]'; + coloredText(notification.instructions.reduce((instructions, item) => instructions + translate(item), ""), "yellow"); if (notification.readyButton) { @@ -948,7 +946,7 @@ function colorizePlayernameHelper(username, playerID) { let playerColor = playerID > -1 ? rgbToGuiColor(g_Players[playerID].color) : "white"; - return '[color="' + playerColor + '"]' + (username || translate("Unknown Player")) + "[/color]"; + return coloredText(username || translate("Unknown Player"), playerColor); } /** Index: ps/trunk/binaries/data/mods/public/gui/session/selection_panels.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/session/selection_panels.js +++ ps/trunk/binaries/data/mods/public/gui/session/selection_panels.js @@ -342,7 +342,7 @@ let tooltip = translate(formationInfo.name); if (!formationOk && formationInfo.tooltip) - tooltip += "\n" + "[color=\"red\"]" + translate(formationInfo.tooltip) + "[/color]"; + tooltip += "\n" + coloredText(translate(formationInfo.tooltip), "red"); data.button.tooltip = tooltip; data.button.enabled = formationOk && controlsPlayer(data.player); @@ -608,8 +608,8 @@ let tooltip = getEntityNames(template); if (queuedItem.neededSlots) { - tooltip += "\n[color=\"red\"]" + translate("Insufficient population capacity:") + "\n[/color]"; - tooltip += sprintf(translate("%(population)s %(neededSlots)s"), { + tooltip += "\n" + coloredText(translate("Insufficient population capacity:"), "red"); + tooltip += "\n" + sprintf(translate("%(population)s %(neededSlots)s"), { "population": resourceIcon("population"), "neededSlots": queuedItem.neededSlots }); @@ -1009,9 +1009,7 @@ ].map(func => func(template))); tooltips.push( - "[color=\"" + g_HotkeyColor + "\"]" + - formatBatchTrainingString(buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch) + - "[/color]", + formatBatchTrainingString(buildingsCountToTrainFullBatch, fullBatchSize, remainderBatch), getRequiredTechnologyTooltip(technologyEnabled, template.requiredTechnology, GetSimState().players[data.player].civ), getNeededResourcesTooltip(neededResources)); Index: ps/trunk/binaries/data/mods/public/gui/session/selection_panels_helpers.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/session/selection_panels_helpers.js +++ ps/trunk/binaries/data/mods/public/gui/session/selection_panels_helpers.js @@ -101,7 +101,7 @@ }); if (trainEntCount >= trainEntLimit) - text = "[color=\"red\"]" + text + "[/color]"; + text = coloredText(text, "red"); for (var c in trainEntLimitChangers) { @@ -161,12 +161,16 @@ else batchString = translate("%(action)s to train %(number)s."); - return "[font=\"sans-13\"]" + sprintf(batchString, { - "action": "[font=\"sans-bold-13\"]" + translate("Shift-click") + "[/font]", - "number": totalBatchTrainingCount, - "fullBatch": fullBatchesString, - "remainderBatch": remainderBatch - }) + "[/font]"; + return "[font=\"sans-13\"]" + + coloredText( + sprintf(batchString, { + "action": "[font=\"sans-bold-13\"]" + translate("Shift-click") + "[/font]", + "number": totalBatchTrainingCount, + "fullBatch": fullBatchesString, + "remainderBatch": remainderBatch + }), + g_HotkeyColor) + + "[/font]"; } /** Index: ps/trunk/binaries/data/mods/public/gui/session/unit_actions.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/session/unit_actions.js +++ ps/trunk/binaries/data/mods/public/gui/session/unit_actions.js @@ -635,7 +635,7 @@ extraCount += entState.garrisonHolder.garrisonedEntitiesCount; if (targetState.garrisonHolder.garrisonedEntitiesCount + extraCount >= targetState.garrisonHolder.capacity) - tooltip = "[color=\"orange\"]" + tooltip + "[/color]"; + tooltip = coloredtext(tooltip, "orange"); if (!MatchesClassList(entState.identity.classes, targetState.garrisonHolder.allowedClasses)) return false; @@ -847,7 +847,7 @@ if (targetState.garrisonHolder.garrisonedEntitiesCount >= targetState.garrisonHolder.capacity) - tooltip = "[color=\"orange\"]" + tooltip + "[/color]"; + tooltip = coloredText(tooltip, "orange"); } else if (targetState.resourceSupply) { Index: ps/trunk/binaries/data/mods/public/gui/summary/counters.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/summary/counters.js +++ ps/trunk/binaries/data/mods/public/gui/summary/counters.js @@ -18,7 +18,7 @@ let ret = ""; for (let type in values) ret += (g_SummaryTypes[type].color ? - '[color="' + g_SummaryTypes[type].color + '"]' + values[type] + '[/color]' : + coloredText(values[type], g_SummaryTypes[type].color) : values[type]) + g_SummaryTypes[type].postfix; return ret; } Index: ps/trunk/binaries/data/mods/public/gui/summary/layout.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/summary/layout.js +++ ps/trunk/binaries/data/mods/public/gui/summary/layout.js @@ -214,7 +214,9 @@ function getColoredTypeTranslation(type) { - return g_SummaryTypes[type].color ? '[color="' + g_SummaryTypes[type].color + '"]' + g_SummaryTypes[type].caption + '[/color]' : g_SummaryTypes[type].caption; + return g_SummaryTypes[type].color ? + coloredText(g_SummaryTypes[type].caption, g_SummaryTypes[type].color) : + g_SummaryTypes[type].caption; } function resetGeneralPanel() Index: ps/trunk/binaries/data/mods/public/gui/summary/summary.js =================================================================== --- ps/trunk/binaries/data/mods/public/gui/summary/summary.js +++ ps/trunk/binaries/data/mods/public/gui/summary/summary.js @@ -183,7 +183,7 @@ let chartLegend = Engine.GetGUIObjectByName("chartLegend"); chartLegend.caption = g_GameData.sim.playerStates.slice(1).map( - (state, index) => '[color="' + player_colors[index] + '"]■[/color] ' + state.name + (state, index) => coloredText("■", player_colors[index]) + state.name ).join(" "); let chart1Part = Engine.GetGUIObjectByName("chart[1]Part");