Mario Editor: add option to select a level to load
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include "../blocks/coineditorblock.hpp"
|
||||
#include <SDL2/SDL_keycode.h>
|
||||
#include <array>
|
||||
#include "../filesystem.hpp"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "../sdlpp/SDL2/SDL2_framerate.h"
|
||||
@@ -46,6 +47,8 @@
|
||||
#define MOD_WIDTH 2
|
||||
#define OVERWORLD_WIDTH 2
|
||||
|
||||
const std::string levelsDir = "levels";
|
||||
|
||||
struct ToolType {
|
||||
enum Value {
|
||||
BLOCK,
|
||||
@@ -142,12 +145,14 @@ bool getFlag(uint64_t flag) {
|
||||
|
||||
void saveMapCallback(void * /*UNUSED*/, Button * /*UNUSED*/) {
|
||||
std::cout << "SAVING" << std::endl;
|
||||
saveMap("levels/" + level_name_text + ".marmap", global_vars.objects);
|
||||
saveMap(levelsDir + FSLib::dir_divisor + level_name_text + ".marmap",
|
||||
global_vars.objects);
|
||||
}
|
||||
|
||||
void loadMapDialogCallback(void * /*UNUSED*/, Button * /*UNUSED*/) {
|
||||
void loadMapDialogCallback(const std::string &level_name) {
|
||||
std::cout << "LOADING" << std::endl;
|
||||
level_name_text = level_name.substr(0, level_name.length() - 7);
|
||||
setFlag(LOAD_MAP_FLAG);
|
||||
setFlag(TEXT_UPDATE_FLAG);
|
||||
}
|
||||
|
||||
void updateTool() {
|
||||
@@ -1023,7 +1028,7 @@ void populateWorldType(
|
||||
scene->addObject(tool_text);
|
||||
}
|
||||
|
||||
void enableTextInput(void */*UNUSED*/, Button */*UNUSED*/) {
|
||||
void enableTextInput(void * /*UNUSED*/, Button * /*UNUSED*/) {
|
||||
setFlag(TEXT_INPUT_FLAG);
|
||||
SDL_StartTextInput();
|
||||
}
|
||||
@@ -1042,11 +1047,11 @@ void openMapEditor(std::shared_ptr<SDLPP::Scene> &scene,
|
||||
|
||||
global_vars.current_world_type = LandType::OVERWORLD;
|
||||
|
||||
if (filename.empty()) {
|
||||
if (filename.empty() || !FSLib::exists(filename)) {
|
||||
loadEmptyMap(global_vars.objects, MAP_WIDTH);
|
||||
} else {
|
||||
loadMap(scene, global_vars.mario, "test_binary.bin",
|
||||
global_vars.objects, true, MAP_WIDTH);
|
||||
loadMap(scene, global_vars.mario, filename, global_vars.objects, true,
|
||||
MAP_WIDTH);
|
||||
}
|
||||
|
||||
// map
|
||||
@@ -1146,7 +1151,8 @@ void openMapEditor(std::shared_ptr<SDLPP::Scene> &scene,
|
||||
|
||||
// level_name label
|
||||
auto level_name_label = std::make_shared<SDLPP::TextRenderer>(
|
||||
0.1, 0.1, BLOCK_SIZE * 8, 0.05, renderer, "Level Name:", font_config, SDLPP_TEXT_LEFT);
|
||||
0.1, 0.1, BLOCK_SIZE * 8, 0.05, renderer, "Level Name:", font_config,
|
||||
SDLPP_TEXT_LEFT);
|
||||
level_name_label->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
||||
level_name_label->setPermanent();
|
||||
scene->addObject(level_name_label);
|
||||
@@ -1335,9 +1341,9 @@ void editorAdditionalRender(std::shared_ptr<SDLPP::Scene> &scene) {
|
||||
unsetFlag(UPDATE_FLAG);
|
||||
}
|
||||
if (getFlag(LOAD_MAP_FLAG)) {
|
||||
// TODO filename
|
||||
editorScene->resetScene();
|
||||
openMapEditor(editorScene, "test_binary.bin");
|
||||
openMapEditor(editorScene, levelsDir + FSLib::dir_divisor +
|
||||
level_name_text + ".marmap");
|
||||
unsetFlag(LOAD_MAP_FLAG);
|
||||
}
|
||||
if (getFlag(TEXT_UPDATE_FLAG)) {
|
||||
|
||||
Reference in New Issue
Block a user