Ticket #23: barter_2011_08_27.diff
File barter_2011_08_27.diff, 13.0 KB (added by , 13 years ago) |
---|
-
binaries/data/mods/public/gui/session/input.js
999 999 inputState = INPUT_BUILDING_PLACEMENT; 1000 1000 } 1001 1001 1002 // Called by GUI when user clicks exchange resources button 1003 function exchangeResources(command) 1004 { 1005 Engine.PostNetworkCommand({"type": "barter", "action": command.action, "resource": command.resource}); 1006 } 1007 1008 1002 1009 // Batch training: 1003 1010 // When the user shift-clicks, we set these variables and switch to INPUT_BATCHTRAINING 1004 1011 // When the user releases shift, or clicks on a different training button, we create the batched units -
binaries/data/mods/public/gui/session/unit_commands.js
119 119 if (guiName == "Selection") 120 120 { 121 121 if (numberOfItems > 16) 122 numberOfItems =16;122 numberOfItems = 16; 123 123 } 124 124 else if (guiName == "Formation") 125 125 { 126 126 if (numberOfItems > 16) 127 numberOfItems =16;127 numberOfItems = 16; 128 128 } 129 129 else if (guiName == "Stance") 130 130 { 131 131 if (numberOfItems > 5) 132 numberOfItems =5;132 numberOfItems = 5; 133 133 } 134 134 else if (guiName == "Queue") 135 135 { … … 150 150 } 151 151 else if (numberOfItems > 24) 152 152 { 153 numberOfItems = 153 numberOfItems = 24; 154 154 } 155 155 156 156 var i; … … 321 321 { 322 322 layoutButtonRowCentered(0, guiName, 0, numButtons, COMMANDS_PANEL_WIDTH); 323 323 } 324 else 324 // exclude case when there is only barter buttons on training panel, 325 // which is processed separatedly in addBarterButtonsToTrainingPanel function 326 else if (!(guiName == "Training" && numButtons == 0)) 325 327 { 326 328 for (var i = 0; i < numRows; i++) 327 329 layoutButtonRow(i, guiName, buttonSideLength, buttonSpacer, rowLength*i, rowLength*(i+1) ); … … 336 338 panel.size = size; 337 339 } 338 340 339 // Hide any buttons we're no longer using 340 for (i = numButtons; i < g_unitPanelButtons[guiName]; ++i) 341 getGUIObjectByName("unit"+guiName+"Button["+i+"]").hidden = true; 341 if (guiName == "Training" && unitEntState.barterMarket) 342 { 343 addBarterButtonsToTrainingPanel(usedPanels, unitEntState, numButtons); 344 } 345 else 346 { 347 // Hide any buttons we're no longer using 348 for (i = numButtons; i < g_unitPanelButtons[guiName]; ++i) 349 getGUIObjectByName("unit"+guiName+"Button["+i+"]").hidden = true; 342 350 343 g_unitPanelButtons[guiName] = numButtons; 351 g_unitPanelButtons[guiName] = numButtons; 352 } 344 353 } 345 354 355 // add barter buttons to training panel to next row after last row with trainable units 356 function addBarterButtonsToTrainingPanel(usedPanels, unitEntState, newButtonsCount) 357 { 358 var previousButtonsCount = g_unitPanelButtons["Training"]; 359 var rowLength = 8; 360 // index of row where we are going to add barter buttons 361 var rowIndex = 0; 362 // if Training panel have some buttons, calculate row index 363 // for barter buttons 364 if (newButtonsCount > 0) 365 { 366 rowIndex = Math.ceil(newButtonsCount / rowLength); 367 } 368 369 for (var i = 0; i < 6; i++) 370 { 371 var action = ["buy", "sell"][Math.floor(i/3)]; 372 var resource = ["food", "wood", "stone"][i%3]; 373 374 var buttonIndex = i + rowLength*rowIndex; 375 376 var button = getGUIObjectByName("unitTrainingButton["+buttonIndex+"]"); 377 button.hidden = false; 378 button.tooltip = action + " 100 " + resource + " for " + unitEntState.barterPrices[action][resource] + " metal"; 379 var command = { "action": action, "resource": resource }; 380 button.onpress = (function(e) { return function() { exchangeResources(e) } })(command); 381 382 var icon = getGUIObjectByName("unitTrainingIcon["+buttonIndex+"]"); 383 icon.sprite = "stretched:session/actions/" + action + "_" + resource + ".png"; 384 } 385 386 var buttonSideLength = getGUIObjectByName("unitTrainingButton[0]").size.bottom; 387 var buttonSpacer = buttonSideLength+1; 388 layoutButtonRow(rowIndex, "Training", buttonSideLength, buttonSpacer, rowLength*rowIndex, rowLength*(rowIndex+1)); 389 390 // Hide any buttons we're no longer using 391 // hide buttons between last unit train button and first barter button 392 for (i = newButtonsCount; i < rowIndex * rowLength; ++i) 393 getGUIObjectByName("unitTrainingButton["+i+"]").hidden = true; 394 // hide buttons after last barter button 395 for (i = rowLength*rowIndex + 6; i < previousButtonsCount; ++i) 396 getGUIObjectByName("unitTrainingButton["+i+"]").hidden = true; 397 // update number of buttons, we suppose that all rows before one with barter buttons 398 // are fully filled (indeed there can be some empty places) and barter buttons row 399 // always have 6 buttons 400 g_unitPanelButtons["Training"] = rowIndex * rowLength + 6; 401 } 402 346 403 // Updates right Unit Commands Panel - runs in the main session loop via updateSelectionDetails() 347 404 function updateUnitCommands(entState, supplementalDetailsPanel, commandsPanel, selection) 348 405 { … … 411 468 function (trainEntType) { addToTrainingQueue(entState.id, trainEntType); } ); 412 469 // isInvisible = false; 413 470 } 471 else if (entState.barterMarket) 472 { 473 setupUnitPanel("Training", usedPanels, entState, [], null); 474 } 414 475 415 476 if (entState.training && entState.training.queue.length) 416 477 setupUnitPanel("Queue", usedPanels, entState, entState.training.queue, -
binaries/data/mods/public/simulation/helpers/Commands.js
319 319 } 320 320 break; 321 321 322 case "barter": 323 var cmpPlayerBarter = Engine.QueryInterface(playerEnt, IID_PlayerBarter); 324 cmpPlayerBarter.ExchangeResources(cmd.action, cmd.resource); 325 break; 326 322 327 default: 323 328 error("Ignoring unrecognised command type '" + cmd.type + "'"); 324 329 } -
binaries/data/mods/public/simulation/components/GuiInterface.js
132 132 "classes": cmpIdentity.GetClassesList(), 133 133 "selectionGroupName": cmpIdentity.GetSelectionGroupName() 134 134 }; 135 136 if (cmpIdentity.GetClassesList().indexOf("BarterMarket") != -1) 137 { 138 ret.barterMarket = true; 139 var cmpPlayerManager = Engine.QueryInterface(SYSTEM_ENTITY, IID_PlayerManager); 140 var playerEntity = cmpPlayerManager.GetPlayerByID(player); 141 var cmpPlayerBarter = Engine.QueryInterface(playerEntity, IID_PlayerBarter); 142 ret.barterPrices = cmpPlayerBarter.GetPrices(); 143 } 135 144 } 136 145 137 146 var cmpPosition = Engine.QueryInterface(ent, IID_Position); -
binaries/data/mods/public/simulation/components/interfaces/PlayerBarter.js
1 Engine.RegisterInterface("PlayerBarter"); -
binaries/data/mods/public/simulation/components/Identity.js
81 81 "<value>Civic</value>" + 82 82 "<value>CivCentre</value>" + 83 83 "<value>Economic</value>" + 84 "<value>BarterMarket</value>" + 84 85 "<value>Defensive</value>" + 85 86 "<value>Village</value>" + 86 87 "<value>Town</value>" + -
binaries/data/mods/public/simulation/components/PlayerBarter.js
1 function PlayerBarter() {} 2 3 PlayerBarter.prototype.Schema = 4 "<a:component type='system'/><empty/>"; 5 6 PlayerBarter.prototype.Init = function() 7 { 8 this.prices = { 9 "buy": { 10 "food": 125, 11 "wood": 125, 12 "stone": 125 13 }, 14 "sell": { 15 "food": 75, 16 "wood": 75, 17 "stone": 75 18 } 19 }; 20 }; 21 22 PlayerBarter.prototype.GetPrices = function() 23 { 24 return this.prices; 25 }; 26 27 PlayerBarter.prototype.ExchangeResources = function(action, resource) 28 { 29 var cmpPlayer = Engine.QueryInterface(this.entity, IID_Player); 30 var amountsToSubtract = { 31 "food": 0, 32 "wood": 0, 33 "stone": 0, 34 "metal": 0 35 }; 36 switch (action) 37 { 38 case "buy": 39 amountsToSubtract["metal"] = this.prices.buy[resource]; 40 if (cmpPlayer.TrySubtractResources(amountsToSubtract)) 41 cmpPlayer.AddResource(resource, 100); 42 break; 43 case "sell": 44 amountsToSubtract[resource] = 100; 45 if (cmpPlayer.TrySubtractResources(amountsToSubtract)) 46 cmpPlayer.AddResource("metal", this.prices.sell[resource]); 47 break; 48 } 49 50 }; 51 52 Engine.RegisterComponentType(IID_PlayerBarter, "PlayerBarter", PlayerBarter); 53 -
binaries/data/mods/public/simulation/templates/special/player.xml
9 9 </Limits> 10 10 </BuildLimits> 11 11 <Player/> 12 <PlayerBarter/> 12 13 <StatisticsTracker/> 13 14 </Entity> -
binaries/data/mods/public/simulation/templates/template_structure_economic_market.xml
23 23 </Health> 24 24 <Identity> 25 25 <GenericName>Market</GenericName> 26 <Tooltip>Create Trade units and Barter resources. (Currently a useless structure)</Tooltip>27 <Classes datatype="tokens">Town </Classes>26 <Tooltip>Create Trade units and Barter resources.</Tooltip> 27 <Classes datatype="tokens">Town BarterMarket</Classes> 28 28 <Icon>structures/market.png</Icon> 29 29 </Identity> 30 30 <Obstruction>