Major restructuring of Vars class- made global state less messy
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
package io.anuke.mindustry.ui;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
import static io.anuke.mindustry.Vars.maps;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||
|
||||
import io.anuke.mindustry.GameState;
|
||||
import io.anuke.mindustry.Vars;
|
||||
import io.anuke.mindustry.World;
|
||||
import io.anuke.ucore.core.Settings;
|
||||
import io.anuke.ucore.scene.ui.*;
|
||||
@@ -29,7 +29,7 @@ public class LevelDialog extends Dialog{
|
||||
getButtonTable().addButton("Play", ()->{
|
||||
hide();
|
||||
World.loadMap(selectedMap);
|
||||
GameState.play();
|
||||
Vars.control.play();
|
||||
});
|
||||
|
||||
ButtonGroup<ImageButton> mapgroup = new ButtonGroup<>();
|
||||
@@ -42,7 +42,7 @@ public class LevelDialog extends Dialog{
|
||||
|
||||
for(int i = 0; i < maps.length; i ++){
|
||||
int index = i;
|
||||
ImageButton image = new ImageButton(new TextureRegion(mapTextures[i]), "togglemap");
|
||||
ImageButton image = new ImageButton(new TextureRegion(World.getTexture(i)), "togglemap");
|
||||
mapgroup.add(image);
|
||||
image.clicked(()->{
|
||||
selectedMap = index;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package io.anuke.mindustry.ui;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
import static io.anuke.mindustry.Vars.ui;
|
||||
|
||||
import io.anuke.mindustry.GameState;
|
||||
import io.anuke.mindustry.GameState.State;
|
||||
import io.anuke.ucore.scene.ui.ConfirmDialog;
|
||||
import io.anuke.ucore.scene.ui.Dialog;
|
||||
import io.anuke.ucore.scene.ui.layout.Unit;
|
||||
@@ -16,7 +18,7 @@ public class MenuDialog extends Dialog{
|
||||
void setup(){
|
||||
content().addButton("Back", ()->{
|
||||
hide();
|
||||
paused = false;
|
||||
GameState.set(State.playing);
|
||||
}).width(200).units(Unit.dp);
|
||||
|
||||
content().row();
|
||||
@@ -33,8 +35,7 @@ public class MenuDialog extends Dialog{
|
||||
content().addButton("Back to menu", ()->{
|
||||
new ConfirmDialog("Confirm", "Are you sure you want to quit?", ()->{
|
||||
hide();
|
||||
paused = false;
|
||||
playing = false;
|
||||
GameState.set(State.menu);
|
||||
}).show();
|
||||
}).width(200).units(Unit.dp);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package io.anuke.mindustry.ui;
|
||||
|
||||
import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
import io.anuke.mindustry.GameState;
|
||||
import io.anuke.mindustry.GameState.State;
|
||||
import io.anuke.ucore.core.Settings;
|
||||
import io.anuke.ucore.scene.ui.TextDialog;
|
||||
|
||||
@@ -16,8 +18,7 @@ public class TutorialDialog extends TextDialog{
|
||||
setDialog();
|
||||
|
||||
hidden(()->{
|
||||
playing = true;
|
||||
paused = false;
|
||||
GameState.set(State.playing);
|
||||
});
|
||||
|
||||
getButtonTable().addButton("OK", ()->{
|
||||
|
||||
@@ -4,6 +4,8 @@ import static io.anuke.mindustry.Vars.*;
|
||||
|
||||
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.entities.Weapon;
|
||||
import io.anuke.mindustry.resource.ItemStack;
|
||||
@@ -25,10 +27,10 @@ public class UpgradeDialog extends Dialog{
|
||||
addCloseButton();
|
||||
|
||||
hidden(()->{
|
||||
paused = false;
|
||||
GameState.set(State.playing);
|
||||
});
|
||||
shown(()->{
|
||||
paused = true;
|
||||
GameState.set(State.paused);
|
||||
});
|
||||
|
||||
getButtonTable().addButton("Ok", ()->{
|
||||
@@ -51,7 +53,7 @@ public class UpgradeDialog extends Dialog{
|
||||
|
||||
button.update(()->{
|
||||
|
||||
if(weapons.get(weapon) == Boolean.TRUE){
|
||||
if(control.hasWeapon(weapon)){
|
||||
button.setDisabled(true);
|
||||
button.setColor(Color.GRAY);
|
||||
button.setTouchable(Touchable.disabled);
|
||||
@@ -80,11 +82,11 @@ public class UpgradeDialog extends Dialog{
|
||||
tiptable.background("button");
|
||||
tiptable.add("[PURPLE]" + weapon.name(), 0.75f).left().padBottom(2f);
|
||||
|
||||
if(weapons.get(weapon) != Boolean.TRUE){
|
||||
if(!control.hasWeapon(weapon)){
|
||||
ItemStack[] req = weapon.requirements;
|
||||
for(ItemStack s : req){
|
||||
tiptable.row();
|
||||
int amount = Math.min(items.get(s.item, 0), s.amount);
|
||||
int amount = Math.min(Inventory.getAmount(s.item), s.amount);
|
||||
tiptable.add(
|
||||
(amount >= s.amount ? "[YELLOW]" : "[RED]")
|
||||
+s.item + ": " + amount + " / " +s.amount, 0.5f).left();
|
||||
@@ -96,7 +98,7 @@ public class UpgradeDialog extends Dialog{
|
||||
tiptable.row();
|
||||
tiptable.add("[ORANGE]" + description).left();
|
||||
tiptable.row();
|
||||
if(weapons.get(weapon) == Boolean.TRUE)
|
||||
if(control.hasWeapon(weapon))
|
||||
tiptable.add("[LIME]Purchased!").left();
|
||||
tiptable.pad(10f);
|
||||
};
|
||||
@@ -113,7 +115,7 @@ public class UpgradeDialog extends Dialog{
|
||||
if(button.isDisabled()) return;
|
||||
|
||||
Inventory.removeItems(weapon.requirements);
|
||||
weapons.put(weapon, true);
|
||||
control.addWeapon(weapon);
|
||||
ui.updateWeapons();
|
||||
run.listen();
|
||||
Effects.sound("purchase");
|
||||
|
||||
Reference in New Issue
Block a user