Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/session/input.js
Show First 20 Lines • Show All 275 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
function ownsEntity(ent) | function ownsEntity(ent) | ||||
{ | { | ||||
let entState = GetEntityState(ent); | let entState = GetEntityState(ent); | ||||
return entState && entState.player == g_ViewedPlayer; | return entState && entState.player == g_ViewedPlayer; | ||||
} | } | ||||
function isSnapToEdgesEnabled() | |||||
{ | |||||
let config = Engine.ConfigDB_GetValue("user", "gui.session.snaptoedges"); | |||||
let hotkeyPressed = Engine.HotkeyIsPressed("session.snaptoedges"); | |||||
return hotkeyPressed == (config == "optional"); | |||||
} | |||||
function tryPlaceBuilding(queued) | function tryPlaceBuilding(queued) | ||||
{ | { | ||||
if (placementSupport.mode !== "building") | if (placementSupport.mode !== "building") | ||||
{ | { | ||||
error("tryPlaceBuilding expected 'building', got '" + placementSupport.mode + "'"); | error("tryPlaceBuilding expected 'building', got '" + placementSupport.mode + "'"); | ||||
return false; | return false; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 425 Lines • ▼ Show 20 Lines | case "mousemotion": | ||||
placementSupport.angle = placementSupport.position.horizAngleTo(Engine.GetTerrainAtScreenPoint(ev.x, ev.y)); | placementSupport.angle = placementSupport.position.horizAngleTo(Engine.GetTerrainAtScreenPoint(ev.x, ev.y)); | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
// If the mouse is near the center, snap back to the default orientation | // If the mouse is near the center, snap back to the default orientation | ||||
placementSupport.SetDefaultAngle(); | placementSupport.SetDefaultAngle(); | ||||
} | } | ||||
let snapToEdges = Engine.HotkeyIsPressed("session.snaptoedges"); | |||||
let snapData = Engine.GuiInterfaceCall("GetFoundationSnapData", { | let snapData = Engine.GuiInterfaceCall("GetFoundationSnapData", { | ||||
"template": placementSupport.template, | "template": placementSupport.template, | ||||
"x": placementSupport.position.x, | "x": placementSupport.position.x, | ||||
"z": placementSupport.position.z, | "z": placementSupport.position.z, | ||||
"angle": placementSupport.angle, | "angle": placementSupport.angle, | ||||
"snapToEdges": snapToEdges && Engine.GetEdgesOfStaticObstructionsOnScreenNearTo( | "snapToEdges": isSnapToEdgesEnabled() && Engine.GetEdgesOfStaticObstructionsOnScreenNearTo( | ||||
placementSupport.position.x, placementSupport.position.z) | placementSupport.position.x, placementSupport.position.z) | ||||
}); | }); | ||||
if (snapData) | if (snapData) | ||||
{ | { | ||||
placementSupport.angle = snapData.angle; | placementSupport.angle = snapData.angle; | ||||
placementSupport.position.x = snapData.x; | placementSupport.position.x = snapData.x; | ||||
placementSupport.position.z = snapData.z; | placementSupport.position.z = snapData.z; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 304 Lines • ▼ Show 20 Lines | case "mousemotion": | ||||
// cancel if not enough resources | // cancel if not enough resources | ||||
if (placementSupport.template && Engine.GuiInterfaceCall("GetNeededResources", { "cost": GetTemplateData(placementSupport.template).cost })) | if (placementSupport.template && Engine.GuiInterfaceCall("GetNeededResources", { "cost": GetTemplateData(placementSupport.template).cost })) | ||||
{ | { | ||||
placementSupport.Reset(); | placementSupport.Reset(); | ||||
inputState = INPUT_NORMAL; | inputState = INPUT_NORMAL; | ||||
return true; | return true; | ||||
} | } | ||||
let snapToEdges = Engine.HotkeyIsPressed("session.snaptoedges"); | |||||
let snapData = Engine.GuiInterfaceCall("GetFoundationSnapData", { | let snapData = Engine.GuiInterfaceCall("GetFoundationSnapData", { | ||||
"template": placementSupport.template, | "template": placementSupport.template, | ||||
"x": placementSupport.position.x, | "x": placementSupport.position.x, | ||||
"z": placementSupport.position.z, | "z": placementSupport.position.z, | ||||
"snapToEdges": snapToEdges && Engine.GetEdgesOfStaticObstructionsOnScreenNearTo( | "snapToEdges": isSnapToEdgesEnabled() && Engine.GetEdgesOfStaticObstructionsOnScreenNearTo( | ||||
placementSupport.position.x, placementSupport.position.z) | placementSupport.position.x, placementSupport.position.z) | ||||
}); | }); | ||||
if (snapData) | if (snapData) | ||||
{ | { | ||||
placementSupport.angle = snapData.angle; | placementSupport.angle = snapData.angle; | ||||
placementSupport.position.x = snapData.x; | placementSupport.position.x = snapData.x; | ||||
placementSupport.position.z = snapData.z; | placementSupport.position.z = snapData.z; | ||||
} | } | ||||
Show All 10 Lines | case "mousebuttondown": | ||||
var validPlacement = updateBuildingPlacementPreview(); | var validPlacement = updateBuildingPlacementPreview(); | ||||
if (validPlacement !== false) | if (validPlacement !== false) | ||||
inputState = INPUT_BUILDING_WALL_CLICK; | inputState = INPUT_BUILDING_WALL_CLICK; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
placementSupport.position = Engine.GetTerrainAtScreenPoint(ev.x, ev.y); | placementSupport.position = Engine.GetTerrainAtScreenPoint(ev.x, ev.y); | ||||
let snapToEdges = Engine.HotkeyIsPressed("session.snaptoedges"); | if (isSnapToEdgesEnabled()) | ||||
if (snapToEdges) | |||||
{ | { | ||||
let snapData = Engine.GuiInterfaceCall("GetFoundationSnapData", { | let snapData = Engine.GuiInterfaceCall("GetFoundationSnapData", { | ||||
"template": placementSupport.template, | "template": placementSupport.template, | ||||
"x": placementSupport.position.x, | "x": placementSupport.position.x, | ||||
"z": placementSupport.position.z, | "z": placementSupport.position.z, | ||||
"snapToEdges": Engine.GetEdgesOfStaticObstructionsOnScreenNearTo( | "snapToEdges": Engine.GetEdgesOfStaticObstructionsOnScreenNearTo( | ||||
placementSupport.position.x, placementSupport.position.z) | placementSupport.position.x, placementSupport.position.z) | ||||
}); | }); | ||||
▲ Show 20 Lines • Show All 562 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator