1
0
forked from 0ad/0ad

Fixed a GUI selection display bug where the final element of a large selection was wrapping around and replacing the first selection group.

Added and removed some utility functions in session.js

This was SVN commit r7701.
This commit is contained in:
WhiteTreePaladin 2010-07-05 23:04:38 +00:00
parent 76a099f626
commit 5be1052ad0
4 changed files with 44 additions and 89 deletions

View File

@ -3,14 +3,6 @@ const resourceIconCellIds = {food : 0, wood : 1, stone : 2, metal : 3};
// Multiple Selection Layout // Multiple Selection Layout
function selectionLayoutMultiple() function selectionLayoutMultiple()
{ {
/*
getGUIObjectByName("sdMainText").size = "80 100%-70 100%-14 100%-32";
getGUIObjectByName("sdRankIcon").size = "0 -14 32 18";
getGUIObjectByName("sdSpecific").size = "0 -14 100% 16";
getGUIObjectByName("sdPlayer").size = "0 16 100% 100%";
*/
getGUIObjectByName("sdMainText").size = "80 100%-70 100%-14 100%-10"; getGUIObjectByName("sdMainText").size = "80 100%-70 100%-14 100%-10";
getGUIObjectByName("sdSpecific").size = "0 6 100% 30"; getGUIObjectByName("sdSpecific").size = "0 6 100% 30";
getGUIObjectByName("sdPlayer").size = "0 34 100% 100%-8"; getGUIObjectByName("sdPlayer").size = "0 34 100% 100%-8";
@ -56,9 +48,6 @@ function displayGeneralInfo(playerState, entState, template)
var playerColor = color["r"]*255 + " " + color["g"]*255 + " " + color["b"]*255 + " " + color["a"]*255; var playerColor = color["r"]*255 + " " + color["g"]*255 + " " + color["b"]*255 + " " + color["a"]*255;
var iconTooltip = ""; var iconTooltip = "";
// Is unit Elite?
// var eliteStatus = isUnitElite(entState.template);
// Rank Icon // Rank Icon
var rankId = getRankCellId(entState.template); var rankId = getRankCellId(entState.template);
getGUIObjectByName("sdRankIcon").cell_id = rankId; getGUIObjectByName("sdRankIcon").cell_id = rankId;
@ -130,7 +119,7 @@ function displayGeneralInfo(playerState, entState, template)
} }
// Icon // Icon
getGUIObjectByName("sdIconImage").sprite = getPortraitSheetName(playerState, entState); getGUIObjectByName("sdIconImage").sprite = getPortraitSheetName(getTemplateCategory(entState.template));
getGUIObjectByName("sdIconImage").cell_id = template.icon_cell; getGUIObjectByName("sdIconImage").cell_id = template.icon_cell;
getGUIObjectByName("sdIconImage").tooltip = iconTooltip; getGUIObjectByName("sdIconImage").tooltip = iconTooltip;
//getGUIObjectByName("sdIconOutline"); // Need to change color of icon outline with the playerColor //getGUIObjectByName("sdIconOutline"); // Need to change color of icon outline with the playerColor

View File

@ -1,3 +1,8 @@
const GEOLOGY = "geology";
const FLORA = "flora";
const FAUNA = "fauna";
const SPECIAL = "special";
const GAIA = "Gaia" const GAIA = "Gaia"
const CART = "Cart"; const CART = "Cart";
const CELT = "Celt"; const CELT = "Celt";
@ -201,37 +206,6 @@ function damageTypesToText(dmg)
return dmgArray.join(", "); return dmgArray.join(", ");
} }
/*
function isUnitElite(templateName)
{
var eliteStatus = false;
var firstWord = getTemplateFirstWord(templateName);
var endsWith = templateName.substring(templateName.length-2, templateName.length);
if (firstWord == "units" && endsWith == "_e")
eliteStatus = true;
return eliteStatus;
}
function getRankTitle(templateName)
{
var firstWord = getTemplateFirstWord(templateName);
var endsWith = templateName.substring(templateName.length-2, templateName.length);
if (firstWord == "units")
{
if (endsWith == "_e")
return " Elite";
else if (endsWith == "_a")
return " Advanced";
}
return "";
}
*/
function getRankCellId(templateName) function getRankCellId(templateName)
{ {
var firstWord = getTemplateFirstWord(templateName); var firstWord = getTemplateFirstWord(templateName);
@ -258,22 +232,10 @@ function getRankTitle(cellId)
return ""; return "";
} }
function isUnitElite(templateName)
{
var eliteStatus = false;
var firstWord = getTemplateFirstWord(templateName);
var endsWith = templateName.substring(templateName.length-2, templateName.length);
if (firstWord == "units" && endsWith == "_e")
eliteStatus = true;
return eliteStatus;
}
function getFullName(template) function getFullName(template)
{ {
var name; var name;
if ((template.name.specific && template.name.generic) && (template.name.specific != template.name.generic)) if ((template.name.specific && template.name.generic) && (template.name.specific != template.name.generic))
name = template.name.specific + " (" + template.name.generic + ")"; name = template.name.specific + " (" + template.name.generic + ")";
else else
@ -282,32 +244,33 @@ function getFullName(template)
return "[font=\"serif-bold-16\"]" + name + "[/font]"; return "[font=\"serif-bold-16\"]" + name + "[/font]";
} }
function getPortraitSheetName(playerState, entState) function getTemplateCategory(templateName)
{
var slashIndex = templateName.search("/");
if (slashIndex >= 0)
return templateName.substring(slashIndex+1, templateName.search("_"));
return "unknown category";
}
function getPortraitSheetName(type)
{ {
var portraitSheetName = "snPortraitSheet"; var portraitSheetName = "snPortraitSheet";
var firstWord = getTemplateFirstWord(entState.template);
if (firstWord == "gaia") // Find appropriate Gaia icon sheet switch (type)
{ {
var template = Engine.GuiInterfaceCall("GetTemplateData", entState.template); case GEOLOGY:
var gaiaType = template.name.generic; return portraitSheetName += "RockGaia";
case FLORA:
if ((gaiaType == "Rock") || (gaiaType == "Mineral")) return portraitSheetName += "TreeGaia";
portraitSheetName += "RockGaia"; case FAUNA:
else if ((gaiaType == "Tree") || (gaiaType == "Bush")) return portraitSheetName += "AnimalGaia";
portraitSheetName += "TreeGaia"; case SPECIAL:
else if (gaiaType == "Fauna") return portraitSheetName += "SpecialGaia";
portraitSheetName += "AnimalGaia"; default:
else return portraitSheetName += toTitleCase(type);
portraitSheetName += "SpecialGaia";
} }
else // Find appropriate Civ icon sheet
{
var civName = toTitleCase(playerState.civ);
portraitSheetName += civName;
}
return portraitSheetName;
} }
function getFormalCivName(civ) function getFormalCivName(civ)

View File

@ -285,7 +285,7 @@
size="10 4 278 64" size="10 4 278 64"
> >
<object size="0 0 100% 47"> <object size="0 0 100% 47">
<repeat count="24"> <repeat count="16">
<object name="unitSelectionButton[n]" hidden="true" style="iconButton" type="button" size="0 0 34 34" z="20"> <object name="unitSelectionButton[n]" hidden="true" style="iconButton" type="button" size="0 0 34 34" z="20">
<object name="unitSelectionHighlight[n]" hidden="true" ghost="true" type="image" sprite="primaryGroupHighlight" size="-1 -1 35 35"/> <object name="unitSelectionHighlight[n]" hidden="true" ghost="true" type="image" sprite="primaryGroupHighlight" size="-1 -1 35 35"/>
<object name="unitSelectionIcon[n]" type="image" ghost="true" size="3 3 32 32"/> <object name="unitSelectionIcon[n]" type="image" ghost="true" size="3 3 32 32"/>

View File

@ -7,20 +7,20 @@ var g_unitPanels = ["Stance", "Formation", "Construction", "Research", "Training
// Lay out button rows // Lay out button rows
function layoutButtonRow(rowNumber, guiName, buttonSideLength, buttonSpacer, startIndex, endIndex) function layoutButtonRow(rowNumber, guiName, buttonSideLength, buttonSpacer, startIndex, endIndex)
{ {
var rowIndex = 0; var colNumber = 0;
for (i = startIndex; i < endIndex; i++) for (i = startIndex; i < endIndex; i++)
{ {
var button = getGUIObjectByName("unit"+guiName+"Button["+i+"]"); var button = getGUIObjectByName("unit"+guiName+"Button["+i+"]");
var size = button.size; var size = button.size;
size.left = buttonSpacer*rowIndex; size.left = buttonSpacer*colNumber;
size.right = buttonSpacer*rowIndex + buttonSideLength; size.right = buttonSpacer*colNumber + buttonSideLength;
size.top = buttonSpacer*rowNumber; size.top = buttonSpacer*rowNumber;
size.bottom = buttonSpacer*rowNumber + buttonSideLength; size.bottom = buttonSpacer*rowNumber + buttonSideLength;
button.size = size; button.size = size;
rowIndex++; colNumber++;
} }
} }
@ -34,6 +34,8 @@ function setupUnitPanel(guiName, usedPanels, playerState, unitEntState, items, c
{ {
if (i > 23) // End loop early if there are more than 24 buttons if (i > 23) // End loop early if there are more than 24 buttons
break; break;
else if (guiName == "Selection" && i > 15) // End loop early if more then 16 selection buttons
break
// Get templates // Get templates
var entType; var entType;
@ -54,7 +56,7 @@ function setupUnitPanel(guiName, usedPanels, playerState, unitEntState, items, c
name = getFullName(template); name = getFullName(template);
// Tooltip // Tooltip
var tooltip = name; //(isUnitElite(entType)? "Elite " + name : name ); var tooltip = name;
if (guiName == "Selection") if (guiName == "Selection")
{ {
@ -101,8 +103,9 @@ function setupUnitPanel(guiName, usedPanels, playerState, unitEntState, items, c
if (callback != null) if (callback != null)
button.onpress = (function(e) { return function() { callback(e) } })(item); // (need nested functions to get the closure right) button.onpress = (function(e) { return function() { callback(e) } })(item); // (need nested functions to get the closure right)
icon.sprite = getPortraitSheetName(playerState, unitEntState) //"snPortraitSheetHele"; // TODO // Get icon sheet
icon.sprite = getPortraitSheetName(getTemplateCategory(item));
if (typeof template.icon_cell == "undefined") if (typeof template.icon_cell == "undefined")
icon.cell_id = 0; icon.cell_id = 0;
else else
@ -121,7 +124,7 @@ function setupUnitPanel(guiName, usedPanels, playerState, unitEntState, items, c
if ((guiName == "Queue")) // or garrison if ((guiName == "Queue")) // or garrison
getGUIObjectByName("unit"+guiName+"Panel").size = "0 -60 100% 100%-166"; getGUIObjectByName("unit"+guiName+"Panel").size = "0 -60 100% 100%-166";
layoutButtonRow(0, guiName, buttonSideLength, buttonSpacer, 0, numButtons); layoutButtonRow(0, guiName, buttonSideLength, buttonSpacer, 0, 8);
} }
else if (numButtons < 17) // Row 1 else if (numButtons < 17) // Row 1
{ {
@ -129,7 +132,7 @@ function setupUnitPanel(guiName, usedPanels, playerState, unitEntState, items, c
getGUIObjectByName("unit"+guiName+"Panel").size = "0 -105 100% 100%-166"; getGUIObjectByName("unit"+guiName+"Panel").size = "0 -105 100% 100%-166";
layoutButtonRow(0, guiName, buttonSideLength, buttonSpacer, 0, 8); layoutButtonRow(0, guiName, buttonSideLength, buttonSpacer, 0, 8);
layoutButtonRow(1, guiName, buttonSideLength, buttonSpacer, 8, numButtons); layoutButtonRow(1, guiName, buttonSideLength, buttonSpacer, 8, 16);
} }
else // Row 2 else // Row 2
{ {
@ -139,7 +142,7 @@ function setupUnitPanel(guiName, usedPanels, playerState, unitEntState, items, c
layoutButtonRow(0, guiName, buttonSideLength, buttonSpacer, 0, 8); layoutButtonRow(0, guiName, buttonSideLength, buttonSpacer, 0, 8);
layoutButtonRow(1, guiName, buttonSideLength, buttonSpacer, 8, 16); layoutButtonRow(1, guiName, buttonSideLength, buttonSpacer, 8, 16);
if (guiName != "Selection") if (guiName != "Selection")
layoutButtonRow(2, guiName, buttonSideLength, buttonSpacer, 16, numButtons); layoutButtonRow(2, guiName, buttonSideLength, buttonSpacer, 16, 24);
} }
// Hide any buttons we're no longer using // Hide any buttons we're no longer using