Converted GDXAppMain into enum instance

This commit is contained in:
Willem Cazander 2022-02-15 20:20:23 +01:00
parent 3a11823fdf
commit d3ece6b035
9 changed files with 111 additions and 81 deletions

View file

@ -4,7 +4,6 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import com.badlogic.gdx.Files.FileType; import com.badlogic.gdx.Files.FileType;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application; import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration; import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
@ -27,8 +26,8 @@ public class GDXAppDesktopLauncher {
config.setWindowedMode(GDXAppDesktopConfig.WINDOW_WIDTH, GDXAppDesktopConfig.WINDOW_HEIGHT); config.setWindowedMode(GDXAppDesktopConfig.WINDOW_WIDTH, GDXAppDesktopConfig.WINDOW_HEIGHT);
List<String> args = Arrays.asList(arg); List<String> args = Arrays.asList(arg);
DesktopFileChooser aop0 = new DesktopFileChooser(); DesktopFileChooser aop0 = new DesktopFileChooser();
Game app = new GDXAppMain(args, GDXAppDesktopConfig.WINDOW_WIDTH, GDXAppDesktopConfig.WINDOW_HEIGHT, aop0); GDXAppMain.INSTANCE.BãßInit(args, GDXAppDesktopConfig.WINDOW_WIDTH, GDXAppDesktopConfig.WINDOW_HEIGHT, aop0);
Lwjgl3Application launcher = new Lwjgl3Application(app, config); Lwjgl3Application launcher = new Lwjgl3Application(GDXAppMain.INSTANCE, config);
launcher.exit(); launcher.exit();
} }
} }

View file

@ -4,7 +4,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import com.badlogic.gdx.Game; import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen; import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.OrthographicCamera;
@ -17,8 +17,13 @@ import imgui.flag.ImGuiCond;
import imgui.flag.ImGuiWindowFlags; import imgui.flag.ImGuiWindowFlags;
import imgui.type.ImBoolean; import imgui.type.ImBoolean;
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
import love.distributedrebirth.bassboonyd.BãßBȍőnClassInfoʸᴰ;
import love.distributedrebirth.bassboonyd.BãßBȍőnCoffinOpenʸᴰ; import love.distributedrebirth.bassboonyd.BãßBȍőnCoffinOpenʸᴰ;
import love.distributedrebirth.bassboonyd.BãßBȍőnCoffinʸᴰ;
import love.distributedrebirth.bassboonyd.BãßBȍőnPackageInfoʸᴰ;
import love.distributedrebirth.bassboonyd.jmx.DefaultEnumBaseᴶᴹˣ; import love.distributedrebirth.bassboonyd.jmx.DefaultEnumBaseᴶᴹˣ;
import love.distributedrebirth.bassboonyd.jmx.DefaultEnumInstanceᴶᴹˣ;
import love.distributedrebirth.bassboonyd.jmx.GuageCounterᴶᴹˣ;
import love.distributedrebirth.gdxapp.desktop.DeskAppContourSection; import love.distributedrebirth.gdxapp.desktop.DeskAppContourSection;
import love.distributedrebirth.gdxapp.desktop.DeskAppRenderer; import love.distributedrebirth.gdxapp.desktop.DeskAppRenderer;
import love.distributedrebirth.gdxapp.desktop.DeskTopScreen; import love.distributedrebirth.gdxapp.desktop.DeskTopScreen;
@ -42,26 +47,37 @@ import love.distributedrebirth.numberxd.base2t.part.warp.WaterBucket;
import love.distributedrebirth.numberxd.glyph.BaseGlyphSet; import love.distributedrebirth.numberxd.glyph.BaseGlyphSet;
import net.spookygames.gdx.nativefilechooser.NativeFileChooser; import net.spookygames.gdx.nativefilechooser.NativeFileChooser;
/**
* Main loop render dispatcher and event handling.
*/
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天") @BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
public class GDXAppMain extends Game { @BãßBȍőnClassInfoʸᴰ(name = "GDXAppMain", purpose = "Main loop render dispatcher and bootup.")
@BãßBȍőnPackageInfoʸᴰ(name = "love.distributedrebirth.gdxapp")
public enum GDXAppMain implements DefaultEnumInstanceᴶᴹˣ<GDXAppMain,GDXAppMainKeyʸᴰ>,ApplicationListener {
INSTANCE;
protected Screen screen;
private int lazyIntCnt = 33; private int lazyIntCnt = 33;
private List<String> args; private List<String> args;
public NativeFileChooser fileChooser; public NativeFileChooser fileChooser;
public SpriteBatch batch; public SpriteBatch batch;
public BitmapFont font; public BitmapFont font;
public OrthographicCamera camera; public OrthographicCamera camera;
public final int viewWidth; public int viewWidth;
public final int viewHeight; public int viewHeight;
public MusicManager music; public MusicManager music;
public ImBoolean showImGuiDemo = new ImBoolean(false); public ImBoolean showImGuiDemo = new ImBoolean(false);
private Map<Class<? extends Screen>,Screen> screens; private Map<Class<? extends Screen>,Screen> screens;
private DeskTopScreenMenu screenMenu; private DeskTopScreenMenu screenMenu;
private final GuageCounterᴶᴹˣ selectScreenCounter;
private final BãßBȍőnCoffinOpenʸᴰ<GDXAppMainKeyʸᴰ> BBC = BãßBȍőnCoffinOpenʸᴰ.newInstance();
public BãßBȍőnCoffinʸᴰ<GDXAppMainKeyʸᴰ> GET_BBC() { return BBC; }
private GDXAppMain() {
BBC.BOON_INIT(this);
BȍőnJmxInit(GDXAppMainKeyʸᴰ.JMX);
selectScreenCounter = BȍőnJmxInitGuageCounter(GDXAppMainKeyʸᴰ.JMX, "selectScreenCounter");
}
public GDXAppMain(List<String> args, int viewWidth, int viewHeight, NativeFileChooser fileChooser) { public void BãßInit(List<String> args, int viewWidth, int viewHeight, NativeFileChooser fileChooser) {
this.args = args; this.args = args;
this.viewWidth = viewWidth; this.viewWidth = viewWidth;
this.viewHeight = viewHeight; this.viewHeight = viewHeight;
@ -88,6 +104,7 @@ public class GDXAppMain extends Game {
// ref to init // ref to init
System.out.println("BãßBȍőnCoffinʸᴰ init......"); System.out.println("BãßBȍőnCoffinʸᴰ init......");
BãßBȍőnCoffinOpenʸᴰ.lockCoffin(this);
for (DefaultEnumBaseᴶᴹˣ<?,?> coffin:coffinInstances()) { for (DefaultEnumBaseᴶᴹˣ<?,?> coffin:coffinInstances()) {
BãßBȍőnCoffinOpenʸᴰ.lockCoffin(coffin); BãßBȍőnCoffinOpenʸᴰ.lockCoffin(coffin);
} }
@ -124,9 +141,27 @@ public class GDXAppMain extends Game {
} else { } else {
selectScreen(ScreenIntro.class); selectScreen(ScreenIntro.class);
} }
} }
private void putScreen(Screen screen) {
screens.put(screen.getClass(), screen);
}
public void selectScreen(Class<? extends Screen> screenClass) {
Screen screen = screens.get(screenClass);
if (screen == null) {
throw new NullPointerException("Unknow screen: "+screenClass);
}
selectScreenCounter.increment();
if (this.screen != null) this.screen.hide();
this.screen = screen;
if (this.screen != null) {
this.screen.show();
this.screen.resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
}
@Override
public void create() { public void create() {
batch = new SpriteBatch(); batch = new SpriteBatch();
font = new BitmapFont(); font = new BitmapFont();
@ -151,40 +186,22 @@ public class GDXAppMain extends Game {
DeskTopScreen desktop4 = new ScreenDesktop4(); DeskTopScreen desktop4 = new ScreenDesktop4();
screenMenu = new DeskTopScreenMenu(this, desktop1, desktop2, desktop3, desktop4); screenMenu = new DeskTopScreenMenu(this, desktop1, desktop2, desktop3, desktop4);
putScreen(new ScreenLoading(this)); putScreen(new ScreenLoading());
putScreen(new ScreenIntro(this)); putScreen(new ScreenIntro());
putScreen(new ScreenIntroMission(this)); putScreen(new ScreenIntroMission());
putScreen(desktop1); putScreen(desktop1);
putScreen(desktop2); putScreen(desktop2);
putScreen(desktop3); putScreen(desktop3);
putScreen(desktop4); putScreen(desktop4);
putScreen(new ScreenCredits(this)); putScreen(new ScreenCredits());
putScreen(new ScreenHelp(this)); putScreen(new ScreenHelp());
selectScreen(ScreenLoading.class); selectScreen(ScreenLoading.class);
} }
@Override @Override
public void dispose() { public void resize(int width, int height) {
ImGuiSetup.dispose(); if (screen != null) screen.resize(width, height);
for (Screen screen:screens.values()) {
screen.dispose();
}
music.dispose();
batch.dispose();
font.dispose();
}
private void putScreen(Screen screen) {
screens.put(screen.getClass(), screen);
}
public void selectScreen(Class<? extends Screen> screenClass) {
Screen screen = screens.get(screenClass);
if (screen == null) {
throw new NullPointerException("Unknow screen: "+screenClass);
}
setScreen(screen);
} }
@Override @Override
@ -228,4 +245,25 @@ public class GDXAppMain extends Game {
ImGui.render(); ImGui.render();
ImGuiSetup.imGuiGlImp.renderDrawData(ImGui.getDrawData()); ImGuiSetup.imGuiGlImp.renderDrawData(ImGui.getDrawData());
} }
@Override
public void pause() {
if (screen != null) screen.pause();
}
@Override
public void resume() {
if (screen != null) screen.resume();
}
@Override
public void dispose() {
ImGuiSetup.dispose();
for (Screen screen:screens.values()) {
screen.dispose();
}
music.dispose();
batch.dispose();
font.dispose();
}
} }

View file

@ -1,14 +1,12 @@
package love.distributedrebirth.gdxapp; package love.distributedrebirth.gdxapp;
import com.badlogic.gdx.ScreenAdapter;
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
import love.distributedrebirth.bassboonyd.BãßBȍőnCoffinStoreKeyʸᴰ;
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天") @BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
public class GDXAppMainAdapter extends ScreenAdapter { public enum GDXAppMainKeyʸᴰ implements BãßBȍőnCoffinStoreKeyʸᴰ {
protected final GDXAppMain main;
JMX,
public GDXAppMainAdapter(GDXAppMain main) {
this.main = main; ;
}
} }

View file

@ -2,16 +2,16 @@ package love.distributedrebirth.gdxapp.screen;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen; import com.badlogic.gdx.Screen;
import com.badlogic.gdx.ScreenAdapter;
import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.utils.ScreenUtils; import com.badlogic.gdx.utils.ScreenUtils;
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
import love.distributedrebirth.gdxapp.GDXAppMain; import love.distributedrebirth.gdxapp.GDXAppMain;
import love.distributedrebirth.gdxapp.GDXAppMainAdapter;
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天") @BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
abstract public class AbstractScrollScreen extends GDXAppMainAdapter { abstract public class AbstractScrollScreen extends ScreenAdapter {
private static final int LINE_HEIGHT = 16; private static final int LINE_HEIGHT = 16;
private float scrollDeltaTime = 0f; private float scrollDeltaTime = 0f;
private String scrollText = ""; private String scrollText = "";
@ -19,8 +19,7 @@ abstract public class AbstractScrollScreen extends GDXAppMainAdapter {
private int scrollLine = LINE_HEIGHT; private int scrollLine = LINE_HEIGHT;
private final Texture backgroundImage; private final Texture backgroundImage;
public AbstractScrollScreen(final GDXAppMain main, String background) { public AbstractScrollScreen(String background) {
super(main);
backgroundImage = new Texture(Gdx.files.internal(background)); backgroundImage = new Texture(Gdx.files.internal(background));
} }
@ -31,8 +30,8 @@ abstract public class AbstractScrollScreen extends GDXAppMainAdapter {
@Override @Override
public final void render(float delta) { public final void render(float delta) {
ScreenUtils.clear(0f, 0f, 0f, 1f); ScreenUtils.clear(0f, 0f, 0f, 1f);
main.batch.begin(); GDXAppMain.INSTANCE.batch.begin();
main.batch.draw(backgroundImage, 0, 0, main.viewWidth, main.viewHeight); GDXAppMain.INSTANCE.batch.draw(backgroundImage, 0, 0, GDXAppMain.INSTANCE.viewWidth, GDXAppMain.INSTANCE.viewHeight);
scrollDeltaTime += delta; scrollDeltaTime += delta;
if (scrollDeltaTime > 0.04f) { if (scrollDeltaTime > 0.04f) {
@ -51,14 +50,14 @@ abstract public class AbstractScrollScreen extends GDXAppMainAdapter {
String[] lines = scrollText.split("\n"); String[] lines = scrollText.split("\n");
for (int i=lines.length;i>0;i--) { for (int i=lines.length;i>0;i--) {
String line = lines[i-1]; String line = lines[i-1];
main.font.draw(main.batch, line, 100, scrollLine + (drawLine*LINE_HEIGHT)); GDXAppMain.INSTANCE.font.draw(GDXAppMain.INSTANCE.batch, line, 100, scrollLine + (drawLine*LINE_HEIGHT));
drawLine++; drawLine++;
} }
main.batch.end(); GDXAppMain.INSTANCE.batch.end();
if (scrollText.length() >= 33) { if (scrollText.length() >= 33) {
if (scrollLine >= main.viewHeight || Gdx.input.isTouched() || Gdx.input.isKeyPressed(Keys.ENTER) || Gdx.input.isKeyPressed(Keys.SPACE)) { if (scrollLine >=GDXAppMain.INSTANCE.viewHeight || Gdx.input.isTouched() || Gdx.input.isKeyPressed(Keys.ENTER) || Gdx.input.isKeyPressed(Keys.SPACE)) {
main.selectScreen(getNextScreen(main)); GDXAppMain.INSTANCE.selectScreen(getNextScreen(GDXAppMain.INSTANCE));
} }
} }
} }

View file

@ -63,8 +63,8 @@ public class ScreenCredits extends AbstractScrollScreen {
" " " "
); );
public ScreenCredits(final GDXAppMain main) { public ScreenCredits() {
super(main, "background/doom-credits.png"); super("background/doom-credits.png");
} }
@Override @Override
@ -79,11 +79,11 @@ public class ScreenCredits extends AbstractScrollScreen {
@Override @Override
public void showScroll() { public void showScroll() {
main.music.play(MusicSongType.CREDITS); GDXAppMain.INSTANCE.music.play(MusicSongType.CREDITS);
} }
@Override @Override
public void hideScroll() { public void hideScroll() {
main.music.play(MusicSongType.BACKGROUND); GDXAppMain.INSTANCE.music.play(MusicSongType.BACKGROUND);
} }
} }

View file

@ -46,8 +46,8 @@ public class ScreenHelp extends AbstractScrollScreen {
" " " "
); );
public ScreenHelp(final GDXAppMain main) { public ScreenHelp() {
super(main, "background/terrydavis-nose.png"); super("background/terrydavis-nose.png");
} }
@Override @Override
@ -62,11 +62,11 @@ public class ScreenHelp extends AbstractScrollScreen {
@Override @Override
public void showScroll() { public void showScroll() {
main.music.play(MusicSongType.INTRO); GDXAppMain.INSTANCE.music.play(MusicSongType.INTRO);
} }
@Override @Override
public void hideScroll() { public void hideScroll() {
main.music.play(MusicSongType.BACKGROUND); GDXAppMain.INSTANCE.music.play(MusicSongType.BACKGROUND);
} }
} }

View file

@ -12,13 +12,11 @@ import love.distributedrebirth.gdxapp.music.MusicSongType;
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天") @BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
public class ScreenIntro extends ScreenAdapter { public class ScreenIntro extends ScreenAdapter {
private final GDXAppMain main;
private Texture backgroundImage; private Texture backgroundImage;
private float colorDeltaTime = 0f; private float colorDeltaTime = 0f;
private boolean colorPositive = true; private boolean colorPositive = true;
public ScreenIntro(final GDXAppMain main) { public ScreenIntro() {
this.main = main;
backgroundImage = new Texture(Gdx.files.internal("background/temple-os.png")); backgroundImage = new Texture(Gdx.files.internal("background/temple-os.png"));
} }
@ -36,20 +34,20 @@ public class ScreenIntro extends ScreenAdapter {
} }
ScreenUtils.clear(0.333f, colorDeltaTime, colorDeltaTime, 1); ScreenUtils.clear(0.333f, colorDeltaTime, colorDeltaTime, 1);
main.batch.begin(); GDXAppMain.INSTANCE.batch.begin();
main.batch.draw(backgroundImage, 0, 0, main.viewWidth, main.viewHeight); GDXAppMain.INSTANCE.batch.draw(backgroundImage, 0, 0, GDXAppMain.INSTANCE.viewWidth, GDXAppMain.INSTANCE.viewHeight);
main.font.draw(main.batch, "Tap anywhere to begin!", main.viewWidth/2 - 73, 33); GDXAppMain.INSTANCE.font.draw(GDXAppMain.INSTANCE.batch, "Tap anywhere to begin!", GDXAppMain.INSTANCE.viewWidth/2 - 73, 33);
main.batch.end(); GDXAppMain.INSTANCE.batch.end();
if (Gdx.input.isTouched() || Gdx.input.isKeyPressed(Keys.ENTER) || Gdx.input.isKeyPressed(Keys.SPACE)) { if (Gdx.input.isTouched() || Gdx.input.isKeyPressed(Keys.ENTER) || Gdx.input.isKeyPressed(Keys.SPACE)) {
main.setScreen(new ScreenIntroMission(main)); GDXAppMain.INSTANCE.selectScreen(ScreenIntroMission.class);
dispose(); dispose();
} }
} }
@Override @Override
public void show() { public void show() {
main.music.play(MusicSongType.INTRO); GDXAppMain.INSTANCE.music.play(MusicSongType.INTRO);
} }
@Override @Override

View file

@ -56,8 +56,8 @@ public class ScreenIntroMission extends AbstractScrollScreen {
public ScreenIntroMission(final GDXAppMain main) { public ScreenIntroMission() {
super(main, "background/terrydavis-nose.png"); super("background/terrydavis-nose.png");
} }
@Override @Override
@ -72,6 +72,6 @@ public class ScreenIntroMission extends AbstractScrollScreen {
@Override @Override
public void hideScroll() { public void hideScroll() {
main.music.play(MusicSongType.BACKGROUND); GDXAppMain.INSTANCE.music.play(MusicSongType.BACKGROUND);
} }
} }

View file

@ -9,19 +9,17 @@ import love.distributedrebirth.gdxapp.GDXAppMain;
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天") @BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
public class ScreenLoading extends ScreenAdapter { public class ScreenLoading extends ScreenAdapter {
private final GDXAppMain main;
private Texture backgroundImage; private Texture backgroundImage;
public ScreenLoading(final GDXAppMain main) { public ScreenLoading() {
this.main = main;
backgroundImage = new Texture(Gdx.files.internal("background/gdxapp-loading.png")); backgroundImage = new Texture(Gdx.files.internal("background/gdxapp-loading.png"));
} }
@Override @Override
public void render(float delta) { public void render(float delta) {
main.batch.begin(); GDXAppMain.INSTANCE.batch.begin();
main.batch.draw(backgroundImage, 0, 0, main.viewWidth, main.viewHeight); GDXAppMain.INSTANCE.batch.draw(backgroundImage, 0, 0, GDXAppMain.INSTANCE.viewWidth, GDXAppMain.INSTANCE.viewHeight);
main.batch.end(); GDXAppMain.INSTANCE.batch.end();
} }
@Override @Override