Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/session/input.js
Show First 20 Lines • Show All 1,124 Lines • ▼ Show 20 Lines | function handleInputAfterGui(ev) | ||||
return false; | return false; | ||||
} | } | ||||
function doAction(action, ev) | function doAction(action, ev) | ||||
{ | { | ||||
if (!controlsPlayer(g_ViewedPlayer)) | if (!controlsPlayer(g_ViewedPlayer)) | ||||
return false; | return false; | ||||
// If shift is down, add the order to the unit's order queue instead | return handleUnitAction(Engine.GetTerrainAtScreenPoint(ev.x, ev.y), action); | ||||
// of running it immediately | |||||
var orderone = Engine.HotkeyIsPressed("session.orderone"); | |||||
var queued = Engine.HotkeyIsPressed("session.queue"); | |||||
var target = Engine.GetTerrainAtScreenPoint(ev.x, ev.y); | |||||
if (g_UnitActions[action.type] && g_UnitActions[action.type].execute) | |||||
{ | |||||
let selection = g_Selection.toList(); | |||||
if (orderone) | |||||
{ | |||||
// pick the first unit that can do this order. | |||||
let unit = selection.find(entity => | |||||
["preSelectedActionCheck", "hotkeyActionCheck", "actionCheck"].some(method => | |||||
g_UnitActions[action.type][method] && | |||||
g_UnitActions[action.type][method](action.target || undefined, [entity]) | |||||
)); | |||||
if (unit) | |||||
{ | |||||
selection = [unit]; | |||||
g_Selection.removeList(selection); | |||||
} | |||||
} | |||||
return g_UnitActions[action.type].execute(target, action, selection, queued); | |||||
} | } | ||||
error("Invalid action.type " + action.type); | |||||
return false; | |||||
} | |||||
function positionUnitsFreehandSelectionMouseMove(ev) | function positionUnitsFreehandSelectionMouseMove(ev) | ||||
{ | { | ||||
// Converting the input line into a List of points. | // Converting the input line into a List of points. | ||||
// For better performance the points must have a minimum distance to each other. | // For better performance the points must have a minimum distance to each other. | ||||
let target = Vector2D.from3D(Engine.GetTerrainAtScreenPoint(ev.x, ev.y)); | let target = Vector2D.from3D(Engine.GetTerrainAtScreenPoint(ev.x, ev.y)); | ||||
if (!g_FreehandSelection_InputLine.length || | if (!g_FreehandSelection_InputLine.length || | ||||
target.distanceToSquared(g_FreehandSelection_InputLine[g_FreehandSelection_InputLine.length - 1]) >= | target.distanceToSquared(g_FreehandSelection_InputLine[g_FreehandSelection_InputLine.length - 1]) >= | ||||
▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | |||||
function handleMinimapEvent(target) | function handleMinimapEvent(target) | ||||
{ | { | ||||
// Partly duplicated from handleInputAfterGui(), but with the input being | // Partly duplicated from handleInputAfterGui(), but with the input being | ||||
// world coordinates instead of screen coordinates. | // world coordinates instead of screen coordinates. | ||||
if (inputState != INPUT_NORMAL) | if (inputState != INPUT_NORMAL) | ||||
return false; | return false; | ||||
var fromMinimap = true; | let action = determineAction(undefined, undefined, true); | ||||
var action = determineAction(undefined, undefined, fromMinimap); | |||||
if (!action) | if (!action) | ||||
return false; | return false; | ||||
var selection = g_Selection.toList(); | return handleUnitAction(target, action); | ||||
} | |||||
var queued = Engine.HotkeyIsPressed("session.queue"); | function handleUnitAction(target, action) | ||||
if (g_UnitActions[action.type] && g_UnitActions[action.type].execute) | { | ||||
return g_UnitActions[action.type].execute(target, action, selection, queued); | 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; | ||||
} | } | ||||
let selection = g_Selection.toList(); | |||||
if (Engine.HotkeyIsPressed("session.orderone")) | |||||
{ | |||||
// Pick the first unit that can do this order. | |||||
let unit = selection.find(entity => | |||||
["preSelectedActionCheck", "hotkeyActionCheck", "actionCheck"].some(method => | |||||
g_UnitActions[action.type][method] && | |||||
g_UnitActions[action.type][method](action.target || undefined, [entity]) | |||||
)); | |||||
if (unit) | |||||
{ | |||||
selection = [unit]; | |||||
g_Selection.removeList(selection); | |||||
} | |||||
} | |||||
// If the session.queue hotkey is down, add the order to the unit's order queue instead | |||||
// of running it immediately | |||||
return g_UnitActions[action.type].execute(target, action, selection, Engine.HotkeyIsPressed("session.queue")); | |||||
} | |||||
function getEntityLimitAndCount(playerState, entType) | function getEntityLimitAndCount(playerState, entType) | ||||
{ | { | ||||
let ret = { | let ret = { | ||||
"entLimit": undefined, | "entLimit": undefined, | ||||
"entCount": undefined, | "entCount": undefined, | ||||
"entLimitChangers": undefined, | "entLimitChangers": undefined, | ||||
"canBeAddedCount": undefined | "canBeAddedCount": undefined | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 374 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator