Skip to content

Commit

Permalink
Drag to config bridges & payload drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
7003Mars committed Dec 7, 2024
1 parent 26708df commit 0122f4c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
25 changes: 25 additions & 0 deletions core/src/mindustry/input/DesktopInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public class DesktopInput extends InputHandler{
/** Previously selected tile. */
public Tile prevSelected;
private long lastShiftZ;
/** Whether the current selected building being dragged from*/
private boolean configDragging = false;

@Override
public void buildUI(Group group){
Expand Down Expand Up @@ -188,6 +190,13 @@ public void drawTop(){
}
}

if (configDragging && config.getSelected() != null) {
Vec2 mouseCoords = input.mouseWorld();
Building selected = config.getSelected();
Draw.color(Pal.accent);
Lines.line(mouseCoords.x, mouseCoords.y, selected.x, selected.y);
Draw.reset();
}

drawCommanded();

Expand Down Expand Up @@ -791,6 +800,22 @@ void pollInput(){
int cursorY = tileY(Core.input.mouseY());
int rawCursorX = World.toTile(Core.input.mouseWorld().x), rawCursorY = World.toTile(Core.input.mouseWorld().y);

// Handle drag to config behaviour
if (config.selectedCanDrag) {
if (input.keyDown(Binding.select)) {
if (selected.build == config.getSelected()) configDragging = true;
} else if (configDragging) {
Building hovered = world.build(cursorX, cursorY);
if (hovered != config.getSelected()) {
if (hovered != null) {
config.getSelected().onConfigureBuildTapped(hovered);
}
config.hideConfig();
}
configDragging = false;
}
}

//automatically pause building if the current build queue is empty
if(Core.settings.getBool("buildautopause") && isBuilding && !isBuildingIgnoreNetworking()){
isBuilding = false;
Expand Down
14 changes: 13 additions & 1 deletion core/src/mindustry/ui/fragments/BlockConfigFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,26 @@
import arc.scene.*;
import arc.scene.actions.*;
import arc.scene.ui.layout.*;
import arc.struct.ObjectSet;
import arc.util.*;
import mindustry.content.*;
import mindustry.game.EventType.*;
import mindustry.gen.*;
import mindustry.world.blocks.distribution.BufferedItemBridge.BufferedItemBridgeBuild;
import mindustry.world.blocks.distribution.ItemBridge.ItemBridgeBuild;
import mindustry.world.blocks.distribution.MassDriver.MassDriverBuild;
import mindustry.world.blocks.liquid.LiquidBridge.LiquidBridgeBuild;
import mindustry.world.blocks.payloads.PayloadMassDriver.PayloadDriverBuild;

import static mindustry.Vars.*;

public class BlockConfigFragment{
static ObjectSet<Class<? extends Building>> validBuilds = ObjectSet.with(
BufferedItemBridgeBuild.class, ItemBridgeBuild.class, LiquidBridgeBuild.class, MassDriverBuild.class, PayloadDriverBuild.class
);
Table table = new Table();
Building selected;
public boolean selectedCanDrag = false;

public void build(Group parent){
table.visible = false;
Expand All @@ -26,6 +36,7 @@ public void build(Group parent){
public void forceHide(){
table.visible = false;
selected = null;
selectedCanDrag = false;
}

public boolean isShown(){
Expand All @@ -40,7 +51,7 @@ public void showConfig(Building tile){
if(selected != null) selected.onConfigureClosed();
if(tile.configTapped()){
selected = tile;

selectedCanDrag = validBuilds.contains(selected.getClass());
table.visible = true;
table.clear();
table.background(null); // clear the background as some blocks set custom ones
Expand Down Expand Up @@ -74,6 +85,7 @@ public boolean hasConfigMouse(){
public void hideConfig(){
if(selected != null) selected.onConfigureClosed();
selected = null;
selectedCanDrag = false;
table.actions(Actions.scaleTo(0f, 1f, 0.06f, Interp.pow3Out), Actions.visible(false));
}
}

0 comments on commit 0122f4c

Please sign in to comment.