Changeset View
Standalone View
binaries/data/mods/public/gui/session/input.js
Show First 20 Lines • Show All 716 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(); | ||||
} | } | ||||
var snapData = Engine.GuiInterfaceCall("GetFoundationSnapData", { | let snapToEdge = Engine.HotkeyIsPressed("session.snaptoedge"); | ||||
Stan: let | |||||
Not Done Inline ActionsLet. Stan: Let. | |||||
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, | |||||
"snapToEdges": snapToEdge && Engine.GetEdgesOfStaticObstructionsOnScreen() | |||||
}); | }); | ||||
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 303 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; | ||||
} | } | ||||
var snapData = Engine.GuiInterfaceCall("GetFoundationSnapData", { | let snapToEdge = Engine.HotkeyIsPressed("session.snaptoedge"); | ||||
Not Done Inline Actionslet maybe reduce the duplication wile at it Stan: let maybe reduce the duplication wile at it | |||||
Not Done Inline ActionsLet. Stan: Let. | |||||
let snapData = Engine.GuiInterfaceCall("GetFoundationSnapData", { | |||||
Not Done Inline ActionsHelper function for all three calls ? Stan: Helper function for all three calls ? | |||||
Done Inline ActionsI'm thinking about moving to another class. vladislavbelov: I'm thinking about moving to another class. | |||||
Not Done Inline ActionsMaybe that would be nicer. Though might be slower; Stan: Maybe that would be nicer. Though might be slower; | |||||
"template": placementSupport.template, | "template": placementSupport.template, | ||||
"x": placementSupport.position.x, | "x": placementSupport.position.x, | ||||
"z": placementSupport.position.z, | "z": placementSupport.position.z, | ||||
"snapToEdges": snapToEdge && Engine.GetEdgesOfStaticObstructionsOnScreen(g_ViewedPlayer) | |||||
}); | }); | ||||
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; | ||||
} | } | ||||
} | } | ||||
updateBuildingPlacementPreview(); // includes an update of the snap entity candidates | updateBuildingPlacementPreview(); // includes an update of the snap entity candidates | ||||
return false; // continue processing mouse motion | return false; // continue processing mouse motion | ||||
case "mousebuttondown": | case "mousebuttondown": | ||||
if (ev.button == SDL_BUTTON_LEFT) | if (ev.button == SDL_BUTTON_LEFT) | ||||
{ | { | ||||
if (placementSupport.mode === "wall") | if (placementSupport.mode === "wall") | ||||
{ | { | ||||
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 snapToEdge = Engine.HotkeyIsPressed("session.snaptoedge"); | |||||
Not Done Inline Actionslet where possible elexis: let where possible | |||||
Done Inline ActionsLet. Stan: Let. | |||||
if (snapToEdge) | |||||
{ | |||||
let snapData = Engine.GuiInterfaceCall("GetFoundationSnapData", { | |||||
Done Inline ActionsLet. Stan: Let. | |||||
"template": placementSupport.template, | |||||
"x": placementSupport.position.x, | |||||
"z": placementSupport.position.z, | |||||
"snapToEdges": Engine.GetEdgesOfStaticObstructionsOnScreen(g_ViewedPlayer) | |||||
Not Done Inline Actions(there is also a method for screen slices, perhaps the area can be reduced, maybe not, it doesnt account for the footprint of buildings as you mentioned on irc) elexis: (there is also a method for screen slices, perhaps the area can be reduced, maybe not, it… | |||||
Not Done Inline ActionsIMO Engine.PickPlayerEntitiesOnScreen(g_ViewedPlayer) will be the decisive factor to make this feature fast. As elexis said, something like screen slices would help. This would make the others possible optimizations marginal given that the possible snapping candidates should be minimal. nani: IMO `Engine.PickPlayerEntitiesOnScreen(g_ViewedPlayer)` will be the decisive factor to make… | |||||
Done Inline ActionsCurrently we don't have a correct implementation of such methods, we don't account obstructions. I may suggest to add it as optional and test it within a bunch of matches. vladislavbelov: Currently we don't have a correct implementation of such methods, we don't account obstructions. | |||||
Not Done Inline ActionsShould this only pick the players entities or also the ones of allies? elexis: Should this only pick the players entities or also the ones of allies?
I wonder about the worst… | |||||
}); | |||||
if (snapData) | |||||
{ | |||||
placementSupport.angle = snapData.angle; | |||||
Not Done Inline ActionsCan't you assign the object directly ? Object.assign(secondObject, firstObject); or a = b ? Stan: Can't you assign the object directly ? Object.assign(secondObject, firstObject); or a = b ? | |||||
Done Inline ActionsNo, different types. vladislavbelov: No, different types. | |||||
placementSupport.position.x = snapData.x; | |||||
placementSupport.position.z = snapData.z; | |||||
} | |||||
} | |||||
g_DragStart = new Vector2D(ev.x, ev.y); | g_DragStart = new Vector2D(ev.x, ev.y); | ||||
inputState = INPUT_BUILDING_CLICK; | inputState = INPUT_BUILDING_CLICK; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
else if (ev.button == SDL_BUTTON_RIGHT) | else if (ev.button == SDL_BUTTON_RIGHT) | ||||
{ | { | ||||
// Cancel building | // Cancel building | ||||
▲ Show 20 Lines • Show All 544 Lines • Show Last 20 Lines |
let