Ticket #2357: idle_worker_blink_v13.patch

File idle_worker_blink_v13.patch, 15.0 KB (added by Michael, 10 years ago)

Update because #2421 was updated.

  • binaries/data/mods/public/gui/common/colorFades.js

     
    217217    return false;
    218218}
    219219
    220 //[END] of hero fade functions
    221  No newline at end of file
     220//[END] of hero fade functions
     221//[START] idle workers icon
     222
     223function colorFade_IdleWorker(data)
     224{
     225    var rgb = data.rgb;
     226    // init color
     227    if (data.tickCounter == 0)
     228    {
     229        rgb.r = 255;
     230        rgb.g = 255;
     231        rgb.b = 255;
     232    }
     233    // hide it every tick
     234    if (data.tickCounter % 2 == 0)
     235        rgb.o = 0;
     236    else
     237        rgb.o = 100;
     238}
     239
     240//[END] of idle workers icon functions
     241 No newline at end of file
  • binaries/data/mods/public/gui/session/input.js

     
    20842084    lastIdleType = undefined;
    20852085}
    20862086
    2087 function findIdleUnit(classes)
     2087// selectionLimit [optional]: positive number greater than zero or false, if all should be selected
     2088function findIdleUnit(classes, selectionLimit)
    20882089{
    20892090    var append = Engine.HotkeyIsPressed("selection.add");
    2090     var selectall = Engine.HotkeyIsPressed("selection.offscreen");
     2091    var selectall = Engine.HotkeyIsPressed("selection.offscreen") || selectionLimit === false;
     2092    if (!selectionLimit || selectionLimit <= 0)
     2093        selectionLimit = 1;
    20912094
    20922095    // Reset the last idle unit, etc., if the selection type has changed.
    20932096    var type = classes.join();
     
    21012104
    21022105    for (var i = 0; i < classes.length; ++i)
    21032106    {
    2104         var data = { idleClass: classes[currIdleClass], prevUnit: lastIdleUnit, limit: 1 };
     2107        var data = { idleClass: classes[currIdleClass], prevUnit: lastIdleUnit, limit: selectionLimit };
    21052108        if (append)
    21062109            data.excludeUnits = g_Selection.toList();
    21072110
  • binaries/data/mods/public/gui/session/session.js

     
    5656// always through the list of all ongoing attacks...
    5757var g_previousHeroHitPoints = undefined;
    5858
     59// cache idle worker button class names
     60var g_idleWorkerClasses = undefined;
     61
    5962function GetSimState()
    6063{
    6164    if (!g_SimState)
     
    148151    {
    149152        g_Players = getPlayerData(null);
    150153    }
     154   
     155    // cache worker class data
     156    g_idleWorkerClasses = Engine.GuiInterfaceCall("GetIdleWorkerClasses");
    151157
     158    // set function to button
     159    for (var n = 1; n <= 3; n++)
     160    {
     161        var idleWorkerButton = Engine.GetGUIObjectByName("idleWorkerButton[" + n + "]");
     162        if (idleWorkerButton)
     163        {
     164            idleWorkerButton.onpress = function() { findIdleUnit(g_idleWorkerClasses); };
     165            idleWorkerButton.onpressright = function() { findIdleUnit(g_idleWorkerClasses, false); };
     166        }
     167    }
     168
    152169    // Cache civ data
    153170    g_CivData = loadCivData();
    154171    g_CivData["gaia"] = { "Code": "gaia", "Name": "Gaia" };
     
    490507    updatePlayerDisplay();
    491508    updateSelectionDetails();
    492509    updateResearchDisplay();
     510    updateIdleWorkerButton();
    493511    updateBuildingPlacementPreview();
    494512    updateTimeElapsedCounter();
    495513    updateTimeNotifications(); 
     
    502520}
    503521
    504522/**
     523+ * updates the idle worker button
     524+ */
     525function updateIdleWorkerButton()
     526{
     527    var simState = GetSimState();
     528    var idleUnitsCounter = simState.players[Engine.GetPlayerID()].idleWorkerButtonCount;
     529    // set color fade and label
     530    if (idleUnitsCounter > 0)
     531    {
     532        startColorFade("idleWorkerColorOverlay", 750, 0, colorFade_IdleWorker, "session/minimap-idle-colorMask.png", false);
     533        var label = Engine.GetGUIObjectByName("idleWorkerLabel")
     534        label.caption = idleUnitsCounter;
     535        label.hidden = false;
     536    }
     537    else
     538    {
     539        stopColorFade("idleWorkerColorOverlay");
     540        var label = Engine.GetGUIObjectByName("idleWorkerLabel");
     541        label.hidden = true;
     542    }
     543}
     544
     545/**
    505546* updates a status bar on the GUI
    506547* nameOfBar: name of the bar
    507548* points: points to show
     
    595636    {   
    596637        g_previousHeroHitPoints = heroState.hitpoints;
    597638        // trigger the animation
    598         startColorFade("heroHitOverlay", 100, 0, colorFade_attackUnit, true, smoothColorFadeRestart_attackUnit);
     639        startColorFade("heroHitOverlay", 100, 0, colorFade_attackUnit, undefined, true, smoothColorFadeRestart_attackUnit);
    599640        return;
    600641    }
    601642}
  • binaries/data/mods/public/gui/session/session.xml

     
    949949
    950950        <!-- Idle Worker Button -->
    951951        <object size="100%-36 100%-36 100%-5 100%-5">
    952             <!-- TODO: should highlight the button if there's non-zero idle workers -->
    953952            <object name="idle-overlay" size="-85 -85 100% 100%" type="image" sprite="stretched:session/minimap-idle.png" ghost="true"/>
    954953            <!-- Since we don't support non-rectangular buttons, we approximate the area using 3 rectangles TODO: Make this cleaner -->
    955             <object type="button"
     954            <object type="button" name="idleWorkerButton[1]"
    956955                tooltip_style="sessionToolTip"
    957                 tooltip="Find idle worker"
     956                tooltip="Click to find an idle worker, right-click to select all idle workers."
    958957                hotkey="selection.idleworker"
    959             >
    960                 <action on="Press">findIdleUnit(["Female", "Trade", "FishingBoat", "CitizenSoldier", "Healer"]);</action>
    961             </object>
    962             <object type="button"
     958            />
     959            <object type="button" name="idleWorkerButton[2]"
    963960                tooltip_style="sessionToolTip"
    964                 tooltip="Find idle worker"
     961                tooltip="Click to find an idle worker, right-click to select all idle workers."
    965962                size="15 -15 100% 0"
    966             >
    967                 <action on="Press">findIdleUnit(["Female", "Trade", "FishingBoat", "CitizenSoldier", "Healer"]);</action>
    968             </object>
    969             <object type="button"
     963            />
     964            <object type="button" name="idleWorkerButton[3]"
    970965                tooltip_style="sessionToolTip"
    971                 tooltip="Find idle worker"
     966                tooltip="Click to find an idle worker, right-click to select all idle workers."
    972967                size="-15 15 0 100%"
    973             >
    974                 <action on="Press">findIdleUnit(["Female", "Trade", "FishingBoat", "CitizenSoldier", "Healer"]);</action>
    975             </object>
     968            />
     969            <object name="idleWorkerColorOverlay" type="image" size="-85 -85 100% 100%" ghost="true"/>
     970            <object name="idleWorkerLabel" type="text" style="groupIconsText" size="0 0 100% 100%" ghost="true"/>
    976971        </object>
    977972    </object>
    978973
  • binaries/data/mods/public/simulation/components/GuiInterface.js

     
    8989            "team": cmpPlayer.GetTeam(),
    9090            "teamsLocked": cmpPlayer.GetLockTeams(),
    9191            "cheatsEnabled": cmpPlayer.GetCheatsEnabled(),
     92            "idleWorkerButtonCount": cmpPlayer.GetIdleWorkerButtonCount(),
    9293            "phase": phase,
    9394            "isAlly": allies,
    9495            "isMutualAlly": mutualAllies,
     
    727728};
    728729
    729730// Returns the battle state of the player.
     731GuiInterface.prototype.GetIdleWorkerClasses = function(player)
     732{
     733    // try to get the data
     734    var cmpPlayer = QueryPlayerIDInterface(player, IID_Player);
     735    if (!cmpPlayer)
     736        return [];
     737    else
     738        return cmpPlayer.GetIdleWorkerButtonClassesList();
     739};
     740
     741// Returns the battle state of the player.
    730742GuiInterface.prototype.GetBattleState = function(player)
    731743{
    732744    var cmpBattleDetection = QueryPlayerIDInterface(player, IID_BattleDetection);
     
    19761988    "SetWallPlacementPreview": 1,
    19771989    "GetFoundationSnapData": 1,
    19781990    "PlaySound": 1,
     1991    "GetIdleWorkerClasses" :1,
    19791992    "FindIdleUnits": 1,
    19801993    "GetTradingRouteGain": 1,
    19811994    "GetTradingDetails": 1,
  • binaries/data/mods/public/simulation/components/Player.js

     
    11function Player() {}
    22
    33Player.prototype.Schema =
    4     "<a:component type='system'/><empty/>";
    5 
     4    "<element name='IdleWorkerButtonClasses' a:help='Classes of entities which are used for the idle worker button.'>" +
     5        "<attribute name='datatype'>" +
     6            "<value>tokens</value>" +
     7        "</attribute>" +
     8        "<text/>" +
     9    "</element>";
     10   
    611Player.prototype.Init = function()
    712{
    813    this.playerID = undefined;
     
    3641    this.cheatsEnabled = false;
    3742    this.cheatTimeMultiplier = 1;
    3843    this.heroes = [];
     44    this.idleWorkerButtonCount = 0;
     45    this.idleWorkerButtonClasses = this.template.IdleWorkerButtonClasses._string ? this.template.IdleWorkerButtonClasses._string.split(/\s+/) : []; // classes used for the work idle button
    3946    Engine.QueryInterface(SYSTEM_ENTITY, IID_EndGameManager).CheckConquestCriticalEntities();
    4047};
    4148
     49/**
     50 * Returns an array of unit classes which are used for the idle worker button
     51 */
     52Player.prototype.GetIdleWorkerButtonClassesList = function()
     53{
     54    return this.idleWorkerButtonClasses;
     55};
     56
    4257Player.prototype.SetPlayerID = function(id)
    4358{
    4459    this.playerID = id;
     
    559574            if (index >= 0)
    560575                this.heroes.splice(index, 1);
    561576        }
     577        // check, if new idle worker is gone
     578        var cmpUnitAI = Engine.QueryInterface(msg.entity, IID_UnitAI);
     579        if (cmpUnitAI)
     580            if (cmpUnitAI.IsIdle() && cmpUnitAI.IsUsedForIdleWorkerButton())
     581                this.DecreaseWorkerButtonCount();
    562582    }
    563583    if (msg.to == this.playerID)
    564584    {
     
    570590
    571591        if (cmpIdentity && cmpIdentity.HasClass("Hero"))
    572592            this.heroes.push(msg.entity);
     593           
     594        // check, if new idle worker is there
     595        var cmpUnitAI = Engine.QueryInterface(msg.entity, IID_UnitAI);
     596        if (cmpUnitAI)
     597            if (cmpUnitAI.IsIdle() && cmpUnitAI.IsUsedForIdleWorkerButton())
     598                this.IncreaseWorkerButtonCount();
    573599    }
    574600};
    575601
     
    664690        cmpGUIInterface.PushNotification(notification);
    665691};
    666692
     693Player.prototype.GetIdleWorkerButtonCount = function()
     694{
     695    return this.idleWorkerButtonCount;
     696};
     697
     698Player.prototype.IncreaseWorkerButtonCount = function()
     699{
     700    this.idleWorkerButtonCount++;
     701};
     702
     703Player.prototype.DecreaseWorkerButtonCount = function()
     704{
     705    this.idleWorkerButtonCount--;
     706    if (this.idleWorkerButtonCount < 0)
     707    {
     708        this.idleWorkerButtonCount = 0;
     709        error("Negative worker idle count for player '" + this.playerID + "'");
     710    }
     711};
     712
    667713Engine.RegisterComponentType(IID_Player, "Player", Player);
  • binaries/data/mods/public/simulation/components/UnitAI.js

     
    169169    "GuardedAttacked": function(msg) {
    170170        // ignore
    171171    },
     172   
     173    "UnitIdleChanged": function(msg) {     
     174        // do only if its not animal and is used for the idle worker button
     175        if (!this.IsAnimal() && this.IsUsedForIdleWorkerButton())
     176        {
     177            var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player);
     178            if (cmpPlayer)
     179            {
     180                if(msg.idle)
     181                    cmpPlayer.IncreaseWorkerButtonCount();
     182                else
     183                    cmpPlayer.DecreaseWorkerButtonCount();
     184            }
     185        }
     186    },
    172187
    173188    // Formation handlers:
    174189
     
    14011416                return false;
    14021417            },
    14031418
    1404             "leave": function() {
     1419            "leave": function(msg) {
    14051420                var rangeMan = Engine.QueryInterface(SYSTEM_ENTITY, IID_RangeManager);
    14061421                if (this.losRangeQuery)
    14071422                    rangeMan.DisableActiveQuery(this.losRangeQuery);
     
    14091424                    rangeMan.DisableActiveQuery(this.losHealRangeQuery);
    14101425
    14111426                this.StopTimer();
    1412 
    1413                 if (this.isIdle)
     1427                // only change idle state, if next state is different from idle (happens in case of death of unit FormationIdle --> IndiviIdle)
     1428                if (this.isIdle && !(msg.nextState && msg.nextState.length > 0 && msg.nextState[msg.nextState.length-1].indexOf(".IDLE") != -1))
    14141429                {
    14151430                    this.isIdle = false;
    14161431                    Engine.PostMessage(this.entity, MT_UnitIdleChanged, { "idle": this.isIdle });
     
    30593074    this.formationController = INVALID_ENTITY; // entity with IID_Formation that we belong to
    30603075    this.isGarrisoned = false;
    30613076    this.isIdle = false;
     3077    this.isUsedForIdleWorkerButton = undefined; // will be initialised, if IsUsedForIdleWorkerButton() is called the first time
    30623078    this.lastFormationTemplate = "";
    30633079    this.finishedOrder = false; // used to find if all formation members finished the order
    30643080   
     
    31433159    return Engine.QueryInterface(this.entity, IID_Heal);
    31443160};
    31453161
     3162UnitAI.prototype.IsUsedForIdleWorkerButton = function()
     3163{
     3164    // return cached value, if some is stored
     3165    if (this.isUsedForIdleWorkerButton !== undefined)
     3166        return this.isUsedForIdleWorkerButton;
     3167   
     3168    // calculate value
     3169    this.isUsedForIdleWorkerButton = false;
     3170    var cmpIdentity = Engine.QueryInterface(this.entity, IID_Identity);
     3171    if (!cmpIdentity)
     3172        return false;
     3173    var cmpPlayer = QueryOwnerInterface(this.entity, IID_Player);
     3174    if (!cmpPlayer)
     3175        return false;
     3176    // check idle class names   
     3177    for each(var className in cmpPlayer.GetIdleWorkerButtonClassesList())
     3178        if (cmpIdentity.HasClass(className)) {
     3179            this.isUsedForIdleWorkerButton = true;
     3180            break;
     3181        }
     3182    // return the value
     3183    return this.isUsedForIdleWorkerButton;
     3184};
     3185
    31463186UnitAI.prototype.IsIdle = function()
    31473187{
    31483188    return this.isIdle;
     
    37913831    UnitFsm.ProcessMessage(this, {"type": "PackFinished", "packed": msg.packed});
    37923832};
    37933833
     3834UnitAI.prototype.OnUnitIdleChanged = function(msg)
     3835{
     3836    var cmpOwnership = Engine.QueryInterface(this.entity, IID_Ownership);
     3837    if (!cmpOwnership)
     3838        return;
     3839    UnitFsm.ProcessMessage(this, {"type": "UnitIdleChanged", "idle": msg.idle, "player": cmpOwnership.GetOwner()});
     3840}
     3841
    37943842//// Helper functions to be called by the FSM ////
    37953843
    37963844UnitAI.prototype.GetWalkSpeed = function()
  • binaries/data/mods/public/simulation/helpers/FSM.js

     
    359359        if (leave)
    360360        {
    361361            obj.fsmStateName = fromState[i];
    362             if (leave.apply(obj))
     362            if (leave.apply(obj, [{"nextState": toState}]))
    363363            {
    364364                obj.FsmStateNameChanged(obj.fsmStateName);
    365365                return;
     
    373373        if (enter)
    374374        {
    375375            obj.fsmStateName = toState[i];
    376             if (enter.apply(obj))
     376            if (enter.apply(obj, [{"previousState": fromState}]))
    377377            {
    378378                obj.FsmStateNameChanged(obj.fsmStateName);
    379379                return;
  • binaries/data/mods/public/simulation/templates/special/player.xml

     
    3939      </Pillar>
    4040    </LimitChangers>
    4141  </EntityLimits>
    42   <Player/>
     42  <Player>
     43    <IdleWorkerButtonClasses datatype="tokens">Worker Trade FishingBoat</IdleWorkerButtonClasses>
     44  </Player>
    4345  <StatisticsTracker/>
    4446  <TechnologyManager/>
    4547</Entity>