1
0
forked from 0ad/0ad

Added resource quantities to GUI for resource entities

Some code cleanup

This was SVN commit r7657.
This commit is contained in:
WhiteTreePaladin 2010-07-01 20:06:23 +00:00
parent 5fec6c40dd
commit 6d625fdc55
3 changed files with 123 additions and 74 deletions

View File

@ -73,7 +73,7 @@ function onSimulationUpdate()
updateDebug(simState);
updatePlayerDisplay(simState);
updateUnitDisplay();
updateSelectionDetails();
}
function updateDebug(simState)
@ -137,14 +137,19 @@ function damageTypesToText(dmg)
if (!dmg)
return "[font=\"serif-12\"](None)[/font]";
var hackLabel = "[font=\"serif-12\"] Hack, [/font]";
var pierceLabel = "[font=\"serif-12\"] Pierce, [/font]";
var hackLabel = "[font=\"serif-12\"] Hack[/font]";
var pierceLabel = "[font=\"serif-12\"] Pierce[/font]";
var crushLabel = "[font=\"serif-12\"] Crush[/font]";
var hackDamage = dmg.hack;
var pierceDamage = dmg.pierce;
var crushDamage = dmg.crush;
return hackDamage + hackLabel + pierceDamage + pierceLabel + crushDamage + crushLabel;
var dmgArray = [];
(hackDamage? dmgArray.push(hackDamage + hackLabel) : "");
(pierceDamage? dmgArray.push(pierceDamage + pierceLabel) : "");
(crushDamage? dmgArray.push(crushDamage + crushLabel) : "");
return dmgArray.join(", ");
}
function isUnitElite(templateName)
@ -270,6 +275,8 @@ function hideCommands(booleanValue)
// Details Panel layout
//-------------------------------- -------------------------------- --------------------------------
const resourceIconCellIds = {food : 0, wood : 1, stone : 2, metal : 3};
// Multiple Selection Layout
function selectionLayoutMultiple()
{
@ -280,10 +287,10 @@ function selectionLayoutMultiple()
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("selectionDetailsArmour").hidden = true;
getGUIObjectByName("selectionDetailsMainText").sprite = "goldPanel";
getGUIObjectByName("selectionDetailsSpecific").sprite = "";
}
@ -291,16 +298,17 @@ function selectionLayoutMultiple()
// Single Selection Layout
function selectionLayoutSingle()
{
getGUIObjectByName("selectionDetailsMainText").size = "6 0 100%-6 60";
getGUIObjectByName("selectionDetailsMainText").size = "6 0 100%-6 50";
getGUIObjectByName("selectionDetailsSpecific").size = "0 0 100% 30";
getGUIObjectByName("selectionDetailsPlayer").size = "0 30 100% 56";
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 72 100% 100%";
getGUIObjectByName("selectionDetailsArmour").size = "204 72 100% 100%";
getGUIObjectByName("selectionDetailsAttack").size = "104 64 100% 100%-30";
getGUIObjectByName("selectionDetailsArmour").size = "204 64 100% 100%-30";
getGUIObjectByName("selectionDetailsAttack").hidden = false;
getGUIObjectByName("selectionDetailsArmour").hidden = false;
@ -314,9 +322,7 @@ var g_unitPanelButtons = { "Construction": 0, "Training": 0, "Queue": 0 };
// Unit panels are panels with row(s) of buttons
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)
{
usedPanels[guiName] = 1;
@ -443,14 +449,92 @@ function setupUnitPanel(guiName, usedPanels, unitEntState, items, callback)
g_unitPanelButtons[guiName] = numButtons;
}
//-------------------------------- -------------------------------- --------------------------------
// Updates middle Selection Details Panel - runs in the main session loop
//-------------------------------- -------------------------------- --------------------------------
function updateUnitDisplay()
// Fills out information that most entities have
function displayGeneralInfo(entState, template)
{
var iconTooltip = "";
// 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
getGUIObjectByName("selectionDetailsPlayer").caption = "Player " + entState.player; // TODO: get player name
// 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);
// Is this a Gaia unit?
var firstWord = entState.template.substring(0, entState.template.search("/"));
if (firstWord == "gaia")
{
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"];
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;
}
// Icon
getGUIObjectByName("selectionDetailsIconImage").tooltip = iconTooltip;
getGUIObjectByName("selectionDetailsIconImage").sprite = "snPortraitSheetHele";
getGUIObjectByName("selectionDetailsIconImage").cell_id = template.icon_cell;
}
function updateSelectionDetails()
{
var detailsPanel = getGUIObjectByName("selectionDetails");
var commandsPanel = getGUIObjectByName("unitCommands");
var selection = g_Selection.toList();
if (selection.length == 0)
{
@ -469,57 +553,8 @@ function updateUnitDisplay()
commandsPanel.hidden = true;
return;
}
var template = Engine.GuiInterfaceCall("GetTemplateData", entState.template);
var iconTooltip = "";
// 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;
getGUIObjectByName("selectionDetailsHealth").tooltip = "Hitpoints " + entState.hitpoints + " / " + entState.maxHitpoints;
getGUIObjectByName("selectionDetailsHealth").hidden = false;
}
else
{
getGUIObjectByName("selectionDetailsHealth").hidden = true;
getGUIObjectByName("selectionDetailsHealth").tooltip = "";
}
// Is unit Elite?
var eliteStatus = isUnitElite(entState.template);
// Specific Name
getGUIObjectByName("selectionDetailsSpecific").caption = (eliteStatus? "Elite " + template.name.specific : template.name.specific );
// Generic Name
if (template.name.generic == template.name.specific)
{
getGUIObjectByName("selectionDetailsGeneric").hidden = true;
getGUIObjectByName("selectionDetailsSpecific").tooltip = "";
//iconTooltip += template.name.specific;
}
else
{
getGUIObjectByName("selectionDetailsSpecific").tooltip = template.name.generic;
//iconTooltip += template.name.specific + " (" + template.name.generic + ")";
}
// Player Name
getGUIObjectByName("selectionDetailsPlayer").caption = "Player " + entState.player; // TODO: get player name
// Icon
iconTooltip += (eliteStatus? "[font=\"serif-bold-16\"]Elite [/font]" : "");
iconTooltip += createIconTooltip(entState, template);
getGUIObjectByName("selectionDetailsIconImage").tooltip = iconTooltip;
getGUIObjectByName("selectionDetailsIconImage").sprite = "snPortraitSheetHele";
getGUIObjectByName("selectionDetailsIconImage").cell_id = template.icon_cell;
// Attack and Armour Stats
getGUIObjectByName("selectionDetailsAttackStats").caption = damageTypesToTextStacked(entState.attack);
getGUIObjectByName("selectionDetailsArmourStats").caption = damageTypesToTextStacked(entState.armour);
// Different selection details are shown based on whether multiple units or a single unit is selected
if (selection.length > 1)
@ -527,9 +562,19 @@ function updateUnitDisplay()
else
selectionLayoutSingle();
// Fill out general info and display it
displayGeneralInfo(entState, template); // must come after layout functions
// Show Panels
detailsPanel.hidden = false;
detailsPanel.hidden = false;
// Fill out commands panel for specific unit selected (or first unit of primary group)
updateUnitCommands(commandsPanel, selection, entState);
}
// Updates right Unit Commands Panel - runs in the main session loop via updateSelectionDetails()
function updateUnitCommands(commandsPanel, selection, entState)
{
// Panels that are active
var usedPanels = {};
@ -565,7 +610,7 @@ function updateUnitDisplay()
// Stamina
// if (entState.stamina != undefined)
getGUIObjectByName("selectionDetailsStamina").hidden = false;
getGUIObjectByName("selectionDetailsStamina").hidden = false;
// else
// getGUIObjectByName("selectionDetailsStamina").hidden = true;
@ -598,3 +643,4 @@ function updateUnitDisplay()
}
}
}

View File

@ -245,8 +245,6 @@
<!-- Player resource bar -->
<object
size="188 100%-130 100% 100%-2"
type="image"
sprite="bronzeResourceRectangles"
>
<!-- Food -->
<object size="0 0 100% 26" type="image" style="resourceCounter" tooltip="Food" >
@ -357,6 +355,12 @@
<object size="-4 -4 36 36" type="image" name="selectionDetailsArmourImage" ghost="true" sprite="snIconSheetStance" cell_id="3"/>
<object size="30 0 100% 100%" type="text" name="selectionDetailsArmourStats" ghost="true" font="serif-bold-12"/>
</object>
<!-- Resource Quantity -->
<object hidden="true" size="152 80 100% 100" type="image" name="selectionDetailsResources" tooltip="Resources" tooltip_style="snToolTip">
<object size="0 0 28 24" name="selectionDetailsResourceIcon" type="image" style="resourceIcon" cell_id="0"/>
<object size="28 0 100% 100%" name="selectionDetailsResourceStats" ghost="true" type="text" font="serif-bold-14"/>
</object>
</object>
<!-- ================================ ================================ -->

View File

@ -28,7 +28,6 @@
/>
<style name="resourceText"
textcolor="white"
font="serif-bold-14"
ghost="true"
text_valign="center"