From 6d625fdc55041437cb97d4e11a07520535ef5cb1 Mon Sep 17 00:00:00 2001 From: WhiteTreePaladin Date: Thu, 1 Jul 2010 20:06:23 +0000 Subject: [PATCH] Added resource quantities to GUI for resource entities Some code cleanup This was SVN commit r7657. --- .../mods/public/gui/session_new/session.js | 188 +++++++++++------- .../mods/public/gui/session_new/session.xml | 8 +- .../mods/public/gui/session_new/styles.xml | 1 - 3 files changed, 123 insertions(+), 74 deletions(-) diff --git a/binaries/data/mods/public/gui/session_new/session.js b/binaries/data/mods/public/gui/session_new/session.js index 2776f19af3..0e9a5e4d40 100644 --- a/binaries/data/mods/public/gui/session_new/session.js +++ b/binaries/data/mods/public/gui/session_new/session.js @@ -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() } } } + diff --git a/binaries/data/mods/public/gui/session_new/session.xml b/binaries/data/mods/public/gui/session_new/session.xml index 59b3510019..20f1967a1c 100644 --- a/binaries/data/mods/public/gui/session_new/session.xml +++ b/binaries/data/mods/public/gui/session_new/session.xml @@ -245,8 +245,6 @@ @@ -357,6 +355,12 @@ + + +