feat: basic gen loading
This commit is contained in:
@@ -78,4 +78,9 @@ public class MultiPlayerView extends BaseView {
|
||||
renderGameStatus();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanResources() {
|
||||
this.selector.clean();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,4 +25,9 @@ public class SoloMenu extends BaseView {
|
||||
renderReturnButton();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanResources() {
|
||||
this.sudokuSelector.clean();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user