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
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("sdSpecific").size = "0 6 100% 30";
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 iconTooltip = "";
// Is unit Elite?
// var eliteStatus = isUnitElite(entState.template);
// Rank Icon
var rankId = getRankCellId(entState.template);
getGUIObjectByName("sdRankIcon").cell_id = rankId;
@ -130,7 +119,7 @@ function displayGeneralInfo(playerState, entState, template)
}
// Icon
getGUIObjectByName("sdIconImage").sprite = getPortraitSheetName(playerState, entState);
getGUIObjectByName("sdIconImage").sprite = getPortraitSheetName(getTemplateCategory(entState.template));
getGUIObjectByName("sdIconImage").cell_id = template.icon_cell;
getGUIObjectByName("sdIconImage").tooltip = iconTooltip;
//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 CART = "Cart";
const CELT = "Celt";
@ -201,37 +206,6 @@ function damageTypesToText(dmg)
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)
{
var firstWord = getTemplateFirstWord(templateName);
@ -258,22 +232,10 @@ function getRankTitle(cellId)
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)
{
var name;
if ((template.name.specific && template.name.generic) && (template.name.specific != template.name.generic))
name = template.name.specific + " (" + template.name.generic + ")";
else
@ -282,32 +244,33 @@ function getFullName(template)
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 firstWord = getTemplateFirstWord(entState.template);
if (firstWord == "gaia") // Find appropriate Gaia icon sheet
switch (type)
{
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";
case GEOLOGY:
return portraitSheetName += "RockGaia";
case FLORA:
return portraitSheetName += "TreeGaia";
case FAUNA:
return portraitSheetName += "AnimalGaia";
case SPECIAL:
return portraitSheetName += "SpecialGaia";
default:
return portraitSheetName += toTitleCase(type);
}
else // Find appropriate Civ icon sheet
{
var civName = toTitleCase(playerState.civ);
portraitSheetName += civName;
}
return portraitSheetName;
}
function getFormalCivName(civ)

View File

@ -285,7 +285,7 @@
size="10 4 278 64"
>
<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="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"/>

View File

@ -7,20 +7,20 @@ var g_unitPanels = ["Stance", "Formation", "Construction", "Research", "Training
// Lay out button rows
function layoutButtonRow(rowNumber, guiName, buttonSideLength, buttonSpacer, startIndex, endIndex)
{
var rowIndex = 0;
var colNumber = 0;
for (i = startIndex; i < endIndex; i++)
{
var button = getGUIObjectByName("unit"+guiName+"Button["+i+"]");
var size = button.size;
size.left = buttonSpacer*rowIndex;
size.right = buttonSpacer*rowIndex + buttonSideLength;
size.left = buttonSpacer*colNumber;
size.right = buttonSpacer*colNumber + buttonSideLength;
size.top = buttonSpacer*rowNumber;
size.bottom = buttonSpacer*rowNumber + buttonSideLength;
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
break;
else if (guiName == "Selection" && i > 15) // End loop early if more then 16 selection buttons
break
// Get templates
var entType;
@ -54,7 +56,7 @@ function setupUnitPanel(guiName, usedPanels, playerState, unitEntState, items, c
name = getFullName(template);
// Tooltip
var tooltip = name; //(isUnitElite(entType)? "Elite " + name : name );
var tooltip = name;
if (guiName == "Selection")
{
@ -101,8 +103,9 @@ function setupUnitPanel(guiName, usedPanels, playerState, unitEntState, items, c
if (callback != null)
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")
icon.cell_id = 0;
else
@ -121,7 +124,7 @@ function setupUnitPanel(guiName, usedPanels, playerState, unitEntState, items, c
if ((guiName == "Queue")) // or garrison
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
{
@ -129,7 +132,7 @@ function setupUnitPanel(guiName, usedPanels, playerState, unitEntState, items, c
getGUIObjectByName("unit"+guiName+"Panel").size = "0 -105 100% 100%-166";
layoutButtonRow(0, guiName, buttonSideLength, buttonSpacer, 0, 8);
layoutButtonRow(1, guiName, buttonSideLength, buttonSpacer, 8, numButtons);
layoutButtonRow(1, guiName, buttonSideLength, buttonSpacer, 8, 16);
}
else // Row 2
{
@ -139,7 +142,7 @@ function setupUnitPanel(guiName, usedPanels, playerState, unitEntState, items, c
layoutButtonRow(0, guiName, buttonSideLength, buttonSpacer, 0, 8);
layoutButtonRow(1, guiName, buttonSideLength, buttonSpacer, 8, 16);
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