Ticket #1571: redIcons.3.patch

File redIcons.3.patch, 11.2 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

     
    159159        this.resourceCount[type] += (+amounts[type]);
    160160    }
    161161};
    162 
    163 Player.prototype.TrySubtractResources = function(amounts)
     162Player.prototype.GetNeededResources = function(amounts)
    164163{
    165164    // Check if we can afford it all
    166165    var amountsNeeded = {};
     
    171170    var formattedAmountsNeeded = [];
    172171    for (var type in amountsNeeded)
    173172        formattedAmountsNeeded.push(type + ": " + amountsNeeded[type]);
     173    return formattedAmountsNeeded;
     174};
     175
     176Player.prototype.TrySubtractResources = function(amounts)
     177{
     178    var formattedAmountsNeeded = this.GetNeededResources(amounts);
    174179           
    175180    // If we don't have enough resources, send a notification to the player
    176181    if (formattedAmountsNeeded.length)
  • binaries/data/mods/public/gui/session/unit_commands.js

     
    332332            case GATE:
    333333                var tooltip = item.tooltip;
    334334                if (item.template)
    335                     tooltip += "\n" + getEntityCostTooltip(GetTemplateData(item.template));
     335                {
     336                    var template = GetTemplateData(item.template);
     337
     338                    var affordableMask = getGUIObjectByName("unitGateUnaffordable["+i+"]");
     339                    affordableMask.hidden = true;
     340                    var totalCosts = { "food" : 0, "wood" : 0, "stone" : 0, "metal" : 0 };
     341                    for (var r in totalCosts)
     342                        if (template.cost !== undefined)
     343                            totalCosts[r] = Math.floor(template.cost[r]);
     344                    var neededResources = Engine.GuiInterfaceCall("GetNeededResources", totalCosts);
     345                   
     346                    tooltip += "\n" + getEntityCostTooltip(template);
     347                   
     348                    if(neededResources.length)
     349                    {
     350                        affordableMask.hidden = false;
     351                        tooltip += "\n[font=\"serif-bold-13\"]You don't have enough resources to convert this wall.[/font]";
     352                    }
     353                }
    336354                break;
    337355
    338356            case STANCE:
     
    415433
    416434        // Button
    417435        var button = getGUIObjectByName("unit"+guiName+"Button["+i+"]");
    418         var button1 = getGUIObjectByName("unit"+guiName+"Button["+(i+rowLength)+"]");
     436        var button1 = getGUIObjectByName("unit"+guiName+"Button["+(i+rowLength)+"]");       
     437        var affordableMask = getGUIObjectByName("unit"+guiName+"Unaffordable["+i+"]");
     438        var affordableMask1 = getGUIObjectByName("unit"+guiName+"Unaffordable["+(i+rowLength)+"]");
    419439        var icon = getGUIObjectByName("unit"+guiName+"Icon["+i+"]");
    420440        var selection = getGUIObjectByName("unit"+guiName+"Selection["+i+"]");
    421441        var pair = getGUIObjectByName("unit"+guiName+"Pair["+i+"]");
     
    553573           
    554574            if (guiName == RESEARCH)
    555575            {
     576                // Check resource requirements for first button
     577                affordableMask.hidden = true;
     578                var totalCosts = { "food" : 0, "wood" : 0, "stone" : 0, "metal" : 0 };
     579               
     580                for (var r in totalCosts)
     581                    totalCosts[r] = Math.floor(template.cost[r]);
     582               
     583                var neededResources = Engine.GuiInterfaceCall("GetNeededResources", totalCosts);
     584                if(neededResources.length)
     585                {
     586                    if(button.enabled !== false)
     587                    {
     588                        button.enabled = false;
     589                        affordableMask.hidden = false;
     590                    }
     591                    button.tooltip += "\n\n[font=\"serif-bold-13\"]Insufficient resources:[/font]\n"+neededResources.join(", ");
     592                }
     593
    556594                if (item.pair)
    557595                {
    558596                    grayscale = "";
    559597                    button1.enabled = true;
    560                     if (guiName == RESEARCH && !Engine.GuiInterfaceCall("CheckTechnologyRequirements", entType1))
     598
     599                    if (!Engine.GuiInterfaceCall("CheckTechnologyRequirements", entType1))
    561600                    {
    562601                        button1.enabled = false;
    563602                        button1.tooltip += "\n" + GetTechnologyData(entType1).requirementsTooltip;
    564603                        grayscale = "grayscale:";
    565604                    }
    566605                    icon1.sprite = "stretched:" + grayscale + "session/portraits/" +template1.icon;
     606
     607                    // Check resource requirements for second button
     608                    affordableMask1.hidden = true;
     609                    totalCosts = { "food" : 0, "wood" : 0, "stone" : 0, "metal" : 0 };
     610                   
     611                    for (var r in totalCosts)
     612                        totalCosts[r] = Math.floor(template1.cost[r]);
     613                   
     614                    neededResources = Engine.GuiInterfaceCall("GetNeededResources", totalCosts);
     615                    if(neededResources.length)
     616                    {
     617                        if(button1.enabled !== false)
     618                        {
     619                            button1.enabled = false;
     620                            affordableMask1.hidden = false;
     621                        }
     622                        button1.tooltip += "\n\n[font=\"serif-bold-13\"]Insufficient resources:[/font]\n"+neededResources.join(", ");
     623                    }
    567624                }
    568625                else
    569626                {
    570627                    pair.hidden = true;
    571628                    button1.hidden = true;
     629                    affordableMask1.hidden = true;
     630                }
     631            }
     632            if(guiName == CONSTRUCTION || guiName == TRAINING)
     633            {
     634                affordableMask.hidden = true;
     635                var totalCosts = { "food" : 0, "wood" : 0, "stone" : 0, "metal" : 0 };
     636                var totalCost = 0;
     637                var trainNum = 1;
     638                if (Engine.HotkeyIsPressed("session.batchtrain") && guiName == TRAINING)
     639                {
     640                    var [batchSize, batchIncrement] = getTrainingBatchStatus(unitEntState.id, entType);
     641                    trainNum = batchSize + batchIncrement;
    572642                }
     643                for (var r in totalCosts)
     644                {
     645                    // Walls have no cost defined.
     646                    if (template.cost !== undefined)
     647                    {
     648                        totalCosts[r] = Math.floor(template.cost[r]*trainNum);
     649                        totalCost += totalCosts[r];
     650                    }
     651                }
     652                var neededResources = Engine.GuiInterfaceCall("GetNeededResources", totalCosts);
     653                if(neededResources.length)
     654                {
     655                    if(button.enabled !== false)
     656                    {
     657                        button.enabled = false;
     658                        affordableMask.hidden = false;
     659                        var alpha = 75 + totalCost/6;
     660                        alpha = alpha > 150 ? 150 : alpha;
     661                        affordableMask.sprite = "colour: 255 0 0 " + (alpha);
     662                    }
     663                    button.tooltip += "\n\n[font=\"serif-bold-13\"]Insufficient resources:[/font]\n"+neededResources.join(", ");
     664                }
    573665            }
    574666        }
    575667        else
     
    718810                var buyPrice = unitEntState.barterMarket.prices["buy"][resource];
    719811                amountToBuy = "+" + Math.round(sellPrice / buyPrice * amountToSell);
    720812            }
     813
    721814            var amount;
    722815            if (j == 0)
    723816            {
    724817                button.onpress = (function(i) { return function() { g_barterSell = i; } })(i);
    725                 amount = (i == g_barterSell) ? "-" + amountToSell : "";
     818                if (i == g_barterSell)
     819                {
     820                    amount = "-" + amountToSell;
     821                   
     822                    var neededRess = {};
     823                    neededRess[resource] = amountToSell;
     824                    var neededResources = Engine.GuiInterfaceCall("GetNeededResources", neededRess );
     825                    var hidden = (neededResources.length === 0);
     826                    for (var ii = 0; ii < BARTER_RESOURCES.length; ii++)
     827                    {
     828                        var affordableMask = getGUIObjectByName("unitBarterBuyUnaffordable["+ii+"]");
     829                        affordableMask.hidden = hidden;
     830                    }
     831                }
     832                else
     833                {
     834                    amount = "";
     835                }
    726836            }
    727837            else
    728838            {
  • binaries/data/mods/public/gui/session/session.xml

     
    603603            <repeat count="4">
    604604                <object name="unitBarterSellButton[n]" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottomBold">
    605605                <object name="unitBarterSellIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
     606                <object name="unitBarterSellUnaffordable[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="colour: 255 0 0 60"/>
    606607                <object name="unitBarterSellAmount[n]" ghost="true" style="resourceText" type="text" size="0 0 100% 50%"/>
    607608                <object name="unitBarterSellSelection[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="stretched:session/icons/corners.png"/>
    608609                </object>
     
    612613            <repeat count="4">
    613614                <object name="unitBarterBuyButton[n]" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottomBold">
    614615                <object name="unitBarterBuyIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
     616                <object name="unitBarterBuyUnaffordable[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="colour: 255 0 0 60"/>
    615617                <object name="unitBarterBuyAmount[n]" ghost="true" style="resourceText" type="text" size="0 0 100% 50%"/>
    616618                </object>
    617619            </repeat>
     
    822824            <repeat count="24">
    823825                <object name="unitConstructionButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom">
    824826                <object name="unitConstructionIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
     827                <object name="unitConstructionUnaffordable[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="colour: 255 0 0 127"/>
    825828                </object>
    826829            </repeat>
    827830            </object>
     
    835838                <object name="unitResearchButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom">
    836839                <object name="unitResearchIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
    837840                <object name="unitResearchSelection[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="colour: 255 0 0 127"/>
     841                <object name="unitResearchUnaffordable[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="colour: 255 0 0 60"/>
    838842                </object>
    839843            </repeat>
    840844            <repeat count="8">
     
    852856            <repeat count="24">
    853857                <object name="unitTrainingButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom">
    854858                <object name="unitTrainingIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
     859                <object name="unitTrainingUnaffordable[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="colour: 255 0 0 127"/>
    855860                </object>
    856861            </repeat>
    857862            </object>
     
    898903                <object name="unitGateButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom">
    899904                <object name="unitGateIcon[n]" type="image" ghost="true" size="3 3 43 43"/>
    900905                <object name="unitGateSelection[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="stretched:session/icons/corners.png"/>
     906                <object name="unitGateUnaffordable[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="colour: 255 0 0 127"/>
    901907                </object>
    902908            </repeat>
    903909            </object>