rainbow
All checks were successful
Linux arm64 / Build (push) Successful in 5m42s

This commit is contained in:
2025-01-22 22:41:47 +01:00
parent 396abb30b3
commit ba65cb9ff5
4 changed files with 137 additions and 24 deletions

View File

@@ -1,46 +1,91 @@
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 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 int[] values = new int[9 * 9];
private Sudoku sudoku;
private int currentIndex = -1;
private Map<Block, Color> colorPalette = new HashMap<>();
private static final int SUDOKU_SIZE = 5;
@Override
protected void configure(Configuration config) {
config.setTitle("Let's play sudoku!");
}
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++;
}
}
@Override
protected void initImGui(Configuration config) {
super.initImGui(config);
ImGui.getIO().getFonts().addFontFromFileTTF("comic.ttf", 50.0f);
Random r = new Random();
for (int i = 0; i < 9 * 9; i++) {
values[i] = r.nextInt(9) + 1;
MultiDoku doku = SudokuFactory.createBasicEmptySquareSudoku(SUDOKU_SIZE);
sudoku = doku.getSubGrid(0);
initColors();
}
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 process() {
ImGui.begin("Sudoku Window");
for (int y = 0; y < 9; y++) {
for (int x = 0; x < 9; x++) {
for (int y = 0; y < sudoku.getSize(); y++) {
for (int x = 0; x < sudoku.getSize(); x++) {
if (x > 0)
ImGui.sameLine();
ImGui.pushID(y * 9 + x);
ImGui.selectable(Integer.toString(values[y * 9 + x]), false, 0, new ImVec2(50, 50));
ImGui.popID();
int index = y * sudoku.getSize() + x;
Cell cell = sudoku.getCell(x, y);
int symbol = cell.getSymbolIndex();
Color blockColor = colorPalette.get(cell.getBlock());
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))) {
ImGui.openPopup("editPopup");
currentIndex = index;
}
ImGui.popStyleColor();
}
}
renderPopup();
ImGui.end();
// ImGui.showDemoWindow();
ImGui.showDemoWindow();
}
public static void main(String[] args) {