git repos / blockattack-game

blame: source/code/puzzle_editor/PuzzleEditorState.cpp

normal view · raw

1873b078 Poul Sander 2025-02-06 22:01 1
/*
1873b078 Poul Sander 2025-02-06 22:01 2
===========================================================================
1873b078 Poul Sander 2025-02-06 22:01 3
blockattack - Block Attack - Rise of the Blocks
1873b078 Poul Sander 2025-02-06 22:01 4
Copyright (C) 2005-2025 Poul Sander
1873b078 Poul Sander 2025-02-06 22:01 5
1873b078 Poul Sander 2025-02-06 22:01 6
This program is free software: you can redistribute it and/or modify
1873b078 Poul Sander 2025-02-06 22:01 7
it under the terms of the GNU General Public License as published by
1873b078 Poul Sander 2025-02-06 22:01 8
the Free Software Foundation, either version 2 of the License, or
1873b078 Poul Sander 2025-02-06 22:01 9
(at your option) any later version.
1873b078 Poul Sander 2025-02-06 22:01 10
1873b078 Poul Sander 2025-02-06 22:01 11
This program is distributed in the hope that it will be useful,
1873b078 Poul Sander 2025-02-06 22:01 12
but WITHOUT ANY WARRANTY; without even the implied warranty of
1873b078 Poul Sander 2025-02-06 22:01 13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1873b078 Poul Sander 2025-02-06 22:01 14
GNU General Public License for more details.
1873b078 Poul Sander 2025-02-06 22:01 15
1873b078 Poul Sander 2025-02-06 22:01 16
You should have received a copy of the GNU General Public License
1873b078 Poul Sander 2025-02-06 22:01 17
along with this program.  If not, see http://www.gnu.org/licenses/
1873b078 Poul Sander 2025-02-06 22:01 18
1873b078 Poul Sander 2025-02-06 22:01 19
Source information and contacts persons can be found at
1873b078 Poul Sander 2025-02-06 22:01 20
https://blockattack.net
1873b078 Poul Sander 2025-02-06 22:01 21
===========================================================================
1873b078 Poul Sander 2025-02-06 22:01 22
*/
1873b078 Poul Sander 2025-02-06 22:01 23
1873b078 Poul Sander 2025-02-06 22:01 24
#include "PuzzleEditorState.hpp"
1873b078 Poul Sander 2025-02-06 22:01 25
#include "imgui.h"
1873b078 Poul Sander 2025-02-06 22:01 26
#include "backends/imgui_impl_sdl2.h"
1873b078 Poul Sander 2025-02-06 22:01 27
#include "backends/imgui_impl_sdlrenderer2.h"
a80f6a78 Poul Sander 2025-04-04 18:34 28
#include "../sago/SagoMisc.hpp"
a80f6a78 Poul Sander 2025-04-04 18:34 29
#include "../puzzlehandler.hpp"
1873b078 Poul Sander 2025-02-06 22:01 30
1873b078 Poul Sander 2025-02-06 22:01 31
1873b078 Poul Sander 2025-02-06 22:01 32
bool PuzzleEditorState::IsActive() {
1873b078 Poul Sander 2025-02-06 22:01 33
	return isActive;
1873b078 Poul Sander 2025-02-06 22:01 34
}
1873b078 Poul Sander 2025-02-06 22:01 35
1873b078 Poul Sander 2025-02-06 22:01 36
void PuzzleEditorState::ProcessInput(const SDL_Event& event, bool& processed) {
1873b078 Poul Sander 2025-02-06 22:01 37
	ImGui_ImplSDL2_ProcessEvent(&event);
1873b078 Poul Sander 2025-02-06 22:01 38
}
1873b078 Poul Sander 2025-02-06 22:01 39
a80f6a78 Poul Sander 2025-04-04 18:34 40
void PuzzleEditorState::Init() {
a80f6a78 Poul Sander 2025-04-04 18:34 41
	this->selected_file = "";
a80f6a78 Poul Sander 2025-04-04 18:34 42
	this->puzzle_files = sago::GetFileList("puzzles");
6046ca3f Poul Sander 2025-04-06 16:14 43
	game = std::make_shared<BlockGameSdl>(globalData.xsize-450,100,&globalData.spriteHolder->GetDataHolder());
6046ca3f Poul Sander 2025-04-06 16:14 44
	game->name = "Player 1";
a80f6a78 Poul Sander 2025-04-04 18:34 45
}
a80f6a78 Poul Sander 2025-04-04 18:34 46
a80f6a78 Poul Sander 2025-04-04 18:34 47
void PuzzleEditorState::SelectFile(const std::string& file) {
a80f6a78 Poul Sander 2025-04-04 18:34 48
	this->selected_file = file;
a80f6a78 Poul Sander 2025-04-04 18:34 49
	PuzzleSetName(file);
a80f6a78 Poul Sander 2025-04-04 18:34 50
	LoadPuzzleStages();
a80f6a78 Poul Sander 2025-04-04 18:34 51
}
a80f6a78 Poul Sander 2025-04-04 18:34 52
1873b078 Poul Sander 2025-02-06 22:01 53
void PuzzleEditorState::Draw(SDL_Renderer* target) {
6046ca3f Poul Sander 2025-04-06 16:14 54
	DrawBackground(target);
6046ca3f Poul Sander 2025-04-06 16:14 55
	if (game) {
6046ca3f Poul Sander 2025-04-06 16:14 56
		game->DoPaintJob();
6046ca3f Poul Sander 2025-04-06 16:14 57
	}
1873b078 Poul Sander 2025-02-06 22:01 58
	ImGui::Begin("File list", nullptr, ImGuiWindowFlags_NoCollapse);
a80f6a78 Poul Sander 2025-04-04 18:34 59
	for (const auto& file : this->puzzle_files) {
a80f6a78 Poul Sander 2025-04-04 18:34 60
		if (ImGui::Selectable(file.c_str(), this->selected_file == file)) {
a80f6a78 Poul Sander 2025-04-04 18:34 61
			SelectFile(file);
a80f6a78 Poul Sander 2025-04-04 18:34 62
		}
1873b078 Poul Sander 2025-02-06 22:01 63
	}
1873b078 Poul Sander 2025-02-06 22:01 64
a80f6a78 Poul Sander 2025-04-04 18:34 65
a80f6a78 Poul Sander 2025-04-04 18:34 66
	ImGui::End();
a80f6a78 Poul Sander 2025-04-04 18:34 67
	ImGui::Begin("Puzzles in file");
a80f6a78 Poul Sander 2025-04-04 18:34 68
	int puzzle_count = PuzzleGetNumberOfPuzzles();
a80f6a78 Poul Sander 2025-04-04 18:34 69
	for (int i = 0; i < puzzle_count; ++i) {
6046ca3f Poul Sander 2025-04-06 16:14 70
		if (ImGui::Selectable(std::to_string(i).c_str(), this->selected_puzzle == i)) {
6046ca3f Poul Sander 2025-04-06 16:14 71
			this->selected_puzzle = i;
72f219a9 Poul Sander 2025-04-06 17:00 72
			BlockGameStartInfo s;
72f219a9 Poul Sander 2025-04-06 17:00 73
			s.ticks = 0;
72f219a9 Poul Sander 2025-04-06 17:00 74
			s.level = i+1;
72f219a9 Poul Sander 2025-04-06 17:00 75
			s.puzzleMode = true;
72f219a9 Poul Sander 2025-04-06 17:00 76
			if (game) {
72f219a9 Poul Sander 2025-04-06 17:00 77
				game->NewGame(s);
72f219a9 Poul Sander 2025-04-06 17:00 78
			}
a80f6a78 Poul Sander 2025-04-04 18:34 79
		}
a80f6a78 Poul Sander 2025-04-04 18:34 80
	}
1873b078 Poul Sander 2025-02-06 22:01 81
	ImGui::End();
1873b078 Poul Sander 2025-02-06 22:01 82
}
1873b078 Poul Sander 2025-02-06 22:01 83
1873b078 Poul Sander 2025-02-06 22:01 84
void PuzzleEditorState::Update() {
1873b078 Poul Sander 2025-02-06 22:01 85
}
1873b078 Poul Sander 2025-02-06 22:01 86
1970-01-01 00:00 87