Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/session/input.js
Context not available. | |||||
// Number of pixels the mouse can move before the action is considered a drag | // Number of pixels the mouse can move before the action is considered a drag | ||||
var maxDragDelta = 4; | var maxDragDelta = 4; | ||||
// Time in milliseconds in which a double click is recognized | // Store the clicked entity on mousedown or mouseup | ||||
const doubleClickTime = 500; | var clickedEntity = 0; | ||||
elexis: Should have called this `g_ClickedEntity` even if the other names in this file don't abide the… | |||||
var doubleClickTimer = 0; | |||||
var doubleClicked = false; | |||||
// Store the previously clicked entity - ensure a double/triple click happens on the same entity | |||||
var prevClickedEntity = 0; | |||||
// Same double-click behaviour for hotkey presses | // Same double-click behaviour for hotkey presses | ||||
const doublePressTime = 500; | const doublePressTime = 500; | ||||
Not Done Inline ActionsWe usually go with doubleClickDistSquared for this. wraitii: We usually go with doubleClickDistSquared for this. | |||||
Context not available. | |||||
{ | { | ||||
dragStart = [ ev.x, ev.y ]; | dragStart = [ ev.x, ev.y ]; | ||||
inputState = INPUT_SELECTING; | inputState = INPUT_SELECTING; | ||||
// if a single click, always reset the clickedEntity | |||||
// also set it if we're double/triple clicking and missed the unit earlier | |||||
if (ev.clicks == 1 || clickedEntity == INVALID_ENTITY) | |||||
clickedEntity = Engine.PickEntityAtPoint(ev.x, ev.y); | |||||
return true; | return true; | ||||
} | } | ||||
else if (ev.button == SDL_BUTTON_RIGHT) | else if (ev.button == SDL_BUTTON_RIGHT) | ||||
Context not available. | |||||
case "mousebuttonup": | case "mousebuttonup": | ||||
if (ev.button == SDL_BUTTON_LEFT) | if (ev.button == SDL_BUTTON_LEFT) | ||||
{ | { | ||||
var ents = []; | if (clickedEntity == INVALID_ENTITY) | ||||
var selectedEntity = Engine.PickEntityAtPoint(ev.x, ev.y); | clickedEntity = Engine.PickEntityAtPoint(ev.x, ev.y); | ||||
Not Done Inline ActionsAppears wrong to have the input handler change camera controls. If the user wants to follow an entity, why not let him do so? elexis: Appears wrong to have the input handler change camera controls. If the user wants to follow an… | |||||
if (selectedEntity == INVALID_ENTITY) | if (clickedEntity == INVALID_ENTITY) | ||||
{ | { | ||||
if (!Engine.HotkeyIsPressed("selection.add") && !Engine.HotkeyIsPressed("selection.remove")) | if (!Engine.HotkeyIsPressed("selection.add") && !Engine.HotkeyIsPressed("selection.remove")) | ||||
{ | { | ||||
Context not available. | |||||
inputState = INPUT_NORMAL; | inputState = INPUT_NORMAL; | ||||
return true; | return true; | ||||
} | } | ||||
var now = new Date(); | |||||
// If camera following and we select different unit, stop | // If camera following and we select different unit, stop | ||||
if (Engine.GetFollowedEntity() != selectedEntity) | if (Engine.GetFollowedEntity() != clickedEntity) | ||||
Engine.CameraFollow(0); | |||||
var ents = []; | |||||
if (ev.clicks == 1) | |||||
{ | { | ||||
Engine.CameraFollow(0); | ents = [clickedEntity]; | ||||
} | } | ||||
else | |||||
if (now.getTime() - doubleClickTimer < doubleClickTime && selectedEntity == prevClickedEntity) | |||||
{ | { | ||||
// Double click or triple click has occurred | // Double click or triple click has occurred | ||||
var showOffscreen = Engine.HotkeyIsPressed("selection.offscreen"); | var showOffscreen = Engine.HotkeyIsPressed("selection.offscreen"); | ||||
Context not available. | |||||
var templateToMatch; | var templateToMatch; | ||||
// Check for double click or triple click | // Check for double click or triple click | ||||
if (!doubleClicked) | if (ev.clicks == 2) | ||||
{ | { | ||||
// If double click hasn't already occurred, this is a double click. | |||||
// Select similar units regardless of rank | // Select similar units regardless of rank | ||||
templateToMatch = GetEntityState(selectedEntity).identity.selectionGroupName; | templateToMatch = GetEntityState(clickedEntity).identity.selectionGroupName; | ||||
if (templateToMatch) | if (templateToMatch) | ||||
matchRank = false; | matchRank = false; | ||||
else | 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; | templateToMatch = GetEntityState(clickedEntity).template; | ||||
doubleClicked = true; | |||||
// Reset the timer so the user has an extra period 'doubleClickTimer' to do a triple-click | |||||
doubleClickTimer = now.getTime(); | |||||
} | } | ||||
else | else | ||||
// Double click has already occurred, so this is a triple click. | // Triple click | ||||
// Select units matching exact template name (same rank) | // Select units matching exact template name (same rank) | ||||
templateToMatch = GetEntityState(selectedEntity).template; | templateToMatch = GetEntityState(clickedEntity).template; | ||||
// TODO: Should we handle "control all units" here as well? | // TODO: Should we handle "control all units" here as well? | ||||
ents = Engine.PickSimilarPlayerEntities(templateToMatch, showOffscreen, matchRank, false); | ents = Engine.PickSimilarPlayerEntities(templateToMatch, showOffscreen, matchRank, false); | ||||
} | } | ||||
else | |||||
{ | |||||
// It's single click right now but it may become double or triple click | |||||
doubleClicked = false; | |||||
doubleClickTimer = now.getTime(); | |||||
prevClickedEntity = selectedEntity; | |||||
// We only want to include the first picked unit in the selection | |||||
ents = [selectedEntity]; | |||||
} | |||||
// Update the list of selected units | // Update the list of selected units | ||||
if (Engine.HotkeyIsPressed("selection.add")) | if (Engine.HotkeyIsPressed("selection.add")) | ||||
g_Selection.addList(ents); | g_Selection.addList(ents); | ||||
Context not available. |
Wildfire Games · Phabricator
Should have called this g_ClickedEntity even if the other names in this file don't abide the http://trac.wildfiregames.com/wiki/Coding_Conventions yet