Refactored to instance code

This commit is contained in:
Willem Cazander 2022-02-17 22:00:22 +01:00
parent 458ab90f24
commit e1f67db17c
3 changed files with 26 additions and 29 deletions

View file

@ -184,7 +184,7 @@ public enum GDXAppMain implements DefaultEnumInstanceᴶᴹˣ<GDXAppMain,GDXAppM
DeskTopScreen desktop2 = new ScreenDesktop2(this);
DeskTopScreen desktop3 = new ScreenDesktop3();
DeskTopScreen desktop4 = new ScreenDesktop4();
screenMenu = new DeskTopScreenMenu(this, desktop1, desktop2, desktop3, desktop4);
screenMenu = new DeskTopScreenMenu(desktop1, desktop2, desktop3, desktop4);
putScreen(new ScreenLoading());
putScreen(new ScreenIntro());

View file

@ -26,7 +26,6 @@ import love.distributedrebirth.gdxapp.screen.ScreenHelp;
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
public class DeskTopScreenMenu {
private final GDXAppMain main;
private final DeskTopScreen desktop1;
private final DeskTopScreen desktop2;
private final DeskTopScreen desktop3;
@ -35,9 +34,8 @@ public class DeskTopScreenMenu {
private ImBoolean fileMinimizeSelected = new ImBoolean(false);
private ImBoolean fileCloseSelected = new ImBoolean(false);
public DeskTopScreenMenu(final GDXAppMain main, DeskTopScreen desktop1, DeskTopScreen desktop2,
public DeskTopScreenMenu(DeskTopScreen desktop1, DeskTopScreen desktop2,
DeskTopScreen desktop3, DeskTopScreen desktop4) {
this.main = main;
this.desktop1 = desktop1;
this.desktop2 = desktop2;
this.desktop3 = desktop3;
@ -49,7 +47,7 @@ public class DeskTopScreenMenu {
apps.add(new GDXAppLauncher("Base Parts", () -> new SystemBasePartApp()));
apps.add(new GDXAppLauncher("Hebrew Wallet", () -> new HebrewWalletApp()));
apps.add(new GDXAppLauncher("Unicode4D", () -> new Unicode4DApp()));
apps.add(new GDXAppLauncher("Music Player", () -> new MusicPlayerApp(main)));
apps.add(new GDXAppLauncher("Music Player", () -> new MusicPlayerApp()));
}
public void renderMenu(DeskTopScreen appScreen) {
@ -184,12 +182,12 @@ public class DeskTopScreenMenu {
}
if (ImGui.beginMenu(infix1+"Desktop1")) {
if (ImGui.menuItem("Main reality")) {
main.selectScreen(ScreenDesktop1.class);
GDXAppMain.INSTANCE.selectScreen(ScreenDesktop1.class);
desktop1.getDeskAppScreen().setCurrentDeskApp(null);
}
for (DeskApp app: desktop1.getDeskAppScreen().getDeskApps()) {
if (ImGui.menuItem(app.getTitle())) {
main.selectScreen(ScreenDesktop1.class);
GDXAppMain.INSTANCE.selectScreen(ScreenDesktop1.class);
desktop1.getDeskAppScreen().setCurrentDeskApp(app);
}
}
@ -197,12 +195,12 @@ public class DeskTopScreenMenu {
}
if (ImGui.beginMenu(infix2+"Desktop2")) {
if (ImGui.menuItem("Main reality")) {
main.selectScreen(ScreenDesktop2.class);
GDXAppMain.INSTANCE.selectScreen(ScreenDesktop2.class);
desktop2.getDeskAppScreen().setCurrentDeskApp(null);
}
for (DeskApp app: desktop2.getDeskAppScreen().getDeskApps()) {
if (ImGui.menuItem(app.getTitle())) {
main.selectScreen(ScreenDesktop2.class);
GDXAppMain.INSTANCE.selectScreen(ScreenDesktop2.class);
desktop2.getDeskAppScreen().setCurrentDeskApp(app);
}
}
@ -210,12 +208,12 @@ public class DeskTopScreenMenu {
}
if (ImGui.beginMenu(infix3+"Desktop3")) {
if (ImGui.menuItem("Main reality")) {
main.selectScreen(ScreenDesktop3.class);
GDXAppMain.INSTANCE.selectScreen(ScreenDesktop3.class);
desktop3.getDeskAppScreen().setCurrentDeskApp(null);
}
for (DeskApp app: desktop3.getDeskAppScreen().getDeskApps()) {
if (ImGui.menuItem(app.getTitle())) {
main.selectScreen(ScreenDesktop3.class);
GDXAppMain.INSTANCE.selectScreen(ScreenDesktop3.class);
desktop3.getDeskAppScreen().setCurrentDeskApp(app);
}
}
@ -223,12 +221,12 @@ public class DeskTopScreenMenu {
}
if (ImGui.beginMenu(infix4+"Desktop4")) {
if (ImGui.menuItem("Main reality")) {
main.selectScreen(ScreenDesktop4.class);
GDXAppMain.INSTANCE.selectScreen(ScreenDesktop4.class);
desktop4.getDeskAppScreen().setCurrentDeskApp(null);
}
for (DeskApp app: desktop4.getDeskAppScreen().getDeskApps()) {
if (ImGui.menuItem(app.getTitle())) {
main.selectScreen(ScreenDesktop4.class);
GDXAppMain.INSTANCE.selectScreen(ScreenDesktop4.class);
desktop4.getDeskAppScreen().setCurrentDeskApp(app);
}
}
@ -248,7 +246,7 @@ public class DeskTopScreenMenu {
ImGui.separator();
if (Gdx.graphics.isFullscreen()) {
if (ImGui.menuItem("Window Mode")) {
Gdx.graphics.setWindowedMode(main.viewWidth, main.viewHeight);
Gdx.graphics.setWindowedMode(GDXAppMain.INSTANCE.viewWidth, GDXAppMain.INSTANCE.viewHeight);
}
} else {
if (ImGui.menuItem("Full Screen")) {
@ -257,17 +255,17 @@ public class DeskTopScreenMenu {
}
ImGui.separator();
if (ImGui.menuItem("Credits")) {
main.selectScreen(ScreenCredits.class);
GDXAppMain.INSTANCE.selectScreen(ScreenCredits.class);
}
if (ImGui.menuItem("Help")) {
main.selectScreen(ScreenHelp.class);
GDXAppMain.INSTANCE.selectScreen(ScreenHelp.class);
}
ImGui.separator();
if (ImGui.menuItem("ImGui Demo")) {
main.showImGuiDemo.set(true);
GDXAppMain.INSTANCE.showImGuiDemo.set(true);
}
if (ImGui.menuItem("Shutdown")) {
main.dispose();
GDXAppMain.INSTANCE.dispose();
System.exit(0);
}
ImGui.endMenu();

View file

@ -24,10 +24,9 @@ import net.spookygames.gdx.nativefilechooser.NativeFileChooserConfiguration;
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
public class MusicPlayerApp extends DefaultDeskApp implements DeskAppRenderer {
private final GDXAppMain main;
private final NativeFileChooserConfiguration fileChooserConfig;
public MusicPlayerApp(GDXAppMain main) {
public MusicPlayerApp() {
setTitle("Music Player");
getContours().registrateContour(DeskAppContourSection.MAIN, this);
getContours().registrateContour(DeskAppContourSection.FILE_NEW, new DeskAppRenderer() {
@ -35,12 +34,12 @@ public class MusicPlayerApp extends DefaultDeskApp implements DeskAppRenderer {
@Override
public void render() {
if (ImGui.menuItem("Add")) {
main.fileChooser.chooseFile(fileChooserConfig, NativeFileChooserCallbackAdapter.onFileChosen(v -> main.music.addBackgroundMusic(v)));
GDXAppMain.INSTANCE.fileChooser.chooseFile(fileChooserConfig,
NativeFileChooserCallbackAdapter.onFileChosen(v -> GDXAppMain.INSTANCE.music.addBackgroundMusic(v)));
}
}
});
this.main = main;
fileChooserConfig = new NativeFileChooserConfiguration();
fileChooserConfig.directory = Gdx.files.absolute(System.getProperty("user.home"));
fileChooserConfig.mimeFilter = "audio/*";
@ -50,7 +49,7 @@ public class MusicPlayerApp extends DefaultDeskApp implements DeskAppRenderer {
@Override
public void render() {
ImGui.text("Current Song:");
MusicSong currentSong = main.music.getCurrentSong();
MusicSong currentSong = GDXAppMain.INSTANCE.music.getCurrentSong();
if (currentSong != null) {
ImGui.sameLine();
ImGui.text(currentSong.getName());
@ -58,22 +57,22 @@ public class MusicPlayerApp extends DefaultDeskApp implements DeskAppRenderer {
ImGui.separator();
if (currentSong != null) {
if (ImGui.button("Play")) {
main.music.play(currentSong);
GDXAppMain.INSTANCE.music.play(currentSong);
}
} else {
ImGui.text("Play");
}
ImGui.sameLine();
if (ImGui.button("<")) {
main.music.prev();
GDXAppMain.INSTANCE.music.prev();
}
ImGui.sameLine();
if (ImGui.button(">")) {
main.music.next();
GDXAppMain.INSTANCE.music.next();
}
ImGui.sameLine();
if (ImGui.button("Stop")) {
main.music.stop();
GDXAppMain.INSTANCE.music.stop();
}
int flags = ImGuiTableFlags.ScrollX | ImGuiTableFlags.RowBg | ImGuiTableFlags.BordersOuter | ImGuiTableFlags.BordersV;
ImGui.beginTable("playlist", 3, flags);
@ -82,14 +81,14 @@ public class MusicPlayerApp extends DefaultDeskApp implements DeskAppRenderer {
ImGui.tableSetupColumn("Name");
ImGui.tableHeadersRow();
int i=1;
for (MusicSong song:main.music.getBackgroundSongs()) {
for (MusicSong song:GDXAppMain.INSTANCE.music.getBackgroundSongs()) {
ImGui.pushID(i);
ImGui.tableNextRow();
ImGui.tableNextColumn();
ImGui.selectable(""+i, song.isPlaying(), ImGuiSelectableFlags.None);
ImGui.tableNextColumn();
if (ImGui.smallButton(">")) {
main.music.play(song);
GDXAppMain.INSTANCE.music.play(song);
}
ImGui.tableNextColumn();
ImGui.selectable(song.getName(), song.isPlaying(), ImGuiSelectableFlags.None);