Ticket #1214: barter_two_clicks_2012_04_01.diff
File barter_two_clicks_2012_04_01.diff, 3.5 KB (added by , 12 years ago) |
---|
-
binaries/data/mods/public/gui/session/session.xml
554 554 </object> 555 555 </repeat> 556 556 </object> 557 <object name="PerformDealButton" type="button" style="StoneButton" size="2 112 100%-7 142">558 <object ghost="true" style="statsText" type="text" size="0 0 100% 100%">Barter</object>559 </object>560 557 </object> 561 558 562 559 <!-- Stance Selection --> -
binaries/data/mods/public/gui/session/unit_commands.js
30 30 31 31 // Indexes of resources to sell and buy on barter panel 32 32 var g_barterSell = 0; 33 var g_barterBuy = 1;34 33 35 34 // Lay out a row of centered buttons (does not work inside a loop like the other function) 36 35 function layoutButtonRowCentered(rowNumber, guiName, startIndex, endIndex, width) … … 121 120 } 122 121 } 123 122 124 function selectBarterResourceToSell(resourceIndex)125 {126 g_barterSell = resourceIndex;127 // g_barterBuy should be set to different value in case if it is the same as g_barterSell128 // (it is no make sense to exchange resource to the same one).129 // We change it cyclic to next value.130 if (g_barterBuy == g_barterSell)131 g_barterBuy = (g_barterBuy + 1) % BARTER_RESOURCES.length;132 }133 134 123 // Sets up "unit panels" - the panels with rows of icons (Helper function for updateUnitDisplay) 135 124 function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback) 136 125 { … … 446 435 // One pass for 'sell' row and another for 'buy' 447 436 for (var j = 0; j < 2; j++) 448 437 { 449 var selectedResourceIndex = [g_barterSell, g_barterBuy][j];450 438 var action = BARTER_ACTIONS[j]; 451 439 452 var imageNameSuffix = ( i == selectedResourceIndex) ? "selected" : "inactive";440 var imageNameSuffix = (j == 0 && i == g_barterSell) ? "selected" : "inactive"; 453 441 var icon = getGUIObjectByName("unitBarter" + action + "Icon["+i+"]"); 454 442 455 443 var button = getGUIObjectByName("unitBarter" + action + "Button["+i+"]"); … … 475 463 var amount; 476 464 if (j == 0) 477 465 { 478 button.onpress = (function(i){ return function() { selectBarterResourceToSell(i); } })(i);466 button.onpress = (function(i){ return function() { g_barterSell = i; } })(i); 479 467 amount = (i == g_barterSell) ? "-" + amountToSell : ""; 480 468 } 481 469 else 482 470 { 483 button.onpress = (function(i){ return function() { g_barterBuy = i; } })(i); 471 var exchangeResourcesParameters = { "sell": BARTER_RESOURCES[g_barterSell], "buy": BARTER_RESOURCES[i], "amount": amountToSell }; 472 button.onpress = (function(exchangeResourcesParameters){ return function() { exchangeResources(exchangeResourcesParameters); } })(exchangeResourcesParameters); 484 473 amount = amountToBuy; 485 474 } 486 475 getGUIObjectByName("unitBarter" + action + "Amount["+i+"]").caption = amount; 487 476 } 488 477 } 489 var performDealButton = getGUIObjectByName("PerformDealButton");490 var exchangeResourcesParameters = { "sell": BARTER_RESOURCES[g_barterSell], "buy": BARTER_RESOURCES[g_barterBuy], "amount": amountToSell };491 performDealButton.onpress = function() { exchangeResources(exchangeResourcesParameters) };492 478 } 493 479 494 480 // Updates right Unit Commands Panel - runs in the main session loop via updateSelectionDetails()