Mario editor: can paginate blocks now

This commit is contained in:
2021-05-07 10:08:41 +02:00
parent f89d36c177
commit e084ed6f86
4 changed files with 81 additions and 5 deletions
+61 -5
View File
@@ -70,6 +70,17 @@ void updateTool() {
current_tool->getCollisions()[0]->setId(possibleBlocks[current_block]);
}
void updateToolSelection(int prev_index) {
auto prev = prev_index * 8;
auto cur = current_tool_index * 8;
for(int i = prev; i < (tools.size() < prev + 8 ? tools.size() : prev + 8); i++) {
tools[i]->setHidden(true);
}
for(int i = cur; i < (tools.size() < cur + 8 ? tools.size() : cur + 8); i++) {
tools[i]->setHidden(false);
}
}
void handleKeyUp( SDL_Keycode key ) {
switch ( key ) {
case SDLK_a:
@@ -132,6 +143,14 @@ void pollEvents( SDLPP::Scene &scene ) {
current_start_index += 1;
scene.moveEverything(-BLOCK_SIZE,0);
}
if(previous_selected_flags == current_selected_flags && MouseVisitor::moveToolsLeft(current_selected_flags) && current_tool_index != 0) {
current_tool_index -= 1;
updateToolSelection(current_tool_index + 1);
}
if(previous_selected_flags == current_selected_flags && MouseVisitor::moveToolsRight(current_selected_flags) && current_tool_index != max_tool_index) {
current_tool_index += 1;
updateToolSelection(current_tool_index - 1);
}
if(current_box.getX() != -1) {
std::lock_guard<std::mutex> lock(destruction_mutex);
@@ -155,7 +174,7 @@ void pollEvents( SDLPP::Scene &scene ) {
if(current_tool_box.getX() != -1) {
auto index = current_tool_index + current_tool_box.getY() * 4 + current_tool_box.getX();
if(index < tools.size()) {
current_block = index;
current_block = (current_tool_index * 8 - 1) + index;
updateTool();
}
}
@@ -187,7 +206,7 @@ int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
int main() {
#endif
SDLPP::init();
SDLPP::Window w( "Mario clone!" );
SDLPP::Window w( "Mario editor!" );
w.setResizable( true );
BLOCK_SIZE = 1.0 / 20;
@@ -277,6 +296,7 @@ int main() {
current_max_index = objects.size() - 18;
// tools
max_tool_index = (possibleBlocks.size() - 1) / 8;
for(int i = 0; i < 4; i++) {
auto tool_box1 = std::make_shared<ToolBox>(i, 0, renderer);
auto tool_box2 = std::make_shared<ToolBox>(i, 1, renderer);
@@ -313,6 +333,34 @@ int main() {
scene->addObject(line);
}
auto tool_rect1 = std::make_shared< SDLPP::RectangleRender >(
13*BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE, renderer, "#FFFFFF88", true);
tool_rect1->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
tool_rect1->setId(EDITOR_LEFT_TOOL_ID);
tool_rect1->setPermanent();
tool_rect1->addCollision(SDLPP::RectColider(0, 0, 1, 1));
scene->addObject(tool_rect1);
// white rectangles
auto tool_rect2 = std::make_shared< SDLPP::RectangleRender >(
18*BLOCK_SIZE, 1 * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE, renderer, "#FFFFFF88", true);
tool_rect2->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
tool_rect2->setId(EDITOR_RIGHT_TOOL_ID);
tool_rect2->setPermanent();
tool_rect2->addCollision(SDLPP::RectColider(0, 0, 1, 1));
scene->addObject(tool_rect2);
auto left_tool = std::make_shared< SDLPP::TextRenderer >(
13*BLOCK_SIZE, 1.5 * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, renderer, "<", font_config);
left_tool->setId(0);
left_tool->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
left_tool->setPermanent();
scene->addObject(left_tool);
auto right_tool = std::make_shared< SDLPP::TextRenderer >(
18*BLOCK_SIZE, 1.5 * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, renderer, ">", font_config);
right_tool->setId(0);
right_tool->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
right_tool->setPermanent();
scene->addObject(right_tool);
g_placeholder_texture = std::make_shared< SDLPP::Texture >(
renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY );
current_tool = createTerrainBlock(possibleBlocks[current_block], OVERWORLD, renderer, g_placeholder_texture, false);
@@ -327,9 +375,7 @@ int main() {
SDL_initFramerate( &gFPS );
SDL_setFramerate( &gFPS, 60 );
for(int i = current_tool_index; i < (tools.size() < current_tool_index + 8 ? tools.size() : current_tool_index + 8); i++) {
tools[i]->setHidden(false);
}
updateToolSelection(0);
auto base = SDL_GetTicks();
int frames = 0;
@@ -359,6 +405,16 @@ int main() {
right->setTextColor(font, "#000000", "#282828", 0.05);
right->changeText(">");
}
if(current_tool_index == 0) {
left_tool->setTextColor(font, "#CCCCCC", "#CCCCCC", 0.05);
} else {
left_tool->setTextColor(font, "#000000", "#282828", 0.05);
}
if(current_tool_index == max_tool_index) {
right_tool->setTextColor(font, "#CCCCCC", "#CCCCCC", 0.05);
} else {
right_tool->setTextColor(font, "#000000", "#282828", 0.05);
}
if(update_size) {
scene->updateSizeAndPosition();
}