Laid groundwork for tutorial, changed map storage
This commit is contained in:
@@ -7,6 +7,7 @@ import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input.Keys;
|
||||
import com.badlogic.gdx.input.GestureDetector;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||
import com.badlogic.gdx.utils.reflect.Constructor;
|
||||
|
||||
@@ -19,7 +20,10 @@ import io.anuke.mindustry.input.AndroidInput;
|
||||
import io.anuke.mindustry.input.GestureHandler;
|
||||
import io.anuke.mindustry.input.Input;
|
||||
import io.anuke.mindustry.io.SaveIO;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.resource.ItemStack;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
import io.anuke.mindustry.world.Map;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.World;
|
||||
import io.anuke.ucore.UCore;
|
||||
@@ -34,9 +38,11 @@ public class Control extends Module{
|
||||
int targetscale = baseCameraScale;
|
||||
|
||||
boolean showedTutorial;
|
||||
Tutorial tutorial = new Tutorial();
|
||||
boolean hiscore = false;
|
||||
|
||||
final Array<Weapon> weapons = new Array<>();
|
||||
final ObjectMap<Item, Integer> items = new ObjectMap<>();
|
||||
|
||||
Array<EnemySpawn> spawns = new Array<>();
|
||||
int wave = 1;
|
||||
@@ -84,8 +90,8 @@ public class Control extends Module{
|
||||
|
||||
Settings.loadAll("io.anuke.moment");
|
||||
|
||||
for(String map : maps){
|
||||
Settings.defaults("hiscore"+map, 0);
|
||||
for(Map map : Map.values()){
|
||||
Settings.defaults("hiscore" + map.name(), 0);
|
||||
}
|
||||
|
||||
player = new Player();
|
||||
@@ -127,13 +133,6 @@ public class Control extends Module{
|
||||
}}
|
||||
|
||||
);
|
||||
|
||||
/*
|
||||
//TODO remove this debugging
|
||||
for(int i = 1; i < 60; i ++){
|
||||
UCore.log("\n\n--WAVE " + i);
|
||||
printEnemies(i);
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
@@ -154,7 +153,7 @@ public class Control extends Module{
|
||||
player.add();
|
||||
|
||||
player.heal();
|
||||
Inventory.clearItems();
|
||||
clearItems();
|
||||
World.spawnpoints.clear();
|
||||
respawntime = -1;
|
||||
hiscore = false;
|
||||
@@ -183,6 +182,20 @@ public class Control extends Module{
|
||||
}
|
||||
}
|
||||
|
||||
public void playMap(Map map){
|
||||
Vars.ui.showLoading();
|
||||
|
||||
Timers.run(16, ()->{
|
||||
Vars.control.reset();
|
||||
World.loadMap(map);
|
||||
Vars.control.play();
|
||||
});
|
||||
|
||||
Timers.run(18, ()->{
|
||||
Vars.ui.hideLoading();
|
||||
});
|
||||
}
|
||||
|
||||
public boolean hasWeapon(Weapon weapon){
|
||||
return weapons.contains(weapon, true);
|
||||
}
|
||||
@@ -236,10 +249,10 @@ public class Control extends Module{
|
||||
|
||||
wave ++;
|
||||
|
||||
int last = Settings.getInt("hiscore"+maps[World.getMap()]);
|
||||
int last = Settings.getInt("hiscore" + World.getMap().name());
|
||||
|
||||
if(wave > last){
|
||||
Settings.putInt("hiscore"+maps[World.getMap()], wave);
|
||||
Settings.putInt("hiscore" + World.getMap().name(), wave);
|
||||
Settings.save();
|
||||
hiscore = true;
|
||||
}
|
||||
@@ -312,6 +325,52 @@ public class Control extends Module{
|
||||
return wave;
|
||||
}
|
||||
|
||||
public void clearItems(){
|
||||
items.clear();
|
||||
|
||||
items.put(Item.stone, 40);
|
||||
|
||||
if(debug){
|
||||
for(Item item : Item.values())
|
||||
items.put(item, 2000000);
|
||||
}
|
||||
}
|
||||
|
||||
public int getAmount(Item item){
|
||||
return items.get(item, 0);
|
||||
}
|
||||
|
||||
public void addItem(Item item, int amount){
|
||||
items.put(item, items.get(item, 0)+amount);
|
||||
ui.updateItems();
|
||||
}
|
||||
|
||||
public boolean hasItems(ItemStack[] items){
|
||||
for(ItemStack stack : items)
|
||||
if(!hasItem(stack))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean hasItem(ItemStack req){
|
||||
return items.get(req.item, 0) >= req.amount;
|
||||
}
|
||||
|
||||
public void removeItem(ItemStack req){
|
||||
items.put(req.item, items.get(req.item, 0)-req.amount);
|
||||
ui.updateItems();
|
||||
}
|
||||
|
||||
public void removeItems(ItemStack... reqs){
|
||||
for(ItemStack req : reqs)
|
||||
items.put(req.item, items.get(req.item, 0)-req.amount);
|
||||
ui.updateItems();
|
||||
}
|
||||
|
||||
public ObjectMap<Item, Integer> getItems(){
|
||||
return items;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(){
|
||||
Musics.shuffleAll();
|
||||
@@ -322,7 +381,7 @@ public class Control extends Module{
|
||||
return World.solid(x, y);
|
||||
});
|
||||
|
||||
EffectLoader.create();
|
||||
EffectCreator.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -386,10 +445,14 @@ public class Control extends Module{
|
||||
}
|
||||
}
|
||||
|
||||
extrawavetime -= delta();
|
||||
if(!tutorial.active()){
|
||||
extrawavetime -= delta();
|
||||
|
||||
if(enemies <= 0){
|
||||
wavetime -= delta();
|
||||
if(enemies <= 0){
|
||||
wavetime -= delta();
|
||||
}
|
||||
}else{
|
||||
tutorial.update();
|
||||
}
|
||||
|
||||
if(wavetime <= 0 || (debug && Inputs.keyUp(Keys.F)) || extrawavetime <= 0){
|
||||
|
||||
@@ -9,7 +9,7 @@ import io.anuke.ucore.core.Effects;
|
||||
import io.anuke.ucore.graphics.Hue;
|
||||
import io.anuke.ucore.util.Angles;
|
||||
|
||||
public class EffectLoader{
|
||||
public class EffectCreator{
|
||||
static Color lightRed = Hue.mix(Color.WHITE, Color.FIREBRICK, 0.1f);
|
||||
|
||||
public static void create(){
|
||||
@@ -1,66 +0,0 @@
|
||||
package io.anuke.mindustry;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.resource.ItemStack;
|
||||
|
||||
public class Inventory{
|
||||
final static ObjectMap<Item, Integer> items = new ObjectMap<>();
|
||||
|
||||
public static void clearItems(){
|
||||
items.clear();
|
||||
//TODO make this not hardcoded
|
||||
items.put(Item.stone, 40);
|
||||
|
||||
if(debug){
|
||||
items.put(Item.stone, 2000000);
|
||||
items.put(Item.iron, 2000000);
|
||||
items.put(Item.steel, 2000000);
|
||||
items.put(Item.coal, 2000000);
|
||||
items.put(Item.titanium, 2000000);
|
||||
items.put(Item.dirium, 2000000);
|
||||
}
|
||||
}
|
||||
|
||||
public static Iterable<Item> getItemTypes(){
|
||||
return items.keys();
|
||||
}
|
||||
|
||||
public static int getAmount(Item item){
|
||||
return items.get(item, 0);
|
||||
}
|
||||
|
||||
public static void addItem(Item item, int amount){
|
||||
items.put(item, items.get(item, 0)+amount);
|
||||
ui.updateItems();
|
||||
}
|
||||
|
||||
public static boolean hasItems(ItemStack[] items){
|
||||
for(ItemStack stack : items)
|
||||
if(!hasItem(stack))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean hasItem(ItemStack req){
|
||||
return items.get(req.item, 0) >= req.amount;
|
||||
}
|
||||
|
||||
public static void removeItem(ItemStack req){
|
||||
items.put(req.item, items.get(req.item, 0)-req.amount);
|
||||
ui.updateItems();
|
||||
}
|
||||
|
||||
public static void removeItems(ItemStack... reqs){
|
||||
for(ItemStack req : reqs)
|
||||
items.put(req.item, items.get(req.item, 0)-req.amount);
|
||||
ui.updateItems();
|
||||
}
|
||||
|
||||
public static ObjectMap<Item, Integer> getItems(){
|
||||
return items;
|
||||
}
|
||||
}
|
||||
@@ -226,7 +226,7 @@ public class Renderer extends RendererModule{
|
||||
|
||||
void renderPixelOverlay(){
|
||||
|
||||
if(player.recipe != null && Inventory.hasItems(player.recipe.requirements) && (!ui.hasMouse() || android) && AndroidInput.mode == PlaceMode.cursor){
|
||||
if(player.recipe != null && Vars.control.hasItems(player.recipe.requirements) && (!ui.hasMouse() || android) && AndroidInput.mode == PlaceMode.cursor){
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ import io.anuke.mindustry.input.AndroidInput;
|
||||
import io.anuke.mindustry.input.PlaceMode;
|
||||
import io.anuke.mindustry.resource.*;
|
||||
import io.anuke.mindustry.ui.*;
|
||||
import io.anuke.mindustry.world.Map;
|
||||
import io.anuke.ucore.core.*;
|
||||
import io.anuke.ucore.function.VisibilityProvider;
|
||||
import io.anuke.ucore.modules.SceneModule;
|
||||
@@ -258,7 +259,7 @@ public class UI extends SceneModule{
|
||||
|
||||
image.update(()->{
|
||||
|
||||
boolean has = Inventory.hasItems(r.requirements);
|
||||
boolean has = control.hasItems(r.requirements);
|
||||
//image.setDisabled(!has);
|
||||
image.setChecked(player.recipe == r);
|
||||
//image.setTouchable(has ? Touchable.enabled : Touchable.disabled);
|
||||
@@ -292,14 +293,7 @@ public class UI extends SceneModule{
|
||||
|
||||
end();
|
||||
}}.right().bottom().uniformX();
|
||||
/*
|
||||
row();
|
||||
|
||||
if(!android){
|
||||
new button("Upgrades", ()->{
|
||||
upgrades.show();
|
||||
}).uniformX().fillX();
|
||||
}*/
|
||||
visible(play);
|
||||
|
||||
}}.end();
|
||||
@@ -367,7 +361,8 @@ public class UI extends SceneModule{
|
||||
row();
|
||||
|
||||
new label(()-> control.getEnemiesRemaining() > 0 ?
|
||||
control.getEnemiesRemaining() + " Enemies remaining" : "New wave in " + (int) (control.getWaveCountdown() / 60f))
|
||||
control.getEnemiesRemaining() + " Enemies remaining" :
|
||||
control.tutorial.active() ? "waiting..." : "New wave in " + (int) (control.getWaveCountdown() / 60f))
|
||||
.minWidth(150);
|
||||
|
||||
get().pad(Unit.dp.inPixels(12));
|
||||
@@ -375,6 +370,12 @@ public class UI extends SceneModule{
|
||||
|
||||
get().setVisible(play);
|
||||
}}.end();
|
||||
|
||||
new table(){{
|
||||
control.tutorial.buildUI(this);
|
||||
|
||||
visible(()->control.tutorial.active());
|
||||
}}.end();
|
||||
|
||||
//menu table
|
||||
new table(){{
|
||||
@@ -386,8 +387,11 @@ public class UI extends SceneModule{
|
||||
levels.show();
|
||||
});
|
||||
|
||||
row();
|
||||
|
||||
new button("Tutorial", ()->{
|
||||
//TODO
|
||||
//TODO show loading, etc
|
||||
control.playMap(Map.tutorial);
|
||||
});
|
||||
|
||||
if(Gdx.app.getType() != ApplicationType.WebGL){
|
||||
@@ -533,7 +537,7 @@ public class UI extends SceneModule{
|
||||
scene.add(tools);
|
||||
|
||||
tools.setVisible(()->
|
||||
!GameState.is(State.menu) && android && player.recipe != null && Inventory.hasItems(player.recipe.requirements) &&
|
||||
!GameState.is(State.menu) && android && player.recipe != null && control.hasItems(player.recipe.requirements) &&
|
||||
AndroidInput.mode == PlaceMode.cursor
|
||||
);
|
||||
|
||||
@@ -583,7 +587,7 @@ public class UI extends SceneModule{
|
||||
Label reqlabel = new Label("");
|
||||
|
||||
reqlabel.update(()->{
|
||||
int current = Inventory.getAmount(fs.item);
|
||||
int current = control.getAmount(fs.item);
|
||||
String text = Mathf.clamp(current, 0, stack.amount) + "/" + stack.amount;
|
||||
|
||||
reqlabel.setColor(current < stack.amount ? Colors.get("missingitems") : Color.WHITE);
|
||||
@@ -712,9 +716,9 @@ public class UI extends SceneModule{
|
||||
itemtable.clear();
|
||||
itemtable.left();
|
||||
|
||||
for(Item stack : Inventory.getItemTypes()){
|
||||
for(Item stack : control.getItems().keys()){
|
||||
Image image = new Image(Draw.region("icon-" + stack.name()));
|
||||
Label label = new Label("" + Mindustry.formatter.format(Inventory.getAmount(stack)));
|
||||
Label label = new Label("" + Mindustry.formatter.format(control.getAmount(stack)));
|
||||
label.setFontScale(fontscale*1.5f);
|
||||
itemtable.add(image).size(8*3).units(Unit.dp);
|
||||
itemtable.add(label).left();
|
||||
|
||||
@@ -28,6 +28,7 @@ public class Vars{
|
||||
//if true, player speed will be increased, massive amounts of resources will be given on start, and other debug options will be available
|
||||
public static boolean debug = false;
|
||||
//number of save slots-- increasing may lead to layout issues
|
||||
//TODO named save slots, possibly with a scroll dialog
|
||||
public static final int saveSlots = 4;
|
||||
|
||||
//turret and enemy shoot speed inverse multiplier
|
||||
@@ -41,8 +42,6 @@ public class Vars{
|
||||
|
||||
public static Player player;
|
||||
|
||||
public static final String[] maps = {"delta", "canyon", "pit", "maze"};
|
||||
|
||||
public static String[] aboutText = {
|
||||
"Made by [ROYAL]Anuken[] for the" + "\nGDL Metal Monstrosity jam.",
|
||||
"",
|
||||
|
||||
@@ -7,7 +7,7 @@ import com.badlogic.gdx.Input.Keys;
|
||||
import com.badlogic.gdx.InputAdapter;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
import io.anuke.mindustry.Inventory;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.resource.ItemStack;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.World;
|
||||
@@ -62,7 +62,7 @@ public class AndroidInput extends InputAdapter{
|
||||
if(player.breaktime >= tile.block().breaktime){
|
||||
brokeBlock = true;
|
||||
if(tile.block().drops != null){
|
||||
Inventory.addItem(tile.block().drops.item, tile.block().drops.amount);
|
||||
Vars.control.addItem(tile.block().drops.item, tile.block().drops.amount);
|
||||
}
|
||||
|
||||
Effects.effect("break", tile.worldx(), tile.worldy());
|
||||
@@ -95,7 +95,7 @@ public class AndroidInput extends InputAdapter{
|
||||
Sounds.play("place");
|
||||
|
||||
for(ItemStack stack : player.recipe.requirements){
|
||||
Inventory.removeItem(stack);
|
||||
Vars.control.removeItem(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.input.GestureDetector.GestureAdapter;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
|
||||
import io.anuke.mindustry.Inventory;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
@@ -35,7 +34,7 @@ public class GestureHandler extends GestureAdapter{
|
||||
@Override
|
||||
public boolean tap (float x, float y, int count, int button) {
|
||||
if(AndroidInput.mode == PlaceMode.touch && !ui.hasMouse() && player.recipe != null &&
|
||||
Inventory.hasItems(player.recipe.requirements) && !Vars.ui.hasMouse() && !AndroidInput.brokeBlock){
|
||||
Vars.control.hasItems(player.recipe.requirements) && !Vars.ui.hasMouse() && !AndroidInput.brokeBlock){
|
||||
AndroidInput.mousex = x;
|
||||
AndroidInput.mousey = y;
|
||||
AndroidInput.place();
|
||||
@@ -46,7 +45,7 @@ public class GestureHandler extends GestureAdapter{
|
||||
|
||||
@Override
|
||||
public boolean pan(float x, float y, float deltaX, float deltaY){
|
||||
if(player.recipe == null || !Inventory.hasItems(player.recipe.requirements) || AndroidInput.mode == PlaceMode.touch){
|
||||
if(player.recipe == null || !Vars.control.hasItems(player.recipe.requirements) || AndroidInput.mode == PlaceMode.touch){
|
||||
player.x -= deltaX*Core.camera.zoom/Core.cameraScale;
|
||||
player.y += deltaY*Core.camera.zoom/Core.cameraScale;
|
||||
}else if(AndroidInput.mode == PlaceMode.cursor){
|
||||
|
||||
@@ -5,7 +5,6 @@ import static io.anuke.mindustry.Vars.*;
|
||||
import com.badlogic.gdx.Input.Buttons;
|
||||
import com.badlogic.gdx.Input.Keys;
|
||||
|
||||
import io.anuke.mindustry.Inventory;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.resource.ItemStack;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
@@ -51,7 +50,7 @@ public class Input{
|
||||
|
||||
if(Inputs.buttonUp(Buttons.LEFT) && player.recipe != null &&
|
||||
World.validPlace(World.tilex(), World.tiley(), player.recipe.result) && !ui.hasMouse() &&
|
||||
Inventory.hasItems(player.recipe.requirements)){
|
||||
Vars.control.hasItems(player.recipe.requirements)){
|
||||
Tile tile = World.tile(World.tilex(), World.tiley());
|
||||
|
||||
if(tile == null)
|
||||
@@ -65,10 +64,10 @@ public class Input{
|
||||
Sounds.play("place");
|
||||
|
||||
for(ItemStack stack : player.recipe.requirements){
|
||||
Inventory.removeItem(stack);
|
||||
Vars.control.removeItem(stack);
|
||||
}
|
||||
|
||||
if(!Inventory.hasItems(player.recipe.requirements)){
|
||||
if(!Vars.control.hasItems(player.recipe.requirements)){
|
||||
Cursors.restoreCursor();
|
||||
}
|
||||
}
|
||||
@@ -87,7 +86,7 @@ public class Input{
|
||||
player.breaktime += Timers.delta();
|
||||
if(player.breaktime >= tile.block().breaktime){
|
||||
if(tile.block().drops != null){
|
||||
Inventory.addItem(tile.block().drops.item, tile.block().drops.amount);
|
||||
Vars.control.addItem(tile.block().drops.item, tile.block().drops.amount);
|
||||
}
|
||||
|
||||
Effects.effect("break", tile.worldx(), tile.worldy());
|
||||
|
||||
@@ -14,15 +14,12 @@ import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import com.badlogic.gdx.utils.reflect.ClassReflection;
|
||||
|
||||
import io.anuke.mindustry.Inventory;
|
||||
import io.anuke.mindustry.Mindustry;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.entities.enemies.*;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
import io.anuke.mindustry.world.Block;
|
||||
import io.anuke.mindustry.world.Tile;
|
||||
import io.anuke.mindustry.world.World;
|
||||
import io.anuke.mindustry.world.*;
|
||||
import io.anuke.mindustry.world.blocks.Blocks;
|
||||
import io.anuke.ucore.core.Core;
|
||||
import io.anuke.ucore.entities.Entities;
|
||||
@@ -171,11 +168,11 @@ public class SaveIO{
|
||||
|
||||
//--INVENTORY--
|
||||
|
||||
stream.writeByte(Inventory.getItems().size); //amount of items
|
||||
stream.writeByte(Vars.control.getItems().size); //amount of items
|
||||
|
||||
for(Item item : Inventory.getItems().keys()){
|
||||
for(Item item : Vars.control.getItems().keys()){
|
||||
stream.writeByte(item.ordinal()); //item ID
|
||||
stream.writeInt(Inventory.getAmount(item)); //item amount
|
||||
stream.writeInt(Vars.control.getAmount(item)); //item amount
|
||||
}
|
||||
|
||||
//--ENEMIES--
|
||||
@@ -205,7 +202,7 @@ public class SaveIO{
|
||||
//--MAP DATA--
|
||||
|
||||
//map ID
|
||||
stream.writeByte(World.getMap());
|
||||
stream.writeByte(World.getMap().ordinal());
|
||||
|
||||
//seed
|
||||
stream.writeInt(World.getSeed());
|
||||
@@ -300,12 +297,12 @@ public class SaveIO{
|
||||
|
||||
int totalItems = stream.readByte();
|
||||
|
||||
Inventory.getItems().clear();
|
||||
Vars.control.getItems().clear();
|
||||
|
||||
for(int i = 0; i < totalItems; i ++){
|
||||
Item item = itemEnums[stream.readByte()];
|
||||
int amount = stream.readInt();
|
||||
Inventory.getItems().put(item, amount);
|
||||
Vars.control.getItems().put(item, amount);
|
||||
}
|
||||
|
||||
Vars.ui.updateItems();
|
||||
@@ -350,7 +347,7 @@ public class SaveIO{
|
||||
int seed = stream.readInt();
|
||||
int tiles = stream.readInt();
|
||||
|
||||
World.loadMap(mapid, seed);
|
||||
World.loadMap(Map.values()[mapid], seed);
|
||||
Vars.renderer.clearTiles();
|
||||
|
||||
for(Enemy enemy : enemiesToUpdate){
|
||||
|
||||
@@ -1,60 +1,48 @@
|
||||
package io.anuke.mindustry.ui;
|
||||
|
||||
import static io.anuke.mindustry.Vars.maps;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.world.Map;
|
||||
import io.anuke.mindustry.world.World;
|
||||
import io.anuke.ucore.core.Settings;
|
||||
import io.anuke.ucore.core.Timers;
|
||||
import io.anuke.ucore.scene.ui.*;
|
||||
import io.anuke.ucore.scene.ui.ButtonGroup;
|
||||
import io.anuke.ucore.scene.ui.Dialog;
|
||||
import io.anuke.ucore.scene.ui.ImageButton;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
|
||||
public class LevelDialog extends Dialog{
|
||||
Label[] scores = new Label[maps.length];
|
||||
private int selectedMap;
|
||||
private Map selectedMap = Map.delta;
|
||||
|
||||
public LevelDialog(){
|
||||
super("Level Select");
|
||||
setup();
|
||||
|
||||
shown(()->{
|
||||
for(int i = 0; i < maps.length; i ++)
|
||||
scores[i].setText("High Score: [lime]" + Settings.getInt("hiscore"+maps[i]));
|
||||
});
|
||||
}
|
||||
|
||||
void setup(){
|
||||
addCloseButton();
|
||||
getButtonTable().addButton("Play", ()->{
|
||||
hide();
|
||||
Vars.ui.showLoading();
|
||||
Timers.run(16, ()->{
|
||||
Vars.control.reset();
|
||||
World.loadMap(selectedMap);
|
||||
Vars.control.play();
|
||||
});
|
||||
|
||||
Timers.run(18, ()->{
|
||||
Vars.ui.hideLoading();
|
||||
});
|
||||
Vars.control.playMap(selectedMap);
|
||||
}).pad(3).size(180, 44).units(Unit.dp);
|
||||
|
||||
ButtonGroup<ImageButton> mapgroup = new ButtonGroup<>();
|
||||
|
||||
for(int i = 0; i < maps.length; i ++){
|
||||
content().add(maps[i]);
|
||||
for(Map map : Map.values()){
|
||||
if(!map.visible) continue;
|
||||
|
||||
content().add(map.name());
|
||||
}
|
||||
|
||||
content().row();
|
||||
|
||||
for(int i = 0; i < maps.length; i ++){
|
||||
int index = i;
|
||||
ImageButton image = new ImageButton(new TextureRegion(World.getTexture(i)), "togglemap");
|
||||
for(Map map : Map.values()){
|
||||
if(!map.visible) continue;
|
||||
|
||||
ImageButton image = new ImageButton(new TextureRegion(World.getTexture(map)), "togglemap");
|
||||
mapgroup.add(image);
|
||||
image.clicked(()->{
|
||||
selectedMap = index;
|
||||
selectedMap = map;
|
||||
});
|
||||
image.getImageCell().size(Unit.dp.inPixels(164));
|
||||
content().add(image).size(Unit.dp.inPixels(180));
|
||||
@@ -62,9 +50,10 @@ public class LevelDialog extends Dialog{
|
||||
|
||||
content().row();
|
||||
|
||||
for(int i = 0; i < maps.length; i ++){
|
||||
scores[i] = new Label("");
|
||||
content().add(scores[i]);
|
||||
for(Map map : Map.values()){
|
||||
if(!map.visible) continue;
|
||||
|
||||
content().add(()->"High Score: [lime]" + Settings.getInt("hiscore" + map.name()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import io.anuke.ucore.scene.ui.Label;
|
||||
import io.anuke.ucore.scene.ui.TextButton;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
|
||||
//TODO unified save/load dialogs
|
||||
public class LoadDialog extends Dialog{
|
||||
|
||||
public LoadDialog() {
|
||||
|
||||
@@ -11,6 +11,7 @@ import io.anuke.ucore.scene.ui.*;
|
||||
import io.anuke.ucore.scene.ui.layout.Cell;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
|
||||
//TODO unified save/load dialogs
|
||||
public class SaveDialog extends Dialog{
|
||||
|
||||
public SaveDialog() {
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.badlogic.gdx.graphics.Color;
|
||||
|
||||
import io.anuke.mindustry.GameState;
|
||||
import io.anuke.mindustry.GameState.State;
|
||||
import io.anuke.mindustry.Inventory;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.resource.ItemStack;
|
||||
import io.anuke.mindustry.resource.Weapon;
|
||||
import io.anuke.ucore.core.Draw;
|
||||
@@ -58,7 +58,7 @@ public class UpgradeDialog extends Dialog{
|
||||
if(control.hasWeapon(weapon)){
|
||||
button.setDisabled(true);
|
||||
button.setColor(Color.GRAY);
|
||||
}else if(!Inventory.hasItems(weapon.requirements)){
|
||||
}else if(!Vars.control.hasItems(weapon.requirements)){
|
||||
button.setDisabled(true);
|
||||
}else{
|
||||
button.setDisabled(false);
|
||||
@@ -92,7 +92,7 @@ public class UpgradeDialog extends Dialog{
|
||||
ItemStack[] req = weapon.requirements;
|
||||
for(ItemStack s : req){
|
||||
|
||||
int amount = Math.min(Inventory.getAmount(s.item), s.amount);
|
||||
int amount = Math.min(Vars.control.getAmount(s.item), s.amount);
|
||||
reqtable.addImage(Draw.region("icon-" + s.item.name())).padRight(3).size(8*2);
|
||||
reqtable.add(
|
||||
(amount >= s.amount ? "" : "[RED]")
|
||||
@@ -123,7 +123,7 @@ public class UpgradeDialog extends Dialog{
|
||||
button.clicked(()->{
|
||||
if(button.isDisabled()) return;
|
||||
|
||||
Inventory.removeItems(weapon.requirements);
|
||||
Vars.control.removeItems(weapon.requirements);
|
||||
control.addWeapon(weapon);
|
||||
ui.updateWeapons();
|
||||
run.listen();
|
||||
|
||||
@@ -29,11 +29,12 @@ public class World{
|
||||
|
||||
private static Pixmap[] mapPixmaps;
|
||||
private static Texture[] mapTextures;
|
||||
private static int currentMap;
|
||||
private static Map currentMap;
|
||||
private static Tile[][] tiles = new Tile[worldsize][worldsize];
|
||||
private static Tile[] temptiles = new Tile[4];
|
||||
|
||||
public static Tile core;
|
||||
//TODO move this to control?
|
||||
public static Array<Tile> spawnpoints = new Array<Tile>();
|
||||
|
||||
public static boolean solid(int x, int y){
|
||||
@@ -51,16 +52,16 @@ public class World{
|
||||
return !wallSolid(x, y-1) || !wallSolid(x, y+1) || !wallSolid(x-1, y) ||!wallSolid(x+1, y);
|
||||
}
|
||||
|
||||
public static int getMap(){
|
||||
public static Map getMap(){
|
||||
return currentMap;
|
||||
}
|
||||
|
||||
public static int width(){
|
||||
return mapPixmaps[currentMap].getWidth();
|
||||
return mapPixmaps[currentMap.ordinal()].getWidth();
|
||||
}
|
||||
|
||||
public static int height(){
|
||||
return mapPixmaps[currentMap].getHeight();
|
||||
return mapPixmaps[currentMap.ordinal()].getHeight();
|
||||
}
|
||||
|
||||
public static Tile tile(int x, int y){
|
||||
@@ -80,11 +81,13 @@ public class World{
|
||||
return temptiles;
|
||||
}
|
||||
|
||||
public static Texture getTexture(int map){
|
||||
return mapTextures[map];
|
||||
public static Texture getTexture(Map map){
|
||||
return mapTextures[map.ordinal()];
|
||||
}
|
||||
|
||||
public static void loadMaps(){
|
||||
Map[] maps = Map.values();
|
||||
|
||||
mapPixmaps = new Pixmap[maps.length];
|
||||
mapTextures = new Texture[maps.length];
|
||||
|
||||
@@ -115,18 +118,18 @@ public class World{
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadMap(int id){
|
||||
loadMap(id, MathUtils.random(0, 99999));
|
||||
public static void loadMap(Map map){
|
||||
loadMap(map, MathUtils.random(0, 99999));
|
||||
}
|
||||
|
||||
public static void loadMap(int id, int seed){
|
||||
public static void loadMap(Map map, int seed){
|
||||
|
||||
spawnpoints.clear();
|
||||
|
||||
int size = mapPixmaps[id].getWidth();
|
||||
int size = mapPixmaps[map.ordinal()].getWidth();
|
||||
worldsize = size;
|
||||
pixsize = worldsize*tilesize;
|
||||
currentMap = id;
|
||||
currentMap = map;
|
||||
|
||||
if(tiles != null){
|
||||
clearTileEntities();
|
||||
@@ -146,7 +149,7 @@ public class World{
|
||||
Entities.resizeTree(0, 0, pixsize, pixsize);
|
||||
|
||||
World.seed = seed;
|
||||
Generator.generate(mapPixmaps[id]);
|
||||
Generator.generate(mapPixmaps[map.ordinal()]);
|
||||
|
||||
Pathfind.reset();
|
||||
|
||||
@@ -183,6 +186,7 @@ public class World{
|
||||
return seed;
|
||||
}
|
||||
|
||||
//TODO move this to control?
|
||||
public static boolean validPlace(int x, int y, Block type){
|
||||
|
||||
if(!cursorNear() && !android)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package io.anuke.mindustry.world.blocks;
|
||||
|
||||
import io.anuke.mindustry.Inventory;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.resource.Item;
|
||||
import io.anuke.mindustry.resource.Liquid;
|
||||
@@ -22,7 +21,7 @@ public class ProductionBlocks{
|
||||
|
||||
@Override
|
||||
public void handleItem(Tile tile, Item item, Tile source){
|
||||
Inventory.addItem(item, 1);
|
||||
Vars.control.addItem(item, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,6 +23,7 @@ import io.anuke.ucore.util.Mathf;
|
||||
|
||||
public class Turret extends Block{
|
||||
public static final int targetInterval = 15;
|
||||
private static boolean drawDebug = false;
|
||||
|
||||
protected float range = 50f;
|
||||
protected float reload = 10f;
|
||||
@@ -51,7 +52,7 @@ public class Turret extends Block{
|
||||
TurretEntity entity = tile.entity();
|
||||
Draw.rect(name(), tile.worldx(), tile.worldy(), entity.rotation - 90);
|
||||
|
||||
if(Vars.debug){
|
||||
if(Vars.debug && drawDebug){
|
||||
drawTargeting(tile);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user