Ticket #1571: redIcons.2.patch
File redIcons.2.patch, 10.8 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
157 157 this.resourceCount[type] += (+amounts[type]); 158 158 } 159 159 }; 160 161 Player.prototype.TrySubtractResources = function(amounts) 160 Player.prototype.GetNeededResources = function(amounts) 162 161 { 163 162 // Check if we can afford it all 164 163 var amountsNeeded = {}; … … 169 168 var formattedAmountsNeeded = []; 170 169 for (var type in amountsNeeded) 171 170 formattedAmountsNeeded.push(type + ": " + amountsNeeded[type]); 171 return formattedAmountsNeeded; 172 }; 173 174 Player.prototype.TrySubtractResources = function(amounts) 175 { 176 var formattedAmountsNeeded = this.GetNeededResources(amounts); 172 177 173 178 // If we don't have enough resources, send a notification to the player 174 179 if (formattedAmountsNeeded.length) -
binaries/data/mods/public/gui/session/session.xml
583 583 <repeat count="4"> 584 584 <object name="unitBarterSellButton[n]" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottomBold"> 585 585 <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"/> 586 587 <object name="unitBarterSellAmount[n]" ghost="true" style="resourceText" type="text" size="0 0 100% 50%"/> 587 588 <object name="unitBarterSellSelection[n]" hidden="true" type="image" ghost="true" size="3 3 43 43" sprite="stretched:session/icons/corners.png"/> 588 589 </object> … … 592 593 <repeat count="4"> 593 594 <object name="unitBarterBuyButton[n]" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottomBold"> 594 595 <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"/> 595 597 <object name="unitBarterBuyAmount[n]" ghost="true" style="resourceText" type="text" size="0 0 100% 50%"/> 596 598 </object> 597 599 </repeat> … … 802 804 <repeat count="24"> 803 805 <object name="unitConstructionButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom"> 804 806 <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"/> 805 808 </object> 806 809 </repeat> 807 810 </object> … … 815 818 <object name="unitResearchButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom"> 816 819 <object name="unitResearchIcon[n]" type="image" ghost="true" size="3 3 43 43"/> 817 820 <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"/> 818 822 </object> 819 823 </repeat> 820 824 <repeat count="8"> … … 832 836 <repeat count="24"> 833 837 <object name="unitTrainingButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom"> 834 838 <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"/> 835 840 </object> 836 841 </repeat> 837 842 </object> … … 878 883 <object name="unitGateButton[n]" hidden="true" style="iconButton" type="button" size="0 0 46 46" tooltip_style="sessionToolTipBottom"> 879 884 <object name="unitGateIcon[n]" type="image" ghost="true" size="3 3 43 43"/> 880 885 <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"/> 881 887 </object> 882 888 </repeat> 883 889 </object> -
binaries/data/mods/public/gui/session/unit_commands.js
331 331 332 332 case GATE: 333 333 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 } 336 352 break; 337 353 338 354 case STANCE: … … 419 435 var icon = getGUIObjectByName("unit"+guiName+"Icon["+i+"]"); 420 436 var selection = getGUIObjectByName("unit"+guiName+"Selection["+i+"]"); 421 437 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 422 441 button.hidden = false; 423 442 button.tooltip = tooltip; 424 443 … … 569 588 { 570 589 pair.hidden = true; 571 590 button1.hidden = true; 591 affordableMask1.hidden = true; 572 592 } 573 593 } 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 } 574 668 } 575 669 else 576 670 { … … 647 741 getGUIObjectByName("unit"+guiName+"Pair["+i+"]").hidden = true; 648 742 } 649 743 } 650 651 744 g_unitPanelButtons[guiName] = numButtons; 652 745 } 653 746 … … 713 806 { 714 807 button.hidden = false; 715 808 button.tooltip = action + " " + resource; 716 icon.sprite = "stretched:"+grayscale+"session/icons/resources/" + resource + ".png"; 809 icon.sprite = "stretched:"+grayscale+"session/icons/resources/" + resource + ".png"; 717 810 var sellPrice = unitEntState.barterMarket.prices["sell"][BARTER_RESOURCES[g_barterSell]]; 718 811 var buyPrice = unitEntState.barterMarket.prices["buy"][resource]; 719 812 amountToBuy = "+" + Math.round(sellPrice / buyPrice * amountToSell); 720 813 } 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 721 832 var amount; 722 833 if (j == 0) 723 834 {