Skip to content

Commit

Permalink
Fix accidentally dragging build plans (Anuken#9334)
Browse files Browse the repository at this point in the history
Co-authored-by: Yuri Apollov <apollovy@icloud.com>
  • Loading branch information
BalaM314 and apollovy committed Dec 12, 2023
1 parent 53b3410 commit ed50547
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions core/src/mindustry/input/DesktopInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ public class DesktopInput extends InputHandler{
public float selectScale;
/** Selected build plan for movement. */
public @Nullable BuildPlan splan;
/** Used to track whether the splan was moved. */
public boolean splanMoved = false;
/** Used to keep track of where in the tile a build plan was clicked for dragging. */
public final Vec2 buildPlanClickOffset = new Vec2();
/** Whether player is currently deleting removal plans. */
public boolean deleting = false, shouldShoot = false, panning = false;
/** Mouse pan speed. */
Expand Down Expand Up @@ -869,12 +869,10 @@ void pollInput(){
}

if(splan != null){
float offset = ((splan.block.size + 2) % 2) * tilesize / 2f;
int x = (int)((Core.input.mouseWorld().x + offset) / tilesize);
int y = (int)((Core.input.mouseWorld().y + offset) / tilesize);
if (splan.x != x || splan.y != y) splanMoved = true;
splan.x = x;
splan.y = y;
float x = Core.input.mouseWorld().x + buildPlanClickOffset.x;
float y = Core.input.mouseWorld().y + buildPlanClickOffset.y;
splan.x = Math.round(x / tilesize);
splan.y = Math.round(y / tilesize);
}

if(block == null || mode != placing){
Expand Down Expand Up @@ -927,6 +925,8 @@ else if (Core.input.ctrl()) {
updateLine(selectX, selectY);
}else if(plan != null && !plan.breaking && mode == none && !plan.initialized){
splan = plan;
buildPlanClickOffset.x = splan.x * tilesize - Core.input.mouseWorld().x;
buildPlanClickOffset.y = splan.y * tilesize - Core.input.mouseWorld().y;
}else if(plan != null && plan.breaking){
deleting = true;
}else if(commandMode){
Expand Down Expand Up @@ -1022,9 +1022,7 @@ else if (Core.input.ctrl()) {
if(getPlan(splan.x, splan.y, splan.block.size, splan) != null){
player.unit().plans().remove(splan, true);
}
if(!splanMoved) player.unit().addBuild(splan, false); // Add the plan to the top of the queue
splan = null;
splanMoved = false;
}

mode = none;
Expand Down

0 comments on commit ed50547

Please sign in to comment.