git repos / blockattack-game

commit f87a08db

Poul Sander · 2025-02-06 19:50
f87a08dbeeddfc7e4dabe4a87a0cdf69f71613c9 patch · browse files
parent d488281633cf0c48702228cd04dd5819fd142849

Well, now the Puzzle Editor starts up

Changed files

M source/code/main.cpp before
M source/code/mainVars.inc before
diff --git a/source/code/main.cpp b/source/code/main.cpp index 1ebb55d..911d9d6 100644 --- a/source/code/main.cpp +++ b/source/code/main.cpp
@@ -68,6 +68,9 @@ https://blockattack.net
#include "ExplosionManager.hpp"
+#include "puzzle_editor/PuzzleEditorState.hpp"
+#include "SagoImGui.hpp"
+
/*******************************************************************************
* All variables and constant has been moved to mainVars.inc for the overview. *
*******************************************************************************/
@@ -412,6 +415,65 @@ void RunGameState(sago::GameStateInterface& state ) {
}
}
+void RunImGuiGameState(sago::GameStateInterface& state ) {
+ bool done = false; //We are done!
+ while (!done && !Config::getInstance()->isShuttingDown()) {
+ SDL_SetRenderDrawColor(globalData.screen, 0, 0, 0, 0);
+ SDL_RenderClear(globalData.screen);
+ ImGui_ImplSDLRenderer2_NewFrame();
+ ImGui_ImplSDL2_NewFrame();
+ ImGui::NewFrame();
+ state.Draw(globalData.screen);
+ ImGui::Render();
+ ImGui_ImplSDLRenderer2_RenderDrawData( ImGui::GetDrawData(), globalData.screen );
+
+ //While using Dear ImGui we do not draw the mouse ourself. This is gone: globalData.mouse.Draw(globalData.screen, SDL_GetTicks(), globalData.mousex, globalData.mousey);
+ SDL_RenderPresent(globalData.screen);
+
+ SDL_Delay(1);
+ SDL_Event event;
+ bool mustWriteScreenshot = false;
+
+ while ( SDL_PollEvent(&event) ) {
+ if ( event.type == SDL_QUIT ) {
+ Config::getInstance()->setShuttingDown(5);
+ done = true;
+ }
+
+ if (event.type == SDL_WINDOWEVENT) {
+ if (event.window.event == SDL_WINDOWEVENT_SIZE_CHANGED) {
+ std::cout << event.window.data1 << ", " << event.window.data2 << "\n";
+ SDL_GetRendererOutputSize(globalData.screen, &globalData.xsize, &globalData.ysize);
+ }
+ }
+
+ if (event.type == SDL_KEYDOWN) {
+ if ( event.key.keysym.sym == SDLK_F9 ) {
+ mustWriteScreenshot = true;
+ }
+ }
+
+ if (mustWriteScreenshot) {
+ writeScreenShot();
+ }
+ bool processed = false;
+ ImGui_ImplSDL2_ProcessEvent(&event);
+ state.ProcessInput(event, processed);
+
+ }
+
+
+ state.Update();
+
+ //SDL_RenderPresent(globalData.screen);
+
+
+ if (!state.IsActive()) {
+ done = true;
+ }
+ }
+}
+
void OpenScoresDisplay() {
ScoresDisplay d;
d.scoreX = buttonXsize*2;
@@ -857,6 +919,7 @@ static void ParseArguments(int argc, char* argv[], globalConfig& conf) {
("print-search-path", "Prints the search path and quits")
("no-auto-scale", "Do not automatically auto scale")
("always-sixteen-nine", "Use 16:9 format even in Window mode")
+ ("puzzle-editor", "Start the build in puzzle editor")
("puzzle-level-file", boost::program_options::value<std::string>(), "Sets the default puzzle file to load")
("puzzle-single-level", boost::program_options::value<int>(), "Start the specific puzzle level directly")
#ifdef REPLAY_IMPLEMENTED
@@ -952,6 +1015,9 @@ static void ParseArguments(int argc, char* argv[], globalConfig& conf) {
if (vm.count("always-sixteen-nine")) {
globalData.alwaysSixteenNine = true;
}
+ if (vm.count("puzzle-editor")) {
+ puzzleEditor = true;
+ }
if (vm.count("puzzle-level-file")) {
conf.puzzleName = vm["puzzle-level-file"].as<std::string>();
}
@@ -1236,6 +1302,11 @@ int main(int argc, char* argv[]) {
if (singlePuzzle) {
runGame(Gametype::Puzzle, singlePuzzleNr);
}
+ else if (puzzleEditor) {
+ InitImGui(sdlWindow, renderer, globalData.xsize, globalData.ysize);
+ PuzzleEditorState s;
+ RunImGuiGameState(s);
+ }
else if (globalData.replayArgument.length()) {
ReplayPlayer rp;
RunGameState(rp);
diff --git a/source/code/mainVars.inc b/source/code/mainVars.inc index 57143e3..66221e4 100644 --- a/source/code/mainVars.inc +++ b/source/code/mainVars.inc
@@ -84,12 +84,13 @@ static Uint8 player2handicap=0;
unsigned long int currentTime; //contains the current time, so we don't call SDL_GetTickets() too often...
-bool twoPlayers; //True if two players are playing
+bool twoPlayers; //True if two playerImGui_ImplSDL2_ProcessEvent(&event);s are playing
//Allows starting the game with just a single puzzle. Mainly to be able to open a puzzle directly from the level editor
static bool singlePuzzle = false;
+static bool puzzleEditor = false;
static int singlePuzzleNr = 0;
static std::string singlePuzzleFile;