This commit is contained in:
Anuken
2020-03-08 21:53:19 -04:00
parent 863c7ae2bc
commit 0ff3c1ee78
26 changed files with 59 additions and 54 deletions

View File

@@ -213,7 +213,7 @@ public class Control implements ApplicationListener, Loadable{
input = new DesktopInput();
}
if(!state.is(State.menu)){
if(state.isGame()){
player.add();
}
@@ -445,7 +445,7 @@ public class Control implements ApplicationListener, Loadable{
settings.save();
}
if(!state.is(State.menu)){
if(state.isGame()){
input.update();
if(state.isCampaign()){

View File

@@ -58,6 +58,15 @@ public class GameState{
return (is(State.paused) && !net.active()) || (gameOver && !net.active());
}
/** @return whether the current state is *not* the menu. */
public boolean isGame(){
return state != State.menu;
}
public boolean isMenu(){
return state == State.menu;
}
public boolean is(State astate){
return state == astate;
}

View File

@@ -206,7 +206,7 @@ public class Logic implements ApplicationListener{
Events.fire(Trigger.update);
universe.updateGlobal();
if(!state.is(State.menu)){
if(state.isGame()){
if(!net.client()){
state.enemies = Groups.unit.count(b -> b.team() == state.rules.waveTeam && b.type().isCounted);
}

View File

@@ -451,7 +451,7 @@ public class NetClient implements ApplicationListener{
public void update(){
if(!net.client()) return;
if(!state.is(State.menu)){
if(state.isGame()){
if(!connecting) sync();
}else if(!connecting){
net.disconnect();

View File

@@ -673,7 +673,7 @@ public class NetServer implements ApplicationListener{
@Override
public void update(){
if(!headless && !closing && net.server() && state.is(State.menu)){
if(!headless && !closing && net.server() && state.isMenu()){
closing = true;
ui.loadfrag.show("$server.closing");
Time.runTask(5f, () -> {
@@ -683,7 +683,7 @@ public class NetServer implements ApplicationListener{
});
}
if(!state.is(State.menu) && net.server()){
if(state.isGame() && net.server()){
sync();
}
}

View File

@@ -9,7 +9,6 @@ import arc.math.*;
import arc.scene.ui.layout.*;
import arc.util.*;
import mindustry.content.*;
import mindustry.core.GameState.*;
import mindustry.game.EventType.*;
import mindustry.gen.*;
import mindustry.graphics.*;
@@ -27,7 +26,7 @@ public class Renderer implements ApplicationListener{
public FrameBuffer effectBuffer = new FrameBuffer(2, 2);
private Bloom bloom;
private Color clearColor;
private Color clearColor = new Color(0f, 0f, 0f, 1f);
private float targetscale = Scl.scl(4);
private float camerascale = targetscale;
private float landscale = 0f, landTime;
@@ -37,8 +36,6 @@ public class Renderer implements ApplicationListener{
public Renderer(){
camera = new Camera();
Shaders.init();
clearColor = new Color(0f, 0f, 0f, 1f);
}
public void shake(float intensity, float duration){
@@ -68,7 +65,7 @@ public class Renderer implements ApplicationListener{
camera.width = graphics.getWidth() / camerascale;
camera.height = graphics.getHeight() / camerascale;
if(state.is(State.menu)){
if(state.isMenu()){
landTime = 0f;
graphics.clear(Color.black);
}else{

View File

@@ -20,7 +20,6 @@ import arc.scene.ui.Tooltip.*;
import arc.scene.ui.layout.*;
import arc.struct.*;
import arc.util.*;
import mindustry.core.GameState.*;
import mindustry.editor.*;
import mindustry.game.EventType.*;
import mindustry.gen.*;
@@ -185,10 +184,10 @@ public class UI implements ApplicationListener, Loadable{
menuGroup.setFillParent(true);
menuGroup.touchable(Touchable.childrenOnly);
menuGroup.visible(() -> state.is(State.menu));
menuGroup.visible(() -> state.isMenu());
hudGroup.setFillParent(true);
hudGroup.touchable(Touchable.childrenOnly);
hudGroup.visible(() -> !state.is(State.menu));
hudGroup.visible(() -> state.isGame());
Core.scene.add(menuGroup);
Core.scene.add(hudGroup);
@@ -296,7 +295,7 @@ public class UI implements ApplicationListener, Loadable{
table.setFillParent(true);
table.touchable(Touchable.disabled);
table.update(() -> {
if(state.is(State.menu)) table.remove();
if(state.isMenu()) table.remove();
});
table.actions(Actions.delay(duration * 0.9f), Actions.fadeOut(duration * 0.1f, Interpolation.fade), Actions.remove());
table.top().table(Styles.black3, t -> t.margin(4).add(info).style(Styles.outlineLabel)).padTop(10);
@@ -309,7 +308,7 @@ public class UI implements ApplicationListener, Loadable{
table.setFillParent(true);
table.touchable(Touchable.disabled);
table.update(() -> {
if(state.is(State.menu)) table.remove();
if(state.isMenu()) table.remove();
});
table.actions(Actions.delay(duration), Actions.remove());
table.align(align).table(Styles.black3, t -> t.margin(4).add(info).style(Styles.outlineLabel)).pad(top, left, bottom, right);
@@ -322,7 +321,7 @@ public class UI implements ApplicationListener, Loadable{
table.setFillParent(true);
table.touchable(Touchable.disabled);
table.update(() -> {
if(state.is(State.menu)) table.remove();
if(state.isMenu()) table.remove();
});
table.actions(Actions.delay(duration), Actions.remove());
table.align(Align.center).table(Styles.black3, t -> t.margin(4).add(info).style(Styles.outlineLabel)).update(t -> {

View File

@@ -46,7 +46,7 @@ public class MusicControl{
/** Update and play the right music track.*/
public void update(){
if(state.is(State.menu)){
if(state.isMenu()){
silenced = false;
if(ui.planet.isShown()){
play(Musics.launch);

View File

@@ -77,7 +77,7 @@ public class Saves{
public void update(){
SaveSlot current = this.current;
if(current != null && !state.is(State.menu)
if(current != null && state.isGame()
&& !(state.isPaused() && Core.scene.hasDialog())){
if(lastTimestamp != 0){
totalPlaytime += Time.timeSinceMillis(lastTimestamp);
@@ -85,7 +85,7 @@ public class Saves{
lastTimestamp = Time.millis();
}
if(!state.is(State.menu) && !state.gameOver && current != null && current.isAutosave() && !state.rules.tutorial){
if(state.isGame() && !state.gameOver && current != null && current.isAutosave() && !state.rules.tutorial){
time += Time.delta();
if(time > Core.settings.getInt("saveinterval") * 60){
saving = true;
@@ -192,7 +192,7 @@ public class Saves{
SaveIO.save(file);
meta = SaveIO.getMeta(file);
if(!state.is(State.menu)){
if(state.isGame()){
current = this;
}

View File

@@ -177,11 +177,11 @@ public class DesktopInput extends InputHandler{
isShooting = false;
}
if(!state.is(State.menu) && Core.input.keyTap(Binding.minimap) && !scene.hasDialog() && !(scene.getKeyboardFocus() instanceof TextField)){
if(state.isGame() && Core.input.keyTap(Binding.minimap) && !scene.hasDialog() && !(scene.getKeyboardFocus() instanceof TextField)){
ui.minimapfrag.toggle();
}
if(state.is(State.menu) || Core.scene.hasDialog()) return;
if(state.isMenu() || Core.scene.hasDialog()) return;
//zoom camera
if((!Core.scene.hasScroll() || Core.input.keyDown(Binding.diagonal_placement)) && !ui.chatfrag.shown() && Math.abs(Core.input.axisTap(Binding.zoom)) > 0
@@ -491,7 +491,7 @@ public class DesktopInput extends InputHandler{
@Override
public void updateState(){
if(state.is(State.menu)){
if(state.isMenu()){
droppingItem = false;
mode = none;
block = null;

View File

@@ -432,7 +432,7 @@ public class MobileInput extends InputHandler implements GestureListener{
@Override
public boolean touchDown(int screenX, int screenY, int pointer, KeyCode button){
if(state.is(State.menu)) return false;
if(state.isMenu()) return false;
down = true;
@@ -513,7 +513,7 @@ public class MobileInput extends InputHandler implements GestureListener{
@Override
public boolean longPress(float x, float y){
if(state.is(State.menu) || mode == none || player.dead()) return false;
if(state.isMenu() || mode == none || player.dead()) return false;
//get tile on cursor
Tile cursor = tileAt(x, y);
@@ -541,7 +541,7 @@ public class MobileInput extends InputHandler implements GestureListener{
@Override
public boolean tap(float x, float y, int count, KeyCode button){
if(state.is(State.menu) || lineMode) return false;
if(state.isMenu() || lineMode) return false;
float worldx = Core.input.mouseWorld(x, y).x, worldy = Core.input.mouseWorld(x, y).y;
@@ -574,7 +574,7 @@ public class MobileInput extends InputHandler implements GestureListener{
public void update(){
super.update();
if(state.is(State.menu) ){
if(state.isMenu() ){
selectRequests.clear();
removals.clear();
mode = none;

View File

@@ -41,7 +41,7 @@ public class ItemsDisplay extends Table{
}).get().setScrollingDisabled(true, false), false).setDuration(0.3f);
c.addImageTextButton("$launcheditems", Icon.downOpen, Styles.clearTogglet, col::toggle).update(t -> {
t.setText(state.is(State.menu) ? "$launcheditems" : "$launchinfo");
t.setText(state.isMenu() ? "$launcheditems" : "$launchinfo");
t.setChecked(col.isCollapsed());
((Image)t.getChildren().get(1)).setDrawable(col.isCollapsed() ? Icon.upOpen : Icon.downOpen);
}).padBottom(4).left().fillX().margin(12f).minWidth(200f);
@@ -53,7 +53,7 @@ public class ItemsDisplay extends Table{
private String format(Item item){
builder.setLength(0);
builder.append(ui.formatAmount(data.items().get(item, 0)));
if(!state.is(State.menu) && player.team().data().hasCore() && player.team().core().items().get(item) > 0){
if(state.isGame() && player.team().data().hasCore() && player.team().core().items().get(item) > 0){
builder.append(" [unlaunched]+ ");
builder.append(ui.formatAmount(state.teams.get(player.team()).core().items().get(item)));
}

View File

@@ -91,6 +91,6 @@ public class DatabaseDialog extends FloatingDialog{
}
boolean unlocked(UnlockableContent content){
return (!Vars.state.isCampaign() && !Vars.state.is(State.menu)) || content.unlocked();
return (!Vars.state.isCampaign() && !Vars.state.isMenu()) || content.unlocked();
}
}

View File

@@ -24,7 +24,7 @@ public class FloatingDialog extends Dialog{
.growX().height(3f).pad(4f);
hidden(() -> {
if(shouldPause && !state.is(State.menu)){
if(shouldPause && state.isGame()){
if(!wasPaused || net.active()){
state.set(State.playing);
}
@@ -33,7 +33,7 @@ public class FloatingDialog extends Dialog{
});
shown(() -> {
if(shouldPause && !state.is(State.menu)){
if(shouldPause && state.isGame()){
wasPaused = state.is(State.paused);
state.set(State.paused);
}

View File

@@ -29,7 +29,7 @@ public class PausedDialog extends FloatingDialog{
cont.clear();
update(() -> {
if(state.is(State.menu) && isShown()){
if(state.isMenu() && isShown()){
hide();
}
});

View File

@@ -15,7 +15,7 @@ public class SaveDialog extends LoadDialog{
super("$savegame");
update(() -> {
if(state.is(State.menu) && isShown()){
if(state.isMenu() && isShown()){
hide();
}
});

View File

@@ -122,7 +122,7 @@ public class SchematicsDialog extends FloatingDialog{
})).size(200f);
}, () -> {
if(sel[0].childrenPressed()) return;
if(state.is(State.menu)){
if(state.isMenu()){
showInfo(s);
}else{
control.input.useSchematic(s);

View File

@@ -37,7 +37,7 @@ public class SettingsMenuDialog extends SettingsDialog{
public SettingsMenuDialog(){
hidden(() -> {
Sounds.back.play();
if(!state.is(State.menu)){
if(state.isGame()){
if(!wasPaused || net.active())
state.set(State.playing);
}
@@ -45,7 +45,7 @@ public class SettingsMenuDialog extends SettingsDialog{
shown(() -> {
back();
if(!state.is(State.menu)){
if(state.isGame()){
wasPaused = state.is(State.paused);
state.set(State.paused);
}

View File

@@ -27,7 +27,7 @@ public class BlockConfigFragment extends Fragment{
@Override
public void act(float delta){
super.act(delta);
if(state.is(State.menu)){
if(state.isMenu()){
table.visible(false);
configTile = null;
}

View File

@@ -99,7 +99,7 @@ public class BlockInventoryFragment extends Fragment{
table.touchable(Touchable.enabled);
table.update(() -> {
if(state.is(State.menu) || tile == null || !tile.isValid() || !tile.block().isAccessible() || tile.items().total() == 0){
if(state.isMenu() || tile == null || !tile.isValid() || !tile.block().isAccessible() || tile.items().total() == 0){
hide();
}else{
if(holding && lastItem != null){

View File

@@ -229,7 +229,7 @@ public class HudFragment extends Fragment{
});
t.top().visible(() -> {
if(state.is(State.menu) || !state.teams.get(player.team()).hasCore()){
if(state.isMenu() || !state.teams.get(player.team()).hasCore()){
coreAttackTime[0] = 0f;
return false;
}
@@ -288,7 +288,7 @@ public class HudFragment extends Fragment{
.style(Styles.outlineLabel)).padTop(10).visible(p.color.a >= 0.001f);
p.update(() -> {
p.color.a = Mathf.lerpDelta(p.color.a, Mathf.num(showHudText), 0.2f);
if(state.is(State.menu)){
if(state.isMenu()){
p.color.a = 0f;
showHudText = false;
}
@@ -328,14 +328,14 @@ public class HudFragment extends Fragment{
}
public void showToast(String text){
if(state.is(State.menu)) return;
if(state.isMenu()) return;
scheduleToast(() -> {
Sounds.message.play();
Table table = new Table(Tex.button);
table.update(() -> {
if(state.is(State.menu)){
if(state.isMenu()){
table.remove();
}
});
@@ -362,7 +362,7 @@ public class HudFragment extends Fragment{
public void showUnlock(UnlockableContent content){
//some content may not have icons... yet
//also don't play in the tutorial to prevent confusion
if(state.is(State.menu) || state.rules.tutorial) return;
if(state.isMenu() || state.rules.tutorial) return;
Sounds.message.play();
@@ -371,7 +371,7 @@ public class HudFragment extends Fragment{
scheduleToast(() -> {
Table table = new Table(Tex.button);
table.update(() -> {
if(state.is(State.menu)){
if(state.isMenu()){
table.remove();
lastUnlockLayout = null;
lastUnlockTable = null;
@@ -454,7 +454,7 @@ public class HudFragment extends Fragment{
image.setFillParent(true);
image.actions(Actions.fadeIn(40f / 60f));
image.update(() -> {
if(state.is(State.menu)){
if(state.isMenu()){
image.remove();
}
});
@@ -469,7 +469,7 @@ public class HudFragment extends Fragment{
image.actions(Actions.fadeOut(0.8f), Actions.remove());
image.update(() -> {
image.toFront();
if(state.is(State.menu)){
if(state.isMenu()){
image.remove();
}
});

View File

@@ -7,7 +7,6 @@ import arc.scene.event.*;
import arc.scene.ui.*;
import arc.scene.ui.layout.*;
import arc.util.*;
import mindustry.core.GameState.*;
import mindustry.gen.*;
import mindustry.graphics.*;
import mindustry.net.*;
@@ -26,7 +25,7 @@ public class PlayerListFragment extends Fragment{
parent.fill(cont -> {
cont.visible(() -> visible);
cont.update(() -> {
if(!(net.active() && !state.is(State.menu))){
if(!(net.active() && state.isGame())){
visible = false;
return;
}