feat: basic gen loading

This commit is contained in:
2025-02-02 10:53:24 +01:00
parent 68021b796b
commit 4b98341618
3 changed files with 44 additions and 7 deletions

View File

@@ -78,4 +78,9 @@ public class MultiPlayerView extends BaseView {
renderGameStatus();
}
@Override
public void cleanResources() {
this.selector.clean();
}
}

View File

@@ -25,4 +25,9 @@ public class SoloMenu extends BaseView {
renderReturnButton();
}
@Override
public void cleanResources() {
this.sudokuSelector.clean();
}
}

View File

@@ -35,6 +35,8 @@ public class SudokuSelector {
private final String confirmMessage;
private Thread genThread = null;
public SudokuSelector(boolean canGenEmptyGrid, String confirmMessage) {
this.canGenEmptyGrid = canGenEmptyGrid;
this.confirmMessage = confirmMessage;
@@ -56,16 +58,36 @@ public class SudokuSelector {
}
}
private void stopGenThread() {
if (this.genThread != null) {
this.genThread.interrupt();
this.genThread = null;
}
}
private void renderGenProgress() {
if (ImGui.beginPopup("genProgress")) {
ImGui.text("Loading ...");
ImGui.endPopup();
} else {
stopGenThread();
}
}
private void selectSudoku(MultiDoku doku, boolean empty) {
this.doku = doku;
if (!empty) {
try {
SudokuFactory.fillDoku(doku, Difficulty.values()[difficulty.get()]);
} catch (Exception e) {
e.printStackTrace();
ImGui.openPopup("genProgress");
this.genThread = new Thread(() -> {
if (!empty) {
try {
SudokuFactory.fillDoku(doku, Difficulty.values()[difficulty.get()]);
this.onSelect.emit(this.doku);
} catch (Exception e) {
e.printStackTrace();
}
}
}
this.onSelect.emit(this.doku);
});
this.genThread.start();
}
public void renderFileDialog() {
@@ -131,7 +153,12 @@ public class SudokuSelector {
if (ImGui.button("À partir d'un fichier")) {
ImGuiFileDialog.openDialog("browse-sudoku", "Choisissez un fichier", ".json", ".");
}
renderGenProgress();
renderFileDialog();
}
public void clean() {
stopGenThread();
}
}