Demo UI fixes and launch options

This commit is contained in:
Willem Cazander 2022-01-31 23:05:27 +01:00
parent 37175e0fee
commit 45879c1992
6 changed files with 125 additions and 64 deletions

View file

@ -18,6 +18,7 @@ import imgui.type.ImBoolean;
import love.distributedrebirth.demo4d.matrix4d.ScreenMatrix4D; import love.distributedrebirth.demo4d.matrix4d.ScreenMatrix4D;
import love.distributedrebirth.demo4d.music.MusicManager; import love.distributedrebirth.demo4d.music.MusicManager;
import love.distributedrebirth.demo4d.music.MusicPlayerRenderer; import love.distributedrebirth.demo4d.music.MusicPlayerRenderer;
import love.distributedrebirth.demo4d.music.MusicSongType;
import love.distributedrebirth.demo4d.screen.BasePartRenderer; import love.distributedrebirth.demo4d.screen.BasePartRenderer;
import love.distributedrebirth.demo4d.screen.BasicConsoleRenderer; import love.distributedrebirth.demo4d.screen.BasicConsoleRenderer;
import love.distributedrebirth.demo4d.screen.HebrewWalletRenderer; import love.distributedrebirth.demo4d.screen.HebrewWalletRenderer;
@ -40,8 +41,8 @@ public class Demo4DMain extends Game {
public SpriteBatch batch; public SpriteBatch batch;
public BitmapFont font; public BitmapFont font;
public OrthographicCamera camera; public OrthographicCamera camera;
public final int viewWidth = 800; public final int viewWidth;
public final int viewHeight = 600; public final int viewHeight;
public MusicManager music; public MusicManager music;
private Map<Class<? extends Screen>,Screen> screens; private Map<Class<? extends Screen>,Screen> screens;
@ -52,8 +53,10 @@ public class Demo4DMain extends Game {
private ImBoolean showBasePart = new ImBoolean(false); private ImBoolean showBasePart = new ImBoolean(false);
private ImBoolean showBasicConsole = new ImBoolean(false); private ImBoolean showBasicConsole = new ImBoolean(false);
public Demo4DMain(List<String> args, NativeFileChooser fileChooser) { public Demo4DMain(List<String> args, int viewWidth, int viewHeight, NativeFileChooser fileChooser) {
this.args = args; this.args = args;
this.viewWidth = viewWidth;
this.viewHeight = viewHeight;
this.fileChooser = fileChooser; this.fileChooser = fileChooser;
} }
@ -67,7 +70,7 @@ public class Demo4DMain extends Game {
batch.setProjectionMatrix(camera.combined); batch.setProjectionMatrix(camera.combined);
music = new MusicManager(); music = new MusicManager();
music.init(); music.init(args.contains("no-music"));
ImGuiSetup.init(); ImGuiSetup.init();
widgets = new HashMap<>(); widgets = new HashMap<>();
@ -85,11 +88,15 @@ public class Demo4DMain extends Game {
putScreen(new ScreenMatrix4D(this)); putScreen(new ScreenMatrix4D(this));
putScreen(new ScreenUnicode4D(this)); putScreen(new ScreenUnicode4D(this));
if (args.contains("default")) { if (args.contains("no-intro")) {
selectScreen(ScreenDefault.class); selectScreen(ScreenDefault.class);
music.play(MusicSongType.BACKGROUND);
} else { } else {
selectScreen(ScreenIntro.class); selectScreen(ScreenIntro.class);
} }
if (args.contains("full-screen")) {
Gdx.graphics.setFullscreenMode(Gdx.graphics.getDisplayMode());
}
} }
@Override @Override
@ -155,6 +162,16 @@ public class Demo4DMain extends Game {
private void renderMenu() { private void renderMenu() {
ImGui.beginMainMenuBar(); ImGui.beginMainMenuBar();
if (ImGui.beginMenu("Demo")) { 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")) { if (ImGui.menuItem("Matrix4D")) {
selectScreen(ScreenMatrix4D.class); selectScreen(ScreenMatrix4D.class);
} }
@ -186,9 +203,6 @@ public class Demo4DMain extends Game {
if (ImGui.menuItem("Music Player")) { if (ImGui.menuItem("Music Player")) {
showMusicPlayer.set(true); showMusicPlayer.set(true);
} }
if (ImGui.menuItem("Stop Music")) {
music.stop();
}
ImGui.endMenu(); ImGui.endMenu();
} }
if (ImGui.beginMenu("Help")) { if (ImGui.beginMenu("Help")) {
@ -218,6 +232,9 @@ public class Demo4DMain extends Game {
if (ScreenCredits.class.equals(screen.getClass())) { if (ScreenCredits.class.equals(screen.getClass())) {
return false; return false;
} }
if (ScreenHelp.class.equals(screen.getClass())) {
return false;
}
return true; return true;
} }
} }

View file

@ -20,6 +20,7 @@ public class MusicManager {
private final List<MusicSong> backgroundSongs; private final List<MusicSong> backgroundSongs;
private final NextSongListener nextSongListener; private final NextSongListener nextSongListener;
private MusicSong currentSong = null; private MusicSong currentSong = null;
private boolean noMusic = false;
public MusicManager() { public MusicManager() {
backgroundSongs = new ArrayList<>(); backgroundSongs = new ArrayList<>();
@ -34,7 +35,8 @@ public class MusicManager {
backgroundSongs.add(new MusicSong(music, file.name())); 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-risen.mp3"));
addBackgroundMusic(Gdx.files.internal("music/sanctumwave-devine-intellect.mp3")); addBackgroundMusic(Gdx.files.internal("music/sanctumwave-devine-intellect.mp3"));
addBackgroundMusic(Gdx.files.internal("music/theselfhelpgroup-temple-os.mp3")); addBackgroundMusic(Gdx.files.internal("music/theselfhelpgroup-temple-os.mp3"));
@ -53,12 +55,8 @@ public class MusicManager {
return backgroundSongs; return backgroundSongs;
} }
public String getCurrentSongName() { public MusicSong getCurrentSong() {
if (currentSong != null) { return currentSong;
return currentSong.getName();
} else {
return "None";
}
} }
public void stop() { public void stop() {
@ -71,8 +69,10 @@ public class MusicManager {
MusicSong nextSong = null; MusicSong nextSong = null;
if (MusicSongType.INTRO.equals(type)) { if (MusicSongType.INTRO.equals(type)) {
nextSong = introSong; nextSong = introSong;
play(nextSong);
} else if (MusicSongType.CREDITS.equals(type)) { } else if (MusicSongType.CREDITS.equals(type)) {
nextSong = creditsSong; nextSong = creditsSong;
play(nextSong);
} else { } else {
int currentBackground = backgroundSongs.indexOf(currentSong); int currentBackground = backgroundSongs.indexOf(currentSong);
if (currentBackground == -1) { if (currentBackground == -1) {
@ -80,9 +80,11 @@ public class MusicManager {
} else { } else {
nextSong = currentSong; nextSong = currentSong;
} }
} if (!noMusic) {
play(nextSong); play(nextSong);
} }
}
}
public void play(MusicSong song) { public void play(MusicSong song) {
if (song == null) { if (song == null) {

View file

@ -1,5 +1,7 @@
package love.distributedrebirth.demo4d.music; package love.distributedrebirth.demo4d.music;
import java.util.function.Consumer;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.files.FileHandle; import com.badlogic.gdx.files.FileHandle;
@ -21,8 +23,14 @@ import net.spookygames.gdx.nativefilechooser.NativeFileChooserConfiguration;
*/ */
public class MusicPlayerRenderer extends ImGuiRendererMain { public class MusicPlayerRenderer extends ImGuiRendererMain {
private final NativeFileChooserConfiguration fileChooserConfig;
public MusicPlayerRenderer(Demo4DMain main) { public MusicPlayerRenderer(Demo4DMain main) {
super(main); super(main);
fileChooserConfig = new NativeFileChooserConfiguration();
fileChooserConfig.directory = Gdx.files.absolute(System.getProperty("user.home"));
fileChooserConfig.mimeFilter = "audio/*";
fileChooserConfig.title = "Choose audio file";
} }
@Override @Override
@ -32,11 +40,14 @@ public class MusicPlayerRenderer extends ImGuiRendererMain {
ImGui.begin("Music Player", widgetOpen); ImGui.begin("Music Player", widgetOpen);
ImGui.text("Current Song:"); ImGui.text("Current Song:");
MusicSong currentSong = main.music.getCurrentSong();
if (currentSong != null) {
ImGui.sameLine(); ImGui.sameLine();
ImGui.text(main.music.getCurrentSongName()); ImGui.text(currentSong.getName());
}
ImGui.separator(); ImGui.separator();
if (ImGui.button("Play")) { if (ImGui.button("Play")) {
main.music.play(MusicSongType.BACKGROUND); main.music.play(currentSong);
} }
ImGui.sameLine(); ImGui.sameLine();
if (ImGui.button("<")) { if (ImGui.button("<")) {
@ -52,26 +63,7 @@ public class MusicPlayerRenderer extends ImGuiRendererMain {
} }
ImGui.sameLine(); ImGui.sameLine();
if (ImGui.button("Add")) { if (ImGui.button("Add")) {
NativeFileChooserConfiguration conf = new NativeFileChooserConfiguration(); main.fileChooser.chooseFile(fileChooserConfig, NativeFileChooserCallbackAdapter.onFileChosen(v -> main.music.addBackgroundMusic(v)));
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) {
}
});
} }
int flags = ImGuiTableFlags.ScrollX | ImGuiTableFlags.RowBg | ImGuiTableFlags.BordersOuter | ImGuiTableFlags.BordersV; int flags = ImGuiTableFlags.ScrollX | ImGuiTableFlags.RowBg | ImGuiTableFlags.BordersOuter | ImGuiTableFlags.BordersV;
ImGui.beginTable("playlist", 3, flags); ImGui.beginTable("playlist", 3, flags);
@ -98,4 +90,28 @@ public class MusicPlayerRenderer extends ImGuiRendererMain {
ImGui.end(); 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<FileHandle> eater) {
return new NativeFileChooserCallbackAdapter() {
@Override
public void onFileChosen(FileHandle file) {
eater.accept(file);
}
};
}
}
} }

View file

@ -3,6 +3,7 @@ package love.distributedrebirth.demo4d.screen;
import com.badlogic.gdx.Screen; import com.badlogic.gdx.Screen;
import love.distributedrebirth.demo4d.Demo4DMain; import love.distributedrebirth.demo4d.Demo4DMain;
import love.distributedrebirth.demo4d.music.MusicSongType;
/** /**
* *
@ -61,4 +62,14 @@ public class ScreenHelp extends ScrollScreenAdapter {
protected Class<? extends Screen> getNextScreen(Demo4DMain main) { protected Class<? extends Screen> getNextScreen(Demo4DMain main) {
return ScreenDefault.class; return ScreenDefault.class;
} }
@Override
public void show () {
main.music.play(MusicSongType.INTRO);
}
@Override
public void hide () {
main.music.play(MusicSongType.BACKGROUND);
}
} }

View file

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

View file

@ -4,6 +4,7 @@ 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;
@ -11,37 +12,23 @@ import love.distributedrebirth.demo4d.Demo4DMain;
import net.spookygames.gdx.nativefilechooser.desktop.DesktopFileChooser; import net.spookygames.gdx.nativefilechooser.desktop.DesktopFileChooser;
/** /**
* Desktop game app launcher.
* *
* @author willemtsade ©Δ 仙上主天 * @author willemtsade ©Δ 仙上主天
*
*/ */
public class DesktopLauncher { public class DesktopLauncher {
private static String WINDOW_TITLE = "demo⁴ᴰ"; public static void main(String[] arg) {
private static String[] WINDOW_ICONS = { DesktopConfig.printBootMessage();
"icon/window-128.png",
"icon/window-32.png",
"icon/window-16.png"
};
public static void main (String[] arg) {
printMessage();
List<String> args = Arrays.asList(arg);
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration(); Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
config.setMaxNetThreads(Runtime.getRuntime().availableProcessors()); config.setMaxNetThreads(Runtime.getRuntime().availableProcessors());
config.setTitle(WINDOW_TITLE); config.setTitle(DesktopConfig.WINDOW_TITLE);
config.setWindowedMode(800, 600); config.setWindowIcon(FileType.Internal, DesktopConfig.WINDOW_ICONS);
config.setWindowIcon(FileType.Internal, WINDOW_ICONS); config.setWindowedMode(DesktopConfig.WINDOW_WIDTH, DesktopConfig.WINDOW_HEIGHT);
new Lwjgl3Application(new Demo4DMain(args, new DesktopFileChooser()), config); List<String> args = Arrays.asList(arg);
} DesktopFileChooser aop0 = new DesktopFileChooser();
Game app = new Demo4DMain(args, DesktopConfig.WINDOW_WIDTH, DesktopConfig.WINDOW_HEIGHT, aop0);
private static void printMessage() { Lwjgl3Application launcher = new Lwjgl3Application(app, config);
System.out.println("=========================="); launcher.exit();
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...");
} }
} }