Ticket #1214: barter_two_clicks_2012_04_01.diff

File barter_two_clicks_2012_04_01.diff, 3.5 KB (added by fcxSanya, 12 years ago)
  • binaries/data/mods/public/gui/session/session.xml

     
    554554                            </object>
    555555                        </repeat>
    556556                    </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>
    560557                </object>
    561558
    562559                <!-- Stance Selection -->
  • binaries/data/mods/public/gui/session/unit_commands.js

     
    3030
    3131// Indexes of resources to sell and buy on barter panel
    3232var g_barterSell = 0;
    33 var g_barterBuy = 1;
    3433
    3534// Lay out a row of centered buttons (does not work inside a loop like the other function)
    3635function layoutButtonRowCentered(rowNumber, guiName, startIndex, endIndex, width)
     
    121120    }
    122121}
    123122
    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_barterSell
    128     // (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 
    134123// Sets up "unit panels" - the panels with rows of icons (Helper function for updateUnitDisplay)
    135124function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
    136125{
     
    446435        // One pass for 'sell' row and another for 'buy'
    447436        for (var j = 0; j < 2; j++)
    448437        {
    449             var selectedResourceIndex = [g_barterSell, g_barterBuy][j];
    450438            var action = BARTER_ACTIONS[j];
    451439
    452             var imageNameSuffix = (i == selectedResourceIndex) ? "selected" : "inactive";
     440            var imageNameSuffix = (j == 0 && i == g_barterSell) ? "selected" : "inactive";
    453441            var icon = getGUIObjectByName("unitBarter" + action + "Icon["+i+"]");
    454442
    455443            var button = getGUIObjectByName("unitBarter" + action + "Button["+i+"]");
     
    475463            var amount;
    476464            if (j == 0)
    477465            {
    478                 button.onpress = (function(i){ return function() { selectBarterResourceToSell(i); } })(i);
     466                button.onpress = (function(i){ return function() { g_barterSell = i; } })(i);
    479467                amount = (i == g_barterSell) ? "-" + amountToSell : "";
    480468            }
    481469            else
    482470            {
    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);
    484473                amount = amountToBuy;
    485474            }
    486475            getGUIObjectByName("unitBarter" + action + "Amount["+i+"]").caption = amount;
    487476        }
    488477    }
    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) };
    492478}
    493479
    494480// Updates right Unit Commands Panel - runs in the main session loop via updateSelectionDetails()