Show rank icon above status bars

Reviewed by: bb
Fixes: #5005
Differential Revision: https://code.wildfiregames.com/D717
This was SVN commit r21076.
This commit is contained in:
Imarok 2018-01-30 15:10:20 +00:00
parent 2bfb580415
commit 776899c254
11 changed files with 45 additions and 23 deletions

View File

@ -364,6 +364,7 @@ woundedunithotkeythreshold = 33 ; The wounded unit hotkey considers the select
attackrange = true ; Display attack range overlays of selected defensive structures attackrange = true ; Display attack range overlays of selected defensive structures
aurasrange = true ; Display aura range overlays of selected units and structures aurasrange = true ; Display aura range overlays of selected units and structures
healrange = true ; Display heal range overlays of selected units healrange = true ; Display heal range overlays of selected units
rankabovestatusbar = true ; Show rank icons above status bars
respoptooltipsort = 0 ; Sorting players in the resources and population tooltip by value (0 - no sort, -1 - ascending, 1 - descending) respoptooltipsort = 0 ; Sorting players in the resources and population tooltip by value (0 - no sort, -1 - ascending, 1 - descending)
[gui.session.minimap] [gui.session.minimap]

View File

@ -128,6 +128,12 @@
"tooltip": "Display the healing range of selected units (can also be toggled in-game with the hotkey).", "tooltip": "Display the healing range of selected units (can also be toggled in-game with the hotkey).",
"config": "gui.session.healrange" "config": "gui.session.healrange"
}, },
{
"type": "boolean",
"label": "Rank icon above status bar",
"tooltip": "Show rank icons above status bars",
"config": "gui.session.rankabovestatusbar"
},
{ {
"type": "dropdown", "type": "dropdown",
"label": "Sort resources and population tooltip", "label": "Sort resources and population tooltip",

View File

@ -9,7 +9,7 @@
<object type="image" sprite="ModernFade"/> <object type="image" sprite="ModernFade"/>
<!-- Settings Window --> <!-- Settings Window -->
<object name="options" type="image" style="ModernDialog" size="50%-350 50%-330 50%+350 50%+330"> <object name="options" type="image" style="ModernDialog" size="50%-350 50%-332 50%+350 50%+332">
<object style="ModernLabelText" type="text" size="50%-128 -16 50%+128 16"> <object style="ModernLabelText" type="text" size="50%-128 -16 50%+128 16">
<translatableAttribute id="caption">Game Options</translatableAttribute> <translatableAttribute id="caption">Game Options</translatableAttribute>

View File

@ -14,8 +14,13 @@ function _setHighlight(ents, alpha, selected)
function _setStatusBars(ents, enabled) function _setStatusBars(ents, enabled)
{ {
if (ents.length) if (!ents.length)
Engine.GuiInterfaceCall("SetStatusBars", { "entities": ents, "enabled": enabled }); return;
Engine.GuiInterfaceCall("SetStatusBars", {
"entities": ents,
"enabled": enabled,
"showRank": Engine.ConfigDB_GetValue("user", "gui.session.rankabovestatusbar") == "true"
});
} }
function _setMotionOverlay(ents, enabled) function _setMotionOverlay(ents, enabled)

View File

@ -84,7 +84,7 @@ function displaySingle(entState)
Engine.GetGUIObjectByName("rankIcon").tooltip = sprintf(translate("%(rank)s Rank"), { Engine.GetGUIObjectByName("rankIcon").tooltip = sprintf(translate("%(rank)s Rank"), {
"rank": translateWithContext("Rank", entState.identity.rank) "rank": translateWithContext("Rank", entState.identity.rank)
}); });
Engine.GetGUIObjectByName("rankIcon").sprite = getRankIconSprite(entState); Engine.GetGUIObjectByName("rankIcon").sprite = "stretched:session/icons/ranks/" + entState.identity.rank + ".png";
Engine.GetGUIObjectByName("rankIcon").hidden = false; Engine.GetGUIObjectByName("rankIcon").hidden = false;
} }
else else
@ -476,20 +476,6 @@ function updateSelectionDetails()
updateGarrisonHealthBar(entStates[0], g_Selection.toList()); updateGarrisonHealthBar(entStates[0], g_Selection.toList());
} }
function getRankIconSprite(entState)
{
if (entState.identity.rank == "Elite")
return "stretched:session/icons/rank3.png";
if (entState.identity.rank == "Advanced")
return "stretched:session/icons/rank2.png";
if (entState.identity.classes.indexOf("CitizenSoldier") != -1)
return "stretched:session/icons/rank1.png";
return "";
}
function tradingGainString(gain, owner) function tradingGainString(gain, owner)
{ {
// Translation: Used in the trading gain tooltip // Translation: Used in the trading gain tooltip

View File

@ -1292,7 +1292,8 @@ function recalculateStatusBarDisplay(remove = false)
Engine.GuiInterfaceCall("SetStatusBars", { Engine.GuiInterfaceCall("SetStatusBars", {
"entities": entities, "entities": entities,
"enabled": g_ShowAllStatusBars && !remove "enabled": g_ShowAllStatusBars && !remove,
"showRank": Engine.ConfigDB_GetValue("user", "gui.session.rankabovestatusbar") == "true"
}); });
} }

View File

@ -823,7 +823,7 @@ GuiInterface.prototype.SetStatusBars = function(player, cmd)
let cmpStatusBars = Engine.QueryInterface(ent, IID_StatusBars); let cmpStatusBars = Engine.QueryInterface(ent, IID_StatusBars);
if (!cmpStatusBars) if (!cmpStatusBars)
continue; continue;
cmpStatusBars.SetEnabled(cmd.enabled); cmpStatusBars.SetEnabled(cmd.enabled, cmd.showRank);
let cmpAuras = Engine.QueryInterface(ent, IID_Auras); let cmpAuras = Engine.QueryInterface(ent, IID_Auras);
if (!cmpAuras) if (!cmpAuras)

View File

@ -26,11 +26,13 @@ StatusBars.prototype.Sprites = [
"CaptureBar", "CaptureBar",
"HealthBar", "HealthBar",
"AuraIcons", "AuraIcons",
]; "RankIcon"
];
StatusBars.prototype.Init = function() StatusBars.prototype.Init = function()
{ {
this.enabled = false; this.enabled = false;
this.showRank = false;
this.auraSources = new Map(); this.auraSources = new Map();
}; };
@ -48,13 +50,14 @@ StatusBars.prototype.Deserialize = function(data)
this.auraSources = data.auraSources; this.auraSources = data.auraSources;
}; };
StatusBars.prototype.SetEnabled = function(enabled) StatusBars.prototype.SetEnabled = function(enabled, showRank)
{ {
// Quick return if no change // Quick return if no change
if (enabled == this.enabled) if (enabled == this.enabled && showRank == this.showRank)
return; return;
this.enabled = enabled; this.enabled = enabled;
this.showRank = showRank;
// Update the displayed sprites // Update the displayed sprites
this.RegenerateSprites(); this.RegenerateSprites();
@ -269,4 +272,24 @@ StatusBars.prototype.AddAuraIcons = function(cmpOverlayRenderer, yoffset)
return iconSize + this.template.BarHeight / 2; return iconSize + this.template.BarHeight / 2;
}; };
StatusBars.prototype.AddRankIcon = function(cmpOverlayRenderer, yoffset)
{
if (!this.enabled || !this.showRank)
return 0;
let cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity);
if (!cmpIdentity || !cmpIdentity.GetRank())
return 0;
let iconSize = +this.template.BarWidth / 2;
cmpOverlayRenderer.AddSprite(
"art/textures/ui/session/icons/ranks/" + cmpIdentity.GetRank() + ".png",
{ "x": -iconSize / 2, "y": yoffset },
{ "x": iconSize / 2, "y": iconSize + yoffset },
{ "x": 0, "y": +this.template.HeightOffset + 0.1, "z": 0 },
g_NaturalColor);
return iconSize + this.template.BarHeight / 2;
};
Engine.RegisterComponentType(IID_StatusBars, "StatusBars", StatusBars); Engine.RegisterComponentType(IID_StatusBars, "StatusBars", StatusBars);