Ticket #4193: 4193-loot-tooltip.5.patch
File 4193-loot-tooltip.5.patch, 9.3 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/globalscripts/LootHelper.js
1 /* 2 Helper to calculate the loot used by gui and simulation. 3 */ 4 5 function calculateResourcesCarried(carriedResources, carriedGoods) 6 { 7 var resources = {}; 8 // Loot resources workers carried 9 if (carriedResources) 10 for (let resource of carriedResources) 11 resources[resource.type] = (resources[resource.type] || 0) + resource.amount; 12 13 // Loot resources traders carried 14 if (carriedGoods && carriedGoods.amount) 15 resources[carriedGoods.type] = 16 (resources[carriedGoods.type] || 0) 17 + (carriedGoods.amount.traderGain || 0) 18 + (carriedGoods.amount.market1Gain || 0) 19 + (carriedGoods.amount.market2Gain || 0); 20 21 return resources; 22 } 23 No newline at end of file -
binaries/data/mods/public/globalscripts/Templates.js
1 const lootTypes = ["xp", "food", "wood", "stone", "metal"]; 2 1 3 /** 2 4 * Gets an array of all classes for this identity template 3 5 */ … … 244 246 "rate": getEntityValue("Heal/Rate") 245 247 }; 246 248 249 if (template.Loot) 250 { 251 ret.loot = {}; 252 for (let type of lootTypes) 253 if (template.Loot[type]) 254 ret.loot[type] = getEntityValue("Loot/" + type); 255 } 256 247 257 if (template.Obstruction) 248 258 { 249 259 ret.obstruction = { -
binaries/data/mods/public/gui/common/setup_resources.xml
25 25 sprite="stretched:session/icons/resources/time_small.png" 26 26 size="16 16" 27 27 /> 28 <icon name="icon_xp" 29 sprite="stretched:session/icons/resources/xp_small.png" 30 size="16 16" 31 /> 28 32 </setup> -
binaries/data/mods/public/gui/common/tooltips.js
575 575 return headerFont(translate("Classes:")) + ' ' + 576 576 bodyFont(template.visibleIdentityClasses.map(c => translate(c)).join(translate(", "))); 577 577 } 578 579 function getLootTooltip(template) 580 { 581 if (!template.loot) 582 return ""; 583 584 let loots = []; 585 for (let type in template.loot) 586 loots.push(sprintf(translate("%(component)s %(loot)s"), { 587 "component": costIcon(type), 588 "loot": template.loot[type] 589 })); 590 591 return headerFont(translate("Loot") + ": ") + loots.join(" "); 592 } -
binaries/data/mods/public/gui/session/selection_details.js
291 291 getBuildRateTooltip, 292 292 getSpeedTooltip, 293 293 getGarrisonTooltip, 294 getProjectilesTooltip 294 getProjectilesTooltip, 295 getLootTooltip 295 296 ].map(func => func(entState)).filter(tip => tip).join("\n"); 296 297 297 298 let iconTooltips = []; … … 320 321 let capturePoints = (new Array(g_MaxPlayers + 1)).fill(0); 321 322 let playerID = 0; 322 323 let totalResourcesCarried = {}; 324 let totalLoot = {}; 323 325 324 326 for (let i = 0; i < selection.length; ++i) 325 327 { 326 328 let entState = GetEntityState(selection[i]); 329 let extEntState = GetExtendedEntityState(selection[i]); 327 330 if (!entState) 328 331 continue; 329 332 playerID = entState.player; // trust that all selected entities have the same owner … … 338 341 capturePoints = entState.capturePoints.map((v, i) => v + capturePoints[i]); 339 342 } 340 343 341 if (entState.resourceCarrying && entState.resourceCarrying.length) 342 { 343 let carrying = entState.resourceCarrying[0]; 344 totalResourcesCarried[carrying.type] = (totalResourcesCarried[carrying.type] || 0) + carrying.amount; 345 } 344 let resourcesCarried = calculateResourcesCarried(entState.resourceCarrying, entState.trader ? entState.trader.goods : {}); 345 346 for (let type of lootTypes) 347 totalLoot[type] = (totalLoot[type] || 0) + (extEntState.loot[type] || 0) + (resourcesCarried[type] || 0); 348 349 for (let type in resourcesCarried) 350 totalResourcesCarried[type] = (totalResourcesCarried[type] || 0) + resourcesCarried[type]; 346 351 } 347 352 348 353 Engine.GetGUIObjectByName("healthMultiple").hidden = averageHealth <= 0; … … 394 399 395 400 let numberOfUnits = Engine.GetGUIObjectByName("numberOfUnits"); 396 401 numberOfUnits.caption = selection.length; 397 numberOfUnits.tooltip = Object.keys(totalResourcesCarried).map(res =>398 costIcon(res) + totalResourcesCarried[res]399 ).join(" ");400 402 403 numberOfUnits.tooltip = ""; 404 405 if (Object.keys(totalResourcesCarried).length > 0) 406 numberOfUnits.tooltip = translate("Carrying") + ": " + Object.keys(totalResourcesCarried).map(res => 407 costIcon(res) + totalResourcesCarried[res]).join(" ") + "\n"; 408 409 numberOfUnits.tooltip += translate("Loot") + ": " + Object.keys(totalLoot).map(res => 410 costIcon(res) + totalLoot[res]).join(" "); 411 401 412 // Unhide Details Area 402 413 Engine.GetGUIObjectByName("detailsAreaMultiple").hidden = false; 403 414 Engine.GetGUIObjectByName("detailsAreaSingle").hidden = true; -
binaries/data/mods/public/gui/structree/draw.js
14 14 getProjectilesTooltip, 15 15 getSpeedTooltip, 16 16 getGatherTooltip, 17 getPopulationBonusTooltip 17 getPopulationBonusTooltip, 18 getLootTooltip 18 19 ]; 19 20 20 21 /** -
binaries/data/mods/public/simulation/components/GuiInterface.js
421 421 "barterMarket": null, 422 422 "buildingAI": null, 423 423 "heal": null, 424 "loot": null, 424 425 "obstruction": null, 425 426 "turretParent":null, 426 427 "promotion": null, … … 568 569 "healableClasses": cmpHeal.GetHealableClasses(), 569 570 }; 570 571 572 let cmpLoot = Engine.QueryInterface(ent, IID_Loot); 573 if (cmpLoot) 574 { 575 let resources = cmpLoot.GetResources(); 576 ret.loot = { 577 "xp": cmpLoot.GetXp(), 578 "food": resources.food, 579 "wood": resources.wood, 580 "stone": resources.stone, 581 "metal": resources.metal 582 }; 583 } 584 571 585 let cmpUnitMotion = Engine.QueryInterface(ent, IID_UnitMotion); 572 586 if (cmpUnitMotion) 573 587 ret.speed = { -
binaries/data/mods/public/simulation/components/Looter.js
14 14 if (!cmpLoot) 15 15 return; 16 16 17 // Collect resources carried by workers and traders 18 var cmpResourceGatherer = Engine.QueryInterface(targetEntity, IID_ResourceGatherer); 19 var cmpTrader = Engine.QueryInterface(targetEntity, IID_Trader); 20 21 let resourcesCarried = calculateResourcesCarried( 22 cmpResourceGatherer ? cmpResourceGatherer.resourceCarrying : {}, 23 cmpTrader ? cmpTrader.goods : {} 24 ); 25 17 26 // Loot resources as defined in the templates 18 27 var resources = cmpLoot.GetResources(); 19 28 for (let type in resources) 20 resources[type] = ApplyValueModificationsToEntity("Looter/Resource/"+type, resources[type], this.entity); 29 resources[type] = ApplyValueModificationsToEntity("Looter/Resource/"+type, resources[type], this.entity) 30 + (resourcesCarried[type] || 0); 21 31 22 // TODO: stop assuming that cmpLoot.GetResources() delivers all resource types (by defining them in a central location)23 24 // Loot resources that killed enemies carried25 var cmpResourceGatherer = Engine.QueryInterface(targetEntity, IID_ResourceGatherer);26 if (cmpResourceGatherer)27 for (let resource of cmpResourceGatherer.GetCarryingStatus())28 resources[resource.type] += resource.amount;29 30 // Loot resources traders carry31 var cmpTrader = Engine.QueryInterface(targetEntity, IID_Trader);32 if (cmpTrader)33 {34 let carriedGoods = cmpTrader.GetGoods();35 if (carriedGoods.amount)36 {37 resources[carriedGoods.type] +=38 + (carriedGoods.amount.traderGain || 0)39 + (carriedGoods.amount.market1Gain || 0)40 + (carriedGoods.amount.market2Gain || 0);41 }42 }43 44 32 // Transfer resources 45 33 var cmpPlayer = QueryOwnerInterface(this.entity); 46 34 cmpPlayer.AddResources(resources); -
binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js
535 535 }, 536 536 buildingAI: null, 537 537 heal: null, 538 loot: null, 538 539 obstruction: null, 539 540 turretParent: null, 540 541 promotion: null,