diff --git a/binaries/data/mods/public/gui/session_new/input.js b/binaries/data/mods/public/gui/session_new/input.js index 327753c858..2a4911cbe0 100644 --- a/binaries/data/mods/public/gui/session_new/input.js +++ b/binaries/data/mods/public/gui/session_new/input.js @@ -4,7 +4,7 @@ const SDL_BUTTON_RIGHT = 3; const SDLK_RSHIFT = 303; const SDLK_LSHIFT = 304; -const MAX_SELECTION_SIZE = 24; +const MAX_SELECTION_SIZE = 32; // TODO: these constants should be defined somewhere else instead, in // case any other code wants to use them too @@ -266,9 +266,6 @@ function handleInputBeforeGui(ev) g_Selection.reset(); g_Selection.addList(ents); - // Create the selection groups - g_Selection.groups.createGroups(ents); - inputState = INPUT_NORMAL; return true; } @@ -616,3 +613,12 @@ function removeFromTrainingQueue(entity, id) { Engine.PostNetworkCommand({"type": "stop-train", "entity": entity, "id": id}); } + +// Called by unit selection buttons +function changePrimarySelectionGroup(index) +{ + if (specialKeyStates[SDLK_RSHIFT] || specialKeyStates[SDLK_LSHIFT]) + g_Selection.makePrimarySelection(index, true); + else + g_Selection.makePrimarySelection(index, false); +} diff --git a/binaries/data/mods/public/gui/session_new/menu.js b/binaries/data/mods/public/gui/session_new/menu.js index 30ec8a5099..8edc60dd59 100644 --- a/binaries/data/mods/public/gui/session_new/menu.js +++ b/binaries/data/mods/public/gui/session_new/menu.js @@ -1,11 +1,3 @@ -// Group Selection by Rank -var g_GroupSelectionByRank = true; // referenced in EntityGroups.createGroups(ents) AND in setupUnitPanel(...) -function groupSelectionByRank(booleanValue) -{ - g_GroupSelectionByRank = booleanValue; - g_Selection.groups.createGroups(g_Selection.toList()); -} - function toggleDeveloperOverlay() { if (getGUIObjectByName("devCommands").hidden) diff --git a/binaries/data/mods/public/gui/session_new/selection.js b/binaries/data/mods/public/gui/session_new/selection.js index d197e68fbb..9c32fabc9e 100644 --- a/binaries/data/mods/public/gui/session_new/selection.js +++ b/binaries/data/mods/public/gui/session_new/selection.js @@ -14,163 +14,6 @@ function _setMotionOverlay(ents, enabled) Engine.GuiInterfaceCall("SetMotionDebugOverlay", { "entities":ents, "enabled":enabled }); } -//-------------------------------- -------------------------------- -------------------------------- -// EntityGroups class for ordering / managing entities by their templates -//-------------------------------- -------------------------------- -------------------------------- -function EntityGroups() -{ - // private properties - this.primary = 0; - this.groups = []; // Includes only highest ranked versions of each type -} - -EntityGroups.prototype.Group = function(templateName, typeCount, firstOfType) -{ - this.templateName = templateName; - this.typeCount = typeCount; - this.firstOfType = firstOfType; -}; - -EntityGroups.prototype.reset = function() -{ - this.primary = 0; - this.groups = []; -}; - -EntityGroups.prototype.getLength = function() -{ - return this.groups.length; -}; - -EntityGroups.prototype.getPrimary = function() -{ - return this.primary; -}; - -EntityGroups.prototype.setPrimary = function(index) -{ - if (this.groups.length > index) - this.primary = index; - else - console.write("Warning: \"index\" is larger than g_Selection.toList().length: Cannot set Primary Selection."); -}; - -EntityGroups.prototype.getGroup = function(templateName) -{ - // Get the group that corresponds to the template name - var group = this.groups[this.getGroupNumber(templateName)]; - if (group) - return group; - - // The templateName didn't match any in the groups... - // Check if it's the same unit, but a different rank and return that group - - if (g_GroupSelectionByRank) - { - var thatGenericTemplateName = templateName.substring(0, templateName.length-2); - var templateNames = this.getTemplateNames(); - - for (var i = 0; i < templateNames.length; i++) - { - var thisGenericTemplateName = templateNames[i].substring(0, templateNames[i].length-2); - if (thisGenericTemplateName == thatGenericTemplateName) - return this.groups[i]; - } - } - - // There was no match... - //console.write("Warning: Could not find either \"" + templateName + "\" or the more generic: \"" + thatGenericTemplateName + "\""); - return undefined; -}; - -EntityGroups.prototype.addGroup = function(templateName, typeCount, firstOfType) -{ - this.groups.push(new this.Group(templateName, typeCount, firstOfType)); -}; - -EntityGroups.prototype.removeGroup = function(templateName) -{ - var index = this.getGroupNumber(templateName); - this.groups.splice(index, 1); -}; - -EntityGroups.prototype.getGroupNumber = function(templateName) -{ - for (var i = 0; i < this.groups.length; i++) - if (this.groups[i].templateName == templateName) - return i; - - return -1; -}; - -EntityGroups.prototype.getTemplateNames = function() -{ - var templateNames = []; - - for (var i = 0; i < this.groups.length; i++) - templateNames.push(this.groups[i].templateName); - - return templateNames; -}; - -// Checks if the new rank code is greater than the old rank code (private helper function for EntityGroups.createGroups) -EntityGroups.prototype.greaterThanPreviousRank = function(oldRank, newRank) -{ - if (oldRank == newRank) - return false; - else if (oldRank == 'b' || newRank == 'e') - return true; - else - return false; -}; - -EntityGroups.prototype.createGroups = function(ents) -{ - // Erase old groups first - this.reset(); - - // Make selection groups - for (var i = 0; i < ents.length; i++) - { - var templateName = Engine.GuiInterfaceCall("GetEntityState", ents[i]).template; - var group = this.getGroup(templateName); - - // We already have one of these types - if (group) - { - // See if the new one has a higher rank - var isRankableUnit = ((templateName.charAt(templateName.length-2) == '_')? true : false); - - if (g_GroupSelectionByRank && isRankableUnit) - { - var oldRank = group.templateName.charAt(group.templateName.length-1); - var newRank = templateName.charAt(templateName.length-1); - - if (this.greaterThanPreviousRank(oldRank, newRank)) - { - var oldTypeCount = group.typeCount; - this.removeGroup(group.templateName); - this.addGroup(templateName, oldTypeCount+1, i); - } - else - { - group.typeCount += 1; - } - } - else // It was not a rankable unit or its rank was not higher than the one we had - { - group.typeCount += 1; - } - } - else // Don't have any of this type, so add it in - { - this.addGroup(templateName, 1, i); - } - } - - resetCycleIndex(); -} - //-------------------------------- -------------------------------- -------------------------------- // EntitySelection class for managing the entity selection list and the primary selection //-------------------------------- -------------------------------- -------------------------------- @@ -178,7 +21,6 @@ function EntitySelection() { // Private properties: //-------------------------------- - this.primary = 0; // The active selection in the unit details panel this.selected = {}; // { id:id, id:id, ... } for each selected entity ID 'id' // { id:id, ... } for mouseover-highlighted entity IDs in these, the key is a string and the value is an int; @@ -189,38 +31,56 @@ function EntitySelection() // Public properties: //-------------------------------- - this.groups = new EntityGroups(); // the selection entity groups must be reset whenever the selection changes this.dirty = false; // set whenever the selection has changed } -EntitySelection.prototype.getPrimaryTemplateName = function() +// Deselect everything but entities of the chosen type if the modifier is true +// otherwise deselect just the chosen entity +EntitySelection.prototype.makePrimarySelection = function(primaryIndex, modifierKey) { - var entId = g_Selection.toList()[this.primary]; - var entState = Engine.GuiInterfaceCall("GetEntityState", entId); - - if (entState) - return entState.template - - return undefined; -}; + var ents = []; + var selection = this.toList(); -EntitySelection.prototype.getPrimary = function() -{ - return this.primary; -}; + if (modifierKey) + { + var primaryEntState = Engine.GuiInterfaceCall("GetEntityState", selection[primaryIndex]); + if (!primaryEntState) + return; -EntitySelection.prototype.setPrimary = function(index) -{ - if (g_Selection.toList().length > index) - this.primary = index; + for (var i = 0; i < selection.length; i++) + { + var entState = Engine.GuiInterfaceCall("GetEntityState", selection[i]); + if (!entState) + return; + + if (entState.template == primaryEntState.template) + ents.push(selection[i]); + } + } else - console.write("Warning: \"index\" is larger than g_Selection.toList().length: Cannot set Primary Selection."); -}; + { + ents.push(selection[primaryIndex]); + } -EntitySelection.prototype.resetPrimary = function() + this.reset(); + this.addList(ents); +} + +// Get a list of the template names +EntitySelection.prototype.getTemplateNames = function() { - this.primary = 0; // the primary selection must be reset whenever the selection changes -}; + var templateNames = []; + var ents = this.toList(); + + for each (var ent in ents) + { + var entState = Engine.GuiInterfaceCall("GetEntityState", ent); + if (entState) + templateNames.push(entState.template); + } + + return templateNames; +} // Update the selection to take care of changes (like units that have been killed) EntitySelection.prototype.updateSelection = function() @@ -228,13 +88,13 @@ EntitySelection.prototype.updateSelection = function() var numberRemoved = 0; var i = 0; - for each (var unit in this.selected) + for each (var ent in this.selected) { - var entState = Engine.GuiInterfaceCall("GetEntityState", unit); + var entState = Engine.GuiInterfaceCall("GetEntityState", ent); if (!entState) { - delete this.selected[unit]; + delete this.selected[ent]; numberRemoved++; } @@ -242,11 +102,7 @@ EntitySelection.prototype.updateSelection = function() } if (numberRemoved > 0) - { this.dirty = true; - this.groups.createGroups(this.toList()); - this.resetPrimary(); // TODO: should probably set this to a unit of the same type as the unit that was removed... - } }; EntitySelection.prototype.toggle = function(ent) @@ -287,8 +143,6 @@ EntitySelection.prototype.reset = function() _setHighlight(this.toList(), g_InactiveSelectionColour); _setMotionOverlay(this.toList(), false); this.selected = {}; - this.resetPrimary(); - this.groups.reset(); this.dirty = true; }; diff --git a/binaries/data/mods/public/gui/session_new/selection_details.js b/binaries/data/mods/public/gui/session_new/selection_details.js index 5f60b2ab3e..baabfef351 100644 --- a/binaries/data/mods/public/gui/session_new/selection_details.js +++ b/binaries/data/mods/public/gui/session_new/selection_details.js @@ -1,96 +1,30 @@ const RESOURCE_ICON_CELL_IDS = {food : 0, wood : 1, stone : 2, metal : 3}; -// Called by unit selection buttons -function changePrimarySelectionGroup(entType) +function layoutSelectionMultiple() { - g_Selection.groups.setPrimary(g_Selection.groups.getGroupNumber(entType)); // set primary group - g_Selection.setPrimary(g_Selection.groups.getGroup(entType).firstOfType); // set primary selection - resetCycleIndex(); + getGUIObjectByName("sdSpecific").hidden = true; + getGUIObjectByName("sdIcon").hidden = true; + getGUIObjectByName("sdStatsArea").hidden = true; + getGUIObjectByName("sdHealth").hidden = true; + getGUIObjectByName("sdStamina").hidden = true; } -// Cycle through the units in the main icon -var cycleIndex = 0; -var displayedCycleIndex = 1; - -function resetCycleIndex() +function layoutSelectionSingle(entState) { - cycleIndex = 0; - displayedCycleIndex = 1; -} - -function cycleThroughSelection() -{ - var selection = g_Selection.toList(); + getGUIObjectByName("sdSpecific").hidden = false; + getGUIObjectByName("sdIcon").hidden = false; + getGUIObjectByName("sdStatsArea").hidden = false; - if (selection.length > 1) + if (entState.maxHitpoints != undefined) + getGUIObjectByName("sdHealth").hidden = false; + + var player = Engine.GetPlayerID(); + if (entState.player == player || g_DevSettings.controlAll) { - var primaryTemplateName = g_Selection.getPrimaryTemplateName(); - var primaryIndex = g_Selection.getPrimary(); - var startIndex = cycleIndex; - var endIndex = selection.length-1; - - cycleIndex = ((cycleIndex < endIndex)? cycleIndex+1 : 0); - - while (cycleIndex != startIndex) - { - var entState = Engine.GuiInterfaceCall("GetEntityState", selection[cycleIndex]); - if (!entState) - return; - - var equivalentTemplateNames; - if (g_GroupSelectionByRank) - equivalentTemplateNames = templatesEqualWithoutRank(primaryTemplateName, entState.template); - else - equivalentTemplateNames = (primaryTemplateName == entState.template); - - if ((cycleIndex != primaryIndex) && equivalentTemplateNames) - { - var typeCount = g_Selection.groups.getGroup(entState.template).typeCount; - displayedCycleIndex = ((displayedCycleIndex < typeCount)? displayedCycleIndex+1 : 1); - g_Selection.setPrimary(cycleIndex); - break; - } - - cycleIndex = ((cycleIndex < endIndex)? cycleIndex+1 : 0); - } - } -} - -function reverseCycleThroughSelection() -{ - var selection = g_Selection.toList(); - - if (selection.length > 1) - { - var primaryTemplateName = g_Selection.getPrimaryTemplateName(); - var primaryIndex = g_Selection.getPrimary(); - var startIndex = cycleIndex; - var endIndex = selection.length-1; - - cycleIndex = ((cycleIndex > 0)? cycleIndex-1 : endIndex); - - while (cycleIndex != startIndex) - { - var entState = Engine.GuiInterfaceCall("GetEntityState", selection[cycleIndex]); - if (!entState) - return; - - var equivalentTemplateNames; - if (g_GroupSelectionByRank) - equivalentTemplateNames = templatesEqualWithoutRank(primaryTemplateName, entState.template); - else - equivalentTemplateNames = (primaryTemplateName == entState.template); - - if ((cycleIndex != primaryIndex) && equivalentTemplateNames) - { - var typeCount = g_Selection.groups.getGroup(entState.template).typeCount; - displayedCycleIndex = ((displayedCycleIndex > 1)? displayedCycleIndex-1 : typeCount); - g_Selection.setPrimary(cycleIndex); - break; - } - - cycleIndex = ((cycleIndex > 0)? cycleIndex-1 : endIndex); - } +// if (entState.stamina != undefined) + getGUIObjectByName("sdStamina").hidden = false; +// else +// getGUIObjectByName("sdStamina").hidden = true; } } @@ -107,10 +41,10 @@ function displayGeneralInfo(playerState, entState, template) getGUIObjectByName("sdRankIcon").cell_id = rankId; var rankText = getRankTitle(rankId); - rankText = (rankText? " (" + rankText + ")" : "" ); + rankText = (rankText? " (" + rankText + ")" : ""); // Specific Name - var name = template.name.specific + rankText; // (eliteStatus? "Elite " + template.name.specific : template.name.specific); + var name = template.name.specific + rankText; getGUIObjectByName("sdSpecific").caption = name; iconTooltip += "[font=\"serif-bold-16\"]" + name + "[/font]"; @@ -126,20 +60,19 @@ function displayGeneralInfo(playerState, entState, template) getGUIObjectByName("sdPlayer").textcolor = playerColor; // Hitpoints - if (entState.hitpoints != undefined) + if (entState.maxHitpoints != undefined) { - var healthSize = getGUIObjectByName("sdHealthBar").size; + var unitHealthBar = getGUIObjectByName("sdHealthBar"); + var healthSize = unitHealthBar.size; healthSize.rright = 100*Math.max(0, Math.min(1, entState.hitpoints / entState.maxHitpoints)); - getGUIObjectByName("sdHealthBar").size = healthSize; + unitHealthBar.size = healthSize; var tooltipHitPoints = "[font=\"serif-bold-13\"]Hitpoints [/font]" + entState.hitpoints + "/" + entState.maxHitpoints; getGUIObjectByName("sdHealth").tooltip = tooltipHitPoints; - getGUIObjectByName("sdHealth").hidden = false; iconTooltip += "\n" + tooltipHitPoints; } else { - getGUIObjectByName("sdHealth").hidden = true; getGUIObjectByName("sdHealth").tooltip = ""; } @@ -206,7 +139,7 @@ function updateSelectionDetails(simState) /* 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()]); + var entState = Engine.GuiInterfaceCall("GetEntityState", selection[0]); if (!entState) return; @@ -217,28 +150,9 @@ function updateSelectionDetails(simState) // Choose the highest ranked version of the primary selection // Different selection details are shown based on whether multiple units or a single unit is selected if (selection.length > 1) - { - var typeCount = g_Selection.groups.getGroup(entState.template).typeCount; - getGUIObjectByName("sdSelectionCount").caption = ((typeCount > 1)? displayedCycleIndex + "/" + typeCount : ""); - - // Show cycle area if there is more than one unit of that type - if (typeCount > 1) - getGUIObjectByName("sdCycleArea").hidden = false; - else - getGUIObjectByName("sdCycleArea").hidden = true; - - // Hide stats area if there is more thanone group - if (g_Selection.groups.getLength() > 1) - getGUIObjectByName("sdStatsArea").hidden = true; - else - getGUIObjectByName("sdStatsArea").hidden = false; - } + layoutSelectionMultiple(); else - { - getGUIObjectByName("sdSelectionCount").caption = ""; - getGUIObjectByName("sdCycleArea").hidden = true; - getGUIObjectByName("sdStatsArea").hidden = false; - } + layoutSelectionSingle(entState); var template = Engine.GuiInterfaceCall("GetTemplateData", entState.template); diff --git a/binaries/data/mods/public/gui/session_new/session.js b/binaries/data/mods/public/gui/session_new/session.js index 73d06fd113..2aa165e356 100644 --- a/binaries/data/mods/public/gui/session_new/session.js +++ b/binaries/data/mods/public/gui/session_new/session.js @@ -139,7 +139,7 @@ function updateDebug(simState) var selection = g_Selection.toList(); if (selection.length) { - var entState = Engine.GuiInterfaceCall("GetEntityState", selection[g_Selection.getPrimary()]); + var entState = Engine.GuiInterfaceCall("GetEntityState", selection[0]); if (entState) { var template = Engine.GuiInterfaceCall("GetTemplateData", entState.template); @@ -276,22 +276,3 @@ function getFormalCivName(civ) return "Gaia"; } } - -/* -function getTemplateCategory(templateName) -{ - var slashIndex = templateName.search("/"); - - if (slashIndex >= 0) - return templateName.substring(slashIndex+1, templateName.search("_")); - - return "unknown category"; -} -*/ - - -function templatesEqualWithoutRank(templateName1, templateName2) -{ - return ((templateName1.substring(0, templateName1.length-2) == templateName2.substring(0, templateName2.length-2))? true : false); -} - diff --git a/binaries/data/mods/public/gui/session_new/session.xml b/binaries/data/mods/public/gui/session_new/session.xml index 2ef335d7d0..06bdc86044 100644 --- a/binaries/data/mods/public/gui/session_new/session.xml +++ b/binaries/data/mods/public/gui/session_new/session.xml @@ -126,7 +126,7 @@ Settings @@ -156,11 +156,6 @@ toggleDeveloperOverlay(); - - Group Selections by Rank - - groupSelectionByRank(this.checked); - @@ -296,19 +291,20 @@