add menu logic
Some checks failed
Linux arm64 / Build (push) Failing after 5m1s

This commit is contained in:
2025-01-23 12:50:00 +01:00
parent 48fc88d8ab
commit 749f5c831d
8 changed files with 145 additions and 15 deletions

View File

@@ -1,28 +1,18 @@
package gui;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Random;
import gui.ColorGenerator.Color;
import gui.menu.MainMenu;
import gui.menu.StateMachine;
import imgui.ImGui;
import imgui.ImVec2;
import imgui.ImVec4;
import imgui.app.Application;
import imgui.app.Configuration;
import imgui.flag.ImGuiCol;
import sudoku.Block;
import sudoku.Cell;
import sudoku.MultiDoku;
import sudoku.Sudoku;
import sudoku.SudokuFactory;
public class Main extends Application {
// temp thing
private static final int SUDOKU_SIZE = 4;
private static final int SUDOKU_SIZE = 3;
private final StateMachine stateMachine = new StateMachine();
private SudokuRenderer renderer;
@Override
@@ -36,11 +26,13 @@ public class Main extends Application {
ImGui.getIO().getFonts().addFontFromFileTTF("comic.ttf", 50.0f);
MultiDoku doku = SudokuFactory.createBasicEmptySquareSudoku(SUDOKU_SIZE);
renderer = new SudokuRenderer(doku.getSubGrid(0));
stateMachine.pushState(new MainMenu(stateMachine));
}
@Override
public void process() {
renderer.render();
stateMachine.render();
ImGui.showDemoWindow();
}

View File

@@ -9,6 +9,7 @@ import imgui.ImGui;
import imgui.ImVec2;
import imgui.ImVec4;
import imgui.flag.ImGuiCol;
import imgui.flag.ImGuiStyleVar;
import sudoku.Block;
import sudoku.Cell;
import sudoku.Sudoku;
@@ -58,11 +59,16 @@ public class SudokuRenderer {
Cell cell = sudoku.getCell(x, y);
int symbol = cell.getSymbolIndex();
Color blockColor = colorPalette.get(cell.getBlock());
ImGui.pushStyleVar(ImGuiStyleVar.SelectableTextAlign, new ImVec2(0.5f, 0.5f));
ImGui.pushStyleColor(ImGuiCol.Header, new ImVec4(blockColor.r, blockColor.g, blockColor.b, 1.0f));
if (ImGui.selectable(Integer.toString(symbol + 1) + "##" + index, true, 0, new ImVec2(50, 50))) {
String cellText = "";
if (symbol != -1)
cellText += Integer.toString(symbol + 1);
if (ImGui.selectable(cellText + "##" + index, true, 0, new ImVec2(50, 50))) {
ImGui.openPopup("editPopup");
currentIndex = index;
}
ImGui.popStyleVar();
ImGui.popStyleColor();
}
}

View File

@@ -0,0 +1,25 @@
package gui.menu;
import imgui.ImGui;
public abstract class BaseMenu {
protected final StateMachine stateMachine;
public BaseMenu(StateMachine stateMachine) {
this.stateMachine = stateMachine;
}
public abstract void render();
public void closeMenu() {
this.stateMachine.popState();
}
protected void renderReturnButton() {
if (ImGui.button("Retour")) {
closeMenu();
}
}
}

View File

@@ -0,0 +1,24 @@
package gui.menu;
import imgui.ImGui;
public class MainMenu extends BaseMenu {
public MainMenu(StateMachine stateMachine) {
super(stateMachine);
}
@Override
public void render() {
if (ImGui.button("Mode histoire")) {
this.stateMachine.pushState(new SoloMenu(this.stateMachine));
}
if (ImGui.button("Multijoueur")) {
this.stateMachine.pushState(new MultiMenu(this.stateMachine));
}
if (ImGui.button("Options")) {
this.stateMachine.pushState(new OptionsMenu(this.stateMachine));
}
}
}

View File

@@ -0,0 +1,18 @@
package gui.menu;
import imgui.ImGui;
public class MultiMenu extends BaseMenu {
public MultiMenu(StateMachine stateMachine) {
super(stateMachine);
}
@Override
public void render() {
// TODO Auto-generated method stub
ImGui.text("Multi");
renderReturnButton();
}
}

View File

@@ -0,0 +1,18 @@
package gui.menu;
import imgui.ImGui;
public class OptionsMenu extends BaseMenu {
public OptionsMenu(StateMachine stateMachine) {
super(stateMachine);
}
@Override
public void render() {
// TODO Auto-generated method stub
ImGui.text("Options");
renderReturnButton();
}
}

View File

@@ -0,0 +1,18 @@
package gui.menu;
import imgui.ImGui;
public class SoloMenu extends BaseMenu {
public SoloMenu(StateMachine stateMachine) {
super(stateMachine);
}
@Override
public void render() {
// TODO Auto-generated method stub
ImGui.text("Solo");
renderReturnButton();
}
}

View File

@@ -0,0 +1,29 @@
package gui.menu;
import java.util.Stack;
import imgui.ImGui;
public class StateMachine {
private final Stack<BaseMenu> menus;
public StateMachine() {
this.menus = new Stack<>();
}
public void pushState(BaseMenu menu) {
menus.add(menu);
}
public void popState() {
menus.pop();
}
public void render() {
ImGui.begin("##Main Window");
menus.getLast().render();
ImGui.end();
}
}