Ticket #4193: 4193-loot-tooltip.8.patch
File 4193-loot-tooltip.8.patch, 10.4 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/globalscripts/Templates.js
244 244 "rate": getEntityValue("Heal/Rate") 245 245 }; 246 246 247 if (template.Loot) 248 { 249 ret.loot = {}; 250 for (let type in template.Loot) 251 ret.loot[type] = getEntityValue("Loot/"+ type); 252 } 253 247 254 if (template.Obstruction) 248 255 { 249 256 ret.obstruction = { … … 381 388 382 389 return ret; 383 390 } 391 392 /** 393 * Helper to calculate the loot used by gui and simulation. 394 * @param carriedResources resources carried by the looted worker 395 * @param trader the looted trader 396 * @return the sum of carried resources and goods 397 */ 398 function calculateResourcesAndGoodsCarried(carriedResources, trader) 399 { 400 var resources = {}; 401 // Loot resources workers carried 402 if (carriedResources) 403 for (let resource of carriedResources) 404 resources[resource.type] = (resources[resource.type] || 0) + resource.amount; 405 406 // Loot resources traders carried 407 if (trader) 408 resources[trader.goods.type] = 409 (resources[trader.goods.type] || 0) + 410 (trader.goods.amount.traderGain || 0) + 411 (trader.goods.amount.market1Gain || 0) + 412 (trader.goods.amount.market2Gain || 0); 413 414 return resources; 415 } -
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) //TODO: what if a worker/trader is carring resources but do not have base loot defined? 582 return ""; 583 584 let loots = []; 585 let resourcesCarried = []; 586 const lootTypes = ["xp", "food", "wood", "stone", "metal"]; 587 588 if ("resourceCarrying" in template) 589 resourcesCarried = calculateResourcesAndGoodsCarried(template.resourceCarrying, template.trader); 590 591 for (let type of lootTypes) 592 { 593 let loot = (loots[type] || 0) + (template.loot[type] || 0) + (resourcesCarried[type] || 0); 594 if (loot > 0) 595 loots[type] = loot; 596 } 597 598 for (let type of Object.keys(loots)) 599 loots.push(sprintf(translate("%(component)s %(loot)s"), { 600 "component": costIcon(type), 601 "loot": loots[type] 602 })); 603 604 return sprintf(translate("%(label)s %(details)s"), { 605 "label": headerFont(translate("Loot:")), 606 "details": loots.join(" ") 607 }); 608 } -
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 = []; … … 319 320 let maxCapturePoints = 0; 320 321 let capturePoints = (new Array(g_MaxPlayers + 1)).fill(0); 321 322 let playerID = 0; 322 let totalResourcesCarried = {}; 323 let totalResourcesAndGoodsCarried = {}; 324 let totalLoot = {}; 323 325 324 326 for (let i = 0; i < selection.length; ++i) 325 327 { 326 let entState = GetE ntityState(selection[i]);328 let entState = GetExtendedEntityState(selection[i]); 327 329 if (!entState) 328 330 continue; 329 331 playerID = entState.player; // trust that all selected entities have the same owner … … 338 340 capturePoints = entState.capturePoints.map((v, i) => v + capturePoints[i]); 339 341 } 340 342 341 if (entState.resourceCarrying && entState.resourceCarrying.length) 343 let resourcesAndGoodsCarried = calculateResourcesAndGoodsCarried(entState.resourceCarrying, entState.trader); 344 345 const lootTypes = ["xp", "food", "wood", "stone", "metal"]; 346 347 for (let type of lootTypes) 342 348 { 343 let carrying = entState.resourceCarrying[0]; 344 totalResourcesCarried[carrying.type] = (totalResourcesCarried[carrying.type] || 0) + carrying.amount; 349 let loot = (totalLoot[type] || 0) + (entState.loot[type] || 0) + (resourcesAndGoodsCarried[type] || 0); 350 if (loot > 0) 351 totalLoot[type] = loot; 345 352 } 353 354 for (let type in resourcesAndGoodsCarried) 355 totalResourcesAndGoodsCarried[type] = (totalResourcesAndGoodsCarried[type] || 0) + resourcesAndGoodsCarried[type]; 346 356 } 347 357 348 358 Engine.GetGUIObjectByName("healthMultiple").hidden = averageHealth <= 0; … … 394 404 395 405 let numberOfUnits = Engine.GetGUIObjectByName("numberOfUnits"); 396 406 numberOfUnits.caption = selection.length; 397 numberOfUnits.tooltip = Object.keys(totalResourcesCarried).map(res =>398 costIcon(res) + totalResourcesCarried[res]399 ).join(" ");400 407 408 numberOfUnits.tooltip = ""; 409 410 if (Object.keys(totalResourcesAndGoodsCarried).length) 411 numberOfUnits.tooltip = sprintf(translate("%(label)s %(details)s\n"), { 412 "label": headerFont(translate("Carrying:")), 413 "details": bodyFont(Object.keys(totalResourcesAndGoodsCarried).map( 414 res => sprintf(translate("%(type)s %(amount)s"), 415 {"type" : costIcon(res), "amount" : totalResourcesAndGoodsCarried[res]})).join(" ")) 416 }); 417 418 if (Object.keys(totalLoot).length) 419 numberOfUnits.tooltip += sprintf(translate("%(label)s %(details)s"), { 420 "label": headerFont(translate("Loot:")), 421 "details": bodyFont(Object.keys(totalLoot).map( 422 res => sprintf(translate("%(type)s %(amount)s"), 423 {"type" : costIcon(res), "amount" : totalLoot[res]})).join(" ")) 424 }); 425 401 426 // Unhide Details Area 402 427 Engine.GetGUIObjectByName("detailsAreaMultiple").hidden = false; 403 428 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 = calculateResourcesAndGoodsCarried( 22 cmpResourceGatherer.GetCarryingStatus() || null, 23 cmpTrader 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 32 // TODO: stop assuming that cmpLoot.GetResources() delivers all resource types (by defining them in a central location) 23 33 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 34 // Transfer resources 45 35 var cmpPlayer = QueryOwnerInterface(this.entity); 46 36 cmpPlayer.AddResources(resources); -
binaries/data/mods/public/simulation/components/tests/test_GuiInterface.js
15 15 Engine.LoadComponentScript("interfaces/Guard.js"); 16 16 Engine.LoadComponentScript("interfaces/Heal.js"); 17 17 Engine.LoadComponentScript("interfaces/Health.js"); 18 Engine.LoadComponentScript("interfaces/Loot.js"); 18 19 Engine.LoadComponentScript("interfaces/Market.js"); 19 20 Engine.LoadComponentScript("interfaces/Pack.js"); 20 21 Engine.LoadComponentScript("interfaces/ProductionQueue.js"); … … 535 536 }, 536 537 buildingAI: null, 537 538 heal: null, 539 loot: null, 538 540 obstruction: null, 539 541 turretParent: null, 540 542 promotion: null,