This commit is contained in:
@@ -5,15 +5,10 @@ import gui.menu.StateMachine;
|
|||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
import imgui.app.Application;
|
import imgui.app.Application;
|
||||||
import imgui.app.Configuration;
|
import imgui.app.Configuration;
|
||||||
import sudoku.MultiDoku;
|
|
||||||
import sudoku.SudokuFactory;
|
|
||||||
|
|
||||||
public class Main extends Application {
|
public class Main extends Application {
|
||||||
|
|
||||||
// temp thing
|
|
||||||
private static final int SUDOKU_SIZE = 3;
|
|
||||||
private final StateMachine stateMachine = new StateMachine();
|
private final StateMachine stateMachine = new StateMachine();
|
||||||
private SudokuRenderer renderer;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void configure(Configuration config) {
|
protected void configure(Configuration config) {
|
||||||
@@ -24,16 +19,13 @@ public class Main extends Application {
|
|||||||
protected void initImGui(Configuration config) {
|
protected void initImGui(Configuration config) {
|
||||||
super.initImGui(config);
|
super.initImGui(config);
|
||||||
ImGui.getIO().getFonts().addFontFromFileTTF("comic.ttf", 50.0f);
|
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));
|
stateMachine.pushState(new MainMenu(stateMachine));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void process() {
|
public void process() {
|
||||||
renderer.render();
|
|
||||||
stateMachine.render();
|
stateMachine.render();
|
||||||
ImGui.showDemoWindow();
|
// ImGui.showDemoWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ package gui.menu;
|
|||||||
|
|
||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
|
|
||||||
public abstract class BaseMenu {
|
public abstract class BaseView {
|
||||||
|
|
||||||
protected final StateMachine stateMachine;
|
protected final StateMachine stateMachine;
|
||||||
|
|
||||||
public BaseMenu(StateMachine stateMachine) {
|
public BaseView(StateMachine stateMachine) {
|
||||||
this.stateMachine = stateMachine;
|
this.stateMachine = stateMachine;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
package gui.menu;
|
package gui.menu;
|
||||||
|
|
||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
|
import imgui.ImVec2;
|
||||||
|
|
||||||
public class MainMenu extends BaseMenu {
|
public class MainMenu extends BaseView {
|
||||||
|
|
||||||
public MainMenu(StateMachine stateMachine) {
|
public MainMenu(StateMachine stateMachine) {
|
||||||
super(stateMachine);
|
super(stateMachine);
|
||||||
@@ -10,13 +11,25 @@ public class MainMenu extends BaseMenu {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render() {
|
public void render() {
|
||||||
if (ImGui.button("Mode histoire")) {
|
var displaySize = ImGui.getIO().getDisplaySize();
|
||||||
|
ImVec2 buttonSize = new ImVec2(500, 150);
|
||||||
|
int paddingHeight = 20;
|
||||||
|
|
||||||
|
float centerX = displaySize.x / 2.0f - buttonSize.x / 2.0f;
|
||||||
|
float centerY = displaySize.y / 2.0f - buttonSize.y / 2.0f;
|
||||||
|
|
||||||
|
ImGui.setCursorPos(centerX, centerY - buttonSize.y - paddingHeight);
|
||||||
|
if (ImGui.button("Mode histoire", buttonSize)) {
|
||||||
this.stateMachine.pushState(new SoloMenu(this.stateMachine));
|
this.stateMachine.pushState(new SoloMenu(this.stateMachine));
|
||||||
}
|
}
|
||||||
if (ImGui.button("Multijoueur")) {
|
|
||||||
|
ImGui.setCursorPos(centerX, centerY);
|
||||||
|
if (ImGui.button("Multijoueur", buttonSize)) {
|
||||||
this.stateMachine.pushState(new MultiMenu(this.stateMachine));
|
this.stateMachine.pushState(new MultiMenu(this.stateMachine));
|
||||||
}
|
}
|
||||||
if (ImGui.button("Options")) {
|
|
||||||
|
ImGui.setCursorPos(centerX, centerY + buttonSize.y + paddingHeight);
|
||||||
|
if (ImGui.button("Options", buttonSize)) {
|
||||||
this.stateMachine.pushState(new OptionsMenu(this.stateMachine));
|
this.stateMachine.pushState(new OptionsMenu(this.stateMachine));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package gui.menu;
|
|||||||
|
|
||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
|
|
||||||
public class MultiMenu extends BaseMenu {
|
public class MultiMenu extends BaseView {
|
||||||
|
|
||||||
public MultiMenu(StateMachine stateMachine) {
|
public MultiMenu(StateMachine stateMachine) {
|
||||||
super(stateMachine);
|
super(stateMachine);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package gui.menu;
|
|||||||
|
|
||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
|
|
||||||
public class OptionsMenu extends BaseMenu {
|
public class OptionsMenu extends BaseView {
|
||||||
|
|
||||||
public OptionsMenu(StateMachine stateMachine) {
|
public OptionsMenu(StateMachine stateMachine) {
|
||||||
super(stateMachine);
|
super(stateMachine);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package gui.menu;
|
|||||||
|
|
||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
|
|
||||||
public class SoloMenu extends BaseMenu {
|
public class SoloMenu extends BaseView {
|
||||||
|
|
||||||
public SoloMenu(StateMachine stateMachine) {
|
public SoloMenu(StateMachine stateMachine) {
|
||||||
super(stateMachine);
|
super(stateMachine);
|
||||||
@@ -12,6 +12,9 @@ public class SoloMenu extends BaseMenu {
|
|||||||
public void render() {
|
public void render() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
ImGui.text("Solo");
|
ImGui.text("Solo");
|
||||||
|
if (ImGui.button("Résoudre un sudoku")) {
|
||||||
|
this.stateMachine.pushState(new SudokuView(stateMachine, 3));
|
||||||
|
}
|
||||||
renderReturnButton();
|
renderReturnButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,16 +3,18 @@ package gui.menu;
|
|||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
import imgui.ImGui;
|
import imgui.ImGui;
|
||||||
|
import imgui.ImVec2;
|
||||||
|
import imgui.flag.ImGuiWindowFlags;
|
||||||
|
|
||||||
public class StateMachine {
|
public class StateMachine {
|
||||||
|
|
||||||
private final Stack<BaseMenu> menus;
|
private final Stack<BaseView> menus;
|
||||||
|
|
||||||
public StateMachine() {
|
public StateMachine() {
|
||||||
this.menus = new Stack<>();
|
this.menus = new Stack<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pushState(BaseMenu menu) {
|
public void pushState(BaseView menu) {
|
||||||
menus.add(menu);
|
menus.add(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -21,7 +23,11 @@ public class StateMachine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void render() {
|
public void render() {
|
||||||
ImGui.begin("##Main Window");
|
var displaySize = ImGui.getIO().getDisplaySize();
|
||||||
|
ImGui.setNextWindowPos(new ImVec2(0.0f, 0.0f));
|
||||||
|
ImGui.setNextWindowSize(displaySize);
|
||||||
|
ImGui.begin("##Main Window", null, ImGuiWindowFlags.NoDecoration | ImGuiWindowFlags.NoMove
|
||||||
|
| ImGuiWindowFlags.NoSavedSettings | ImGuiWindowFlags.NoBackground);
|
||||||
menus.getLast().render();
|
menus.getLast().render();
|
||||||
ImGui.end();
|
ImGui.end();
|
||||||
}
|
}
|
||||||
|
|||||||
84
app/src/main/java/gui/menu/SudokuView.java
Normal file
84
app/src/main/java/gui/menu/SudokuView.java
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
package gui.menu;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import gui.ColorGenerator;
|
||||||
|
import gui.ColorGenerator.Color;
|
||||||
|
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.MultiDoku;
|
||||||
|
import sudoku.Sudoku;
|
||||||
|
import sudoku.SudokuFactory;
|
||||||
|
|
||||||
|
public class SudokuView extends BaseView {
|
||||||
|
|
||||||
|
private final Sudoku sudoku;
|
||||||
|
private int currentIndex = -1;
|
||||||
|
private final Map<Block, Color> colorPalette;
|
||||||
|
|
||||||
|
public SudokuView(StateMachine stateMachine, int size) {
|
||||||
|
super(stateMachine);
|
||||||
|
MultiDoku doku = SudokuFactory.createBasicEmptySquareSudoku(size);
|
||||||
|
this.sudoku = doku.getSubGrid(0);
|
||||||
|
this.colorPalette = new HashMap<>();
|
||||||
|
initColors();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initColors() {
|
||||||
|
List<Color> colors = ColorGenerator.greatPalette(sudoku.getSize());
|
||||||
|
int index = 0;
|
||||||
|
for (Block block : sudoku.getBlocks()) {
|
||||||
|
colorPalette.put(block, colors.get(index));
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderPopup() {
|
||||||
|
if (ImGui.beginPopup("editPopup")) {
|
||||||
|
for (int i = 1; i < sudoku.getSize() + 1; i++) {
|
||||||
|
if (i % (int) (Math.sqrt(sudoku.getSize())) != 1)
|
||||||
|
ImGui.sameLine();
|
||||||
|
if (ImGui.button(Integer.toString(i), new ImVec2(50, 50))) {
|
||||||
|
this.sudoku.setCellSymbol(currentIndex % sudoku.getSize(), currentIndex / sudoku.getSize(), i - 1);
|
||||||
|
ImGui.closeCurrentPopup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImGui.endPopup();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render() {
|
||||||
|
for (int y = 0; y < sudoku.getSize(); y++) {
|
||||||
|
for (int x = 0; x < sudoku.getSize(); x++) {
|
||||||
|
if (x > 0)
|
||||||
|
ImGui.sameLine();
|
||||||
|
int index = y * sudoku.getSize() + x;
|
||||||
|
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));
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
renderPopup();
|
||||||
|
renderReturnButton();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user