Ticket #1571: redIcons.4.patch
File redIcons.4.patch, 12.1 KB (added by , 12 years ago) |
---|
-
binaries/data/mods/public/simulation/components/Player.js
160 160 } 161 161 }; 162 162 163 Player.prototype. TrySubtractResources = function(amounts)163 Player.prototype.GetNeededResources = function(amounts) 164 164 { 165 165 // Check if we can afford it all 166 166 var amountsNeeded = {}; 167 167 for (var type in amounts) 168 if ( amounts[type] > this.resourceCount[type])168 if (this.resourceCount[type] != undefined && amounts[type] > this.resourceCount[type]) 169 169 amountsNeeded[type] = amounts[type] - this.resourceCount[type]; 170 171 var formattedAmountsNeeded = []; 172 for (var type in amountsNeeded) 173 formattedAmountsNeeded.push(type + ": " + amountsNeeded[type]); 170 171 if (Object.keys(amountsNeeded).length == 0) 172 return undefined; 173 return amountsNeeded; 174 }; 175 176 Player.prototype.TrySubtractResources = function(amounts) 177 { 178 var amountsNeeded = this.GetNeededResources(amounts); 174 179 175 180 // If we don't have enough resources, send a notification to the player 176 if ( formattedAmountsNeeded.length)181 if (amountsNeeded) 177 182 { 178 var notification = {"player": this.playerID, "message": "Insufficient resources - " + formattedAmountsNeeded.join(", ")}; 183 var formatted = []; 184 for (var type in amountsNeeded) 185 formatted.push(amountsNeeded[type] + " " + type[0].toUpperCase() + type.substr(1) ); 186 var notification = {"player": this.playerID, "message": "Insufficient resources - " + formatted.join(", ")}; 179 187 var cmpGUIInterface = Engine.QueryInterface(SYSTEM_ENTITY, IID_GuiInterface); 180 188 cmpGUIInterface.PushNotification(notification); 181 189 return false; -
binaries/data/mods/public/simulation/components/GuiInterface.js
567 567 return ret; 568 568 } 569 569 570 // Used to show a red square over GUI elements you can't yet afford. 571 GuiInterface.prototype.GetNeededResources = function(player, amounts) 572 { 573 var cmpPlayer = QueryPlayerIDInterface(player, IID_Player); 574 return cmpPlayer.GetNeededResources(amounts); 575 }; 576 577 570 578 GuiInterface.prototype.PushNotification = function(notification) 571 579 { 572 580 this.notifications.push(notification); … … 1617 1625 "IsTechnologyResearched": 1, 1618 1626 "CheckTechnologyRequirements": 1, 1619 1627 "GetStartedResearch": 1, 1628 "GetNeededResources": 1, 1620 1629 "GetNextNotification": 1, 1621 1630 1622 1631 "GetAvailableFormations": 1, -
binaries/data/mods/public/gui/session/utility_functions.js
318 318 return popBonus; 319 319 } 320 320 321 /** 322 * Returns a message with the amount of each resource needed to create an entity. 323 */ 324 function getNeededResourcesTooltip(resources) 325 { 326 var formatted = []; 327 for (var resource in resources) 328 formatted.push(resources[resource] + " [font=\"serif-12\"]" + getCostComponentDisplayName(resource) + "[/font]"); 329 330 return "\n\n[font=\"serif-bold-13\"]Insufficient resources:[/font]\n" + formatted.join(", "); 331 } 332 321 333 function getEntitySpeed(template) 322 334 { 323 335 var speed = ""; -
binaries/data/mods/public/gui/session/unit_commands.js
332 332 case GATE: 333 333 var tooltip = item.tooltip; 334 334 if (item.template) 335 tooltip += "\n" + getEntityCostTooltip(GetTemplateData(item.template)); 335 { 336 var template = GetTemplateData(item.template); 337 tooltip += "\n" + getEntityCostTooltip(template); 338 339 var affordableMask = getGUIObjectByName("unitGateUnaffordable["+i+"]"); 340 affordableMask.hidden = true; 341 342 var neededResources = Engine.GuiInterfaceCall("GetNeededResources", template.cost); 343 if (neededResources) 344 { 345 affordableMask.hidden = false; 346 tooltip += getNeededResourcesTooltip(neededResources); 347 } 348 } 336 349 break; 337 350 338 351 case STANCE: … … 416 429 // Button 417 430 var button = getGUIObjectByName("unit"+guiName+"Button["+i+"]"); 418 431 var button1 = getGUIObjectByName("unit"+guiName+"Button["+(i+rowLength)+"]"); 432 var affordableMask = getGUIObjectByName("unit"+guiName+"Unaffordable["+i+"]"); 433 var affordableMask1 = getGUIObjectByName("unit"+guiName+"Unaffordable["+(i+rowLength)+"]"); 419 434 var icon = getGUIObjectByName("unit"+guiName+"Icon["+i+"]"); 420 435 var selection = getGUIObjectByName("unit"+guiName+"Selection["+i+"]"); 421 436 var pair = getGUIObjectByName("unit"+guiName+"Pair["+i+"]"); … … 553 568 554 569 if (guiName == RESEARCH) 555 570 { 571 // Check resource requirements for first button 572 affordableMask.hidden = true; 573 var neededResources = Engine.GuiInterfaceCall("GetNeededResources", template.cost); 574 if (neededResources) 575 { 576 if (button.enabled !== false) 577 { 578 button.enabled = false; 579 affordableMask.hidden = false; 580 } 581 button.tooltip += getNeededResourcesTooltip(neededResources); 582 } 583 556 584 if (item.pair) 557 585 { 558 586 grayscale = ""; 559 587 button1.enabled = true; 560 if (guiName == RESEARCH && !Engine.GuiInterfaceCall("CheckTechnologyRequirements", entType1)) 588 589 if (!Engine.GuiInterfaceCall("CheckTechnologyRequirements", entType1)) 561 590 { 562 591 button1.enabled = false; 563 592 button1.tooltip += "\n" + GetTechnologyData(entType1).requirementsTooltip; 564 593 grayscale = "grayscale:"; 565 594 } 566 595 icon1.sprite = "stretched:" + grayscale + "session/portraits/" +template1.icon; 596 597 // Check resource requirements for second button 598 affordableMask1.hidden = true; 599 neededResources = Engine.GuiInterfaceCall("GetNeededResources", template.cost); 600 if (neededResources) 601 { 602 if (button1.enabled !== false) 603 { 604 button1.enabled = false; 605 affordableMask1.hidden = false; 606 } 607 button1.tooltip += getNeededResourcesTooltip(neededResources); 608 } 567 609 } 568 610 else 569 611 { 570 612 pair.hidden = true; 571 613 button1.hidden = true; 614 affordableMask1.hidden = true; 615 } 616 } 617 else if (guiName == CONSTRUCTION || guiName == TRAINING) 618 { 619 affordableMask.hidden = true; 620 var totalCosts = {}; 621 var trainNum = 1; 622 if (Engine.HotkeyIsPressed("session.batchtrain") && guiName == TRAINING) 623 { 624 var [batchSize, batchIncrement] = getTrainingBatchStatus(unitEntState.id, entType); 625 trainNum = batchSize + batchIncrement; 572 626 } 627 628 // Walls have no cost defined. 629 if (template.cost !== undefined) 630 for (var r in template.cost) 631 totalCosts[r] = Math.floor(template.cost[r] * trainNum); 632 633 var neededResources = Engine.GuiInterfaceCall("GetNeededResources", totalCosts); 634 if (neededResources) 635 { 636 var totalCost = 0; 637 if (button.enabled !== false) 638 { 639 for each (var resource in neededResources) 640 totalCost += resource; 641 642 button.enabled = false; 643 affordableMask.hidden = false; 644 var alpha = 75 + totalCost/6; 645 alpha = alpha > 150 ? 150 : alpha; 646 affordableMask.sprite = "colour: 255 0 0 " + (alpha); 647 } 648 button.tooltip += getNeededResourcesTooltip(neededResources); 649 } 573 650 } 574 651 } 575 652 else … … 718 795 var buyPrice = unitEntState.barterMarket.prices["buy"][resource]; 719 796 amountToBuy = "+" + Math.round(sellPrice / buyPrice * amountToSell); 720 797 } 798 721 799 var amount; 722 800 if (j == 0) 723 801 { 724 802 button.onpress = (function(i){ return function() { g_barterSell = i; } })(i); 725 amount = (i == g_barterSell) ? "-" + amountToSell : ""; 726 } 803 if (i == g_barterSell) 804 { 805 amount = "-" + amountToSell; 806 807 var neededRes = {}; 808 neededRes[resource] = amountToSell; 809 var neededResources = Engine.GuiInterfaceCall("GetNeededResources", neededRes); 810 var hidden = neededResources ? false : true; 811 for (var ii = 0; ii < BARTER_RESOURCES.length; ii++) 812 { 813 var affordableMask = getGUIObjectByName("unitBarterBuyUnaffordable["+ii+"]"); 814 affordableMask.hidden = hidden; 815 } 816 } 817 else 818 amount = ""; 819 } 727 820 else 728 821 { 729 822 var exchangeResourcesParameters = { "sell": BARTER_RESOURCES[g_barterSell], "buy": BARTER_RESOURCES[i], "amount": amountToSell }; -
binaries/data/mods/public/gui/session/session.xml
603 603 <repeat count="4"> 604 604 <object name="unitBarterSellButton[n]" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottomBold"> 605 605 <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"/> 606 607 <object name="unitBarterSellAmount[n]" ghost="true" style="resourceText" type="text" size="0 0 100% 50%"/> 607 608 <object name="unitBarterSellSelection[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="stretched:session/icons/corners.png"/> 608 609 </object> … … 612 613 <repeat count="4"> 613 614 <object name="unitBarterBuyButton[n]" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottomBold"> 614 615 <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"/> 615 617 <object name="unitBarterBuyAmount[n]" ghost="true" style="resourceText" type="text" size="0 0 100% 50%"/> 616 618 </object> 617 619 </repeat> … … 822 824 <repeat count="24"> 823 825 <object name="unitConstructionButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom"> 824 826 <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"/> 825 828 </object> 826 829 </repeat> 827 830 </object> … … 835 838 <object name="unitResearchButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom"> 836 839 <object name="unitResearchIcon[n]" type="image" ghost="true" size="3 3 43 43"/> 837 840 <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"/> 838 842 </object> 839 843 </repeat> 840 844 <repeat count="8"> … … 852 856 <repeat count="24"> 853 857 <object name="unitTrainingButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom"> 854 858 <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"/> 855 860 </object> 856 861 </repeat> 857 862 </object> … … 898 903 <object name="unitGateButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom"> 899 904 <object name="unitGateIcon[n]" type="image" ghost="true" size="3 3 43 43"/> 900 905 <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"/> 901 907 </object> 902 908 </repeat> 903 909 </object>