From d3ece6b035d7bb582f349f8b4bd78f24f38d7999 Mon Sep 17 00:00:00 2001 From: Willem Date: Tue, 15 Feb 2022 20:20:23 +0100 Subject: [PATCH] Converted GDXAppMain into enum instance --- .../gdxapp/desktop/GDXAppDesktopLauncher.java | 5 +- .../distributedrebirth/gdxapp/GDXAppMain.java | 106 ++++++++++++------ ...pMainAdapter.java => GDXAppMainKeyʸᴰ.java} | 14 +-- .../gdxapp/screen/AbstractScrollScreen.java | 19 ++-- .../gdxapp/screen/ScreenCredits.java | 8 +- .../gdxapp/screen/ScreenHelp.java | 8 +- .../gdxapp/screen/ScreenIntro.java | 16 ++- .../gdxapp/screen/ScreenIntroMission.java | 6 +- .../gdxapp/screen/ScreenLoading.java | 10 +- 9 files changed, 111 insertions(+), 81 deletions(-) rename main-gdxapp/src/main/love/distributedrebirth/gdxapp/{GDXAppMainAdapter.java => GDXAppMainKeyʸᴰ.java} (50%) diff --git a/main-gdxapp-desktop/src/main/love/distributedrebirth/gdxapp/desktop/GDXAppDesktopLauncher.java b/main-gdxapp-desktop/src/main/love/distributedrebirth/gdxapp/desktop/GDXAppDesktopLauncher.java index 0f8f33aa..908b2010 100644 --- a/main-gdxapp-desktop/src/main/love/distributedrebirth/gdxapp/desktop/GDXAppDesktopLauncher.java +++ b/main-gdxapp-desktop/src/main/love/distributedrebirth/gdxapp/desktop/GDXAppDesktopLauncher.java @@ -4,7 +4,6 @@ import java.util.Arrays; import java.util.List; import com.badlogic.gdx.Files.FileType; -import com.badlogic.gdx.Game; import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application; import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration; @@ -27,8 +26,8 @@ public class GDXAppDesktopLauncher { config.setWindowedMode(GDXAppDesktopConfig.WINDOW_WIDTH, GDXAppDesktopConfig.WINDOW_HEIGHT); List args = Arrays.asList(arg); DesktopFileChooser aop0 = new DesktopFileChooser(); - Game app = new GDXAppMain(args, GDXAppDesktopConfig.WINDOW_WIDTH, GDXAppDesktopConfig.WINDOW_HEIGHT, aop0); - Lwjgl3Application launcher = new Lwjgl3Application(app, config); + GDXAppMain.INSTANCE.BãßInit(args, GDXAppDesktopConfig.WINDOW_WIDTH, GDXAppDesktopConfig.WINDOW_HEIGHT, aop0); + Lwjgl3Application launcher = new Lwjgl3Application(GDXAppMain.INSTANCE, config); launcher.exit(); } } diff --git a/main-gdxapp/src/main/love/distributedrebirth/gdxapp/GDXAppMain.java b/main-gdxapp/src/main/love/distributedrebirth/gdxapp/GDXAppMain.java index 8ef42a7f..837f7a5b 100644 --- a/main-gdxapp/src/main/love/distributedrebirth/gdxapp/GDXAppMain.java +++ b/main-gdxapp/src/main/love/distributedrebirth/gdxapp/GDXAppMain.java @@ -4,7 +4,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import com.badlogic.gdx.Game; +import com.badlogic.gdx.ApplicationListener; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Screen; import com.badlogic.gdx.graphics.OrthographicCamera; @@ -17,8 +17,13 @@ import imgui.flag.ImGuiCond; import imgui.flag.ImGuiWindowFlags; import imgui.type.ImBoolean; 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ȍőnCoffinʸᴰ; +import love.distributedrebirth.bassboonyd.BãßBȍőnPackageInfoʸᴰ; 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.DeskAppRenderer; 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 net.spookygames.gdx.nativefilechooser.NativeFileChooser; -/** - * Main loop render dispatcher and event handling. - */ @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ᴶᴹˣ,ApplicationListener { + + INSTANCE; + + protected Screen screen; private int lazyIntCnt = 33; private List args; public NativeFileChooser fileChooser; public SpriteBatch batch; public BitmapFont font; public OrthographicCamera camera; - public final int viewWidth; - public final int viewHeight; + public int viewWidth; + public int viewHeight; public MusicManager music; public ImBoolean showImGuiDemo = new ImBoolean(false); private Map,Screen> screens; private DeskTopScreenMenu screenMenu; + private final GuageCounterᴶᴹˣ selectScreenCounter; + private final BãßBȍőnCoffinOpenʸᴰ BBC = BãßBȍőnCoffinOpenʸᴰ.newInstance(); + public BãßBȍőnCoffinʸᴰ GET_BBC() { return BBC; } + private GDXAppMain() { + BBC.BOON_INIT(this); + BȍőnJmxInit(GDXAppMainKeyʸᴰ.JMX); + selectScreenCounter = BȍőnJmxInitGuageCounter(GDXAppMainKeyʸᴰ.JMX, "selectScreenCounter"); + } - public GDXAppMain(List args, int viewWidth, int viewHeight, NativeFileChooser fileChooser) { + public void BãßInit(List args, int viewWidth, int viewHeight, NativeFileChooser fileChooser) { this.args = args; this.viewWidth = viewWidth; this.viewHeight = viewHeight; @@ -88,6 +104,7 @@ public class GDXAppMain extends Game { // ref to init System.out.println("BãßBȍőnCoffinʸᴰ init......"); + BãßBȍőnCoffinOpenʸᴰ.lockCoffin(this); for (DefaultEnumBaseᴶᴹˣ coffin:coffinInstances()) { BãßBȍőnCoffinOpenʸᴰ.lockCoffin(coffin); } @@ -124,9 +141,27 @@ public class GDXAppMain extends Game { } else { selectScreen(ScreenIntro.class); } - } + private void putScreen(Screen screen) { + screens.put(screen.getClass(), screen); + } + + public void selectScreen(Class 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() { batch = new SpriteBatch(); font = new BitmapFont(); @@ -151,40 +186,22 @@ public class GDXAppMain extends Game { DeskTopScreen desktop4 = new ScreenDesktop4(); screenMenu = new DeskTopScreenMenu(this, desktop1, desktop2, desktop3, desktop4); - putScreen(new ScreenLoading(this)); - putScreen(new ScreenIntro(this)); - putScreen(new ScreenIntroMission(this)); + putScreen(new ScreenLoading()); + putScreen(new ScreenIntro()); + putScreen(new ScreenIntroMission()); putScreen(desktop1); putScreen(desktop2); putScreen(desktop3); putScreen(desktop4); - putScreen(new ScreenCredits(this)); - putScreen(new ScreenHelp(this)); + putScreen(new ScreenCredits()); + putScreen(new ScreenHelp()); selectScreen(ScreenLoading.class); } @Override - public void dispose() { - ImGuiSetup.dispose(); - 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 screenClass) { - Screen screen = screens.get(screenClass); - if (screen == null) { - throw new NullPointerException("Unknow screen: "+screenClass); - } - setScreen(screen); + public void resize(int width, int height) { + if (screen != null) screen.resize(width, height); } @Override @@ -228,4 +245,25 @@ public class GDXAppMain extends Game { ImGui.render(); 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(); + } } diff --git a/main-gdxapp/src/main/love/distributedrebirth/gdxapp/GDXAppMainAdapter.java b/main-gdxapp/src/main/love/distributedrebirth/gdxapp/GDXAppMainKeyʸᴰ.java similarity index 50% rename from main-gdxapp/src/main/love/distributedrebirth/gdxapp/GDXAppMainAdapter.java rename to main-gdxapp/src/main/love/distributedrebirth/gdxapp/GDXAppMainKeyʸᴰ.java index 2ce87527..4b4f19ce 100644 --- a/main-gdxapp/src/main/love/distributedrebirth/gdxapp/GDXAppMainAdapter.java +++ b/main-gdxapp/src/main/love/distributedrebirth/gdxapp/GDXAppMainKeyʸᴰ.java @@ -1,14 +1,12 @@ package love.distributedrebirth.gdxapp; -import com.badlogic.gdx.ScreenAdapter; - import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; +import love.distributedrebirth.bassboonyd.BãßBȍőnCoffinStoreKeyʸᴰ; @BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天") -public class GDXAppMainAdapter extends ScreenAdapter { - protected final GDXAppMain main; - - public GDXAppMainAdapter(GDXAppMain main) { - this.main = main; - } +public enum GDXAppMainKeyʸᴰ implements BãßBȍőnCoffinStoreKeyʸᴰ { + + JMX, + + ; } diff --git a/main-gdxapp/src/main/love/distributedrebirth/gdxapp/screen/AbstractScrollScreen.java b/main-gdxapp/src/main/love/distributedrebirth/gdxapp/screen/AbstractScrollScreen.java index 2475653c..325e2106 100644 --- a/main-gdxapp/src/main/love/distributedrebirth/gdxapp/screen/AbstractScrollScreen.java +++ b/main-gdxapp/src/main/love/distributedrebirth/gdxapp/screen/AbstractScrollScreen.java @@ -2,16 +2,16 @@ package love.distributedrebirth.gdxapp.screen; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Screen; +import com.badlogic.gdx.ScreenAdapter; import com.badlogic.gdx.Input.Keys; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.utils.ScreenUtils; import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; import love.distributedrebirth.gdxapp.GDXAppMain; -import love.distributedrebirth.gdxapp.GDXAppMainAdapter; @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 float scrollDeltaTime = 0f; private String scrollText = ""; @@ -19,8 +19,7 @@ abstract public class AbstractScrollScreen extends GDXAppMainAdapter { private int scrollLine = LINE_HEIGHT; private final Texture backgroundImage; - public AbstractScrollScreen(final GDXAppMain main, String background) { - super(main); + public AbstractScrollScreen(String background) { backgroundImage = new Texture(Gdx.files.internal(background)); } @@ -31,8 +30,8 @@ abstract public class AbstractScrollScreen extends GDXAppMainAdapter { @Override public final void render(float delta) { ScreenUtils.clear(0f, 0f, 0f, 1f); - main.batch.begin(); - main.batch.draw(backgroundImage, 0, 0, main.viewWidth, main.viewHeight); + GDXAppMain.INSTANCE.batch.begin(); + GDXAppMain.INSTANCE.batch.draw(backgroundImage, 0, 0, GDXAppMain.INSTANCE.viewWidth, GDXAppMain.INSTANCE.viewHeight); scrollDeltaTime += delta; if (scrollDeltaTime > 0.04f) { @@ -51,14 +50,14 @@ abstract public class AbstractScrollScreen extends GDXAppMainAdapter { String[] lines = scrollText.split("\n"); for (int i=lines.length;i>0;i--) { 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++; } - main.batch.end(); + GDXAppMain.INSTANCE.batch.end(); if (scrollText.length() >= 33) { - if (scrollLine >= main.viewHeight || Gdx.input.isTouched() || Gdx.input.isKeyPressed(Keys.ENTER) || Gdx.input.isKeyPressed(Keys.SPACE)) { - main.selectScreen(getNextScreen(main)); + if (scrollLine >=GDXAppMain.INSTANCE.viewHeight || Gdx.input.isTouched() || Gdx.input.isKeyPressed(Keys.ENTER) || Gdx.input.isKeyPressed(Keys.SPACE)) { + GDXAppMain.INSTANCE.selectScreen(getNextScreen(GDXAppMain.INSTANCE)); } } } diff --git a/main-gdxapp/src/main/love/distributedrebirth/gdxapp/screen/ScreenCredits.java b/main-gdxapp/src/main/love/distributedrebirth/gdxapp/screen/ScreenCredits.java index 139f374f..ccaff4c3 100644 --- a/main-gdxapp/src/main/love/distributedrebirth/gdxapp/screen/ScreenCredits.java +++ b/main-gdxapp/src/main/love/distributedrebirth/gdxapp/screen/ScreenCredits.java @@ -63,8 +63,8 @@ public class ScreenCredits extends AbstractScrollScreen { " " ); - public ScreenCredits(final GDXAppMain main) { - super(main, "background/doom-credits.png"); + public ScreenCredits() { + super("background/doom-credits.png"); } @Override @@ -79,11 +79,11 @@ public class ScreenCredits extends AbstractScrollScreen { @Override public void showScroll() { - main.music.play(MusicSongType.CREDITS); + GDXAppMain.INSTANCE.music.play(MusicSongType.CREDITS); } @Override public void hideScroll() { - main.music.play(MusicSongType.BACKGROUND); + GDXAppMain.INSTANCE.music.play(MusicSongType.BACKGROUND); } } diff --git a/main-gdxapp/src/main/love/distributedrebirth/gdxapp/screen/ScreenHelp.java b/main-gdxapp/src/main/love/distributedrebirth/gdxapp/screen/ScreenHelp.java index ad04d7fb..728934fb 100644 --- a/main-gdxapp/src/main/love/distributedrebirth/gdxapp/screen/ScreenHelp.java +++ b/main-gdxapp/src/main/love/distributedrebirth/gdxapp/screen/ScreenHelp.java @@ -46,8 +46,8 @@ public class ScreenHelp extends AbstractScrollScreen { " " ); - public ScreenHelp(final GDXAppMain main) { - super(main, "background/terrydavis-nose.png"); + public ScreenHelp() { + super("background/terrydavis-nose.png"); } @Override @@ -62,11 +62,11 @@ public class ScreenHelp extends AbstractScrollScreen { @Override public void showScroll() { - main.music.play(MusicSongType.INTRO); + GDXAppMain.INSTANCE.music.play(MusicSongType.INTRO); } @Override public void hideScroll() { - main.music.play(MusicSongType.BACKGROUND); + GDXAppMain.INSTANCE.music.play(MusicSongType.BACKGROUND); } } diff --git a/main-gdxapp/src/main/love/distributedrebirth/gdxapp/screen/ScreenIntro.java b/main-gdxapp/src/main/love/distributedrebirth/gdxapp/screen/ScreenIntro.java index c75b69ab..455942c8 100644 --- a/main-gdxapp/src/main/love/distributedrebirth/gdxapp/screen/ScreenIntro.java +++ b/main-gdxapp/src/main/love/distributedrebirth/gdxapp/screen/ScreenIntro.java @@ -12,13 +12,11 @@ import love.distributedrebirth.gdxapp.music.MusicSongType; @BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天") public class ScreenIntro extends ScreenAdapter { - private final GDXAppMain main; private Texture backgroundImage; private float colorDeltaTime = 0f; private boolean colorPositive = true; - public ScreenIntro(final GDXAppMain main) { - this.main = main; + public ScreenIntro() { 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); - main.batch.begin(); - main.batch.draw(backgroundImage, 0, 0, main.viewWidth, main.viewHeight); - main.font.draw(main.batch, "Tap anywhere to begin!", main.viewWidth/2 - 73, 33); - main.batch.end(); + GDXAppMain.INSTANCE.batch.begin(); + GDXAppMain.INSTANCE.batch.draw(backgroundImage, 0, 0, GDXAppMain.INSTANCE.viewWidth, GDXAppMain.INSTANCE.viewHeight); + GDXAppMain.INSTANCE.font.draw(GDXAppMain.INSTANCE.batch, "Tap anywhere to begin!", GDXAppMain.INSTANCE.viewWidth/2 - 73, 33); + GDXAppMain.INSTANCE.batch.end(); 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(); } } @Override public void show() { - main.music.play(MusicSongType.INTRO); + GDXAppMain.INSTANCE.music.play(MusicSongType.INTRO); } @Override diff --git a/main-gdxapp/src/main/love/distributedrebirth/gdxapp/screen/ScreenIntroMission.java b/main-gdxapp/src/main/love/distributedrebirth/gdxapp/screen/ScreenIntroMission.java index 213cdbae..b20c9cf6 100644 --- a/main-gdxapp/src/main/love/distributedrebirth/gdxapp/screen/ScreenIntroMission.java +++ b/main-gdxapp/src/main/love/distributedrebirth/gdxapp/screen/ScreenIntroMission.java @@ -56,8 +56,8 @@ public class ScreenIntroMission extends AbstractScrollScreen { - public ScreenIntroMission(final GDXAppMain main) { - super(main, "background/terrydavis-nose.png"); + public ScreenIntroMission() { + super("background/terrydavis-nose.png"); } @Override @@ -72,6 +72,6 @@ public class ScreenIntroMission extends AbstractScrollScreen { @Override public void hideScroll() { - main.music.play(MusicSongType.BACKGROUND); + GDXAppMain.INSTANCE.music.play(MusicSongType.BACKGROUND); } } diff --git a/main-gdxapp/src/main/love/distributedrebirth/gdxapp/screen/ScreenLoading.java b/main-gdxapp/src/main/love/distributedrebirth/gdxapp/screen/ScreenLoading.java index 9c4e5e0d..73b74e19 100644 --- a/main-gdxapp/src/main/love/distributedrebirth/gdxapp/screen/ScreenLoading.java +++ b/main-gdxapp/src/main/love/distributedrebirth/gdxapp/screen/ScreenLoading.java @@ -9,19 +9,17 @@ import love.distributedrebirth.gdxapp.GDXAppMain; @BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天") public class ScreenLoading extends ScreenAdapter { - private final GDXAppMain main; private Texture backgroundImage; - public ScreenLoading(final GDXAppMain main) { - this.main = main; + public ScreenLoading() { backgroundImage = new Texture(Gdx.files.internal("background/gdxapp-loading.png")); } @Override public void render(float delta) { - main.batch.begin(); - main.batch.draw(backgroundImage, 0, 0, main.viewWidth, main.viewHeight); - main.batch.end(); + GDXAppMain.INSTANCE.batch.begin(); + GDXAppMain.INSTANCE.batch.draw(backgroundImage, 0, 0, GDXAppMain.INSTANCE.viewWidth, GDXAppMain.INSTANCE.viewHeight); + GDXAppMain.INSTANCE.batch.end(); } @Override