Ticket #1571: redIcons.3.patch
File redIcons.3.patch, 11.2 KB (added by , 12 years ago) |
---|
-
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 var cmpPlayer = QueryPlayerIDInterface(player, IID_Player); 573 return cmpPlayer.GetNeededResources(amounts); 574 }; 575 576 570 577 GuiInterface.prototype.PushNotification = function(notification) 571 578 { 572 579 this.notifications.push(notification); … … 1617 1624 "IsTechnologyResearched": 1, 1618 1625 "CheckTechnologyRequirements": 1, 1619 1626 "GetStartedResearch": 1, 1627 "GetNeededResources": 1, 1620 1628 "GetNextNotification": 1, 1621 1629 1622 1630 "GetAvailableFormations": 1, -
binaries/data/mods/public/simulation/components/Player.js
159 159 this.resourceCount[type] += (+amounts[type]); 160 160 } 161 161 }; 162 163 Player.prototype.TrySubtractResources = function(amounts) 162 Player.prototype.GetNeededResources = function(amounts) 164 163 { 165 164 // Check if we can afford it all 166 165 var amountsNeeded = {}; … … 171 170 var formattedAmountsNeeded = []; 172 171 for (var type in amountsNeeded) 173 172 formattedAmountsNeeded.push(type + ": " + amountsNeeded[type]); 173 return formattedAmountsNeeded; 174 }; 175 176 Player.prototype.TrySubtractResources = function(amounts) 177 { 178 var formattedAmountsNeeded = this.GetNeededResources(amounts); 174 179 175 180 // If we don't have enough resources, send a notification to the player 176 181 if (formattedAmountsNeeded.length) -
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 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 } 336 354 break; 337 355 338 356 case STANCE: … … 415 433 416 434 // Button 417 435 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)+"]"); 419 439 var icon = getGUIObjectByName("unit"+guiName+"Icon["+i+"]"); 420 440 var selection = getGUIObjectByName("unit"+guiName+"Selection["+i+"]"); 421 441 var pair = getGUIObjectByName("unit"+guiName+"Pair["+i+"]"); … … 553 573 554 574 if (guiName == RESEARCH) 555 575 { 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 556 594 if (item.pair) 557 595 { 558 596 grayscale = ""; 559 597 button1.enabled = true; 560 if (guiName == RESEARCH && !Engine.GuiInterfaceCall("CheckTechnologyRequirements", entType1)) 598 599 if (!Engine.GuiInterfaceCall("CheckTechnologyRequirements", entType1)) 561 600 { 562 601 button1.enabled = false; 563 602 button1.tooltip += "\n" + GetTechnologyData(entType1).requirementsTooltip; 564 603 grayscale = "grayscale:"; 565 604 } 566 605 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 } 567 624 } 568 625 else 569 626 { 570 627 pair.hidden = true; 571 628 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; 572 642 } 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 } 573 665 } 574 666 } 575 667 else … … 718 810 var buyPrice = unitEntState.barterMarket.prices["buy"][resource]; 719 811 amountToBuy = "+" + Math.round(sellPrice / buyPrice * amountToSell); 720 812 } 813 721 814 var amount; 722 815 if (j == 0) 723 816 { 724 817 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 } 726 836 } 727 837 else 728 838 { -
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>