mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-02 20:33:50 +07:00
Implemented null-items for sorters and item sources
This commit is contained in:
parent
d56c041c4a
commit
99fb1a4c5f
@ -8,12 +8,11 @@ buildscript {
|
||||
}
|
||||
dependencies {
|
||||
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 {
|
||||
apply plugin: "eclipse"
|
||||
apply plugin: "idea"
|
||||
|
||||
version = 'release'
|
||||
|
@ -92,8 +92,11 @@ public class DebugBlocks extends BlockList implements ContentList{
|
||||
@Override
|
||||
public void update(Tile tile){
|
||||
SorterEntity entity = tile.entity();
|
||||
if(entity.sortItem == null) return;
|
||||
|
||||
entity.items.set(entity.sortItem, 1);
|
||||
tryDump(tile, entity.sortItem);
|
||||
entity.items.set(entity.sortItem, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -156,7 +156,7 @@ public class JoinDialog extends FloatingDialog{
|
||||
versionString = Bundles.get("text.server.outdated");
|
||||
}else if(host.version < Version.build && Version.build != -1){
|
||||
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){
|
||||
versionString = Bundles.get("text.server.outdated.client") + "\n" +
|
||||
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.ucore.function.Consumer;
|
||||
import io.anuke.ucore.function.Supplier;
|
||||
import io.anuke.ucore.graphics.Draw;
|
||||
import io.anuke.ucore.scene.style.TextureRegionDrawable;
|
||||
import io.anuke.ucore.scene.ui.ButtonGroup;
|
||||
import io.anuke.ucore.scene.ui.ImageButton;
|
||||
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{
|
||||
|
||||
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();
|
||||
|
||||
ButtonGroup<ImageButton> group = new ButtonGroup<>();
|
||||
group.setMinCheckCount(0);
|
||||
Table cont = new Table();
|
||||
cont.defaults().size(38);
|
||||
|
||||
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){
|
||||
if(!control.unlocks.isUnlocked(item)) continue;
|
||||
|
||||
ImageButton button = cont.addImageButton("white", "clear-toggle", 24, () -> consumer.accept(item))
|
||||
.group(group).get();
|
||||
ImageButton button = cont.addImageButton("white", "clear-toggle", 24, () -> {}).group(group).get();
|
||||
button.changed(() -> consumer.accept(button.isChecked() ? item : null));
|
||||
button.getStyle().imageUp = new TextureRegionDrawable(item.region);
|
||||
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)
|
||||
public static void setSorterItem(Player player, Tile tile, Item item){
|
||||
SorterEntity entity = tile.entity();
|
||||
if(entity != null) entity.sortItem = item;
|
||||
if(entity != null){
|
||||
entity.sortItem = item;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -56,6 +58,7 @@ public class Sorter extends Block implements SelectionTrait{
|
||||
super.draw(tile);
|
||||
|
||||
SorterEntity entity = tile.entity();
|
||||
if(entity.sortItem == null) return;
|
||||
|
||||
Draw.color(entity.sortItem.color);
|
||||
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 Item sortItem = content.item(0);
|
||||
public Item sortItem;
|
||||
|
||||
@Override
|
||||
public void writeConfig(DataOutput stream) throws IOException{
|
||||
stream.writeByte(sortItem.id);
|
||||
stream.writeByte(sortItem == null ? -1 : sortItem.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
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)
|
||||
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();
|
||||
|
||||
|
@ -65,7 +65,7 @@ public class SortedUnloader extends Unloader implements SelectionTrait{
|
||||
@Override
|
||||
public void buildTable(Tile tile, Table table){
|
||||
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
|
||||
|
@ -3,7 +3,6 @@ apply plugin: "java"
|
||||
sourceCompatibility = 1.8
|
||||
sourceSets.main.java.srcDirs = [ "src/" ]
|
||||
|
||||
|
||||
import com.badlogic.gdx.graphics.Color
|
||||
import com.badlogic.gdx.tools.texturepacker.TexturePacker
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user