Ticket #3113: total_carried_resources_v1.6.patch
File total_carried_resources_v1.6.patch, 8.2 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/gui/common/tooltips.js
1 const g_CostDisplay Names = {1 const g_CostDisplayIcons = { 2 2 "food": '[icon="iconFood"]', 3 3 "wood": '[icon="iconWood"]', 4 4 "stone": '[icon="iconStone"]', … … 258 258 * Translates a cost component identifier as they are used internally 259 259 * (e.g. "population", "food", etc.) to proper display names. 260 260 */ 261 function getCostComponentDisplay Name(costComponentName)261 function getCostComponentDisplayIcon(costComponentName) 262 262 { 263 if (costComponentName in g_CostDisplay Names)264 return g_CostDisplay Names[costComponentName];263 if (costComponentName in g_CostDisplayIcons) 264 return g_CostDisplayIcons[costComponentName]; 265 265 266 266 warn(sprintf("The specified cost component, ‘%(component)s’, is not currently supported.", { "component": costComponentName })); 267 267 return ""; … … 291 291 totalCosts.time = Math.ceil(template.cost.time * (entity ? Engine.GuiInterfaceCall("GetBatchTime", { "entity": entity, "batchSize": trainNum }) : 1)); 292 292 293 293 let costs = []; 294 if (totalCosts.food) costs.push(sprintf(translate("%(component)s %(cost)s"), { "component": getCostComponentDisplay Name("food"), "cost": totalCosts.food }));295 if (totalCosts.wood) costs.push(sprintf(translate("%(component)s %(cost)s"), { "component": getCostComponentDisplay Name("wood"), "cost": totalCosts.wood }));296 if (totalCosts.metal) costs.push(sprintf(translate("%(component)s %(cost)s"), { "component": getCostComponentDisplay Name("metal"), "cost": totalCosts.metal }));297 if (totalCosts.stone) costs.push(sprintf(translate("%(component)s %(cost)s"), { "component": getCostComponentDisplay Name("stone"), "cost": totalCosts.stone }));298 if (totalCosts.population) costs.push(sprintf(translate("%(component)s %(cost)s"), { "component": getCostComponentDisplay Name("population"), "cost": totalCosts.population }));299 if (totalCosts.time) costs.push(sprintf(translate("%(component)s %(cost)s"), { "component": getCostComponentDisplay Name("time"), "cost": totalCosts.time }));294 if (totalCosts.food) costs.push(sprintf(translate("%(component)s %(cost)s"), { "component": getCostComponentDisplayIcon("food"), "cost": totalCosts.food })); 295 if (totalCosts.wood) costs.push(sprintf(translate("%(component)s %(cost)s"), { "component": getCostComponentDisplayIcon("wood"), "cost": totalCosts.wood })); 296 if (totalCosts.metal) costs.push(sprintf(translate("%(component)s %(cost)s"), { "component": getCostComponentDisplayIcon("metal"), "cost": totalCosts.metal })); 297 if (totalCosts.stone) costs.push(sprintf(translate("%(component)s %(cost)s"), { "component": getCostComponentDisplayIcon("stone"), "cost": totalCosts.stone })); 298 if (totalCosts.population) costs.push(sprintf(translate("%(component)s %(cost)s"), { "component": getCostComponentDisplayIcon("population"), "cost": totalCosts.population })); 299 if (totalCosts.time) costs.push(sprintf(translate("%(component)s %(cost)s"), { "component": getCostComponentDisplayIcon("time"), "cost": totalCosts.time })); 300 300 return costs; 301 301 } 302 302 … … 351 351 // Translation: This string is part of the resources cost string on 352 352 // the tooltip for wall structures. 353 353 out.push(sprintf(translate("%(resourceIcon)s %(minimum)s to %(resourceIcon)s %(maximum)s"), { 354 "resourceIcon": getCostComponentDisplay Name(resource),354 "resourceIcon": getCostComponentDisplayIcon(resource), 355 355 "minimum": resourceMin, 356 356 "maximum": resourceMax 357 357 })); … … 413 413 let formatted = []; 414 414 for (let resource in resources) 415 415 formatted.push(sprintf(translate("%(component)s %(cost)s"), { 416 "component": '[font="sans-12"]' + getCostComponentDisplay Name(resource) + '[/font]',416 "component": '[font="sans-12"]' + getCostComponentDisplayIcon(resource) + '[/font]', 417 417 "cost": resources[resource] 418 418 })); 419 419 -
binaries/data/mods/public/gui/session/selection_details.js
341 341 let maxCapturePoints = 0; 342 342 let capturePoints = (new Array(9)).fill(0); 343 343 let playerID = 0; 344 let totalResourcesCarried; 344 345 345 346 for (let i = 0; i < selection.length; i++) 346 347 { … … 358 359 maxCapturePoints += entState.maxCapturePoints; 359 360 capturePoints = entState.capturePoints.map((v, i) => v + capturePoints[i]); 360 361 } 362 363 if (entState.resourceCarrying && entState.resourceCarrying.length !== 0) 364 { 365 if (!totalResourcesCarried) 366 totalResourcesCarried = {}; 367 368 let carrying = entState.resourceCarrying[0]; 369 if (totalResourcesCarried[carrying.type]) 370 totalResourcesCarried[carrying.type] += carrying.amount; 371 else 372 totalResourcesCarried[carrying.type] = carrying.amount; 373 } 361 374 } 362 375 363 376 Engine.GetGUIObjectByName("healthMultiple").hidden = averageHealth <= 0; … … 407 420 }); 408 421 } 409 422 410 Engine.GetGUIObjectByName("numberOfUnits").caption = selection.length; 423 let numberOfUnits = Engine.GetGUIObjectByName("numberOfUnits"); 424 numberOfUnits.caption = selection.length; 411 425 426 let str = ""; 427 if (totalResourcesCarried) 428 for (let res of RESOURCES) 429 if (totalResourcesCarried[res]) 430 str += getCostComponentDisplayIcon(res) + totalResourcesCarried[res] + " "; 431 numberOfUnits.tooltip = str.substr(0, str.length - 1); 432 412 433 // Unhide Details Area 413 434 Engine.GetGUIObjectByName("detailsAreaMultiple").hidden = false; 414 435 Engine.GetGUIObjectByName("detailsAreaSingle").hidden = true; -
binaries/data/mods/public/gui/session/selection_panels.js
737 737 { 738 738 tooltip += "\n[color=\"red\"]" + translate("Insufficient population capacity:") + "\n[/color]"; 739 739 tooltip += sprintf(translate("%(population)s %(neededSlots)s"), { 740 "population": getCostComponentDisplay Name("population"),740 "population": getCostComponentDisplayIcon("population"), 741 741 "neededSlots": data.item.neededSlots 742 742 }); 743 743 } … … 979 979 { 980 980 if (data.carried) 981 981 { 982 var str = data.name + "\n"; 983 var ress = ["food", "wood", "stone", "metal"]; 984 for (var i = 0; i < 4; ++i) 985 { 986 if (data.carried[ress[i]]) 987 { 988 str += getCostComponentDisplayName(ress[i]) + data.carried[ress[i]]; 989 if (i !== 3) 990 str += " "; 991 } 992 } 993 data.button.tooltip = str; 982 let str = data.name + "\n"; 983 for (let res of RESOURCES) 984 if (data.carried[res]) 985 str += getCostComponentDisplayIcon(res) + data.carried[res] + " "; 986 987 data.button.tooltip = str.substr(0, str.length - 1); 994 988 } 995 989 else 996 990 data.button.tooltip = data.name; -
binaries/data/mods/public/gui/session/selection_panels_middle/multiple_details_area.xml
19 19 20 20 <!-- Total --> 21 21 <object size="100%-42 12 100%-8 46" type="image" sprite="groupsIcon"> 22 <object size="0 0 100% 100%" type="text" style="largeCenteredOutlinedText" name="numberOfUnits" />22 <object size="0 0 100% 100%" type="text" style="largeCenteredOutlinedText" name="numberOfUnits" tooltip_style="sessionToolTipBold"/> 23 23 </object> 24 24 25 25 <!-- Stats Bars --> -
binaries/data/mods/public/gui/structree/draw.js
366 366 let rates = []; 367 367 for (let type in template.gather) 368 368 rates.push(sprintf(translate("%(resourceIcon)s %(rate)s"), { 369 "resourceIcon": getCostComponentDisplay Name(type),369 "resourceIcon": getCostComponentDisplayIcon(type), 370 370 "rate": template.gather[type] 371 371 })); 372 372