2010-07-01 22:31:47 +02:00
|
|
|
const resourceIconCellIds = {food : 0, wood : 1, stone : 2, metal : 3};
|
|
|
|
|
|
|
|
// Multiple Selection Layout
|
|
|
|
function selectionLayoutMultiple()
|
|
|
|
{
|
|
|
|
getGUIObjectByName("selectionDetailsMainText").size = "80 100%-70 100%-14 100%-10";
|
|
|
|
getGUIObjectByName("selectionDetailsSpecific").size = "0 6 100% 30";
|
|
|
|
getGUIObjectByName("selectionDetailsPlayer").size = "0 34 100% 100%-8";
|
|
|
|
|
|
|
|
getGUIObjectByName("selectionDetailsIcon").size = "10 100%-74 66 100%-18";
|
|
|
|
getGUIObjectByName("selectionDetailsHealth").size = "10 100%-16 66 100%-12";
|
|
|
|
getGUIObjectByName("selectionDetailsStamina").size = "10 100%-10 66 100%-6";
|
|
|
|
|
|
|
|
getGUIObjectByName("selectionDetailsAttack").hidden = true;
|
|
|
|
getGUIObjectByName("selectionDetailsArmour").hidden = true;
|
|
|
|
|
|
|
|
getGUIObjectByName("selectionDetailsMainText").sprite = "goldPanel";
|
|
|
|
getGUIObjectByName("selectionDetailsSpecific").sprite = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Single Selection Layout
|
|
|
|
function selectionLayoutSingle()
|
|
|
|
{
|
|
|
|
getGUIObjectByName("selectionDetailsMainText").size = "6 0 100%-6 50";
|
|
|
|
getGUIObjectByName("selectionDetailsSpecific").size = "0 0 100% 30";
|
|
|
|
getGUIObjectByName("selectionDetailsPlayer").size = "0 30 100% 50";
|
|
|
|
|
|
|
|
getGUIObjectByName("selectionDetailsIcon").size = "10 100%-104 90 100%-22";
|
|
|
|
getGUIObjectByName("selectionDetailsHealth").size = "10 100%-20 90 100%-14";
|
|
|
|
getGUIObjectByName("selectionDetailsStamina").size = "10 100%-12 90 100%-6";
|
|
|
|
|
|
|
|
getGUIObjectByName("selectionDetailsAttack").size = "104 64 100% 100%-30";
|
|
|
|
getGUIObjectByName("selectionDetailsArmour").size = "204 64 100% 100%-30";
|
|
|
|
|
|
|
|
getGUIObjectByName("selectionDetailsAttack").hidden = false;
|
|
|
|
getGUIObjectByName("selectionDetailsArmour").hidden = false;
|
|
|
|
|
|
|
|
getGUIObjectByName("selectionDetailsMainText").sprite = "";
|
|
|
|
getGUIObjectByName("selectionDetailsSpecific").sprite = "wheatWindowTitle";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fills out information that most entities have
|
2010-07-02 04:50:45 +02:00
|
|
|
function displayGeneralInfo(playerState, entState, template)
|
2010-07-01 22:31:47 +02:00
|
|
|
{
|
2010-07-02 04:50:45 +02:00
|
|
|
var civName = toTitleCase(playerState.civ);
|
2010-07-01 22:31:47 +02:00
|
|
|
var iconTooltip = "";
|
2010-07-02 04:50:45 +02:00
|
|
|
|
2010-07-01 22:31:47 +02:00
|
|
|
// Is unit Elite?
|
|
|
|
var eliteStatus = isUnitElite(entState.template);
|
|
|
|
|
|
|
|
// Specific Name
|
|
|
|
var name = (eliteStatus? "Elite " + template.name.specific : template.name.specific);
|
|
|
|
getGUIObjectByName("selectionDetailsSpecific").caption = name;
|
|
|
|
iconTooltip += "[font=\"serif-bold-16\"]" + name + "[/font]";
|
|
|
|
|
|
|
|
// Generic Name
|
|
|
|
if (template.name.generic != template.name.specific)
|
|
|
|
getGUIObjectByName("selectionDetailsSpecific").tooltip = template.name.generic;
|
|
|
|
else
|
|
|
|
getGUIObjectByName("selectionDetailsSpecific").tooltip = "";
|
|
|
|
|
|
|
|
// Player Name
|
2010-07-02 04:50:45 +02:00
|
|
|
getGUIObjectByName("selectionDetailsPlayer").caption = playerState.name; //"Player " + entState.player; // TODO: get player name
|
|
|
|
getGUIObjectByName("selectionDetailsPlayer").tooltip = civName;
|
|
|
|
|
|
|
|
// NEED TO FIND OUT HOW COLORS WORK - THIS WILL ARTIFICIALLY COLOR THEM "CORRECTLY"
|
|
|
|
if (entState.player == 1)
|
|
|
|
getGUIObjectByName("selectionDetailsPlayer").textcolor = "blue"; //playerState.colour;
|
|
|
|
else if (entState.player == 2)
|
|
|
|
getGUIObjectByName("selectionDetailsPlayer").textcolor = "red";
|
|
|
|
else
|
|
|
|
getGUIObjectByName("selectionDetailsPlayer").textcolor = "darkgray";
|
2010-07-01 22:31:47 +02:00
|
|
|
|
|
|
|
// Hitpoints
|
|
|
|
if (entState.hitpoints != undefined)
|
|
|
|
{
|
|
|
|
var healthSize = getGUIObjectByName("selectionDetailsHealthBar").size;
|
|
|
|
healthSize.rright = 100*Math.max(0, Math.min(1, entState.hitpoints / entState.maxHitpoints));
|
|
|
|
getGUIObjectByName("selectionDetailsHealthBar").size = healthSize;
|
|
|
|
|
|
|
|
var tooltipHitPoints = "[font=\"serif-bold-13\"]Hitpoints [/font]" + entState.hitpoints + "/" + entState.maxHitpoints;
|
|
|
|
getGUIObjectByName("selectionDetailsHealth").tooltip = tooltipHitPoints;
|
|
|
|
getGUIObjectByName("selectionDetailsHealth").hidden = false;
|
|
|
|
iconTooltip += "\n" + tooltipHitPoints;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
getGUIObjectByName("selectionDetailsHealth").hidden = true;
|
|
|
|
getGUIObjectByName("selectionDetailsHealth").tooltip = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Attack stats
|
|
|
|
getGUIObjectByName("selectionDetailsAttackStats").caption = damageTypesToTextStacked(entState.attack);
|
|
|
|
if (entState.attack)
|
|
|
|
iconTooltip += "\n" + "[font=\"serif-bold-13\"]Attack: [/font]" + damageTypesToText(entState.attack);
|
|
|
|
|
|
|
|
// Armour stats
|
|
|
|
getGUIObjectByName("selectionDetailsArmourStats").caption = damageTypesToTextStacked(entState.armour);
|
|
|
|
if (entState.armour)
|
|
|
|
iconTooltip += "\n" + "[font=\"serif-bold-13\"]Armour: [/font]" + damageTypesToText(entState.armour);
|
|
|
|
|
2010-07-02 04:50:45 +02:00
|
|
|
// Resources
|
|
|
|
getGUIObjectByName("selectionDetailsResources").hidden = true;
|
|
|
|
|
2010-07-01 22:31:47 +02:00
|
|
|
// Is this a Gaia unit?
|
|
|
|
var firstWord = entState.template.substring(0, entState.template.search("/"));
|
|
|
|
if (firstWord == "gaia")
|
|
|
|
{
|
2010-07-02 04:50:45 +02:00
|
|
|
getGUIObjectByName("selectionDetailsPlayer").tooltip = "";
|
2010-07-01 22:31:47 +02:00
|
|
|
getGUIObjectByName("selectionDetailsAttack").hidden = true;
|
|
|
|
getGUIObjectByName("selectionDetailsArmour").hidden = true;
|
|
|
|
|
2010-07-02 04:50:45 +02:00
|
|
|
// Resource stats
|
|
|
|
if (entState.resourceSupply)
|
|
|
|
{
|
|
|
|
var resources = entState.resourceSupply.amount + "/" + entState.resourceSupply.max + " ";
|
|
|
|
var resourceType = entState.resourceSupply.type["generic"];
|
2010-07-01 22:31:47 +02:00
|
|
|
|
2010-07-02 04:50:45 +02:00
|
|
|
getGUIObjectByName("selectionDetailsResourceStats").caption = resources;
|
|
|
|
getGUIObjectByName("selectionDetailsResourceIcon").cell_id = resourceIconCellIds[resourceType];
|
|
|
|
getGUIObjectByName("selectionDetailsResources").hidden = false;
|
2010-07-01 22:31:47 +02:00
|
|
|
|
2010-07-02 04:50:45 +02:00
|
|
|
iconTooltip += "\n[font=\"serif-bold-13\"]Resources: [/font]" + resources + "[font=\"serif-12\"]" + resourceType + "[/font]";
|
|
|
|
}
|
2010-07-01 22:31:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Icon
|
2010-07-02 04:50:45 +02:00
|
|
|
getGUIObjectByName("selectionDetailsIconImage").sprite = getPortraitSheetName(playerState, entState);
|
2010-07-01 22:31:47 +02:00
|
|
|
getGUIObjectByName("selectionDetailsIconImage").cell_id = template.icon_cell;
|
2010-07-02 04:50:45 +02:00
|
|
|
getGUIObjectByName("selectionDetailsIconImage").tooltip = iconTooltip;
|
2010-07-01 22:31:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Updates middle entity Selection Details Panel
|
2010-07-02 04:50:45 +02:00
|
|
|
function updateSelectionDetails(simState)
|
2010-07-01 22:31:47 +02:00
|
|
|
{
|
|
|
|
var detailsPanel = getGUIObjectByName("selectionDetails");
|
|
|
|
var commandsPanel = getGUIObjectByName("unitCommands");
|
|
|
|
|
|
|
|
var selection = g_Selection.toList();
|
|
|
|
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) */
|
|
|
|
var entState = Engine.GuiInterfaceCall("GetEntityState", selection[g_Selection.getPrimary()]);
|
|
|
|
if (!entState)
|
|
|
|
{
|
|
|
|
detailsPanel.hidden = true;
|
|
|
|
commandsPanel.hidden = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-07-02 04:50:45 +02:00
|
|
|
var playerState = simState.players[entState.player];
|
|
|
|
if (!playerState)
|
|
|
|
return;
|
|
|
|
|
2010-07-01 22:31:47 +02:00
|
|
|
var template = Engine.GuiInterfaceCall("GetTemplateData", entState.template);
|
|
|
|
|
|
|
|
// Different selection details are shown based on whether multiple units or a single unit is selected
|
|
|
|
if (selection.length > 1)
|
|
|
|
selectionLayoutMultiple();
|
|
|
|
else
|
|
|
|
selectionLayoutSingle();
|
|
|
|
|
|
|
|
// Fill out general info and display it
|
2010-07-02 04:50:45 +02:00
|
|
|
displayGeneralInfo(playerState, 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-02 04:50:45 +02:00
|
|
|
updateUnitCommands(playerState, entState, commandsPanel, selection);
|
2010-07-01 22:31:47 +02:00
|
|
|
}
|