Mario Editor: add save/load functionality
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
92ffac0edf
commit
4143af9962
@ -96,6 +96,10 @@ MapObject parseBlock(std::ifstream &map_file) {
|
||||
modifier_id, modifier_data);
|
||||
}
|
||||
|
||||
void loadEmptyMap( std::vector<mapColumnType> &objects, size_t editor_width) {
|
||||
objects.resize(editor_width);
|
||||
}
|
||||
|
||||
// editor loader
|
||||
// TODO catch exception in calling functions
|
||||
void loadMap(std::shared_ptr<SDLPP::Scene> &scene,
|
||||
@ -104,7 +108,7 @@ void loadMap(std::shared_ptr<SDLPP::Scene> &scene,
|
||||
bool editor, size_t editor_width) {
|
||||
if(!FSLib::exists(file)) {
|
||||
// create empty array large enough for initial editor window
|
||||
objects.resize(editor_width);
|
||||
loadEmptyMap(objects, editor_width);
|
||||
return;
|
||||
}
|
||||
auto renderer = scene->getRendererShared();
|
||||
|
@ -14,6 +14,7 @@ void loadMap(std::shared_ptr<SDLPP::Scene> &scene,
|
||||
std::shared_ptr<SDLPP::RenderObject> &mario,
|
||||
const std::string &file, std::vector<mapColumnType> &objects,
|
||||
bool editor = false, size_t editor_width = 0);
|
||||
void loadEmptyMap( std::vector<mapColumnType> &objects, size_t editor_width);
|
||||
void saveMap(const std::string &file, std::vector<mapColumnType> &objects);
|
||||
|
||||
#endif
|
||||
|
@ -35,6 +35,7 @@
|
||||
#define MOD_RIGHT_ENABLED_FLAG 0x00000080
|
||||
#define CHARACTER_LEFT_ENABLED_FLAG 0x00000100
|
||||
#define CHARACTER_RIGHT_ENABLED_FLAG 0x00000200
|
||||
#define LOAD_MAP_FLAG 0x00000400
|
||||
|
||||
#define TOOLS_WIDTH 4
|
||||
#define CHARACTER_WIDTH 3
|
||||
@ -114,11 +115,37 @@ struct moveStruct {
|
||||
|
||||
GlobalVars global_vars;
|
||||
std::mutex render_mutex;
|
||||
int click_num = 0;
|
||||
std::vector<moveStruct> arrowInputs{};
|
||||
std::shared_ptr<SDLPP::Scene> editorScene;
|
||||
SceneStruct mainMenuScene;
|
||||
//SceneStruct fileChoiceScene;
|
||||
|
||||
void openMapEditor(std::shared_ptr<SDLPP::Scene> &scene, const std::string &filename);
|
||||
|
||||
void setFlag(uint64_t flag) {
|
||||
global_vars.flags |= flag;
|
||||
}
|
||||
void unsetFlag(uint64_t flag) {
|
||||
global_vars.flags &= ~flag;
|
||||
}
|
||||
bool getFlag(uint64_t flag) {
|
||||
return global_vars.flags & flag;
|
||||
}
|
||||
|
||||
void saveMapCallback(void */*UNUSED*/, Button */*UNUSED*/) {
|
||||
std::cout << "SAVING" << std::endl;
|
||||
// TODO filename
|
||||
saveMap("test_binary2.bin", global_vars.objects);
|
||||
}
|
||||
|
||||
void loadMapDialogCallback(void */*UNUSED*/, Button */*UNUSED*/) {
|
||||
std::cout << "LOADING" << std::endl;
|
||||
setFlag(LOAD_MAP_FLAG);
|
||||
// TODO filename
|
||||
/* editorScene->resetScene();
|
||||
openMapEditor(editorScene, "test_binary.bin");*/
|
||||
}
|
||||
|
||||
void updateTool() {
|
||||
auto tool_index = global_vars.tool.index;
|
||||
uint64_t tool_id = 0;
|
||||
@ -468,16 +495,6 @@ void selectNextTool() {
|
||||
updateToolIndex(global_vars.tool.index + addition);
|
||||
}
|
||||
|
||||
void setFlag(uint64_t flag) {
|
||||
global_vars.flags |= flag;
|
||||
}
|
||||
void unsetFlag(uint64_t flag) {
|
||||
global_vars.flags &= ~flag;
|
||||
}
|
||||
bool getFlag(uint64_t flag) {
|
||||
return global_vars.flags & flag;
|
||||
}
|
||||
|
||||
void updateWorld() {
|
||||
for (auto &block : global_vars.tools) {
|
||||
block->setType(global_vars.current_world_type);
|
||||
@ -857,6 +874,9 @@ void populateToolGrid(
|
||||
std::vector<std::shared_ptr<SDLPP::RenderObject>> &tool_box_store,
|
||||
std::shared_ptr<SDLPP::Scene> &scene, const std::string &title,
|
||||
const std::shared_ptr<SDLPP::FontConfiguration> &font_config) {
|
||||
tool_store.clear();
|
||||
tool_box_store.clear();
|
||||
|
||||
auto renderer = scene->getRendererShared();
|
||||
for (int j = 0; j < count_y; j++) {
|
||||
for (int i = 0; i < count_x; i++) {
|
||||
@ -952,11 +972,11 @@ void testButtonFunc(void *input, Button *caller) {
|
||||
caller->disable();
|
||||
}
|
||||
|
||||
std::shared_ptr<SDLPP::Scene> createEditorMainScene(std::shared_ptr<SDLPP::Renderer> &renderer) {
|
||||
void openMapEditor(std::shared_ptr<SDLPP::Scene> &scene, const std::string &filename) {
|
||||
auto renderer = scene->getRendererShared();
|
||||
auto font = std::make_shared<SDLPP::Font>("testfont.ttf", 36);
|
||||
auto font_config = std::make_shared<SDLPP::FontConfiguration>(
|
||||
font, "#000000", "#282828", 0.05);
|
||||
auto scene = std::make_shared<SDLPP::Scene>(renderer);
|
||||
auto bg = std::make_shared<SDLPP::RectangleRender>(
|
||||
0, 0, 10, 10, renderer, MARIO_OVERWORLD_COLORKEY, true);
|
||||
bg->setPermanent();
|
||||
@ -965,50 +985,14 @@ std::shared_ptr<SDLPP::Scene> createEditorMainScene(std::shared_ptr<SDLPP::Rende
|
||||
|
||||
global_vars.current_world_type = LandType::OVERWORLD;
|
||||
|
||||
// TODO file name
|
||||
loadMap(scene, global_vars.mario, "test_binary.bin", global_vars.objects,
|
||||
true, MAP_WIDTH);
|
||||
if(filename.empty()) {
|
||||
loadEmptyMap(global_vars.objects, MAP_WIDTH);
|
||||
} else {
|
||||
loadMap(scene, global_vars.mario, "test_binary.bin", global_vars.objects,
|
||||
true, MAP_WIDTH);
|
||||
}
|
||||
|
||||
// create grids and arrow controls
|
||||
// map
|
||||
ButtonConfig default_button_theme{};
|
||||
default_button_theme.bg_color = "#FFFFFF88";
|
||||
default_button_theme.bg_color_highlight = "#FFFFFFBB";
|
||||
default_button_theme.bg_color_disabled = "#AAAAAA88";
|
||||
default_button_theme.font_color = "#000000";
|
||||
default_button_theme.font_color_highlight = "#000000";
|
||||
default_button_theme.font_color_disabled = "#555555";
|
||||
default_button_theme.font_outline_color = "#FFFFFF88";
|
||||
default_button_theme.font_outline_color_highlight = "#FFFFFFAA";
|
||||
default_button_theme.font_outline_color_disabled = "#787878";
|
||||
default_button_theme.outline = 0.1;
|
||||
// left map arrow
|
||||
arrowInputs.resize(8);
|
||||
auto &left_map_input = arrowInputs[0];
|
||||
left_map_input.scene = scene;
|
||||
left_map_input.other_button = nullptr;
|
||||
global_vars.buttons.emplace_back(std::make_shared<Button>(
|
||||
0, 1 - MAP_HEIGHT * BLOCK_SIZE, BLOCK_SIZE, MAP_HEIGHT * BLOCK_SIZE,
|
||||
renderer, "<", default_button_theme, moveMapLeft, &left_map_input));
|
||||
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
||||
global_vars.buttons.back()->setPermanent();
|
||||
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
|
||||
// right map arrow
|
||||
auto &right_map_input = arrowInputs[1];
|
||||
right_map_input.scene = scene;
|
||||
right_map_input.other_button = global_vars.buttons.back();
|
||||
global_vars.buttons.emplace_back(std::make_shared<Button>(
|
||||
(MAP_WIDTH + 1) * BLOCK_SIZE, 1 - MAP_HEIGHT * BLOCK_SIZE, BLOCK_SIZE, MAP_HEIGHT * BLOCK_SIZE,
|
||||
renderer, ">", default_button_theme, moveMapRight, &right_map_input));
|
||||
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
||||
global_vars.buttons.back()->setPermanent();
|
||||
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
|
||||
left_map_input.other_button = global_vars.buttons.back();
|
||||
// ensure disabled/enabled properly
|
||||
toolMoveUpdateButtons(right_map_input.other_button.get(), global_vars.buttons.back().get(), global_vars.map.cur_page, global_vars.map.max_page, true);
|
||||
createGrid(BLOCK_SIZE, 1 - MAP_HEIGHT * BLOCK_SIZE, MAP_WIDTH, MAP_HEIGHT,
|
||||
scene);
|
||||
// edit blocks on map
|
||||
for (int i = 0; i < MAP_WIDTH; i++) {
|
||||
for (int j = 0; j < MAP_HEIGHT; j++) {
|
||||
scene->addObject(std::make_shared<EditBox>(
|
||||
@ -1016,44 +1000,13 @@ std::shared_ptr<SDLPP::Scene> createEditorMainScene(std::shared_ptr<SDLPP::Rende
|
||||
MAP_HEIGHT, renderer));
|
||||
}
|
||||
}
|
||||
|
||||
global_vars.tool.max_page_tools =
|
||||
(possibleBlocks.size() - 1) / (2 * TOOLS_WIDTH);
|
||||
global_vars.tool.max_page_mods =
|
||||
(possibleMods.size() - 1) / (2 * MOD_WIDTH);
|
||||
global_vars.tool.max_page_characters =
|
||||
(possibleCharacters.size() - 1) / (2 * CHARACTER_WIDTH);
|
||||
|
||||
createGrid(BLOCK_SIZE, 1 - MAP_HEIGHT * BLOCK_SIZE, MAP_WIDTH, MAP_HEIGHT,
|
||||
scene);
|
||||
// tools
|
||||
populateToolGrid(TOOLS_WIDTH, 2, (MAP_WIDTH - TOOLS_WIDTH) * BLOCK_SIZE,
|
||||
1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, ToolType::BLOCK,
|
||||
possibleBlocks, global_vars.tools, global_vars.tool_boxes,
|
||||
scene, "TERRAIN", font_config);
|
||||
// left tool arrow
|
||||
auto &left_tool_input = arrowInputs[2];
|
||||
left_tool_input.scene = scene;
|
||||
left_tool_input.other_button = nullptr;
|
||||
global_vars.buttons.emplace_back(std::make_shared<Button>(
|
||||
(MAP_WIDTH - TOOLS_WIDTH - 1) * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE,
|
||||
renderer, "<", default_button_theme, moveToolsLeftButton, &left_tool_input));
|
||||
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
||||
global_vars.buttons.back()->setPermanent();
|
||||
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
|
||||
global_vars.tool.button_left_tools = global_vars.buttons.back();
|
||||
// right tool arrow
|
||||
auto &right_tool_input = arrowInputs[3];
|
||||
right_tool_input.scene = scene;
|
||||
right_tool_input.other_button = global_vars.buttons.back();
|
||||
global_vars.buttons.emplace_back(std::make_shared<Button>(
|
||||
MAP_WIDTH * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE,
|
||||
renderer, ">", default_button_theme, moveToolsRightButton, &right_tool_input));
|
||||
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
||||
global_vars.buttons.back()->setPermanent();
|
||||
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
|
||||
left_tool_input.other_button = global_vars.buttons.back();
|
||||
global_vars.tool.button_right_tools = global_vars.buttons.back();
|
||||
// ensure disabled/enabled properly
|
||||
toolMoveUpdateButtons(right_tool_input.other_button.get(), global_vars.buttons.back().get(), global_vars.tool.cur_page_tools, global_vars.tool.max_page_tools, false);
|
||||
createGrid((MAP_WIDTH - TOOLS_WIDTH) * BLOCK_SIZE,
|
||||
1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, TOOLS_WIDTH, 2, scene);
|
||||
// mods
|
||||
@ -1061,31 +1014,6 @@ std::shared_ptr<SDLPP::Scene> createEditorMainScene(std::shared_ptr<SDLPP::Rende
|
||||
1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, ToolType::MOD,
|
||||
possibleMods, global_vars.mods, global_vars.mod_boxes,
|
||||
scene, "MODS", font_config);
|
||||
// left mod arrow
|
||||
auto &left_mod_input = arrowInputs[4];
|
||||
left_mod_input.scene = scene;
|
||||
left_mod_input.other_button = nullptr;
|
||||
global_vars.buttons.emplace_back(std::make_shared<Button>(
|
||||
4 * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE,
|
||||
renderer, "<", default_button_theme, moveModsLeft, &left_mod_input));
|
||||
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
||||
global_vars.buttons.back()->setPermanent();
|
||||
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
|
||||
global_vars.tool.button_left_mods = global_vars.buttons.back();
|
||||
// right mod arrow
|
||||
auto &right_mod_input = arrowInputs[5];
|
||||
right_mod_input.scene = scene;
|
||||
right_mod_input.other_button = global_vars.buttons.back();
|
||||
global_vars.buttons.emplace_back(std::make_shared<Button>(
|
||||
(MOD_WIDTH + 5) * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE,
|
||||
renderer, ">", default_button_theme, moveModsRight, &right_mod_input));
|
||||
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
||||
global_vars.buttons.back()->setPermanent();
|
||||
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
|
||||
left_mod_input.other_button = global_vars.buttons.back();
|
||||
global_vars.tool.button_right_mods = global_vars.buttons.back();
|
||||
// ensure disabled/enabled properly
|
||||
toolMoveUpdateButtons(right_mod_input.other_button.get(), global_vars.buttons.back().get(), global_vars.tool.cur_page_mods, global_vars.tool.max_page_mods, false);
|
||||
createGrid(5 * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, MOD_WIDTH, 2,
|
||||
scene);
|
||||
// characters
|
||||
@ -1094,31 +1022,6 @@ std::shared_ptr<SDLPP::Scene> createEditorMainScene(std::shared_ptr<SDLPP::Rende
|
||||
possibleCharacters, global_vars.characters,
|
||||
global_vars.character_boxes, scene, "CHARACTERS",
|
||||
font_config);
|
||||
// left character arrow
|
||||
auto &left_character_input = arrowInputs[6];
|
||||
left_character_input.scene = scene;
|
||||
left_character_input.other_button = nullptr;
|
||||
global_vars.buttons.emplace_back(std::make_shared<Button>(
|
||||
(MOD_WIDTH + 7) * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE,
|
||||
renderer, "<", default_button_theme, moveCharsLeft, &left_character_input));
|
||||
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
||||
global_vars.buttons.back()->setPermanent();
|
||||
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
|
||||
global_vars.tool.button_left_characters = global_vars.buttons.back();
|
||||
// right character arrow
|
||||
auto &right_character_input = arrowInputs[7];
|
||||
right_character_input.scene = scene;
|
||||
right_character_input.other_button = global_vars.buttons.back();
|
||||
global_vars.buttons.emplace_back(std::make_shared<Button>(
|
||||
(MOD_WIDTH + 8 + CHARACTER_WIDTH) * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE,
|
||||
renderer, ">", default_button_theme, moveCharsRight, &right_character_input));
|
||||
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
||||
global_vars.buttons.back()->setPermanent();
|
||||
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
|
||||
global_vars.tool.button_right_characters = global_vars.buttons.back();
|
||||
// ensure disabled/enabled properly
|
||||
toolMoveUpdateButtons(right_character_input.other_button.get(), global_vars.buttons.back().get(), global_vars.tool.cur_page_characters, global_vars.tool.max_page_characters, false);
|
||||
left_character_input.other_button = global_vars.buttons.back();
|
||||
createGrid((MOD_WIDTH + 8) * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE,
|
||||
CHARACTER_WIDTH, 2, scene);
|
||||
|
||||
@ -1130,6 +1033,8 @@ std::shared_ptr<SDLPP::Scene> createEditorMainScene(std::shared_ptr<SDLPP::Rende
|
||||
2, scene);
|
||||
|
||||
global_vars.map.max_page = global_vars.objects.size() - MAP_WIDTH;
|
||||
// arrowInputs[1] - rightMapInput, arrowInputs[0] - leftMapInput
|
||||
toolMoveUpdateButtons(arrowInputs[1].other_button.get(), arrowInputs[0].other_button.get(), global_vars.map.cur_page, global_vars.map.max_page, true);
|
||||
|
||||
auto mouse =
|
||||
std::make_shared<SDLPP::RectangleRender>(0.01, 0.01, 0, 0, renderer);
|
||||
@ -1176,9 +1081,6 @@ std::shared_ptr<SDLPP::Scene> createEditorMainScene(std::shared_ptr<SDLPP::Rende
|
||||
updateToolSelection(0, ToolType::CHARACTER);
|
||||
setToolColor();
|
||||
|
||||
global_vars.buttons.emplace_back(std::make_shared<Button>(0, 0, 0.2, 0.2, renderer, "CLICK ME", default_button_theme, testButtonFunc, &click_num));
|
||||
global_vars.buttons.back()->setPermanent();
|
||||
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
|
||||
for(auto &button : global_vars.buttons) {
|
||||
scene->addObject(button);
|
||||
}
|
||||
@ -1187,17 +1089,141 @@ std::shared_ptr<SDLPP::Scene> createEditorMainScene(std::shared_ptr<SDLPP::Rende
|
||||
global_vars.tool.cur_page_tools = 0;
|
||||
global_vars.tool.cur_page_mods = 0;
|
||||
global_vars.tool.cur_page_characters = 0;
|
||||
}
|
||||
|
||||
std::shared_ptr<SDLPP::Scene> createEditorMainScene(std::shared_ptr<SDLPP::Renderer> &renderer) {
|
||||
auto scene = std::make_shared<SDLPP::Scene>(renderer);
|
||||
|
||||
global_vars.tool.max_page_tools =
|
||||
(possibleBlocks.size() - 1) / (2 * TOOLS_WIDTH);
|
||||
global_vars.tool.max_page_mods =
|
||||
(possibleMods.size() - 1) / (2 * MOD_WIDTH);
|
||||
global_vars.tool.max_page_characters =
|
||||
(possibleCharacters.size() - 1) / (2 * CHARACTER_WIDTH);
|
||||
|
||||
// create buttons
|
||||
ButtonConfig default_button_theme{};
|
||||
default_button_theme.bg_color = "#FFFFFF88";
|
||||
default_button_theme.bg_color_highlight = "#FFFFFFBB";
|
||||
default_button_theme.bg_color_disabled = "#AAAAAA88";
|
||||
default_button_theme.font_color = "#000000";
|
||||
default_button_theme.font_color_highlight = "#000000";
|
||||
default_button_theme.font_color_disabled = "#555555";
|
||||
default_button_theme.font_outline_color = "#FFFFFF88";
|
||||
default_button_theme.font_outline_color_highlight = "#FFFFFFAA";
|
||||
default_button_theme.font_outline_color_disabled = "#787878";
|
||||
default_button_theme.outline = 0.1;
|
||||
|
||||
// left map arrow
|
||||
arrowInputs.resize(8);
|
||||
auto &left_map_input = arrowInputs[0];
|
||||
left_map_input.scene = scene;
|
||||
left_map_input.other_button = nullptr;
|
||||
global_vars.buttons.emplace_back(std::make_shared<Button>(
|
||||
0, 1 - MAP_HEIGHT * BLOCK_SIZE, BLOCK_SIZE, MAP_HEIGHT * BLOCK_SIZE,
|
||||
renderer, "<", default_button_theme, moveMapLeft, &left_map_input));
|
||||
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
||||
global_vars.buttons.back()->setPermanent();
|
||||
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
|
||||
// right map arrow
|
||||
auto &right_map_input = arrowInputs[1];
|
||||
right_map_input.scene = scene;
|
||||
right_map_input.other_button = global_vars.buttons.back();
|
||||
global_vars.buttons.emplace_back(std::make_shared<Button>(
|
||||
(MAP_WIDTH + 1) * BLOCK_SIZE, 1 - MAP_HEIGHT * BLOCK_SIZE, BLOCK_SIZE, MAP_HEIGHT * BLOCK_SIZE,
|
||||
renderer, ">", default_button_theme, moveMapRight, &right_map_input));
|
||||
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
||||
global_vars.buttons.back()->setPermanent();
|
||||
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
|
||||
left_map_input.other_button = global_vars.buttons.back();
|
||||
// ensure disabled/enabled properly
|
||||
toolMoveUpdateButtons(right_map_input.other_button.get(), global_vars.buttons.back().get(), global_vars.map.cur_page, global_vars.map.max_page, true);
|
||||
|
||||
// left tool arrow
|
||||
auto &left_tool_input = arrowInputs[2];
|
||||
left_tool_input.scene = scene;
|
||||
left_tool_input.other_button = nullptr;
|
||||
global_vars.buttons.emplace_back(std::make_shared<Button>(
|
||||
(MAP_WIDTH - TOOLS_WIDTH - 1) * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE,
|
||||
renderer, "<", default_button_theme, moveToolsLeftButton, &left_tool_input));
|
||||
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
||||
global_vars.buttons.back()->setPermanent();
|
||||
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
|
||||
global_vars.tool.button_left_tools = global_vars.buttons.back();
|
||||
// right tool arrow
|
||||
auto &right_tool_input = arrowInputs[3];
|
||||
right_tool_input.scene = scene;
|
||||
right_tool_input.other_button = global_vars.buttons.back();
|
||||
global_vars.buttons.emplace_back(std::make_shared<Button>(
|
||||
MAP_WIDTH * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE,
|
||||
renderer, ">", default_button_theme, moveToolsRightButton, &right_tool_input));
|
||||
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
||||
global_vars.buttons.back()->setPermanent();
|
||||
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
|
||||
left_tool_input.other_button = global_vars.buttons.back();
|
||||
global_vars.tool.button_right_tools = global_vars.buttons.back();
|
||||
// ensure disabled/enabled properly
|
||||
toolMoveUpdateButtons(right_tool_input.other_button.get(), global_vars.buttons.back().get(), global_vars.tool.cur_page_tools, global_vars.tool.max_page_tools, false);
|
||||
|
||||
// left mod arrow
|
||||
auto &left_mod_input = arrowInputs[4];
|
||||
left_mod_input.scene = scene;
|
||||
left_mod_input.other_button = nullptr;
|
||||
global_vars.buttons.emplace_back(std::make_shared<Button>(
|
||||
4 * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE,
|
||||
renderer, "<", default_button_theme, moveModsLeft, &left_mod_input));
|
||||
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
||||
global_vars.buttons.back()->setPermanent();
|
||||
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
|
||||
global_vars.tool.button_left_mods = global_vars.buttons.back();
|
||||
// right mod arrow
|
||||
auto &right_mod_input = arrowInputs[5];
|
||||
right_mod_input.scene = scene;
|
||||
right_mod_input.other_button = global_vars.buttons.back();
|
||||
global_vars.buttons.emplace_back(std::make_shared<Button>(
|
||||
(MOD_WIDTH + 5) * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE,
|
||||
renderer, ">", default_button_theme, moveModsRight, &right_mod_input));
|
||||
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
||||
global_vars.buttons.back()->setPermanent();
|
||||
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
|
||||
left_mod_input.other_button = global_vars.buttons.back();
|
||||
global_vars.tool.button_right_mods = global_vars.buttons.back();
|
||||
// ensure disabled/enabled properly
|
||||
toolMoveUpdateButtons(right_mod_input.other_button.get(), global_vars.buttons.back().get(), global_vars.tool.cur_page_mods, global_vars.tool.max_page_mods, false);
|
||||
|
||||
// left character arrow
|
||||
auto &left_character_input = arrowInputs[6];
|
||||
left_character_input.scene = scene;
|
||||
left_character_input.other_button = nullptr;
|
||||
global_vars.buttons.emplace_back(std::make_shared<Button>(
|
||||
(MOD_WIDTH + 7) * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE,
|
||||
renderer, "<", default_button_theme, moveCharsLeft, &left_character_input));
|
||||
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
||||
global_vars.buttons.back()->setPermanent();
|
||||
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
|
||||
global_vars.tool.button_left_characters = global_vars.buttons.back();
|
||||
// right character arrow
|
||||
auto &right_character_input = arrowInputs[7];
|
||||
right_character_input.scene = scene;
|
||||
right_character_input.other_button = global_vars.buttons.back();
|
||||
global_vars.buttons.emplace_back(std::make_shared<Button>(
|
||||
(MOD_WIDTH + 8 + CHARACTER_WIDTH) * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE,
|
||||
renderer, ">", default_button_theme, moveCharsRight, &right_character_input));
|
||||
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
||||
global_vars.buttons.back()->setPermanent();
|
||||
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
|
||||
global_vars.tool.button_right_characters = global_vars.buttons.back();
|
||||
// ensure disabled/enabled properly
|
||||
toolMoveUpdateButtons(right_character_input.other_button.get(), global_vars.buttons.back().get(), global_vars.tool.cur_page_characters, global_vars.tool.max_page_characters, false);
|
||||
left_character_input.other_button = global_vars.buttons.back();
|
||||
|
||||
openMapEditor(scene, "");
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
void editorAdditionalRender(std::shared_ptr<SDLPP::Scene> &scene) {
|
||||
g_quit = getFlag(QUIT_FLAG);
|
||||
if(g_quit) {
|
||||
saveMap("test_binary2.bin", global_vars.objects);
|
||||
std::cout << "QUIT" << std::endl;
|
||||
}
|
||||
click_num = (click_num + 1) % 256;
|
||||
for(auto &button : global_vars.buttons) {
|
||||
button->update();
|
||||
}
|
||||
@ -1205,6 +1231,12 @@ void editorAdditionalRender(std::shared_ptr<SDLPP::Scene> &scene) {
|
||||
scene->updateSizeAndPosition();
|
||||
unsetFlag(UPDATE_FLAG);
|
||||
}
|
||||
if (getFlag(LOAD_MAP_FLAG)) {
|
||||
// TODO filename
|
||||
editorScene->resetScene();
|
||||
openMapEditor(editorScene, "test_binary.bin");
|
||||
unsetFlag(LOAD_MAP_FLAG);
|
||||
}
|
||||
}
|
||||
|
||||
SceneStruct createEditorScene(std::shared_ptr<SDLPP::Renderer> &renderer) {
|
||||
@ -1212,6 +1244,8 @@ SceneStruct createEditorScene(std::shared_ptr<SDLPP::Renderer> &renderer) {
|
||||
ret.scene = createEditorMainScene(renderer);
|
||||
ret.doInput = pollEvents;
|
||||
ret.additionalRender = editorAdditionalRender;
|
||||
editorScene = ret.scene;
|
||||
|
||||
mainMenuScene = createEditorMainMenuScene(renderer);
|
||||
// fileChoiceScene = createEditorFileChoiceScene(renderer);
|
||||
return ret;
|
||||
|
@ -80,13 +80,25 @@ std::shared_ptr<SDLPP::Scene> createSceneMainMenu(std::shared_ptr<SDLPP::Rendere
|
||||
default_button_theme.outline = 0.1;
|
||||
// buttons
|
||||
__buttons_main_menu.emplace_back(std::make_shared<Button>(
|
||||
0.2, 0.3, 0.6, 0.1,
|
||||
0.2, 0.25, 0.6, 0.1,
|
||||
renderer, "SAVE", default_button_theme, saveMapCallback, nullptr));
|
||||
__buttons_main_menu.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
||||
__buttons_main_menu.back()->setPermanent();
|
||||
__buttons_main_menu.back()->setButtonIndex(__buttons_main_menu.size() - 1);
|
||||
__buttons_main_menu.emplace_back(std::make_shared<Button>(
|
||||
0.2, 0.4, 0.6, 0.1,
|
||||
renderer, "LOAD", default_button_theme, loadMapDialogCallback, nullptr));
|
||||
__buttons_main_menu.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
||||
__buttons_main_menu.back()->setPermanent();
|
||||
__buttons_main_menu.back()->setButtonIndex(__buttons_main_menu.size() - 1);
|
||||
__buttons_main_menu.emplace_back(std::make_shared<Button>(
|
||||
0.2, 0.55, 0.6, 0.1,
|
||||
renderer, "RESUME", default_button_theme, resumeMainMenuCallback, nullptr));
|
||||
__buttons_main_menu.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
||||
__buttons_main_menu.back()->setPermanent();
|
||||
__buttons_main_menu.back()->setButtonIndex(__buttons_main_menu.size() - 1);
|
||||
__buttons_main_menu.emplace_back(std::make_shared<Button>(
|
||||
0.2, 0.45, 0.6, 0.1,
|
||||
0.2, 0.7, 0.6, 0.1,
|
||||
renderer, "QUIT", default_button_theme, quitMainMenuCallback, nullptr));
|
||||
__buttons_main_menu.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
||||
__buttons_main_menu.back()->setPermanent();
|
||||
|
@ -2,6 +2,7 @@
|
||||
#define EDITOR_MAIN_HPP
|
||||
|
||||
#include "../../sdlpp/sdlpp_scene.hpp"
|
||||
#include "../gui/gui.hpp"
|
||||
#include <functional>
|
||||
|
||||
struct SceneStruct {
|
||||
@ -13,6 +14,9 @@ struct SceneStruct {
|
||||
extern std::mutex render_mutex;
|
||||
extern std::vector<SceneStruct> game_scenes;
|
||||
|
||||
void saveMapCallback(void *input, Button *caller);
|
||||
void loadMapDialogCallback(void *input, Button *caller);
|
||||
|
||||
SceneStruct createEditorScene(std::shared_ptr<SDLPP::Renderer> &renderer);
|
||||
SceneStruct createEditorMainMenuScene(std::shared_ptr<SDLPP::Renderer> &renderer);
|
||||
SceneStruct createEditorFileChoiceScene(std::shared_ptr<SDLPP::Renderer> &renderer);
|
||||
|
Loading…
Reference in New Issue
Block a user