Production queue GUI interface.
Some refactoring of updateTab() function. Disabling some unimplemented buttons. This was SVN commit r6418.
This commit is contained in:
parent
dba26306e0
commit
bcfbf972ed
@ -415,4 +415,4 @@ function togglePlayersList()
|
||||
pl.hidden = ! pl.hidden;
|
||||
var pls = getGUIObjectByName("PlayersListShadow");
|
||||
pls.hidden = ! pls.hidden;
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,9 @@ function defineCommandButtons(command)
|
||||
snStatusPaneCommand = new Array();
|
||||
snStatusPaneCommand.tab = new Object();
|
||||
snStatusPaneCommand.list = new Object();
|
||||
snStatusPaneCommand.button = new Object();
|
||||
snStatusPaneCommand.button = new Object();
|
||||
|
||||
empty = false;
|
||||
|
||||
// Maximum number of buttons (either single or lists).
|
||||
snStatusPaneCommand.tab.max = command.substring (command.lastIndexOf ("d")+1, command.lastIndexOf ("_")); // 8
|
||||
@ -153,384 +155,228 @@ function updateTab (tab, type, cellSheet, attribute, attribute2, arrayCells)
|
||||
// * pick: Usually a group that's the same as the tab name, so use this.
|
||||
// * command: Tends to be "Command" (though not always), so defaults to this.
|
||||
// * If no value is specified, it will use the above default for the type.
|
||||
// attribute: * For production & pick: the attribute containing the list of items to display (eg selection[0].actions.create.list.research), which this entity must
|
||||
// attribute: * For production & pick: the attribute containing the list of items to display
|
||||
// (eg selection[0].actions.create.list.research), which this entity must
|
||||
// have in order to update the tab with this list.
|
||||
// * For command: the attribute that the entity must have in order to have this command.
|
||||
// * If no value is specified, all entities have this attribute.
|
||||
// attribute2: * For pick: The variable used to store the current item in the pick that has been selected -- placed in the tab (eg selection[0].actions.formation.curr)
|
||||
// arrayCells: * Optional attribute. If true, assume that items cannot all be found in the same cellSheet; check in attribute.sheet for cell sheet name for each item.
|
||||
// attribute2: * For pick: The variable used to store the current item in the pick that has been selected -- placed in the tab
|
||||
// (eg selection[0].actions.formation.curr)
|
||||
// arrayCells: * Optional attribute. If true, assume that items cannot all be found in the same cellSheet; check in attribute.sheet
|
||||
// for cell sheet name for each item.
|
||||
|
||||
// Store string form of attribute for future reference.
|
||||
attributeString = attribute;
|
||||
attribute2String = attribute2;
|
||||
|
||||
// If either attribute is not a valid property, return false.
|
||||
if ( (validProperty (attributeString)) && (validProperty (attribute2String)) )
|
||||
{
|
||||
// Use the value of the attribute from this point forwards.
|
||||
attribute = eval (attribute);
|
||||
attribute2 = eval (attribute2);
|
||||
// String properties taken from entities can be a little confused about their variable type, so make sure they're considered strings.
|
||||
attribute2 = String (attribute2);
|
||||
|
||||
//console.write ("1st: " + tabCounter + " " + tab + " " + type + " " + cellSheet + " " + attribute + " " + attribute2);
|
||||
|
||||
// Set default values.
|
||||
if (cellSheet == "")
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case "command":
|
||||
cellSheet = "Command";
|
||||
break;
|
||||
case "pick":
|
||||
cellSheet = toTitleCase(tab);
|
||||
tab = attribute2.toLowerCase();
|
||||
// avoid, pick, Stance, .traits.ai.stance.list
|
||||
break;
|
||||
default:
|
||||
cellSheet = "Tab";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//console.write ("2nd: " + tabCounter + " " + tab + " " + type + " " + cellSheet + " " + attribute + " " + attribute2);
|
||||
// If either attribute is not a valid property, return false.
|
||||
if (! ((validProperty (attributeString)) && (validProperty (attribute2String))) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Get tab.
|
||||
var tabObject = getGUIObjectByName ("snStatusPaneCommand" + tabCounter + "_1");
|
||||
// Enable tab.
|
||||
guiUnHide (tabObject.name);
|
||||
|
||||
// Set tab portrait.
|
||||
switch (tab)
|
||||
{
|
||||
case "selection":
|
||||
case "garrison":
|
||||
// Temporarily (until we have the tab textures) force a particular cell ID for selection and garrison so we can see the icon.
|
||||
cellGroup[cellSheet][tab].id = 2;
|
||||
|
||||
// Use the horizontal tab. (Extends right.)
|
||||
setPortrait ("snStatusPaneCommand" + tabCounter + "_1", "IconSheet", cellSheet + "Button_H", cellGroup[cellSheet][tab].id);
|
||||
break;
|
||||
default:
|
||||
if (type == "pick" && cellSheet != "Tab") // Force the tab background for pick lists,
|
||||
setPortrait ("snStatusPaneCommand" + tabCounter + "_1", "IconSheet", cellSheet + "TabButton", cellGroup[cellSheet][tab].id);
|
||||
else
|
||||
setPortrait ("snStatusPaneCommand" + tabCounter + "_1", "IconSheet", cellSheet + "Button", cellGroup[cellSheet][tab].id);
|
||||
break;
|
||||
}
|
||||
|
||||
//console.write ("3rd: " + "snStatusPaneCommand" + tabCounter + "_1" + "|" + "IconSheet" + "|" + cellSheet + "Button" + "|" + cellGroup[cellSheet][tab].id);
|
||||
|
||||
// Use the value of the attribute from this point forwards.
|
||||
attribute = eval (attribute);
|
||||
attribute2 = eval (attribute2);
|
||||
// String properties taken from entities can be a little confused about their variable type, so make sure they're considered strings.
|
||||
attribute2 = String (attribute2);
|
||||
|
||||
|
||||
// Set default values.
|
||||
if (cellSheet == "")
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case "command":
|
||||
// Set tab tooltip.
|
||||
var tooltip = cellGroup[cellSheet][tab].name;
|
||||
tooltip += " " + cellSheet;
|
||||
cellSheet = "Command";
|
||||
break;
|
||||
case "pick":
|
||||
// Set tab tooltip.
|
||||
var tooltip = cellSheet;
|
||||
tooltip += " List\nCurrent " + cellSheet + ": " + cellGroup[cellSheet][tab].name;
|
||||
cellSheet = toTitleCase(tab);
|
||||
tab = attribute2.toLowerCase();
|
||||
// avoid, pick, Stance, .traits.ai.stance.list
|
||||
break;
|
||||
default:
|
||||
// Set tab tooltip.
|
||||
var tooltip = cellGroup[cellSheet][tab].name;
|
||||
tooltip += " " + cellSheet;
|
||||
cellSheet = "Tab";
|
||||
break;
|
||||
}
|
||||
tabObject.tooltip = tooltip;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case "command":
|
||||
// An array of actions for the command "tabs" can be triggered by clicking the individual commands. We'll set them here.
|
||||
switch(tab)
|
||||
{
|
||||
case "rally":
|
||||
tabObject.onPress = function (event)
|
||||
{
|
||||
setCursor("cursor-rally");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
tabObject.onPress = function (event)
|
||||
{
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// Set tab function when user moves mouse over tab.
|
||||
tabObject.onMouseEnter = function (event)
|
||||
{
|
||||
var currTab = this.name.substring (this.name.lastIndexOf ("d")+1, this.name.lastIndexOf ("_"));
|
||||
// Seek through all list tabs. (Only the one being hovered should stay open.)
|
||||
for (var i = 1; i < snStatusPaneCommand.split; i++)
|
||||
{
|
||||
// If we've found the current tab,
|
||||
if (i == currTab)
|
||||
{
|
||||
// Click the tab button to toggle visibility of its list.
|
||||
guiToggle ( "snStatusPaneCommandGroup" + currTab );
|
||||
}
|
||||
else // If it's another list tab,
|
||||
{
|
||||
// Ensure this tab is hidden.
|
||||
guiHide ("snStatusPaneCommandGroup" + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Set tab function when user clicks tab.
|
||||
tabObject.onPress = function (event)
|
||||
{
|
||||
// Click the tab button to toggle visibility of its list.
|
||||
guiToggle ( "snStatusPaneCommandGroup" + this.name.substring (this.name.lastIndexOf ("d")+1, this.name.lastIndexOf ("_")) );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Get group.
|
||||
var groupObject = getGUIObjectByName ("snStatusPaneCommand" + "Group" + tabCounter);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// If the list hasn't been hidden (tab is open), and it should have list items (it's not merely a command),
|
||||
if ( type != "command" && attribute != undefined )
|
||||
{
|
||||
// Reset array.
|
||||
var listArray = [];
|
||||
// Insert blank array element at location 0 (to buffer array so items are in 1..n range).
|
||||
listArray[0] = "";
|
||||
// Get tab.
|
||||
var tabObject = getGUIObjectByName ("snStatusPaneCommand" + tabCounter + "_1");
|
||||
guiUnHide (tabObject.name);
|
||||
|
||||
|
||||
setTabPortrait(type, tab, cellSheet, cellGroup, tabCounter);
|
||||
|
||||
// Extract item list into an array.
|
||||
if (!attribute.length)
|
||||
{ // If it's a list where each element is a value, (entity list)
|
||||
for ( var i in attribute )
|
||||
setTooltip(type, tab, cellSheet, cellGroup, tabObject);
|
||||
|
||||
setEvents(type, tab, tabObject);
|
||||
|
||||
// Get group.
|
||||
var groupObject = getGUIObjectByName ("snStatusPaneCommand" + "Group" + tabCounter);
|
||||
|
||||
// If the list hasn't been hidden (tab is open), and it should have list items (it's not merely a command),
|
||||
if ( type != "command" && attribute != undefined )
|
||||
{
|
||||
if (tab == "queue")
|
||||
{
|
||||
var newAttribute = groupProductionItems(attribute);
|
||||
//ok, now split newAttribute into 2 arrays: 1 containing items, and another one containing nums.
|
||||
|
||||
var nums = new Array();
|
||||
attribute = new Array();
|
||||
|
||||
for (i=0; i<newAttribute.length; i++)
|
||||
{
|
||||
attribute.push(newAttribute[i].item);
|
||||
nums.push(newAttribute[i].num);
|
||||
}
|
||||
}
|
||||
|
||||
listArray = extractItemList(attribute, arrayCells);
|
||||
|
||||
// Populate the buttons in this tab's list.
|
||||
for (var createLoop = 1; createLoop < snStatusPaneCommand.list.max; createLoop++)
|
||||
{
|
||||
// (Skip research list for the moment, since we don't have any portraits for techs.
|
||||
// But we should remove the research condition later.)
|
||||
if (createLoop < listArray.length && type != "command")
|
||||
{
|
||||
// Get name of current button.
|
||||
var listObject = getGUIObjectByName ("snStatusPaneCommand" + tabCounter + "_" + (createLoop+1));
|
||||
|
||||
switch (type)
|
||||
{
|
||||
listArray[listArray.length] = i;
|
||||
case "pick":
|
||||
// Set tooltip.
|
||||
if (arrayCells == true)
|
||||
{
|
||||
// Check a .sheet property for each item in the list to know its cellsheet.
|
||||
listObject.tooltip = cellGroup[listArray[createLoop].sheet][listArray[createLoop]].name;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Assume each item uses the same cell sheet as the tab.
|
||||
if(cellGroup[cellSheet][listArray[createLoop]]) {
|
||||
listObject.tooltip = cellGroup[cellSheet][listArray[createLoop]].name;
|
||||
}
|
||||
else {
|
||||
listObject.tooltip = "(no name)";
|
||||
}
|
||||
}
|
||||
|
||||
// Set portrait.
|
||||
if(cellGroup[cellSheet][listArray[createLoop]]) {
|
||||
setPortrait (listObject.name, "IconSheet",
|
||||
cellSheet + "Button", cellGroup[cellSheet][listArray[createLoop]].id);
|
||||
}
|
||||
|
||||
// Store properties which we will need when doing the press event as a comma-delimited string.
|
||||
// * 0 Name of variable that contains the ".curr" value.
|
||||
// * 1 String name of current button's content.
|
||||
// * 2 Array list of tab items.
|
||||
// * 3 Name of tab (eg stance).
|
||||
// * 4 Tab number.
|
||||
// (Storing the properties in the hotkey is an evil hack, and we'll eventually need the hotkey, but since new properties cannot be
|
||||
// attached to controls, there doesn't seem to be much choice ... Maybe add a .container property for situations such as this?)
|
||||
listObject.hotkey = attribute2String + "," + listArray[createLoop] + "," + attributeString + "," + cellSheet.toLowerCase() + "," + tabCounter + ",";
|
||||
|
||||
// Set item function.
|
||||
|
||||
listObject.onPress = function (event)
|
||||
{
|
||||
// Extract the properties from the comma-delimited string.
|
||||
var tempArray = parseDelimiterString (this.hotkey, ",");
|
||||
|
||||
// Refresh tab so it displays the new .curr sprite.
|
||||
tabCounter = tempArray[4];
|
||||
updateTab (tempArray[3], "pick", "", tempArray[2], '"' + tempArray[1] + '"');
|
||||
|
||||
// Do case-specific stuff depending on name of tab.
|
||||
switch (tempArray[3])
|
||||
{
|
||||
case "stance":
|
||||
issueCommand(selection, true, NMT_SET_STANCE, tempArray[1]);
|
||||
break;
|
||||
case "formation":
|
||||
// Remove the selected units from any existing formation.
|
||||
removeFromFormation (selection);
|
||||
// Set the selected entities to the chosen formation name.
|
||||
createEntityFormation (selection, tempArray[0]);
|
||||
// If the player is choosing to "disband" the formation (disable "batallion mode"),
|
||||
if ( tempArray[0] == "Loose" && isFormationLocked (selection) )
|
||||
{
|
||||
// Unlock the formation so each entity can be individually selected.
|
||||
lockEntityFormation (false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Lock the formation so the selection can be controlled as one unit.
|
||||
lockEntityFormation (true);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
var itemName = "?";
|
||||
|
||||
if (tab == "selection" || tab == "garrison" || tab == "research" || tab == "queue")
|
||||
{
|
||||
// Get name of item to display in list.
|
||||
// (These already know the full name of the entity tag, so we don't prefix it.)
|
||||
itemName = listArray[createLoop];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get name of item to display in list.
|
||||
itemName = selection[0].traits.id.civ_code + "_" + listArray[createLoop];
|
||||
}
|
||||
|
||||
setItemTooltip(tab, itemName, listObject, selection);
|
||||
setItemFunction(tab, listObject, selection);
|
||||
break;
|
||||
}
|
||||
|
||||
//Only for queue tab: write the number of queued similar items.
|
||||
if (tab == "queue")
|
||||
{
|
||||
listObject.caption = "[font=trebuchet14b] " + parseInt(attribute[createLoop-1].progress * 100) + "%[/font]";
|
||||
listObject.caption += "\n[font=trebuchet14b] (" + nums[createLoop-1] + ")[/font]";
|
||||
}
|
||||
else
|
||||
{
|
||||
listObject.caption = "";
|
||||
}
|
||||
|
||||
// Reveal portrait.
|
||||
guiUnHide (listObject.name);
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{ // If it's a list where each element is part of a numbered array, (array list)
|
||||
for ( var i = 0; i < attribute.length; i++ )
|
||||
{
|
||||
listArray[listArray.length] = attribute[i];
|
||||
// If cell sheet for each item is stored in attribute.sheet, transfer that across too.
|
||||
if (arrayCells == true)
|
||||
{
|
||||
//console.write (attribute[i].sheet);
|
||||
listArray[listArray.length].sheet = new Object(attribute[i].sheet);
|
||||
//console.write (listArray[listArray.length].sheet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Populate the buttons in this tab's list.
|
||||
for (var createLoop = 1; createLoop < snStatusPaneCommand.list.max; createLoop++)
|
||||
{
|
||||
// (Skip research list for the moment, since we don't have any portraits for techs. But we should remove the research condition later.)
|
||||
if (createLoop < listArray.length && type != "command")
|
||||
{
|
||||
// Get name of current button.
|
||||
var listObject = getGUIObjectByName ("snStatusPaneCommand" + tabCounter + "_" + (createLoop+1));
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case "pick":
|
||||
// Set tooltip.
|
||||
if (arrayCells == true) { // Check a .sheet property for each item in the list to know its cellsheet.
|
||||
listObject.tooltip = cellGroup[listArray[createLoop].sheet][listArray[createLoop]].name;
|
||||
}
|
||||
else { // Assume each item uses the same cell sheet as the tab.
|
||||
if(cellGroup[cellSheet][listArray[createLoop]]) {
|
||||
listObject.tooltip = cellGroup[cellSheet][listArray[createLoop]].name;
|
||||
}
|
||||
else {
|
||||
listObject.tooltip = "(no name)";
|
||||
}
|
||||
}
|
||||
|
||||
// Set portrait.
|
||||
if(cellGroup[cellSheet][listArray[createLoop]]) {
|
||||
setPortrait (listObject.name,
|
||||
"IconSheet", cellSheet + "Button", cellGroup[cellSheet][listArray[createLoop]].id);
|
||||
}
|
||||
|
||||
// Store properties which we will need when doing the press event as a comma-delimited string.
|
||||
// * 0 Name of variable that contains the ".curr" value.
|
||||
// * 1 String name of current button's content.
|
||||
// * 2 Array list of tab items.
|
||||
// * 3 Name of tab (eg stance).
|
||||
// * 4 Tab number.
|
||||
// (Storing the properties in the hotkey is an evil hack, and we'll eventually need the hotkey, but since new properties cannot be
|
||||
// attached to controls, there doesn't seem to be much choice ... Maybe add a .container property for situations such as this?)
|
||||
listObject.hotkey = attribute2String + "," + listArray[createLoop] + "," + attributeString + "," + cellSheet.toLowerCase() + "," + tabCounter + ",";
|
||||
// console.write (listObject.caption);
|
||||
|
||||
// Set item function.
|
||||
listObject.onPress = function (event)
|
||||
{
|
||||
// Extract the properties from the comma-delimited string.
|
||||
var tempArray = parseDelimiterString (this.hotkey, ",");
|
||||
|
||||
// Refresh tab so it displays the new .curr sprite.
|
||||
tabCounter = tempArray[4];
|
||||
updateTab (tempArray[3], "pick", "", tempArray[2], '"' + tempArray[1] + '"');
|
||||
|
||||
// Do case-specific stuff depending on name of tab.
|
||||
switch (tempArray[3])
|
||||
{
|
||||
case "stance":
|
||||
issueCommand(selection, true, NMT_SET_STANCE, tempArray[1]);
|
||||
break;
|
||||
case "formation":
|
||||
// Remove the selected units from any existing formation.
|
||||
removeFromFormation (selection);
|
||||
// Set the selected entities to the chosen formation name.
|
||||
createEntityFormation (selection, tempArray[0]);
|
||||
// If the player is choosing to "disband" the formation (disable "batallion mode"),
|
||||
if ( tempArray[0] == "Loose" && isFormationLocked (selection) )
|
||||
{
|
||||
// Unlock the formation so each entity can be individually selected.
|
||||
lockEntityFormation (false);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Lock the formation so the selection can be controlled as one unit.
|
||||
lockEntityFormation (true);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
var itemName = "?";
|
||||
//console.write(listArray[createLoop]);
|
||||
switch (tab)
|
||||
{
|
||||
case "selection":
|
||||
case "garrison":
|
||||
case "research":
|
||||
// Get name of item to display in list.
|
||||
// (These already know the full name of the entity tag, so we don't prefix it.)
|
||||
itemName = listArray[createLoop];
|
||||
break;
|
||||
default:
|
||||
// Get name of item to display in list.
|
||||
itemName = selection[0].traits.id.civ_code + "_" + listArray[createLoop];
|
||||
break;
|
||||
}
|
||||
|
||||
//console.write ("4th: " + "snStatusPaneCommand" + tabCounter + "_1" + "|" + "IconSheet" + "|" + cellSheet + "Button" + "|" + createLoop + "|" + listArray[createLoop]);
|
||||
|
||||
switch (tab)
|
||||
{
|
||||
case "research":
|
||||
// Store name of tech to display in list in this button's coordinate.
|
||||
var tech = getTechnology(itemName, selection[0].player);
|
||||
Crd[getCrd (listObject.name, true)].entity = tech;
|
||||
|
||||
if(!tech) {
|
||||
listObject.tooltip = "Bad tech: " + itemName;
|
||||
}
|
||||
else {
|
||||
// Set tooltip.
|
||||
listObject.tooltip = Crd[getCrd (listObject.name, true)].entity.generic + " (" + Crd[getCrd (listObject.name, true)].entity.specific + ")";
|
||||
|
||||
// Set portrait.
|
||||
setPortrait (listObject.name,
|
||||
Crd[getCrd (listObject.name, true)].entity.icon,
|
||||
"Button",
|
||||
Crd[getCrd (listObject.name, true)].entity.icon_cell);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// Store name of entity to display in list in this button's coordinate.
|
||||
Crd[getCrd (listObject.name, true)].entity = new Object(itemName);
|
||||
|
||||
// Set tooltip.
|
||||
var template = getEntityTemplate(itemName);
|
||||
if (!template) break;
|
||||
|
||||
//If there are several units selected, don´t show this tooltip when moving the cursor over the selection tab.
|
||||
if (tab != "selection")
|
||||
{
|
||||
listObject.tooltip = getProductionTooltip(template);
|
||||
}
|
||||
else if (tab == "selection")
|
||||
{
|
||||
listObject.tooltip = template.traits.id.specific;
|
||||
}
|
||||
|
||||
// Set portrait.
|
||||
setPortrait (listObject.name,
|
||||
template.traits.id.icon,
|
||||
"Button" + toTitleCase(selection[0].traits.id.civ_code),
|
||||
template.traits.id.icon_cell);
|
||||
break;
|
||||
}
|
||||
|
||||
// Set item function.
|
||||
listObject.onPress = function (event)
|
||||
{
|
||||
switch (tab)
|
||||
{
|
||||
case "train":
|
||||
// TODO: Remove this item from the production queue if right-clicked.
|
||||
issueCommand(selection, true, NMT_PRODUCE, PRODUCTION_TRAIN, ""+(Crd[getCrd (this.name, true)].entity));
|
||||
break;
|
||||
case "research":
|
||||
// TODO: Remove this item from the production queue if right-clicked.
|
||||
issueCommand(selection, true, NMT_PRODUCE, PRODUCTION_RESEARCH, ""+(Crd[getCrd (this.name, true)].entity.name));
|
||||
break;
|
||||
case "barter":
|
||||
// Buy a quantity of this resource if left-clicked.
|
||||
// Sell a quantity of this resource if right-clicked.
|
||||
break;
|
||||
case "structCiv":
|
||||
case "structMil":
|
||||
// Select building placement cursor.
|
||||
tryConstruction( Crd[getCrd (this.name, true)].entity );
|
||||
break;
|
||||
case "garrison":
|
||||
// Remove this item from the entity's garrison inventory.
|
||||
break;
|
||||
case "selection":
|
||||
// Change the selection to this unit.
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// Reveal portrait.
|
||||
guiUnHide (listObject.name);
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// Conceal this button.
|
||||
guiHide ("snStatusPaneCommand" + tabCounter + "_" + parseInt(createLoop+1));
|
||||
}
|
||||
// Conceal this button.
|
||||
guiHide ("snStatusPaneCommand" + tabCounter + "_" + parseInt(createLoop+1));
|
||||
}
|
||||
}
|
||||
|
||||
// Default the list to closed.
|
||||
groupObject.hidden = true;
|
||||
|
||||
tabCounter++;
|
||||
|
||||
// Completed tab update successfully.
|
||||
return true;
|
||||
}
|
||||
// Invalid property ... Cancel tab update.
|
||||
return false;
|
||||
|
||||
// Default the list to closed.
|
||||
|
||||
if (tab == "queue") {
|
||||
groupObject.hidden = false;
|
||||
}
|
||||
else {
|
||||
groupObject.hidden = true;
|
||||
}
|
||||
|
||||
tabCounter++;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -584,7 +430,7 @@ function refreshCommandButtons()
|
||||
|
||||
|
||||
// Update research. (Tab button, persistent buttons, click them to do things.)
|
||||
updateTab ("research", "production", "", "selection[0].actions.create.list.research", "");
|
||||
//updateTab ("research", "production", "", "selection[0].actions.create.list.research", "");
|
||||
|
||||
// End of production and pick lists. Store end position.
|
||||
var listCounter = tabCounter;
|
||||
@ -592,10 +438,10 @@ function refreshCommandButtons()
|
||||
// Commands begin from this point.
|
||||
tabCounter = snStatusPaneCommand.split;
|
||||
// Update commands. (Click "tab" button to do something; no list.)
|
||||
updateTab ("patrol", "command", "", "selection[0].actions.patrol", "");
|
||||
updateTab ("townbell", "command", "", "selection[0].actions.townBell", "");
|
||||
//updateTab ("patrol", "command", "", "selection[0].actions.patrol", "");
|
||||
//updateTab ("townbell", "command", "", "selection[0].actions.townBell", "");
|
||||
updateTab ("rally", "command", "", "selection[0].actions.create.rally", "");
|
||||
updateTab ("explore", "command", "", "selection[0].actions.explore", "");
|
||||
//updateTab ("explore", "command", "", "selection[0].actions.explore", "");
|
||||
updateTab ("retreat", "command", "", "selection[0].actions.retreat", "");
|
||||
updateTab ("stop", "command", "", "selection[0].actions.stop", "");
|
||||
|
||||
@ -641,13 +487,38 @@ function refreshCommandButtons()
|
||||
// If more than one entity is selected, list them.
|
||||
if (selection.length > 1)
|
||||
{
|
||||
tempArray = [];
|
||||
tempArray = new Array();
|
||||
for ( var i = 0; i < selection.length; i++ )
|
||||
tempArray[i] = selection[i].tag;
|
||||
tempArray.length = i;
|
||||
tempArray.push(selection[i].tag);
|
||||
updateTab ("selection", "production", "Tab", "tempArray", "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (selection.length == 1)
|
||||
{
|
||||
if (selection[0].productionQueue && selection[0].productionQueue.length > 0)
|
||||
{
|
||||
tabCounter = snStatusPaneCommand.tab.max;
|
||||
tempArray = new Array();
|
||||
var queue = selection[0].productionQueue;
|
||||
|
||||
for(var i=0; i < queue.length; i++)
|
||||
{
|
||||
tempArray.push(queue.get(i));
|
||||
}
|
||||
|
||||
updateTab("queue", "production", "Tab", "tempArray", "");
|
||||
empty = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
tabCounter = snStatusPaneCommand.tab.max;
|
||||
var tabObject = getGUIObjectByName ("snStatusPaneCommand" + tabCounter + "_1");
|
||||
guiHide(tabObject.name);
|
||||
var groupObject = getGUIObjectByName ("snStatusPaneCommand" + "Group" + tabCounter);
|
||||
guiHide(groupObject.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -675,8 +546,8 @@ function getProductionTooltip(template)
|
||||
first = false;
|
||||
tooltip += "[font=tahoma10b]Wood:[/font] " + template.traits.creation.resource.wood;
|
||||
}
|
||||
if (template.traits.creation.resource.metal > 0)
|
||||
{
|
||||
if (template.traits.creation.resource.metal > 0)
|
||||
{
|
||||
tooltip += (first ? "\n" : ", ");
|
||||
first = false;
|
||||
tooltip += "[font=tahoma10b]Metal:[/font] " + template.traits.creation.resource.metal
|
||||
@ -695,4 +566,277 @@ function getProductionTooltip(template)
|
||||
}
|
||||
|
||||
return tooltip;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ===================================================================================
|
||||
//entity is the name.
|
||||
function removeFromProductionQueue(selection, entity)
|
||||
{
|
||||
var queue = selection[0].productionQueue;
|
||||
|
||||
for(var i=0;i<queue.length;i++)
|
||||
{
|
||||
if (entity == queue.get(i).name) {
|
||||
queue.cancel(i);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// =====================================================================================
|
||||
|
||||
function groupProductionItems(l_attr)
|
||||
{
|
||||
var newAttribute = new Array();
|
||||
for (var i=0; i<l_attr.length && newAttribute.length < 8; i++) //allow max 8 items
|
||||
{
|
||||
var result = new Object();
|
||||
|
||||
result.num = 1;
|
||||
result.item = l_attr[i];
|
||||
|
||||
while (i < (l_attr.length-1) && result.item.name == l_attr[i+1].name)
|
||||
{
|
||||
i++;
|
||||
result.num++;
|
||||
}
|
||||
newAttribute.push(result);
|
||||
}
|
||||
|
||||
return newAttribute;
|
||||
}
|
||||
|
||||
// =====================================================================================
|
||||
|
||||
function setTooltip(type, tab, cellSheet, cellGroup, tabObject)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case "command":
|
||||
var tooltip = cellGroup[cellSheet][tab].name;
|
||||
tooltip += " " + cellSheet;
|
||||
break;
|
||||
case "pick":
|
||||
var tooltip = cellSheet;
|
||||
tooltip += " List\nCurrent " + cellSheet + ": " + cellGroup[cellSheet][tab].name;
|
||||
break;
|
||||
default:
|
||||
var tooltip = cellGroup[cellSheet][tab].name;
|
||||
tooltip += " " + cellSheet;
|
||||
break;
|
||||
}
|
||||
tabObject.tooltip = tooltip;
|
||||
}
|
||||
|
||||
// =====================================================================================
|
||||
|
||||
function setEvents(type, tab, tabObject)
|
||||
{
|
||||
if (type == "command")
|
||||
{
|
||||
if (tab == "rally")
|
||||
{
|
||||
tabObject.onPress = function (event)
|
||||
{
|
||||
setCursor("cursor-rally");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tabObject.onPress = function (event)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tabObject.onMouseEnter = function (event)
|
||||
{
|
||||
var currTab = this.name.substring (this.name.lastIndexOf ("d")+1, this.name.lastIndexOf ("_"));
|
||||
// Seek through all list tabs. (Only the one being hovered should stay open.)
|
||||
for (var i = 1; i < snStatusPaneCommand.split; i++)
|
||||
{
|
||||
// If we've found the current tab,
|
||||
if (i == currTab)
|
||||
{
|
||||
// Click the tab button to toggle visibility of its list.
|
||||
guiToggle ( "snStatusPaneCommandGroup" + currTab );
|
||||
}
|
||||
else // If it's another list tab,
|
||||
{
|
||||
// Ensure this tab is hidden.
|
||||
guiHide ("snStatusPaneCommandGroup" + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Set tab function when user clicks tab.
|
||||
tabObject.onPress = function (event)
|
||||
{
|
||||
// Click the tab button to toggle visibility of its list.
|
||||
guiToggle ( "snStatusPaneCommandGroup" + this.name.substring (this.name.lastIndexOf ("d")+1, this.name.lastIndexOf ("_")) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// =====================================================================================
|
||||
|
||||
function setTabPortrait(type, tab, cellSheet, cellGroup, tabCounter)
|
||||
{
|
||||
switch (tab)
|
||||
{
|
||||
case "selection":
|
||||
case "garrison":
|
||||
case "queue":
|
||||
// Temporarily (until we have the tab textures) force a particular cell ID
|
||||
cellGroup[cellSheet][tab].id = 2;
|
||||
|
||||
// Use the horizontal tab. (Extends right.)
|
||||
setPortrait ("snStatusPaneCommand" + tabCounter + "_1", "IconSheet",
|
||||
cellSheet + "Button_H", cellGroup[cellSheet][tab].id);
|
||||
break;
|
||||
default:
|
||||
if (type == "pick" && cellSheet != "Tab")
|
||||
{
|
||||
setPortrait ("snStatusPaneCommand" + tabCounter + "_1", "IconSheet",
|
||||
cellSheet + "TabButton", cellGroup[cellSheet][tab].id);
|
||||
}
|
||||
else
|
||||
{
|
||||
setPortrait ("snStatusPaneCommand" + tabCounter + "_1", "IconSheet",
|
||||
cellSheet + "Button", cellGroup[cellSheet][tab].id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// =====================================================================================
|
||||
|
||||
function setItemTooltip(tab, itemName, listObject, selection)
|
||||
{
|
||||
switch (tab)
|
||||
{
|
||||
case "research":
|
||||
// Store name of tech to display in list in this button's coordinate.
|
||||
var tech = getTechnology(itemName, selection[0].player);
|
||||
Crd[getCrd (listObject.name, true)].entity = tech;
|
||||
|
||||
if(!tech) {
|
||||
listObject.tooltip = "Bad tech: " + itemName;
|
||||
}
|
||||
else {
|
||||
// Set tooltip.
|
||||
listObject.tooltip = Crd[getCrd (listObject.name, true)].entity.generic +
|
||||
" (" + Crd[getCrd (listObject.name, true)].entity.specific + ")";
|
||||
|
||||
// Set portrait.
|
||||
setPortrait (listObject.name,
|
||||
Crd[getCrd (listObject.name, true)].entity.icon,
|
||||
"Button",
|
||||
Crd[getCrd (listObject.name, true)].entity.icon_cell);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
// Store name of entity to display in list in this button's coordinate.
|
||||
Crd[getCrd (listObject.name, true)].entity = new Object(itemName);
|
||||
|
||||
// Set tooltip.
|
||||
var template = getEntityTemplate(itemName);
|
||||
if (!template) break;
|
||||
|
||||
//If there are several units selected, don´t show this tooltip when moving the cursor over the selection tab.
|
||||
if (tab != "selection")
|
||||
{
|
||||
listObject.tooltip = getProductionTooltip(template);
|
||||
}
|
||||
else
|
||||
{
|
||||
listObject.tooltip = template.traits.id.specific;
|
||||
}
|
||||
|
||||
// Set portrait.
|
||||
setPortrait (listObject.name,
|
||||
template.traits.id.icon,
|
||||
"Button" + toTitleCase(selection[0].traits.id.civ_code),
|
||||
template.traits.id.icon_cell);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// =====================================================================================
|
||||
|
||||
function setItemFunction(tab, listObject, selection)
|
||||
{
|
||||
listObject.onPress = function (event)
|
||||
{
|
||||
switch (tab)
|
||||
{
|
||||
case "train":
|
||||
issueCommand(selection, true, NMT_PRODUCE, PRODUCTION_TRAIN, ""+(Crd[getCrd (this.name, true)].entity));
|
||||
break;
|
||||
case "research":
|
||||
// TODO: Remove this item from the production queue if right-clicked.
|
||||
issueCommand(selection, true, NMT_PRODUCE, PRODUCTION_RESEARCH, ""+(Crd[getCrd (this.name, true)].entity.name));
|
||||
break;
|
||||
case "barter":
|
||||
// Buy a quantity of this resource if left-clicked.
|
||||
// Sell a quantity of this resource if right-clicked.
|
||||
break;
|
||||
case "structCiv":
|
||||
case "structMil":
|
||||
// Select building placement cursor.
|
||||
tryConstruction( Crd[getCrd (this.name, true)].entity );
|
||||
break;
|
||||
case "garrison":
|
||||
// Remove this item from the entity's garrison inventory.
|
||||
break;
|
||||
case "selection":
|
||||
// Change the selection to this unit.
|
||||
break;
|
||||
case "queue":
|
||||
//Cancel this production item.
|
||||
removeFromProductionQueue(selection, Crd[getCrd(this.name, true)].entity);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// =====================================================================================
|
||||
|
||||
function extractItemList(attribute, arrayCells)
|
||||
{
|
||||
var listArray = new Array();
|
||||
// Insert blank array element at location 0 (to buffer array so items are in 1..n range).
|
||||
listArray.push("");
|
||||
|
||||
if (!attribute.length)
|
||||
{ // If it's a list where each element is a value, (entity list)
|
||||
for ( var i in attribute )
|
||||
{
|
||||
listArray.push(i);
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // If it's a list where each element is part of a numbered array, (array list)
|
||||
for ( var i = 0; i < attribute.length; i++ )
|
||||
{
|
||||
if (attribute[i].name) {
|
||||
if (attribute[i].name != "special_settlement")
|
||||
listArray.push(attribute[i].name);
|
||||
} else {
|
||||
if (attribute[i] != "special_settlement")
|
||||
listArray.push(attribute[i]);
|
||||
}
|
||||
|
||||
// If cell sheet for each item is stored in attribute.sheet, transfer that across too.
|
||||
if (arrayCells == true)
|
||||
{
|
||||
listArray[listArray.length-1].sheet = new Object(attribute[i].name.sheet);
|
||||
}
|
||||
}
|
||||
}
|
||||
return listArray;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user