Mario Editor: add level input field
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
zv0n 2022-07-22 18:48:06 +02:00
parent fffa56706d
commit c505915fd2

View File

@ -39,6 +39,7 @@
#define LOAD_MAP_FLAG 0x00000400 #define LOAD_MAP_FLAG 0x00000400
#define TEXT_UPDATE_FLAG 0x00000800 #define TEXT_UPDATE_FLAG 0x00000800
#define TEXT_INPUT_FLAG 0x00001000 #define TEXT_INPUT_FLAG 0x00001000
#define STOP_TEXT_FLAG 0x00002000
#define TOOLS_WIDTH 4 #define TOOLS_WIDTH 4
#define CHARACTER_WIDTH 3 #define CHARACTER_WIDTH 3
@ -123,8 +124,8 @@ std::shared_ptr<SDLPP::Scene> editorScene;
SceneStruct mainMenuScene; SceneStruct mainMenuScene;
// SceneStruct fileChoiceScene; // SceneStruct fileChoiceScene;
std::shared_ptr<SDLPP::TextRenderer> global_test_text{}; std::shared_ptr<Button> level_name_object{};
std::string global_test_text_text{}; std::string level_name_text = "<no_name>";
void openMapEditor(std::shared_ptr<SDLPP::Scene> &scene, void openMapEditor(std::shared_ptr<SDLPP::Scene> &scene,
const std::string &filename); const std::string &filename);
@ -807,25 +808,24 @@ void pollEvents(std::shared_ptr<SDLPP::Scene> &scene) {
} else { } else {
if (event.key.keysym.sym == SDLK_ESCAPE || if (event.key.keysym.sym == SDLK_ESCAPE ||
event.key.keysym.sym == SDLK_RETURN) { event.key.keysym.sym == SDLK_RETURN) {
SDL_StopTextInput(); setFlag(STOP_TEXT_FLAG);
unsetFlag(TEXT_INPUT_FLAG);
} }
} }
break; break;
case SDL_KEYDOWN: case SDL_KEYDOWN:
if (getFlag(TEXT_INPUT_FLAG)) { if (getFlag(TEXT_INPUT_FLAG)) {
if (event.key.keysym.sym == SDLK_BACKSPACE && if (event.key.keysym.sym == SDLK_BACKSPACE &&
!global_test_text_text.empty()) { !level_name_text.empty()) {
global_test_text_text.pop_back(); level_name_text.pop_back();
setFlag(TEXT_UPDATE_FLAG); setFlag(TEXT_UPDATE_FLAG);
} else if (event.key.keysym.sym == SDLK_c && } else if (event.key.keysym.sym == SDLK_c &&
SDL_GetModState() & KMOD_CTRL) { SDL_GetModState() & KMOD_CTRL) {
// handle copy // handle copy
SDL_SetClipboardText(global_test_text_text.c_str()); SDL_SetClipboardText(level_name_text.c_str());
} else if (event.key.keysym.sym == SDLK_v && } else if (event.key.keysym.sym == SDLK_v &&
SDL_GetModState() & KMOD_CTRL) { SDL_GetModState() & KMOD_CTRL) {
// handle paste // handle paste
global_test_text_text += SDL_GetClipboardText(); level_name_text += SDL_GetClipboardText();
setFlag(TEXT_UPDATE_FLAG); setFlag(TEXT_UPDATE_FLAG);
} }
} }
@ -895,7 +895,7 @@ void pollEvents(std::shared_ptr<SDLPP::Scene> &scene) {
break; break;
case SDL_TEXTINPUT: case SDL_TEXTINPUT:
if (getFlag(TEXT_INPUT_FLAG)) { if (getFlag(TEXT_INPUT_FLAG)) {
global_test_text_text += event.text.text; level_name_text += event.text.text;
setFlag(TEXT_UPDATE_FLAG); setFlag(TEXT_UPDATE_FLAG);
} }
break; break;
@ -1028,12 +1028,12 @@ void populateWorldType(
} }
void dialogFinishedTest(bool result) { void dialogFinishedTest(bool result) {
global_test_text_text = result ? "YEAH, BOI!" : "Nah, boi"; level_name_text = result ? "YEAH, BOI!" : "Nah, boi";
setFlag(TEXT_UPDATE_FLAG); setFlag(TEXT_UPDATE_FLAG);
} }
void okDialogFinalizer() { void okDialogFinalizer() {
global_test_text_text = "You OK'd"; level_name_text = "You OK'd";
setFlag(TEXT_UPDATE_FLAG); setFlag(TEXT_UPDATE_FLAG);
} }
@ -1048,6 +1048,11 @@ void testButtonFunc(void * /*UNUSED*/, Button * /*UNUSED*/) {
SDL_StartTextInput();*/ SDL_StartTextInput();*/
} }
void enableTextInput(void */*UNUSED*/, Button */*UNUSED*/) {
setFlag(TEXT_INPUT_FLAG);
SDL_StartTextInput();
}
void openMapEditor(std::shared_ptr<SDLPP::Scene> &scene, void openMapEditor(std::shared_ptr<SDLPP::Scene> &scene,
const std::string &filename) { const std::string &filename) {
auto renderer = scene->getRendererShared(); auto renderer = scene->getRendererShared();
@ -1109,13 +1114,6 @@ void openMapEditor(std::shared_ptr<SDLPP::Scene> &scene,
createGrid(BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, OVERWORLD_WIDTH, createGrid(BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, OVERWORLD_WIDTH,
2, scene); 2, scene);
global_test_text = std::make_shared<SDLPP::TextRenderer>(
0.3, 0.05, BLOCK_SIZE * 4, BLOCK_SIZE * 2, renderer, "TEST TEXT",
font_config, SDLPP_TEXT_CENTER);
global_test_text->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
global_test_text->setPermanent();
scene->addObject(global_test_text);
global_vars.map.max_page = global_vars.objects.size() - MAP_WIDTH; global_vars.map.max_page = global_vars.objects.size() - MAP_WIDTH;
// arrowInputs[1] - rightMapInput, arrowInputs[0] - leftMapInput // arrowInputs[1] - rightMapInput, arrowInputs[0] - leftMapInput
toolMoveUpdateButtons( toolMoveUpdateButtons(
@ -1329,10 +1327,14 @@ createEditorMainScene(std::shared_ptr<SDLPP::Renderer> &renderer) {
global_vars.tool.max_page_characters, false); global_vars.tool.max_page_characters, false);
left_character_input.other_button = global_vars.buttons.back(); left_character_input.other_button = global_vars.buttons.back();
global_vars.buttons.emplace_back(std::make_shared<Button>( // level name
0, 0, 0.2, 0.2, renderer, "Test Button", default_button_theme, level_name_object = std::make_shared<Button>(
testButtonFunc, nullptr)); 0.1, 0.05, BLOCK_SIZE * 16, BLOCK_SIZE * 2, renderer, level_name_text,
global_vars.buttons.back()->setPermanent(); default_button_theme, enableTextInput, nullptr);
level_name_object->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
level_name_object->setPermanent();
level_name_object->setColor("#FFFFFF88");
global_vars.buttons.push_back(level_name_object);
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1); global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
openMapEditor(scene, ""); openMapEditor(scene, "");
@ -1347,6 +1349,7 @@ void editorAdditionalRender(std::shared_ptr<SDLPP::Scene> &scene) {
} }
if (getFlag(UPDATE_FLAG)) { if (getFlag(UPDATE_FLAG)) {
scene->updateSizeAndPosition(); scene->updateSizeAndPosition();
mainMenuScene.scene->updateSizeAndPosition();
unsetFlag(UPDATE_FLAG); unsetFlag(UPDATE_FLAG);
} }
if (getFlag(LOAD_MAP_FLAG)) { if (getFlag(LOAD_MAP_FLAG)) {
@ -1356,10 +1359,15 @@ void editorAdditionalRender(std::shared_ptr<SDLPP::Scene> &scene) {
unsetFlag(LOAD_MAP_FLAG); unsetFlag(LOAD_MAP_FLAG);
} }
if (getFlag(TEXT_UPDATE_FLAG)) { if (getFlag(TEXT_UPDATE_FLAG)) {
global_test_text->changeText(global_test_text_text); level_name_object->changeText(level_name_text);
unsetFlag(TEXT_UPDATE_FLAG); unsetFlag(TEXT_UPDATE_FLAG);
setFlag(UPDATE_FLAG); setFlag(UPDATE_FLAG);
} }
if (getFlag(STOP_TEXT_FLAG)) {
SDL_StopTextInput();
unsetFlag(TEXT_INPUT_FLAG);
unsetFlag(STOP_TEXT_FLAG);
}
} }
SceneStruct createEditorScene(std::shared_ptr<SDLPP::Renderer> &renderer) { SceneStruct createEditorScene(std::shared_ptr<SDLPP::Renderer> &renderer) {