From d03ceb2a23d3ab0b38396527b0d16bc2ea944a76 Mon Sep 17 00:00:00 2001 From: Anuken Date: Mon, 26 Nov 2018 12:40:24 -0500 Subject: [PATCH] Bugfixes / Sorter item memory --- .../ui/fragments/PlacementFragment.java | 8 ++++++-- .../world/blocks/distribution/Sorter.java | 19 ++++++++++++++++--- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/core/src/io/anuke/mindustry/ui/fragments/PlacementFragment.java b/core/src/io/anuke/mindustry/ui/fragments/PlacementFragment.java index f3923079d8..6388b3ee28 100644 --- a/core/src/io/anuke/mindustry/ui/fragments/PlacementFragment.java +++ b/core/src/io/anuke/mindustry/ui/fragments/PlacementFragment.java @@ -2,6 +2,7 @@ package io.anuke.mindustry.ui.fragments; import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.math.Interpolation; +import com.badlogic.gdx.math.Vector2; import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.entities.TileEntity; import io.anuke.mindustry.game.EventType.WorldLoadGraphicsEvent; @@ -33,7 +34,7 @@ public class PlacementFragment extends Fragment{ Category currentCategory = Category.turret; Block hovered, lastDisplay; Tile hoverTile; - Table blockTable, toggler; + Table blockTable, toggler, topTable; boolean shown = true; public PlacementFragment(){ @@ -106,6 +107,7 @@ public class PlacementFragment extends Fragment{ //top table with hover info frame.table("clear", top -> { + topTable = top; top.add(new Table()).growX().update(topTable -> { if((tileDisplayBlock() == null && lastDisplay == getSelected()) || (tileDisplayBlock() != null && lastDisplay == tileDisplayBlock())) return; @@ -194,8 +196,10 @@ public class PlacementFragment extends Fragment{ Block getSelected(){ Block toDisplay = null; + Vector2 v = topTable.stageToLocalCoordinates(Graphics.mouse()); + //setup hovering tile - if(!ui.hasMouse()){ + if(!ui.hasMouse() && topTable.hit(v.x, v.y, false) == null){ Tile tile = world.tileWorld(Graphics.mouseWorld().x, Graphics.mouseWorld().y); if(tile != null){ hoverTile = tile.target(); diff --git a/core/src/io/anuke/mindustry/world/blocks/distribution/Sorter.java b/core/src/io/anuke/mindustry/world/blocks/distribution/Sorter.java index e99769ffd6..c7a5737e54 100644 --- a/core/src/io/anuke/mindustry/world/blocks/distribution/Sorter.java +++ b/core/src/io/anuke/mindustry/world/blocks/distribution/Sorter.java @@ -4,7 +4,6 @@ import io.anuke.annotations.Annotations.Loc; import io.anuke.annotations.Annotations.Remote; import io.anuke.mindustry.entities.Player; import io.anuke.mindustry.entities.TileEntity; -import io.anuke.mindustry.gen.Call; import io.anuke.mindustry.type.Item; import io.anuke.mindustry.world.Block; import io.anuke.mindustry.world.Tile; @@ -13,13 +12,17 @@ import io.anuke.mindustry.world.meta.BlockGroup; import io.anuke.ucore.graphics.Draw; import io.anuke.ucore.scene.ui.layout.Table; import io.anuke.ucore.util.Mathf; +import io.anuke.mindustry.gen.Call; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; -import static io.anuke.mindustry.Vars.*; + +import static io.anuke.mindustry.Vars.content; +import static io.anuke.mindustry.Vars.threads; public class Sorter extends Block implements SelectionTrait{ + private static Item lastItem; public Sorter(String name){ super(name); @@ -35,6 +38,13 @@ public class Sorter extends Block implements SelectionTrait{ return true; } + @Override + public void playerPlaced(Tile tile){ + if(lastItem != null){ + threads.runDelay(() -> Call.setSorterItem(null, tile, lastItem)); + } + } + @Remote(targets = Loc.both, called = Loc.both, forward = true) public static void setSorterItem(Player player, Tile tile, Item item){ SorterEntity entity = tile.entity(); @@ -108,7 +118,10 @@ public class Sorter extends Block implements SelectionTrait{ @Override public void buildTable(Tile tile, Table table){ SorterEntity entity = tile.entity(); - buildItemTable(table, () -> entity.sortItem, item -> Call.setSorterItem(null, tile, item)); + buildItemTable(table, () -> entity.sortItem, item -> { + lastItem = item; + Call.setSorterItem(null, tile, item); + }); } @Override