diff --git a/core/assets/ui/uiskin.json b/core/assets/ui/uiskin.json index f49fc606a3..ab630372a6 100644 --- a/core/assets/ui/uiskin.json +++ b/core/assets/ui/uiskin.json @@ -40,7 +40,9 @@ ImageButtonStyle: { toggle: {checked: button-down, down: button-down, up: button, imageDisabledColor: gray, imageUpColor: white }, select: {checked: button-select, up: none }, clear: {down: clear-down, up: clear, over: clear-over}, + clear-partial: {down: clear-down, up: none, over: clear-over}, clear-toggle: {down: clear-down, checked: clear-down, up: clear, over: clear-over}, + clear-toggle-partial: {down: clear-down, checked: clear-down, up: none, over: clear-over}, }, ScrollPaneStyle: { default: {background: border, vScroll: scroll, vScrollKnob: scroll-knob-vertical-black}, diff --git a/core/src/io/anuke/mindustry/input/InputHandler.java b/core/src/io/anuke/mindustry/input/InputHandler.java index 84b1563b22..36722ffe21 100644 --- a/core/src/io/anuke/mindustry/input/InputHandler.java +++ b/core/src/io/anuke/mindustry/input/InputHandler.java @@ -25,7 +25,7 @@ import io.anuke.ucore.core.Effects; import io.anuke.ucore.core.Graphics; import io.anuke.ucore.core.Inputs; import io.anuke.ucore.core.Timers; -import io.anuke.ucore.scene.Group; +import io.anuke.ucore.scene.ui.layout.Table; import io.anuke.ucore.util.Angles; import io.anuke.ucore.util.Mathf; import io.anuke.ucore.util.Translator; @@ -145,7 +145,7 @@ public abstract class InputHandler extends InputAdapter{ return false; } - public void buildUI(Group group){ + public void buildUI(Table table){ } diff --git a/core/src/io/anuke/mindustry/input/MobileInput.java b/core/src/io/anuke/mindustry/input/MobileInput.java index 0197d323e0..b0761dfb7e 100644 --- a/core/src/io/anuke/mindustry/input/MobileInput.java +++ b/core/src/io/anuke/mindustry/input/MobileInput.java @@ -30,8 +30,7 @@ import io.anuke.mindustry.world.Tile; import io.anuke.ucore.core.*; import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.graphics.Lines; -import io.anuke.ucore.scene.Group; -import io.anuke.ucore.scene.event.Touchable; +import io.anuke.ucore.scene.ui.layout.Table; import io.anuke.ucore.util.Mathf; import static io.anuke.mindustry.Vars.*; @@ -208,78 +207,53 @@ public class MobileInput extends InputHandler implements GestureListener{ //region UI and drawing @Override - public void buildUI(Group group){ + public void buildUI(Table table){ + table.addImage("blank").color(Palette.accent).height(3f).colspan(4).growX(); + table.row(); + table.left().margin(0f).defaults().size(48f); - //Create confirm/cancel table - group.fill(c -> { - c.bottom().left().visible(() -> !state.is(State.menu)); + table.addImageButton("icon-break", "clear-toggle-partial", 16 * 2f, () -> { + mode = mode == breaking ? recipe == null ? none : placing : breaking; + lastRecipe = recipe; + if(mode == breaking){ + showGuide("deconstruction"); + } + }).update(l -> l.setChecked(mode == breaking)); - c.table("pane", act -> { - act.margin(5); - act.defaults().size(60f); + //rotate button + table.addImageButton("icon-arrow", "clear-partial", 16 * 2f, () -> rotation = Mathf.mod(rotation + 1, 4)) + .update(i -> i.getImage().setRotationOrigin(rotation * 90, Align.center)) + .visible(() -> recipe != null && recipe.result.rotate); - //Add a cancel button - act.addImageButton("icon-cancel", 16*2f, () -> { - mode = none; - recipe = null; - }); + //cancel button + table.addImageButton("icon-cancel", "clear-partial", 16 * 2f, () -> { + player.clearBuilding(); + mode = none; + recipe = null; + }).visible(() -> player.isBuilding() || mode != none); - act.row(); + //confirm button + table.addImageButton("icon-check", "clear-partial", 16 * 2f, () -> { + for(PlaceRequest request : selection){ + Tile tile = request.tile(); - //Add an accept button, which places everything. - act.addImageButton("icon-check", 16 * 2f, () -> { - for(PlaceRequest request : selection){ - Tile tile = request.tile(); - - //actually place/break all selected blocks - if(tile != null){ - if(!request.remove){ - rotation = request.rotation; - recipe = request.recipe; - tryPlaceBlock(tile.x, tile.y); - }else{ - tryBreakBlock(tile.x, tile.y); - } - } + //actually place/break all selected blocks + if(tile != null){ + if(!request.remove){ + rotation = request.rotation; + recipe = request.recipe; + tryPlaceBlock(tile.x, tile.y); + }else{ + tryBreakBlock(tile.x, tile.y); } + } + } - //move all current requests to removal array so they fade out - removals.addAll(selection); - selection.clear(); - selecting = false; - }).disabled(i -> selection.size == 0); - - act.row(); - - //Add a rotate button - act.addImageButton("icon-arrow", 16 * 2f, () -> rotation = Mathf.mod(rotation + 1, 4)) - .update(i -> i.getImage().setRotationOrigin(rotation * 90, Align.center)) - .disabled(i -> recipe == null || !recipe.result.rotate); - }).visible(() -> mode != none).touchable(Touchable.enabled); - - c.row(); - - c.table("pane", remove -> { - remove.defaults().size(60f); - - //Add a break button. - remove.addImageButton("icon-break", "toggle", 16 * 2f, () -> { - mode = mode == breaking ? recipe == null ? none : placing : breaking; - lastRecipe = recipe; - if(mode == breaking){ - showGuide("deconstruction"); - } - }).update(l -> l.setChecked(mode == breaking)); - }).margin(5).touchable(Touchable.enabled); - - c.table("pane", cancel -> { - cancel.defaults().size(60f); - - //Add a 'cancel building' button. - cancel.addImageButton("icon-cancel", 16 * 2f, player::clearBuilding); - - }).left().colspan(2).margin(5).touchable(Touchable.enabled).visible(() -> player.getPlaceQueue().size > 0); - }); + //move all current requests to removal array so they fade out + removals.addAll(selection); + selection.clear(); + selecting = false; + }).visible(() -> !selection.isEmpty()); } @Override diff --git a/core/src/io/anuke/mindustry/type/Recipe.java b/core/src/io/anuke/mindustry/type/Recipe.java index eed821961c..2b5d02fb57 100644 --- a/core/src/io/anuke/mindustry/type/Recipe.java +++ b/core/src/io/anuke/mindustry/type/Recipe.java @@ -23,6 +23,7 @@ import static io.anuke.mindustry.Vars.*; public class Recipe extends UnlockableContent{ private static ObjectMap recipeMap = new ObjectMap<>(); + private static Array returnArray = new Array<>(); public final Block result; public final ItemStack[] requirements; @@ -55,34 +56,15 @@ public class Recipe extends UnlockableContent{ recipeMap.put(result, this); } - /** - * Returns unlocked recipes in a category. - * Do not call on the server backend, as unlocking does not exist! - */ - public static void getUnlockedByCategory(Category category, Array arr){ - if(headless){ - throw new RuntimeException("Not implemented on the headless backend!"); - } - - arr.clear(); - for(Recipe r : content.recipes()){ - if(r.category == category && (control.unlocks.isUnlocked(r)) && - !((r.mode != null && r.mode != state.mode) || !r.visibility.shown())){ - arr.add(r); - } - } - } - - /** - * Returns all recipes in a category. - */ - public static void getByCategory(Category category, Array r){ - r.clear(); + /**Returns all non-hidden recipes in a category.*/ + public static Array getByCategory(Category category){ + returnArray.clear(); for(Recipe recipe : content.recipes()){ - if(recipe.category == category){ - r.add(recipe); + if(recipe.category == category && !recipe.isHidden()){ + returnArray.add(recipe); } } + return returnArray; } public static Recipe getByResult(Block block){ diff --git a/core/src/io/anuke/mindustry/ui/fragments/OverlayFragment.java b/core/src/io/anuke/mindustry/ui/fragments/OverlayFragment.java index fd861518ad..f19ec137a4 100644 --- a/core/src/io/anuke/mindustry/ui/fragments/OverlayFragment.java +++ b/core/src/io/anuke/mindustry/ui/fragments/OverlayFragment.java @@ -31,7 +31,7 @@ public class OverlayFragment extends Fragment{ config.build(group); consume.build(group); - input.buildUI(group); + //input.buildUI(group); } public void remove(){ diff --git a/core/src/io/anuke/mindustry/ui/fragments/PlacementFragment.java b/core/src/io/anuke/mindustry/ui/fragments/PlacementFragment.java index d424b0c999..4eb3e6b7f6 100644 --- a/core/src/io/anuke/mindustry/ui/fragments/PlacementFragment.java +++ b/core/src/io/anuke/mindustry/ui/fragments/PlacementFragment.java @@ -2,7 +2,6 @@ package io.anuke.mindustry.ui.fragments; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.math.Interpolation; -import com.badlogic.gdx.utils.Array; import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.graphics.Palette; @@ -29,7 +28,6 @@ import static io.anuke.mindustry.Vars.*; public class PlacementFragment extends Fragment{ final int rowWidth = 4; - Array returned = new Array<>(); Category currentCategory = Category.turret; Block hovered, lastDisplay; Tile hoverTile; @@ -44,6 +42,7 @@ public class PlacementFragment extends Fragment{ full.table(frame -> { InputHandler input = control.input(0); + //rebuilds the category table with the correct recipes Runnable rebuildCategory = () -> { blockTable.clear(); @@ -54,7 +53,7 @@ public class PlacementFragment extends Fragment{ ButtonGroup group = new ButtonGroup<>(); group.setMinCheckCount(0); - for(Recipe recipe : recipes(currentCategory)){ + for(Recipe recipe : Recipe.getByCategory(currentCategory)){ if(index++ % rowWidth == 0){ blockTable.row(); @@ -98,6 +97,7 @@ public class PlacementFragment extends Fragment{ blockTable.act(0f); }; + //top table with hover info frame.table("clear", top -> { top.add(new Table()).growX().update(topTable -> { if((tileDisplayBlock() == null && lastDisplay == getSelected()) || @@ -113,12 +113,12 @@ public class PlacementFragment extends Fragment{ header.left(); header.add(new ImageStack(lastDisplay.getCompactIcon())).size(8*4); header.labelWrap(() -> - !control.unlocks.isUnlocked(Recipe.getByResult(lastDisplay)) ? Bundles.get("text.blocks.unknown") : lastDisplay.formalName) - .left().width(190f).padLeft(5); + !control.unlocks.isUnlocked(Recipe.getByResult(lastDisplay)) ? Bundles.get("text.blocks.unknown") : lastDisplay.formalName) + .left().width(190f).padLeft(5); header.add().growX(); if(control.unlocks.isUnlocked(Recipe.getByResult(lastDisplay))){ header.addButton("?", "clear-partial", () -> ui.content.show(Recipe.getByResult(lastDisplay))) - .size(8 * 5).padTop(-5).padRight(-5).right().grow(); + .size(8 * 5).padTop(-5).padRight(-5).right().grow(); } }).growX().left(); topTable.row(); @@ -155,15 +155,19 @@ public class PlacementFragment extends Fragment{ top.addImage("blank").growX().color(Palette.accent).height(3f); }).colspan(3).fillX().visible(() -> getSelected() != null || tileDisplayBlock() != null).touchable(Touchable.enabled); frame.row(); - frame.table("clear", blocks -> blockTable = blocks).fillY().bottom().touchable(Touchable.enabled); + frame.table("clear", blocksSelect -> { + blocksSelect.table(blocks -> blockTable = blocks).grow(); + blocksSelect.row(); + blocksSelect.table(input::buildUI).growX(); + }).fillY().bottom().touchable(Touchable.enabled); frame.addImage("blank").width(3f).fillY().color(Palette.accent); frame.table(categories -> { - categories.defaults().size(48f); + categories.defaults().size(50f); ButtonGroup group = new ButtonGroup<>(); for(Category cat : Category.values()){ - if(recipes(cat).isEmpty()) continue; + if(Recipe.getByCategory(cat).isEmpty()) continue; categories.addImageButton("icon-" + cat.name(), "clear-toggle", 16*2, () -> { currentCategory = cat; @@ -213,15 +217,7 @@ public class PlacementFragment extends Fragment{ return hoverTile == null ? null : hoverTile.block().synthetic() ? hoverTile.block() : hoverTile.floor() instanceof OreBlock ? hoverTile.floor() : null; } - Array recipes(Category cat){ - returned.clear(); - for(Recipe recipe : content.recipes()){ - if(recipe.category != cat || recipe.isHidden()) continue; - returned.add(recipe); - } - return returned; - } - + /**Show or hide the placement menu.*/ void toggle(float t, Interpolation ip){ if(shown){ shown = false;