mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-17 05:44:08 -07:00
Add gui tag color setter function, so that we don't have to read and ensure the color syntax each time.
Differential Revision: https://code.wildfiregames.com/D1088 Patch By: fpre / ffffffff This was SVN commit r20585.
This commit is contained in:
parent
2c8b78ddaa
commit
54904b1750
18 changed files with 75 additions and 85 deletions
9
binaries/data/mods/mod/gui/common/guitags.js
Normal file
9
binaries/data/mods/mod/gui/common/guitags.js
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
/**
|
||||
* Add color to text string.
|
||||
*/
|
||||
function coloredText(text, color)
|
||||
{
|
||||
return '[color="' + color + '"]' + text + '[/color]';
|
||||
}
|
||||
|
||||
//TODO: font setter
|
||||
|
|
@ -249,19 +249,14 @@ function areDependenciesMet(folder)
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -71,13 +71,12 @@ function subHeading(obj)
|
|||
{
|
||||
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");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -149,10 +149,7 @@ function colorizeHotkey(text, hotkey)
|
|||
return "";
|
||||
|
||||
return sprintf(text, {
|
||||
"hotkey":
|
||||
"[color=\"" + g_HotkeyColor + "\"]" +
|
||||
"\\[" + key + "]" +
|
||||
"[/color]"
|
||||
"hotkey": coloredText("\\[" + key + "]", g_HotkeyColor)
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -164,9 +161,7 @@ function colorizeAutocompleteHotkey(string)
|
|||
{
|
||||
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 colorizeAutocompleteHotkey(string)
|
|||
*/
|
||||
function compatibilityColor(text, isCompatible)
|
||||
{
|
||||
return isCompatible ? text : '[color="96 96 96"]' + text + '[/color]';
|
||||
return isCompatible ? text : coloredText(text, "96 96 96");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -154,14 +154,12 @@ function formatPlayerInfo(playerDataArray, playerStates)
|
|||
|
||||
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 @@ function getGameDescription(extended = false)
|
|||
}
|
||||
|
||||
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")
|
||||
|
|
|
|||
|
|
@ -596,10 +596,9 @@ function getNeededResourcesTooltip(resources)
|
|||
"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(" ");
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -517,11 +517,12 @@ var g_Dropdowns = {
|
|||
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 @@ var g_PlayerMiscElements = {
|
|||
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 @@ function initDropdown(name, playerIdx)
|
|||
|
||||
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 @@ function colorizePlayernameByGUID(guid, username = "")
|
|||
color = rgbToGuiColor({ "r": r, "g": g, "b": b });
|
||||
}
|
||||
|
||||
return '[color="' + color + '"]' + username + '[/color]';
|
||||
return coloredText(username, color);
|
||||
}
|
||||
|
||||
function addChatMessage(msg)
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ function selectionChanged()
|
|||
|
||||
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(
|
||||
|
|
|
|||
|
|
@ -334,7 +334,7 @@ var g_ChatCommands = {
|
|||
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 @@ function updatePlayerList()
|
|||
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 @@ function updateGameList()
|
|||
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 @@ function handleChatCommand(text)
|
|||
"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 @@ function handleChatCommand(text)
|
|||
"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 @@ function ircFormat(msg)
|
|||
// 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 getPlayerColor(playername)
|
|||
*/
|
||||
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)
|
||||
|
|
|
|||
|
|
@ -143,9 +143,8 @@ function ShowRenderPathMessage()
|
|||
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
|
||||
|
|
|
|||
|
|
@ -922,7 +922,7 @@ function getIdleLandTradersText(traderNumber)
|
|||
"openingTradingString": activeString,
|
||||
"openingGarrisonedString": garrisonedString,
|
||||
"garrisonedString": garrisonedString,
|
||||
"inactiveString": "[color=\"" + g_IdleTraderTextColor + "\"]" + inactiveString + "[/color]"
|
||||
"inactiveString": coloredText(inactiveString, g_IdleTraderTextColor)
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -970,7 +970,7 @@ function getIdleShipTradersText(traderNumber)
|
|||
|
||||
return sprintf(message, {
|
||||
"openingTradingString": activeString,
|
||||
"inactiveString": "[color=\"" + g_IdleTraderTextColor + "\"]" + inactiveString + "[/color]"
|
||||
"inactiveString": coloredText(inactiveString, g_IdleTraderTextColor)
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -546,7 +546,7 @@ function updateTutorial(notification)
|
|||
|
||||
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 @@ function updateTutorial(notification)
|
|||
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 colorizePlayernameByGUID(guid)
|
|||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -342,7 +342,7 @@ g_SelectionPanels.Formation = {
|
|||
|
||||
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 @@ g_SelectionPanels.Queue = {
|
|||
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 @@ g_SelectionPanels.Training = {
|
|||
].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));
|
||||
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ function formatLimitString(trainEntLimit, trainEntCount, trainEntLimitChangers)
|
|||
});
|
||||
|
||||
if (trainEntCount >= trainEntLimit)
|
||||
text = "[color=\"red\"]" + text + "[/color]";
|
||||
text = coloredText(text, "red");
|
||||
|
||||
for (var c in trainEntLimitChangers)
|
||||
{
|
||||
|
|
@ -161,12 +161,16 @@ function formatBatchTrainingString(buildingsCountToTrainFullBatch, fullBatchSize
|
|||
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]";
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -635,7 +635,7 @@ var g_UnitActions =
|
|||
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 @@ var g_UnitActions =
|
|||
|
||||
if (targetState.garrisonHolder.garrisonedEntitiesCount >=
|
||||
targetState.garrisonHolder.capacity)
|
||||
tooltip = "[color=\"orange\"]" + tooltip + "[/color]";
|
||||
tooltip = coloredText(tooltip, "orange");
|
||||
}
|
||||
else if (targetState.resourceSupply)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ function formatSummaryValue(values)
|
|||
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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -214,7 +214,9 @@ var getScorePanelsData = () => ({
|
|||
|
||||
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()
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ function initGUICharts()
|
|||
|
||||
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");
|
||||
|
|
|
|||
Loading…
Reference in a new issue