Bugfixes / Sorter item memory

This commit is contained in:
Anuken
2018-11-26 12:40:24 -05:00
parent a241f63ddc
commit d03ceb2a23
2 changed files with 22 additions and 5 deletions

View File

@@ -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();

View File

@@ -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