From 45879c1992a9ca3d1408dcce7e335617b1bab3e2 Mon Sep 17 00:00:00 2001 From: Willem Cazander Date: Mon, 31 Jan 2022 23:05:27 +0100 Subject: [PATCH] Demo UI fixes and launch options --- .../distributedrebirth/demo4d/Demo4DMain.java | 33 +++++++--- .../demo4d/music/MusicManager.java | 18 +++--- .../demo4d/music/MusicPlayerRenderer.java | 62 ++++++++++++------- .../demo4d/screen/ScreenHelp.java | 11 ++++ .../demo4d/desktop/DesktopConfig.java | 28 +++++++++ .../demo4d/desktop/DesktopLauncher.java | 37 ++++------- 6 files changed, 125 insertions(+), 64 deletions(-) create mode 100644 desktop/src/love/distributedrebirth/demo4d/desktop/DesktopConfig.java diff --git a/core/src/love/distributedrebirth/demo4d/Demo4DMain.java b/core/src/love/distributedrebirth/demo4d/Demo4DMain.java index 7e099e46..510c2939 100644 --- a/core/src/love/distributedrebirth/demo4d/Demo4DMain.java +++ b/core/src/love/distributedrebirth/demo4d/Demo4DMain.java @@ -18,6 +18,7 @@ import imgui.type.ImBoolean; import love.distributedrebirth.demo4d.matrix4d.ScreenMatrix4D; import love.distributedrebirth.demo4d.music.MusicManager; import love.distributedrebirth.demo4d.music.MusicPlayerRenderer; +import love.distributedrebirth.demo4d.music.MusicSongType; import love.distributedrebirth.demo4d.screen.BasePartRenderer; import love.distributedrebirth.demo4d.screen.BasicConsoleRenderer; import love.distributedrebirth.demo4d.screen.HebrewWalletRenderer; @@ -40,8 +41,8 @@ public class Demo4DMain extends Game { public SpriteBatch batch; public BitmapFont font; public OrthographicCamera camera; - public final int viewWidth = 800; - public final int viewHeight = 600; + public final int viewWidth; + public final int viewHeight; public MusicManager music; private Map,Screen> screens; @@ -52,8 +53,10 @@ public class Demo4DMain extends Game { private ImBoolean showBasePart = new ImBoolean(false); private ImBoolean showBasicConsole = new ImBoolean(false); - public Demo4DMain(List args, NativeFileChooser fileChooser) { + public Demo4DMain(List args, int viewWidth, int viewHeight, NativeFileChooser fileChooser) { this.args = args; + this.viewWidth = viewWidth; + this.viewHeight = viewHeight; this.fileChooser = fileChooser; } @@ -67,7 +70,7 @@ public class Demo4DMain extends Game { batch.setProjectionMatrix(camera.combined); music = new MusicManager(); - music.init(); + music.init(args.contains("no-music")); ImGuiSetup.init(); widgets = new HashMap<>(); @@ -85,11 +88,15 @@ public class Demo4DMain extends Game { putScreen(new ScreenMatrix4D(this)); putScreen(new ScreenUnicode4D(this)); - if (args.contains("default")) { + if (args.contains("no-intro")) { selectScreen(ScreenDefault.class); + music.play(MusicSongType.BACKGROUND); } else { selectScreen(ScreenIntro.class); } + if (args.contains("full-screen")) { + Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode()); + } } @Override @@ -155,6 +162,16 @@ public class Demo4DMain extends Game { private void renderMenu() { ImGui.beginMainMenuBar(); if (ImGui.beginMenu("Demo")) { + if (Gdx.graphics.isFullscreen()) { + if (ImGui.menuItem("Window Mode")) { + Gdx.graphics.setWindowedMode(viewWidth, viewHeight); + } + } else { + if (ImGui.menuItem("Full Screen")) { + Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode()); + } + } + ImGui.separator(); if (ImGui.menuItem("Matrix4D")) { selectScreen(ScreenMatrix4D.class); } @@ -186,9 +203,6 @@ public class Demo4DMain extends Game { if (ImGui.menuItem("Music Player")) { showMusicPlayer.set(true); } - if (ImGui.menuItem("Stop Music")) { - music.stop(); - } ImGui.endMenu(); } if (ImGui.beginMenu("Help")) { @@ -218,6 +232,9 @@ public class Demo4DMain extends Game { if (ScreenCredits.class.equals(screen.getClass())) { return false; } + if (ScreenHelp.class.equals(screen.getClass())) { + return false; + } return true; } } diff --git a/core/src/love/distributedrebirth/demo4d/music/MusicManager.java b/core/src/love/distributedrebirth/demo4d/music/MusicManager.java index dbdc20e9..d1a30095 100644 --- a/core/src/love/distributedrebirth/demo4d/music/MusicManager.java +++ b/core/src/love/distributedrebirth/demo4d/music/MusicManager.java @@ -20,6 +20,7 @@ public class MusicManager { private final List backgroundSongs; private final NextSongListener nextSongListener; private MusicSong currentSong = null; + private boolean noMusic = false; public MusicManager() { backgroundSongs = new ArrayList<>(); @@ -34,7 +35,8 @@ public class MusicManager { backgroundSongs.add(new MusicSong(music, file.name())); } - public void init() { + public void init(boolean noMusic) { + this.noMusic = noMusic; addBackgroundMusic(Gdx.files.internal("music/sanctumwave-risen.mp3")); addBackgroundMusic(Gdx.files.internal("music/sanctumwave-devine-intellect.mp3")); addBackgroundMusic(Gdx.files.internal("music/theselfhelpgroup-temple-os.mp3")); @@ -53,12 +55,8 @@ public class MusicManager { return backgroundSongs; } - public String getCurrentSongName() { - if (currentSong != null) { - return currentSong.getName(); - } else { - return "None"; - } + public MusicSong getCurrentSong() { + return currentSong; } public void stop() { @@ -71,8 +69,10 @@ public class MusicManager { MusicSong nextSong = null; if (MusicSongType.INTRO.equals(type)) { nextSong = introSong; + play(nextSong); } else if (MusicSongType.CREDITS.equals(type)) { nextSong = creditsSong; + play(nextSong); } else { int currentBackground = backgroundSongs.indexOf(currentSong); if (currentBackground == -1) { @@ -80,8 +80,10 @@ public class MusicManager { } else { nextSong = currentSong; } + if (!noMusic) { + play(nextSong); + } } - play(nextSong); } public void play(MusicSong song) { diff --git a/core/src/love/distributedrebirth/demo4d/music/MusicPlayerRenderer.java b/core/src/love/distributedrebirth/demo4d/music/MusicPlayerRenderer.java index d38cfecf..7e1c3e5b 100644 --- a/core/src/love/distributedrebirth/demo4d/music/MusicPlayerRenderer.java +++ b/core/src/love/distributedrebirth/demo4d/music/MusicPlayerRenderer.java @@ -1,5 +1,7 @@ package love.distributedrebirth.demo4d.music; +import java.util.function.Consumer; + import com.badlogic.gdx.Gdx; import com.badlogic.gdx.files.FileHandle; @@ -21,8 +23,14 @@ import net.spookygames.gdx.nativefilechooser.NativeFileChooserConfiguration; */ public class MusicPlayerRenderer extends ImGuiRendererMain { + private final NativeFileChooserConfiguration fileChooserConfig; + public MusicPlayerRenderer(Demo4DMain main) { super(main); + fileChooserConfig = new NativeFileChooserConfiguration(); + fileChooserConfig.directory = Gdx.files.absolute(System.getProperty("user.home")); + fileChooserConfig.mimeFilter = "audio/*"; + fileChooserConfig.title = "Choose audio file"; } @Override @@ -32,11 +40,14 @@ public class MusicPlayerRenderer extends ImGuiRendererMain { ImGui.begin("Music Player", widgetOpen); ImGui.text("Current Song:"); - ImGui.sameLine(); - ImGui.text(main.music.getCurrentSongName()); + MusicSong currentSong = main.music.getCurrentSong(); + if (currentSong != null) { + ImGui.sameLine(); + ImGui.text(currentSong.getName()); + } ImGui.separator(); if (ImGui.button("Play")) { - main.music.play(MusicSongType.BACKGROUND); + main.music.play(currentSong); } ImGui.sameLine(); if (ImGui.button("<")) { @@ -52,26 +63,7 @@ public class MusicPlayerRenderer extends ImGuiRendererMain { } ImGui.sameLine(); if (ImGui.button("Add")) { - NativeFileChooserConfiguration conf = new NativeFileChooserConfiguration(); - conf.directory = Gdx.files.absolute(System.getProperty("user.home")); - conf.mimeFilter = "audio/*"; - conf.title = "Choose audio file"; - main.fileChooser.chooseFile(conf, new NativeFileChooserCallback() { - - @Override - public void onFileChosen(FileHandle file) { - main.music.addBackgroundMusic(file); - } - - @Override - public void onCancellation() { - } - - @Override - public void onError(Exception exception) { - } - }); - + main.fileChooser.chooseFile(fileChooserConfig, NativeFileChooserCallbackAdapter.onFileChosen(v -> main.music.addBackgroundMusic(v))); } int flags = ImGuiTableFlags.ScrollX | ImGuiTableFlags.RowBg | ImGuiTableFlags.BordersOuter | ImGuiTableFlags.BordersV; ImGui.beginTable("playlist", 3, flags); @@ -98,4 +90,28 @@ public class MusicPlayerRenderer extends ImGuiRendererMain { ImGui.end(); } + + static class NativeFileChooserCallbackAdapter implements NativeFileChooserCallback { + + @Override + public void onFileChosen(FileHandle file) { + } + + @Override + public void onCancellation() { + } + + @Override + public void onError(Exception exception) { + } + + static NativeFileChooserCallbackAdapter onFileChosen(Consumer eater) { + return new NativeFileChooserCallbackAdapter() { + @Override + public void onFileChosen(FileHandle file) { + eater.accept(file); + } + }; + } + } } diff --git a/core/src/love/distributedrebirth/demo4d/screen/ScreenHelp.java b/core/src/love/distributedrebirth/demo4d/screen/ScreenHelp.java index 69c4a758..6486e5a7 100644 --- a/core/src/love/distributedrebirth/demo4d/screen/ScreenHelp.java +++ b/core/src/love/distributedrebirth/demo4d/screen/ScreenHelp.java @@ -3,6 +3,7 @@ package love.distributedrebirth.demo4d.screen; import com.badlogic.gdx.Screen; import love.distributedrebirth.demo4d.Demo4DMain; +import love.distributedrebirth.demo4d.music.MusicSongType; /** * @@ -61,4 +62,14 @@ public class ScreenHelp extends ScrollScreenAdapter { protected Class getNextScreen(Demo4DMain main) { return ScreenDefault.class; } + + @Override + public void show () { + main.music.play(MusicSongType.INTRO); + } + + @Override + public void hide () { + main.music.play(MusicSongType.BACKGROUND); + } } diff --git a/desktop/src/love/distributedrebirth/demo4d/desktop/DesktopConfig.java b/desktop/src/love/distributedrebirth/demo4d/desktop/DesktopConfig.java new file mode 100644 index 00000000..1d6485bc --- /dev/null +++ b/desktop/src/love/distributedrebirth/demo4d/desktop/DesktopConfig.java @@ -0,0 +1,28 @@ +package love.distributedrebirth.demo4d.desktop; + +/** + * Desktop game app base config. + * + * @author willemtsade ©Δ∞ 仙上主天 + */ +public final class DesktopConfig { + + public static int WINDOW_WIDTH = 1024; + public static int WINDOW_HEIGHT = 768; + public static String WINDOW_TITLE = "demo⁴ᴰ"; + public static String[] WINDOW_ICONS = { + "icon/window-128.png", + "icon/window-32.png", + "icon/window-16.png" + }; + + public static void printBootMessage() { + System.out.println("=========================="); + System.out.println(" @Ω\u4ed9⁴ ˧꜏⋇꜊꜔ ⁴ﷲΩ@ "); + System.out.println(" ©Δ∞ 仙上主天 "); + System.out.println("בְּרֵאשִׁית :o: יְסוֺד :o: יִשְׂרָאֵל"); + System.out.println("=========================="); + System.out.println("Welcome to the matrix;"); + System.out.println("Starting demo⁴ᴰ now..."); + } +} diff --git a/desktop/src/love/distributedrebirth/demo4d/desktop/DesktopLauncher.java b/desktop/src/love/distributedrebirth/demo4d/desktop/DesktopLauncher.java index 78de47cc..d5b476b9 100644 --- a/desktop/src/love/distributedrebirth/demo4d/desktop/DesktopLauncher.java +++ b/desktop/src/love/distributedrebirth/demo4d/desktop/DesktopLauncher.java @@ -4,6 +4,7 @@ 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; @@ -11,37 +12,23 @@ import love.distributedrebirth.demo4d.Demo4DMain; import net.spookygames.gdx.nativefilechooser.desktop.DesktopFileChooser; /** + * Desktop game app launcher. * * @author willemtsade ©Δ∞ 仙上主天 - * */ public class DesktopLauncher { - private static String WINDOW_TITLE = "demo⁴ᴰ"; - private static String[] WINDOW_ICONS = { - "icon/window-128.png", - "icon/window-32.png", - "icon/window-16.png" - }; - - public static void main (String[] arg) { - printMessage(); - List args = Arrays.asList(arg); + public static void main(String[] arg) { + DesktopConfig.printBootMessage(); Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration(); config.setMaxNetThreads(Runtime.getRuntime().availableProcessors()); - config.setTitle(WINDOW_TITLE); - config.setWindowedMode(800, 600); - config.setWindowIcon(FileType.Internal, WINDOW_ICONS); - new Lwjgl3Application(new Demo4DMain(args, new DesktopFileChooser()), config); - } - - private static void printMessage() { - System.out.println("=========================="); - System.out.println(" @Ω\u4ed9⁴ ˧꜏⋇꜊꜔ ⁴ﷲΩ@ "); - System.out.println(" ©Δ∞ 仙上主天 "); - System.out.println("בְּרֵאשִׁית :o: יְסוֺד :o: יִשְׂרָאֵל"); - System.out.println("=========================="); - System.out.println("Welcome to the matrix;"); - System.out.println("Starting demo⁴ᴰ now..."); + config.setTitle(DesktopConfig.WINDOW_TITLE); + config.setWindowIcon(FileType.Internal, DesktopConfig.WINDOW_ICONS); + config.setWindowedMode(DesktopConfig.WINDOW_WIDTH, DesktopConfig.WINDOW_HEIGHT); + List args = Arrays.asList(arg); + DesktopFileChooser aop0 = new DesktopFileChooser(); + Game app = new Demo4DMain(args, DesktopConfig.WINDOW_WIDTH, DesktopConfig.WINDOW_HEIGHT, aop0); + Lwjgl3Application launcher = new Lwjgl3Application(app, config); + launcher.exit(); } }