From 76f55fd98c791a3cda08d057a4dad9710c413a13 Mon Sep 17 00:00:00 2001 From: zvon Date: Fri, 4 Jun 2021 14:49:24 +0200 Subject: [PATCH] Mario Editor: fix highlighting --- mario/editor.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/mario/editor.cpp b/mario/editor.cpp index 0ca333b..af80e68 100644 --- a/mario/editor.cpp +++ b/mario/editor.cpp @@ -166,6 +166,8 @@ void setToolColor( const std::string &color ) { store = nullptr; break; } + if(store == nullptr) + return; auto index = global_vars.tool.index % ( 2 * multiplier ); store->at( index )->setColor( color ); } @@ -201,6 +203,8 @@ void updateToolSelection( int prev_index, ToolType::Value type ) { default: break; } + if(tool_vec == nullptr) + return; auto cur = cur_page * multiplier; size_t prev = prev_index * multiplier; for ( size_t i = prev; @@ -215,8 +219,9 @@ void updateToolSelection( int prev_index, ToolType::Value type ) { i++ ) { tool_vec->at( i )->setHidden( false ); } - if ( global_vars.tool.index / multiplier == cur_page ) + if ( global_vars.tool.index / multiplier == cur_page ) { setToolColor(); + } } void moveToolsLeft( ToolType::Value type ) { @@ -255,7 +260,7 @@ void moveToolsRight( ToolType::Value type ) { } } -void updateToolIndex( uint64_t new_index ) { +void updateToolIndex( uint64_t new_index, ToolType::Value new_type ) { int multiplier = 0; int *page = nullptr; switch ( global_vars.tool.type ) { @@ -274,6 +279,7 @@ void updateToolIndex( uint64_t new_index ) { break; } unsetToolColor(); + global_vars.tool.type = new_type; global_vars.tool.index = new_index; setToolColor(); updateTool(); @@ -284,6 +290,10 @@ void updateToolIndex( uint64_t new_index ) { } } +void updateToolIndex( uint64_t new_index ) { + updateToolIndex(new_index, global_vars.tool.type); +} + void selectLowerTool() { int multiplier = 0; size_t max_index = 0; @@ -695,8 +705,7 @@ void pollEvents( SDLPP::Scene &scene ) { global_vars.current_world_type = possibleLands[index]; updateWorld(); } else if ( index < max_index ) { - global_vars.tool.type = global_vars.mouse.tool_type; - updateToolIndex( cur_page * multiplier + index ); + updateToolIndex( cur_page * multiplier + index, global_vars.mouse.tool_type ); } } break;