From 7024273a02ab2b5e75e433c480e42805436a247a Mon Sep 17 00:00:00 2001 From: Anuken Date: Fri, 15 Feb 2019 12:32:01 -0500 Subject: [PATCH] Better team interaction --- .../src/io/anuke/mindustry/AndroidLauncher.java | 4 ++-- core/src/io/anuke/mindustry/game/Teams.java | 3 ++- .../anuke/mindustry/graphics/OverlayRenderer.java | 2 +- .../io/anuke/mindustry/input/InputHandler.java | 15 +++++++-------- core/src/io/anuke/mindustry/world/Tile.java | 4 ++++ 5 files changed, 16 insertions(+), 12 deletions(-) diff --git a/android/src/io/anuke/mindustry/AndroidLauncher.java b/android/src/io/anuke/mindustry/AndroidLauncher.java index 8fbb105dc4..323352d9eb 100644 --- a/android/src/io/anuke/mindustry/AndroidLauncher.java +++ b/android/src/io/anuke/mindustry/AndroidLauncher.java @@ -172,10 +172,10 @@ public class AndroidLauncher extends AndroidApplication{ SaveSlot slot = control.saves.importSave(file); ui.load.runLoadSave(slot); }catch(IOException e){ - ui.showError(Core.bundle.format("text.save.import.fail", Strings.parseException(e, false))); + ui.showError(Core.bundle.format("save.import.fail", Strings.parseException(e, false))); } }else{ - ui.showError("$text.save.import.invalid"); + ui.showError("$save.import.invalid"); } }else if(map){ //open map Core.app.post(() -> { diff --git a/core/src/io/anuke/mindustry/game/Teams.java b/core/src/io/anuke/mindustry/game/Teams.java index 7fac1100ad..d7d2e77177 100644 --- a/core/src/io/anuke/mindustry/game/Teams.java +++ b/core/src/io/anuke/mindustry/game/Teams.java @@ -23,9 +23,10 @@ public class Teams{ public TeamData get(Team team){ if(map[team.ordinal()] == null){ //By default, a non-defined team will be enemies of everything. + //neutral teams (none) do not have any enemies. Team[] others = new Team[Team.all.length-1]; for(int i = 0, j = 0; i < Team.all.length; i++){ - if(Team.all[i] != team) others[j++] = Team.all[i]; + if(Team.all[i] != team && team != Team.none && Team.all[i] != Team.none) others[j++] = Team.all[i]; } add(team, others); } diff --git a/core/src/io/anuke/mindustry/graphics/OverlayRenderer.java b/core/src/io/anuke/mindustry/graphics/OverlayRenderer.java index 2d9f50b4b5..a2cf531e7e 100644 --- a/core/src/io/anuke/mindustry/graphics/OverlayRenderer.java +++ b/core/src/io/anuke/mindustry/graphics/OverlayRenderer.java @@ -106,7 +106,7 @@ public class OverlayRenderer{ Tile tile = world.tileWorld(v.x, v.y); if(tile != null) tile = tile.target(); - if(tile != null && tile.getTeam() == player.getTeam() && tile.block().acceptStack(player.item().item, player.item().amount, tile, player) > 0){ + if(tile != null && tile.interactable(player.getTeam()) && tile.block().acceptStack(player.item().item, player.item().amount, tile, player) > 0){ Draw.color(Pal.place); Lines.square(tile.drawx(), tile.drawy(), tile.block().size * tilesize / 2f + 1 + Mathf.absin(Time.time(), 5f, 1f)); Draw.color(); diff --git a/core/src/io/anuke/mindustry/input/InputHandler.java b/core/src/io/anuke/mindustry/input/InputHandler.java index c9551a5a5d..0ca11d526a 100644 --- a/core/src/io/anuke/mindustry/input/InputHandler.java +++ b/core/src/io/anuke/mindustry/input/InputHandler.java @@ -3,7 +3,6 @@ package io.anuke.mindustry.input; import io.anuke.annotations.Annotations.Loc; import io.anuke.annotations.Annotations.Remote; import io.anuke.arc.Core; -import io.anuke.mindustry.entities.Effects; import io.anuke.arc.graphics.Color; import io.anuke.arc.input.InputProcessor; import io.anuke.arc.math.Angles; @@ -13,10 +12,10 @@ import io.anuke.arc.scene.ui.layout.Table; import io.anuke.arc.util.Time; import io.anuke.mindustry.content.Blocks; import io.anuke.mindustry.content.Fx; -import io.anuke.mindustry.entities.type.Player; +import io.anuke.mindustry.entities.Effects; import io.anuke.mindustry.entities.effect.ItemTransfer; import io.anuke.mindustry.entities.traits.BuilderTrait.BuildRequest; -import io.anuke.mindustry.game.Team; +import io.anuke.mindustry.entities.type.Player; import io.anuke.mindustry.gen.Call; import io.anuke.mindustry.net.Net; import io.anuke.mindustry.net.ValidateException; @@ -157,7 +156,7 @@ public abstract class InputHandler implements InputProcessor{ boolean consumed = false, showedInventory = false; //check if tapped block is configurable - if(tile.block().configurable && tile.getTeam() == player.getTeam()){ + if(tile.block().configurable && tile.interactable(player.getTeam())){ consumed = true; if(((!frag.config.isShown() && tile.block().shouldShowConfigure(tile, player)) //if the config fragment is hidden, show //alternatively, the current selected block can 'agree' to switch config tiles @@ -178,14 +177,14 @@ public abstract class InputHandler implements InputProcessor{ } //call tapped event - if(!consumed && tile.getTeam() == player.getTeam()){ + if(!consumed && tile.interactable(player.getTeam())){ Call.onTileTapped(player, tile); } //consume tap event if necessary - if(tile.getTeam() == player.getTeam() && tile.block().consumesTap){ + if(tile.interactable(player.getTeam()) && tile.block().consumesTap){ consumed = true; - }else if((tile.getTeam() == player.getTeam() || tile.getTeam() == Team.none) && tile.block().synthetic() && !consumed){ + }else if(tile.interactable(player.getTeam()) && tile.block().synthetic() && !consumed){ if(tile.block().hasItems && tile.entity.items.total() > 0){ frag.inv.showFor(tile); consumed = true; @@ -297,7 +296,7 @@ public abstract class InputHandler implements InputProcessor{ ItemStack stack = player.item(); - if(tile.block().acceptStack(stack.item, stack.amount, tile, player) > 0 && tile.getTeam() == player.getTeam() && tile.block().hasItems){ + if(tile.block().acceptStack(stack.item, stack.amount, tile, player) > 0 && tile.interactable(player.getTeam()) && tile.block().hasItems){ Call.transferInventory(player, tile); }else{ Call.dropItem(player.angleTo(x, y)); diff --git a/core/src/io/anuke/mindustry/world/Tile.java b/core/src/io/anuke/mindustry/world/Tile.java index 6472edd13d..9bdbe56b48 100644 --- a/core/src/io/anuke/mindustry/world/Tile.java +++ b/core/src/io/anuke/mindustry/world/Tile.java @@ -312,6 +312,10 @@ public class Tile implements Position, TargetTrait{ return null; } + public boolean interactable(Team team){ + return getTeam() == Team.none || team == getTeam(); + } + public void updateOcclusion(){ cost = 1; boolean occluded = false;