Remove redundant functions from blocks.cpp, fix editor problem with pagination
This commit is contained in:
+64
-67
@@ -20,7 +20,7 @@
|
||||
#include "edit_box.hpp"
|
||||
#include "editor_visitor.hpp"
|
||||
#include "tool_box.hpp"
|
||||
#include "blocks/coinblock.hpp"
|
||||
#include "blocks/coineditorblock.hpp"
|
||||
|
||||
#define MAP_WIDTH 24
|
||||
#define MAP_HEIGHT 16
|
||||
@@ -66,6 +66,7 @@ struct MapInfo {
|
||||
struct ToolInfo {
|
||||
ToolType::Value type;
|
||||
uint64_t index;
|
||||
SDL_Rect texture_src;
|
||||
int cur_page_tools;
|
||||
int max_page_tools;
|
||||
int cur_page_mods;
|
||||
@@ -80,9 +81,9 @@ struct GlobalVars {
|
||||
ToolInfo tool;
|
||||
uint64_t flags;
|
||||
std::vector< mapColumnType > objects;
|
||||
std::vector< std::shared_ptr< SDLPP::RenderObject > > tools;
|
||||
std::vector< std::shared_ptr< SDLPP::RenderObject > > mods;
|
||||
std::vector< std::shared_ptr< SDLPP::RenderObject > > characters;
|
||||
std::vector< std::shared_ptr< MarioBlock > > tools;
|
||||
std::vector< std::shared_ptr< MarioBlock > > mods;
|
||||
std::vector< std::shared_ptr< MarioBlock > > characters;
|
||||
std::vector< std::shared_ptr< SDLPP::RenderObject > > tool_boxes;
|
||||
std::vector< std::shared_ptr< SDLPP::RenderObject > > mod_boxes;
|
||||
std::vector< std::shared_ptr< SDLPP::RenderObject > > character_boxes;
|
||||
@@ -117,33 +118,36 @@ void updateTool() {
|
||||
}
|
||||
auto tool_role = getBlockRole( tool_id );
|
||||
std::shared_ptr< SDLPP::Texture > target_texture = nullptr;
|
||||
SDL_Rect target_src;
|
||||
switch ( tool_role ) {
|
||||
case BlockRole::TERRAIN:
|
||||
target_texture = global_vars.translucent_terrain_texture;
|
||||
target_src = global_vars.tools[global_vars.tool.index]->getTextureSourceRect();
|
||||
break;
|
||||
case BlockRole::MARIO:
|
||||
target_texture = global_vars.translucent_mario_texture;
|
||||
target_src = global_vars.characters[global_vars.tool.index]->getTextureSourceRect();
|
||||
break;
|
||||
case BlockRole::MODIFIER:
|
||||
target_texture = global_vars.translucent_mod_texture;
|
||||
target_src = global_vars.mods[global_vars.tool.index]->getTextureSourceRect();
|
||||
break;
|
||||
case BlockRole::CHARACTER:
|
||||
target_src = global_vars.characters[global_vars.tool.index]->getTextureSourceRect();
|
||||
break;
|
||||
}
|
||||
global_vars.current_tool->setHidden(true);
|
||||
if(tool_id == COIN_MODIFIER_ID) {
|
||||
global_vars.coin_tool->setPos(global_vars.current_tool->getPos());
|
||||
global_vars.current_tool->setHidden( true );
|
||||
if ( tool_id == COIN_MODIFIER_ID ) {
|
||||
global_vars.coin_tool->setPos( global_vars.current_tool->getPos() );
|
||||
global_vars.current_tool = global_vars.coin_tool;
|
||||
} else {
|
||||
global_vars.generic_tool->setPos(global_vars.current_tool->getPos());
|
||||
global_vars.generic_tool->setPos( global_vars.current_tool->getPos() );
|
||||
global_vars.current_tool = global_vars.generic_tool;
|
||||
global_vars.current_tool->setTexture(
|
||||
target_texture,
|
||||
getSourceRectByID( tool_id, global_vars.current_world_type ) );
|
||||
global_vars.current_tool->setTexture( target_texture, target_src );
|
||||
global_vars.current_tool->setId( tool_id );
|
||||
global_vars.current_tool->getCollisions()[0]->setId( tool_id );
|
||||
}
|
||||
global_vars.current_tool->setHidden(false);
|
||||
global_vars.current_tool->setHidden( false );
|
||||
}
|
||||
|
||||
void removeMario() {
|
||||
@@ -193,7 +197,7 @@ void updateToolSelection( int prev_index, ToolType::Value type ) {
|
||||
unsetToolColor();
|
||||
size_t cur_page = 0;
|
||||
size_t multiplier = 0;
|
||||
std::vector< std::shared_ptr< SDLPP::RenderObject > > *tool_vec = nullptr;
|
||||
std::vector< std::shared_ptr< MarioBlock > > *tool_vec = nullptr;
|
||||
switch ( type ) {
|
||||
case ToolType::BLOCK:
|
||||
cur_page = global_vars.tool.cur_page_tools;
|
||||
@@ -272,7 +276,7 @@ void moveToolsRight( ToolType::Value type ) {
|
||||
void updateToolIndex( uint64_t new_index, ToolType::Value new_type ) {
|
||||
int multiplier = 0;
|
||||
int *page = nullptr;
|
||||
switch ( global_vars.tool.type ) {
|
||||
switch ( new_type ) {
|
||||
case ToolType::BLOCK:
|
||||
multiplier = 2 * TOOLS_WIDTH;
|
||||
page = &global_vars.tool.cur_page_tools;
|
||||
@@ -416,20 +420,13 @@ 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 );
|
||||
block->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 );
|
||||
block->setType( global_vars.current_world_type );
|
||||
}
|
||||
if(getBlockRole(global_vars.current_tool->getId()) != BlockRole::MODIFIER) {
|
||||
global_vars.current_tool->setTextureSourceRect( getSourceRectByID(
|
||||
global_vars.current_tool->getId(), global_vars.current_world_type ) );
|
||||
if ( getBlockRole( global_vars.current_tool->getId() ) !=
|
||||
BlockRole::MODIFIER ) {
|
||||
global_vars.current_tool->setType( global_vars.current_world_type );
|
||||
}
|
||||
}
|
||||
@@ -582,7 +579,6 @@ void placeTool( SDLPP::Scene &scene ) {
|
||||
scene.visitCollisions( *global_vars.current_tool, visitor );
|
||||
auto &obj = getSelectedObject();
|
||||
if ( visitor.removeBlock() && !visitor.addBlock() ) {
|
||||
std::cout << "DO NOT ADD" << std::endl;
|
||||
switch ( visitor.getVisitorType() ) {
|
||||
case VisitorType::Terrain:
|
||||
obj.unsetTerrain();
|
||||
@@ -594,7 +590,6 @@ void placeTool( SDLPP::Scene &scene ) {
|
||||
break;
|
||||
}
|
||||
} else if ( visitor.addBlock() ) {
|
||||
std::cout << "ADD" << std::endl;
|
||||
auto renderer = scene.getRendererShared();
|
||||
int z_index = 1;
|
||||
std::shared_ptr< MarioBlock > new_obj = nullptr;
|
||||
@@ -603,18 +598,18 @@ void placeTool( SDLPP::Scene &scene ) {
|
||||
obj.setTerrain( global_vars.current_tool->getId(),
|
||||
global_vars.current_world_type );
|
||||
new_obj = createTerrainBlock(
|
||||
obj.getTerrainId(),
|
||||
obj.getTerrainType(), renderer,
|
||||
obj.getTerrainId(), obj.getTerrainType(), renderer,
|
||||
global_vars.mouse.edit_box.getX(),
|
||||
global_vars.mouse.edit_box.getY(), false, true );
|
||||
new_obj->getCollisions()[0]->setId( EDITOR_TERRAIN_ID );
|
||||
break;
|
||||
case VisitorType::Modifier:
|
||||
if ( tool_type == BlockRole::MARIO ) {
|
||||
obj.setCharacter(MARIO_ID, global_vars.current_world_type);
|
||||
new_obj = createMario( global_vars.current_world_type, renderer,
|
||||
global_vars.mouse.edit_box.getX(),
|
||||
global_vars.mouse.edit_box.getY(), true );
|
||||
obj.setCharacter( MARIO_ID, global_vars.current_world_type );
|
||||
new_obj =
|
||||
createMario( global_vars.current_world_type, renderer,
|
||||
global_vars.mouse.edit_box.getX(),
|
||||
global_vars.mouse.edit_box.getY(), true );
|
||||
// remove mario if exists
|
||||
removeMario();
|
||||
global_vars.mario = new_obj;
|
||||
@@ -623,15 +618,15 @@ void placeTool( SDLPP::Scene &scene ) {
|
||||
z_index = scene.getObjects().size() - 1;
|
||||
// TODO BlockRole::Character
|
||||
} else {
|
||||
obj.setModifier(global_vars.current_tool->getId(), global_vars.current_tool->getData());
|
||||
obj.setModifier( global_vars.current_tool->getId(),
|
||||
global_vars.current_tool->getData() );
|
||||
new_obj = createTerrainBlock(
|
||||
obj.getModifierId(),
|
||||
LandType::OVERWORLD, renderer,
|
||||
obj.getModifierId(), LandType::OVERWORLD, renderer,
|
||||
global_vars.mouse.edit_box.getX(),
|
||||
global_vars.mouse.edit_box.getY(),
|
||||
false, true );
|
||||
new_obj->setTextureKeepSRC(global_vars.translucent_mod_texture);
|
||||
new_obj->setData(global_vars.current_tool->getData());
|
||||
global_vars.mouse.edit_box.getY(), false, true );
|
||||
new_obj->setTextureKeepSRC(
|
||||
global_vars.translucent_mod_texture );
|
||||
new_obj->setData( global_vars.current_tool->getData() );
|
||||
new_obj->getCollisions()[0]->setId( EDITOR_TERRAIN_ID );
|
||||
// TODO createModifierBlock
|
||||
dynamic_cast< MarioBlock * >( new_obj.get() )
|
||||
@@ -714,9 +709,9 @@ void pollEvents( SDLPP::Scene &scene ) {
|
||||
global_vars.mouse.prev_flags = global_vars.mouse.cur_flags;
|
||||
break;
|
||||
case SDL_MOUSEWHEEL:
|
||||
if(event.wheel.y > 0) {
|
||||
if ( event.wheel.y > 0 ) {
|
||||
global_vars.current_tool->onScrollUp();
|
||||
} else if (event.wheel.y < 0) {
|
||||
} else if ( event.wheel.y < 0 ) {
|
||||
global_vars.current_tool->onScrollDown();
|
||||
}
|
||||
break;
|
||||
@@ -804,7 +799,7 @@ createArrowControls(
|
||||
void populateToolGrid(
|
||||
int count_x, int count_y, float start_x, float start_y,
|
||||
ToolType::Value type, const std::vector< uint64_t > &blocks,
|
||||
std::vector< std::shared_ptr< SDLPP::RenderObject > > &tool_store,
|
||||
std::vector< std::shared_ptr< MarioBlock > > &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 ) {
|
||||
@@ -825,17 +820,17 @@ void populateToolGrid(
|
||||
global_vars.current_world_type, renderer, 0, 0, true ) );
|
||||
break;
|
||||
}
|
||||
// fall through
|
||||
case ToolType::MOD:
|
||||
tool_store.push_back(
|
||||
createTerrainBlock( block, global_vars.current_world_type,
|
||||
renderer, false, true ) );
|
||||
break;
|
||||
case ToolType::BLOCK:
|
||||
tool_store.push_back(
|
||||
createTerrainBlock( block, global_vars.current_world_type,
|
||||
renderer, false, true ) );
|
||||
break;
|
||||
// fall through
|
||||
case ToolType::MOD:
|
||||
tool_store.push_back(
|
||||
createTerrainBlock( block, global_vars.current_world_type,
|
||||
renderer, false, true ) );
|
||||
break;
|
||||
case ToolType::BLOCK:
|
||||
tool_store.push_back(
|
||||
createTerrainBlock( block, global_vars.current_world_type,
|
||||
renderer, false, true ) );
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -958,13 +953,13 @@ int main() {
|
||||
renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY );
|
||||
g_mario_texture = std::make_shared< SDLPP::Texture >(
|
||||
renderer, "sprites/mario.png", MARIO_OVERWORLD_COLORKEY );
|
||||
g_mod_texture = std::make_shared<SDLPP::Texture>(
|
||||
renderer, "sprites/mods.png");
|
||||
g_mod_texture =
|
||||
std::make_shared< SDLPP::Texture >( renderer, "sprites/mods.png" );
|
||||
g_translucent_terrain_texture = std::make_shared< SDLPP::Texture >(
|
||||
renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY );
|
||||
g_translucent_terrain_texture->setAlpha( 100 );
|
||||
g_translucent_mod_texture = std::make_shared<SDLPP::Texture>(
|
||||
renderer, "sprites/mods.png");
|
||||
g_translucent_mod_texture =
|
||||
std::make_shared< SDLPP::Texture >( renderer, "sprites/mods.png" );
|
||||
g_translucent_mod_texture->setAlpha( 100 );
|
||||
|
||||
auto scene = std::make_shared< SDLPP::Scene >( renderer );
|
||||
@@ -977,8 +972,8 @@ int main() {
|
||||
global_vars.current_world_type = LandType::OVERWORLD;
|
||||
|
||||
// TODO file name
|
||||
loadMap( scene, global_vars.mario, "test_binary.bin",
|
||||
global_vars.objects, true, MAP_WIDTH );
|
||||
loadMap( scene, global_vars.mario, "test_binary.bin", global_vars.objects,
|
||||
true, MAP_WIDTH );
|
||||
|
||||
// create grids and arrow controls
|
||||
// map
|
||||
@@ -1076,17 +1071,19 @@ int main() {
|
||||
global_vars.translucent_mario_texture = std::make_shared< SDLPP::Texture >(
|
||||
renderer, "sprites/mario.png", MARIO_OVERWORLD_COLORKEY );
|
||||
global_vars.translucent_mario_texture->setAlpha( 100 );
|
||||
global_vars.generic_tool = createTerrainBlock(
|
||||
possibleBlocks[global_vars.tool.index], global_vars.current_world_type,
|
||||
renderer, false );
|
||||
global_vars.generic_tool->setTextureKeepSRC(global_vars.translucent_terrain_texture);
|
||||
global_vars.generic_tool =
|
||||
createTerrainBlock( possibleBlocks[global_vars.tool.index],
|
||||
global_vars.current_world_type, renderer, false );
|
||||
global_vars.generic_tool->setTextureKeepSRC(
|
||||
global_vars.translucent_terrain_texture );
|
||||
global_vars.generic_tool->removeCollisions();
|
||||
global_vars.generic_tool->addCollision(
|
||||
SDLPP::RectColider( 0.1, 0.1, 0.8, 0.8 ) );
|
||||
global_vars.current_tool = global_vars.generic_tool;
|
||||
|
||||
global_vars.coin_tool = createTerrainBlock(COIN_MODIFIER_ID, LandType::OVERWORLD, renderer, 0, 0, false, true );
|
||||
global_vars.coin_tool->setData(1);
|
||||
global_vars.coin_tool = createTerrainBlock(
|
||||
COIN_MODIFIER_ID, LandType::OVERWORLD, renderer, 0, 0, false, true );
|
||||
global_vars.coin_tool->setData( 1 );
|
||||
global_vars.coin_tool->removeCollisions();
|
||||
global_vars.coin_tool->addCollision(
|
||||
SDLPP::RectColider( 0.1, 0.1, 0.8, 0.8 ) );
|
||||
@@ -1094,7 +1091,7 @@ int main() {
|
||||
dynamic_cast< MarioBlock & >( *global_vars.current_tool ).setTool();
|
||||
scene->addObject( global_vars.current_tool );
|
||||
scene->addObject( global_vars.coin_tool );
|
||||
global_vars.coin_tool->setHidden(true);
|
||||
global_vars.coin_tool->setHidden( true );
|
||||
scene->moveZTop( global_vars.current_tool );
|
||||
scene->moveZTop( global_vars.coin_tool );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user