Ticket #1802: hero_button.4.patch

File hero_button.4.patch, 6.7 KB (added by alpha123, 11 years ago)

Removed hotkey (moved to another ticket)

  • binaries/data/mods/public/gui/common/global.xml

     
    2626            sprite="colour: 0 0 0 200"
    2727            font="mono-stroke-10"
    2828            textcolor="white"
    29             size="5 35 80 55"
     29            size="100%-80 70 100%-10 90"
    3030            z="199"
    3131        >
    3232            <action on="Tick"><![CDATA[
  • binaries/data/mods/public/gui/session/session.js

     
    369369    if (g_ShowAllStatusBars)
    370370        recalculateStatusBarDisplay();
    371371
     372    updateHero(simState);
    372373    updateGroups();
    373374    updateDebug(simState);
    374375    updatePlayerDisplay(simState);
     
    383384        global.music.setState(global.music.states[battleState]);
    384385}
    385386
     387function updateHero(simState)
     388{
     389    var playerState = simState.players[Engine.GetPlayerID()];
     390
     391    if (playerState.heroes.length > 0)
     392    {
     393        var heroImage = getGUIObjectByName("unitHeroImage");
     394        var heroState = Engine.GuiInterfaceCall("GetEntityState", playerState.heroes[0]);
     395        var template = GetTemplateData(heroState.template);
     396        heroImage.sprite = "stretched:session/portraits/" + template.icon;
     397
     398        var heroButton = getGUIObjectByName("unitHeroButton");
     399        heroButton.onpress = (function(e) { return function() { g_Selection.reset(); g_Selection.addList([e]); } })(playerState.heroes[0]);
     400        heroButton.ondoublepress = (function(e) { return function() { selectAndMoveTo(e) }; })(playerState.heroes[0]);
     401        heroButton.hidden = false;
     402       
     403        // Setup tooltip
     404
     405        var name = "[font=\"serif-bold-16\"]" + template.name.specific + "[/font] ";
     406        var health = "[font=\"serif-bold-13\"]Health:[/font] " + heroState.hitpoints + "/" + heroState.maxHitpoints;
     407       
     408        var type = "";
     409        if (heroState.attack)
     410            type = heroState.attack.type + " ";
     411        var attack = "[font=\"serif-bold-13\"]" + type + "Attack:[/font] " + damageTypeDetails(heroState.attack);
     412        // Show max attack range if ranged attack, also convert to tiles (4m per tile)
     413        if (heroState.attack && heroState.attack.type == "Ranged")
     414            attack += ", [font=\"serif-bold-13\"]Range:[/font] " + Math.round(heroState.attack.maxRange/4);
     415
     416        var armor = "[font=\"serif-bold-13\"]Armor:[/font] " + damageTypeDetails(heroState.armour);
     417        var extra = template.tooltip;
     418       
     419        heroButton.tooltip = name + "\n" + health + "\n" + attack + "\n" + armor + "\n" + extra;
     420    }
     421    else
     422    {   
     423        var heroButton = getGUIObjectByName("unitHeroButton");
     424        heroButton.hidden = true;
     425    }
     426
     427};
     428
    386429function updateGroups()
    387430{
    388431    var guiName = "Group";
  • binaries/data/mods/public/gui/session/session.xml

     
    666757    </object>
    667758
    668759    <!-- ================================  ================================ -->
     760    <!-- Hero Selection -->
     761    <!-- ================================  ================================ -->
     762    <object
     763        name="unitHeroPanel"
     764        size="0% 5% 0%+50 5%+50"
     765    >
     766        <object name="unitHeroButton" size="0 0 50 50" type="button" hidden="false" style="iconButton"
     767            tooltip_style="sessionToolTip" tooltip="Attack and Armor">
     768            <object name="unitHeroImage" size="5 5 100%-5 100%-5" type="image" ghost="true"/>
     769        </object>
     770
     771    </object>   
     772   
     773    <!-- ================================  ================================ -->
    669774    <!-- Unit Selection Groups -->
    670775    <!-- ================================  ================================ -->
    671776    <objectIndex: binaries/data/mods/public/simulation/components/GuiInterface.js
  • binaries/data/mods/public/simulation/components/GuiInterface.js

     
    7979            "popCount": cmpPlayer.GetPopulationCount(),
    8080            "popLimit": cmpPlayer.GetPopulationLimit(),
    8181            "popMax": cmpPlayer.GetMaxPopulation(),
     82            "heroes": cmpPlayer.GetHeroes(),
    8283            "resourceCounts": cmpPlayer.GetResourceCounts(),
    8384            "trainingBlocked": cmpPlayer.IsTrainingBlocked(),
    8485            "state": cmpPlayer.GetState(),
  • binaries/data/mods/public/simulation/components/Player.js

     
    1919        "metal": 300,
    2020        "stone": 300
    2121    };
    22 
     22   
    2323    this.team = -1; // team number of the player, players on the same team will always have ally diplomatic status - also this is useful for team emblems, scoring, etc.
    2424    this.teamsLocked = false;
    2525    this.state = "active"; // game state - one of "active", "defeated", "won"
     
    3232    this.isAI = false;
    3333    this.cheatsEnabled = true;
    3434    this.cheatTimeMultiplier = 1;
     35    this.heroes = [];
    3536};
    3637
    3738Player.prototype.SetPlayerID = function(id)
     
    109110    return Math.round(ApplyTechModificationsToPlayer("Player/MaxPopulation", this.maxPop, this.entity));
    110111};
    111112
     113Player.prototype.GetHeroes = function()
     114{
     115    return this.heroes;
     116};
     117
    112118Player.prototype.IsTrainingBlocked = function()
    113119{
    114120    return this.trainingBlocked;
     
    446452Player.prototype.OnGlobalOwnershipChanged = function(msg)
    447453{
    448454    var isConquestCritical = false;
     455    var cmpIdentity = Engine.QueryInterface(msg.entity, IID_Identity);
     456   
    449457    // Load class list only if we're going to need it
    450458    if (msg.from == this.playerID || msg.to == this.playerID)
    451459    {
    452         var cmpIdentity = Engine.QueryInterface(msg.entity, IID_Identity);
    453460        if (cmpIdentity)
    454461        {
    455462            isConquestCritical = cmpIdentity.HasClass("ConquestCritical");
     
    465472            this.popUsed -= cost.GetPopCost();
    466473            this.popBonuses -= cost.GetPopBonus();
    467474        }
     475       
     476        if (cmpIdentity && cmpIdentity.HasClass("Hero"))
     477        {
     478            //Remove from Heroes list
     479            var index = this.heroes.indexOf(msg.entity);
     480            if (index >= 0)
     481            {
     482                this.heroes.splice(index, 1);
     483            }
     484            else
     485            {
     486                // Why is not the Hero in the list?
     487            }
     488        }
     489       
    468490    }
    469491    if (msg.to == this.playerID)
    470492    {
     
    476498            this.popUsed += cost.GetPopCost();
    477499            this.popBonuses += cost.GetPopBonus();
    478500        }
     501       
     502        if (cmpIdentity && cmpIdentity.HasClass("Hero"))
     503        {
     504            this.heroes.push(msg.entity);
     505        }
    479506    }
    480507};
    481508