From dc00e22f13546c296a0762f7dda8b1250139a5c9 Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 3 Sep 2018 21:51:13 -0400 Subject: [PATCH] Fixed unit pads hiding in PvP / Fixed recipes not deselecting in menu --- .../io/anuke/mindustry/content/Recipes.java | 53 +++---------------- .../src/io/anuke/mindustry/game/GameMode.java | 4 +- core/src/io/anuke/mindustry/type/Recipe.java | 7 ++- .../ui/fragments/BlocksFragment.java | 6 ++- 4 files changed, 19 insertions(+), 51 deletions(-) diff --git a/core/src/io/anuke/mindustry/content/Recipes.java b/core/src/io/anuke/mindustry/content/Recipes.java index 76d2c82d47..ea6280fb79 100644 --- a/core/src/io/anuke/mindustry/content/Recipes.java +++ b/core/src/io/anuke/mindustry/content/Recipes.java @@ -3,9 +3,9 @@ package io.anuke.mindustry.content; import com.badlogic.gdx.utils.Array; import io.anuke.mindustry.content.blocks.*; import io.anuke.mindustry.game.Content; -import io.anuke.mindustry.game.GameMode; -import io.anuke.mindustry.type.*; -import io.anuke.mindustry.world.Block; +import io.anuke.mindustry.type.ContentList; +import io.anuke.mindustry.type.ItemStack; +import io.anuke.mindustry.type.Recipe; import static io.anuke.mindustry.type.Category.*; @@ -145,14 +145,14 @@ public class Recipes implements ContentList{ new Recipe(units, UnitBlocks.dronePad, new ItemStack(Items.copper, 70), new ItemStack(Items.lead, 110), new ItemStack(Items.silicon, 130)); new Recipe(units, UnitBlocks.fabricatorPad, new ItemStack(Items.densealloy, 90), new ItemStack(Items.thorium, 80), new ItemStack(Items.lead, 110), new ItemStack(Items.silicon, 210)); - new Recipe(units, UnitBlocks.daggerPad, new ItemStack(Items.lead, 90), new ItemStack(Items.silicon, 70)).setMode(GameMode.noWaves); - new Recipe(units, UnitBlocks.titanPad, new ItemStack(Items.thorium, 90), new ItemStack(Items.lead, 140), new ItemStack(Items.silicon, 90)).setMode(GameMode.noWaves); + new Recipe(units, UnitBlocks.daggerPad, new ItemStack(Items.lead, 90), new ItemStack(Items.silicon, 70)).setPad(); + new Recipe(units, UnitBlocks.titanPad, new ItemStack(Items.thorium, 90), new ItemStack(Items.lead, 140), new ItemStack(Items.silicon, 90)).setPad(); - new Recipe(units, UnitBlocks.interceptorPad, new ItemStack(Items.titanium, 60), new ItemStack(Items.lead, 80), new ItemStack(Items.silicon, 90)).setMode(GameMode.noWaves); - new Recipe(units, UnitBlocks.monsoonPad, new ItemStack(Items.plastanium, 80), new ItemStack(Items.titanium, 100), new ItemStack(Items.lead, 130), new ItemStack(Items.silicon, 220)).setMode(GameMode.noWaves); + new Recipe(units, UnitBlocks.interceptorPad, new ItemStack(Items.titanium, 60), new ItemStack(Items.lead, 80), new ItemStack(Items.silicon, 90)).setPad(); + new Recipe(units, UnitBlocks.monsoonPad, new ItemStack(Items.plastanium, 80), new ItemStack(Items.titanium, 100), new ItemStack(Items.lead, 130), new ItemStack(Items.silicon, 220)).setPad(); new Recipe(units, UnitBlocks.repairPoint, new ItemStack(Items.lead, 30), new ItemStack(Items.copper, 30), new ItemStack(Items.silicon, 30)); - new Recipe(units, UnitBlocks.commandCenter, new ItemStack(Items.lead, 100), new ItemStack(Items.densealloy, 100), new ItemStack(Items.silicon, 200)).setMode(GameMode.noWaves); + new Recipe(units, UnitBlocks.commandCenter, new ItemStack(Items.lead, 100), new ItemStack(Items.densealloy, 100), new ItemStack(Items.silicon, 200)).setPad(); //LIQUIDS new Recipe(liquid, LiquidBlocks.conduit, new ItemStack(Items.lead, 1)).setDependencies(CraftingBlocks.smelter); @@ -176,43 +176,6 @@ public class Recipes implements ContentList{ new Recipe(units, DebugBlocks.powerInfinite).setDebug(); } - static void init(Object... objects){ - Category cat = null; - Block block = null; - ItemStack stack = null; - Array arr = new Array<>(); - for(Object object : objects){ - if(object instanceof Category){ - if(stack != null) throw new RuntimeException("Finish defining stack before beginning category"); - if(block != null){ - new Recipe(cat, block, arr.toArray(ItemStack.class)); - block = null; - stack = null; - arr.clear(); - } - cat = (Category) object; - }else if(object instanceof Block){ - if(cat == null) throw new RuntimeException("Finish defining category before beginning blocks"); - if(block != null){ - new Recipe(cat, block, arr.toArray(ItemStack.class)); - stack = null; - arr.clear(); - } - block = (Block) object; - arr.clear(); - }else if(object instanceof Item){ - if(block == null) throw new RuntimeException("Finish defining block before defining item"); - if(stack != null) throw new RuntimeException("Finish defining stack before defining another stack"); - stack = new ItemStack((Item) object, 1); - }else if(object instanceof Integer){ - if(stack == null) throw new RuntimeException("Finish defining item before defining item amount"); - stack.amount = (Integer) object; - arr.add(stack); - stack = null; - } - } - } - @Override public Array getAll(){ return Recipe.all(); diff --git a/core/src/io/anuke/mindustry/game/GameMode.java b/core/src/io/anuke/mindustry/game/GameMode.java index 2fdc39cead..b4040d8209 100644 --- a/core/src/io/anuke/mindustry/game/GameMode.java +++ b/core/src/io/anuke/mindustry/game/GameMode.java @@ -15,8 +15,10 @@ public enum GameMode{ disableWaves = true; hidden = true; autoSpawn = true; + showPads = true; }}, pvp{{ + showPads = true; disableWaves = true; isPvp = true; hidden = true; @@ -24,7 +26,7 @@ public enum GameMode{ respawnTime = 60 * 10; }}; - public boolean infiniteResources, disableWaveTimer, disableWaves, hidden, autoSpawn, isPvp; + public boolean infiniteResources, disableWaveTimer, disableWaves, hidden, autoSpawn, isPvp, showPads; public float enemyCoreBuildRadius = 400f; public float enemyCoreShieldRadius = 140f; public float respawnTime = 60 * 4; diff --git a/core/src/io/anuke/mindustry/type/Recipe.java b/core/src/io/anuke/mindustry/type/Recipe.java index 43814cc620..0dc49bee28 100644 --- a/core/src/io/anuke/mindustry/type/Recipe.java +++ b/core/src/io/anuke/mindustry/type/Recipe.java @@ -6,7 +6,6 @@ import com.badlogic.gdx.utils.ObjectMap; import com.badlogic.gdx.utils.OrderedMap; import io.anuke.mindustry.Vars; import io.anuke.mindustry.game.Content; -import io.anuke.mindustry.game.GameMode; import io.anuke.mindustry.game.UnlockableContent; import io.anuke.mindustry.ui.ContentDisplay; import io.anuke.mindustry.world.Block; @@ -35,7 +34,7 @@ public class Recipe implements UnlockableContent{ public boolean desktopOnly = false, debugOnly = false; //the only gamemode in which the recipe shows up - public GameMode targetMode; + public boolean isPad; private Block[] dependencies; private Recipe[] recipeDependencies; @@ -104,8 +103,8 @@ public class Recipe implements UnlockableContent{ } } - public Recipe setMode(GameMode mode){ - this.targetMode = mode; + public Recipe setPad(){ + this.isPad = true; return this; } diff --git a/core/src/io/anuke/mindustry/ui/fragments/BlocksFragment.java b/core/src/io/anuke/mindustry/ui/fragments/BlocksFragment.java index 2be80718fd..30892eb4ac 100644 --- a/core/src/io/anuke/mindustry/ui/fragments/BlocksFragment.java +++ b/core/src/io/anuke/mindustry/ui/fragments/BlocksFragment.java @@ -67,6 +67,10 @@ public class BlocksFragment extends Fragment{ descTable = new Table("button"); descTable.visible(() -> (hoverRecipe != null || input.recipe != null) && shown); //make sure it's visible when necessary descTable.update(() -> { + if(state.is(State.menu)){ + descTable.clear(); + control.input(0).recipe = null; + } // note: This is required because there is no direct connection between input.recipe and the description ui. // If input.recipe gets set to null, a proper cleanup of the ui elements is required. boolean anyRecipeShown = input.recipe != null || hoverRecipe != null; @@ -167,7 +171,7 @@ public class BlocksFragment extends Fragment{ //add actual recipes for(Recipe r : recipes){ - if((r.debugOnly && !debug) || (r.desktopOnly && mobile) || (r.targetMode != null && r.targetMode != state.mode)) continue; + if((r.debugOnly && !debug) || (r.desktopOnly && mobile) || (r.isPad && !state.mode.showPads)) continue; ImageButton image = new ImageButton(new TextureRegion(), "select");