Ticket #4193: 4193-loot-tooltip.4.patch
File 4193-loot-tooltip.4.patch, 23.1 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/credits/texts/programming.json
122 122 {"nick": "MarkT", "name": "Mark Thompson"}, 123 123 {"nick": "Markus"}, 124 124 {"nick": "Matei", "name": "Matei Zaharia"}, 125 {"nick": "Mate-86", "name": "Mate Kovacs"}, 125 126 {"nick": "MattDoerksen", "name": "Matt Doerksen"}, 126 127 {"nick": "mattlott", "name": "Matt Lott"}, 127 128 {"nick": "maveric", "name": "Anton Protko"}, -
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/session/session.js
1143 1143 "Cavalry", 1144 1144 "Champion", 1145 1145 "Hero", 1146 "Siege", 1146 1147 "Ship", 1147 1148 "Trader" 1148 1149 ]; -
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/gui/summary/counters.js
5 5 g_TeamHelperData = []; 6 6 } 7 7 8 function formatTrained(trained, lost, killed)8 function formatTrained(trained, killed, lost) 9 9 { 10 10 return g_TrainedColor + trained + '[/color] / ' + 11 g_ LostColor + lost+ '[/color] / ' +12 g_ KilledColor + killed+ '[/color]';11 g_KilledColor + killed + '[/color] / ' + 12 g_LostColor + lost + '[/color]'; 13 13 } 14 14 15 15 function formatCaptured(constructed, destroyed, captured, lost) … … 217 217 218 218 for (let w in counters) 219 219 { 220 let total = { 221 "constructed": 0, 222 "lost": 0, 223 "destroyed": 0 220 let total = 221 { 222 "trained": 0, 223 "killed": 0, 224 "captured" : 0, 225 "lost": 0 224 226 }; 225 227 226 228 for (let p = 0; p < g_Teams[t]; ++p) 227 229 { 228 let splitCaption = cleanGUICaption(t, p, w).split("/"); 230 if (w == 0 || w == 6) 231 { 232 let splitCaption = cleanGUICaption(t, p, w, false).split("\n"); 233 let first = splitCaption[0].split("/"); 234 let second = splitCaption[1].split("/"); 229 235 230 total.constructed += +splitCaption[0]; 231 total.lost += +splitCaption[1]; 232 total.destroyed += +splitCaption[2]; 236 total.trained += +first[0]; 237 total.killed += +first[1]; 238 total.captured += +second[0]; 239 total.lost += +second[1]; 240 } 241 else 242 { 243 let splitCaption = cleanGUICaption(t, p, w).split("/"); 244 total.trained += +splitCaption[0]; 245 total.killed += +splitCaption[1]; 246 total.lost += +splitCaption[2]; 247 } 233 248 } 234 249 235 Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + w + "]").caption = 236 formatTrained(total.constructed, total.lost, total.destroyed); 250 let formattedCaption = ""; 251 252 if (w == 0 || w == 6) 253 formattedCaption = formatCaptured(total.trained, total.killed, total.captured, total.lost); 254 else 255 formattedCaption = formatTrained(total.trained, total.killed, total.lost); 256 257 Engine.GetGUIObjectByName("valueDataTeam[" + t + "][" + w + "]").caption = formattedCaption; 237 258 } 238 259 } 239 260 } 240 261 262 function calculateUnitsWithCaptured(playerState, position) 263 { 264 let type = g_UnitsTypes[position]; 265 266 return formatCaptured( 267 playerState.statistics.unitsTrained[type], 268 playerState.statistics.enemyUnitsKilled[type], 269 playerState.statistics.unitsCaptured[type], 270 playerState.statistics.unitsLost[type]); 271 } 272 241 273 function calculateUnits(playerState, position) 242 274 { 243 275 let type = g_UnitsTypes[position]; … … 244 276 245 277 return formatTrained( 246 278 playerState.statistics.unitsTrained[type], 247 playerState.statistics. unitsLost[type],248 playerState.statistics. enemyUnitsKilled[type]);279 playerState.statistics.enemyUnitsKilled[type], 280 playerState.statistics.unitsLost[type]); 249 281 } 250 282 251 283 function calculateResources(playerState, position) -
binaries/data/mods/public/gui/summary/layout.js
56 56 "units": { 57 57 "headings": [ 58 58 { "caption": translate("Player name"), "yStart": 26, "width": 200 }, 59 { "caption": translate("Total"), "yStart": 34, "width": 120 }, 60 { "caption": translate("Infantry"), "yStart": 34, "width": 100 }, 61 { "caption": translate("Worker"), "yStart": 34, "width": 100 }, 62 { "caption": translate("Cavalry"), "yStart": 34, "width": 100 }, 63 { "caption": translate("Champion"), "yStart": 34, "width": 100 }, 64 { "caption": translate("Heroes"), "yStart": 34, "width": 100 }, 65 { "caption": translate("Navy"), "yStart": 34, "width": 100 }, 66 { "caption": translate("Traders"), "yStart": 34, "width": 100 } 59 { "caption": translate("Total"), "yStart": 34, "width": 105 }, 60 { "caption": translate("Infantry"), "yStart": 34, "width": 85 }, 61 { "caption": translate("Worker"), "yStart": 34, "width": 85 }, 62 { "caption": translate("Cavalry"), "yStart": 34, "width": 85 }, 63 { "caption": translate("Champion"), "yStart": 34, "width": 85 }, 64 { "caption": translate("Heroes"), "yStart": 34, "width": 85 }, 65 { "caption": translate("Siege"), "yStart": 34, "width": 85 }, 66 { "caption": translate("Navy"), "yStart": 34, "width": 85 }, 67 { "caption": translate("Traders"), "yStart": 34, "width": 85 } 67 68 ], 68 69 "titleHeadings": [ 69 70 { 70 "caption": sprintf(translate("Units Statistics (%(trained)s / %( lost)s / %(killed)s)"),71 "caption": sprintf(translate("Units Statistics (%(trained)s / %(killed)s / %(captured)s / %(lost)s)"), 71 72 { 72 73 "trained": g_TrainedColor + translate("Trained") + '[/color]', 73 "lost": g_LostColor + translate("Lost") + '[/color]', 74 "killed": g_KilledColor + translate("Killed") + '[/color]' 74 "killed": g_KilledColor + translate("Killed") + '[/color]', 75 "captured": g_CapturedColor + translate("Captured") + '[/color]', 76 "lost": g_LostColor + translate("Lost") + '[/color]' 75 77 }), 76 78 "yStart": 16, 77 79 "width": (100 * 7 + 120) … … 78 80 }, // width = 820 79 81 ], 80 82 "counters": [ 81 { "width": 120, "fn": calculateUnits, "verticalOffset": 12 }, 82 { "width": 100, "fn": calculateUnits, "verticalOffset": 12 }, 83 { "width": 100, "fn": calculateUnits, "verticalOffset": 12 }, 84 { "width": 100, "fn": calculateUnits, "verticalOffset": 12 }, 85 { "width": 100, "fn": calculateUnits, "verticalOffset": 12 }, 86 { "width": 100, "fn": calculateUnits, "verticalOffset": 12 }, 87 { "width": 100, "fn": calculateUnits, "verticalOffset": 12 }, 88 { "width": 100, "fn": calculateUnits, "verticalOffset": 12 } 83 { "width": 105, "fn": calculateUnitsWithCaptured, "verticalOffset": 3 }, 84 { "width": 85, "fn": calculateUnits, "verticalOffset": 12 }, 85 { "width": 85, "fn": calculateUnits, "verticalOffset": 12 }, 86 { "width": 85, "fn": calculateUnits, "verticalOffset": 12 }, 87 { "width": 85, "fn": calculateUnits, "verticalOffset": 12 }, 88 { "width": 85, "fn": calculateUnits, "verticalOffset": 12 }, 89 { "width": 105, "fn": calculateUnitsWithCaptured, "verticalOffset": 3 }, 90 { "width": 85, "fn": calculateUnits, "verticalOffset": 12 }, 91 { "width": 85, "fn": calculateUnits, "verticalOffset": 12 } 89 92 ], 90 93 "teamCounterFn": calculateUnitsTeam 91 94 }, -
binaries/data/mods/public/gui/summary/summary.js
1 const g_MaxHeadingTitle= 8;1 const g_MaxHeadingTitle= 9; 2 2 3 3 // const for filtering long collective headings 4 4 const g_LongHeadingWidth = 250; … … 16 16 const g_CapturedColor = '[color="255 255 157"]'; 17 17 18 18 const g_BuildingsTypes = [ "total", "House", "Economic", "Outpost", "Military", "Fortress", "CivCentre", "Wonder" ]; 19 const g_UnitsTypes = [ "total", "Infantry", "Worker", "Cavalry", "Champion", "Hero", "S hip", "Trader" ];19 const g_UnitsTypes = [ "total", "Infantry", "Worker", "Cavalry", "Champion", "Hero", "Siege", "Ship", "Trader" ]; 20 20 const g_ResourcesTypes = [ "food", "wood", "stone", "metal" ]; 21 21 22 22 // Colors used for gathered and traded resources -
binaries/data/mods/public/gui/summary/summary.xml
103 103 <object name="playerNameHeading" type="text" style="ModernLeftTabLabelText"> 104 104 <translatableAttribute id="caption">Player name</translatableAttribute> 105 105 </object> 106 <repeat var="x" count=" 8">106 <repeat var="x" count="9"> 107 107 <object name="titleHeading[x]" type="text" style="ModernTabLabelText"> 108 108 </object> 109 109 </repeat> 110 <repeat var="x" count=" 8">110 <repeat var="x" count="9"> 111 111 <object name="Heading[x]" type="text" style="ModernTabLabelText"> 112 112 </object> 113 113 </repeat> … … 124 124 </object> 125 125 <object name="playerNamet[i][n]" type="text" size="40 2 208 100%" style="ModernLeftLabelText"/> 126 126 <object name="civIcont[i][n]" type="image" size="208 5 240 37" /> 127 <repeat var="x" count=" 8">127 <repeat var="x" count="9"> 128 128 <object name="valueDataTeam[i][n][x]" type="text" style="ModernTabLabelText"> 129 129 </object> 130 130 </repeat> … … 132 132 </repeat> 133 133 </object> 134 134 <object name="teamHeadingt[i]" type="text" style="ModernLeftTabLabelText"/> 135 <repeat var="x" count=" 8">135 <repeat var="x" count="9"> 136 136 <object name="valueDataTeam[i][x]" type="text" style="ModernTabLabelText"> 137 137 </object> 138 138 </repeat> … … 147 147 </object> 148 148 <object name="playerName[n]" type="text" size="40 2 208 100%" style="ModernLeftLabelText"/> 149 149 <object name="civIcon[n]" type="image" size="208 5 240 37"/> 150 <repeat var="x" count=" 8">150 <repeat var="x" count="9"> 151 151 <object name="valueData[n][x]" type="text" style="ModernTabLabelText"> 152 152 </object> 153 153 </repeat> -
binaries/data/mods/public/simulation/components/Capturable.js
159 159 160 160 let cmpCapturedPlayerStatisticsTracker = QueryOwnerInterface(this.entity, IID_StatisticsTracker); 161 161 if (cmpCapturedPlayerStatisticsTracker) 162 cmpCapturedPlayerStatisticsTracker.Captured Building(this.entity);162 cmpCapturedPlayerStatisticsTracker.CapturedEntity(this.entity); 163 163 }; 164 164 165 165 Capturable.prototype.GetRegenRate = function() -
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/StatisticsTracker.js
12 12 "Cavalry", 13 13 "Champion", 14 14 "Hero", 15 "Siege", 15 16 "Ship", 16 17 "Trader" 17 18 ]; … … 22 23 "Cavalry": 0, 23 24 "Champion": 0, 24 25 "Hero": 0, 26 "Siege": 0, 25 27 "Ship": 0, 26 28 "Trader": 0, 27 29 "total": 0 … … 33 35 "Cavalry": 0, 34 36 "Champion": 0, 35 37 "Hero": 0, 38 "Siege": 0, 36 39 "Ship": 0, 37 40 "Trader": 0, 38 41 "total": 0 … … 45 48 "Cavalry": 0, 46 49 "Champion": 0, 47 50 "Hero": 0, 51 "Siege": 0, 48 52 "Ship": 0, 49 53 "Trader": 0, 50 54 "total": 0 51 55 }; 52 56 this.enemyUnitsKilledValue = 0; 57 this.unitsCaptured = { 58 "Infantry": 0, 59 "Worker": 0, 60 "Female": 0, 61 "Cavalry": 0, 62 "Champion": 0, 63 "Hero": 0, 64 "Siege": 0, 65 "Ship": 0, 66 "Trader": 0, 67 "total": 0 68 }; 69 this.unitsCapturedValue = 0; 53 70 54 71 this.buildingsClasses = [ 55 72 "House", … … 163 180 "unitsLostValue": this.unitsLostValue, 164 181 "enemyUnitsKilled": this.enemyUnitsKilled, 165 182 "enemyUnitsKilledValue": this.enemyUnitsKilledValue, 183 "unitsCaptured": this.unitsCaptured, 184 "unitsCapturedValue": this.unitsCapturedValue, 166 185 "buildingsConstructed": this.buildingsConstructed, 167 186 "buildingsLost": this.buildingsLost, 168 187 "buildingsLostValue": this.buildingsLostValue, … … 308 327 } 309 328 }; 310 329 311 StatisticsTracker.prototype.Captured Building = function(capturedBuilding)330 StatisticsTracker.prototype.CapturedEntity = function(capturedEntity) 312 331 { 313 let cmpCaptured BuildingIdentity = Engine.QueryInterface(capturedBuilding, IID_Identity);314 if (!cmpCaptured BuildingIdentity)332 let cmpCapturedEntityIdentity = Engine.QueryInterface(capturedEntity, IID_Identity); 333 if (!cmpCapturedEntityIdentity) 315 334 return; 316 335 317 for (let type of this.buildingsClasses) 318 this.CounterIncrement(cmpCapturedBuildingIdentity, "buildingsCaptured", type); 336 if (cmpCapturedEntityIdentity.HasClass("Unit")) 337 { 338 for (let type of this.unitsClasses) 339 this.CounterIncrement(cmpCapturedEntityIdentity, "unitsCaptured", type); 319 340 320 ++this.buildingsCaptured.total;341 ++this.unitsCaptured.total; 321 342 322 let cmpCost = Engine.QueryInterface(capturedBuilding, IID_Cost);323 if (!cmpCost)324 return;343 let cmpCost = Engine.QueryInterface(capturedEntity, IID_Cost); 344 if (!cmpCost) 345 return; 325 346 326 let costs = cmpCost.GetResourceCosts(); 327 for (let type in costs) 328 this.buildingsCapturedValue += costs[type]; 347 let costs = cmpCost.GetResourceCosts(); 348 for (let type in costs) 349 this.unitsCapturedValue += costs[type]; 350 } 351 352 if (cmpCapturedEntityIdentity.HasClass("Structure")) 353 { 354 for (let type of this.buildingsClasses) 355 this.CounterIncrement(cmpCapturedEntityIdentity, "buildingsCaptured", type); 356 357 ++this.buildingsCaptured.total; 358 359 let cmpCost = Engine.QueryInterface(capturedEntity, IID_Cost); 360 if (!cmpCost) 361 return; 362 363 let costs = cmpCost.GetResourceCosts(); 364 for (let type in costs) 365 this.buildingsCapturedValue += costs[type]; 366 } 329 367 }; 330 368 331 369 /** -
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,