1
0
forked from 0ad/0ad
0ad/binaries/data/mods/public/gui/session_new/input.js

73 lines
1.8 KiB
JavaScript
Raw Normal View History

const SDL_BUTTON_LEFT = 1;
const SDL_BUTTON_MIDDLE = 2;
const SDL_BUTTON_RIGHT = 3;
// TODO: these constants should be defined somewhere else instead, in
// case any other code wants to use them too
var INPUT_NORMAL = 0;
var INPUT_DRAGGING = 1;
var inputState = INPUT_NORMAL;
function handleInputBeforeGui(ev)
{
return false;
}
/*
Selection methods: (not all currently implemented)
- Left-click on entity to select (always chooses the 'closest' one if the mouse is over several).
Includes non-controllable units (e.g. trees, enemy units).
- Double-left-click to select entity plus all of the same type on the screen.
- Triple-left-click to select entity plus all of the same type in the world.
- Left-click-and-drag to select all in region. Only includes controllable units.
- Left-click on empty space to deselect all.
- Hotkeys to select various groups.
- Shift plus left-click on entity to toggle selection of that unit. Only includes controllable.
- Shift plus any other selection method above, to add them to current selection.
*/
function handleInputAfterGui(ev)
{
switch (inputState)
{
case INPUT_NORMAL:
switch (ev.type)
{
case "mousebuttondown":
if (ev.button == SDL_BUTTON_LEFT)
{
var ents = Engine.PickEntitiesAtPoint(ev.x, ev.y);
if (!ents.length)
{
resetEntitySelection();
return true;
}
resetEntitySelection();
addEntitySelection([ents[0]]);
Engine.PostNetworkCommand({"type": "spin", "entities": [ents[0]]});
return true;
}
else if (ev.button == SDL_BUTTON_RIGHT)
{
var ents = getEntitySelection();
if (ents.length)
{
var target = Engine.GetTerrainAtPoint(ev.x, ev.y);
Engine.PostNetworkCommand({"type": "walk", "entities": ents, "x": target.x, "z": target.z});
return true;
}
}
}
break;
}
return false;
}