feat: basic gen loading
This commit is contained in:
@@ -78,4 +78,9 @@ public class MultiPlayerView extends BaseView {
|
|||||||
renderGameStatus();
|
renderGameStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cleanResources() {
|
||||||
|
this.selector.clean();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,4 +25,9 @@ public class SoloMenu extends BaseView {
|
|||||||
renderReturnButton();
|
renderReturnButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cleanResources() {
|
||||||
|
this.sudokuSelector.clean();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ public class SudokuSelector {
|
|||||||
|
|
||||||
private final String confirmMessage;
|
private final String confirmMessage;
|
||||||
|
|
||||||
|
private Thread genThread = null;
|
||||||
|
|
||||||
public SudokuSelector(boolean canGenEmptyGrid, String confirmMessage) {
|
public SudokuSelector(boolean canGenEmptyGrid, String confirmMessage) {
|
||||||
this.canGenEmptyGrid = canGenEmptyGrid;
|
this.canGenEmptyGrid = canGenEmptyGrid;
|
||||||
this.confirmMessage = confirmMessage;
|
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) {
|
private void selectSudoku(MultiDoku doku, boolean empty) {
|
||||||
this.doku = doku;
|
this.doku = doku;
|
||||||
if (!empty) {
|
ImGui.openPopup("genProgress");
|
||||||
try {
|
this.genThread = new Thread(() -> {
|
||||||
SudokuFactory.fillDoku(doku, Difficulty.values()[difficulty.get()]);
|
if (!empty) {
|
||||||
} catch (Exception e) {
|
try {
|
||||||
e.printStackTrace();
|
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() {
|
public void renderFileDialog() {
|
||||||
@@ -131,7 +153,12 @@ public class SudokuSelector {
|
|||||||
if (ImGui.button("À partir d'un fichier")) {
|
if (ImGui.button("À partir d'un fichier")) {
|
||||||
ImGuiFileDialog.openDialog("browse-sudoku", "Choisissez un fichier", ".json", ".");
|
ImGuiFileDialog.openDialog("browse-sudoku", "Choisissez un fichier", ".json", ".");
|
||||||
}
|
}
|
||||||
|
renderGenProgress();
|
||||||
renderFileDialog();
|
renderFileDialog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void clean() {
|
||||||
|
stopGenThread();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user