Mario Editor: add level input field
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
fffa56706d
commit
c505915fd2
@ -39,6 +39,7 @@
|
||||
#define LOAD_MAP_FLAG 0x00000400
|
||||
#define TEXT_UPDATE_FLAG 0x00000800
|
||||
#define TEXT_INPUT_FLAG 0x00001000
|
||||
#define STOP_TEXT_FLAG 0x00002000
|
||||
|
||||
#define TOOLS_WIDTH 4
|
||||
#define CHARACTER_WIDTH 3
|
||||
@ -123,8 +124,8 @@ std::shared_ptr<SDLPP::Scene> editorScene;
|
||||
SceneStruct mainMenuScene;
|
||||
// SceneStruct fileChoiceScene;
|
||||
|
||||
std::shared_ptr<SDLPP::TextRenderer> global_test_text{};
|
||||
std::string global_test_text_text{};
|
||||
std::shared_ptr<Button> level_name_object{};
|
||||
std::string level_name_text = "<no_name>";
|
||||
|
||||
void openMapEditor(std::shared_ptr<SDLPP::Scene> &scene,
|
||||
const std::string &filename);
|
||||
@ -807,25 +808,24 @@ void pollEvents(std::shared_ptr<SDLPP::Scene> &scene) {
|
||||
} else {
|
||||
if (event.key.keysym.sym == SDLK_ESCAPE ||
|
||||
event.key.keysym.sym == SDLK_RETURN) {
|
||||
SDL_StopTextInput();
|
||||
unsetFlag(TEXT_INPUT_FLAG);
|
||||
setFlag(STOP_TEXT_FLAG);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
if (getFlag(TEXT_INPUT_FLAG)) {
|
||||
if (event.key.keysym.sym == SDLK_BACKSPACE &&
|
||||
!global_test_text_text.empty()) {
|
||||
global_test_text_text.pop_back();
|
||||
!level_name_text.empty()) {
|
||||
level_name_text.pop_back();
|
||||
setFlag(TEXT_UPDATE_FLAG);
|
||||
} else if (event.key.keysym.sym == SDLK_c &&
|
||||
SDL_GetModState() & KMOD_CTRL) {
|
||||
// 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 &&
|
||||
SDL_GetModState() & KMOD_CTRL) {
|
||||
// handle paste
|
||||
global_test_text_text += SDL_GetClipboardText();
|
||||
level_name_text += SDL_GetClipboardText();
|
||||
setFlag(TEXT_UPDATE_FLAG);
|
||||
}
|
||||
}
|
||||
@ -895,7 +895,7 @@ void pollEvents(std::shared_ptr<SDLPP::Scene> &scene) {
|
||||
break;
|
||||
case SDL_TEXTINPUT:
|
||||
if (getFlag(TEXT_INPUT_FLAG)) {
|
||||
global_test_text_text += event.text.text;
|
||||
level_name_text += event.text.text;
|
||||
setFlag(TEXT_UPDATE_FLAG);
|
||||
}
|
||||
break;
|
||||
@ -1028,12 +1028,12 @@ void populateWorldType(
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
void okDialogFinalizer() {
|
||||
global_test_text_text = "You OK'd";
|
||||
level_name_text = "You OK'd";
|
||||
setFlag(TEXT_UPDATE_FLAG);
|
||||
}
|
||||
|
||||
@ -1048,6 +1048,11 @@ void testButtonFunc(void * /*UNUSED*/, Button * /*UNUSED*/) {
|
||||
SDL_StartTextInput();*/
|
||||
}
|
||||
|
||||
void enableTextInput(void */*UNUSED*/, Button */*UNUSED*/) {
|
||||
setFlag(TEXT_INPUT_FLAG);
|
||||
SDL_StartTextInput();
|
||||
}
|
||||
|
||||
void openMapEditor(std::shared_ptr<SDLPP::Scene> &scene,
|
||||
const std::string &filename) {
|
||||
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,
|
||||
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;
|
||||
// arrowInputs[1] - rightMapInput, arrowInputs[0] - leftMapInput
|
||||
toolMoveUpdateButtons(
|
||||
@ -1329,10 +1327,14 @@ createEditorMainScene(std::shared_ptr<SDLPP::Renderer> &renderer) {
|
||||
global_vars.tool.max_page_characters, false);
|
||||
left_character_input.other_button = global_vars.buttons.back();
|
||||
|
||||
global_vars.buttons.emplace_back(std::make_shared<Button>(
|
||||
0, 0, 0.2, 0.2, renderer, "Test Button", default_button_theme,
|
||||
testButtonFunc, nullptr));
|
||||
global_vars.buttons.back()->setPermanent();
|
||||
// level name
|
||||
level_name_object = std::make_shared<Button>(
|
||||
0.1, 0.05, BLOCK_SIZE * 16, BLOCK_SIZE * 2, renderer, level_name_text,
|
||||
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);
|
||||
|
||||
openMapEditor(scene, "");
|
||||
@ -1347,6 +1349,7 @@ void editorAdditionalRender(std::shared_ptr<SDLPP::Scene> &scene) {
|
||||
}
|
||||
if (getFlag(UPDATE_FLAG)) {
|
||||
scene->updateSizeAndPosition();
|
||||
mainMenuScene.scene->updateSizeAndPosition();
|
||||
unsetFlag(UPDATE_FLAG);
|
||||
}
|
||||
if (getFlag(LOAD_MAP_FLAG)) {
|
||||
@ -1356,10 +1359,15 @@ void editorAdditionalRender(std::shared_ptr<SDLPP::Scene> &scene) {
|
||||
unsetFlag(LOAD_MAP_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);
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user