Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/session/input.js
Show All 26 Lines | |||||
const INPUT_BUILDING_CLICK = 4; | const INPUT_BUILDING_CLICK = 4; | ||||
const INPUT_BUILDING_DRAG = 5; | const INPUT_BUILDING_DRAG = 5; | ||||
const INPUT_BATCHTRAINING = 6; | const INPUT_BATCHTRAINING = 6; | ||||
const INPUT_PRESELECTEDACTION = 7; | const INPUT_PRESELECTEDACTION = 7; | ||||
const INPUT_BUILDING_WALL_CLICK = 8; | const INPUT_BUILDING_WALL_CLICK = 8; | ||||
const INPUT_BUILDING_WALL_PATHING = 9; | const INPUT_BUILDING_WALL_PATHING = 9; | ||||
const INPUT_UNIT_POSITION_START = 10; | const INPUT_UNIT_POSITION_START = 10; | ||||
const INPUT_UNIT_POSITION = 11; | const INPUT_UNIT_POSITION = 11; | ||||
const INPUT_FLARE = 12; | |||||
var inputState = INPUT_NORMAL; | var inputState = INPUT_NORMAL; | ||||
const INVALID_ENTITY = 0; | const INVALID_ENTITY = 0; | ||||
var mouseX = 0; | var mouseX = 0; | ||||
var mouseY = 0; | var mouseY = 0; | ||||
var mouseIsOverObject = false; | var mouseIsOverObject = false; | ||||
Show All 31 Lines | |||||
/** | /** | ||||
* Store the clicked entity on mousedown or mouseup for single/double/triple clicks to select entities. | * Store the clicked entity on mousedown or mouseup for single/double/triple clicks to select entities. | ||||
* If any mousedown or mouseup of a sequence of clicks lands on a unit, | * If any mousedown or mouseup of a sequence of clicks lands on a unit, | ||||
* that unit will be selected, which makes it easier to click on moving units. | * that unit will be selected, which makes it easier to click on moving units. | ||||
*/ | */ | ||||
var clickedEntity = INVALID_ENTITY; | var clickedEntity = INVALID_ENTITY; | ||||
/** | |||||
* Store the last time the flare functionality was used to prevent overusage. | |||||
*/ | |||||
var g_LastFlareTime; | |||||
/** | |||||
* The duration in ms for which we disable flaring after each flare to prevent overusage. | |||||
*/ | |||||
const g_FlareCooldown = 5000; | |||||
// Same double-click behaviour for hotkey presses. | // Same double-click behaviour for hotkey presses. | ||||
const doublePressTime = 500; | const doublePressTime = 500; | ||||
var doublePressTimer = 0; | var doublePressTimer = 0; | ||||
var prevHotkey = 0; | var prevHotkey = 0; | ||||
function updateCursorAndTooltip() | function updateCursorAndTooltip() | ||||
{ | { | ||||
let cursorSet = false; | let cursorSet = false; | ||||
let tooltipSet = false; | let tooltipSet = false; | ||||
let informationTooltip = Engine.GetGUIObjectByName("informationTooltip"); | let informationTooltip = Engine.GetGUIObjectByName("informationTooltip"); | ||||
if (!mouseIsOverObject && (inputState == INPUT_NORMAL || inputState == INPUT_PRESELECTEDACTION) || g_MiniMapPanel.isMouseOverMiniMap()) | if (inputState == INPUT_FLARE || inputState == INPUT_NORMAL && Engine.HotkeyIsPressed("session.flare") && !g_IsObserver) | ||||
{ | |||||
Engine.SetCursor("action-flare"); | |||||
cursorSet = true; | |||||
} | |||||
else if (!mouseIsOverObject && (inputState == INPUT_NORMAL || inputState == INPUT_PRESELECTEDACTION) || g_MiniMapPanel.isMouseOverMiniMap()) | |||||
{ | { | ||||
let action = determineAction(mouseX, mouseY, g_MiniMapPanel.isMouseOverMiniMap()); | let action = determineAction(mouseX, mouseY, g_MiniMapPanel.isMouseOverMiniMap()); | ||||
if (action) | if (action) | ||||
{ | { | ||||
if (action.cursor) | if (action.cursor) | ||||
{ | { | ||||
Engine.SetCursor(action.cursor); | Engine.SetCursor(action.cursor); | ||||
cursorSet = true; | cursorSet = true; | ||||
▲ Show 20 Lines • Show All 704 Lines • ▼ Show 20 Lines | case "mousemotion": | ||||
if (ent != INVALID_ENTITY) | if (ent != INVALID_ENTITY) | ||||
g_Selection.setHighlightList([ent]); | g_Selection.setHighlightList([ent]); | ||||
else | else | ||||
g_Selection.setHighlightList([]); | g_Selection.setHighlightList([]); | ||||
return false; | return false; | ||||
case "mousebuttondown": | case "mousebuttondown": | ||||
if (Engine.HotkeyIsPressed("session.flare") && controlsPlayer(g_ViewedPlayer)) | |||||
{ | |||||
triggerFlareAction(Engine.GetTerrainAtScreenPoint(ev.x, ev.y)); | |||||
return true; | |||||
} | |||||
if (ev.button == SDL_BUTTON_LEFT) | if (ev.button == SDL_BUTTON_LEFT) | ||||
{ | { | ||||
g_DragStart = new Vector2D(ev.x, ev.y); | g_DragStart = new Vector2D(ev.x, ev.y); | ||||
inputState = INPUT_SELECTING; | inputState = INPUT_SELECTING; | ||||
// If a single click occured, reset the clickedEntity. | // If a single click occured, reset the clickedEntity. | ||||
// Also set it if we're double/triple clicking and missed the unit earlier. | // Also set it if we're double/triple clicking and missed the unit earlier. | ||||
if (ev.clicks == 1 || clickedEntity == INVALID_ENTITY) | if (ev.clicks == 1 || clickedEntity == INVALID_ENTITY) | ||||
clickedEntity = Engine.PickEntityAtPoint(ev.x, ev.y); | clickedEntity = Engine.PickEntityAtPoint(ev.x, ev.y); | ||||
▲ Show 20 Lines • Show All 285 Lines • ▼ Show 20 Lines | case "hotkeydown": | ||||
placementSupport.angle -= rotation_step; | placementSupport.angle -= rotation_step; | ||||
updateBuildingPlacementPreview(); | updateBuildingPlacementPreview(); | ||||
break; | break; | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
break; | break; | ||||
case INPUT_FLARE: | |||||
if (ev.type == "mousebuttondown") | |||||
{ | |||||
if (ev.button == SDL_BUTTON_LEFT && controlsPlayer(g_ViewedPlayer)) | |||||
{ | |||||
triggerFlareAction(Engine.GetTerrainAtScreenPoint(ev.x, ev.y)); | |||||
inputState = INPUT_NORMAL; | |||||
return true; | |||||
} | |||||
else if (ev.button == SDL_BUTTON_RIGHT) | |||||
{ | |||||
inputState = INPUT_NORMAL; | |||||
return true; | |||||
} | |||||
} | |||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
function doAction(action, ev) | function doAction(action, ev) | ||||
{ | { | ||||
if (!controlsPlayer(g_ViewedPlayer)) | if (!controlsPlayer(g_ViewedPlayer)) | ||||
return false; | return false; | ||||
▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | function positionUnitsFreehandSelectionMouseUp(ev) | ||||
Engine.GuiInterfaceCall("PlaySound", { | Engine.GuiInterfaceCall("PlaySound", { | ||||
"name": "order_walk", | "name": "order_walk", | ||||
"entity": selection[0] | "entity": selection[0] | ||||
}); | }); | ||||
return true; | return true; | ||||
} | } | ||||
function triggerFlareAction(target) | |||||
{ | |||||
let now = Date.now(); | |||||
if (g_LastFlareTime && now < g_LastFlareTime + g_FlareCooldown) | |||||
return; | |||||
g_LastFlareTime = now; | |||||
displayFlare(target, Engine.GetPlayerID()); | |||||
Engine.PlayUISound(g_FlareSound, false); | |||||
Engine.PostNetworkCommand({ | |||||
"type": "map-flare", | |||||
"target": target | |||||
}); | |||||
} | |||||
function handleUnitAction(target, action) | function handleUnitAction(target, action) | ||||
{ | { | ||||
if (!g_UnitActions[action.type] || !g_UnitActions[action.type].execute) | if (!g_UnitActions[action.type] || !g_UnitActions[action.type].execute) | ||||
{ | { | ||||
error("Invalid action.type " + action.type); | error("Invalid action.type " + action.type); | ||||
return false; | return false; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 426 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator