|
|
|
@@ -36,14 +36,16 @@
|
|
|
|
|
#define CHARACTER_RIGHT_ENABLED_FLAG 0x00000200
|
|
|
|
|
|
|
|
|
|
#define TOOLS_WIDTH 4
|
|
|
|
|
#define CHARACTER_WIDTH 3
|
|
|
|
|
#define MOD_WIDTH 3
|
|
|
|
|
#define CHARACTER_WIDTH 2
|
|
|
|
|
#define MOD_WIDTH 2
|
|
|
|
|
#define OVERWORLD_WIDTH 2
|
|
|
|
|
|
|
|
|
|
struct ToolType {
|
|
|
|
|
enum Value {
|
|
|
|
|
BLOCK,
|
|
|
|
|
MOD,
|
|
|
|
|
CHARACTER,
|
|
|
|
|
WORLD,
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@@ -83,6 +85,7 @@ struct GlobalVars {
|
|
|
|
|
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;
|
|
|
|
|
enum LandType::Value current_world_type;
|
|
|
|
|
std::shared_ptr< SDLPP::RenderObject > current_tool;
|
|
|
|
|
std::shared_ptr< SDLPP::Texture > translucent_terrain_texture;
|
|
|
|
|
std::shared_ptr< SDLPP::Texture > translucent_mario_texture;
|
|
|
|
@@ -93,7 +96,6 @@ struct GlobalVars {
|
|
|
|
|
GlobalVars global_vars;
|
|
|
|
|
std::mutex destruction_mutex;
|
|
|
|
|
|
|
|
|
|
enum LandType::Value g_current_world_type = LandType::OVERWORLD;
|
|
|
|
|
|
|
|
|
|
void updateTool() {
|
|
|
|
|
auto tool_index = global_vars.tool.index;
|
|
|
|
@@ -126,7 +128,7 @@ void updateTool() {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
global_vars.current_tool->setTexture(
|
|
|
|
|
target_texture, getSourceRectByID( tool_id, g_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 );
|
|
|
|
|
}
|
|
|
|
@@ -159,7 +161,9 @@ void setToolColor( const std::string &color ) {
|
|
|
|
|
case ToolType::CHARACTER:
|
|
|
|
|
multiplier = CHARACTER_WIDTH;
|
|
|
|
|
store = &global_vars.character_boxes;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
store = nullptr;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
auto index = global_vars.tool.index % ( 2 * multiplier );
|
|
|
|
@@ -390,6 +394,19 @@ bool getFlag( uint64_t flag ) {
|
|
|
|
|
return global_vars.flags & 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.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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO add mouse wheel control for modifiers
|
|
|
|
|
void handleKeyUp( SDL_Keycode key, SDLPP::Scene &scene ) {
|
|
|
|
|
switch ( key ) {
|
|
|
|
@@ -408,6 +425,22 @@ void handleKeyUp( SDL_Keycode key, SDLPP::Scene &scene ) {
|
|
|
|
|
case SDLK_s:
|
|
|
|
|
selectLowerTool();
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_1:
|
|
|
|
|
global_vars.current_world_type = possibleLands[0];
|
|
|
|
|
updateWorld();
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_2:
|
|
|
|
|
global_vars.current_world_type = possibleLands[1];
|
|
|
|
|
updateWorld();
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_3:
|
|
|
|
|
global_vars.current_world_type = possibleLands[2];
|
|
|
|
|
updateWorld();
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_4:
|
|
|
|
|
global_vars.current_world_type = possibleLands[3];
|
|
|
|
|
updateWorld();
|
|
|
|
|
break;
|
|
|
|
|
case SDLK_r:
|
|
|
|
|
scene.getRenderer().setRenderColiders(
|
|
|
|
|
!scene.getRenderer().getRenderColiders() );
|
|
|
|
@@ -506,6 +539,7 @@ void placeTool( SDLPP::Scene &scene ) {
|
|
|
|
|
std::lock_guard< std::mutex > lock( destruction_mutex );
|
|
|
|
|
|
|
|
|
|
ToolVisitor visitor;
|
|
|
|
|
visitor.setSourceType(global_vars.current_world_type);
|
|
|
|
|
auto tool_type = getBlockRole( global_vars.current_tool->getId() );
|
|
|
|
|
switch ( tool_type ) {
|
|
|
|
|
case BlockRole::TERRAIN:
|
|
|
|
@@ -521,7 +555,7 @@ void placeTool( SDLPP::Scene &scene ) {
|
|
|
|
|
auto &obj = getSelectedObject();
|
|
|
|
|
switch ( visitor.getVisitorType() ) {
|
|
|
|
|
case VisitorType::Terrain:
|
|
|
|
|
std::get< MapObject::TERRAIN_TYPE >( obj ) = LandType::OVERWORLD;
|
|
|
|
|
std::get< MapObject::TERRAIN_TYPE >( obj ) = global_vars.current_world_type;
|
|
|
|
|
std::get< MapObject::TERRAIN_ID >( obj ) = 0;
|
|
|
|
|
break;
|
|
|
|
|
case VisitorType::Modifier:
|
|
|
|
@@ -540,12 +574,12 @@ 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 ) = LandType::OVERWORLD;
|
|
|
|
|
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(), LandType::OVERWORLD,
|
|
|
|
|
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 );
|
|
|
|
@@ -553,11 +587,11 @@ void placeTool( SDLPP::Scene &scene ) {
|
|
|
|
|
case VisitorType::Modifier:
|
|
|
|
|
if ( tool_type == BlockRole::MARIO ) {
|
|
|
|
|
std::get< MapObject::CHARACTER_TYPE >( obj ) =
|
|
|
|
|
LandType::OVERWORLD;
|
|
|
|
|
global_vars.current_world_type;
|
|
|
|
|
std::get< MapObject::CHARACTER_ID >( obj ) = MARIO_ID;
|
|
|
|
|
std::get< MapObject::MODIFIER_TYPE >( obj ) = 0;
|
|
|
|
|
std::get< MapObject::MODIFIER_DATA >( obj ) = 0;
|
|
|
|
|
new_obj = createMario( LandType::OVERWORLD, renderer,
|
|
|
|
|
new_obj = createMario( global_vars.current_world_type, renderer,
|
|
|
|
|
1 + global_vars.mouse.edit_box.getX(),
|
|
|
|
|
global_vars.mouse.edit_box.getY() );
|
|
|
|
|
// remove mario if exists
|
|
|
|
@@ -573,7 +607,7 @@ 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(), LandType::OVERWORLD,
|
|
|
|
|
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 );
|
|
|
|
@@ -637,12 +671,18 @@ void pollEvents( SDLPP::Scene &scene ) {
|
|
|
|
|
multiplier = 2 * CHARACTER_WIDTH;
|
|
|
|
|
max_index = global_vars.characters.size();
|
|
|
|
|
cur_page = global_vars.tool.cur_page_characters;
|
|
|
|
|
break;
|
|
|
|
|
case ToolType::WORLD:
|
|
|
|
|
multiplier = 2 * OVERWORLD_WIDTH;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
size_t index =
|
|
|
|
|
tool_box.getY() * ( multiplier / 2 ) + tool_box.getX();
|
|
|
|
|
if ( index < max_index ) {
|
|
|
|
|
if(global_vars.mouse.tool_type == ToolType::WORLD) {
|
|
|
|
|
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 );
|
|
|
|
|
}
|
|
|
|
@@ -738,7 +778,7 @@ 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 ) {
|
|
|
|
|
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++ ) {
|
|
|
|
@@ -753,12 +793,14 @@ void populateToolGrid(
|
|
|
|
|
case ToolType::CHARACTER:
|
|
|
|
|
if ( block == MARIO_ID )
|
|
|
|
|
tool_store.push_back(
|
|
|
|
|
createMario( LandType::OVERWORLD, renderer, 0, 0 ) );
|
|
|
|
|
createMario( global_vars.current_world_type, renderer, 0, 0 ) );
|
|
|
|
|
else
|
|
|
|
|
case ToolType::BLOCK:
|
|
|
|
|
case ToolType::MOD:
|
|
|
|
|
tool_store.push_back( createTerrainBlock(
|
|
|
|
|
block, LandType::OVERWORLD, renderer, false ) );
|
|
|
|
|
block, global_vars.current_world_type, renderer, false ) );
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
tool_store.back()->setHidden( true );
|
|
|
|
|
tool_store.back()->setPermanent();
|
|
|
|
@@ -779,6 +821,40 @@ 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);
|
|
|
|
|
tool_text->setPermanent();
|
|
|
|
|
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 ) {
|
|
|
|
|
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);
|
|
|
|
|
scene->addObject( tool_box );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
int tool_index = 0;
|
|
|
|
|
for ( auto &type : possibleLands ) {
|
|
|
|
|
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->setPermanent();
|
|
|
|
|
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);
|
|
|
|
|
tool_text->setPermanent();
|
|
|
|
|
scene->addObject(tool_text);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void checkArrowsEnabled( uint64_t cur_page, uint64_t max_page,
|
|
|
|
@@ -846,6 +922,8 @@ int main() {
|
|
|
|
|
bg->setId( 1 );
|
|
|
|
|
scene->addObject( bg );
|
|
|
|
|
|
|
|
|
|
global_vars.current_world_type = LandType::OVERWORLD;
|
|
|
|
|
|
|
|
|
|
// TODO file name
|
|
|
|
|
loadMap( scene, global_vars.mario, "test_binary.bin", renderer,
|
|
|
|
|
global_vars.objects );
|
|
|
|
@@ -875,7 +953,7 @@ 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 );
|
|
|
|
|
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,
|
|
|
|
@@ -885,30 +963,34 @@ int main() {
|
|
|
|
|
createGrid( ( MAP_WIDTH - TOOLS_WIDTH ) * BLOCK_SIZE, BLOCK_SIZE,
|
|
|
|
|
TOOLS_WIDTH, 2, scene );
|
|
|
|
|
// mods
|
|
|
|
|
populateToolGrid( MOD_WIDTH, 2, 2 * BLOCK_SIZE, BLOCK_SIZE, ToolType::MOD,
|
|
|
|
|
populateToolGrid( MOD_WIDTH, 2, 4 * BLOCK_SIZE, BLOCK_SIZE, ToolType::MOD,
|
|
|
|
|
possibleMods, global_vars.mods, global_vars.mod_boxes,
|
|
|
|
|
scene );
|
|
|
|
|
scene, "MODS", font_config );
|
|
|
|
|
arrows = createArrowControls(
|
|
|
|
|
BLOCK_SIZE, ( MOD_WIDTH + 2 ) * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE,
|
|
|
|
|
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( 2 * BLOCK_SIZE, BLOCK_SIZE, MOD_WIDTH, 2, scene );
|
|
|
|
|
createGrid( 4 * BLOCK_SIZE, BLOCK_SIZE, MOD_WIDTH, 2, scene );
|
|
|
|
|
// characters
|
|
|
|
|
populateToolGrid( CHARACTER_WIDTH, 2, ( MOD_WIDTH + 5 ) * BLOCK_SIZE,
|
|
|
|
|
populateToolGrid( CHARACTER_WIDTH, 2, ( MOD_WIDTH + 7 ) * BLOCK_SIZE,
|
|
|
|
|
BLOCK_SIZE, ToolType::CHARACTER, possibleCharacters,
|
|
|
|
|
global_vars.characters, global_vars.character_boxes,
|
|
|
|
|
scene );
|
|
|
|
|
scene, "CHARACTERS", font_config );
|
|
|
|
|
arrows = createArrowControls(
|
|
|
|
|
( MOD_WIDTH + 4 ) * BLOCK_SIZE,
|
|
|
|
|
( MOD_WIDTH + 5 + CHARACTER_WIDTH ) * BLOCK_SIZE, BLOCK_SIZE,
|
|
|
|
|
( MOD_WIDTH + 6 ) * BLOCK_SIZE,
|
|
|
|
|
( MOD_WIDTH + 7 + CHARACTER_WIDTH ) * BLOCK_SIZE, BLOCK_SIZE,
|
|
|
|
|
2 * BLOCK_SIZE, EDITOR_LEFT_CHARACTER_ID, EDITOR_RIGHT_CHARACTER_ID,
|
|
|
|
|
scene, font_config );
|
|
|
|
|
auto left_char_arrow = arrows.first;
|
|
|
|
|
auto right_char_arrow = arrows.second;
|
|
|
|
|
createGrid( ( MOD_WIDTH + 5 ) * BLOCK_SIZE, BLOCK_SIZE, CHARACTER_WIDTH, 2,
|
|
|
|
|
createGrid( ( MOD_WIDTH + 7 ) * BLOCK_SIZE, BLOCK_SIZE, CHARACTER_WIDTH, 2,
|
|
|
|
|
scene );
|
|
|
|
|
|
|
|
|
|
// world type
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
global_vars.tool.max_page_tools =
|
|
|
|
@@ -936,7 +1018,7 @@ 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], LandType::OVERWORLD, renderer,
|
|
|
|
|
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 ) );
|
|
|
|
|