1
0
forked from 0ad/0ad

Player name now references actual player name (almost)

Added civ name to tooltip of player name
Player colors hacked in (to at least look consistent)
Made icons reference proper portrait sheets

This was SVN commit r7662.
This commit is contained in:
WhiteTreePaladin 2010-07-02 02:50:45 +00:00
parent 0002a5befe
commit 98a7d67b43
4 changed files with 85 additions and 36 deletions

View File

@ -40,10 +40,11 @@ function selectionLayoutSingle()
}
// Fills out information that most entities have
function displayGeneralInfo(entState, template)
function displayGeneralInfo(playerState, entState, template)
{
var civName = toTitleCase(playerState.civ);
var iconTooltip = "";
// Is unit Elite?
var eliteStatus = isUnitElite(entState.template);
@ -59,7 +60,16 @@ function displayGeneralInfo(entState, template)
getGUIObjectByName("selectionDetailsSpecific").tooltip = "";
// Player Name
getGUIObjectByName("selectionDetailsPlayer").caption = "Player " + entState.player; // TODO: get player name
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";
// Hitpoints
if (entState.hitpoints != undefined)
@ -89,39 +99,39 @@ function displayGeneralInfo(entState, template)
if (entState.armour)
iconTooltip += "\n" + "[font=\"serif-bold-13\"]Armour: [/font]" + damageTypesToText(entState.armour);
// Resources
getGUIObjectByName("selectionDetailsResources").hidden = true;
// Is this a Gaia unit?
var firstWord = entState.template.substring(0, entState.template.search("/"));
if (firstWord == "gaia")
{
getGUIObjectByName("selectionDetailsPlayer").tooltip = "";
getGUIObjectByName("selectionDetailsAttack").hidden = true;
getGUIObjectByName("selectionDetailsArmour").hidden = true;
}
// Resource stats
if (entState.resourceSupply)
{
var resources = entState.resourceSupply.amount + "/" + entState.resourceSupply.max + " ";
var resourceType = entState.resourceSupply.type["generic"];
// Resource stats
if (entState.resourceSupply)
{
var resources = entState.resourceSupply.amount + "/" + entState.resourceSupply.max + " ";
var resourceType = entState.resourceSupply.type["generic"];
getGUIObjectByName("selectionDetailsResourceStats").caption = resources;
getGUIObjectByName("selectionDetailsResourceIcon").cell_id = resourceIconCellIds[resourceType];
getGUIObjectByName("selectionDetailsResources").hidden = false;
getGUIObjectByName("selectionDetailsResourceStats").caption = resources;
getGUIObjectByName("selectionDetailsResourceIcon").cell_id = resourceIconCellIds[resourceType];
getGUIObjectByName("selectionDetailsResources").hidden = false;
iconTooltip += "\n[font=\"serif-bold-13\"]Resources: [/font]" + resources + "[font=\"serif-12\"]" + resourceType + "[/font]";
}
else
{
getGUIObjectByName("selectionDetailsResources").hidden = true;
iconTooltip += "\n[font=\"serif-bold-13\"]Resources: [/font]" + resources + "[font=\"serif-12\"]" + resourceType + "[/font]";
}
}
// Icon
getGUIObjectByName("selectionDetailsIconImage").tooltip = iconTooltip;
getGUIObjectByName("selectionDetailsIconImage").sprite = "snPortraitSheetHele";
getGUIObjectByName("selectionDetailsIconImage").sprite = getPortraitSheetName(playerState, entState);
getGUIObjectByName("selectionDetailsIconImage").cell_id = template.icon_cell;
getGUIObjectByName("selectionDetailsIconImage").tooltip = iconTooltip;
}
// Updates middle entity Selection Details Panel
function updateSelectionDetails()
function updateSelectionDetails(simState)
{
var detailsPanel = getGUIObjectByName("selectionDetails");
var commandsPanel = getGUIObjectByName("unitCommands");
@ -145,6 +155,10 @@ function updateSelectionDetails()
return;
}
var playerState = simState.players[entState.player];
if (!playerState)
return;
var template = Engine.GuiInterfaceCall("GetTemplateData", entState.template);
// Different selection details are shown based on whether multiple units or a single unit is selected
@ -154,11 +168,11 @@ function updateSelectionDetails()
selectionLayoutSingle();
// Fill out general info and display it
displayGeneralInfo(entState, template); // must come after layout functions
displayGeneralInfo(playerState, 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(commandsPanel, selection, entState);
updateUnitCommands(playerState, entState, commandsPanel, selection);
}

View File

@ -73,7 +73,7 @@ function onSimulationUpdate()
updateDebug(simState);
updatePlayerDisplay(simState);
updateSelectionDetails();
updateSelectionDetails(simState);
}
function updateDebug(simState)
@ -109,7 +109,7 @@ function updateDebug(simState)
function updatePlayerDisplay(simState)
{
var playerState = simState.players[Engine.GetPlayerID()];
if (!playerState)
return;
@ -120,11 +120,17 @@ function updatePlayerDisplay(simState)
getGUIObjectByName("resourcePop").caption = playerState.popCount + "/" + playerState.popLimit;
}
//-------------------------------- -------------------------------- --------------------------------
// Utility functions
//-------------------------------- -------------------------------- --------------------------------
function toTitleCase(string)
{
if (string.length > 0)
string = string.charAt(0).toUpperCase() + string.substring(1, string.length).toLowerCase();
return string;
}
function damageTypesToTextStacked(dmg)
{
if (!dmg)
@ -145,9 +151,9 @@ function damageTypesToText(dmg)
var crushDamage = dmg.crush;
var dmgArray = [];
(hackDamage? dmgArray.push(hackDamage + hackLabel) : "");
(pierceDamage? dmgArray.push(pierceDamage + pierceLabel) : "");
(crushDamage? dmgArray.push(crushDamage + crushLabel) : "");
if (hackDamage) dmgArray.push(hackDamage + hackLabel);
if (pierceDamage) dmgArray.push(pierceDamage + pierceLabel);
if (crushDamage) dmgArray.push(crushDamage + crushLabel);
return dmgArray.join(", ");
}
@ -175,3 +181,31 @@ function getFullName(template)
return "[font=\"serif-bold-16\"]" + name + "[/font]";
}
function getPortraitSheetName(playerState, entState)
{
var portraitSheetName = "snPortraitSheet";
var civName = toTitleCase(playerState.civ);
if (civName != "Gaia")
{
portraitSheetName += civName;
}
else // Find appropriate Gaia icon sheet
{
var template = Engine.GuiInterfaceCall("GetTemplateData", entState.template);
var gaiaType = template.name.generic;
if ((gaiaType == "Rock") || (gaiaType == "Mineral"))
portraitSheetName += "RockGaia";
else if ((gaiaType == "Tree") || (gaiaType == "Bush"))
portraitSheetName += "TreeGaia";
else if (gaiaType == "Fauna")
portraitSheetName += "AnimalGaia";
else
portraitSheetName += "SpecialGaia";
}
return portraitSheetName;
}

View File

@ -317,7 +317,7 @@
<object size="10 0 100%-10 56" name="selectionDetailsMainText" type="image" sprite="wheatWindowTitle">
<object size="0 5 100% 30" name="selectionDetailsSpecific" type="text" style="largeBoldCenteredText" tooltip_style="snToolTip"/>
<object hidden="true" size="0 20 100% 40" name="selectionDetailsGeneric" type="text" font="serif-14"/>
<object size="0 30 100% 50" name="selectionDetailsPlayer" type="text" style="centeredText" font="serif-14" textcolor="blue"/>
<object size="0 30 100% 50" name="selectionDetailsPlayer" type="text" style="centeredText" font="serif-14" tooltip_style="snToolTip" textcolor="blue"/>
</object>
<!-- Attack stats -->

View File

@ -5,7 +5,7 @@ var g_unitPanelButtons = { "Construction": 0, "Training": 0, "Queue": 0 };
var g_unitPanels = ["Stance", "Formation", "Construction", "Research", "Training", "Queue", "Selection"];
// Sets up "unit panels" - the panels with rows of icons (Helper function for updateUnitDisplay)
function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
function setupUnitPanel(guiName, usedPanels, playerState, unitEntState, items, callback)
{
usedPanels[guiName] = 1;
var i = 0;
@ -81,7 +81,8 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
if (callback != null)
button.onpress = (function(e) { return function() { callback(e) } })(item); // (need nested functions to get the closure right)
icon.sprite = "snPortraitSheetHele"; // TODO
icon.sprite = getPortraitSheetName(playerState, unitEntState) //"snPortraitSheetHele"; // TODO
if (typeof template.icon_cell == "undefined")
icon.cell_id = 0;
else
@ -132,7 +133,7 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
}
// Updates right Unit Commands Panel - runs in the main session loop via updateSelectionDetails()
function updateUnitCommands(commandsPanel, selection, entState)
function updateUnitCommands(playerState, entState, commandsPanel, selection)
{
// Panels that are active
var usedPanels = {};
@ -153,18 +154,18 @@ function updateUnitCommands(commandsPanel, selection, entState)
}
if (entState.buildEntities && entState.buildEntities.length)
setupUnitPanel("Construction", usedPanels, entState, entState.buildEntities, startBuildingPlacement);
setupUnitPanel("Construction", usedPanels, playerState, entState, entState.buildEntities, startBuildingPlacement);
if (entState.training && entState.training.entities.length)
setupUnitPanel("Training", usedPanels, entState, entState.training.entities,
setupUnitPanel("Training", usedPanels, playerState, entState, entState.training.entities,
function (trainEntType) { addToTrainingQueue(entState.id, trainEntType); } );
if (entState.training && entState.training.queue.length)
setupUnitPanel("Queue", usedPanels, entState, entState.training.queue,
setupUnitPanel("Queue", usedPanels, playerState, entState, entState.training.queue,
function (item) { removeFromTrainingQueue(entState.id, item.id); } );
if (selection.length > 1)
setupUnitPanel("Selection", usedPanels, entState, g_Selection.groups.groupTemplates,
setupUnitPanel("Selection", usedPanels, playerState, entState, g_Selection.groups.groupTemplates,
function (entType) { changePrimarySelectionGroup(entType); } );
// Stamina