Adds useful stats to training and construction tooltips, based on patch from pejuko. Fixes #872.

This was SVN commit r10518.
This commit is contained in:
historic_bruno 2011-11-12 22:23:08 +00:00
parent 99e012ba56
commit ff064aca95
3 changed files with 107 additions and 30 deletions

View File

@ -214,25 +214,39 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
case TRAINING: case TRAINING:
var tooltip = getEntityNameWithGenericType(template); var tooltip = getEntityNameWithGenericType(template);
if (template.tooltip) if (template.tooltip)
tooltip += "\n[font=\"serif-13\"]" + template.tooltip + "[/font]"; tooltip += "\n[font=\"serif-13\"]" + template.tooltip + "[/font]";
var [batchSize, batchIncrement] = getTrainingQueueBatchStatus(unitEntState.id, entType);
var trainNum = batchSize ? batchSize+batchIncrement : batchIncrement;
tooltip += "\n" + getEntityCost(template); tooltip += "\n" + getEntityCost(template);
var [batchSize, batchIncrement] = getTrainingQueueBatchStatus(unitEntState.id, entType); if (template.health)
if (batchSize) tooltip += "\n[font=\"serif-bold-13\"]Health:[/font] " + template.health;
{ if (template.armour)
tooltip += "\n[font=\"serif-13\"]Training [font=\"serif-bold-13\"]" + batchSize + "[font=\"serif-13\"] units; " + tooltip += "\n[font=\"serif-bold-13\"]Armour:[/font] " + damageTypesToText(template.armour);
"Shift-click to train [font=\"serif-bold-13\"]"+ (batchSize+batchIncrement) + "[font=\"serif-13\"] units[/font]"; if (template.attack)
} tooltip += "\n" + getEntityAttack(template);
if (template.speed)
tooltip += "\n" + getEntitySpeed(template);
tooltip += "\n\n[font=\"serif-bold-13\"]Shift-click[/font][font=\"serif-13\"] to train " + trainNum + ".[/font]";
break; break;
case CONSTRUCTION: case CONSTRUCTION:
var tooltip = getEntityNameWithGenericType(template); var tooltip = getEntityNameWithGenericType(template);
if (template.tooltip) if (template.tooltip)
tooltip += "\n[font=\"serif-13\"]" + template.tooltip + getPopulationBonus(template) + "[/font]"; tooltip += "\n[font=\"serif-13\"]" + template.tooltip + "[/font]";
tooltip += "\n" + getEntityCost(template); tooltip += "\n" + getEntityCost(template);
tooltip += getPopulationBonus(template);
if (template.health)
tooltip += "\n[font=\"serif-bold-13\"]Health:[/font] " + template.health;
break; break;
case COMMAND: case COMMAND:

View File

@ -245,19 +245,19 @@ function getEntityCommandsList(entState)
function getEntityCost(template) function getEntityCost(template)
{ {
var cost = "";
if (template.cost) if (template.cost)
{ {
var costs = []; var costs = [];
if (template.cost.food) costs.push("[font=\"serif-bold-13\"]Food:[/font] " + template.cost.food); if (template.cost.food) costs.push(template.cost.food + " [font=\"serif-12\"]Food[/font]");
if (template.cost.wood) costs.push("[font=\"serif-bold-13\"]Wood:[/font] " + template.cost.wood); if (template.cost.wood) costs.push(template.cost.wood + " [font=\"serif-12\"]Wood[/font]");
if (template.cost.metal) costs.push("[font=\"serif-bold-13\"]Metal:[/font] " + template.cost.metal); if (template.cost.metal) costs.push(template.cost.metal + " [font=\"serif-12\"]Metal[/font]");
if (template.cost.stone) costs.push("[font=\"serif-bold-13\"]Stone:[/font] " + template.cost.stone); if (template.cost.stone) costs.push(template.cost.stone + " [font=\"serif-12\"]Stone[/font]");
if (template.cost.population) costs.push("[font=\"serif-bold-13\"]Population:[/font] " + template.cost.population); if (template.cost.population) costs.push(template.cost.population + " [font=\"serif-12\"]Population[/font]");
if (costs.length) cost += "[font=\"serif-bold-13\"]Costs:[/font] " + costs.join(", ");
return costs.join(", ");
} }
return ""; return cost;
} }
function getPopulationBonus(template) function getPopulationBonus(template)
@ -268,20 +268,48 @@ function getPopulationBonus(template)
return popBonus; return popBonus;
} }
function getEntitySpeed(template)
{
var speed = "";
if (template.speed)
{
speed += "[font=\"serif-bold-13\"]Speed:[/font] ";
var speeds = [];
if (template.speed.walk) speeds.push(template.speed.walk + " [font=\"serif-12\"]Walk[/font]");
if (template.speed.run) speeds.push(template.speed.run + " [font=\"serif-12\"]Run[/font]");
speed += speeds.join(", ");
}
return speed;
}
function getEntityAttack(template)
{
var attacks = [];
if (template.attack)
{
for (var type in template.attack)
{
attacks.push("[font=\"serif-bold-13\"]" + type + " Attack:[/font] " + damageTypesToText(template.attack[type]));
}
}
return attacks.join("\n");
}
function getEntityName(template) function getEntityName(template)
{ {
return template.name.specific || template.name.generic || "???"; return template.name.specific || template.name.generic || "???";
} }
function getEntityNameWithGenericType(template) function getEntityNameWithGenericType(template)
{ {
var name; var name;
if ((template.name.specific && template.name.generic) && (template.name.specific != template.name.generic)) if ((template.name.specific && template.name.generic) && (template.name.specific != template.name.generic))
name = template.name.specific + " (" + template.name.generic + ")"; name = template.name.specific + " (" + template.name.generic + ")";
else else
name = template.name.specific || template.name.generic || "???"; name = template.name.specific || template.name.generic || "???";
return "[font=\"serif-bold-16\"]" + name + "[/font]"; return "[font=\"serif-bold-16\"]" + name + "[/font]";
} }
function getEntityRankedName(entState) function getEntityRankedName(entState)

View File

@ -270,6 +270,44 @@ GuiInterface.prototype.GetTemplateData = function(player, name)
var ret = {}; var ret = {};
if (template.Armour)
{
ret.armour = {
"hack": +template.Armour.Hack,
"pierce": +template.Armour.Pierce,
"crush": +template.Armour.Crush,
};
}
if (template.Attack)
{
ret.attack = {};
for (var type in template.Attack)
{
ret.attack[type] = {
"hack": (+template.Attack[type].Hack || 0),
"pierce": (+template.Attack[type].Pierce || 0),
"crush": (+template.Attack[type].Crush || 0),
};
}
}
if (template.Cost)
{
ret.cost = {};
if (template.Cost.Resources.food) ret.cost.food = +template.Cost.Resources.food;
if (template.Cost.Resources.wood) ret.cost.wood = +template.Cost.Resources.wood;
if (template.Cost.Resources.stone) ret.cost.stone = +template.Cost.Resources.stone;
if (template.Cost.Resources.metal) ret.cost.metal = +template.Cost.Resources.metal;
if (template.Cost.Population) ret.cost.population = +template.Cost.Population;
if (template.Cost.PopulationBonus) ret.cost.populationBonus = +template.Cost.PopulationBonus;
}
if (template.Health)
{
ret.health = +template.Health.Max;
}
if (template.Identity) if (template.Identity)
{ {
ret.selectionGroupName = template.Identity.SelectionGroupName; ret.selectionGroupName = template.Identity.SelectionGroupName;
@ -281,15 +319,12 @@ GuiInterface.prototype.GetTemplateData = function(player, name)
ret.tooltip = template.Identity.Tooltip; ret.tooltip = template.Identity.Tooltip;
} }
if (template.Cost) if (template.UnitMotion)
{ {
ret.cost = {}; ret.speed = {
if (template.Cost.Resources.food) ret.cost.food = +template.Cost.Resources.food; "walk": +template.UnitMotion.WalkSpeed,
if (template.Cost.Resources.wood) ret.cost.wood = +template.Cost.Resources.wood; };
if (template.Cost.Resources.stone) ret.cost.stone = +template.Cost.Resources.stone; if (template.UnitMotion.Run) ret.speed.run = +template.UnitMotion.Run.Speed;
if (template.Cost.Resources.metal) ret.cost.metal = +template.Cost.Resources.metal;
if (template.Cost.Population) ret.cost.population = +template.Cost.Population;
if (template.Cost.PopulationBonus) ret.cost.populationBonus = +template.Cost.PopulationBonus;
} }
return ret; return ret;