Ensure arrows are enabled/disabled even when moving tools with wsad
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
zvon 2022-06-24 21:51:47 +02:00
parent 38dfa533c4
commit c59851b490

View File

@ -76,6 +76,12 @@ struct ToolInfo {
int max_page_mods; int max_page_mods;
int cur_page_characters; int cur_page_characters;
int max_page_characters; int max_page_characters;
std::shared_ptr<Button> button_left_tools;
std::shared_ptr<Button> button_right_tools;
std::shared_ptr<Button> button_left_mods;
std::shared_ptr<Button> button_right_mods;
std::shared_ptr<Button> button_left_characters;
std::shared_ptr<Button> button_right_characters;
}; };
struct GlobalVars { struct GlobalVars {
@ -105,7 +111,6 @@ struct GlobalVars {
GlobalVars global_vars; GlobalVars global_vars;
std::mutex destruction_mutex; std::mutex destruction_mutex;
std::mutex render_mutex;
void updateTool() { void updateTool() {
auto tool_index = global_vars.tool.index; auto tool_index = global_vars.tool.index;
@ -204,9 +209,39 @@ void unsetToolColor() {
setToolColor("#FFFFFF00"); setToolColor("#FFFFFF00");
} }
void toolMoveUpdateButtons(Button *left, Button *right, int &cur_page, int &max_page, bool canAdd) {
if(cur_page == 0) {
left->disable();
} else {
left->enable();
}
if(cur_page != max_page) {
if(canAdd) {
// TOOD global button config
right->changeText(">");
right->setFontColor("#000000");
right->setFontOutlineColor("#FFFFFF88");
right->setFontColorHighlight("#000000");
right->setFontOutlineColorHighlight("#FFFFFFAA");
} else {
right->enable();
}
} else {
if(canAdd) {
right->changeText("+");
right->setFontColor("#00FF00");
right->setFontOutlineColor("#000000");
right->setFontColorHighlight("#88FF88");
right->setFontOutlineColorHighlight("#444444");
} else {
right->disable();
}
}
}
void updateToolSelection(int prev_index, ToolType::Value type) { void updateToolSelection(int prev_index, ToolType::Value type) {
unsetToolColor(); unsetToolColor();
size_t cur_page = 0; int cur_page = 0;
size_t multiplier = 0; size_t multiplier = 0;
std::vector<std::shared_ptr<MarioBlock>> *tool_vec = nullptr; std::vector<std::shared_ptr<MarioBlock>> *tool_vec = nullptr;
switch (type) { switch (type) {
@ -214,16 +249,19 @@ void updateToolSelection(int prev_index, ToolType::Value type) {
cur_page = global_vars.tool.cur_page_tools; cur_page = global_vars.tool.cur_page_tools;
multiplier = 2 * TOOLS_WIDTH; multiplier = 2 * TOOLS_WIDTH;
tool_vec = &global_vars.tools; tool_vec = &global_vars.tools;
toolMoveUpdateButtons(global_vars.tool.button_left_tools.get(), global_vars.tool.button_right_tools.get(), cur_page, global_vars.tool.max_page_tools, false);
break; break;
case ToolType::MOD: case ToolType::MOD:
cur_page = global_vars.tool.cur_page_mods; cur_page = global_vars.tool.cur_page_mods;
multiplier = 2 * MOD_WIDTH; multiplier = 2 * MOD_WIDTH;
tool_vec = &global_vars.mods; tool_vec = &global_vars.mods;
toolMoveUpdateButtons(global_vars.tool.button_left_mods.get(), global_vars.tool.button_right_mods.get(), cur_page, global_vars.tool.max_page_mods, false);
break; break;
case ToolType::CHARACTER: case ToolType::CHARACTER:
cur_page = global_vars.tool.cur_page_characters; cur_page = global_vars.tool.cur_page_characters;
multiplier = 2 * CHARACTER_WIDTH; multiplier = 2 * CHARACTER_WIDTH;
tool_vec = &global_vars.characters; tool_vec = &global_vars.characters;
toolMoveUpdateButtons(global_vars.tool.button_left_characters.get(), global_vars.tool.button_right_characters.get(), cur_page, global_vars.tool.max_page_characters, false);
default: default:
break; break;
} }
@ -498,10 +536,10 @@ void getMousePositionFlags(SDLPP::Scene &scene) {
scene.visitCollisions(*mouse, visitor); scene.visitCollisions(*mouse, visitor);
if(visitor.getCurButton() != global_vars.mouse.cur_button_index) { if(visitor.getCurButton() != global_vars.mouse.cur_button_index) {
if(global_vars.mouse.cur_button_index != (uint64_t)-1) { if(global_vars.mouse.cur_button_index != (uint64_t)-1) {
global_vars.buttons[global_vars.mouse.cur_button_index]->unsetHighlight(render_mutex); global_vars.buttons[global_vars.mouse.cur_button_index]->unsetHighlight();
} }
if(visitor.getCurButton() != (uint64_t)-1) { if(visitor.getCurButton() != (uint64_t)-1) {
global_vars.buttons[visitor.getCurButton()]->setHighlight(render_mutex); global_vars.buttons[visitor.getCurButton()]->setHighlight();
} }
} }
global_vars.mouse.cur_button_index = visitor.getCurButton(); global_vars.mouse.cur_button_index = visitor.getCurButton();
@ -526,49 +564,13 @@ struct moveStruct {
std::shared_ptr<Button> other_button; std::shared_ptr<Button> other_button;
}; };
void toolMoveLeftUpdateButtons(Button *left, Button *right, int &cur_page, int &max_page, bool canAdd) {
if(cur_page == 0) {
left->disable(render_mutex);
}
if(cur_page != max_page) {
if(canAdd) {
// 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) { void toolMoveLeft(Button *left, Button *right, int &cur_page, int &max_page, bool canAdd) {
cur_page--; cur_page--;
toolMoveLeftUpdateButtons(left, right, cur_page, max_page, canAdd); toolMoveUpdateButtons(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) { void toolMoveRight(Button *left, Button *right, int &cur_page, int &max_page, bool canAdd) {
cur_page += 1; cur_page += 1;
toolMoveRightUpdateButtons(left, right, cur_page, max_page, canAdd); toolMoveUpdateButtons(left, right, cur_page, max_page, canAdd);
} }
void moveMapLeft(void *input, Button *caller) { void moveMapLeft(void *input, Button *caller) {
@ -1028,7 +1030,7 @@ void populateWorldType(
void testButtonFunc(void *input, Button *caller) { 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;
caller->disable(render_mutex); caller->disable();
} }
#ifdef _WIN32 #ifdef _WIN32
@ -1127,8 +1129,7 @@ int main() {
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1); global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
left_map_input.other_button = global_vars.buttons.back(); left_map_input.other_button = global_vars.buttons.back();
// ensure disabled/enabled properly // 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); toolMoveUpdateButtons(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
@ -1169,6 +1170,7 @@ int main() {
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER); global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
global_vars.buttons.back()->setPermanent(); 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);
global_vars.tool.button_left_tools = global_vars.buttons.back();
// right tool arrow // right tool arrow
moveStruct right_tool_input{ moveStruct right_tool_input{
.scene = scene, .scene = scene,
@ -1181,9 +1183,9 @@ int main() {
global_vars.buttons.back()->setPermanent(); 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);
left_tool_input.other_button = global_vars.buttons.back(); left_tool_input.other_button = global_vars.buttons.back();
global_vars.tool.button_right_tools = global_vars.buttons.back();
// ensure disabled/enabled properly // 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); 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);
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
@ -1208,6 +1210,7 @@ int main() {
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER); global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
global_vars.buttons.back()->setPermanent(); 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);
global_vars.tool.button_left_mods = global_vars.buttons.back();
// right mod arrow // right mod arrow
moveStruct right_mod_input{ moveStruct right_mod_input{
.scene = scene, .scene = scene,
@ -1220,9 +1223,9 @@ int main() {
global_vars.buttons.back()->setPermanent(); 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);
left_mod_input.other_button = global_vars.buttons.back(); left_mod_input.other_button = global_vars.buttons.back();
global_vars.tool.button_right_mods = global_vars.buttons.back();
// ensure disabled/enabled properly // 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); 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);
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
@ -1249,6 +1252,7 @@ int main() {
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER); global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
global_vars.buttons.back()->setPermanent(); 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);
global_vars.tool.button_left_characters = global_vars.buttons.back();
// right character arrow // right character arrow
moveStruct right_character_input{ moveStruct right_character_input{
.scene = scene, .scene = scene,
@ -1260,9 +1264,9 @@ int main() {
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER); global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
global_vars.buttons.back()->setPermanent(); 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);
global_vars.tool.button_right_characters = global_vars.buttons.back();
// ensure disabled/enabled properly // 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); 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);
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(); 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);
@ -1356,17 +1360,17 @@ int main() {
SDL_framerateDelay(&gFPS); SDL_framerateDelay(&gFPS);
SDL_PumpEvents(); SDL_PumpEvents();
std::lock_guard<std::mutex> lock(destruction_mutex); std::lock_guard<std::mutex> lock(destruction_mutex);
{ scene->renderScene();
std::lock_guard<std::mutex> render(render_mutex); renderer->presentRenderer();
scene->renderScene();
renderer->presentRenderer();
}
frames++; frames++;
if (SDL_GetTicks() - base >= 1000) { if (SDL_GetTicks() - base >= 1000) {
std::cout << "FPS: " << frames << std::endl; std::cout << "FPS: " << frames << std::endl;
frames = 0; frames = 0;
base = SDL_GetTicks(); base = SDL_GetTicks();
} }
for(auto &button : global_vars.buttons) {
button->update();
}
// TODO maybe button update func instead of using mutex? // TODO maybe button update func instead of using mutex?
/* checkArrowsEnabled(global_vars.map.cur_page, global_vars.map.max_page, /* 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,