2010-07-26 05:31:54 +02:00
|
|
|
const RESOURCE_ICON_CELL_IDS = {food : 0, wood : 1, stone : 2, metal : 3};
|
|
|
|
|
|
|
|
// Called by unit selection buttons
|
|
|
|
function changePrimarySelectionGroup(entType)
|
|
|
|
{
|
|
|
|
g_Selection.groups.setPrimary(g_Selection.groups.getGroupNumber(entType)); // set primary group
|
|
|
|
g_Selection.setPrimary(g_Selection.groups.getGroup(entType).firstOfType); // set primary selection
|
|
|
|
resetCycleIndex();
|
|
|
|
}
|
2010-07-01 22:31:47 +02:00
|
|
|
|
2010-07-19 23:23:12 +02:00
|
|
|
// Cycle through the units in the main icon
|
|
|
|
var cycleIndex = 0;
|
|
|
|
var displayedCycleIndex = 1;
|
|
|
|
|
|
|
|
function resetCycleIndex()
|
2010-07-01 22:31:47 +02:00
|
|
|
{
|
2010-07-19 23:23:12 +02:00
|
|
|
cycleIndex = 0;
|
|
|
|
displayedCycleIndex = 1;
|
|
|
|
}
|
|
|
|
|
2010-07-21 23:02:21 +02:00
|
|
|
function cycleThroughSelection()
|
2010-07-01 22:31:47 +02:00
|
|
|
{
|
2010-07-19 23:23:12 +02:00
|
|
|
var selection = g_Selection.toList();
|
|
|
|
|
|
|
|
if (selection.length > 1)
|
|
|
|
{
|
|
|
|
var primaryTemplateName = g_Selection.getPrimaryTemplateName();
|
|
|
|
var primaryIndex = g_Selection.getPrimary();
|
|
|
|
var startIndex = cycleIndex;
|
|
|
|
var endIndex = selection.length-1;
|
2010-07-01 22:31:47 +02:00
|
|
|
|
2010-07-19 23:23:12 +02:00
|
|
|
cycleIndex = ((cycleIndex < endIndex)? cycleIndex+1 : 0);
|
2010-07-01 22:31:47 +02:00
|
|
|
|
2010-07-19 23:23:12 +02:00
|
|
|
while (cycleIndex != startIndex)
|
|
|
|
{
|
2010-07-29 20:22:58 +02:00
|
|
|
var entState = Engine.GuiInterfaceCall("GetEntityState", selection[cycleIndex]);
|
|
|
|
if (!entState)
|
|
|
|
return;
|
|
|
|
|
2010-07-19 23:23:12 +02:00
|
|
|
var equivalentTemplateNames;
|
|
|
|
if (g_GroupSelectionByRank)
|
|
|
|
equivalentTemplateNames = templatesEqualWithoutRank(primaryTemplateName, entState.template);
|
|
|
|
else
|
|
|
|
equivalentTemplateNames = (primaryTemplateName == entState.template);
|
2010-07-01 22:31:47 +02:00
|
|
|
|
2010-07-19 23:23:12 +02:00
|
|
|
if ((cycleIndex != primaryIndex) && equivalentTemplateNames)
|
|
|
|
{
|
|
|
|
var typeCount = g_Selection.groups.getGroup(entState.template).typeCount;
|
|
|
|
displayedCycleIndex = ((displayedCycleIndex < typeCount)? displayedCycleIndex+1 : 1);
|
|
|
|
g_Selection.setPrimary(cycleIndex);
|
|
|
|
break;
|
|
|
|
}
|
2010-07-01 22:31:47 +02:00
|
|
|
|
2010-07-19 23:23:12 +02:00
|
|
|
cycleIndex = ((cycleIndex < endIndex)? cycleIndex+1 : 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function reverseCycleThroughSelection()
|
|
|
|
{
|
|
|
|
var selection = g_Selection.toList();
|
|
|
|
|
|
|
|
if (selection.length > 1)
|
|
|
|
{
|
|
|
|
var primaryTemplateName = g_Selection.getPrimaryTemplateName();
|
|
|
|
var primaryIndex = g_Selection.getPrimary();
|
|
|
|
var startIndex = cycleIndex;
|
|
|
|
var endIndex = selection.length-1;
|
|
|
|
|
|
|
|
cycleIndex = ((cycleIndex > 0)? cycleIndex-1 : endIndex);
|
|
|
|
|
|
|
|
while (cycleIndex != startIndex)
|
|
|
|
{
|
2010-07-29 20:22:58 +02:00
|
|
|
var entState = Engine.GuiInterfaceCall("GetEntityState", selection[cycleIndex]);
|
|
|
|
if (!entState)
|
|
|
|
return;
|
|
|
|
|
2010-07-19 23:23:12 +02:00
|
|
|
var equivalentTemplateNames;
|
|
|
|
if (g_GroupSelectionByRank)
|
|
|
|
equivalentTemplateNames = templatesEqualWithoutRank(primaryTemplateName, entState.template);
|
|
|
|
else
|
|
|
|
equivalentTemplateNames = (primaryTemplateName == entState.template);
|
|
|
|
|
|
|
|
if ((cycleIndex != primaryIndex) && equivalentTemplateNames)
|
|
|
|
{
|
|
|
|
var typeCount = g_Selection.groups.getGroup(entState.template).typeCount;
|
|
|
|
displayedCycleIndex = ((displayedCycleIndex > 1)? displayedCycleIndex-1 : typeCount);
|
|
|
|
g_Selection.setPrimary(cycleIndex);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
cycleIndex = ((cycleIndex > 0)? cycleIndex-1 : endIndex);
|
|
|
|
}
|
|
|
|
}
|
2010-07-01 22:31:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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-02 23:42:17 +02:00
|
|
|
var color = playerState.color;
|
|
|
|
var playerColor = color["r"]*255 + " " + color["g"]*255 + " " + color["b"]*255 + " " + color["a"]*255;
|
2010-07-01 22:31:47 +02:00
|
|
|
var iconTooltip = "";
|
2010-07-19 23:23:12 +02:00
|
|
|
|
2010-07-03 17:06:31 +02:00
|
|
|
// Rank Icon
|
2010-07-05 18:50:06 +02:00
|
|
|
var rankId = getRankCellId(entState.template);
|
|
|
|
getGUIObjectByName("sdRankIcon").cell_id = rankId;
|
2010-07-19 23:23:12 +02:00
|
|
|
|
|
|
|
var rankText = getRankTitle(rankId);
|
|
|
|
rankText = (rankText? " (" + rankText + ")" : "" );
|
|
|
|
|
2010-07-01 22:31:47 +02:00
|
|
|
// Specific Name
|
2010-07-19 23:23:12 +02:00
|
|
|
var name = template.name.specific + rankText; // (eliteStatus? "Elite " + template.name.specific : template.name.specific);
|
2010-07-05 18:50:06 +02:00
|
|
|
getGUIObjectByName("sdSpecific").caption = name;
|
2010-07-01 22:31:47 +02:00
|
|
|
iconTooltip += "[font=\"serif-bold-16\"]" + name + "[/font]";
|
|
|
|
|
|
|
|
// Generic Name
|
|
|
|
if (template.name.generic != template.name.specific)
|
2010-07-05 18:50:06 +02:00
|
|
|
getGUIObjectByName("sdSpecific").tooltip = template.name.generic;
|
2010-07-01 22:31:47 +02:00
|
|
|
else
|
2010-07-05 18:50:06 +02:00
|
|
|
getGUIObjectByName("sdSpecific").tooltip = "";
|
2010-07-01 22:31:47 +02:00
|
|
|
|
|
|
|
// Player Name
|
2010-07-05 18:50:06 +02:00
|
|
|
getGUIObjectByName("sdPlayer").caption = playerState.name;
|
|
|
|
getGUIObjectByName("sdPlayer").tooltip = getFormalCivName(civName);
|
|
|
|
getGUIObjectByName("sdPlayer").textcolor = playerColor;
|
2010-07-01 22:31:47 +02:00
|
|
|
|
|
|
|
// Hitpoints
|
|
|
|
if (entState.hitpoints != undefined)
|
|
|
|
{
|
2010-07-05 18:50:06 +02:00
|
|
|
var healthSize = getGUIObjectByName("sdHealthBar").size;
|
2010-07-01 22:31:47 +02:00
|
|
|
healthSize.rright = 100*Math.max(0, Math.min(1, entState.hitpoints / entState.maxHitpoints));
|
2010-07-05 18:50:06 +02:00
|
|
|
getGUIObjectByName("sdHealthBar").size = healthSize;
|
2010-07-01 22:31:47 +02:00
|
|
|
|
|
|
|
var tooltipHitPoints = "[font=\"serif-bold-13\"]Hitpoints [/font]" + entState.hitpoints + "/" + entState.maxHitpoints;
|
2010-07-05 18:50:06 +02:00
|
|
|
getGUIObjectByName("sdHealth").tooltip = tooltipHitPoints;
|
|
|
|
getGUIObjectByName("sdHealth").hidden = false;
|
2010-07-01 22:31:47 +02:00
|
|
|
iconTooltip += "\n" + tooltipHitPoints;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-07-05 18:50:06 +02:00
|
|
|
getGUIObjectByName("sdHealth").hidden = true;
|
|
|
|
getGUIObjectByName("sdHealth").tooltip = "";
|
2010-07-01 22:31:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Attack stats
|
2010-07-05 18:50:06 +02:00
|
|
|
getGUIObjectByName("sdAttackStats").caption = damageTypesToTextStacked(entState.attack);
|
2010-07-01 22:31:47 +02:00
|
|
|
if (entState.attack)
|
2010-07-19 23:23:12 +02:00
|
|
|
iconTooltip += "\n[font=\"serif-bold-13\"]Attack: [/font]" + damageTypesToText(entState.attack);
|
2010-07-01 22:31:47 +02:00
|
|
|
|
|
|
|
// Armour stats
|
2010-07-05 18:50:06 +02:00
|
|
|
getGUIObjectByName("sdArmourStats").caption = damageTypesToTextStacked(entState.armour);
|
2010-07-01 22:31:47 +02:00
|
|
|
if (entState.armour)
|
2010-07-19 23:23:12 +02:00
|
|
|
iconTooltip += "\n[font=\"serif-bold-13\"]Armour: [/font]" + damageTypesToText(entState.armour);
|
2010-07-01 22:31:47 +02:00
|
|
|
|
2010-07-04 05:49:58 +02:00
|
|
|
// Resource stats
|
|
|
|
if (entState.resourceSupply)
|
2010-07-01 22:31:47 +02:00
|
|
|
{
|
2010-07-04 05:49:58 +02:00
|
|
|
var resources = entState.resourceSupply.amount + "/" + entState.resourceSupply.max + " ";
|
|
|
|
var resourceType = entState.resourceSupply.type["generic"];
|
2010-07-01 22:31:47 +02:00
|
|
|
|
2010-07-16 04:45:22 +02:00
|
|
|
getGUIObjectByName("sdResourceStats").caption = resources;
|
2010-07-26 05:31:54 +02:00
|
|
|
getGUIObjectByName("sdResourceIcon").cell_id = RESOURCE_ICON_CELL_IDS[resourceType];
|
2010-07-05 18:50:06 +02:00
|
|
|
getGUIObjectByName("sdResources").hidden = false;
|
2010-07-02 23:42:17 +02:00
|
|
|
|
2010-07-04 05:49:58 +02:00
|
|
|
iconTooltip += "\n[font=\"serif-bold-13\"]Resources: [/font]" + resources + "[font=\"serif-12\"]" + resourceType + "[/font]";
|
2010-07-02 23:42:17 +02:00
|
|
|
|
2010-07-04 05:49:58 +02:00
|
|
|
// Don't show attack and armour stats on unit with resources - not enough space
|
2010-07-05 18:50:06 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
// Icon
|
2010-07-16 04:45:22 +02:00
|
|
|
getGUIObjectByName("sdIconImage").sprite = template.icon_sheet;
|
2010-07-05 18:50:06 +02:00
|
|
|
getGUIObjectByName("sdIconImage").cell_id = template.icon_cell;
|
2010-07-19 23:23:12 +02:00
|
|
|
getGUIObjectByName("sdIcon").tooltip = iconTooltip;
|
2010-07-05 18:50:06 +02:00
|
|
|
//getGUIObjectByName("sdIconOutline"); // Need to change color of icon outline with the playerColor
|
2010-07-04 05:49:58 +02:00
|
|
|
|
|
|
|
// Is this a Gaia unit?
|
|
|
|
if (civName == GAIA)
|
2010-07-05 18:50:06 +02:00
|
|
|
getGUIObjectByName("sdPlayer").tooltip = ""; // Don't need civ tooltip for Gaia Player - redundant
|
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");
|
|
|
|
|
2010-07-05 18:50:06 +02:00
|
|
|
g_Selection.updateSelection();
|
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) */
|
|
|
|
var entState = Engine.GuiInterfaceCall("GetEntityState", selection[g_Selection.getPrimary()]);
|
|
|
|
if (!entState)
|
|
|
|
return;
|
|
|
|
|
2010-07-02 04:50:45 +02:00
|
|
|
var playerState = simState.players[entState.player];
|
|
|
|
if (!playerState)
|
|
|
|
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-19 23:23:12 +02:00
|
|
|
{
|
|
|
|
var typeCount = g_Selection.groups.getGroup(entState.template).typeCount;
|
|
|
|
getGUIObjectByName("sdSelectionCount").caption = ((typeCount > 1)? displayedCycleIndex + "/" + typeCount : "");
|
2010-07-21 23:02:21 +02:00
|
|
|
|
|
|
|
// Show cycle area if there is more than one unit of that type
|
|
|
|
if (typeCount > 1)
|
|
|
|
getGUIObjectByName("sdCycleArea").hidden = false;
|
|
|
|
else
|
|
|
|
getGUIObjectByName("sdCycleArea").hidden = true;
|
2010-07-19 23:23:12 +02:00
|
|
|
|
2010-07-21 23:02:21 +02:00
|
|
|
// Hide stats area if there is more thanone group
|
|
|
|
if (g_Selection.groups.getLength() > 1)
|
|
|
|
getGUIObjectByName("sdStatsArea").hidden = true;
|
|
|
|
else
|
|
|
|
getGUIObjectByName("sdStatsArea").hidden = false;
|
2010-07-19 23:23:12 +02:00
|
|
|
}
|
2010-07-01 22:31:47 +02:00
|
|
|
else
|
2010-07-19 23:23:12 +02:00
|
|
|
{
|
|
|
|
getGUIObjectByName("sdSelectionCount").caption = "";
|
|
|
|
getGUIObjectByName("sdCycleArea").hidden = true;
|
|
|
|
getGUIObjectByName("sdStatsArea").hidden = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
var template = Engine.GuiInterfaceCall("GetTemplateData", entState.template);
|
2010-07-01 22:31:47 +02:00
|
|
|
|
|
|
|
// 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
|
|
|
}
|