mirror of
https://github.com/Anuken/Mindustry.git
synced 2025-02-11 11:17:11 +07:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
2a10562e9e
@ -18,6 +18,7 @@ import io.anuke.mindustry.gen.BrokenBlock;
|
||||
import io.anuke.mindustry.gen.Call;
|
||||
import io.anuke.mindustry.net.Net;
|
||||
import io.anuke.mindustry.type.Item;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.blocks.BuildBlock;
|
||||
@ -81,9 +82,11 @@ public class Logic implements ApplicationListener{
|
||||
//add starting items
|
||||
if(!world.isZone()){
|
||||
for(Team team : Team.all){
|
||||
if(state.teams.isActive(team)){
|
||||
for(Tile core : state.teams.get(team).cores){
|
||||
core.entity.items.add(Items.copper, 200);
|
||||
if(!state.teams.get(team).cores.isEmpty()){
|
||||
TileEntity entity = state.teams.get(team).cores.first().entity;
|
||||
entity.items.clear();
|
||||
for(ItemStack stack : state.rules.loadout){
|
||||
entity.items.add(stack.item, stack.amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,9 @@ package io.anuke.mindustry.game;
|
||||
|
||||
import io.anuke.annotations.Annotations.Serialize;
|
||||
import io.anuke.arc.collection.Array;
|
||||
import io.anuke.mindustry.content.Items;
|
||||
import io.anuke.mindustry.io.JsonIO;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.type.Zone;
|
||||
|
||||
/**
|
||||
@ -63,6 +65,8 @@ public class Rules{
|
||||
public boolean attackMode = false;
|
||||
/** Whether this is the editor gamemode. */
|
||||
public boolean editor = false;
|
||||
/** Starting items put in cores */
|
||||
public Array<ItemStack> loadout = Array.with(ItemStack.with(Items.copper, 200));
|
||||
|
||||
/** Copies this ruleset exactly. Not very efficient at all, do not use often. */
|
||||
public Rules copy(){
|
||||
|
@ -14,6 +14,7 @@ public class JsonIO{
|
||||
private static Json json = new Json(){{
|
||||
setIgnoreUnknownFields(true);
|
||||
setElementType(Rules.class, "spawns", SpawnGroup.class);
|
||||
setElementType(Rules.class, "loadout", ItemStack.class);
|
||||
|
||||
setSerializer(Zone.class, new Serializer<Zone>(){
|
||||
@Override
|
||||
@ -57,6 +58,21 @@ public class JsonIO{
|
||||
return out;
|
||||
}
|
||||
});
|
||||
|
||||
setSerializer(ItemStack.class, new Serializer<ItemStack>(){
|
||||
@Override
|
||||
public void write(Json json, ItemStack object, Class knownType){
|
||||
json.writeObjectStart();
|
||||
json.writeValue("item", object.item);
|
||||
json.writeValue("amount", object.amount);
|
||||
json.writeObjectEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack read(Json json, JsonValue jsonData, Class type){
|
||||
return new ItemStack(json.getSerializer(Item.class).read(json, jsonData.get("item"), Item.class), jsonData.getInt("amount"));
|
||||
}
|
||||
});
|
||||
}};
|
||||
|
||||
public static String write(Object object){
|
||||
|
@ -4,9 +4,13 @@ import io.anuke.arc.function.*;
|
||||
import io.anuke.arc.graphics.Color;
|
||||
import io.anuke.arc.scene.ui.layout.Table;
|
||||
import io.anuke.arc.util.Strings;
|
||||
import io.anuke.mindustry.content.Blocks;
|
||||
import io.anuke.mindustry.content.Items;
|
||||
import io.anuke.mindustry.core.Platform;
|
||||
import io.anuke.mindustry.game.Rules;
|
||||
import io.anuke.mindustry.graphics.Pal;
|
||||
import io.anuke.mindustry.type.ItemStack;
|
||||
import io.anuke.mindustry.type.ItemType;
|
||||
|
||||
import static io.anuke.mindustry.Vars.tilesize;
|
||||
|
||||
@ -14,10 +18,12 @@ public class CustomRulesDialog extends FloatingDialog{
|
||||
private Table main;
|
||||
private Rules rules;
|
||||
private Supplier<Rules> resetter;
|
||||
private LoadoutDialog loadoutDialog;
|
||||
|
||||
public CustomRulesDialog(){
|
||||
super("$mode.custom");
|
||||
|
||||
loadoutDialog = new LoadoutDialog();
|
||||
setFillParent(true);
|
||||
shown(this::setup);
|
||||
addCloseButton();
|
||||
@ -58,6 +64,19 @@ public class CustomRulesDialog extends FloatingDialog{
|
||||
number("$rules.buildcostmultiplier", false, f -> rules.buildCostMultiplier = f, () -> rules.buildCostMultiplier, () -> !rules.infiniteResources);
|
||||
number("$rules.buildspeedmultiplier", f -> rules.buildSpeedMultiplier = f, () -> rules.buildSpeedMultiplier);
|
||||
|
||||
main.addButton("$configure",
|
||||
() -> loadoutDialog.show(
|
||||
Blocks.coreShard.itemCapacity,
|
||||
() -> rules.loadout,
|
||||
() -> {
|
||||
rules.loadout.clear();
|
||||
rules.loadout.add(new ItemStack(Items.copper, 200));
|
||||
},
|
||||
() -> {}, () -> {},
|
||||
item -> item.type == ItemType.material
|
||||
)).left().width(300f);
|
||||
main.row();
|
||||
|
||||
title("$rules.title.player");
|
||||
number("$rules.playerdamagemultiplier", f -> rules.playerDamageMultiplier = f, () -> rules.playerDamageMultiplier);
|
||||
number("$rules.playerhealthmultiplier", f -> rules.playerHealthMultiplier = f, () -> rules.playerHealthMultiplier);
|
||||
|
@ -1,16 +1,22 @@
|
||||
package io.anuke.mindustry.ui.dialogs;
|
||||
|
||||
import io.anuke.arc.collection.Array;
|
||||
import io.anuke.arc.function.Predicate;
|
||||
import io.anuke.arc.function.Supplier;
|
||||
import io.anuke.arc.scene.ui.TextButton;
|
||||
import io.anuke.mindustry.type.*;
|
||||
|
||||
import static io.anuke.mindustry.Vars.content;
|
||||
import static io.anuke.mindustry.Vars.data;
|
||||
|
||||
public class ZoneLoadoutDialog extends FloatingDialog{
|
||||
private Zone zone;
|
||||
public class LoadoutDialog extends FloatingDialog{
|
||||
private Runnable hider;
|
||||
private Supplier<Array<ItemStack>> supplier;
|
||||
private Runnable resetter;
|
||||
private Runnable updater;
|
||||
private Predicate<Item> filter;
|
||||
private int capacity;
|
||||
|
||||
public ZoneLoadoutDialog(){
|
||||
public LoadoutDialog(){
|
||||
super("$configure");
|
||||
setFillParent(false);
|
||||
addCloseButton();
|
||||
@ -22,15 +28,19 @@ public class ZoneLoadoutDialog extends FloatingDialog{
|
||||
});
|
||||
buttons.row();
|
||||
buttons.addButton("$settings.reset", () -> {
|
||||
zone.resetStartingItems();
|
||||
zone.updateLaunchCost();
|
||||
resetter.run();
|
||||
updater.run();
|
||||
setup();
|
||||
}).size(210f, 64f);
|
||||
}
|
||||
|
||||
public void show(Zone zone, Runnable hider){
|
||||
public void show(int capacity, Supplier<Array<ItemStack>> supplier, Runnable reseter, Runnable updater, Runnable hider, Predicate<Item> filter){
|
||||
this.resetter = reseter;
|
||||
this.supplier = supplier;
|
||||
this.updater = updater;
|
||||
this.capacity = capacity;
|
||||
this.hider = hider;
|
||||
this.zone = zone;
|
||||
this.filter = filter;
|
||||
show();
|
||||
}
|
||||
|
||||
@ -39,20 +49,20 @@ public class ZoneLoadoutDialog extends FloatingDialog{
|
||||
float bsize = 40f;
|
||||
int step = 50;
|
||||
|
||||
for(ItemStack stack : zone.getStartingItems()){
|
||||
for(ItemStack stack : supplier.get()){
|
||||
cont.addButton("x", "clear-partial", () -> {
|
||||
zone.getStartingItems().remove(stack);
|
||||
zone.updateLaunchCost();
|
||||
supplier.get().remove(stack);
|
||||
updater.run();
|
||||
setup();
|
||||
}).size(bsize);
|
||||
|
||||
cont.addButton("-", "clear-partial", () -> {
|
||||
stack.amount = Math.max(stack.amount - step, 0);
|
||||
zone.updateLaunchCost();
|
||||
updater.run();
|
||||
}).size(bsize);
|
||||
cont.addButton("+", "clear-partial", () -> {
|
||||
stack.amount = Math.min(stack.amount + step, zone.loadout.core().itemCapacity);
|
||||
zone.updateLaunchCost();
|
||||
stack.amount = Math.min(stack.amount + step, capacity);
|
||||
updater.run();
|
||||
}).size(bsize);
|
||||
|
||||
cont.addImage(stack.item.icon(Item.Icon.medium)).size(8 * 3).padRight(4);
|
||||
@ -64,10 +74,10 @@ public class ZoneLoadoutDialog extends FloatingDialog{
|
||||
cont.addButton("$add", () -> {
|
||||
FloatingDialog dialog = new FloatingDialog("");
|
||||
dialog.setFillParent(false);
|
||||
for(Item item : content.items().select(item -> data.getItem(item) > 0 && item.type == ItemType.material && zone.getStartingItems().find(stack -> stack.item == item) == null)){
|
||||
for(Item item : content.items().select(item -> filter.test(item) && item.type == ItemType.material && supplier.get().find(stack -> stack.item == item) == null)){
|
||||
TextButton button = dialog.cont.addButton("", "clear", () -> {
|
||||
zone.getStartingItems().add(new ItemStack(item, 0));
|
||||
zone.updateLaunchCost();
|
||||
supplier.get().add(new ItemStack(item, 0));
|
||||
updater.run();
|
||||
setup();
|
||||
dialog.hide();
|
||||
}).size(300f, 36f).get();
|
||||
@ -78,7 +88,7 @@ public class ZoneLoadoutDialog extends FloatingDialog{
|
||||
dialog.cont.row();
|
||||
}
|
||||
dialog.show();
|
||||
}).colspan(4).size(100f, bsize).left().disabled(b -> !content.items().contains(item -> data.getItem(item) > 0 && item.type == ItemType.material && !zone.getStartingItems().contains(stack -> stack.item == item)));
|
||||
}).colspan(4).size(100f, bsize).left().disabled(b -> !content.items().contains(item -> filter.test(item) && !supplier.get().contains(stack -> stack.item == item)));
|
||||
pack();
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@ import io.anuke.mindustry.world.Block.Icon;
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
public class ZoneInfoDialog extends FloatingDialog{
|
||||
private ZoneLoadoutDialog loadout = new ZoneLoadoutDialog();
|
||||
private LoadoutDialog loadout = new LoadoutDialog();
|
||||
|
||||
public ZoneInfoDialog(){
|
||||
super("");
|
||||
@ -101,7 +101,16 @@ public class ZoneInfoDialog extends FloatingDialog{
|
||||
cont.row();
|
||||
cont.addImage("whiteui").color(Pal.accent).height(3).pad(6).growX();
|
||||
cont.row();
|
||||
cont.addButton(zone.canConfigure() ? "$configure" : Core.bundle.format("configure.locked", zone.configureWave), () -> loadout.show(zone, rebuildItems)).fillX().pad(3).disabled(b -> !zone.canConfigure());
|
||||
cont.addButton(zone.canConfigure() ? "$configure" : Core.bundle.format("configure.locked", zone.configureWave),
|
||||
() -> loadout.show(
|
||||
zone.loadout.core().itemCapacity,
|
||||
() -> zone.getStartingItems(),
|
||||
() -> zone.resetStartingItems(),
|
||||
() -> zone.updateLaunchCost(),
|
||||
rebuildItems,
|
||||
item -> data.getItem(item) > 0 && item.type == ItemType.material
|
||||
)
|
||||
).fillX().pad(3).disabled(b -> !zone.canConfigure());
|
||||
cont.row();
|
||||
cont.table(res -> {
|
||||
res.add("$zone.resources").padRight(6);
|
||||
|
Loading…
Reference in New Issue
Block a user