Move map/tool controls to new button API
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
94d24e37fa
commit
194415500d
315
mario/editor.cpp
315
mario/editor.cpp
@ -1,6 +1,7 @@
|
|||||||
#include "../sdlpp/sdlpp.hpp"
|
#include "../sdlpp/sdlpp.hpp"
|
||||||
#include "gui/gui.hpp"
|
#include "gui/gui.hpp"
|
||||||
#include "sprites.hpp"
|
#include "sprites.hpp"
|
||||||
|
#include <memory>
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include "../sdlpp/SDL2/SDL2_framerate.h"
|
#include "../sdlpp/SDL2/SDL2_framerate.h"
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
@ -520,55 +521,115 @@ void getMousePositionFlags(SDLPP::Scene &scene) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void mouseUpAction(uint64_t flags, SDLPP::Scene &scene) {
|
struct moveStruct {
|
||||||
if (MouseVisitor::moveMapLeft(flags) && global_vars.map.cur_page != 0) {
|
std::shared_ptr<SDLPP::Scene> scene;
|
||||||
global_vars.map.cur_page--;
|
std::shared_ptr<Button> other_button;
|
||||||
scene.moveEverything(BLOCK_SIZE, 0);
|
};
|
||||||
|
|
||||||
|
void toolMoveLeftUpdateButtons(Button *left, Button *right, int &cur_page, int &max_page, bool canAdd) {
|
||||||
|
if(cur_page == 0) {
|
||||||
|
left->disable(render_mutex);
|
||||||
}
|
}
|
||||||
if (MouseVisitor::moveMapRight(flags)) {
|
if(cur_page != max_page) {
|
||||||
if (global_vars.map.cur_page == global_vars.map.max_page) {
|
if(canAdd) {
|
||||||
// add column
|
// TOOD global button config
|
||||||
|
right->changeText(">");
|
||||||
|
right->setFontColor("#000000", render_mutex);
|
||||||
|
right->setFontOutlineColor("#FFFFFF88", render_mutex);
|
||||||
|
right->setFontColorHighlight("#000000", render_mutex);
|
||||||
|
right->setFontOutlineColorHighlight("#FFFFFFAA", render_mutex);
|
||||||
|
} else {
|
||||||
|
right->enable(render_mutex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void toolMoveLeft(Button *left, Button *right, int &cur_page, int &max_page, bool canAdd) {
|
||||||
|
cur_page--;
|
||||||
|
toolMoveLeftUpdateButtons(left, right, cur_page, max_page, canAdd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void toolMoveRightUpdateButtons(Button *left, Button *right, int &cur_page, int &max_page, bool canAdd) {
|
||||||
|
if(cur_page == max_page) {
|
||||||
|
if(canAdd) {
|
||||||
|
right->changeText("+");
|
||||||
|
right->setFontColor("#00FF00", render_mutex);
|
||||||
|
right->setFontOutlineColor("#000000", render_mutex);
|
||||||
|
right->setFontColorHighlight("#88FF88", render_mutex);
|
||||||
|
right->setFontOutlineColorHighlight("#444444", render_mutex);
|
||||||
|
} else {
|
||||||
|
right->disable(render_mutex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(cur_page != 0) {
|
||||||
|
left->enable(render_mutex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void toolMoveRight(Button *left, Button *right, int &cur_page, int &max_page, bool canAdd) {
|
||||||
|
cur_page += 1;
|
||||||
|
toolMoveRightUpdateButtons(left, right, cur_page, max_page, canAdd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void moveMapLeft(void *input, Button *caller) {
|
||||||
|
auto actual_input = static_cast<moveStruct*>(input);
|
||||||
|
actual_input->scene->moveEverything(BLOCK_SIZE, 0);
|
||||||
|
toolMoveLeft(caller, actual_input->other_button.get(), global_vars.map.cur_page, global_vars.map.max_page, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void moveMapRight(void *input, Button *caller) {
|
||||||
|
auto actual_input = static_cast<moveStruct*>(input);
|
||||||
|
if (global_vars.map.cur_page == global_vars.map.max_page) { // add column
|
||||||
global_vars.objects.resize(global_vars.objects.size() + 1);
|
global_vars.objects.resize(global_vars.objects.size() + 1);
|
||||||
global_vars.map.max_page++;
|
global_vars.map.max_page++;
|
||||||
}
|
}
|
||||||
global_vars.map.cur_page += 1;
|
toolMoveRight(actual_input->other_button.get(), caller, global_vars.map.cur_page, global_vars.map.max_page, true);
|
||||||
scene.moveEverything(-BLOCK_SIZE, 0);
|
actual_input->scene->moveEverything(-BLOCK_SIZE, 0);
|
||||||
}
|
}
|
||||||
if (MouseVisitor::moveToolsLeft(flags) &&
|
|
||||||
global_vars.tool.cur_page_tools != 0) {
|
void moveToolsLeftButton(void *input, Button *caller) {
|
||||||
global_vars.tool.cur_page_tools--;
|
auto actual_input = static_cast<moveStruct*>(input);
|
||||||
|
toolMoveLeft(caller, actual_input->other_button.get(), global_vars.tool.cur_page_tools, global_vars.tool.max_page_tools, false);
|
||||||
updateToolSelection(global_vars.tool.cur_page_tools + 1,
|
updateToolSelection(global_vars.tool.cur_page_tools + 1,
|
||||||
ToolType::BLOCK);
|
ToolType::BLOCK);
|
||||||
}
|
}
|
||||||
if (MouseVisitor::moveToolsRight(flags) &&
|
|
||||||
global_vars.tool.cur_page_tools != global_vars.tool.max_page_tools) {
|
void moveToolsRightButton(void *input, Button *caller) {
|
||||||
global_vars.tool.cur_page_tools++;
|
auto actual_input = static_cast<moveStruct*>(input);
|
||||||
|
toolMoveRight(actual_input->other_button.get(), caller, global_vars.tool.cur_page_tools, global_vars.tool.max_page_tools, false);
|
||||||
updateToolSelection(global_vars.tool.cur_page_tools - 1,
|
updateToolSelection(global_vars.tool.cur_page_tools - 1,
|
||||||
ToolType::BLOCK);
|
ToolType::BLOCK);
|
||||||
}
|
}
|
||||||
if (MouseVisitor::moveModsLeft(flags) &&
|
|
||||||
global_vars.tool.cur_page_mods != 0) {
|
void moveModsLeft(void *input, Button *caller) {
|
||||||
global_vars.tool.cur_page_mods--;
|
auto actual_input = static_cast<moveStruct*>(input);
|
||||||
updateToolSelection(global_vars.tool.cur_page_mods + 1, ToolType::MOD);
|
toolMoveLeft(caller, actual_input->other_button.get(), global_vars.tool.cur_page_mods, global_vars.tool.max_page_mods, false);
|
||||||
}
|
updateToolSelection(global_vars.tool.cur_page_tools + 1,
|
||||||
if (MouseVisitor::moveModsRight(flags) &&
|
ToolType::MOD);
|
||||||
global_vars.tool.cur_page_mods != global_vars.tool.max_page_mods) {
|
}
|
||||||
global_vars.tool.cur_page_mods++;
|
|
||||||
updateToolSelection(global_vars.tool.cur_page_mods - 1, ToolType::MOD);
|
void moveModsRight(void *input, Button *caller) {
|
||||||
}
|
auto actual_input = static_cast<moveStruct*>(input);
|
||||||
if (MouseVisitor::moveCharactersLeft(flags) &&
|
toolMoveRight(actual_input->other_button.get(), caller, global_vars.tool.cur_page_mods, global_vars.tool.max_page_mods, false);
|
||||||
global_vars.tool.cur_page_characters != 0) {
|
updateToolSelection(global_vars.tool.cur_page_tools - 1,
|
||||||
global_vars.tool.cur_page_characters--;
|
ToolType::MOD);
|
||||||
updateToolSelection(global_vars.tool.cur_page_characters + 1,
|
}
|
||||||
|
|
||||||
|
void moveCharsLeft(void *input, Button *caller) {
|
||||||
|
auto actual_input = static_cast<moveStruct*>(input);
|
||||||
|
toolMoveLeft(caller, actual_input->other_button.get(), global_vars.tool.cur_page_characters, global_vars.tool.max_page_characters, false);
|
||||||
|
updateToolSelection(global_vars.tool.cur_page_tools + 1,
|
||||||
ToolType::CHARACTER);
|
ToolType::CHARACTER);
|
||||||
}
|
}
|
||||||
if (MouseVisitor::moveCharactersRight(flags) &&
|
|
||||||
global_vars.tool.cur_page_characters !=
|
void moveCharsRight(void *input, Button *caller) {
|
||||||
global_vars.tool.max_page_characters) {
|
auto actual_input = static_cast<moveStruct*>(input);
|
||||||
global_vars.tool.cur_page_characters++;
|
toolMoveRight(actual_input->other_button.get(), caller, global_vars.tool.cur_page_characters, global_vars.tool.max_page_characters, false);
|
||||||
updateToolSelection(global_vars.tool.cur_page_characters - 1,
|
updateToolSelection(global_vars.tool.cur_page_tools - 1,
|
||||||
ToolType::CHARACTER);
|
ToolType::CHARACTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void mouseUpAction(uint64_t flags) {
|
||||||
if(MouseVisitor::button(flags)) {
|
if(MouseVisitor::button(flags)) {
|
||||||
global_vars.buttons[global_vars.mouse.cur_button_index]->performFunction();
|
global_vars.buttons[global_vars.mouse.cur_button_index]->performFunction();
|
||||||
}
|
}
|
||||||
@ -701,7 +762,7 @@ void pollEvents(SDLPP::Scene &scene) {
|
|||||||
break;
|
break;
|
||||||
case SDL_MOUSEBUTTONUP:
|
case SDL_MOUSEBUTTONUP:
|
||||||
if (global_vars.mouse.cur_flags == global_vars.mouse.prev_flags) {
|
if (global_vars.mouse.cur_flags == global_vars.mouse.prev_flags) {
|
||||||
mouseUpAction(global_vars.mouse.cur_flags, scene);
|
mouseUpAction(global_vars.mouse.cur_flags);
|
||||||
}
|
}
|
||||||
if (global_vars.mouse.edit_box.getX() != 0) {
|
if (global_vars.mouse.edit_box.getX() != 0) {
|
||||||
placeTool(scene);
|
placeTool(scene);
|
||||||
@ -931,7 +992,7 @@ void populateWorldType(
|
|||||||
scene->addObject(tool_text);
|
scene->addObject(tool_text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void checkArrowsEnabled(uint64_t cur_page, uint64_t max_page,
|
/*void checkArrowsEnabled(uint64_t cur_page, uint64_t max_page,
|
||||||
uint64_t left_flag, uint64_t right_flag,
|
uint64_t left_flag, uint64_t right_flag,
|
||||||
std::shared_ptr<SDLPP::TextRenderer> &left_arrow,
|
std::shared_ptr<SDLPP::TextRenderer> &left_arrow,
|
||||||
std::shared_ptr<SDLPP::TextRenderer> &right_arrow,
|
std::shared_ptr<SDLPP::TextRenderer> &right_arrow,
|
||||||
@ -962,12 +1023,12 @@ void checkArrowsEnabled(uint64_t cur_page, uint64_t max_page,
|
|||||||
right_arrow->changeText(">");
|
right_arrow->changeText(">");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
void testButtonFunc(void *input) {
|
void testButtonFunc(void *input, Button *caller) {
|
||||||
auto actual = static_cast<int*>(input);
|
auto actual = static_cast<int*>(input);
|
||||||
std::cout << "NUM: " << *actual << std::endl;
|
std::cout << "NUM: " << *actual << std::endl;
|
||||||
global_vars.buttons[0]->disable(render_mutex);
|
caller->disable(render_mutex);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
@ -1025,12 +1086,49 @@ int main() {
|
|||||||
|
|
||||||
// create grids and arrow controls
|
// create grids and arrow controls
|
||||||
// map
|
// map
|
||||||
auto arrows = createArrowControls(
|
/* auto arrows = createArrowControls(
|
||||||
0, (MAP_WIDTH + 1) * BLOCK_SIZE, 1 - MAP_HEIGHT * BLOCK_SIZE,
|
0, (MAP_WIDTH + 1) * BLOCK_SIZE, 1 - MAP_HEIGHT * BLOCK_SIZE,
|
||||||
MAP_HEIGHT * BLOCK_SIZE, EDITOR_LEFT_MAP_ID, EDITOR_RIGHT_MAP_ID, scene,
|
MAP_HEIGHT * BLOCK_SIZE, EDITOR_LEFT_MAP_ID, EDITOR_RIGHT_MAP_ID, scene,
|
||||||
font_config);
|
font_config);
|
||||||
auto left_map_arrow = arrows.first;
|
auto left_map_arrow = arrows.first;
|
||||||
auto right_map_arrow = arrows.second;
|
auto right_map_arrow = arrows.second;*/
|
||||||
|
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
|
||||||
|
moveStruct left_map_input{
|
||||||
|
.scene = scene,
|
||||||
|
.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
|
||||||
|
moveStruct right_map_input{
|
||||||
|
.scene = scene,
|
||||||
|
.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
|
||||||
|
toolMoveRightUpdateButtons(right_map_input.other_button.get(), global_vars.buttons.back().get(), global_vars.map.cur_page, global_vars.map.max_page, true);
|
||||||
|
toolMoveLeftUpdateButtons(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,
|
createGrid(BLOCK_SIZE, 1 - MAP_HEIGHT * BLOCK_SIZE, MAP_WIDTH, MAP_HEIGHT,
|
||||||
scene);
|
scene);
|
||||||
// edit blocks on map
|
// edit blocks on map
|
||||||
@ -1042,17 +1140,50 @@ int main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
// tools
|
// tools
|
||||||
populateToolGrid(TOOLS_WIDTH, 2, (MAP_WIDTH - TOOLS_WIDTH) * BLOCK_SIZE,
|
populateToolGrid(TOOLS_WIDTH, 2, (MAP_WIDTH - TOOLS_WIDTH) * BLOCK_SIZE,
|
||||||
1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, ToolType::BLOCK,
|
1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, ToolType::BLOCK,
|
||||||
possibleBlocks, global_vars.tools, global_vars.tool_boxes,
|
possibleBlocks, global_vars.tools, global_vars.tool_boxes,
|
||||||
scene, "TERRAIN", font_config);
|
scene, "TERRAIN", font_config);
|
||||||
arrows = createArrowControls(
|
/* arrows = createArrowControls(
|
||||||
(MAP_WIDTH - TOOLS_WIDTH - 1) * BLOCK_SIZE, MAP_WIDTH * BLOCK_SIZE,
|
(MAP_WIDTH - TOOLS_WIDTH - 1) * BLOCK_SIZE, MAP_WIDTH * BLOCK_SIZE,
|
||||||
1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, 2 * BLOCK_SIZE, EDITOR_LEFT_TOOL_ID,
|
1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, 2 * BLOCK_SIZE, EDITOR_LEFT_TOOL_ID,
|
||||||
EDITOR_RIGHT_TOOL_ID, scene, font_config);
|
EDITOR_RIGHT_TOOL_ID, scene, font_config);
|
||||||
auto left_tool_arrow = arrows.first;
|
auto left_tool_arrow = arrows.first;
|
||||||
auto right_tool_arrow = arrows.second;
|
auto right_tool_arrow = arrows.second;*/
|
||||||
|
// left tool arrow
|
||||||
|
moveStruct left_tool_input{
|
||||||
|
.scene = scene,
|
||||||
|
.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);
|
||||||
|
// right tool arrow
|
||||||
|
moveStruct right_tool_input{
|
||||||
|
.scene = scene,
|
||||||
|
.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();
|
||||||
|
// ensure disabled/enabled properly
|
||||||
|
toolMoveRightUpdateButtons(right_tool_input.other_button.get(), global_vars.buttons.back().get(), global_vars.tool.cur_page_tools, global_vars.tool.max_page_tools, false);
|
||||||
|
toolMoveLeftUpdateButtons(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,
|
createGrid((MAP_WIDTH - TOOLS_WIDTH) * BLOCK_SIZE,
|
||||||
1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, TOOLS_WIDTH, 2, scene);
|
1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, TOOLS_WIDTH, 2, scene);
|
||||||
// mods
|
// mods
|
||||||
@ -1060,12 +1191,38 @@ int main() {
|
|||||||
1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, ToolType::MOD,
|
1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, ToolType::MOD,
|
||||||
possibleMods, global_vars.mods, global_vars.mod_boxes,
|
possibleMods, global_vars.mods, global_vars.mod_boxes,
|
||||||
scene, "MODS", font_config);
|
scene, "MODS", font_config);
|
||||||
arrows = createArrowControls(4 * BLOCK_SIZE, (MOD_WIDTH + 5) * BLOCK_SIZE,
|
/* arrows = createArrowControls(4 * BLOCK_SIZE, (MOD_WIDTH + 5) * BLOCK_SIZE,
|
||||||
1 - (MAP_HEIGHT + 3) * BLOCK_SIZE,
|
1 - (MAP_HEIGHT + 3) * BLOCK_SIZE,
|
||||||
2 * BLOCK_SIZE, EDITOR_LEFT_MOD_ID,
|
2 * BLOCK_SIZE, EDITOR_LEFT_MOD_ID,
|
||||||
EDITOR_RIGHT_MOD_ID, scene, font_config);
|
EDITOR_RIGHT_MOD_ID, scene, font_config);
|
||||||
auto left_mod_arrow = arrows.first;
|
auto left_mod_arrow = arrows.first;
|
||||||
auto right_mod_arrow = arrows.second;
|
auto right_mod_arrow = arrows.second;*/
|
||||||
|
// left mod arrow
|
||||||
|
moveStruct left_mod_input{
|
||||||
|
.scene = scene,
|
||||||
|
.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);
|
||||||
|
// right mod arrow
|
||||||
|
moveStruct right_mod_input{
|
||||||
|
.scene = scene,
|
||||||
|
.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();
|
||||||
|
// ensure disabled/enabled properly
|
||||||
|
toolMoveRightUpdateButtons(right_mod_input.other_button.get(), global_vars.buttons.back().get(), global_vars.tool.cur_page_mods, global_vars.tool.max_page_mods, false);
|
||||||
|
toolMoveLeftUpdateButtons(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,
|
createGrid(5 * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, MOD_WIDTH, 2,
|
||||||
scene);
|
scene);
|
||||||
// characters
|
// characters
|
||||||
@ -1074,13 +1231,39 @@ int main() {
|
|||||||
possibleCharacters, global_vars.characters,
|
possibleCharacters, global_vars.characters,
|
||||||
global_vars.character_boxes, scene, "CHARACTERS",
|
global_vars.character_boxes, scene, "CHARACTERS",
|
||||||
font_config);
|
font_config);
|
||||||
arrows = createArrowControls((MOD_WIDTH + 7) * BLOCK_SIZE,
|
/* arrows = createArrowControls((MOD_WIDTH + 7) * BLOCK_SIZE,
|
||||||
(MOD_WIDTH + 8 + CHARACTER_WIDTH) * BLOCK_SIZE,
|
(MOD_WIDTH + 8 + CHARACTER_WIDTH) * BLOCK_SIZE,
|
||||||
1 - (MAP_HEIGHT + 3) * BLOCK_SIZE,
|
1 - (MAP_HEIGHT + 3) * BLOCK_SIZE,
|
||||||
2 * BLOCK_SIZE, EDITOR_LEFT_CHARACTER_ID,
|
2 * BLOCK_SIZE, EDITOR_LEFT_CHARACTER_ID,
|
||||||
EDITOR_RIGHT_CHARACTER_ID, scene, font_config);
|
EDITOR_RIGHT_CHARACTER_ID, scene, font_config);
|
||||||
auto left_char_arrow = arrows.first;
|
auto left_char_arrow = arrows.first;
|
||||||
auto right_char_arrow = arrows.second;
|
auto right_char_arrow = arrows.second;*/
|
||||||
|
// left character arrow
|
||||||
|
moveStruct left_character_input{
|
||||||
|
.scene = scene,
|
||||||
|
.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);
|
||||||
|
// right character arrow
|
||||||
|
moveStruct right_character_input{
|
||||||
|
.scene = scene,
|
||||||
|
.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);
|
||||||
|
// ensure disabled/enabled properly
|
||||||
|
toolMoveRightUpdateButtons(right_character_input.other_button.get(), global_vars.buttons.back().get(), global_vars.tool.cur_page_characters, global_vars.tool.max_page_characters, false);
|
||||||
|
toolMoveLeftUpdateButtons(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,
|
createGrid((MOD_WIDTH + 8) * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE,
|
||||||
CHARACTER_WIDTH, 2, scene);
|
CHARACTER_WIDTH, 2, scene);
|
||||||
|
|
||||||
@ -1093,13 +1276,6 @@ int main() {
|
|||||||
|
|
||||||
global_vars.map.max_page = global_vars.objects.size() - MAP_WIDTH;
|
global_vars.map.max_page = global_vars.objects.size() - MAP_WIDTH;
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
auto mouse =
|
auto mouse =
|
||||||
std::make_shared<SDLPP::RectangleRender>(0.01, 0.01, 0, 0, renderer);
|
std::make_shared<SDLPP::RectangleRender>(0.01, 0.01, 0, 0, renderer);
|
||||||
mouse->setMinWidth(1);
|
mouse->setMinWidth(1);
|
||||||
@ -1148,20 +1324,12 @@ int main() {
|
|||||||
updateToolSelection(0, ToolType::CHARACTER);
|
updateToolSelection(0, ToolType::CHARACTER);
|
||||||
setToolColor();
|
setToolColor();
|
||||||
|
|
||||||
ButtonColors default_button_theme{};
|
|
||||||
default_button_theme.bg_color = "#FF0088";
|
|
||||||
default_button_theme.bg_color_highlight = "#FF00FF";
|
|
||||||
default_button_theme.bg_color_disabled = "#FFAAFF";
|
|
||||||
default_button_theme.font_color = "#FFFFFF";
|
|
||||||
default_button_theme.font_color_highlight = "#FFFFFF";
|
|
||||||
default_button_theme.font_color_disabled = "#BBBBBB";
|
|
||||||
default_button_theme.font_outline_color = "#000000";
|
|
||||||
default_button_theme.font_outline_color_highlight = "#444444";
|
|
||||||
default_button_theme.font_outline_color_disabled = "#888888";
|
|
||||||
global_vars.buttons.emplace_back(std::make_shared<Button>(0, 0, 0.2, 0.2, renderer, "CLICK ME", default_button_theme, testButtonFunc, &num));
|
global_vars.buttons.emplace_back(std::make_shared<Button>(0, 0, 0.2, 0.2, renderer, "CLICK ME", default_button_theme, testButtonFunc, &num));
|
||||||
global_vars.buttons.back()->setStatic();
|
global_vars.buttons.back()->setPermanent();
|
||||||
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
|
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
|
||||||
scene->addObject(global_vars.buttons.back());
|
for(auto &button : global_vars.buttons) {
|
||||||
|
scene->addObject(button);
|
||||||
|
}
|
||||||
|
|
||||||
auto base = SDL_GetTicks();
|
auto base = SDL_GetTicks();
|
||||||
int frames = 0;
|
int frames = 0;
|
||||||
@ -1199,7 +1367,8 @@ int main() {
|
|||||||
frames = 0;
|
frames = 0;
|
||||||
base = SDL_GetTicks();
|
base = SDL_GetTicks();
|
||||||
}
|
}
|
||||||
checkArrowsEnabled(global_vars.map.cur_page, global_vars.map.max_page,
|
// TODO maybe button update func instead of using mutex?
|
||||||
|
/* checkArrowsEnabled(global_vars.map.cur_page, global_vars.map.max_page,
|
||||||
MAP_LEFT_ENABLED_FLAG, MAP_RIGHT_ENABLED_FLAG,
|
MAP_LEFT_ENABLED_FLAG, MAP_RIGHT_ENABLED_FLAG,
|
||||||
left_map_arrow, right_map_arrow, font, true);
|
left_map_arrow, right_map_arrow, font, true);
|
||||||
checkArrowsEnabled(global_vars.tool.cur_page_tools,
|
checkArrowsEnabled(global_vars.tool.cur_page_tools,
|
||||||
@ -1214,7 +1383,7 @@ int main() {
|
|||||||
global_vars.tool.max_page_characters,
|
global_vars.tool.max_page_characters,
|
||||||
CHARACTER_LEFT_ENABLED_FLAG,
|
CHARACTER_LEFT_ENABLED_FLAG,
|
||||||
CHARACTER_RIGHT_ENABLED_FLAG, left_char_arrow,
|
CHARACTER_RIGHT_ENABLED_FLAG, left_char_arrow,
|
||||||
right_char_arrow, font);
|
right_char_arrow, font);*/
|
||||||
if (getFlag(UPDATE_FLAG)) {
|
if (getFlag(UPDATE_FLAG)) {
|
||||||
scene->updateSizeAndPosition();
|
scene->updateSizeAndPosition();
|
||||||
unsetFlag(UPDATE_FLAG);
|
unsetFlag(UPDATE_FLAG);
|
||||||
|
@ -8,9 +8,7 @@
|
|||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#define TEXT_OUTLINE 0.2
|
struct ButtonConfig {
|
||||||
|
|
||||||
struct ButtonColors {
|
|
||||||
std::string font_color;
|
std::string font_color;
|
||||||
std::string font_outline_color;
|
std::string font_outline_color;
|
||||||
std::string bg_color;
|
std::string bg_color;
|
||||||
@ -20,6 +18,7 @@ struct ButtonColors {
|
|||||||
std::string font_color_disabled;
|
std::string font_color_disabled;
|
||||||
std::string font_outline_color_disabled;
|
std::string font_outline_color_disabled;
|
||||||
std::string bg_color_disabled;
|
std::string bg_color_disabled;
|
||||||
|
double outline;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Button : public SDLPP::TextRenderer {
|
class Button : public SDLPP::TextRenderer {
|
||||||
@ -27,73 +26,73 @@ public:
|
|||||||
Button() = delete;
|
Button() = delete;
|
||||||
Button(double x, double y, double w, double h,
|
Button(double x, double y, double w, double h,
|
||||||
std::shared_ptr<SDLPP::Renderer> &r, const std::string &text,
|
std::shared_ptr<SDLPP::Renderer> &r, const std::string &text,
|
||||||
const ButtonColors &colors,
|
const ButtonConfig &config,
|
||||||
std::function<void(void *)> click_fun, void *input)
|
std::function<void(void *, Button *)> click_fun, void *input)
|
||||||
: TextRenderer(x, y, w, h, r, g_text_config->getFont(), text, colors.font_color,
|
: TextRenderer(x, y, w, h, r, g_text_config->getFont(), text, config.font_color,
|
||||||
colors.font_outline_color, TEXT_OUTLINE),
|
config.font_outline_color, config.outline),
|
||||||
click_fun(std::move(click_fun)), func_input(input),
|
click_fun(std::move(click_fun)), func_input(input),
|
||||||
colors(colors) {
|
config(config) {
|
||||||
setColor(colors.bg_color);
|
setColor(config.bg_color);
|
||||||
setId(BUTTON_ID);
|
setId(BUTTON_ID);
|
||||||
addCollision(SDLPP::RectColider(0, 0, 1, 1));
|
addCollision(SDLPP::RectColider(0, 0, 1, 1));
|
||||||
}
|
}
|
||||||
void setFontColor(const std::string &color, std::mutex &mutex) {
|
void setFontColor(const std::string &color, std::mutex &mutex) {
|
||||||
colors.font_color = color;
|
config.font_color = color;
|
||||||
if(!highlighted && !disabled) {
|
if(!highlighted && !disabled) {
|
||||||
updateTextColor(colors.font_color, colors.font_outline_color, mutex);
|
updateTextColor(config.font_color, config.font_outline_color, mutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void setFontColorHighlight(const std::string &color, std::mutex &mutex) {
|
void setFontColorHighlight(const std::string &color, std::mutex &mutex) {
|
||||||
colors.font_color_highlight = color;
|
config.font_color_highlight = color;
|
||||||
if(highlighted && !disabled) {
|
if(highlighted && !disabled) {
|
||||||
updateTextColor(colors.font_color_highlight, colors.font_outline_color_highlight, mutex);
|
updateTextColor(config.font_color_highlight, config.font_outline_color_highlight, mutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void setFontColorDisabled(const std::string &color, std::mutex &mutex) {
|
void setFontColorDisabled(const std::string &color, std::mutex &mutex) {
|
||||||
colors.font_color_disabled = color;
|
config.font_color_disabled = color;
|
||||||
if(disabled) {
|
if(disabled) {
|
||||||
updateTextColor(colors.font_color_disabled, colors.font_outline_color_disabled, mutex);
|
updateTextColor(config.font_color_disabled, config.font_outline_color_disabled, mutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void setFontOutlineColor(const std::string &color, std::mutex &mutex) {
|
void setFontOutlineColor(const std::string &color, std::mutex &mutex) {
|
||||||
colors.font_outline_color = color;
|
config.font_outline_color = color;
|
||||||
if(!highlighted && !disabled) {
|
if(!highlighted && !disabled) {
|
||||||
updateTextColor(colors.font_color, colors.font_outline_color, mutex);
|
updateTextColor(config.font_color, config.font_outline_color, mutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void setFontOutlineColorHighlight(const std::string &color, std::mutex &mutex) {
|
void setFontOutlineColorHighlight(const std::string &color, std::mutex &mutex) {
|
||||||
colors.font_outline_color_highlight = color;
|
config.font_outline_color_highlight = color;
|
||||||
if(highlighted && !disabled) {
|
if(highlighted && !disabled) {
|
||||||
updateTextColor(colors.font_color_highlight, colors.font_outline_color_highlight, mutex);
|
updateTextColor(config.font_color_highlight, config.font_outline_color_highlight, mutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void setFontOutlineColorDisabled(const std::string &color, std::mutex &mutex) {
|
void setFontOutlineColorDisabled(const std::string &color, std::mutex &mutex) {
|
||||||
colors.font_outline_color_disabled = color;
|
config.font_outline_color_disabled = color;
|
||||||
if(disabled) {
|
if(disabled) {
|
||||||
updateTextColor(colors.font_color_disabled, colors.font_outline_color_disabled, mutex);
|
updateTextColor(config.font_color_disabled, config.font_outline_color_disabled, mutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void setBackgroundColor(const std::string &color) {
|
void setBackgroundColor(const std::string &color) {
|
||||||
colors.bg_color = color;
|
config.bg_color = color;
|
||||||
if(!highlighted && !disabled) {
|
if(!highlighted && !disabled) {
|
||||||
setColor(color);
|
setColor(color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void setBackgroundColorHighlight(const std::string &color) {
|
void setBackgroundColorHighlight(const std::string &color) {
|
||||||
colors.bg_color_highlight = color;
|
config.bg_color_highlight = color;
|
||||||
if(highlighted && !disabled) {
|
if(highlighted && !disabled) {
|
||||||
setColor(color);
|
setColor(color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void setBackgroundColorDisabled(const std::string &color) {
|
void setBackgroundColorDisabled(const std::string &color) {
|
||||||
colors.bg_color_disabled = color;
|
config.bg_color_disabled = color;
|
||||||
if(disabled) {
|
if(disabled) {
|
||||||
setColor(color);
|
setColor(color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void performFunction() const {
|
void performFunction() {
|
||||||
if(!disabled) {
|
if(!disabled) {
|
||||||
click_fun(func_input);
|
click_fun(func_input, this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
uint64_t getButtonIndex() const {
|
uint64_t getButtonIndex() const {
|
||||||
@ -104,43 +103,43 @@ public:
|
|||||||
}
|
}
|
||||||
void setHighlight(std::mutex &mutex) {
|
void setHighlight(std::mutex &mutex) {
|
||||||
if(!disabled) {
|
if(!disabled) {
|
||||||
setColor(colors.bg_color_highlight);
|
setColor(config.bg_color_highlight);
|
||||||
updateTextColor(colors.font_color_highlight, colors.font_outline_color_highlight, mutex);
|
updateTextColor(config.font_color_highlight, config.font_outline_color_highlight, mutex);
|
||||||
}
|
}
|
||||||
highlighted = true;
|
highlighted = true;
|
||||||
}
|
}
|
||||||
void unsetHighlight(std::mutex &mutex) {
|
void unsetHighlight(std::mutex &mutex) {
|
||||||
if(!disabled) {
|
if(!disabled) {
|
||||||
setColor(colors.bg_color);
|
setColor(config.bg_color);
|
||||||
updateTextColor(colors.font_color, colors.font_outline_color, mutex);
|
updateTextColor(config.font_color, config.font_outline_color, mutex);
|
||||||
}
|
}
|
||||||
highlighted = false;
|
highlighted = false;
|
||||||
}
|
}
|
||||||
void disable(std::mutex &mutex) {
|
void disable(std::mutex &mutex) {
|
||||||
setColor(colors.bg_color_disabled);
|
setColor(config.bg_color_disabled);
|
||||||
updateTextColor(colors.font_color_disabled, colors.font_outline_color_disabled, mutex);
|
updateTextColor(config.font_color_disabled, config.font_outline_color_disabled, mutex);
|
||||||
disabled = true;
|
disabled = true;
|
||||||
}
|
}
|
||||||
void enable(std::mutex &mutex) {
|
void enable(std::mutex &mutex) {
|
||||||
if(!highlighted) {
|
if(!highlighted) {
|
||||||
setColor(colors.bg_color);
|
setColor(config.bg_color);
|
||||||
updateTextColor(colors.font_color, colors.font_outline_color, mutex);
|
updateTextColor(config.font_color, config.font_outline_color, mutex);
|
||||||
} else {
|
} else {
|
||||||
setColor(colors.bg_color_highlight);
|
setColor(config.bg_color_highlight);
|
||||||
updateTextColor(colors.font_color_highlight, colors.font_outline_color_highlight, mutex);
|
updateTextColor(config.font_color_highlight, config.font_outline_color_highlight, mutex);
|
||||||
}
|
}
|
||||||
disabled = false;
|
disabled = false;
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
void updateTextColor(const std::string &font, const std::string &outline, std::mutex &mutex) {
|
void updateTextColor(const std::string &font, const std::string &outline, std::mutex &mutex) {
|
||||||
std::lock_guard<std::mutex> textUpdate(mutex);
|
std::lock_guard<std::mutex> textUpdate(mutex);
|
||||||
setTextColor(g_text_config->getFont(), font, outline, TEXT_OUTLINE);
|
setTextColor(g_text_config->getFont(), font, outline, config.outline);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::function<void(void *)> click_fun;
|
std::function<void(void *, Button *)> click_fun;
|
||||||
void *func_input;
|
void *func_input;
|
||||||
uint64_t _id{};
|
uint64_t _id{};
|
||||||
ButtonColors colors{};
|
ButtonConfig config{};
|
||||||
bool highlighted = false;
|
bool highlighted = false;
|
||||||
bool disabled = false;
|
bool disabled = false;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user