From 5955ecefd3d5aa02e99462efcf3af1bcc83fc8c4 Mon Sep 17 00:00:00 2001 From: Anuken Date: Sat, 21 Sep 2019 15:54:34 -0400 Subject: [PATCH] Bugfixes --- core/src/io/anuke/mindustry/core/Control.java | 2 ++ core/src/io/anuke/mindustry/input/InputHandler.java | 13 +++++++++++++ core/src/io/anuke/mindustry/input/MobileInput.java | 7 ++++++- .../mindustry/ui/fragments/PlacementFragment.java | 9 ++++----- 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/core/src/io/anuke/mindustry/core/Control.java b/core/src/io/anuke/mindustry/core/Control.java index 0ea3c9b59f..de97d07b8f 100644 --- a/core/src/io/anuke/mindustry/core/Control.java +++ b/core/src/io/anuke/mindustry/core/Control.java @@ -208,9 +208,11 @@ public class Control implements ApplicationListener, Loadable{ } public void setInput(InputHandler newInput){ + Block block = input.block; boolean added = Core.input.getInputProcessors().contains(input); input.remove(); this.input = newInput; + newInput.block = block; if(added){ newInput.add(); } diff --git a/core/src/io/anuke/mindustry/input/InputHandler.java b/core/src/io/anuke/mindustry/input/InputHandler.java index d029e080c7..d33292af45 100644 --- a/core/src/io/anuke/mindustry/input/InputHandler.java +++ b/core/src/io/anuke/mindustry/input/InputHandler.java @@ -273,10 +273,23 @@ public abstract class InputHandler implements InputProcessor{ public void remove(){ Core.input.removeProcessor(this); frag.remove(); + if(Core.scene != null){ + Table table = (Table)Core.scene.find("inputTable"); + if(table != null){ + table.clear(); + } + } } public void add(){ Core.input.addProcessor(this); + if(Core.scene != null){ + Table table = (Table)Core.scene.find("inputTable"); + if(table != null){ + table.clear(); + buildUI(table); + } + } } public boolean canShoot(){ diff --git a/core/src/io/anuke/mindustry/input/MobileInput.java b/core/src/io/anuke/mindustry/input/MobileInput.java index dd5a188437..a5e8ec603f 100644 --- a/core/src/io/anuke/mindustry/input/MobileInput.java +++ b/core/src/io/anuke/mindustry/input/MobileInput.java @@ -291,6 +291,7 @@ public class MobileInput extends InputHandler implements GestureListener{ }).visible(() -> !selection.isEmpty()).name("confirmplace"); Core.scene.table(t -> { + t.setName("cancelMobile"); t.bottom().left().visible(() -> (player.isBuilding() || block != null || mode == breaking) && !state.is(State.menu)); t.addImageTextButton("$cancel", Icon.cancelSmall, () -> { player.clearBuilding(); @@ -442,8 +443,8 @@ public class MobileInput extends InputHandler implements GestureListener{ @Override public void add(){ - super.add(); Core.input.addProcessor(detector = new GestureDetector(20, 0.5f, 0.4f, 0.15f, this)); + super.add(); } @Override @@ -452,6 +453,10 @@ public class MobileInput extends InputHandler implements GestureListener{ if(detector != null){ Core.input.removeProcessor(detector); } + + if(Core.scene != null && Core.scene.find("cancelMobile") != null){ + Core.scene.find("cancelMobile").remove(); + } } @Override diff --git a/core/src/io/anuke/mindustry/ui/fragments/PlacementFragment.java b/core/src/io/anuke/mindustry/ui/fragments/PlacementFragment.java index 14e1d1e067..548ae1aee9 100644 --- a/core/src/io/anuke/mindustry/ui/fragments/PlacementFragment.java +++ b/core/src/io/anuke/mindustry/ui/fragments/PlacementFragment.java @@ -116,7 +116,6 @@ public class PlacementFragment extends Fragment{ full.bottom().right().visible(() -> ui.hudfrag.shown()); full.table(frame -> { - InputHandler input = control.input; //rebuilds the category table with the correct recipes Runnable rebuildCategory = () -> { @@ -140,7 +139,7 @@ public class PlacementFragment extends Fragment{ ImageButton button = blockTable.addImageButton(Icon.lockedSmall, Styles.selecti, () -> { if(unlocked(block)){ - input.block = input.block == block ? null : block; + control.input.block = control.input.block == block ? null : block; } }).size(46f).group(group).name("block-" + block.name).get(); @@ -150,7 +149,7 @@ public class PlacementFragment extends Fragment{ TileEntity core = player.getClosestCore(); Color color = state.rules.infiniteResources || (core != null && (core.items.has(block.buildRequirements, state.rules.buildCostMultiplier) || state.rules.infiniteResources)) ? Color.white : Color.gray; button.forEach(elem -> elem.setColor(color)); - button.setChecked(input.block == block); + button.setChecked(control.input.block == block); }); button.hovered(() -> hovered = block); @@ -250,7 +249,7 @@ public class PlacementFragment extends Fragment{ blocksSelect.margin(4).marginTop(0); blocksSelect.table(blocks -> blockTable = blocks).grow(); blocksSelect.row(); - blocksSelect.table(input::buildUI).growX(); + blocksSelect.table(control.input::buildUI).name("inputTable").growX(); }).fillY().bottom().touchable(Touchable.enabled); frame.table(categories -> { categories.defaults().size(50f); @@ -281,7 +280,7 @@ public class PlacementFragment extends Fragment{ rebuildCategory.run(); frame.update(() -> { - if(gridUpdate(input)) rebuildCategory.run(); + if(gridUpdate(control.input)) rebuildCategory.run(); }); }); });