mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 20:04:13 +00:00
Colorize selected units in observermode, reviewed by elexis, fixes #4167
This was SVN commit r18979.
This commit is contained in:
@@ -985,7 +985,7 @@ function handleInputAfterGui(ev)
|
||||
Engine.CameraFollow(0);
|
||||
}
|
||||
|
||||
if ((now.getTime() - doubleClickTimer < doubleClickTime) && (selectedEntity == prevClickedEntity))
|
||||
if (now.getTime() - doubleClickTimer < doubleClickTime && selectedEntity == prevClickedEntity)
|
||||
{
|
||||
// Double click or triple click has occurred
|
||||
var showOffscreen = Engine.HotkeyIsPressed("selection.offscreen");
|
||||
@@ -999,24 +999,24 @@ function handleInputAfterGui(ev)
|
||||
// Select similar units regardless of rank
|
||||
templateToMatch = GetEntityState(selectedEntity).identity.selectionGroupName;
|
||||
if (templateToMatch)
|
||||
{
|
||||
matchRank = false;
|
||||
}
|
||||
else
|
||||
{ // No selection group name defined, so fall back to exact match
|
||||
// No selection group name defined, so fall back to exact match
|
||||
templateToMatch = GetEntityState(selectedEntity).template;
|
||||
}
|
||||
|
||||
doubleClicked = true;
|
||||
// Reset the timer so the user has an extra period 'doubleClickTimer' to do a triple-click
|
||||
doubleClickTimer = now.getTime();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Double click has already occurred, so this is a triple click.
|
||||
// Select units matching exact template name (same rank)
|
||||
templateToMatch = GetEntityState(selectedEntity).template;
|
||||
}
|
||||
|
||||
// Remove the player prefix (e.g. "p3&")
|
||||
let index = templateToMatch.indexOf("&");
|
||||
if (index != -1)
|
||||
templateToMatch = templateToMatch.slice(index+1);
|
||||
|
||||
// TODO: Should we handle "control all units" here as well?
|
||||
ents = Engine.PickSimilarPlayerEntities(templateToMatch, showOffscreen, matchRank, false);
|
||||
@@ -1034,13 +1034,9 @@ function handleInputAfterGui(ev)
|
||||
|
||||
// Update the list of selected units
|
||||
if (Engine.HotkeyIsPressed("selection.add"))
|
||||
{
|
||||
g_Selection.addList(ents);
|
||||
}
|
||||
else if (Engine.HotkeyIsPressed("selection.remove"))
|
||||
{
|
||||
g_Selection.removeList(ents);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_Selection.reset();
|
||||
@@ -1375,15 +1371,11 @@ function addTrainingToQueue(selection, trainEntType, playerState)
|
||||
// Check if we are training in the same building(s) as the last batch
|
||||
var sameEnts = false;
|
||||
if (batchTrainingEntities.length == selection.length)
|
||||
{
|
||||
// NOTE: We just check if the arrays are the same and if the order is the same
|
||||
// If the order changed, we have a new selection and we should create a new batch.
|
||||
for (var i = 0; i < batchTrainingEntities.length; ++i)
|
||||
{
|
||||
if (!(sameEnts = batchTrainingEntities[i] == selection[i]))
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If we're already creating a batch of this unit (in the same building(s)), then just extend it
|
||||
// (if training limits allow)
|
||||
if (sameEnts && batchTrainingType == trainEntType)
|
||||
|
||||
@@ -137,16 +137,10 @@ EntityGroups.prototype.getEntsByName = function(templateName)
|
||||
*/
|
||||
EntityGroups.prototype.getEntsGrouped = function()
|
||||
{
|
||||
var templateNames = this.getTemplateNames();
|
||||
var list = [];
|
||||
for (var t of templateNames)
|
||||
{
|
||||
list.push({
|
||||
"ents": this.getEntsByName(t),
|
||||
"template": t,
|
||||
});
|
||||
}
|
||||
return list;
|
||||
return this.getTemplateNames().map(template => ({
|
||||
"ents": this.getEntsByName(template),
|
||||
"template": template
|
||||
}));
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -186,14 +180,9 @@ function EntitySelection()
|
||||
*/
|
||||
EntitySelection.prototype.makePrimarySelection = function(templateName, modifierKey)
|
||||
{
|
||||
var template = GetTemplateData(templateName);
|
||||
var key = template.selectionGroupName || templateName;
|
||||
|
||||
var ents = [];
|
||||
if (modifierKey)
|
||||
ents = this.groups.getEntsByNameInverse(key);
|
||||
else
|
||||
ents = this.groups.getEntsByName(key);
|
||||
let ents = modifierKey ?
|
||||
this.groups.getEntsByNameInverse(templateName) :
|
||||
this.groups.getEntsByName(templateName);
|
||||
|
||||
this.reset();
|
||||
this.addList(ents);
|
||||
|
||||
@@ -897,16 +897,15 @@ g_SelectionPanels.Selection = {
|
||||
{
|
||||
if (unitEntStates.length < 2)
|
||||
return [];
|
||||
return g_Selection.groups.getTemplateNames();
|
||||
return g_Selection.groups.getEntsGrouped();
|
||||
},
|
||||
"setupButton": function(data)
|
||||
{
|
||||
let template = GetTemplateData(data.item);
|
||||
let template = GetTemplateData(data.item.template);
|
||||
if (!template)
|
||||
return false;
|
||||
|
||||
let ents = g_Selection.groups.getEntsByName(data.item);
|
||||
for (let ent of ents)
|
||||
for (let ent of data.item.ents)
|
||||
{
|
||||
let state = GetEntityState(ent);
|
||||
|
||||
@@ -939,17 +938,23 @@ g_SelectionPanels.Selection = {
|
||||
}
|
||||
}
|
||||
|
||||
let unitOwner = GetEntityState(data.item.ents[0]).player;
|
||||
let tooltip = getEntityNames(template);
|
||||
if (data.carried)
|
||||
tooltip += "\n" + Object.keys(data.carried).map(res =>
|
||||
costIcon(res) + data.carried[res]
|
||||
).join(" ");
|
||||
if (g_IsObserver)
|
||||
tooltip += "\n" + sprintf(translate("Player: %(playername)s"), {
|
||||
"playername": g_Players[unitOwner].name
|
||||
});
|
||||
data.button.tooltip = tooltip;
|
||||
data.guiSelection.sprite = "color:" + (g_IsObserver ? rgbToGuiColor(g_Players[unitOwner].color) + " 120": "0 0 0 0");
|
||||
|
||||
data.countDisplay.caption = ents.length || "";
|
||||
data.countDisplay.caption = data.item.ents.length || "";
|
||||
|
||||
data.button.onPress = function() { changePrimarySelectionGroup(data.item, false); };
|
||||
data.button.onPressRight = function() { changePrimarySelectionGroup(data.item, true); };
|
||||
data.button.onPress = function() { changePrimarySelectionGroup(data.item.template, false); };
|
||||
data.button.onPressRight = function() { changePrimarySelectionGroup(data.item.template, true); };
|
||||
|
||||
if (template.icon)
|
||||
data.icon.sprite = "stretched:session/portraits/" + template.icon;
|
||||
|
||||
+1
@@ -8,6 +8,7 @@
|
||||
<object size="0 0 100% 100%">
|
||||
<repeat count="16">
|
||||
<object name="unitSelectionButton[n]" hidden="true" style="iconButton" type="button" size="0 0 36 36" tooltip_style="sessionToolTipBold" z="100">
|
||||
<object name="unitSelectionSelection[n]" type="image" ghost="true" size="0 0 100% 100%"/>
|
||||
<object name="unitSelectionIcon[n]" type="image" ghost="true" size="3 3 33 33"/>
|
||||
<object name="unitSelectionCount[n]" ghost="true" style="groupIconsText" type="text" size="0 0 100% 100%"/>
|
||||
<object size="0 100%-3 100% 100%" name="unitSelectionHealth[n]" ghost="true">
|
||||
|
||||
@@ -385,8 +385,8 @@ GuiInterface.prototype.GetEntityState = function(player, ent)
|
||||
"possibleStances": cmpUnitAI.GetPossibleStances(),
|
||||
"isIdle":cmpUnitAI.IsIdle(),
|
||||
};
|
||||
// Add some information needed for ungarrisoning
|
||||
if (cmpUnitAI.IsGarrisoned() && ret.player !== undefined)
|
||||
// Add some information to differentiate between owner
|
||||
if (ret.player !== undefined)
|
||||
ret.template = "p" + ret.player + "&" + ret.template;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user