Ticket #1571: redIcons.2.patch

File redIcons.2.patch, 10.8 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);
     
    16171624    "IsTechnologyResearched": 1,
    16181625    "CheckTechnologyRequirements": 1,
    16191626    "GetStartedResearch": 1,
     1627    "GetNeededResources": 1,
    16201628    "GetNextNotification": 1,
    16211629
    16221630    "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

     
    583583            <repeat count="4">
    584584                <object name="unitBarterSellButton[n]" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottomBold">
    585585                <object name="unitBarterSellIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
     586                <object name="unitBarterSellUnaffordable[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="colour: 255 0 0 60"/>
    586587                <object name="unitBarterSellAmount[n]" ghost="true" style="resourceText" type="text" size="0 0 100% 50%"/>
    587588                <object name="unitBarterSellSelection[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="stretched:session/icons/corners.png"/>
    588589                </object>
     
    592593            <repeat count="4">
    593594                <object name="unitBarterBuyButton[n]" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottomBold">
    594595                <object name="unitBarterBuyIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
     596                <object name="unitBarterBuyUnaffordable[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="colour: 255 0 0 60"/>
    595597                <object name="unitBarterBuyAmount[n]" ghost="true" style="resourceText" type="text" size="0 0 100% 50%"/>
    596598                </object>
    597599            </repeat>
     
    802804            <repeat count="24">
    803805                <object name="unitConstructionButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom">
    804806                <object name="unitConstructionIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
     807                <object name="unitConstructionUnaffordable[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="colour: 255 0 0 127"/>
    805808                </object>
    806809            </repeat>
    807810            </object>
     
    815818                <object name="unitResearchButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom">
    816819                <object name="unitResearchIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
    817820                <object name="unitResearchSelection[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="colour: 255 0 0 127"/>
     821                <object name="unitResearchUnaffordable[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="colour: 255 0 0 60"/>
    818822                </object>
    819823            </repeat>
    820824            <repeat count="8">
     
    832836            <repeat count="24">
    833837                <object name="unitTrainingButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom">
    834838                <object name="unitTrainingIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
     839                <object name="unitTrainingUnaffordable[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="colour: 255 0 0 127"/>
    835840                </object>
    836841            </repeat>
    837842            </object>
     
    878883                <object name="unitGateButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom">
    879884                <object name="unitGateIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
    880885                <object name="unitGateSelection[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="stretched:session/icons/corners.png"/>
     886                <object name="unitGateUnaffordable[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="colour: 255 0 0 127"/>
    881887                </object>
    882888            </repeat>
    883889            </object>
  • binaries/data/mods/public/gui/session/unit_commands.js

     
    331331
    332332            case GATE:
    333333                var tooltip = item.tooltip;
    334                 if (item.template)
    335                     tooltip += "\n" + getEntityCostTooltip(GetTemplateData(item.template));
     334                if (item.template) {
     335                   
     336                    var affordableMask = getGUIObjectByName("unitGateUnaffordable["+i+"]");
     337                    affordableMask.hidden = true;
     338                    var totalCosts = {};
     339                    var template = GetTemplateData(item.template);
     340                    for each (var r in ["food", "wood", "stone", "metal"])
     341                        if (template.cost !== undefined)
     342                            totalCosts[r] = Math.floor(template.cost[r]);
     343                    var neededResources = Engine.GuiInterfaceCall("GetNeededResources", totalCosts);
     344
     345                    tooltip += "\n" + getEntityCostTooltip(template);
     346
     347                    if(neededResources.length) {
     348                        affordableMask.hidden = false;
     349                        tooltip += "\n[font=\"serif-bold-13\"]You don't have enough resources to convert this wall.[/font]";
     350                    }
     351                }
    336352                break;
    337353
    338354            case STANCE:
     
    419435        var icon = getGUIObjectByName("unit"+guiName+"Icon["+i+"]");
    420436        var selection = getGUIObjectByName("unit"+guiName+"Selection["+i+"]");
    421437        var pair = getGUIObjectByName("unit"+guiName+"Pair["+i+"]");
     438        var affordableMask = getGUIObjectByName("unit"+guiName+"Unaffordable["+i+"]");
     439        var affordableMask1 = getGUIObjectByName("unit"+guiName+"Unaffordable["+(i+rowLength)+"]");
     440
    422441        button.hidden = false;
    423442        button.tooltip = tooltip;
    424443
     
    569588                {
    570589                    pair.hidden = true;
    571590                    button1.hidden = true;
     591                    affordableMask1.hidden = true;
    572592                }
    573593            }
     594            if (guiName == RESEARCH)
     595            {
     596                affordableMask.hidden = true;
     597                var totalCosts = {};
     598               
     599                for each (var r in ["food", "wood", "stone", "metal"])
     600                    totalCosts[r] = Math.floor(template.cost[r]);
     601               
     602                var neededResources = Engine.GuiInterfaceCall("GetNeededResources", totalCosts);
     603                if(neededResources.length)
     604                {
     605                    if(button.enabled != false)
     606                    {
     607                        button.enabled = false;
     608                        affordableMask.hidden = false;
     609                    }
     610                    button.tooltip += "\n\n[font=\"serif-bold-13\"]Insufficient resources:[/font]\n"+neededResources.join(", ");
     611                }
     612                if (item.pair)
     613                {
     614                    affordableMask1.hidden = true;
     615                    totalCosts = {};
     616                   
     617                    for each (var r in ["food", "wood", "stone", "metal"])
     618                        totalCosts[r] = Math.floor(template1.cost[r]);
     619                   
     620                    neededResources = Engine.GuiInterfaceCall("GetNeededResources", totalCosts);
     621                    if(neededResources.length)
     622                    {
     623                        if(button1.enabled != false)
     624                        {
     625                            button1.enabled = false;
     626                            affordableMask1.hidden = false;
     627                        }
     628                        button1.tooltip += "\n\n[font=\"serif-bold-13\"]Insufficient resources:[/font]\n"+neededResources.join(", ");
     629                    }
     630                }
     631            }
     632           
     633            if(guiName == CONSTRUCTION || guiName == TRAINING)
     634            {
     635                affordableMask.hidden = true;
     636                var totalCosts = {};
     637                var totalCost = 0;
     638                var trainNum = 1;
     639                if (Engine.HotkeyIsPressed("session.batchtrain") && guiName == TRAINING)
     640                {
     641                    var [batchSize, batchIncrement] = getTrainingBatchStatus(unitEntState.id, entType);
     642                    trainNum = batchSize + batchIncrement;
     643                }
     644                for each (var r in ["food", "wood", "stone", "metal"])
     645                {
     646                    // looks like walls can be this case.
     647                    if (template.cost !== undefined)
     648                    {
     649                        totalCosts[r] = Math.floor(template.cost[r]*trainNum);
     650                        totalCost += totalCosts[r];
     651                    }
     652                }
     653                var neededResources = Engine.GuiInterfaceCall("GetNeededResources", totalCosts);
     654                if(neededResources.length)
     655                {
     656                    if(button.enabled != false)
     657                    {
     658                        button.enabled = false;
     659                        affordableMask.hidden = false;
     660                        var alpha = 100 + totalCost/6;
     661                        if (alpha > 175)
     662                            alpha = 175;
     663                        affordableMask.sprite = "colour: 255 0 0 " + (alpha);
     664                    }
     665                    button.tooltip += "\n\n[font=\"serif-bold-13\"]Insufficient resources:[/font]\n"+neededResources.join(", ");
     666                }
     667            }
    574668        }
    575669        else
    576670        {
     
    647741            getGUIObjectByName("unit"+guiName+"Pair["+i+"]").hidden = true;
    648742        }
    649743    }
    650 
    651744    g_unitPanelButtons[guiName] = numButtons;
    652745}
    653746
     
    713806            {
    714807                button.hidden = false;
    715808                button.tooltip = action + " " + resource;
    716                 icon.sprite = "stretched:"+grayscale+"session/icons/resources/" + resource + ".png";
     809                icon.sprite = "stretched:"+grayscale+"session/icons/resources/" + resource + ".png";               
    717810                var sellPrice = unitEntState.barterMarket.prices["sell"][BARTER_RESOURCES[g_barterSell]];
    718811                var buyPrice = unitEntState.barterMarket.prices["buy"][resource];
    719812                amountToBuy = "+" + Math.round(sellPrice / buyPrice * amountToSell);
    720813            }
     814           
     815            if (j == 0 && i == g_barterSell) {
     816                var neededRess = {};
     817                neededRess[resource] = amountToSell;
     818                var neededResources = Engine.GuiInterfaceCall("GetNeededResources", neededRess );
     819                if (neededResources.length !== 0) {
     820                    for (var ii = 0; ii < BARTER_RESOURCES.length; ii++) {
     821                        var affordableMask = getGUIObjectByName("unitBarterBuyUnaffordable["+ii+"]");
     822                        affordableMask.hidden = false;
     823                    }
     824                } else {
     825                    for (var ii = 0; ii < BARTER_RESOURCES.length; ii++) {
     826                        var affordableMask = getGUIObjectByName("unitBarterBuyUnaffordable["+ii+"]");
     827                        affordableMask.hidden = true;
     828                    }
     829                }
     830            }
     831           
    721832            var amount;
    722833            if (j == 0)
    723834            {