Ticket #3180: auravisualisation.diff

File auravisualisation.diff, 9.0 KB (added by sanderd17, 9 years ago)
  • binaries/data/mods/public/simulation/components/Auras.js

     
    4747                        "<text/>" +
    4848                    "</element>" +
    4949                "</optional>" +
     50                "<optional>" +
     51                    "<element name='OverlayIcon' a:help='Icon will be displayed on the affected units'>" +
     52                        "<text/>" +
     53                    "</element>" +
     54                "</optional>" +
    5055                "<element name='Affects' a:help='Affected classes'>" +
    5156                    "<text/>" +
    5257                "</element>" +
     
    103108    return Object.keys(this.template);
    104109};
    105110
     111Auras.prototype.GetOverlayIcon = function(name)
     112{
     113    return this.template[name].OverlayIcon || "";
     114};
     115
    106116Auras.prototype.GetRange = function(name)
    107117{
    108118    if (!this.IsRangeAura(name))
     
    122132    return this.auras[name].modifications;
    123133};
    124134
     135Auras.prototype.GetAffectedEntities = function(name)
     136{
     137    return this[name].targetUnits;
     138};
     139
    125140Auras.prototype.GetAffectedPlayers = function(name)
    126141{
    127142    return this.affectedPlayers[name];
  • binaries/data/mods/public/simulation/components/GuiInterface.js

     
    2626    this.timeNotificationID = 1;
    2727    this.timeNotifications = [];
    2828    this.entsRallyPointsDisplayed = [];
     29    this.entsWithStatusBars = new Set();
    2930};
    3031
    3132/*
     
    859860    }
    860861};
    861862
     863GuiInterface.prototype.GetEntsWithStatusBars = function()
     864{
     865    return [...this.entsWithStatusBars];
     866};
     867
    862868GuiInterface.prototype.SetStatusBars = function(player, cmd)
    863869{
    864     for each (var ent in cmd.entities)
     870    for (let ent of cmd.entities)
    865871    {
    866872        var cmpStatusBars = Engine.QueryInterface(ent, IID_StatusBars);
    867873        if (cmpStatusBars)
    868874            cmpStatusBars.SetEnabled(cmd.enabled);
     875        if (cmd.enabled)
     876            this.entsWithStatusBars.add(ent);
     877        else
     878            this.entsWithStatusBars.delete(ent);
     879
     880        var cmpAuras = Engine.QueryInterface(ent, IID_Auras);
     881        if (!cmpAuras)
     882            continue;
     883
     884        var affectedEntities = [];
     885        var auraNames = cmpAuras.GetAuraNames();
     886        for (let name of auraNames)
     887            if (cmpAuras.GetOverlayIcon(name))
     888                affectedEntities.push(...cmpAuras.GetAffectedEntities(name));
     889
     890        for (let affectedEnt of affectedEntities)
     891        {
     892            var cmpStatusBars = Engine.QueryInterface(affectedEnt, IID_StatusBars);
     893            if (!cmpStatusBars)
     894                continue
     895            if (cmd.enabled)
     896                cmpStatusBars.AddAuraSource(ent);
     897            else
     898                cmpStatusBars.RemoveAuraSource(ent);
     899        }
    869900    }
     901
    870902};
    871903
    872904GuiInterface.prototype.GetPlayerEntities = function(player)
  • binaries/data/mods/public/simulation/components/StatusBars.js

     
    1414StatusBars.prototype.Init = function()
    1515{
    1616    this.enabled = false;
     17    this.auraSource = []; // entity ids of the aura sources
    1718};
    1819
    1920// Because this is enabled directly by the GUI and is not
     
    3738
    3839    this.enabled = enabled;
    3940
    40     if (enabled)
     41    if (enabled || this.auraSource.length)
    4142        this.RegenerateSprites();
    4243    else
    4344        this.ResetSprites();
    4445};
    4546
     47StatusBars.prototype.AddAuraSource = function(ent)
     48{
     49    if (this.auraSource.indexOf(ent) > -1)
     50        return;
     51
     52    this.auraSource.push(ent);
     53    this.RegenerateSprites();
     54};
     55
     56StatusBars.prototype.RemoveAuraSource = function(ent)
     57{
     58    var idx = this.auraSource.indexOf(ent);
     59    if (idx == -1)
     60        return;
     61    this.auraSource.splice(idx, 1);
     62    if (this.enabled || this.auraSource.length)
     63        this.RegenerateSprites();
     64    else
     65        this.ResetSprites();
     66};
     67
    4668StatusBars.prototype.OnHealthChanged = function(msg)
    4769{
    4870    if (this.enabled)
     
    6183        this.RegenerateSprites();
    6284};
    6385
     86StatusBars.prototype.OnValueModification = function(msg)
     87{
     88    // rebuild the aura sources list for this ent
     89    var cmpGuiInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface);
     90    this.auraSource = [];
     91    var entsWithStatusBars = cmpGuiInterface.GetEntsWithStatusBars();
     92    for (let ent of entsWithStatusBars)
     93    {
     94        if (this.auraSource.indexOf(ent) != -1)
     95            continue;
     96
     97        let cmpAuras = Engine.QueryInterface(ent, IID_Auras);
     98        if (!cmpAuras)
     99            continue;
     100
     101        let auraNames = cmpAuras.GetAuraNames();
     102        let affected = false;
     103        for (let name of auraNames)
     104        {
     105            if (!cmpAuras.GetOverlayIcon(name))
     106                continue;
     107            if (cmpAuras.GetAffectedEntities(name).indexOf(this.entity) != -1)
     108                affected = true;
     109        }
     110        if (affected)
     111            this.auraSource.push(ent);
     112    }
     113    this.RegenerateSprites();
     114};
     115
    64116StatusBars.prototype.ResetSprites = function()
    65117{
    66118    var cmpOverlayRenderer = Engine.QueryInterface(this.entity, IID_OverlayRenderer);
     
    82134    // Billboard offset of next bar
    83135    var yoffset = 0;
    84136
     137    var iconList = []
     138    for (let ent of this.auraSource)
     139    {
     140        let cmpAuras = Engine.QueryInterface(ent, IID_Auras);
     141        if (!cmpAuras) // probably the ent just died
     142            return;
     143        let auraNames = cmpAuras.GetAuraNames();
     144        for (let name of auraNames)
     145        {
     146            if (cmpAuras.GetAffectedEntities(name).indexOf(this.entity) == -1)
     147                continue;
     148            let icon = cmpAuras.GetOverlayIcon(name);
     149            if (icon && iconList.indexOf(icon) == -1)
     150                iconList.push(icon);
     151        }
     152    }
     153
     154    var iconSize = width/2;
     155    for (let icon of iconList)
     156    {
     157        cmpOverlayRenderer.AddSprite(
     158            icon,
     159            { "x": -iconSize/2, "y": yoffset - iconSize/2 },
     160            { "x": iconSize/2, "y": yoffset + iconSize/2 },
     161            offset
     162        );
     163        yoffset += iconSize * 1.2;
     164    }
     165
     166    if (iconList.length)
     167        yoffset -= iconSize * 0.6;
     168
    85169    var AddBar = function(type, amount)
    86170    {
    87171        cmpOverlayRenderer.AddSprite(
    88172            "art/textures/ui/session/icons/"+type+"_bg.png",
    89             { "x": -width/2, "y": -height/2 + yoffset },
    90             { "x": width/2, "y": height/2 + yoffset },
     173            { "x": -width/2, "y": yoffset - height/2},
     174            { "x": width/2, "y": yoffset + height/2 },
    91175            offset
    92176        );
    93177
    94178        cmpOverlayRenderer.AddSprite(
    95179            "art/textures/ui/session/icons/"+type+"_fg.png",
    96             { "x": -width/2, "y": -height/2 + yoffset },
    97             { "x": width*(amount - 0.5), "y": height/2 + yoffset },
     180            { "x": -width/2, "y": yoffset - height/2 },
     181            { "x": width*(amount - 0.5), "y": yoffset + height/2 },
    98182            offset
    99183        );
    100184
    101         yoffset -= height * 1.2;
     185        yoffset += height * 1.2;
    102186    };
    103187
    104     var cmpMirage = Engine.QueryInterface(this.entity, IID_Mirage);
     188    if (this.enabled)
     189    {
     190        var cmpMirage = Engine.QueryInterface(this.entity, IID_Mirage);
     191        var cmpPack = Engine.QueryInterface(this.entity, IID_Pack);
     192        if (cmpPack && cmpPack.IsPacking())
     193            AddBar("pack", cmpPack.GetProgress());
    105194
    106     var cmpPack = Engine.QueryInterface(this.entity, IID_Pack);
    107     if (cmpPack && cmpPack.IsPacking())
    108         AddBar("pack", cmpPack.GetProgress());
     195        var cmpHealth = Engine.QueryInterface(this.entity, IID_Health);
     196        if (cmpHealth && cmpHealth.GetHitpoints() > 0)
     197            AddBar("health", cmpHealth.GetHitpoints() / cmpHealth.GetMaxHitpoints());
     198        else if (cmpMirage && cmpMirage.Health())
     199            AddBar("health", cmpMirage.GetHitpoints() / cmpMirage.GetMaxHitpoints());
    109200
    110     var cmpHealth = Engine.QueryInterface(this.entity, IID_Health);
    111     if (cmpHealth && cmpHealth.GetHitpoints() > 0)
    112         AddBar("health", cmpHealth.GetHitpoints() / cmpHealth.GetMaxHitpoints());
    113     else if (cmpMirage && cmpMirage.Health())
    114         AddBar("health", cmpMirage.GetHitpoints() / cmpMirage.GetMaxHitpoints());
    115 
    116     var cmpResourceSupply = Engine.QueryInterface(this.entity, IID_ResourceSupply);
    117     if (cmpResourceSupply)
    118         AddBar("supply", cmpResourceSupply.IsInfinite() ? 1 : cmpResourceSupply.GetCurrentAmount() / cmpResourceSupply.GetMaxAmount());
    119     else if (cmpMirage && cmpMirage.ResourceSupply())
    120         AddBar("supply", cmpMirage.IsInfinite() ? 1 : cmpMirage.GetAmount() / cmpMirage.GetMaxAmount());
    121 
    122     /*
     201        var cmpResourceSupply = Engine.QueryInterface(this.entity, IID_ResourceSupply);
     202        if (cmpResourceSupply)
     203            AddBar("supply", cmpResourceSupply.IsInfinite() ? 1 : cmpResourceSupply.GetCurrentAmount() / cmpResourceSupply.GetMaxAmount());
     204        else if (cmpMirage && cmpMirage.ResourceSupply())
     205            AddBar("supply", cmpMirage.IsInfinite() ? 1 : cmpMirage.GetAmount() / cmpMirage.GetMaxAmount());
     206    }   /*
    123207    // Rank icon disabled for now - see discussion around
    124208    // http://www.wildfiregames.com/forum/index.php?s=&showtopic=13608&view=findpost&p=212154
    125209
  • binaries/data/mods/public/simulation/templates/template_structure_civic_temple.xml

     
    1010      </Modifications>
    1111      <AuraName>Healing Aura</AuraName>
    1212      <AuraDescription>Heals nearby units at 1 HP per second.</AuraDescription>
     13      <OverlayIcon>art/textures/ui/session/auras/heal.png</OverlayIcon>
    1314    </heal>
    1415  </Auras>
    1516  <BuildRestrictions>