Index: binaries/data/mods/public/gui/session/input.js =================================================================== --- binaries/data/mods/public/gui/session/input.js +++ binaries/data/mods/public/gui/session/input.js @@ -46,6 +46,9 @@ const doubleClickTime = 500; var doubleClickTimer = 0; var doubleClicked = false; +var doubleClickDistSquared = 10; // squared number of pixels the mouse may move between clicks of a double click +var prevXClick = 0; +var prevYClick = 0; // Store the previously clicked entity - ensure a double/triple click happens on the same entity var prevClickedEntity = 0; @@ -966,7 +969,12 @@ { var ents = []; var selectedEntity = Engine.PickEntityAtPoint(ev.x, ev.y); - if (selectedEntity == INVALID_ENTITY) + var now = new Date(); + var isDoubleClick = now.getTime() - doubleClickTimer < doubleClickTime + && ((prevXClick - ev.x)*(prevXClick - ev.x) + (prevYClick - ev.y)*(prevYClick - ev.y) <= doubleClickDistSquared); + prevXClick = ev.x; + prevYClick = ev.y; + if (selectedEntity == INVALID_ENTITY && !isDoubleClick) { if (!Engine.HotkeyIsPressed("selection.add") && !Engine.HotkeyIsPressed("selection.remove")) { @@ -977,8 +985,6 @@ return true; } - var now = new Date(); - // If camera following and we select different unit, stop if (Engine.GetFollowedEntity() != selectedEntity) { @@ -985,7 +991,7 @@ Engine.CameraFollow(0); } - if (now.getTime() - doubleClickTimer < doubleClickTime && selectedEntity == prevClickedEntity) + if (isDoubleClick) { // Double click or triple click has occurred var showOffscreen = Engine.HotkeyIsPressed("selection.offscreen"); @@ -997,12 +1003,12 @@ { // If double click hasn't already occurred, this is a double click. // Select similar units regardless of rank - templateToMatch = GetEntityState(selectedEntity).identity.selectionGroupName; + templateToMatch = GetEntityState(prevClickedEntity).identity.selectionGroupName; if (templateToMatch) matchRank = false; else // No selection group name defined, so fall back to exact match - templateToMatch = GetEntityState(selectedEntity).template; + templateToMatch = GetEntityState(prevClickedEntity).template; doubleClicked = true; // Reset the timer so the user has an extra period 'doubleClickTimer' to do a triple-click @@ -1011,7 +1017,7 @@ else // Double click has already occurred, so this is a triple click. // Select units matching exact template name (same rank) - templateToMatch = GetEntityState(selectedEntity).template; + templateToMatch = GetEntityState(prevClickedEntity).template; // TODO: Should we handle "control all units" here as well? ents = Engine.PickSimilarPlayerEntities(templateToMatch, showOffscreen, matchRank, false);