WhiteTreePaladin
4cfca1625d
Made player names match custom names in multi-player The chat window will still need some more aesthetic work This was SVN commit r7909.
166 lines
5.9 KiB
JavaScript
166 lines
5.9 KiB
JavaScript
const RESOURCE_ICON_CELL_IDS = {food : 0, wood : 1, stone : 2, metal : 3};
|
|
|
|
function layoutSelectionMultiple()
|
|
{
|
|
getGUIObjectByName("sdSpecific").hidden = true;
|
|
getGUIObjectByName("sdIcon").hidden = true;
|
|
getGUIObjectByName("sdStatsArea").hidden = true;
|
|
getGUIObjectByName("sdHealth").hidden = true;
|
|
getGUIObjectByName("sdStamina").hidden = true;
|
|
}
|
|
|
|
function layoutSelectionSingle(entState)
|
|
{
|
|
getGUIObjectByName("sdSpecific").hidden = false;
|
|
getGUIObjectByName("sdIcon").hidden = false;
|
|
getGUIObjectByName("sdStatsArea").hidden = false;
|
|
|
|
if (entState.maxHitpoints != undefined)
|
|
getGUIObjectByName("sdHealth").hidden = false;
|
|
|
|
var player = Engine.GetPlayerID();
|
|
if (entState.player == player || g_DevSettings.controlAll)
|
|
{
|
|
if (entState.stamina != undefined)
|
|
getGUIObjectByName("sdStamina").hidden = false;
|
|
else
|
|
getGUIObjectByName("sdStamina").hidden = true;
|
|
}
|
|
}
|
|
|
|
// Fills out information that most entities have
|
|
function displayGeneralInfo(entState, template)
|
|
{
|
|
var civName = toTitleCase(g_Players[entState.player].civ);
|
|
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;
|
|
|
|
var iconTooltip = "";
|
|
|
|
// Specific Name
|
|
var name = template.name.specific + getRankTitle(getRankCellId(entState.template));
|
|
getGUIObjectByName("sdSpecific").caption = name;
|
|
iconTooltip += "[font=\"serif-bold-16\"]" + name + "[/font]";
|
|
|
|
// Generic Name
|
|
if (template.name.generic != template.name.specific)
|
|
getGUIObjectByName("sdSpecific").tooltip = template.name.generic;
|
|
else
|
|
getGUIObjectByName("sdSpecific").tooltip = "";
|
|
|
|
// Player Name
|
|
getGUIObjectByName("sdPlayer").caption = g_Players[entState.player].name;
|
|
getGUIObjectByName("sdPlayer").tooltip = getFormalCivName(civName);
|
|
getGUIObjectByName("sdPlayer").textcolor = playerColor;
|
|
|
|
// Hitpoints
|
|
if (entState.hitpoints != undefined)
|
|
{
|
|
var unitHealthBar = getGUIObjectByName("sdHealthBar");
|
|
var healthSize = unitHealthBar.size;
|
|
healthSize.rright = 100*Math.max(0, Math.min(1, entState.hitpoints / entState.maxHitpoints));
|
|
unitHealthBar.size = healthSize;
|
|
|
|
var tooltipHitPoints = "[font=\"serif-bold-13\"]Hitpoints [/font]" + entState.hitpoints + "/" + entState.maxHitpoints;
|
|
getGUIObjectByName("sdHealth").tooltip = tooltipHitPoints;
|
|
iconTooltip += "\n" + tooltipHitPoints;
|
|
}
|
|
else
|
|
{
|
|
getGUIObjectByName("sdHealth").tooltip = "";
|
|
}
|
|
|
|
// Attack stats
|
|
getGUIObjectByName("sdAttackStats").caption = damageTypesToTextStacked(entState.attack);
|
|
if (entState.attack)
|
|
iconTooltip += "\n[font=\"serif-bold-13\"]Attack: [/font]" + damageTypesToText(entState.attack);
|
|
|
|
// Armour stats
|
|
getGUIObjectByName("sdArmourStats").caption = damageTypesToTextStacked(entState.armour);
|
|
if (entState.armour)
|
|
iconTooltip += "\n[font=\"serif-bold-13\"]Armour: [/font]" + damageTypesToText(entState.armour);
|
|
|
|
// Resource stats
|
|
if (entState.resourceSupply)
|
|
{
|
|
var resources = Math.ceil(+entState.resourceSupply.amount) + "/" + entState.resourceSupply.max + " ";
|
|
var resourceType = entState.resourceSupply.type["generic"];
|
|
|
|
getGUIObjectByName("sdResourceStats").caption = resources;
|
|
getGUIObjectByName("sdResourceIcon").cell_id = RESOURCE_ICON_CELL_IDS[resourceType];
|
|
getGUIObjectByName("sdResources").hidden = false;
|
|
|
|
iconTooltip += "\n[font=\"serif-bold-13\"]Resources: [/font]" + resources + "[font=\"serif-12\"]" + resourceType + "[/font]";
|
|
|
|
// Don't show attack and armour stats on unit with resources - not enough space
|
|
getGUIObjectByName("sdAttack").hidden = true;
|
|
getGUIObjectByName("sdArmour").hidden = true;
|
|
}
|
|
else
|
|
{
|
|
getGUIObjectByName("sdResources").hidden = true;
|
|
getGUIObjectByName("sdAttack").hidden = false;
|
|
getGUIObjectByName("sdArmour").hidden = false;
|
|
}
|
|
|
|
// Icon
|
|
if (template.icon_sheet && typeof template.icon_cell != "undefined")
|
|
{
|
|
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";
|
|
}
|
|
getGUIObjectByName("sdIcon").tooltip = iconTooltip;
|
|
//getGUIObjectByName("sdIconOutline"); // Need to change color of icon outline with the playerColor
|
|
|
|
// Is this a Gaia unit?
|
|
if (civName == GAIA)
|
|
getGUIObjectByName("sdPlayer").tooltip = ""; // Don't need civ tooltip for Gaia Player - redundant
|
|
}
|
|
|
|
// Updates middle entity Selection Details Panel
|
|
function updateSelectionDetails()
|
|
{
|
|
var detailsPanel = getGUIObjectByName("selectionDetails");
|
|
var commandsPanel = getGUIObjectByName("unitCommands");
|
|
|
|
g_Selection.update();
|
|
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[0]);
|
|
if (!entState)
|
|
return;
|
|
|
|
// Choose the highest ranked version of the primary selection
|
|
// Different selection details are shown based on whether multiple units or a single unit is selected
|
|
if (selection.length > 1)
|
|
layoutSelectionMultiple();
|
|
else
|
|
layoutSelectionSingle(entState);
|
|
|
|
var template = Engine.GuiInterfaceCall("GetTemplateData", entState.template);
|
|
|
|
// Fill out general info and display it
|
|
displayGeneralInfo(entState, template); // must come after layout functions
|
|
|
|
// Show Panels
|
|
detailsPanel.hidden = false;
|
|
|
|
// Fill out commands panel for specific unit selected (or first unit of primary group)
|
|
updateUnitCommands(entState, commandsPanel, selection);
|
|
}
|