Global inventory / 'Deploying' / Removed command center

This commit is contained in:
Anuken
2019-01-09 09:07:48 -05:00
parent 28fa0b070d
commit 048b7bd32f
26 changed files with 4501 additions and 4635 deletions

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 338 KiB

After

Width:  |  Height:  |  Size: 120 KiB

View File

@@ -16,6 +16,7 @@ import io.anuke.mindustry.entities.effect.Fire;
import io.anuke.mindustry.entities.effect.Puddle; import io.anuke.mindustry.entities.effect.Puddle;
import io.anuke.mindustry.entities.traits.SyncTrait; import io.anuke.mindustry.entities.traits.SyncTrait;
import io.anuke.mindustry.entities.units.BaseUnit; import io.anuke.mindustry.entities.units.BaseUnit;
import io.anuke.mindustry.game.GlobalData;
import io.anuke.mindustry.game.Team; import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.game.Version; import io.anuke.mindustry.game.Version;
import io.anuke.mindustry.gen.Serialization; import io.anuke.mindustry.gen.Serialization;
@@ -110,6 +111,7 @@ public class Vars{
public static ContentLoader content; public static ContentLoader content;
public static GameState state; public static GameState state;
public static GlobalData data;
public static Control control; public static Control control;
public static Logic logic; public static Logic logic;
@@ -175,6 +177,7 @@ public class Vars{
} }
state = new GameState(); state = new GameState();
data = new GlobalData();
mobile = Core.app.getType() == ApplicationType.Android || Core.app.getType() == ApplicationType.iOS || testMobile; mobile = Core.app.getType() == ApplicationType.Android || Core.app.getType() == ApplicationType.iOS || testMobile;
ios = Core.app.getType() == ApplicationType.iOS; ios = Core.app.getType() == ApplicationType.iOS;

View File

@@ -64,7 +64,7 @@ public class Blocks implements ContentList{
//units //units
spiritFactory, phantomFactory, wraithFactory, ghoulFactory, revenantFactory, daggerFactory, titanFactory, spiritFactory, phantomFactory, wraithFactory, ghoulFactory, revenantFactory, daggerFactory, titanFactory,
fortressFactory, reconstructor, repairPoint, commandCenter, fortressFactory, reconstructor, repairPoint,
//upgrades //upgrades
alphaPad, deltaPad, tauPad, omegaPad, dartPad, javelinPad, tridentPad, glaivePad; alphaPad, deltaPad, tauPad, omegaPad, dartPad, javelinPad, tridentPad, glaivePad;
@@ -1057,10 +1057,6 @@ public class Blocks implements ContentList{
size = 2; size = 2;
}}; }};
commandCenter = new CommandCenter("command-center"){{
size = 2;
}};
//endregion //endregion
//region upgrades //region upgrades

View File

@@ -43,11 +43,12 @@ public class Recipes implements ContentList{
new Recipe(effect, Blocks.container, new ItemStack(Items.titanium, 200)); new Recipe(effect, Blocks.container, new ItemStack(Items.titanium, 200));
new Recipe(effect, Blocks.vault, new ItemStack(Items.titanium, 500), new ItemStack(Items.thorium, 250)); new Recipe(effect, Blocks.vault, new ItemStack(Items.titanium, 500), new ItemStack(Items.thorium, 250));
new Recipe(effect, Blocks.core, //removed; no longer fits gameplay
/*new Recipe(effect, Blocks.core,
new ItemStack(Items.copper, 2000), new ItemStack(Items.titanium, 2000), new ItemStack(Items.copper, 2000), new ItemStack(Items.titanium, 2000),
new ItemStack(Items.silicon, 1750), new ItemStack(Items.thorium, 1000), new ItemStack(Items.silicon, 1750), new ItemStack(Items.thorium, 1000),
new ItemStack(Items.surgealloy, 500), new ItemStack(Items.phasefabric, 750) new ItemStack(Items.surgealloy, 500), new ItemStack(Items.phasefabric, 750)
); );*/
//projectors //projectors
new Recipe(effect, Blocks.mendProjector, new ItemStack(Items.lead, 200), new ItemStack(Items.titanium, 150), new ItemStack(Items.titanium, 50), new ItemStack(Items.silicon, 180)); new Recipe(effect, Blocks.mendProjector, new ItemStack(Items.lead, 200), new ItemStack(Items.titanium, 150), new ItemStack(Items.titanium, 50), new ItemStack(Items.silicon, 180));

View File

@@ -20,7 +20,7 @@ import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.game.Content; import io.anuke.mindustry.game.Content;
import io.anuke.mindustry.game.EventType.*; import io.anuke.mindustry.game.EventType.*;
import io.anuke.mindustry.game.Saves; import io.anuke.mindustry.game.Saves;
import io.anuke.mindustry.game.Unlocks; import io.anuke.mindustry.game.GlobalData;
import io.anuke.mindustry.gen.Call; import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.input.Binding; import io.anuke.mindustry.input.Binding;
import io.anuke.mindustry.input.DesktopInput; import io.anuke.mindustry.input.DesktopInput;
@@ -45,16 +45,15 @@ import static io.anuke.mindustry.Vars.*;
*/ */
public class Control implements ApplicationListener{ public class Control implements ApplicationListener{
public final Saves saves; public final Saves saves;
public final Unlocks unlocks;
private Interval timerRPC = new Interval(), timerUnlock = new Interval(); private Interval timerRPC = new Interval();
private boolean hiscore = false; private boolean hiscore = false;
private boolean wasPaused = false; private boolean wasPaused = false;
private InputHandler[] inputs = {}; private InputHandler[] inputs = {};
public Control(){ public Control(){
saves = new Saves(); saves = new Saves();
unlocks = new Unlocks(); data = new GlobalData();
Core.input.setCatch(KeyCode.BACK, true); Core.input.setCatch(KeyCode.BACK, true);
@@ -70,7 +69,7 @@ public class Control implements ApplicationListener{
"If more textures are used, the map editor will not display them correctly."); "If more textures are used, the map editor will not display them correctly.");
} }
unlocks.load(); data.load();
Core.settings.setAppName(appName); Core.settings.setAppName(appName);
Core.settings.defaults( Core.settings.defaults(
@@ -228,10 +227,10 @@ public class Control implements ApplicationListener{
if(entity == null) return; if(entity == null) return;
entity.items.forEach((item, amount) -> unlocks.unlockContent(item)); entity.items.forEach((item, amount) -> data.unlockContent(item));
if(players[0].inventory.hasItem()){ if(players[0].inventory.hasItem()){
unlocks.unlockContent(players[0].inventory.getItem().item); data.unlockContent(players[0].inventory.getItem().item);
} }
outer: outer:
@@ -242,7 +241,7 @@ public class Control implements ApplicationListener{
if(!entity.items.has(stack.item, Math.min((int) (stack.amount), 2000))) continue outer; if(!entity.items.has(stack.item, Math.min((int) (stack.amount), 2000))) continue outer;
} }
if(unlocks.unlockContent(recipe)){ if(data.unlockContent(recipe)){
ui.hudfrag.showUnlock(recipe); ui.hudfrag.showUnlock(recipe);
} }
} }
@@ -315,16 +314,6 @@ public class Control implements ApplicationListener{
Platform.instance.updateRPC(); Platform.instance.updateRPC();
} }
//check unlocks every 2 seconds
if(!state.mode.infiniteResources && timerUnlock.get(120)){
checkUnlockableBlocks();
//save if the unlocks changed
if(unlocks.isDirty()){
unlocks.save();
}
}
if(Core.input.keyTap(Binding.pause) && !ui.restart.isShown() && (state.is(State.paused) || state.is(State.playing))){ if(Core.input.keyTap(Binding.pause) && !ui.restart.isShown() && (state.is(State.paused) || state.is(State.playing))){
state.set(state.is(State.playing) ? State.paused : State.playing); state.set(state.is(State.playing) ? State.paused : State.playing);
} }

View File

@@ -50,7 +50,7 @@ public class Logic implements ApplicationListener{
/**Handles the event of content being used by either the player or some block.*/ /**Handles the event of content being used by either the player or some block.*/
public void handleContent(UnlockableContent content){ public void handleContent(UnlockableContent content){
if(!headless){ if(!headless){
control.unlocks.unlockContent(content); data.unlockContent(content);
} }
} }

View File

@@ -66,6 +66,7 @@ public class UI implements ApplicationListener{
public LocalPlayerDialog localplayers; public LocalPlayerDialog localplayers;
public UnlocksDialog unlocks; public UnlocksDialog unlocks;
public ContentInfoDialog content; public ContentInfoDialog content;
public DeployDialog deploy;
public Cursor drillCursor, unloadCursor; public Cursor drillCursor, unloadCursor;
@@ -175,6 +176,7 @@ public class UI implements ApplicationListener{
maps = new MapsDialog(); maps = new MapsDialog();
localplayers = new LocalPlayerDialog(); localplayers = new LocalPlayerDialog();
content = new ContentInfoDialog(); content = new ContentInfoDialog();
deploy = new DeployDialog();
Group group = Core.scene.root; Group group = Core.scene.root;

View File

@@ -520,7 +520,7 @@ public class MapEditorDialog extends Dialog implements Disposable{
for(Block block : Vars.content.blocks()){ for(Block block : Vars.content.blocks()){
TextureRegion[] regions = block.getCompactIcon(); TextureRegion[] regions = block.getCompactIcon();
if((block.synthetic() && (Recipe.getByResult(block) == null || !control.unlocks.isUnlocked(Recipe.getByResult(block)))) if((block.synthetic() && (Recipe.getByResult(block) == null || !data.isUnlocked(Recipe.getByResult(block))))
&& block != Blocks.core){ && block != Blocks.core){
continue; continue;
} }

View File

@@ -525,7 +525,7 @@ public class Player extends Unit implements BuilderTrait, CarryTrait, ShooterTra
return; return;
}else{ }else{
//unlock mech when used //unlock mech when used
control.unlocks.unlockContent(mech); data.unlockContent(mech);
} }
if(mobile){ if(mobile){

View File

@@ -15,9 +15,7 @@ import java.io.DataOutput;
import java.io.IOException; import java.io.IOException;
import static io.anuke.mindustry.Vars.content; import static io.anuke.mindustry.Vars.content;
/** /** Class for controlling status effects on an entity.*/
* Class for controlling status effects on an entity.
*/
public class StatusController implements Saveable{ public class StatusController implements Saveable{
private static final StatusEntry globalResult = new StatusEntry(); private static final StatusEntry globalResult = new StatusEntry();
private static final Array<StatusEntry> removals = new Array<>(); private static final Array<StatusEntry> removals = new Array<>();

View File

@@ -31,7 +31,6 @@ import io.anuke.mindustry.type.ContentType;
import io.anuke.mindustry.type.ItemStack; import io.anuke.mindustry.type.ItemStack;
import io.anuke.mindustry.type.Weapon; import io.anuke.mindustry.type.Weapon;
import io.anuke.mindustry.world.Tile; import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.blocks.units.CommandCenter.CommandCenterEntity;
import io.anuke.mindustry.world.meta.BlockFlag; import io.anuke.mindustry.world.meta.BlockFlag;
import java.io.DataInput; import java.io.DataInput;
@@ -100,17 +99,6 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
this.team = team; this.team = team;
} }
public boolean isCommanded(){
return !isWave && world.indexer.getAllied(team, BlockFlag.comandCenter).size != 0 && world.indexer.getAllied(team, BlockFlag.comandCenter).first().entity instanceof CommandCenterEntity;
}
public UnitCommand getCommand(){
if(isCommanded()){
return world.indexer.getAllied(team, BlockFlag.comandCenter).first().<CommandCenterEntity>entity().command;
}
return null;
}
public UnitType getType(){ public UnitType getType(){
return type; return type;
} }
@@ -350,10 +338,6 @@ public abstract class BaseUnit extends Unit implements ShooterTrait{
state.set(getStartState()); state.set(getStartState());
health(maxHealth()); health(maxHealth());
if(isCommanded()){
onCommand(getCommand());
}
} }
@Override @Override

View File

@@ -29,7 +29,7 @@ public class UnitDrops{
for(int i = 0; i < 3; i++){ for(int i = 0; i < 3; i++){
for(Item item : dropTable){ for(Item item : dropTable){
//only drop unlocked items //only drop unlocked items
if(!Vars.headless && !Vars.control.unlocks.isUnlocked(item)){ if(!Vars.headless && !Vars.data.isUnlocked(item)){
continue; continue;
} }

View File

@@ -1,33 +1,32 @@
package io.anuke.mindustry.game; package io.anuke.mindustry.game;
import io.anuke.arc.Core; import io.anuke.arc.Core;
import io.anuke.arc.Events;
import io.anuke.arc.collection.ObjectIntMap;
import io.anuke.arc.collection.ObjectMap; import io.anuke.arc.collection.ObjectMap;
import io.anuke.arc.collection.ObjectSet; import io.anuke.arc.collection.ObjectSet;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.game.EventType.UnlockEvent; import io.anuke.mindustry.game.EventType.UnlockEvent;
import io.anuke.mindustry.type.ContentType; import io.anuke.mindustry.type.ContentType;
import io.anuke.arc.Events; import io.anuke.mindustry.type.Item;
import io.anuke.arc.Settings;
/**Stores player unlocks. Clientside only.*/ /**Stores player unlocks. Clientside only.*/
public class Unlocks{ public class GlobalData{
private ObjectMap<ContentType, ObjectSet<String>> unlocked = new ObjectMap<>(); private ObjectMap<ContentType, ObjectSet<String>> unlocked = new ObjectMap<>();
private boolean dirty; private ObjectIntMap<Item> items = new ObjectIntMap<>();
public Unlocks(){ public GlobalData(){
Core.settings.setSerializer(ContentType.class, (stream, t) -> stream.writeInt(t.ordinal()), stream -> ContentType.values()[stream.readInt()]); Core.settings.setSerializer(ContentType.class, (stream, t) -> stream.writeInt(t.ordinal()), stream -> ContentType.values()[stream.readInt()]);
Core.settings.setSerializer(Item.class, (stream, t) -> stream.writeUTF(t.name), stream -> Vars.content.getByName(ContentType.item, stream.readUTF()));
}
public ObjectIntMap<Item> items(){
return items;
} }
/** Returns whether or not this piece of content is unlocked yet.*/ /** Returns whether or not this piece of content is unlocked yet.*/
public boolean isUnlocked(UnlockableContent content){ public boolean isUnlocked(UnlockableContent content){
if(content.alwaysUnlocked()) return true; return content.alwaysUnlocked() || unlocked.getOr(content.getContentType(), ObjectSet::new).contains(content.getContentName());
if(!unlocked.containsKey(content.getContentType())){
unlocked.put(content.getContentType(), new ObjectSet<>());
}
ObjectSet<String> set = unlocked.get(content.getContentType());
return set.contains(content.getContentName());
} }
/** /**
@@ -40,27 +39,18 @@ public class Unlocks{
public boolean unlockContent(UnlockableContent content){ public boolean unlockContent(UnlockableContent content){
if(!content.canBeUnlocked() || content.alwaysUnlocked()) return false; if(!content.canBeUnlocked() || content.alwaysUnlocked()) return false;
if(!unlocked.containsKey(content.getContentType())){ boolean ret = unlocked.getOr(content.getContentType(), ObjectSet::new).add(content.getContentName());
unlocked.put(content.getContentType(), new ObjectSet<>());
}
boolean ret = unlocked.get(content.getContentType()).add(content.getContentName());
//fire unlock event so other classes can use it //fire unlock event so other classes can use it
if(ret){ if(ret){
content.onUnlock(); content.onUnlock();
Events.fire(new UnlockEvent(content)); Events.fire(new UnlockEvent(content));
dirty = true; save();
} }
return ret; return ret;
} }
/** Returns whether unlockables have changed since the last save.*/
public boolean isDirty(){
return dirty;
}
/** Clears all unlocked content. Automatically saves.*/ /** Clears all unlocked content. Automatically saves.*/
public void reset(){ public void reset(){
save(); save();
@@ -68,11 +58,13 @@ public class Unlocks{
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void load(){ public void load(){
unlocked = Core.settings.getObject("unlockset", ObjectMap.class, ObjectMap::new); unlocked = Core.settings.getObject("unlocks", ObjectMap.class, ObjectMap::new);
items = Core.settings.getObject("items", ObjectIntMap.class, ObjectIntMap::new);
} }
public void save(){ public void save(){
Core.settings.putObject("unlockset", unlocked); Core.settings.putObject("unlocks", unlocked);
Core.settings.putObject("items", items);
Core.settings.save(); Core.settings.save();
} }

View File

@@ -3,7 +3,7 @@ package io.anuke.mindustry.game;
import io.anuke.arc.graphics.g2d.TextureRegion; import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.arc.scene.ui.layout.Table; import io.anuke.arc.scene.ui.layout.Table;
import static io.anuke.mindustry.Vars.control; import static io.anuke.mindustry.Vars.data;
/**Base interface for an unlockable content type.*/ /**Base interface for an unlockable content type.*/
public abstract class UnlockableContent extends MappableContent{ public abstract class UnlockableContent extends MappableContent{
@@ -41,7 +41,7 @@ public abstract class UnlockableContent extends MappableContent{
return true; return true;
}else{ }else{
for(UnlockableContent cont : depend){ for(UnlockableContent cont : depend){
if(!control.unlocks.isUnlocked(cont)){ if(!data.isUnlocked(cont)){
return false; return false;
} }
} }

View File

@@ -143,7 +143,7 @@ public class Recipe extends UnlockableContent{
ContentStatValue stat = (ContentStatValue) value; ContentStatValue stat = (ContentStatValue) value;
UnlockableContent[] content = stat.getValueContent(); UnlockableContent[] content = stat.getValueContent();
for(UnlockableContent c : content){ for(UnlockableContent c : content){
control.unlocks.unlockContent(c); data.unlockContent(c);
} }
} }
} }

View File

@@ -0,0 +1,35 @@
package io.anuke.mindustry.ui.dialogs;
import io.anuke.arc.collection.ObjectIntMap;
import io.anuke.arc.scene.ui.layout.Table;
import io.anuke.mindustry.Vars;
import io.anuke.mindustry.type.Item;
public class DeployDialog extends FloatingDialog{
public DeployDialog(){
super("$text.play");
shown(this::setup);
}
void setup(){
content().clear();
content().stack(new Table(){{
top().left().margin(10);
ObjectIntMap<Item> items = Vars.data.items();
for(Item item : Vars.content.items()){
if(Vars.data.isUnlocked(item)){
add(items.get(item, 0) + "");
addImage(item.region).size(8*3).pad(3);
add(item.localizedName());
row();
}
}
}}, new Table(){{
addButton("$text.play", () -> Vars.world.generator.playRandomMap()).margin(15);
}}).grow();
}
}

View File

@@ -145,7 +145,7 @@ public class SettingsMenuDialog extends SettingsDialog{
dialog.addCloseButton(); dialog.addCloseButton();
dialog.content().addButton("$text.settings.clearunlocks", () -> { dialog.content().addButton("$text.settings.clearunlocks", () -> {
ui.showConfirm("$text.confirm", "$text.settings.clear.confirm", () -> { ui.showConfirm("$text.confirm", "$text.settings.clear.confirm", () -> {
control.unlocks.reset(); data.reset();
dialog.hide(); dialog.hide();
}); });
}); });

View File

@@ -13,8 +13,7 @@ import io.anuke.arc.scene.ui.Tooltip;
import io.anuke.arc.scene.ui.layout.Table; import io.anuke.arc.scene.ui.layout.Table;
import io.anuke.arc.scene.utils.UIUtils; import io.anuke.arc.scene.utils.UIUtils;
import static io.anuke.mindustry.Vars.content; import static io.anuke.mindustry.Vars.*;
import static io.anuke.mindustry.Vars.control;
public class UnlocksDialog extends FloatingDialog{ public class UnlocksDialog extends FloatingDialog{
@@ -59,11 +58,11 @@ public class UnlocksDialog extends FloatingDialog{
if(unlock.isHidden()) continue; if(unlock.isHidden()) continue;
Image image = control.unlocks.isUnlocked(unlock) ? new Image(unlock.getContentIcon()) : new Image("icon-locked"); Image image = data.isUnlocked(unlock) ? new Image(unlock.getContentIcon()) : new Image("icon-locked");
image.addListener(new HandCursorListener()); image.addListener(new HandCursorListener());
list.add(image).size(size).pad(3); list.add(image).size(size).pad(3);
if(control.unlocks.isUnlocked(unlock)){ if(data.isUnlocked(unlock)){
image.clicked(() -> Vars.ui.content.show(unlock)); image.clicked(() -> Vars.ui.content.show(unlock));
image.addListener(new Tooltip<>(new Table("button"){{ image.addListener(new Tooltip<>(new Table("button"){{
add(unlock.localizedName()); add(unlock.localizedName());

View File

@@ -1,17 +1,16 @@
package io.anuke.mindustry.ui.fragments; package io.anuke.mindustry.ui.fragments;
import io.anuke.arc.Core; import io.anuke.arc.Core;
import io.anuke.arc.Events;
import io.anuke.arc.scene.Group;
import io.anuke.arc.scene.ui.layout.Table;
import io.anuke.arc.util.Strings;
import io.anuke.mindustry.core.GameState.State; import io.anuke.mindustry.core.GameState.State;
import io.anuke.mindustry.core.Platform; import io.anuke.mindustry.core.Platform;
import io.anuke.mindustry.game.EventType.ResizeEvent; import io.anuke.mindustry.game.EventType.ResizeEvent;
import io.anuke.mindustry.game.Version; import io.anuke.mindustry.game.Version;
import io.anuke.mindustry.ui.MenuButton; import io.anuke.mindustry.ui.MenuButton;
import io.anuke.mindustry.ui.MobileButton; import io.anuke.mindustry.ui.MobileButton;
import io.anuke.mindustry.ui.dialogs.FloatingDialog;
import io.anuke.arc.Events;
import io.anuke.arc.scene.Group;
import io.anuke.arc.scene.ui.layout.Table;
import io.anuke.arc.util.Strings;
import static io.anuke.mindustry.Vars.*; import static io.anuke.mindustry.Vars.*;
@@ -139,6 +138,9 @@ public class MenuFragment extends Fragment{
} }
private void showPlaySelect(){ private void showPlaySelect(){
ui.deploy.show();
/*
float w = 220f; float w = 220f;
float bw = w * 2f + 10f; float bw = w * 2f + 10f;
@@ -169,6 +171,6 @@ public class MenuFragment extends Fragment{
dialog.hide(); dialog.hide();
})).width(bw).colspan(2); })).width(bw).colspan(2);
dialog.show(); dialog.show();*/
} }
} }

View File

@@ -80,7 +80,7 @@ public class PlacementFragment extends Fragment{
if(tile != null){ if(tile != null){
tile = tile.target(); tile = tile.target();
Recipe tryRecipe = Recipe.getByResult(tile.block()); Recipe tryRecipe = Recipe.getByResult(tile.block());
if(tryRecipe != null && control.unlocks.isUnlocked(tryRecipe)){ if(tryRecipe != null && data.isUnlocked(tryRecipe)){
input.recipe = tryRecipe; input.recipe = tryRecipe;
currentCategory = input.recipe.category; currentCategory = input.recipe.category;
return true; return true;
@@ -91,7 +91,7 @@ public class PlacementFragment extends Fragment{
Array<Recipe> recipes = Recipe.getByCategory(currentCategory); Array<Recipe> recipes = Recipe.getByCategory(currentCategory);
for(KeyCode key : inputGrid){ for(KeyCode key : inputGrid){
if(Core.input.keyDown(key)) if(Core.input.keyDown(key))
input.recipe = (i < recipes.size && control.unlocks.isUnlocked(recipes.get(i))) ? recipes.get(i) : null; input.recipe = (i < recipes.size && data.isUnlocked(recipes.get(i))) ? recipes.get(i) : null;
i++; i++;
} }
} }
@@ -126,13 +126,13 @@ public class PlacementFragment extends Fragment{
boolean[] unlocked = {false}; boolean[] unlocked = {false};
ImageButton button = blockTable.addImageButton("icon-locked", "select", 8 * 4, () -> { ImageButton button = blockTable.addImageButton("icon-locked", "select", 8 * 4, () -> {
if(control.unlocks.isUnlocked(recipe)){ if(data.isUnlocked(recipe)){
input.recipe = input.recipe == recipe ? null : recipe; input.recipe = input.recipe == recipe ? null : recipe;
} }
}).size(46f).group(group).get(); }).size(46f).group(group).get();
button.update(() -> { //color unplacable things gray button.update(() -> { //color unplacable things gray
boolean ulock = control.unlocks.isUnlocked(recipe); boolean ulock = data.isUnlocked(recipe);
TileEntity core = players[0].getClosestCore(); TileEntity core = players[0].getClosestCore();
Color color = core != null && (core.items.has(recipe.requirements) || state.mode.infiniteResources) ? Color.WHITE : ulock ? Color.GRAY : Color.WHITE; Color color = core != null && (core.items.has(recipe.requirements) || state.mode.infiniteResources) ? Color.WHITE : ulock ? Color.GRAY : Color.WHITE;
button.forEach(elem -> elem.setColor(color)); button.forEach(elem -> elem.setColor(color));
@@ -176,10 +176,10 @@ public class PlacementFragment extends Fragment{
header.left(); header.left();
header.add(new ImageStack(lastDisplay.getCompactIcon())).size(8 * 4); header.add(new ImageStack(lastDisplay.getCompactIcon())).size(8 * 4);
header.labelWrap(() -> header.labelWrap(() ->
!control.unlocks.isUnlocked(Recipe.getByResult(lastDisplay)) ? Core.bundle.get("text.blocks.unknown") : lastDisplay.formalName) !data.isUnlocked(Recipe.getByResult(lastDisplay)) ? Core.bundle.get("text.blocks.unknown") : lastDisplay.formalName)
.left().width(190f).padLeft(5); .left().width(190f).padLeft(5);
header.add().growX(); header.add().growX();
if(control.unlocks.isUnlocked(Recipe.getByResult(lastDisplay))){ if(data.isUnlocked(Recipe.getByResult(lastDisplay))){
header.addButton("?", "clear-partial", () -> ui.content.show(Recipe.getByResult(lastDisplay))) header.addButton("?", "clear-partial", () -> ui.content.show(Recipe.getByResult(lastDisplay)))
.size(8 * 5).padTop(-5).padRight(-5).right().grow(); .size(8 * 5).padTop(-5).padRight(-5).right().grow();
} }

View File

@@ -9,8 +9,7 @@ import io.anuke.arc.scene.ui.ButtonGroup;
import io.anuke.arc.scene.ui.ImageButton; import io.anuke.arc.scene.ui.ImageButton;
import io.anuke.arc.scene.ui.layout.Table; import io.anuke.arc.scene.ui.layout.Table;
import static io.anuke.mindustry.Vars.content; import static io.anuke.mindustry.Vars.*;
import static io.anuke.mindustry.Vars.control;
public interface SelectionTrait{ public interface SelectionTrait{
@@ -26,7 +25,7 @@ public interface SelectionTrait{
int i = 0; int i = 0;
for(Item item : items){ for(Item item : items){
if(!control.unlocks.isUnlocked(item)) continue; if(!data.isUnlocked(item)) continue;
ImageButton button = cont.addImageButton("white", "clear-toggle", 24, () -> {}).group(group).get(); ImageButton button = cont.addImageButton("white", "clear-toggle", 24, () -> {}).group(group).get();
button.changed(() -> consumer.accept(button.isChecked() ? item : null)); button.changed(() -> consumer.accept(button.isChecked() ? item : null));

View File

@@ -19,8 +19,7 @@ import java.io.DataInput;
import java.io.DataOutput; import java.io.DataOutput;
import java.io.IOException; import java.io.IOException;
import static io.anuke.mindustry.Vars.content; import static io.anuke.mindustry.Vars.*;
import static io.anuke.mindustry.Vars.control;
public class LiquidSource extends Block{ public class LiquidSource extends Block{
@@ -63,7 +62,7 @@ public class LiquidSource extends Block{
Table cont = new Table(); Table cont = new Table();
for(int i = 0; i < items.size; i++){ for(int i = 0; i < items.size; i++){
if(!control.unlocks.isUnlocked(items.get(i))) continue; if(!data.isUnlocked(items.get(i))) continue;
final int f = i; final int f = i;
ImageButton button = cont.addImageButton("liquid-icon-" + items.get(i).name, "clear-toggle", 24, ImageButton button = cont.addImageButton("liquid-icon-" + items.get(i).name, "clear-toggle", 24,

View File

@@ -1,132 +0,0 @@
package io.anuke.mindustry.world.blocks.units;
import io.anuke.annotations.Annotations.Loc;
import io.anuke.annotations.Annotations.Remote;
import io.anuke.arc.Core;
import io.anuke.arc.collection.EnumSet;
import io.anuke.arc.collection.ObjectSet;
import io.anuke.arc.entities.Effects;
import io.anuke.arc.entities.Effects.Effect;
import io.anuke.arc.graphics.Color;
import io.anuke.arc.graphics.g2d.Draw;
import io.anuke.arc.graphics.g2d.TextureRegion;
import io.anuke.arc.scene.ui.ButtonGroup;
import io.anuke.arc.scene.ui.ImageButton;
import io.anuke.arc.scene.ui.layout.Table;
import io.anuke.mindustry.content.Fx;
import io.anuke.mindustry.entities.Player;
import io.anuke.mindustry.entities.TileEntity;
import io.anuke.mindustry.entities.units.BaseUnit;
import io.anuke.mindustry.entities.units.UnitCommand;
import io.anuke.mindustry.game.Team;
import io.anuke.mindustry.gen.Call;
import io.anuke.mindustry.graphics.Palette;
import io.anuke.mindustry.world.Block;
import io.anuke.mindustry.world.Tile;
import io.anuke.mindustry.world.meta.BlockFlag;
import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import static io.anuke.mindustry.Vars.*;
public class CommandCenter extends Block{
protected TextureRegion[] commandRegions = new TextureRegion[UnitCommand.values().length];
protected Color topColor = Palette.command;
protected Color bottomColor = Color.valueOf("5e5e5e");
protected Effect effect = Fx.commandSend;
public CommandCenter(String name){
super(name);
flags = EnumSet.of(BlockFlag.comandCenter);
destructible = true;
solid = true;
configurable = true;
}
@Override
public void playerPlaced(Tile tile){
ObjectSet<Tile> set = world.indexer.getAllied(tile.getTeam(), BlockFlag.comandCenter);
if(set.size > 0){
CommandCenterEntity entity = tile.entity();
CommandCenterEntity oe = set.first().entity();
entity.command = oe.command;
}
}
@Override
public void load(){
super.load();
for(UnitCommand cmd : UnitCommand.values()){
commandRegions[cmd.ordinal()] = Core.atlas.find("command-" + cmd.name());
}
}
@Override
public void draw(Tile tile){
CommandCenterEntity entity = tile.entity();
super.draw(tile);
Draw.color(bottomColor);
Draw.rect(commandRegions[entity.command.ordinal()], tile.drawx(), tile.drawy() - 1);
Draw.color(topColor);
Draw.rect(commandRegions[entity.command.ordinal()], tile.drawx(), tile.drawy());
Draw.color();
}
@Override
public void buildTable(Tile tile, Table table){
CommandCenterEntity entity = tile.entity();
ButtonGroup<ImageButton> group = new ButtonGroup<>();
Table buttons = new Table();
for(UnitCommand cmd : UnitCommand.values()){
buttons.addImageButton("command-" + cmd.name(), "clear-toggle", 8*3, () -> Call.onCommandCenterSet(players[0], tile, cmd))
.size(38f).group(group).update(b -> b.setChecked(entity.command == cmd));
}
table.add(buttons);
table.row();
table.table("pane", t -> t.label(() -> entity.command.localized()).center().growX()).growX();
}
@Remote(called = Loc.server, forward = true, targets = Loc.both)
public static void onCommandCenterSet(Player player, Tile tile, UnitCommand command){
Effects.effect(((CommandCenter)tile.block()).effect, tile);
for(Tile center : world.indexer.getAllied(tile.getTeam(), BlockFlag.comandCenter)){
if(center.block() instanceof CommandCenter){
CommandCenterEntity entity = center.entity();
entity.command = command;
}
}
Team team = (player == null ? tile.getTeam() : player.getTeam());
for(BaseUnit unit : unitGroups[team.ordinal()].all()){
unit.onCommand(command);
}
}
@Override
public TileEntity newEntity(){
return new CommandCenterEntity();
}
public class CommandCenterEntity extends TileEntity{
public UnitCommand command = UnitCommand.attack;
@Override
public void writeConfig(DataOutput stream) throws IOException{
stream.writeByte(command.ordinal());
}
@Override
public void readConfig(DataInput stream) throws IOException{
command = UnitCommand.values()[stream.readByte()];
}
}
}

View File

@@ -1,5 +1,6 @@
package io.anuke.mindustry.world.meta; package io.anuke.mindustry.world.meta;
//TODO fix flagging system, currently doesn't really work
public enum BlockFlag{ public enum BlockFlag{
/**General important target for all types of units.*/ /**General important target for all types of units.*/
target(0), target(0),
@@ -14,9 +15,7 @@ public enum BlockFlag{
/**Producer or storage unit of volatile materials.*/ /**Producer or storage unit of volatile materials.*/
explosive(Float.MAX_VALUE), explosive(Float.MAX_VALUE),
/**Repair point.*/ /**Repair point.*/
repair(Float.MAX_VALUE), repair(Float.MAX_VALUE);
/**Special flag for command center blocks.*/
comandCenter(Float.MAX_VALUE);
public final static BlockFlag[] all = values(); public final static BlockFlag[] all = values();

View File

@@ -98,7 +98,7 @@ task scaleSprites4x(){
task scaleSprites(){ task scaleSprites(){
finalizedBy 'genSprites' finalizedBy 'genSprites'
dependsOn 'scaleSprites4x' //dependsOn 'scaleSprites4x'
} }
task pack(){ task pack(){