Ticket #1571: redIcons.patch

File redIcons.patch, 7.1 KB (added by wraitii, 12 years ago)
  • binaries/data/mods/public/simulation/components/GuiInterface.js

     
    567567    return ret;
    568568}
    569569
     570// Used to show a red square over GUI elements you can't yet afford.
     571GuiInterface.prototype.GetNeededResources = function(player, amounts){
     572    var cmpPlayer = QueryPlayerIDInterface(player, IID_Player);
     573    return cmpPlayer.GetNeededResources(amounts);
     574};
     575
     576
    570577GuiInterface.prototype.PushNotification = function(notification)
    571578{
    572579    this.notifications.push(notification);
     
    16111618    "IsTechnologyResearched": 1,
    16121619    "CheckTechnologyRequirements": 1,
    16131620    "GetStartedResearch": 1,
     1621    "GetNeededResources": 1,
    16141622    "GetNextNotification": 1,
    16151623
    16161624    "GetAvailableFormations": 1,
  • binaries/data/mods/public/simulation/components/Player.js

     
    157157        this.resourceCount[type] += (+amounts[type]);
    158158    }
    159159};
    160 
    161 Player.prototype.TrySubtractResources = function(amounts)
     160Player.prototype.GetNeededResources = function(amounts)
    162161{
    163162    // Check if we can afford it all
    164163    var amountsNeeded = {};
     
    169168    var formattedAmountsNeeded = [];
    170169    for (var type in amountsNeeded)
    171170        formattedAmountsNeeded.push(type + ": " + amountsNeeded[type]);
     171    return formattedAmountsNeeded;
     172};
     173
     174Player.prototype.TrySubtractResources = function(amounts)
     175{
     176    var formattedAmountsNeeded = this.GetNeededResources(amounts);
    172177           
    173178    // If we don't have enough resources, send a notification to the player
    174179    if (formattedAmountsNeeded.length)
  • binaries/data/mods/public/gui/session/session.xml

     
    802802            <repeat count="24">
    803803                <object name="unitConstructionButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom">
    804804                <object name="unitConstructionIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
     805                <object name="unitConstructionUnaffordable[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="colour: 255 0 0 127"/>
    805806                </object>
    806807            </repeat>
    807808            </object>
     
    815816                <object name="unitResearchButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom">
    816817                <object name="unitResearchIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
    817818                <object name="unitResearchSelection[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="colour: 255 0 0 127"/>
     819                <object name="unitResearchUnaffordable[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="colour: 255 0 0 60"/>
    818820                </object>
    819821            </repeat>
    820822            <repeat count="8">
     
    832834            <repeat count="24">
    833835                <object name="unitTrainingButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom">
    834836                <object name="unitTrainingIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
     837                <object name="unitTrainingUnaffordable[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="colour: 255 0 0 127"/>
    835838                </object>
    836839            </repeat>
    837840            </object>
  • binaries/data/mods/public/gui/session/unit_commands.js

     
    419419        var icon = getGUIObjectByName("unit"+guiName+"Icon["+i+"]");
    420420        var selection = getGUIObjectByName("unit"+guiName+"Selection["+i+"]");
    421421        var pair = getGUIObjectByName("unit"+guiName+"Pair["+i+"]");
     422        var affordableMask = getGUIObjectByName("unit"+guiName+"Unaffordable["+i+"]");
     423        var affordableMask1 = getGUIObjectByName("unit"+guiName+"Unaffordable["+(i+rowLength)+"]");
     424
    422425        button.hidden = false;
    423426        button.tooltip = tooltip;
    424427
     
    569572                {
    570573                    pair.hidden = true;
    571574                    button1.hidden = true;
     575                    affordableMask1.hidden = true;
    572576                }
    573577            }
     578            if (guiName == RESEARCH)
     579            {
     580                affordableMask.hidden = true;
     581                var totalCosts = {};
     582               
     583                for each (var r in ["food", "wood", "stone", "metal"])
     584                    totalCosts[r] = Math.floor(template.cost[r]);
     585               
     586                var neededResources = Engine.GuiInterfaceCall("GetNeededResources", totalCosts);
     587                if(neededResources.length)
     588                {
     589                    if(button.enabled != false)
     590                    {
     591                        button.enabled = false;
     592                        affordableMask.hidden = false;
     593                    }
     594                    button.tooltip += "\n\n[font=\"serif-bold-13\"]Insufficient resources:[/font]\n"+neededResources.join(", ");
     595                }
     596                if (item.pair)
     597                {
     598                    affordableMask1.hidden = true;
     599                    totalCosts = {};
     600                   
     601                    for each (var r in ["food", "wood", "stone", "metal"])
     602                        totalCosts[r] = Math.floor(template1.cost[r]);
     603                   
     604                    neededResources = Engine.GuiInterfaceCall("GetNeededResources", totalCosts);
     605                    if(neededResources.length)
     606                    {
     607                        if(button1.enabled != false)
     608                        {
     609                            button1.enabled = false;
     610                            affordableMask1.hidden = false;
     611                        }
     612                        button1.tooltip += "\n\n[font=\"serif-bold-13\"]Insufficient resources:[/font]\n"+neededResources.join(", ");
     613                    }
     614                }
     615            }
     616           
     617            if(guiName == CONSTRUCTION || guiName == TRAINING)
     618            {
     619                affordableMask.hidden = true;
     620                var totalCosts = {};
     621                var totalCost = 0;
     622                var trainNum = 1;
     623                if (Engine.HotkeyIsPressed("session.batchtrain") && guiName == TRAINING)
     624                {
     625                    var [batchSize, batchIncrement] = getTrainingBatchStatus(unitEntState.id, entType);
     626                    trainNum = batchSize + batchIncrement;
     627                }
     628                for each (var r in ["food", "wood", "stone", "metal"])
     629                {
     630                    // looks like walls can be this case.
     631                    if (template.cost !== undefined)
     632                    {
     633                        totalCosts[r] = Math.floor(template.cost[r]*trainNum);
     634                        totalCost += totalCosts[r];
     635                    }
     636                }
     637                var neededResources = Engine.GuiInterfaceCall("GetNeededResources", totalCosts);
     638                if(neededResources.length)
     639                {
     640                    if(button.enabled != false)
     641                    {
     642                        button.enabled = false;
     643                        affordableMask.hidden = false;
     644                        var alpha = 100 + totalCost/6;
     645                        if (alpha > 175)
     646                            alpha = 175;
     647                        affordableMask.sprite = "colour: 255 0 0 " + (alpha);
     648                    }
     649                    button.tooltip += "\n\n[font=\"serif-bold-13\"]Insufficient resources:[/font]\n"+neededResources.join(", ");
     650                }
     651            }
     652           
    574653        }
    575654        else
    576655        {
     
    647726            getGUIObjectByName("unit"+guiName+"Pair["+i+"]").hidden = true;
    648727        }
    649728    }
    650 
    651729    g_unitPanelButtons[guiName] = numButtons;
    652730}
    653731