Implemented null-items for sorters and item sources
This commit is contained in:
@@ -8,12 +8,11 @@ buildscript {
|
|||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.mobidevelop.robovm:robovm-gradle-plugin:2.3.0'
|
classpath 'com.mobidevelop.robovm:robovm-gradle-plugin:2.3.0'
|
||||||
classpath "com.badlogicgames.gdx:gdx-tools:1.9.8"
|
classpath "com.badlogicgames.gdx:gdx-tools:1.9.9"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
allprojects {
|
allprojects {
|
||||||
apply plugin: "eclipse"
|
|
||||||
apply plugin: "idea"
|
apply plugin: "idea"
|
||||||
|
|
||||||
version = 'release'
|
version = 'release'
|
||||||
|
|||||||
@@ -92,8 +92,11 @@ public class DebugBlocks extends BlockList implements ContentList{
|
|||||||
@Override
|
@Override
|
||||||
public void update(Tile tile){
|
public void update(Tile tile){
|
||||||
SorterEntity entity = tile.entity();
|
SorterEntity entity = tile.entity();
|
||||||
|
if(entity.sortItem == null) return;
|
||||||
|
|
||||||
entity.items.set(entity.sortItem, 1);
|
entity.items.set(entity.sortItem, 1);
|
||||||
tryDump(tile, entity.sortItem);
|
tryDump(tile, entity.sortItem);
|
||||||
|
entity.items.set(entity.sortItem, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ public class JoinDialog extends FloatingDialog{
|
|||||||
versionString = Bundles.get("text.server.outdated");
|
versionString = Bundles.get("text.server.outdated");
|
||||||
}else if(host.version < Version.build && Version.build != -1){
|
}else if(host.version < Version.build && Version.build != -1){
|
||||||
versionString = Bundles.get("text.server.outdated") + "\n" +
|
versionString = Bundles.get("text.server.outdated") + "\n" +
|
||||||
Bundles.format("text.server.version", host.version);
|
Bundles.format("text.server.version", host.version, "");
|
||||||
}else if(host.version > Version.build && Version.build != -1){
|
}else if(host.version > Version.build && Version.build != -1){
|
||||||
versionString = Bundles.get("text.server.outdated.client") + "\n" +
|
versionString = Bundles.get("text.server.outdated.client") + "\n" +
|
||||||
Bundles.format("text.server.version", host.version, "");
|
Bundles.format("text.server.version", host.version, "");
|
||||||
|
|||||||
@@ -4,43 +4,32 @@ import com.badlogic.gdx.utils.Array;
|
|||||||
import io.anuke.mindustry.type.Item;
|
import io.anuke.mindustry.type.Item;
|
||||||
import io.anuke.ucore.function.Consumer;
|
import io.anuke.ucore.function.Consumer;
|
||||||
import io.anuke.ucore.function.Supplier;
|
import io.anuke.ucore.function.Supplier;
|
||||||
import io.anuke.ucore.graphics.Draw;
|
|
||||||
import io.anuke.ucore.scene.style.TextureRegionDrawable;
|
import io.anuke.ucore.scene.style.TextureRegionDrawable;
|
||||||
import io.anuke.ucore.scene.ui.ButtonGroup;
|
import io.anuke.ucore.scene.ui.ButtonGroup;
|
||||||
import io.anuke.ucore.scene.ui.ImageButton;
|
import io.anuke.ucore.scene.ui.ImageButton;
|
||||||
import io.anuke.ucore.scene.ui.layout.Table;
|
import io.anuke.ucore.scene.ui.layout.Table;
|
||||||
|
|
||||||
import static io.anuke.mindustry.Vars.*;
|
import static io.anuke.mindustry.Vars.content;
|
||||||
|
import static io.anuke.mindustry.Vars.control;
|
||||||
|
|
||||||
public interface SelectionTrait{
|
public interface SelectionTrait{
|
||||||
|
|
||||||
default void buildItemTable(Table table, Supplier<Item> holder, Consumer<Item> consumer){
|
default void buildItemTable(Table table, Supplier<Item> holder, Consumer<Item> consumer){
|
||||||
buildItemTable(table, false, holder, consumer);
|
|
||||||
}
|
|
||||||
|
|
||||||
default void buildItemTable(Table table, boolean nullItem, Supplier<Item> holder, Consumer<Item> consumer){
|
|
||||||
|
|
||||||
Array<Item> items = content.items();
|
Array<Item> items = content.items();
|
||||||
|
|
||||||
ButtonGroup<ImageButton> group = new ButtonGroup<>();
|
ButtonGroup<ImageButton> group = new ButtonGroup<>();
|
||||||
|
group.setMinCheckCount(0);
|
||||||
Table cont = new Table();
|
Table cont = new Table();
|
||||||
cont.defaults().size(38);
|
cont.defaults().size(38);
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
if(nullItem){
|
|
||||||
ImageButton button = cont.addImageButton("white", "clear-toggle", 24, () -> consumer.accept(null)).group(group).get();
|
|
||||||
button.getStyle().imageUp = new TextureRegionDrawable(Draw.region("icon-nullitem"));
|
|
||||||
button.setChecked(holder.get() == null);
|
|
||||||
|
|
||||||
i ++;
|
|
||||||
}
|
|
||||||
|
|
||||||
for(Item item : items){
|
for(Item item : items){
|
||||||
if(!control.unlocks.isUnlocked(item)) continue;
|
if(!control.unlocks.isUnlocked(item)) continue;
|
||||||
|
|
||||||
ImageButton button = cont.addImageButton("white", "clear-toggle", 24, () -> consumer.accept(item))
|
ImageButton button = cont.addImageButton("white", "clear-toggle", 24, () -> {}).group(group).get();
|
||||||
.group(group).get();
|
button.changed(() -> consumer.accept(button.isChecked() ? item : null));
|
||||||
button.getStyle().imageUp = new TextureRegionDrawable(item.region);
|
button.getStyle().imageUp = new TextureRegionDrawable(item.region);
|
||||||
button.setChecked(holder.get() == item);
|
button.setChecked(holder.get() == item);
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,9 @@ public class Sorter extends Block implements SelectionTrait{
|
|||||||
@Remote(targets = Loc.both, called = Loc.both, forward = true)
|
@Remote(targets = Loc.both, called = Loc.both, forward = true)
|
||||||
public static void setSorterItem(Player player, Tile tile, Item item){
|
public static void setSorterItem(Player player, Tile tile, Item item){
|
||||||
SorterEntity entity = tile.entity();
|
SorterEntity entity = tile.entity();
|
||||||
if(entity != null) entity.sortItem = item;
|
if(entity != null){
|
||||||
|
entity.sortItem = item;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -56,6 +58,7 @@ public class Sorter extends Block implements SelectionTrait{
|
|||||||
super.draw(tile);
|
super.draw(tile);
|
||||||
|
|
||||||
SorterEntity entity = tile.entity();
|
SorterEntity entity = tile.entity();
|
||||||
|
if(entity.sortItem == null) return;
|
||||||
|
|
||||||
Draw.color(entity.sortItem.color);
|
Draw.color(entity.sortItem.color);
|
||||||
Draw.rect("blank", tile.worldx(), tile.worldy(), 4f, 4f);
|
Draw.rect("blank", tile.worldx(), tile.worldy(), 4f, 4f);
|
||||||
@@ -130,16 +133,17 @@ public class Sorter extends Block implements SelectionTrait{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class SorterEntity extends TileEntity{
|
public static class SorterEntity extends TileEntity{
|
||||||
public Item sortItem = content.item(0);
|
public Item sortItem;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void writeConfig(DataOutput stream) throws IOException{
|
public void writeConfig(DataOutput stream) throws IOException{
|
||||||
stream.writeByte(sortItem.id);
|
stream.writeByte(sortItem == null ? -1 : sortItem.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void readConfig(DataInput stream) throws IOException{
|
public void readConfig(DataInput stream) throws IOException{
|
||||||
sortItem = content.items().get(stream.readByte());
|
byte b = stream.readByte();
|
||||||
|
sortItem = b == -1 ? null : content.items().get(b);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ public class PowerNode extends PowerBlock{
|
|||||||
|
|
||||||
@Remote(targets = Loc.both, called = Loc.server, forward = true)
|
@Remote(targets = Loc.both, called = Loc.server, forward = true)
|
||||||
public static void unlinkPowerNodes(Player player, Tile tile, Tile other){
|
public static void unlinkPowerNodes(Player player, Tile tile, Tile other){
|
||||||
if(tile.entity.power == null) return;
|
if(tile.entity.power == null || other.entity == null || other.entity.power == null) return;
|
||||||
|
|
||||||
TileEntity entity = tile.entity();
|
TileEntity entity = tile.entity();
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public class SortedUnloader extends Unloader implements SelectionTrait{
|
|||||||
@Override
|
@Override
|
||||||
public void buildTable(Tile tile, Table table){
|
public void buildTable(Tile tile, Table table){
|
||||||
SortedUnloaderEntity entity = tile.entity();
|
SortedUnloaderEntity entity = tile.entity();
|
||||||
buildItemTable(table, true, () -> entity.sortItem, item -> Call.setSortedUnloaderItem(null, tile, item));
|
buildItemTable(table, () -> entity.sortItem, item -> Call.setSortedUnloaderItem(null, tile, item));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ apply plugin: "java"
|
|||||||
sourceCompatibility = 1.8
|
sourceCompatibility = 1.8
|
||||||
sourceSets.main.java.srcDirs = [ "src/" ]
|
sourceSets.main.java.srcDirs = [ "src/" ]
|
||||||
|
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color
|
import com.badlogic.gdx.graphics.Color
|
||||||
import com.badlogic.gdx.tools.texturepacker.TexturePacker
|
import com.badlogic.gdx.tools.texturepacker.TexturePacker
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user