diff --git a/binaries/data/mods/public/gui/session/selection_details.js b/binaries/data/mods/public/gui/session/selection_details.js index b40d377b04..ab7e51fb31 100644 --- a/binaries/data/mods/public/gui/session/selection_details.js +++ b/binaries/data/mods/public/gui/session/selection_details.js @@ -15,7 +15,7 @@ function displaySingle(entState, template) { // Get general unit and player data var specificName = template.name.specific; - var genericName = template.name.generic != template.name.specific? template.name.generic : ""; + var genericName = template.name.generic != template.name.specific ? template.name.generic : ""; // If packed, add that to the generic name (reduces template clutter) if (genericName && template.pack && template.pack.state == "packed") genericName += " -- Packed"; @@ -221,33 +221,16 @@ function displaySingle(entState, template) { var realRange = entState.attack.elevationAdaptedRange; var range = entState.attack.maxRange; - attack += ", [font=\"serif-bold-13\"]Range:[/font] " + - Math.round(range/4); + attack += ", [font=\"serif-bold-13\"]Range:[/font] " + range + + "[font=\"sans-10\"][color=\"orange\"] meters[/color][/font]"; - if (Math.round((realRange - range)/4) > 0) - attack += " (+" + Math.round((realRange - range)/4) + ")"; - else if (Math.round((realRange - range)/4) < 0) - attack += " (" + Math.round((realRange - range)/4) + ")"; + if (Math.round(realRange - range) > 0) + attack += " (+" + Math.round(realRange - range) + ")"; + else if (Math.round(realRange - range) < 0) + attack += " (" + Math.round(realRange - range) + ")"; } - attack += "\n[font=\"serif-bold-13\"]Rate:[/font] "; - - var hits = 0; - if (entState.unitAI) - hits++; - if (entState.buildingAI) - hits += entState.buildingAI.arrowCount; - - if (hits == 1) - attack += hits + " attack per "; - else - attack += hits + " attacks per "; - - var time = entState.attack.repeatTime/1000; - if (time == 1) - attack += "second"; - else - attack += time + " seconds"; + attack += ", [font=\"serif-bold-13\"]Rate:[/font] " + attackRateDetails(entState); } Engine.GetGUIObjectByName("attackAndArmorStats").tooltip = attack + "\n[font=\"serif-bold-13\"]Armor:[/font] " + armorTypeDetails(entState.armour); diff --git a/binaries/data/mods/public/gui/session/utility_functions.js b/binaries/data/mods/public/gui/session/utility_functions.js index c701edd16e..2ef3cd51b9 100644 --- a/binaries/data/mods/public/gui/session/utility_functions.js +++ b/binaries/data/mods/public/gui/session/utility_functions.js @@ -32,6 +32,17 @@ function toTitleCase(word) return word; } +function pluralize(word, count, pluralWord) +{ + if (count == 1 && pluralWord != null) + return pluralWord; + + var plural = "s"; + if (word[word.length - 1] == "s") + plural = "es"; + return word + (count == 1 ? "" : plural); +} + // Get the basic player data function getPlayerData(playerAssignments) { @@ -166,6 +177,19 @@ function damageTypeDetails(dmg) } } +function attackRateDetails(entState) { + if (entState.buildingAI) + var arrows = entState.buildingAI.arrowCount; + + var time = entState.attack.repeatTime / 1000; + if (entState.buildingAI) { + return arrows + "[font=\"sans-10\"][color=\"orange\"] " + pluralize("arrow", arrows) + "[/color][/font]" + + " / " + (time == 1 ? "" : time) + " [font=\"sans-10\"][color=\"orange\"]" + pluralize("second", time) + + "[/color][/font]"; + } + return time + "[font=\"sans-10\"][color=\"orange\"] " + pluralize("second", time) + "[/color][/font]"; +} + // Converts an armor level into the actual reduction percentage function armorLevelToPercentage(level) {