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 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<String> 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();
}
}

View file

@ -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ᴶᴹˣ<GDXAppMain,GDXAppMainKeyʸᴰ>,ApplicationListener {
INSTANCE;
protected Screen screen;
private int lazyIntCnt = 33;
private List<String> 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<Class<? extends Screen>,Screen> screens;
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.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<? 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() {
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<? extends Screen> 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();
}
}

View file

@ -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 enum GDXAppMainKeyʸᴰ implements BãßBȍőnCoffinStoreKeyʸᴰ {
public GDXAppMainAdapter(GDXAppMain main) {
this.main = main;
}
JMX,
;
}

View file

@ -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));
}
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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

View file

@ -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);
}
}

View file

@ -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