Changeset View
Standalone View
binaries/data/mods/public/simulation/components/StatusBars.js
Show All 15 Lines | |||||
/** | /** | ||||
* For every sprite, the code will call their "Add" method when regenerating | * For every sprite, the code will call their "Add" method when regenerating | ||||
* the sprites. Every sprite adder should return the height it needs. | * the sprites. Every sprite adder should return the height it needs. | ||||
* | * | ||||
* Modders who need extra sprites can just modify this array, and | * Modders who need extra sprites can just modify this array, and | ||||
* provide the right methods. | * provide the right methods. | ||||
*/ | */ | ||||
StatusBars.prototype.Sprites = | StatusBars.prototype.Sprites = | ||||
[ | [ | ||||
bb: trailing comma | |||||
"PackBar", | "PackBar", | ||||
"ResourceSupplyBar", | "ResourceSupplyBar", | ||||
"CaptureBar", | "CaptureBar", | ||||
"HealthBar", | "HealthBar", | ||||
"AuraIcons", | "AuraIcons", | ||||
"RankIcon", | |||||
]; | ]; | ||||
Done Inline Actionsindentation bb: indentation | |||||
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(); | ||||
}; | }; | ||||
/** | /** | ||||
* Don't serialise this.enabled since it's modified by the GUI | * Don't serialise this.enabled since it's modified by the GUI | ||||
*/ | */ | ||||
StatusBars.prototype.Serialize = function() | StatusBars.prototype.Serialize = function() | ||||
{ | { | ||||
return {"auraSources": this.auraSources}; | return {"auraSources": this.auraSources}; | ||||
Done Inline ActionsBetter commit those unrelated whitespace clenaup hunks separately IMO. Could then add more whitespace fixes too. elexis: Better commit those unrelated whitespace clenaup hunks separately IMO. Could then add more… | |||||
Done Inline ActionsTrue, wasn't sure about that Imarok: True, wasn't sure about that | |||||
}; | }; | ||||
StatusBars.prototype.Deserialize = function(data) | StatusBars.prototype.Deserialize = function(data) | ||||
{ | { | ||||
this.Init(); | this.Init(); | ||||
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(); | ||||
}; | }; | ||||
StatusBars.prototype.AddAuraSource = function(source, auraName) | StatusBars.prototype.AddAuraSource = function(source, auraName) | ||||
{ | { | ||||
if (this.auraSources.has(source)) | if (this.auraSources.has(source)) | ||||
▲ Show 20 Lines • Show All 198 Lines • ▼ Show 20 Lines | cmpOverlayRenderer.AddSprite( | ||||
NATURAL_COLOR | NATURAL_COLOR | ||||
); | ); | ||||
xoffset += iconSize * 1.2; | xoffset += iconSize * 1.2; | ||||
} | } | ||||
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 icon = "art/textures/ui/session/icons/ranks/" + cmpIdentity.GetRank() + ".png"; | |||||
elexisUnsubmitted Done Inline Actionscan be inlined elexis: can be inlined | |||||
let iconSize = +this.template.BarWidth / 2; | |||||
cmpOverlayRenderer.AddSprite( | |||||
icon, | |||||
Done Inline ActionsCreating an object and then picking one item right afterwards is discouraged. Instead one should make that a global or prototype property, which might also ease modding. I believe it's bad to hardcode these png's here, that should be in the templates. elexis: Creating an object and then picking one item right afterwards is discouraged. Instead one… | |||||
Done Inline ActionsI think it would be best to merge it with the one in selection_details (https://github.com/0ad/0ad/blob/99db7f2c4fcab81ddaba5f336efa5ed4395e0019/binaries/data/mods/public/gui/session/selection_details.js#L497).
It's done the same way in the code above, but I agree, it would be nice to have this in the templates, but where? Imarok: I think it would be best to merge it with the one in selection_details (https://github. | |||||
Done Inline ActionsAdding it to Templates.js sounds like giving someone a reason to add a copy of that file again xd Ideally it should be in the templates and the GUI pulling it through the Templates.js file or GUI Interface. A special filter template might also be an idea, so that entities are promoted to elite|civ_foo_e. Also unsatisying becaues the rank information should be grouped. How about just expecting art/textures/ui/session/icons/ranks/ + rankName + ".png"? Will have to juggle with the CitizenSoldier check, but I guess that might be hidden too somehow. Apparently the Rank is optional, so women and champions shouldn't have it (mace infantry champs can promote but don't have a rank afaics. spartan skiritai have a rank but can't promote, so should be fine for our mod). elexis: Adding it to Templates.js sounds like giving someone a reason to add a copy of that file again… | |||||
{ "x": -iconSize / 2, "y": yoffset }, | |||||
Done Inline Actionsimo no need to split these over several lines, but other people might think differently bb: imo no need to split these over several lines, but other people might think differently | |||||
Not Done Inline ActionsI think it's good as is. Imarok: I think it's good as is. | |||||
{ "x": iconSize / 2, "y": iconSize + yoffset }, | |||||
{ "x": 0, "y": +this.template.HeightOffset + 0.1, "z": 0 }, | |||||
Not Done Inline Actionsno need for a new line bb: no need for a new line | |||||
Not Done Inline Actionsok Imarok: ok | |||||
NATURAL_COLOR | |||||
); | |||||
Done Inline ActionsWhy the 0.1? elexis: Why the 0.1? | |||||
Done Inline ActionsIt looks better. Imarok: It looks better.
Else the icons can collide. | |||||
Done Inline Actionsoffset could be inlined. the comment should be clear from the function elexis: offset could be inlined. the comment should be clear from the function | |||||
return iconSize + this.template.BarHeight / 2; | |||||
}; | |||||
Engine.RegisterComponentType(IID_StatusBars, "StatusBars", StatusBars); | Engine.RegisterComponentType(IID_StatusBars, "StatusBars", StatusBars); | ||||
Done Inline ActionsShould that ); should really be on a separate line? it's not an object elexis: Should that `);` should really be on a separate line? it's not an object | |||||
Done Inline ActionsProbably not Imarok: Probably not |
trailing comma