diff --git a/core/src/mindustry/core/Renderer.java b/core/src/mindustry/core/Renderer.java index eb0920cdee..491ad3634b 100644 --- a/core/src/mindustry/core/Renderer.java +++ b/core/src/mindustry/core/Renderer.java @@ -581,6 +581,7 @@ public void showLaunch(CoreBlock coreType){ Vars.ui.hudfrag.showLaunch(); Vars.control.input.config.hideConfig(); Vars.control.input.inv.hide(); + Vars.control.input.planConfig.hide(); launchCoreType = coreType; launching = true; landCore = player.team().core(); diff --git a/core/src/mindustry/input/DesktopInput.java b/core/src/mindustry/input/DesktopInput.java index 4a01e49702..7ff87afcae 100644 --- a/core/src/mindustry/input/DesktopInput.java +++ b/core/src/mindustry/input/DesktopInput.java @@ -1022,7 +1022,14 @@ 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 + if(!splanMoved && input.ctrl()) { + inv.hide(); + config.hideConfig(); + planConfig.showConfig(splan); + } else { + planConfig.hide(); + if (!splanMoved) player.unit().addBuild(splan, false); // Add the plan to the top of the queue + } splan = null; splanMoved = false; } diff --git a/core/src/mindustry/input/InputHandler.java b/core/src/mindustry/input/InputHandler.java index ca94150ff6..ca12cab0c4 100644 --- a/core/src/mindustry/input/InputHandler.java +++ b/core/src/mindustry/input/InputHandler.java @@ -110,6 +110,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{ public final BlockInventoryFragment inv; public final BlockConfigFragment config; + public final PlanConfigFragment planConfig; private WidgetGroup group = new WidgetGroup(); @@ -130,6 +131,7 @@ public InputHandler(){ group.touchable = Touchable.childrenOnly; inv = new BlockInventoryFragment(); config = new BlockConfigFragment(); + planConfig = new PlanConfigFragment(); Events.on(UnitDestroyEvent.class, e -> { if(e.unit != null && e.unit.isPlayer() && e.unit.getPlayer().isLocal() && e.unit.type.weapons.contains(w -> w.bullet.killShooter)){ @@ -1666,6 +1668,8 @@ boolean checkConfigTap(){ /** Handles tile tap events that are not platform specific. */ boolean tileTapped(@Nullable Building build){ + // Should hide plan config regardless of what was tapped + planConfig.hide(); if(build == null){ inv.hide(); config.hideConfig(); @@ -1943,6 +1947,7 @@ public void add(){ inv.build(group); config.build(group); + planConfig.build(group); } } diff --git a/core/src/mindustry/ui/fragments/PlanConfigFragment.java b/core/src/mindustry/ui/fragments/PlanConfigFragment.java new file mode 100644 index 0000000000..ccc53baa55 --- /dev/null +++ b/core/src/mindustry/ui/fragments/PlanConfigFragment.java @@ -0,0 +1,84 @@ +package mindustry.ui.fragments; + +import arc.Core; +import arc.Events; +import arc.math.Interp; +import arc.math.geom.Vec2; +import arc.scene.Group; +import arc.scene.actions.Actions; +import arc.scene.ui.layout.Table; +import arc.struct.Seq; +import arc.util.Align; +import mindustry.ctype.UnlockableContent; +import mindustry.entities.units.BuildPlan; +import mindustry.game.EventType; +import mindustry.type.Item; +import mindustry.type.Liquid; +import mindustry.world.Block; +import mindustry.world.blocks.ItemSelection; + +import static mindustry.Vars.*; + +public class PlanConfigFragment { + Table table = new Table(); + BuildPlan selected; + + public void build(Group parent){ + table.visible = false; + parent.addChild(table); + + Events.on(EventType.ResetEvent.class, e -> forceHide()); + } + + public void showConfig(BuildPlan plan) { + if (this.selected == plan) { + hide(); + return; + } + Block block = plan.block; + if (!block.configurable) return; + selected = plan; + table.clear(); + Seq items = new Seq<>(); + if (block.configurations.containsKey(Item.class)) { + items.add(content.items()); + } else if (block.configurations.containsKey(Liquid.class)) { + items.add(content.liquids()); + } + if (items.isEmpty()) return; + ItemSelection.buildTable(table, items, () -> selected != null ? (selected.config instanceof UnlockableContent c ? c : null) : null, + content -> { + selected.config = content; + hide(); + }, block.selectionRows, block.selectionColumns); + table.pack(); + table.setTransform(true); + table.visible = true; + table.actions(Actions.scaleTo(0f, 1f), Actions.visible(true), + Actions.scaleTo(1f, 1f, 0.07f, Interp.pow3Out)); + table.update(() -> { + table.setOrigin(Align.center); + if (plan.isDone()) { + this.hide(); + return; + } + boolean planExists = control.input.selectPlans.contains(plan) || player.unit().plans.contains(plan); + if (!planExists) { + this.hide(); + return; + } + Vec2 pos = Core.input.mouseScreen(plan.drawx(), plan.drawy() - block.size * tilesize / 2.0F - 1); + table.setPosition(pos.x, pos.y, Align.top); + }); + } + + public void forceHide() { + table.visible = false; + selected = null; + } + + public void hide() { + selected = null; + table.actions(Actions.scaleTo(0f, 1f, 0.06f, Interp.pow3Out), Actions.visible(false)); + } +}