2010-07-26 05:31:54 +02:00
|
|
|
const RESOURCE_ICON_CELL_IDS = {food : 0, wood : 1, stone : 2, metal : 3};
|
|
|
|
|
2010-07-31 00:19:43 +02:00
|
|
|
function layoutSelectionMultiple()
|
2010-07-26 05:31:54 +02:00
|
|
|
{
|
2010-07-31 00:19:43 +02:00
|
|
|
getGUIObjectByName("sdSpecific").hidden = true;
|
|
|
|
getGUIObjectByName("sdIcon").hidden = true;
|
|
|
|
getGUIObjectByName("sdStatsArea").hidden = true;
|
|
|
|
getGUIObjectByName("sdHealth").hidden = true;
|
|
|
|
getGUIObjectByName("sdStamina").hidden = true;
|
2010-07-26 05:31:54 +02:00
|
|
|
}
|
2010-07-01 22:31:47 +02:00
|
|
|
|
2010-07-31 00:19:43 +02:00
|
|
|
function layoutSelectionSingle(entState)
|
2010-07-01 22:31:47 +02:00
|
|
|
{
|
2010-07-31 00:19:43 +02:00
|
|
|
getGUIObjectByName("sdSpecific").hidden = false;
|
|
|
|
getGUIObjectByName("sdIcon").hidden = false;
|
|
|
|
getGUIObjectByName("sdStatsArea").hidden = false;
|
2010-07-19 23:23:12 +02:00
|
|
|
|
2010-08-12 05:01:33 +02:00
|
|
|
if (entState.hitpoints != undefined)
|
2010-07-31 00:19:43 +02:00
|
|
|
getGUIObjectByName("sdHealth").hidden = false;
|
2010-08-12 05:01:33 +02:00
|
|
|
else
|
|
|
|
getGUIObjectByName("sdHealth").hidden = true;
|
2010-07-19 23:23:12 +02:00
|
|
|
|
2010-07-31 00:19:43 +02:00
|
|
|
var player = Engine.GetPlayerID();
|
|
|
|
if (entState.player == player || g_DevSettings.controlAll)
|
2010-07-19 23:23:12 +02:00
|
|
|
{
|
2010-08-07 02:21:17 +02:00
|
|
|
if (entState.stamina != undefined)
|
2010-07-31 00:19:43 +02:00
|
|
|
getGUIObjectByName("sdStamina").hidden = false;
|
2010-08-07 02:21:17 +02:00
|
|
|
else
|
|
|
|
getGUIObjectByName("sdStamina").hidden = true;
|
2010-07-19 23:23:12 +02:00
|
|
|
}
|
2010-07-01 22:31:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Fills out information that most entities have
|
2010-08-12 00:16:16 +02:00
|
|
|
function displayGeneralInfo(entState, template)
|
2010-07-01 22:31:47 +02:00
|
|
|
{
|
2010-08-17 15:37:46 +02:00
|
|
|
// Get general unit and player data
|
|
|
|
var specificName = "[font=\"serif-bold-18\"]" + template.name.specific + "[/font]";
|
|
|
|
var genericName = template.name.generic != template.name.specific? template.name.generic : "";
|
2010-07-19 23:23:12 +02:00
|
|
|
|
2010-08-17 15:37:46 +02:00
|
|
|
var rank = entState.identity.rank? "[font=\"serif-bold-18\"]" + entState.identity.rank + " [/font]" : "";
|
|
|
|
var civName = getFormalCivName(toTitleCase(g_Players[entState.player].civ));
|
2010-07-01 22:31:47 +02:00
|
|
|
|
2010-08-17 15:37:46 +02:00
|
|
|
var playerName = g_Players[entState.player].name;
|
|
|
|
var playerColor = g_Players[entState.player].color.r + " " + g_Players[entState.player].color.g + " " +
|
|
|
|
g_Players[entState.player].color.b+ " " + g_Players[entState.player].color.a;
|
2010-07-01 22:31:47 +02:00
|
|
|
|
|
|
|
// Hitpoints
|
2010-08-17 15:37:46 +02:00
|
|
|
var hitpoints = "";
|
|
|
|
|
|
|
|
if (entState.hitpoints)
|
2010-07-01 22:31:47 +02:00
|
|
|
{
|
2010-07-31 00:19:43 +02:00
|
|
|
var unitHealthBar = getGUIObjectByName("sdHealthBar");
|
|
|
|
var healthSize = unitHealthBar.size;
|
2010-07-01 22:31:47 +02:00
|
|
|
healthSize.rright = 100*Math.max(0, Math.min(1, entState.hitpoints / entState.maxHitpoints));
|
2010-07-31 00:19:43 +02:00
|
|
|
unitHealthBar.size = healthSize;
|
2010-07-01 22:31:47 +02:00
|
|
|
|
2010-08-17 15:37:46 +02:00
|
|
|
hitpoints = "[font=\"serif-bold-13\"]Hitpoints [/font]" + entState.hitpoints + "/" + entState.maxHitpoints;
|
|
|
|
getGUIObjectByName("sdHealth").tooltip = hitpoints;
|
2010-07-01 22:31:47 +02:00
|
|
|
}
|
|
|
|
|
2010-07-04 05:49:58 +02:00
|
|
|
// Resource stats
|
2010-08-17 15:37:46 +02:00
|
|
|
var resources = "";
|
|
|
|
var resourceType = "";
|
|
|
|
var resourceCellID = -1;
|
|
|
|
|
2010-07-04 05:49:58 +02:00
|
|
|
if (entState.resourceSupply)
|
2010-07-01 22:31:47 +02:00
|
|
|
{
|
2010-08-17 15:37:46 +02:00
|
|
|
resources = Math.ceil(+entState.resourceSupply.amount) + "/" + entState.resourceSupply.max + " ";
|
|
|
|
resourceType = entState.resourceSupply.type["generic"];
|
|
|
|
resourceCellID = RESOURCE_ICON_CELL_IDS[resourceType];
|
|
|
|
|
2010-07-05 18:50:06 +02:00
|
|
|
getGUIObjectByName("sdResources").hidden = false;
|
|
|
|
getGUIObjectByName("sdAttack").hidden = true;
|
|
|
|
getGUIObjectByName("sdArmour").hidden = true;
|
2010-07-04 05:49:58 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-07-05 18:50:06 +02:00
|
|
|
getGUIObjectByName("sdResources").hidden = true;
|
2010-07-19 23:23:12 +02:00
|
|
|
getGUIObjectByName("sdAttack").hidden = false;
|
|
|
|
getGUIObjectByName("sdArmour").hidden = false;
|
2010-07-01 22:31:47 +02:00
|
|
|
}
|
|
|
|
|
2010-08-17 15:37:46 +02:00
|
|
|
// Set Captions
|
|
|
|
getGUIObjectByName("sdSpecific").caption = rank + specificName;
|
|
|
|
getGUIObjectByName("sdPlayer").caption = playerName;
|
|
|
|
getGUIObjectByName("sdPlayer").textcolor = playerColor;
|
|
|
|
getGUIObjectByName("sdAttackStats").caption = damageTypesToTextStacked(entState.attack);
|
|
|
|
getGUIObjectByName("sdArmourStats").caption = damageTypesToTextStacked(entState.armour);
|
|
|
|
getGUIObjectByName("sdResourceStats").caption = resources;
|
|
|
|
getGUIObjectByName("sdResourceIcon").cell_id = resourceCellID;
|
|
|
|
|
|
|
|
// Icon image
|
|
|
|
if (template.icon_sheet && typeof template.icon_cell)
|
2010-08-11 12:54:08 +02:00
|
|
|
{
|
|
|
|
getGUIObjectByName("sdIconImage").sprite = template.icon_sheet;
|
|
|
|
getGUIObjectByName("sdIconImage").cell_id = template.icon_cell;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// TODO: we should require all entities to have icons, so this case never occurs
|
|
|
|
getGUIObjectByName("sdIconImage").sprite = "bkFillBlack";
|
|
|
|
}
|
2010-07-04 05:49:58 +02:00
|
|
|
|
2010-08-17 15:37:46 +02:00
|
|
|
// TODO: need to change color of icon outline with the playerColor
|
|
|
|
//getGUIObjectByName("sdIconOutline");
|
|
|
|
|
|
|
|
// Tooltips
|
2010-08-19 16:09:00 +02:00
|
|
|
// getGUIObjectByName("sdSpecific").tooltip = genericName;
|
2010-08-17 15:37:46 +02:00
|
|
|
getGUIObjectByName("sdPlayer").tooltip = civName != GAIA? civName : ""; // Don't need civ tooltip for Gaia Player - redundant
|
|
|
|
getGUIObjectByName("sdHealth").tooltip = hitpoints;
|
|
|
|
|
|
|
|
// Icon Tooltip
|
2010-08-19 16:09:00 +02:00
|
|
|
var iconTooltip = "[font=\"serif-bold-16\"]" + genericName + "[/font]";
|
2010-08-17 15:37:46 +02:00
|
|
|
|
|
|
|
if (template.tooltip)
|
2010-08-19 16:09:00 +02:00
|
|
|
iconTooltip += "\n[font=\"serif-13\"]" + template.tooltip + "[/font]";
|
|
|
|
|
|
|
|
/*
|
2010-08-17 15:37:46 +02:00
|
|
|
if (entState.hitpoints)
|
|
|
|
iconTooltip += "\n" + hitpoints;
|
|
|
|
if (entState.attack)
|
|
|
|
iconTooltip += "\n[font=\"serif-bold-13\"]Attack: [/font]" + damageTypesToText(entState.attack);
|
|
|
|
if (entState.armour)
|
|
|
|
iconTooltip += "\n[font=\"serif-bold-13\"]Armour: [/font]" + damageTypesToText(entState.armour);
|
|
|
|
if (entState.resourceSupply)
|
|
|
|
iconTooltip += "\n[font=\"serif-bold-13\"]Resources: [/font]" + resources + "[font=\"serif-12\"]" + resourceType + "[/font]";
|
2010-08-19 16:09:00 +02:00
|
|
|
*/
|
2010-08-17 15:37:46 +02:00
|
|
|
|
|
|
|
getGUIObjectByName("sdIcon").tooltip = iconTooltip;
|
2010-07-01 22:31:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Updates middle entity Selection Details Panel
|
2010-08-12 00:16:16 +02:00
|
|
|
function updateSelectionDetails()
|
2010-07-01 22:31:47 +02:00
|
|
|
{
|
|
|
|
var detailsPanel = getGUIObjectByName("selectionDetails");
|
|
|
|
var commandsPanel = getGUIObjectByName("unitCommands");
|
|
|
|
|
2010-08-01 18:25:24 +02:00
|
|
|
g_Selection.update();
|
2010-07-01 22:31:47 +02:00
|
|
|
var selection = g_Selection.toList();
|
2010-07-05 18:50:06 +02:00
|
|
|
|
2010-07-01 22:31:47 +02:00
|
|
|
if (selection.length == 0)
|
|
|
|
{
|
|
|
|
detailsPanel.hidden = true;
|
|
|
|
commandsPanel.hidden = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the unit has no data (e.g. it was killed), don't try displaying any
|
|
|
|
data for it. (TODO: it should probably be removed from the selection too;
|
|
|
|
also need to handle multi-unit selections) */
|
2010-07-31 00:19:43 +02:00
|
|
|
var entState = Engine.GuiInterfaceCall("GetEntityState", selection[0]);
|
2010-07-01 22:31:47 +02:00
|
|
|
if (!entState)
|
|
|
|
return;
|
|
|
|
|
2010-07-19 23:23:12 +02:00
|
|
|
// Choose the highest ranked version of the primary selection
|
2010-07-01 22:31:47 +02:00
|
|
|
// Different selection details are shown based on whether multiple units or a single unit is selected
|
|
|
|
if (selection.length > 1)
|
2010-07-31 00:19:43 +02:00
|
|
|
layoutSelectionMultiple();
|
2010-07-01 22:31:47 +02:00
|
|
|
else
|
2010-07-31 00:19:43 +02:00
|
|
|
layoutSelectionSingle(entState);
|
2010-07-19 23:23:12 +02:00
|
|
|
|
|
|
|
var template = Engine.GuiInterfaceCall("GetTemplateData", entState.template);
|
2010-07-01 22:31:47 +02:00
|
|
|
|
|
|
|
// Fill out general info and display it
|
2010-08-12 00:16:16 +02:00
|
|
|
displayGeneralInfo(entState, template); // must come after layout functions
|
2010-07-01 22:31:47 +02:00
|
|
|
|
|
|
|
// Show Panels
|
|
|
|
detailsPanel.hidden = false;
|
|
|
|
|
|
|
|
// Fill out commands panel for specific unit selected (or first unit of primary group)
|
2010-07-31 23:46:25 +02:00
|
|
|
updateUnitCommands(entState, commandsPanel, selection);
|
2010-07-01 22:31:47 +02:00
|
|
|
}
|