Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/session/input.js
Show First 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | function updateBuildingPlacementPreview() | ||||
// The preview should be recomputed every turn, so that it responds to obstructions/fog/etc moving underneath it, or | // The preview should be recomputed every turn, so that it responds to obstructions/fog/etc moving underneath it, or | ||||
// in the case of the wall previews, in response to new tower foundations getting constructed for it to snap to. | // in the case of the wall previews, in response to new tower foundations getting constructed for it to snap to. | ||||
// See onSimulationUpdate in session.js. | // See onSimulationUpdate in session.js. | ||||
if (placementSupport.mode === "building") | if (placementSupport.mode === "building") | ||||
{ | { | ||||
if (placementSupport.template && placementSupport.position) | if (placementSupport.template && placementSupport.position) | ||||
{ | { | ||||
var result = Engine.GuiInterfaceCall("SetBuildingPlacementPreview", { | let result = Engine.GuiInterfaceCall("SetBuildingPlacementPreview", { | ||||
"template": placementSupport.template, | "template": placementSupport.template, | ||||
"x": placementSupport.position.x, | "pos": placementSupport.position, | ||||
"z": placementSupport.position.z, | |||||
"angle": placementSupport.angle, | "angle": placementSupport.angle, | ||||
"snapClasses": placementSupport.socketSnapClasses, | |||||
// Ideally we'd only get entities with certain class. | |||||
"snapEntities": placementSupport.socketSnapClasses && | |||||
placementSupport.socketSnapClasses.length && | |||||
Engine.GetEntitiesWithStaticObstructionOnScreen(), | |||||
"actorSeed": placementSupport.actorSeed | "actorSeed": placementSupport.actorSeed | ||||
}); | }); | ||||
// Show placement info tooltip if invalid position | // Show placement info tooltip if invalid position | ||||
placementSupport.tooltipError = !result.success; | placementSupport.tooltipError = !result.success; | ||||
placementSupport.tooltipMessage = ""; | placementSupport.tooltipMessage = ""; | ||||
if (!result.success) | if (!result.success) | ||||
Show All 24 Lines | if (placementSupport.template && placementSupport.position) | ||||
"range": placementSupport.attack.Ranged.maxRange, | "range": placementSupport.attack.Ranged.maxRange, | ||||
"elevationBonus": placementSupport.attack.Ranged.elevationBonus, | "elevationBonus": placementSupport.attack.Ranged.elevationBonus, | ||||
}; | }; | ||||
var averageRange = Math.round(Engine.GuiInterfaceCall("GetAverageRangeForBuildings", cmd) - cmd.range); | var averageRange = Math.round(Engine.GuiInterfaceCall("GetAverageRangeForBuildings", cmd) - cmd.range); | ||||
var range = Math.round(cmd.range); | var range = Math.round(cmd.range); | ||||
placementSupport.tooltipMessage = sprintf(translatePlural("Basic range: %(range)s meter", "Basic range: %(range)s meters", range), { "range": range }) + "\n" + | placementSupport.tooltipMessage = sprintf(translatePlural("Basic range: %(range)s meter", "Basic range: %(range)s meters", range), { "range": range }) + "\n" + | ||||
sprintf(translatePlural("Average bonus range: %(range)s meter", "Average bonus range: %(range)s meters", averageRange), { "range": averageRange }); | sprintf(translatePlural("Average bonus range: %(range)s meter", "Average bonus range: %(range)s meters", averageRange), { "range": averageRange }); | ||||
} | } | ||||
return true; | return result; | ||||
} | } | ||||
} | } | ||||
else if (placementSupport.mode === "wall") | else if (placementSupport.mode === "wall") | ||||
{ | { | ||||
if (placementSupport.wallSet && placementSupport.position) | if (placementSupport.wallSet && placementSupport.position) | ||||
{ | { | ||||
// Fetch an updated list of snapping candidate entities | // Fetch an updated list of snapping candidate entities | ||||
placementSupport.wallSnapEntities = Engine.PickSimilarPlayerEntities( | placementSupport.wallSnapEntities = Engine.PickSimilarPlayerEntities( | ||||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Lines | |||||
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; | ||||
} | } | ||||
if (!updateBuildingPlacementPreview()) | let buildingPlacementInfo = updateBuildingPlacementPreview(); | ||||
if (!buildingPlacementInfo) | |||||
{ | { | ||||
// invalid location - don't build it | // invalid location - don't build it | ||||
// TODO: play a sound? | // TODO: play a sound? | ||||
return false; | return false; | ||||
} | } | ||||
var selection = g_Selection.toList(); | var selection = g_Selection.toList(); | ||||
Engine.PostNetworkCommand({ | Engine.PostNetworkCommand({ | ||||
"type": "construct", | "type": "construct", | ||||
"template": placementSupport.template, | "template": placementSupport.template, | ||||
"x": placementSupport.position.x, | "x": buildingPlacementInfo.x, | ||||
"z": placementSupport.position.z, | "z": buildingPlacementInfo.z, | ||||
"angle": placementSupport.angle, | "angle": placementSupport.angle, | ||||
"actorSeed": placementSupport.actorSeed, | "actorSeed": placementSupport.actorSeed, | ||||
"entities": selection, | "entities": selection, | ||||
"autorepair": true, | "autorepair": true, | ||||
"autocontinue": true, | "autocontinue": true, | ||||
"queued": queued | "queued": queued, | ||||
"snapEntity": buildingPlacementInfo.snappedEnt | |||||
}); | }); | ||||
Engine.GuiInterfaceCall("PlaySound", { "name": "order_build", "entity": selection[0] }); | Engine.GuiInterfaceCall("PlaySound", { "name": "order_build", "entity": selection[0] }); | ||||
if (!queued) | if (!queued) | ||||
placementSupport.Reset(); | placementSupport.Reset(); | ||||
else | else | ||||
placementSupport.RandomizeActorSeed(); | placementSupport.RandomizeActorSeed(); | ||||
▲ Show 20 Lines • Show All 754 Lines • ▼ Show 20 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); | ||||
if (isSnapToEdgesEnabled()) | |||||
{ | |||||
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( | "snapEntities": placementSupport.socketSnapEntities, | ||||
"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; | ||||
Silier: probably this removal broke edge snapping | |||||
Done Inline ActionsYeah, object type is lost or something. I'll revert to the previous diff. Freagarach: Yeah, object type is lost or something. I'll revert to the previous diff. | |||||
placementSupport.position.x = snapData.x; | placementSupport.position.x = snapData.x; | ||||
placementSupport.position.z = snapData.z; | 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) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 193 Lines • ▼ Show 20 Lines | if (templateData.wallSet) | ||||
placementSupport.wallSet = templateData.wallSet; | placementSupport.wallSet = templateData.wallSet; | ||||
inputState = INPUT_BUILDING_PLACEMENT; | inputState = INPUT_BUILDING_PLACEMENT; | ||||
} | } | ||||
else | else | ||||
{ | { | ||||
placementSupport.mode = "building"; | placementSupport.mode = "building"; | ||||
placementSupport.template = buildTemplate; | placementSupport.template = buildTemplate; | ||||
inputState = INPUT_BUILDING_PLACEMENT; | inputState = INPUT_BUILDING_PLACEMENT; | ||||
placementSupport.socketSnapClasses = templateData.buildRestrictions.sockets; | |||||
Done Inline Actionscannot go here with undefined instead empty array ? Silier: cannot go here with undefined instead empty array ? | |||||
} | } | ||||
if (templateData.attack && | if (templateData.attack && | ||||
templateData.attack.Ranged && | templateData.attack.Ranged && | ||||
templateData.attack.Ranged.maxRange) | templateData.attack.Ranged.maxRange) | ||||
{ | { | ||||
// add attack information to display a good tooltip | // add attack information to display a good tooltip | ||||
placementSupport.attack = templateData.attack; | placementSupport.attack = templateData.attack; | ||||
▲ Show 20 Lines • Show All 338 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
probably this removal broke edge snapping