mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-07-25 02:32:57 +00:00
Moved menu code out into:
menu.js Moved selection details and unit commands code out into: selection_details.js unit_commands.js Deleted some unused sprites This was SVN commit r7659.
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
function toggleDeveloperOverlay()
|
||||
{
|
||||
if (getGUIObjectByName("devCommands").hidden)
|
||||
getGUIObjectByName("devCommands").hidden = false; // show overlay
|
||||
else
|
||||
getGUIObjectByName("devCommands").hidden = true; // hide overlay
|
||||
}
|
||||
|
||||
function toggleSettingsWindow()
|
||||
{
|
||||
if (getGUIObjectByName("settingsWindow").hidden)
|
||||
{
|
||||
getGUIObjectByName("settingsWindow").hidden = false; // show settings
|
||||
setPaused(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
getGUIObjectByName("settingsWindow").hidden = true; // hide settings
|
||||
setPaused(false);
|
||||
}
|
||||
|
||||
getGUIObjectByName("menu").hidden = true; // Hide menu
|
||||
}
|
||||
|
||||
function togglePause()
|
||||
{
|
||||
if (getGUIObjectByName("pauseOverlay").hidden)
|
||||
{
|
||||
getGUIObjectByName("pauseOverlay").hidden = false; // pause game
|
||||
setPaused(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
getGUIObjectByName("pauseOverlay").hidden = true; // unpause game
|
||||
setPaused(false);
|
||||
}
|
||||
|
||||
getGUIObjectByName("menu").hidden = true; // Hide menu
|
||||
}
|
||||
|
||||
function toggleMenu()
|
||||
{
|
||||
if (getGUIObjectByName("menu").hidden)
|
||||
getGUIObjectByName("menu").hidden = false; // View menu
|
||||
else
|
||||
getGUIObjectByName("menu").hidden = true; // Hide menu
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
const resourceIconCellIds = {food : 0, wood : 1, stone : 2, metal : 3};
|
||||
|
||||
// Multiple Selection Layout
|
||||
function selectionLayoutMultiple()
|
||||
{
|
||||
getGUIObjectByName("selectionDetailsMainText").size = "80 100%-70 100%-14 100%-10";
|
||||
getGUIObjectByName("selectionDetailsSpecific").size = "0 6 100% 30";
|
||||
getGUIObjectByName("selectionDetailsPlayer").size = "0 34 100% 100%-8";
|
||||
|
||||
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("selectionDetailsMainText").sprite = "goldPanel";
|
||||
getGUIObjectByName("selectionDetailsSpecific").sprite = "";
|
||||
}
|
||||
|
||||
// Single Selection Layout
|
||||
function selectionLayoutSingle()
|
||||
{
|
||||
getGUIObjectByName("selectionDetailsMainText").size = "6 0 100%-6 50";
|
||||
getGUIObjectByName("selectionDetailsSpecific").size = "0 0 100% 30";
|
||||
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 64 100% 100%-30";
|
||||
getGUIObjectByName("selectionDetailsArmour").size = "204 64 100% 100%-30";
|
||||
|
||||
getGUIObjectByName("selectionDetailsAttack").hidden = false;
|
||||
getGUIObjectByName("selectionDetailsArmour").hidden = false;
|
||||
|
||||
getGUIObjectByName("selectionDetailsMainText").sprite = "";
|
||||
getGUIObjectByName("selectionDetailsSpecific").sprite = "wheatWindowTitle";
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
// Updates middle entity Selection Details Panel
|
||||
function updateSelectionDetails()
|
||||
{
|
||||
var detailsPanel = getGUIObjectByName("selectionDetails");
|
||||
var commandsPanel = getGUIObjectByName("unitCommands");
|
||||
|
||||
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[g_Selection.getPrimary()]);
|
||||
if (!entState)
|
||||
{
|
||||
detailsPanel.hidden = true;
|
||||
commandsPanel.hidden = true;
|
||||
return;
|
||||
}
|
||||
|
||||
var template = Engine.GuiInterfaceCall("GetTemplateData", entState.template);
|
||||
|
||||
// Different selection details are shown based on whether multiple units or a single unit is selected
|
||||
if (selection.length > 1)
|
||||
selectionLayoutMultiple();
|
||||
else
|
||||
selectionLayoutSingle();
|
||||
|
||||
// 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(commandsPanel, selection, entState);
|
||||
}
|
||||
@@ -175,472 +175,3 @@ function getFullName(template)
|
||||
|
||||
return "[font=\"serif-bold-16\"]" + name + "[/font]";
|
||||
}
|
||||
|
||||
function createIconTooltip(entState, template)
|
||||
{
|
||||
var tooltip = "";
|
||||
tooltip = getFullName(template);
|
||||
|
||||
var hitpointsLabel = "[font=\"serif-bold-13\"]Hitpoints: [/font]";
|
||||
tooltip += "\n" + hitpointsLabel + entState.hitpoints + "/" + entState.maxHitpoints;
|
||||
|
||||
var attackLabel = "[font=\"serif-bold-13\"]Attack: [/font]";
|
||||
var armourLabel = "[font=\"serif-bold-13\"]Armour: [/font]";
|
||||
tooltip += "\n" + attackLabel + damageTypesToText(entState.attack) + "\n" + armourLabel + damageTypesToText(entState.armour);
|
||||
|
||||
return tooltip;
|
||||
}
|
||||
|
||||
//-------------------------------- -------------------------------- --------------------------------
|
||||
// Menu Functions
|
||||
//-------------------------------- -------------------------------- --------------------------------
|
||||
|
||||
function toggleDeveloperOverlay()
|
||||
{
|
||||
if (getGUIObjectByName("devCommands").hidden)
|
||||
getGUIObjectByName("devCommands").hidden = false; // show overlay
|
||||
else
|
||||
getGUIObjectByName("devCommands").hidden = true; // hide overlay
|
||||
}
|
||||
|
||||
function toggleSettingsWindow()
|
||||
{
|
||||
if (getGUIObjectByName("settingsWindow").hidden)
|
||||
{
|
||||
getGUIObjectByName("settingsWindow").hidden = false; // show settings
|
||||
setPaused(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
getGUIObjectByName("settingsWindow").hidden = true; // hide settings
|
||||
setPaused(false);
|
||||
}
|
||||
|
||||
getGUIObjectByName("menu").hidden = true; // Hide menu
|
||||
}
|
||||
|
||||
function togglePause()
|
||||
{
|
||||
if (getGUIObjectByName("pauseOverlay").hidden)
|
||||
{
|
||||
getGUIObjectByName("pauseOverlay").hidden = false; // pause game
|
||||
setPaused(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
getGUIObjectByName("pauseOverlay").hidden = true; // unpause game
|
||||
setPaused(false);
|
||||
}
|
||||
|
||||
getGUIObjectByName("menu").hidden = true; // Hide menu
|
||||
}
|
||||
|
||||
function toggleMenu()
|
||||
{
|
||||
if (getGUIObjectByName("menu").hidden)
|
||||
getGUIObjectByName("menu").hidden = false; // View menu
|
||||
else
|
||||
getGUIObjectByName("menu").hidden = true; // Hide menu
|
||||
}
|
||||
|
||||
//-------------------------------- -------------------------------- --------------------------------
|
||||
// View / Hide Details Panel and Commands Panel information
|
||||
//-------------------------------- -------------------------------- --------------------------------
|
||||
|
||||
// Hides Details Panel's Information
|
||||
function hideSelectionDetails(booleanValue)
|
||||
{
|
||||
getGUIObjectByName("selectionDetailsIcon").hidden = booleanValue;
|
||||
getGUIObjectByName("selectionDetailsHealth").hidden = booleanValue;
|
||||
getGUIObjectByName("selectionDetailsStamina").hidden = booleanValue;
|
||||
getGUIObjectByName("selectionDetailsMainText").hidden = booleanValue;
|
||||
getGUIObjectByName("selectionDetailsAttack").hidden = booleanValue;
|
||||
getGUIObjectByName("selectionDetailsArmour").hidden = booleanValue;
|
||||
getGUIObjectByName("unitSelectionPanel").hidden = booleanValue;
|
||||
getGUIObjectByName("selectionProductLogo").hidden = !booleanValue; // gets opposite of booleanValue
|
||||
}
|
||||
|
||||
// Hides Commands Panel's Information
|
||||
function hideCommands(booleanValue)
|
||||
{
|
||||
getGUIObjectByName("unitConstructionPanel").hidden = booleanValue;
|
||||
getGUIObjectByName("unitStancePanel").hidden = booleanValue;
|
||||
getGUIObjectByName("unitFormationPanel").hidden = booleanValue;
|
||||
getGUIObjectByName("unitResearchPanel").hidden = booleanValue;
|
||||
getGUIObjectByName("unitTrainingPanel").hidden = booleanValue;
|
||||
getGUIObjectByName("unitQueuePanel").hidden = booleanValue;
|
||||
}
|
||||
|
||||
//-------------------------------- -------------------------------- --------------------------------
|
||||
// Details Panel layout
|
||||
//-------------------------------- -------------------------------- --------------------------------
|
||||
|
||||
const resourceIconCellIds = {food : 0, wood : 1, stone : 2, metal : 3};
|
||||
|
||||
// Multiple Selection Layout
|
||||
function selectionLayoutMultiple()
|
||||
{
|
||||
getGUIObjectByName("selectionDetailsMainText").size = "80 100%-70 100%-14 100%-10";
|
||||
getGUIObjectByName("selectionDetailsSpecific").size = "0 6 100% 30";
|
||||
getGUIObjectByName("selectionDetailsPlayer").size = "0 34 100% 100%-8";
|
||||
|
||||
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("selectionDetailsMainText").sprite = "goldPanel";
|
||||
getGUIObjectByName("selectionDetailsSpecific").sprite = "";
|
||||
}
|
||||
|
||||
// Single Selection Layout
|
||||
function selectionLayoutSingle()
|
||||
{
|
||||
getGUIObjectByName("selectionDetailsMainText").size = "6 0 100%-6 50";
|
||||
getGUIObjectByName("selectionDetailsSpecific").size = "0 0 100% 30";
|
||||
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 64 100% 100%-30";
|
||||
getGUIObjectByName("selectionDetailsArmour").size = "204 64 100% 100%-30";
|
||||
|
||||
getGUIObjectByName("selectionDetailsAttack").hidden = false;
|
||||
getGUIObjectByName("selectionDetailsArmour").hidden = false;
|
||||
|
||||
getGUIObjectByName("selectionDetailsMainText").sprite = "";
|
||||
getGUIObjectByName("selectionDetailsSpecific").sprite = "wheatWindowTitle";
|
||||
}
|
||||
|
||||
// The number of currently visible buttons (used to optimise showing/hiding)
|
||||
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;
|
||||
var i = 0;
|
||||
|
||||
for each (var item in items)
|
||||
{
|
||||
if (i > 15) // End loop early if more than 16 buttons
|
||||
break;
|
||||
|
||||
// Get templates
|
||||
var entType;
|
||||
if (guiName == "Queue")
|
||||
entType = item.template;
|
||||
else
|
||||
entType = item;
|
||||
|
||||
var template = Engine.GuiInterfaceCall("GetTemplateData", entType);
|
||||
if (!template)
|
||||
continue; // ignore attempts to use invalid templates (an error should have been reported already)
|
||||
|
||||
// Name
|
||||
var name;
|
||||
if (guiName == "Selection")
|
||||
name = template.name.specific || template.name.generic || "???";
|
||||
else
|
||||
name = getFullName(template);
|
||||
|
||||
// Tooltip
|
||||
var tooltip = (isUnitElite(entType)? "Elite " + name : name ); // "Elite " is not formatted in bold, so may need custom versions of this later
|
||||
|
||||
if (guiName == "Selection")
|
||||
{
|
||||
getGUIObjectByName("unit"+guiName+"Count["+i+"]").caption =
|
||||
(g_Selection.groups.groupTypeCount[item] > 1 ? g_Selection.groups.groupTypeCount[item] : "");
|
||||
|
||||
tooltip += (g_Selection.groups.groupTypeCount[item] > 1 ? " (" + g_Selection.groups.groupTypeCount[item] + ")" : "")
|
||||
}
|
||||
else if (guiName == "Queue")
|
||||
{
|
||||
var progress = Math.round(item.progress*100) + "%";
|
||||
tooltip += " - " + progress;
|
||||
getGUIObjectByName("unit"+guiName+"Count["+i+"]").caption = (item.count > 1 ? item.count : "");
|
||||
getGUIObjectByName("unit"+guiName+"Progress["+i+"]").caption = (item.progress ? progress : "");
|
||||
}
|
||||
else if (guiName == "Construction" || guiName == "Training")
|
||||
{
|
||||
if (template.cost)
|
||||
{
|
||||
var costs = [];
|
||||
if (template.cost.food) costs.push("[font=\"serif-bold-13\"]Food:[/font] " + template.cost.food);
|
||||
if (template.cost.wood) costs.push("[font=\"serif-bold-13\"]Wood:[/font] " + template.cost.wood);
|
||||
if (template.cost.metal) costs.push("[font=\"serif-bold-13\"]Metal:[/font] " + template.cost.metal);
|
||||
if (template.cost.stone) costs.push("[font=\"serif-bold-13\"]Stone:[/font] " + template.cost.stone);
|
||||
if (costs.length)
|
||||
tooltip += "\n" + costs.join(", ");
|
||||
}
|
||||
|
||||
if (guiName == "Training")
|
||||
{
|
||||
var [batchSize, batchIncrement] = getTrainingQueueBatchStatus(unitEntState.id, entType);
|
||||
tooltip += "\n[font=\"serif-13\"]";
|
||||
if (batchSize) tooltip += "Training [font=\"serif-bold-13\"]" + batchSize + "[font=\"serif-13\"] units; ";
|
||||
tooltip += "Shift-click to train [font=\"serif-bold-13\"]"+ (batchSize+batchIncrement) + "[font=\"serif-13\"] units[/font]";
|
||||
}
|
||||
}
|
||||
|
||||
// Button
|
||||
var button = getGUIObjectByName("unit"+guiName+"Button["+i+"]");
|
||||
var icon = getGUIObjectByName("unit"+guiName+"Icon["+i+"]");
|
||||
button.hidden = false;
|
||||
button.tooltip = tooltip;
|
||||
|
||||
if (callback != null)
|
||||
button.onpress = (function(e) { return function() { callback(e) } })(item); // (need nested functions to get the closure right)
|
||||
|
||||
icon.sprite = "snPortraitSheetHele"; // TODO
|
||||
if (typeof template.icon_cell == "undefined")
|
||||
icon.cell_id = 0;
|
||||
else
|
||||
icon.cell_id = template.icon_cell;
|
||||
|
||||
++i;
|
||||
}
|
||||
|
||||
// Position the visible buttons (TODO: if there's lots, maybe they should be squeezed together to fit)
|
||||
var buttonSideLength = getGUIObjectByName("unit"+guiName+"Button[0]").size.bottom;
|
||||
var buttonSpacer = ((guiName == "Selection")? 37 : 45);
|
||||
var numButtons = i;
|
||||
var j = 0; // index for second row of buttons
|
||||
|
||||
for (i = 0; i < numButtons; ++i)
|
||||
{
|
||||
var button = getGUIObjectByName("unit"+guiName+"Button["+i+"]");
|
||||
var size = button.size;
|
||||
|
||||
if (i > 7) // Make second row
|
||||
{
|
||||
if (guiName == "Queue")
|
||||
getGUIObjectByName("unit"+guiName+"Panel").size = "0 -104 100% 100%-166"
|
||||
|
||||
size.left = buttonSpacer*j;
|
||||
size.right = buttonSpacer*j + buttonSideLength;
|
||||
size.top = buttonSpacer;
|
||||
size.bottom = buttonSpacer + buttonSideLength;
|
||||
j++;
|
||||
}
|
||||
else // Make first row
|
||||
{
|
||||
if ((guiName == "Queue"))
|
||||
getGUIObjectByName("unit"+guiName+"Panel").size = "0 -60 100% 100%-166"
|
||||
|
||||
size.left = buttonSpacer*i;
|
||||
size.right = buttonSpacer*i + size.bottom;
|
||||
}
|
||||
|
||||
button.size = size;
|
||||
}
|
||||
|
||||
// Hide any buttons we're no longer using
|
||||
for (i = numButtons; i < g_unitPanelButtons[guiName]; ++i)
|
||||
getGUIObjectByName("unit"+guiName+"Button["+i+"]").hidden = true;
|
||||
|
||||
g_unitPanelButtons[guiName] = numButtons;
|
||||
}
|
||||
|
||||
// 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)
|
||||
{
|
||||
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)
|
||||
{
|
||||
detailsPanel.hidden = true;
|
||||
commandsPanel.hidden = true;
|
||||
return;
|
||||
}
|
||||
|
||||
var template = Engine.GuiInterfaceCall("GetTemplateData", entState.template);
|
||||
|
||||
// Different selection details are shown based on whether multiple units or a single unit is selected
|
||||
if (selection.length > 1)
|
||||
selectionLayoutMultiple();
|
||||
else
|
||||
selectionLayoutSingle();
|
||||
|
||||
// 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(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 = {};
|
||||
|
||||
// If the selection is friendly units, add the command panels
|
||||
var player = Engine.GetPlayerID();
|
||||
if (entState.player == player || g_DevSettings.controlAll)
|
||||
{
|
||||
if (entState.attack) // TODO - this should be based on some AI properties
|
||||
{
|
||||
//usedPanels["Stance"] = 1;
|
||||
//usedPanels["Formation"] = 1;
|
||||
// (These are disabled since they're not implemented yet)
|
||||
}
|
||||
else // TODO - this should be based on various other things
|
||||
{
|
||||
//usedPanels["Research"] = 1;
|
||||
}
|
||||
|
||||
if (entState.buildEntities && entState.buildEntities.length)
|
||||
setupUnitPanel("Construction", usedPanels, entState, entState.buildEntities, startBuildingPlacement);
|
||||
|
||||
if (entState.training && entState.training.entities.length)
|
||||
setupUnitPanel("Training", usedPanels, entState, entState.training.entities,
|
||||
function (trainEntType) { addToTrainingQueue(entState.id, trainEntType); } );
|
||||
|
||||
if (entState.training && entState.training.queue.length)
|
||||
setupUnitPanel("Queue", usedPanels, entState, entState.training.queue,
|
||||
function (item) { removeFromTrainingQueue(entState.id, item.id); } );
|
||||
|
||||
if (selection.length > 1)
|
||||
setupUnitPanel("Selection", usedPanels, entState, g_Selection.groups.groupTemplates,
|
||||
function (entType) { changePrimarySelectionGroup(entType); } );
|
||||
|
||||
// Stamina
|
||||
// if (entState.stamina != undefined)
|
||||
getGUIObjectByName("selectionDetailsStamina").hidden = false;
|
||||
// else
|
||||
// getGUIObjectByName("selectionDetailsStamina").hidden = true;
|
||||
|
||||
commandsPanel.hidden = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
getGUIObjectByName("selectionDetailsStamina").hidden = true;
|
||||
commandsPanel.hidden = true;
|
||||
}
|
||||
|
||||
// Hides / unhides Unit Panels (panels should be grouped by type, not by order, but we will leave that for another time)
|
||||
var offset = 0;
|
||||
for each (var panelName in g_unitPanels)
|
||||
{
|
||||
var panel = getGUIObjectByName("unit" + panelName + "Panel");
|
||||
if (usedPanels[panelName])
|
||||
{
|
||||
// var size = panel.size;
|
||||
// var h = size.bottom - size.top;
|
||||
// size.bottom = offset;
|
||||
// size.top = offset - h;
|
||||
// panel.size = size;
|
||||
panel.hidden = false;
|
||||
// offset -= (h + 6); // changed 12 point spacing to 6 point: offset -= (h + 12);
|
||||
}
|
||||
else
|
||||
{
|
||||
panel.hidden = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
<script file="gui/session_new/selection.js"/>
|
||||
<script file="gui/session_new/input.js"/>
|
||||
<script file="gui/session_new/music.js"/>
|
||||
<script file="gui/session_new/menu.js"/>
|
||||
<script file="gui/session_new/selection_details.js"/>
|
||||
<script file="gui/session_new/unit_commands.js"/>
|
||||
|
||||
<object name="sn" hotkey="session.gui.toggle">
|
||||
<action on="Tick">
|
||||
@@ -82,17 +85,6 @@
|
||||
<object size="100%-16 64 100% 80" type="checkbox" style="wheatCrossBox">
|
||||
<action on="Press">g_Selection.SetMotionDebugOverlay(this.checked);</action>
|
||||
</object>
|
||||
<!--
|
||||
<object size="0 80 100%-18 96" type="text" style="devCommandsText">Toggle music</object>
|
||||
<object size="100%-16 80 100% 96" type="checkbox" style="wheatCrossBox" checked="true" hotkey="music.toggle">
|
||||
<action on="Press">if (this.checked) startMusic(); else stopMusic();</action>
|
||||
</object>
|
||||
|
||||
<object size="0 96 100%-18 112" type="text" style="devCommandsText">Pause game</object>
|
||||
<object size="100%-16 96 100% 112" type="checkbox" style="wheatCrossBox" hotkey="pause">
|
||||
<action on="Press">setPaused(this.checked);</action>
|
||||
</object>
|
||||
-->
|
||||
</object>
|
||||
|
||||
<!-- ================================ ================================ -->
|
||||
@@ -288,22 +280,6 @@
|
||||
hidden="true"
|
||||
z="20"
|
||||
>
|
||||
|
||||
<!-- OAD logo background
|
||||
<object name="selectionProductLogo"
|
||||
size="65 45 100%-65 100%-55"
|
||||
type="image"
|
||||
style="frilly"
|
||||
hidden="true"
|
||||
>
|
||||
<object name="selectionProductLogoImage"
|
||||
type="image"
|
||||
size="-4 -16 100%+24 100%+22"
|
||||
sprite="watermarkProduct"
|
||||
/>
|
||||
</object>
|
||||
-->
|
||||
|
||||
<!-- Unit Selection Area -->
|
||||
<object name="unitSelectionPanel"
|
||||
size="10 4 278 64"
|
||||
@@ -467,9 +443,11 @@
|
||||
<!-- ================================ ================================ -->
|
||||
<!-- Selection bandbox -->
|
||||
<!-- ================================ ================================ -->
|
||||
<object name="bandbox" type="image" sprite="bandbox" ghost="true" hidden="true" z="100"
|
||||
/>
|
||||
<object name="bandbox" type="image" sprite="bandbox" ghost="true" hidden="true" z="100"/>
|
||||
|
||||
<!-- ================================ ================================ -->
|
||||
<!-- Network status -->
|
||||
<!-- ================================ ================================ -->
|
||||
<object name="netStatus" type="text" style="netStatus" z="100" hidden="true"/>
|
||||
|
||||
</objects>
|
||||
|
||||
@@ -80,16 +80,7 @@
|
||||
size="100% 50%-16 100%+48 50%+16"
|
||||
/>
|
||||
</sprite>
|
||||
|
||||
<sprite name="bronzeResourceRectangles">
|
||||
<!-- (currently this is all a hack - need proper textures) -->
|
||||
<image
|
||||
texture="global/border/corner_bronze.dds"
|
||||
texture_size="0 0 60 26"
|
||||
size="28 0 100% 100%"
|
||||
/>
|
||||
</sprite>
|
||||
|
||||
|
||||
<sprite name="bronzeCommandsSquares">
|
||||
<!-- (currently this is all a hack - need proper textures) -->
|
||||
<image
|
||||
|
||||
@@ -0,0 +1,204 @@
|
||||
// The number of currently visible buttons (used to optimise showing/hiding)
|
||||
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;
|
||||
var i = 0;
|
||||
|
||||
for each (var item in items)
|
||||
{
|
||||
if (i > 15) // End loop early if more than 16 buttons
|
||||
break;
|
||||
|
||||
// Get templates
|
||||
var entType;
|
||||
if (guiName == "Queue")
|
||||
entType = item.template;
|
||||
else
|
||||
entType = item;
|
||||
|
||||
var template = Engine.GuiInterfaceCall("GetTemplateData", entType);
|
||||
if (!template)
|
||||
continue; // ignore attempts to use invalid templates (an error should have been reported already)
|
||||
|
||||
// Name
|
||||
var name;
|
||||
if (guiName == "Selection")
|
||||
name = template.name.specific || template.name.generic || "???";
|
||||
else
|
||||
name = getFullName(template);
|
||||
|
||||
// Tooltip
|
||||
var tooltip = (isUnitElite(entType)? "Elite " + name : name ); // "Elite " is not formatted in bold, so may need custom versions of this later
|
||||
|
||||
if (guiName == "Selection")
|
||||
{
|
||||
getGUIObjectByName("unit"+guiName+"Count["+i+"]").caption =
|
||||
(g_Selection.groups.groupTypeCount[item] > 1 ? g_Selection.groups.groupTypeCount[item] : "");
|
||||
|
||||
tooltip += (g_Selection.groups.groupTypeCount[item] > 1 ? " (" + g_Selection.groups.groupTypeCount[item] + ")" : "")
|
||||
}
|
||||
else if (guiName == "Queue")
|
||||
{
|
||||
var progress = Math.round(item.progress*100) + "%";
|
||||
tooltip += " - " + progress;
|
||||
getGUIObjectByName("unit"+guiName+"Count["+i+"]").caption = (item.count > 1 ? item.count : "");
|
||||
getGUIObjectByName("unit"+guiName+"Progress["+i+"]").caption = (item.progress ? progress : "");
|
||||
}
|
||||
else if (guiName == "Construction" || guiName == "Training")
|
||||
{
|
||||
if (template.cost)
|
||||
{
|
||||
var costs = [];
|
||||
if (template.cost.food) costs.push("[font=\"serif-bold-13\"]Food:[/font] " + template.cost.food);
|
||||
if (template.cost.wood) costs.push("[font=\"serif-bold-13\"]Wood:[/font] " + template.cost.wood);
|
||||
if (template.cost.metal) costs.push("[font=\"serif-bold-13\"]Metal:[/font] " + template.cost.metal);
|
||||
if (template.cost.stone) costs.push("[font=\"serif-bold-13\"]Stone:[/font] " + template.cost.stone);
|
||||
if (costs.length)
|
||||
tooltip += "\n" + costs.join(", ");
|
||||
}
|
||||
|
||||
if (guiName == "Training")
|
||||
{
|
||||
var [batchSize, batchIncrement] = getTrainingQueueBatchStatus(unitEntState.id, entType);
|
||||
tooltip += "\n[font=\"serif-13\"]";
|
||||
if (batchSize) tooltip += "Training [font=\"serif-bold-13\"]" + batchSize + "[font=\"serif-13\"] units; ";
|
||||
tooltip += "Shift-click to train [font=\"serif-bold-13\"]"+ (batchSize+batchIncrement) + "[font=\"serif-13\"] units[/font]";
|
||||
}
|
||||
}
|
||||
|
||||
// Button
|
||||
var button = getGUIObjectByName("unit"+guiName+"Button["+i+"]");
|
||||
var icon = getGUIObjectByName("unit"+guiName+"Icon["+i+"]");
|
||||
button.hidden = false;
|
||||
button.tooltip = tooltip;
|
||||
|
||||
if (callback != null)
|
||||
button.onpress = (function(e) { return function() { callback(e) } })(item); // (need nested functions to get the closure right)
|
||||
|
||||
icon.sprite = "snPortraitSheetHele"; // TODO
|
||||
if (typeof template.icon_cell == "undefined")
|
||||
icon.cell_id = 0;
|
||||
else
|
||||
icon.cell_id = template.icon_cell;
|
||||
|
||||
++i;
|
||||
}
|
||||
|
||||
// Position the visible buttons (TODO: if there's lots, maybe they should be squeezed together to fit)
|
||||
var buttonSideLength = getGUIObjectByName("unit"+guiName+"Button[0]").size.bottom;
|
||||
var buttonSpacer = ((guiName == "Selection")? 37 : 45);
|
||||
var numButtons = i;
|
||||
var j = 0; // index for second row of buttons
|
||||
|
||||
for (i = 0; i < numButtons; ++i)
|
||||
{
|
||||
var button = getGUIObjectByName("unit"+guiName+"Button["+i+"]");
|
||||
var size = button.size;
|
||||
|
||||
if (i > 7) // Make second row
|
||||
{
|
||||
if (guiName == "Queue")
|
||||
getGUIObjectByName("unit"+guiName+"Panel").size = "0 -104 100% 100%-166"
|
||||
|
||||
size.left = buttonSpacer*j;
|
||||
size.right = buttonSpacer*j + buttonSideLength;
|
||||
size.top = buttonSpacer;
|
||||
size.bottom = buttonSpacer + buttonSideLength;
|
||||
j++;
|
||||
}
|
||||
else // Make first row
|
||||
{
|
||||
if ((guiName == "Queue"))
|
||||
getGUIObjectByName("unit"+guiName+"Panel").size = "0 -60 100% 100%-166"
|
||||
|
||||
size.left = buttonSpacer*i;
|
||||
size.right = buttonSpacer*i + size.bottom;
|
||||
}
|
||||
|
||||
button.size = size;
|
||||
}
|
||||
|
||||
// Hide any buttons we're no longer using
|
||||
for (i = numButtons; i < g_unitPanelButtons[guiName]; ++i)
|
||||
getGUIObjectByName("unit"+guiName+"Button["+i+"]").hidden = true;
|
||||
|
||||
g_unitPanelButtons[guiName] = numButtons;
|
||||
}
|
||||
|
||||
// Updates right Unit Commands Panel - runs in the main session loop via updateSelectionDetails()
|
||||
function updateUnitCommands(commandsPanel, selection, entState)
|
||||
{
|
||||
// Panels that are active
|
||||
var usedPanels = {};
|
||||
|
||||
// If the selection is friendly units, add the command panels
|
||||
var player = Engine.GetPlayerID();
|
||||
if (entState.player == player || g_DevSettings.controlAll)
|
||||
{
|
||||
if (entState.attack) // TODO - this should be based on some AI properties
|
||||
{
|
||||
//usedPanels["Stance"] = 1;
|
||||
//usedPanels["Formation"] = 1;
|
||||
// (These are disabled since they're not implemented yet)
|
||||
}
|
||||
else // TODO - this should be based on various other things
|
||||
{
|
||||
//usedPanels["Research"] = 1;
|
||||
}
|
||||
|
||||
if (entState.buildEntities && entState.buildEntities.length)
|
||||
setupUnitPanel("Construction", usedPanels, entState, entState.buildEntities, startBuildingPlacement);
|
||||
|
||||
if (entState.training && entState.training.entities.length)
|
||||
setupUnitPanel("Training", usedPanels, entState, entState.training.entities,
|
||||
function (trainEntType) { addToTrainingQueue(entState.id, trainEntType); } );
|
||||
|
||||
if (entState.training && entState.training.queue.length)
|
||||
setupUnitPanel("Queue", usedPanels, entState, entState.training.queue,
|
||||
function (item) { removeFromTrainingQueue(entState.id, item.id); } );
|
||||
|
||||
if (selection.length > 1)
|
||||
setupUnitPanel("Selection", usedPanels, entState, g_Selection.groups.groupTemplates,
|
||||
function (entType) { changePrimarySelectionGroup(entType); } );
|
||||
|
||||
// Stamina
|
||||
// if (entState.stamina != undefined)
|
||||
getGUIObjectByName("selectionDetailsStamina").hidden = false;
|
||||
// else
|
||||
// getGUIObjectByName("selectionDetailsStamina").hidden = true;
|
||||
|
||||
commandsPanel.hidden = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
getGUIObjectByName("selectionDetailsStamina").hidden = true;
|
||||
commandsPanel.hidden = true;
|
||||
}
|
||||
|
||||
// Hides / unhides Unit Panels (panels should be grouped by type, not by order, but we will leave that for another time)
|
||||
var offset = 0;
|
||||
for each (var panelName in g_unitPanels)
|
||||
{
|
||||
var panel = getGUIObjectByName("unit" + panelName + "Panel");
|
||||
if (usedPanels[panelName])
|
||||
{
|
||||
// var size = panel.size;
|
||||
// var h = size.bottom - size.top;
|
||||
// size.bottom = offset;
|
||||
// size.top = offset - h;
|
||||
// panel.size = size;
|
||||
panel.hidden = false;
|
||||
// offset -= (h + 6); // changed 12 point spacing to 6 point: offset -= (h + 12);
|
||||
}
|
||||
else
|
||||
{
|
||||
panel.hidden = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user