Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/simulation/components/StatusBars.js
Show All 20 Lines | |||||
* provide the right methods. | * provide the right methods. | ||||
*/ | */ | ||||
StatusBars.prototype.Sprites = [ | StatusBars.prototype.Sprites = [ | ||||
"PackBar", | "PackBar", | ||||
"ResourceSupplyBar", | "ResourceSupplyBar", | ||||
"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(); | ||||
}; | }; | ||||
/** | /** | ||||
* 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 }; | ||||
}; | }; | ||||
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( | ||||
g_NaturalColor | g_NaturalColor | ||||
); | ); | ||||
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 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); |
Wildfire Games · Phabricator