Mario Editor: formatting
This commit is contained in:
parent
cd0a301e52
commit
5d20757d43
109
mario/editor.cpp
109
mario/editor.cpp
@ -96,7 +96,6 @@ struct GlobalVars {
|
||||
GlobalVars global_vars;
|
||||
std::mutex destruction_mutex;
|
||||
|
||||
|
||||
void updateTool() {
|
||||
auto tool_index = global_vars.tool.index;
|
||||
uint64_t tool_id = 0;
|
||||
@ -128,7 +127,8 @@ void updateTool() {
|
||||
break;
|
||||
}
|
||||
global_vars.current_tool->setTexture(
|
||||
target_texture, getSourceRectByID( tool_id, global_vars.current_world_type ) );
|
||||
target_texture,
|
||||
getSourceRectByID( tool_id, global_vars.current_world_type ) );
|
||||
global_vars.current_tool->setId( tool_id );
|
||||
global_vars.current_tool->getCollisions()[0]->setId( tool_id );
|
||||
}
|
||||
@ -395,16 +395,22 @@ bool getFlag( uint64_t flag ) {
|
||||
}
|
||||
|
||||
void updateWorld() {
|
||||
for(auto &block : global_vars.tools) {
|
||||
block->setTextureSourceRect(getSourceRectByID(block->getId(), global_vars.current_world_type));
|
||||
dynamic_cast<MarioBlock *>(block.get())->setType(global_vars.current_world_type);
|
||||
for ( auto &block : global_vars.tools ) {
|
||||
block->setTextureSourceRect( getSourceRectByID(
|
||||
block->getId(), global_vars.current_world_type ) );
|
||||
dynamic_cast< MarioBlock * >( block.get() )
|
||||
->setType( global_vars.current_world_type );
|
||||
}
|
||||
for(auto &block : global_vars.characters) {
|
||||
block->setTextureSourceRect(getSourceRectByID(block->getId(), global_vars.current_world_type));
|
||||
dynamic_cast<MarioBlock *>(block.get())->setType(global_vars.current_world_type);
|
||||
for ( auto &block : global_vars.characters ) {
|
||||
block->setTextureSourceRect( getSourceRectByID(
|
||||
block->getId(), global_vars.current_world_type ) );
|
||||
dynamic_cast< MarioBlock * >( block.get() )
|
||||
->setType( global_vars.current_world_type );
|
||||
}
|
||||
global_vars.current_tool->setTextureSourceRect(getSourceRectByID(global_vars.current_tool->getId(), global_vars.current_world_type));
|
||||
dynamic_cast<MarioBlock *>(global_vars.current_tool.get())->setType(global_vars.current_world_type);
|
||||
global_vars.current_tool->setTextureSourceRect( getSourceRectByID(
|
||||
global_vars.current_tool->getId(), global_vars.current_world_type ) );
|
||||
dynamic_cast< MarioBlock * >( global_vars.current_tool.get() )
|
||||
->setType( global_vars.current_world_type );
|
||||
}
|
||||
|
||||
// TODO add mouse wheel control for modifiers
|
||||
@ -539,7 +545,7 @@ void placeTool( SDLPP::Scene &scene ) {
|
||||
std::lock_guard< std::mutex > lock( destruction_mutex );
|
||||
|
||||
ToolVisitor visitor;
|
||||
visitor.setSourceType(global_vars.current_world_type);
|
||||
visitor.setSourceType( global_vars.current_world_type );
|
||||
auto tool_type = getBlockRole( global_vars.current_tool->getId() );
|
||||
switch ( tool_type ) {
|
||||
case BlockRole::TERRAIN:
|
||||
@ -555,7 +561,8 @@ void placeTool( SDLPP::Scene &scene ) {
|
||||
auto &obj = getSelectedObject();
|
||||
switch ( visitor.getVisitorType() ) {
|
||||
case VisitorType::Terrain:
|
||||
std::get< MapObject::TERRAIN_TYPE >( obj ) = global_vars.current_world_type;
|
||||
std::get< MapObject::TERRAIN_TYPE >( obj ) =
|
||||
global_vars.current_world_type;
|
||||
std::get< MapObject::TERRAIN_ID >( obj ) = 0;
|
||||
break;
|
||||
case VisitorType::Modifier:
|
||||
@ -574,14 +581,16 @@ void placeTool( SDLPP::Scene &scene ) {
|
||||
std::shared_ptr< SDLPP::RenderObject > new_obj = nullptr;
|
||||
switch ( visitor.getVisitorType() ) {
|
||||
case VisitorType::Terrain:
|
||||
std::get< MapObject::TERRAIN_TYPE >( obj ) = global_vars.current_world_type;
|
||||
std::get< MapObject::TERRAIN_TYPE >( obj ) =
|
||||
global_vars.current_world_type;
|
||||
std::get< MapObject::TERRAIN_ID >( obj ) =
|
||||
global_vars.current_tool->getId();
|
||||
// TODO why 1 +?
|
||||
new_obj = createTerrainBlock(
|
||||
global_vars.current_tool->getId(), global_vars.current_world_type,
|
||||
renderer, 1 + global_vars.mouse.edit_box.getX(),
|
||||
global_vars.mouse.edit_box.getY(), true );
|
||||
new_obj =
|
||||
createTerrainBlock( global_vars.current_tool->getId(),
|
||||
global_vars.current_world_type, renderer,
|
||||
1 + global_vars.mouse.edit_box.getX(),
|
||||
global_vars.mouse.edit_box.getY(), true );
|
||||
new_obj->getCollisions()[0]->setId( EDITOR_TERRAIN_ID );
|
||||
break;
|
||||
case VisitorType::Modifier:
|
||||
@ -607,8 +616,9 @@ void placeTool( SDLPP::Scene &scene ) {
|
||||
global_vars.current_tool->getId();
|
||||
std::get< MapObject::MODIFIER_DATA >( obj ) = 0;
|
||||
new_obj = createTerrainBlock(
|
||||
global_vars.current_tool->getId(), global_vars.current_world_type,
|
||||
renderer, 1 + global_vars.mouse.edit_box.getX(),
|
||||
global_vars.current_tool->getId(),
|
||||
global_vars.current_world_type, renderer,
|
||||
1 + global_vars.mouse.edit_box.getX(),
|
||||
global_vars.mouse.edit_box.getY(),
|
||||
global_vars.translucent_terrain_texture, true );
|
||||
new_obj->getCollisions()[0]->setId( EDITOR_TERRAIN_ID );
|
||||
@ -679,7 +689,7 @@ void pollEvents( SDLPP::Scene &scene ) {
|
||||
}
|
||||
size_t index =
|
||||
tool_box.getY() * ( multiplier / 2 ) + tool_box.getX();
|
||||
if(global_vars.mouse.tool_type == ToolType::WORLD) {
|
||||
if ( global_vars.mouse.tool_type == ToolType::WORLD ) {
|
||||
global_vars.current_world_type = possibleLands[index];
|
||||
updateWorld();
|
||||
} else if ( index < max_index ) {
|
||||
@ -778,7 +788,8 @@ void populateToolGrid(
|
||||
ToolType::Value type, const std::vector< uint64_t > &blocks,
|
||||
std::vector< std::shared_ptr< SDLPP::RenderObject > > &tool_store,
|
||||
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 ) {
|
||||
std::shared_ptr< SDLPP::Scene > &scene, const std::string &title,
|
||||
const std::shared_ptr< SDLPP::FontConfiguration > &font_config ) {
|
||||
auto renderer = scene->getRendererShared();
|
||||
for ( int j = 0; j < count_y; j++ ) {
|
||||
for ( int i = 0; i < count_x; i++ ) {
|
||||
@ -792,15 +803,15 @@ void populateToolGrid(
|
||||
switch ( type ) {
|
||||
case ToolType::CHARACTER:
|
||||
if ( block == MARIO_ID )
|
||||
tool_store.push_back(
|
||||
createMario( global_vars.current_world_type, renderer, 0, 0 ) );
|
||||
tool_store.push_back( createMario(
|
||||
global_vars.current_world_type, renderer, 0, 0 ) );
|
||||
else
|
||||
case ToolType::BLOCK:
|
||||
case ToolType::MOD:
|
||||
tool_store.push_back( createTerrainBlock(
|
||||
block, global_vars.current_world_type, renderer, false ) );
|
||||
default:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
tool_store.back()->setHidden( true );
|
||||
tool_store.back()->setPermanent();
|
||||
@ -821,21 +832,25 @@ void populateToolGrid(
|
||||
tool_box_store.push_back( tool_box );
|
||||
}
|
||||
}
|
||||
auto tool_text = std::make_shared<SDLPP::TextRenderer>(start_x - BLOCK_SIZE, start_y - BLOCK_SIZE, (count_x + 2) * BLOCK_SIZE, BLOCK_SIZE, renderer, title, font_config, SDLPP_TEXT_CENTER);
|
||||
tool_text->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
||||
auto tool_text = std::make_shared< SDLPP::TextRenderer >(
|
||||
start_x - BLOCK_SIZE, start_y - BLOCK_SIZE,
|
||||
( count_x + 2 ) * BLOCK_SIZE, BLOCK_SIZE, renderer, title, font_config,
|
||||
SDLPP_TEXT_CENTER );
|
||||
tool_text->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||
tool_text->setPermanent();
|
||||
scene->addObject(tool_text);
|
||||
scene->addObject( tool_text );
|
||||
}
|
||||
|
||||
void populateWorldType(
|
||||
int count_x, int count_y, float start_x, float start_y,
|
||||
std::shared_ptr< SDLPP::Scene > &scene, const std::string &title, const std::shared_ptr<SDLPP::FontConfiguration> &font_config ) {
|
||||
std::shared_ptr< SDLPP::Scene > &scene, const std::string &title,
|
||||
const std::shared_ptr< SDLPP::FontConfiguration > &font_config ) {
|
||||
auto renderer = scene->getRendererShared();
|
||||
for ( int j = 0; j < count_y; j++ ) {
|
||||
for ( int i = 0; i < count_x; i++ ) {
|
||||
auto tool_box = std::make_shared< ToolBox >( i, j, start_x, start_y,
|
||||
renderer );
|
||||
tool_box->setType(ToolType::WORLD);
|
||||
auto tool_box =
|
||||
std::make_shared< ToolBox >( i, j, start_x, start_y, renderer );
|
||||
tool_box->setType( ToolType::WORLD );
|
||||
scene->addObject( tool_box );
|
||||
}
|
||||
}
|
||||
@ -844,17 +859,18 @@ void populateWorldType(
|
||||
auto land = createTerrainBlock( BRICK_ID, type, renderer, false );
|
||||
auto x = tool_index % count_x;
|
||||
auto y = tool_index / count_x;
|
||||
land->setId(EDITOR_WORLD_CHANGE_ID);
|
||||
land->setId( EDITOR_WORLD_CHANGE_ID );
|
||||
land->setPermanent();
|
||||
land->setPos( start_x + x * BLOCK_SIZE,
|
||||
start_y + y * BLOCK_SIZE );
|
||||
land->setPos( start_x + x * BLOCK_SIZE, start_y + y * BLOCK_SIZE );
|
||||
scene->addObject( land );
|
||||
tool_index = ( tool_index + 1 ) % ( 2 * count_x );
|
||||
}
|
||||
auto tool_text = std::make_shared<SDLPP::TextRenderer>(start_x, start_y - BLOCK_SIZE, count_x * BLOCK_SIZE, BLOCK_SIZE, renderer, title, font_config, SDLPP_TEXT_CENTER);
|
||||
tool_text->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
|
||||
auto tool_text = std::make_shared< SDLPP::TextRenderer >(
|
||||
start_x, start_y - BLOCK_SIZE, count_x * BLOCK_SIZE, BLOCK_SIZE,
|
||||
renderer, title, font_config, SDLPP_TEXT_CENTER );
|
||||
tool_text->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||
tool_text->setPermanent();
|
||||
scene->addObject(tool_text);
|
||||
scene->addObject( tool_text );
|
||||
}
|
||||
|
||||
void checkArrowsEnabled( uint64_t cur_page, uint64_t max_page,
|
||||
@ -953,7 +969,8 @@ int main() {
|
||||
// tools
|
||||
populateToolGrid( TOOLS_WIDTH, 2, ( MAP_WIDTH - TOOLS_WIDTH ) * BLOCK_SIZE,
|
||||
BLOCK_SIZE, ToolType::BLOCK, possibleBlocks,
|
||||
global_vars.tools, global_vars.tool_boxes, scene, "TERRAIN", font_config );
|
||||
global_vars.tools, global_vars.tool_boxes, scene,
|
||||
"TERRAIN", font_config );
|
||||
arrows = createArrowControls( ( MAP_WIDTH - TOOLS_WIDTH - 1 ) * BLOCK_SIZE,
|
||||
MAP_WIDTH * BLOCK_SIZE, BLOCK_SIZE,
|
||||
2 * BLOCK_SIZE, EDITOR_LEFT_TOOL_ID,
|
||||
@ -966,9 +983,10 @@ int main() {
|
||||
populateToolGrid( MOD_WIDTH, 2, 4 * BLOCK_SIZE, BLOCK_SIZE, ToolType::MOD,
|
||||
possibleMods, global_vars.mods, global_vars.mod_boxes,
|
||||
scene, "MODS", font_config );
|
||||
arrows = createArrowControls(
|
||||
3 * BLOCK_SIZE, ( MOD_WIDTH + 4 ) * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE,
|
||||
EDITOR_LEFT_MOD_ID, EDITOR_RIGHT_MOD_ID, scene, font_config );
|
||||
arrows =
|
||||
createArrowControls( 3 * BLOCK_SIZE, ( MOD_WIDTH + 4 ) * BLOCK_SIZE,
|
||||
BLOCK_SIZE, 2 * BLOCK_SIZE, EDITOR_LEFT_MOD_ID,
|
||||
EDITOR_RIGHT_MOD_ID, scene, font_config );
|
||||
auto left_mod_arrow = arrows.first;
|
||||
auto right_mod_arrow = arrows.second;
|
||||
createGrid( 4 * BLOCK_SIZE, BLOCK_SIZE, MOD_WIDTH, 2, scene );
|
||||
@ -988,7 +1006,8 @@ int main() {
|
||||
scene );
|
||||
|
||||
// world type
|
||||
populateWorldType(OVERWORLD_WIDTH, 2, 0, BLOCK_SIZE, scene, "WORLD", font_config);
|
||||
populateWorldType( OVERWORLD_WIDTH, 2, 0, BLOCK_SIZE, scene, "WORLD",
|
||||
font_config );
|
||||
createGrid( 0, BLOCK_SIZE, OVERWORLD_WIDTH, 2, scene );
|
||||
|
||||
global_vars.map.max_page = global_vars.objects.size() - MAP_WIDTH;
|
||||
@ -1018,8 +1037,8 @@ int main() {
|
||||
renderer, "sprites/mario.png", MARIO_OVERWORLD_COLORKEY );
|
||||
global_vars.translucent_mario_texture->setAlpha( 100 );
|
||||
global_vars.current_tool = createTerrainBlock(
|
||||
possibleBlocks[global_vars.tool.index], global_vars.current_world_type, renderer,
|
||||
global_vars.translucent_terrain_texture, false );
|
||||
possibleBlocks[global_vars.tool.index], global_vars.current_world_type,
|
||||
renderer, global_vars.translucent_terrain_texture, false );
|
||||
global_vars.current_tool->addCollision(
|
||||
SDLPP::RectColider( 0.1, 0.1, 0.8, 0.8 ) );
|
||||
dynamic_cast< MarioBlock & >( *global_vars.current_tool ).setTool();
|
||||
|
Loading…
Reference in New Issue
Block a user