Mario: slightly better editor UI
This commit is contained in:
parent
af3588501a
commit
9d9068091b
@ -139,10 +139,16 @@ const std::vector< uint64_t > possibleBlocks = {
|
|||||||
TREE_BARK_ID,
|
TREE_BARK_ID,
|
||||||
CANNON_PEDESTAL_ID,
|
CANNON_PEDESTAL_ID,
|
||||||
CANNON_ID,
|
CANNON_ID,
|
||||||
MARIO_ID,
|
};
|
||||||
|
|
||||||
|
const std::vector< uint64_t > possibleMods = {
|
||||||
DESTRUCTIBLE_ID,
|
DESTRUCTIBLE_ID,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const std::vector< uint64_t > possibleCharacters = {
|
||||||
|
MARIO_ID,
|
||||||
|
};
|
||||||
|
|
||||||
const std::unordered_map< uint64_t, const SDL_Rect * > block_mapping = {
|
const std::unordered_map< uint64_t, const SDL_Rect * > block_mapping = {
|
||||||
{ FLOOR_ID, &FLOOR_SRC },
|
{ FLOOR_ID, &FLOOR_SRC },
|
||||||
{ HILL_INCLINE_ID, &HILL_INCLINE_SRC },
|
{ HILL_INCLINE_ID, &HILL_INCLINE_SRC },
|
||||||
|
@ -25,6 +25,8 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
extern const std::vector< uint64_t > possibleBlocks;
|
extern const std::vector< uint64_t > possibleBlocks;
|
||||||
|
extern const std::vector< uint64_t > possibleMods;
|
||||||
|
extern const std::vector< uint64_t > possibleCharacters;
|
||||||
|
|
||||||
struct LandType {
|
struct LandType {
|
||||||
enum Value { OVERWORLD = 0, UNDERWORLD = 1, WATER = 2, BOWSER = 4 };
|
enum Value { OVERWORLD = 0, UNDERWORLD = 1, WATER = 2, BOWSER = 4 };
|
||||||
|
510
mario/editor.cpp
510
mario/editor.cpp
@ -30,12 +30,29 @@
|
|||||||
#define MAP_RIGHT_ENABLED_FLAG 0x00000008
|
#define MAP_RIGHT_ENABLED_FLAG 0x00000008
|
||||||
#define TOOL_LEFT_ENABLED_FLAG 0x00000010
|
#define TOOL_LEFT_ENABLED_FLAG 0x00000010
|
||||||
#define TOOL_RIGHT_ENABLED_FLAG 0x00000020
|
#define TOOL_RIGHT_ENABLED_FLAG 0x00000020
|
||||||
|
#define MOD_LEFT_ENABLED_FLAG 0x00000040
|
||||||
|
#define MOD_RIGHT_ENABLED_FLAG 0x00000080
|
||||||
|
#define CHARACTER_LEFT_ENABLED_FLAG 0x00000100
|
||||||
|
#define CHARACTER_RIGHT_ENABLED_FLAG 0x00000200
|
||||||
|
|
||||||
|
#define TOOLS_WIDTH 4
|
||||||
|
#define CHARACTER_WIDTH 3
|
||||||
|
#define MOD_WIDTH 3
|
||||||
|
|
||||||
|
struct ToolType {
|
||||||
|
enum Value {
|
||||||
|
BLOCK,
|
||||||
|
MOD,
|
||||||
|
CHARACTER,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
struct MouseInfo {
|
struct MouseInfo {
|
||||||
uint64_t cur_flags;
|
uint64_t cur_flags;
|
||||||
uint64_t prev_flags;
|
uint64_t prev_flags;
|
||||||
SDLPP::Vec2D< int > edit_box;
|
SDLPP::Vec2D< int > edit_box;
|
||||||
SDLPP::Vec2D< int > tool_box;
|
SDLPP::Vec2D< int > tool_box;
|
||||||
|
ToolType::Value tool_type;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MapInfo {
|
struct MapInfo {
|
||||||
@ -44,9 +61,14 @@ struct MapInfo {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct ToolInfo {
|
struct ToolInfo {
|
||||||
|
ToolType::Value type;
|
||||||
uint64_t index;
|
uint64_t index;
|
||||||
int cur_page;
|
int cur_page_tools;
|
||||||
int max_page;
|
int max_page_tools;
|
||||||
|
int cur_page_mods;
|
||||||
|
int max_page_mods;
|
||||||
|
int cur_page_characters;
|
||||||
|
int max_page_characters;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GlobalVars {
|
struct GlobalVars {
|
||||||
@ -56,6 +78,8 @@ struct GlobalVars {
|
|||||||
uint64_t flags;
|
uint64_t flags;
|
||||||
std::vector< mapColumnType > objects;
|
std::vector< mapColumnType > objects;
|
||||||
std::vector< std::shared_ptr< SDLPP::RenderObject > > tools;
|
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::shared_ptr< SDLPP::RenderObject > current_tool;
|
std::shared_ptr< SDLPP::RenderObject > current_tool;
|
||||||
std::shared_ptr< SDLPP::Texture > translucent_terrain_texture;
|
std::shared_ptr< SDLPP::Texture > translucent_terrain_texture;
|
||||||
std::shared_ptr< SDLPP::Texture > translucent_mario_texture;
|
std::shared_ptr< SDLPP::Texture > translucent_mario_texture;
|
||||||
@ -70,7 +94,20 @@ enum LandType::Value g_current_world_type = LandType::OVERWORLD;
|
|||||||
|
|
||||||
void updateTool() {
|
void updateTool() {
|
||||||
auto tool_index = global_vars.tool.index;
|
auto tool_index = global_vars.tool.index;
|
||||||
auto tool_role = getBlockRole( possibleBlocks[tool_index] );
|
uint64_t tool_id = 0;
|
||||||
|
switch(global_vars.tool.type) {
|
||||||
|
case ToolType::BLOCK:
|
||||||
|
tool_id = possibleBlocks[tool_index];
|
||||||
|
break;
|
||||||
|
case ToolType::MOD:
|
||||||
|
tool_id = possibleMods[tool_index];
|
||||||
|
break;
|
||||||
|
case ToolType::CHARACTER:
|
||||||
|
tool_id = possibleCharacters[tool_index];
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
auto tool_role = getBlockRole( tool_id );
|
||||||
std::shared_ptr< SDLPP::Texture > target_texture = nullptr;
|
std::shared_ptr< SDLPP::Texture > target_texture = nullptr;
|
||||||
switch ( tool_role ) {
|
switch ( tool_role ) {
|
||||||
case BlockRole::TERRAIN:
|
case BlockRole::TERRAIN:
|
||||||
@ -87,10 +124,9 @@ void updateTool() {
|
|||||||
}
|
}
|
||||||
global_vars.current_tool->setTexture(
|
global_vars.current_tool->setTexture(
|
||||||
target_texture,
|
target_texture,
|
||||||
getSourceRectByID( possibleBlocks[tool_index], g_current_world_type ) );
|
getSourceRectByID( tool_id, g_current_world_type ) );
|
||||||
global_vars.current_tool->setId( possibleBlocks[tool_index] );
|
global_vars.current_tool->setId( tool_id );
|
||||||
global_vars.current_tool->getCollisions()[0]->setId(
|
global_vars.current_tool->getCollisions()[0]->setId( tool_id );
|
||||||
possibleBlocks[tool_index] );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void removeMario() {
|
void removeMario() {
|
||||||
@ -106,51 +142,127 @@ void removeMario() {
|
|||||||
global_vars.mario->destroy();
|
global_vars.mario->destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateToolSelection( int prev_index ) {
|
void updateToolSelection( int prev_index, ToolType::Value type ) {
|
||||||
size_t prev = prev_index * 8;
|
size_t cur = 0;
|
||||||
size_t cur = global_vars.tool.cur_page * 8;
|
size_t multiplier = 0;
|
||||||
|
std::vector< std::shared_ptr< SDLPP::RenderObject > > *tool_vec = nullptr;
|
||||||
|
switch(type) {
|
||||||
|
case ToolType::BLOCK:
|
||||||
|
cur = global_vars.tool.cur_page_tools;
|
||||||
|
multiplier = 2*TOOLS_WIDTH;
|
||||||
|
tool_vec = &global_vars.tools;
|
||||||
|
break;
|
||||||
|
case ToolType::MOD:
|
||||||
|
cur = global_vars.tool.cur_page_mods;
|
||||||
|
multiplier = 2*MOD_WIDTH;
|
||||||
|
tool_vec = &global_vars.mods;
|
||||||
|
break;
|
||||||
|
case ToolType::CHARACTER:
|
||||||
|
cur = global_vars.tool.cur_page_characters;
|
||||||
|
multiplier = 2*CHARACTER_WIDTH;
|
||||||
|
tool_vec = &global_vars.characters;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
cur *= multiplier;
|
||||||
|
size_t prev = prev_index * multiplier;
|
||||||
for ( size_t i = prev;
|
for ( size_t i = prev;
|
||||||
i < ( global_vars.tools.size() < prev + 8 ? global_vars.tools.size()
|
i < ( tool_vec->size() < prev + multiplier ? tool_vec->size() : prev + multiplier );
|
||||||
: prev + 8 );
|
|
||||||
i++ ) {
|
i++ ) {
|
||||||
global_vars.tools[i]->setHidden( true );
|
tool_vec->at(i)->setHidden( true );
|
||||||
}
|
}
|
||||||
for ( size_t i = cur;
|
for ( size_t i = cur;
|
||||||
i < ( global_vars.tools.size() < cur + 8 ? global_vars.tools.size()
|
i < ( tool_vec->size() < cur + multiplier ? tool_vec->size()
|
||||||
: cur + 8 );
|
: cur + multiplier );
|
||||||
i++ ) {
|
i++ ) {
|
||||||
global_vars.tools[i]->setHidden( false );
|
tool_vec->at(i)->setHidden( false );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void moveToolsLeft() {
|
void moveToolsLeft(ToolType::Value type) {
|
||||||
global_vars.tool.cur_page--;
|
switch(type) {
|
||||||
updateToolSelection( global_vars.tool.cur_page + 1 );
|
case ToolType::BLOCK:
|
||||||
|
global_vars.tool.cur_page_tools--;
|
||||||
|
updateToolSelection( global_vars.tool.cur_page_tools + 1, type );
|
||||||
|
break;
|
||||||
|
case ToolType::MOD:
|
||||||
|
global_vars.tool.cur_page_mods--;
|
||||||
|
updateToolSelection( global_vars.tool.cur_page_mods + 1, type );
|
||||||
|
break;
|
||||||
|
case ToolType::CHARACTER:
|
||||||
|
global_vars.tool.cur_page_characters--;
|
||||||
|
updateToolSelection( global_vars.tool.cur_page_characters + 1, type );
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void moveToolsRight() {
|
void moveToolsRight(ToolType::Value type) {
|
||||||
global_vars.tool.cur_page++;
|
switch(type) {
|
||||||
updateToolSelection( global_vars.tool.cur_page - 1 );
|
case ToolType::BLOCK:
|
||||||
|
global_vars.tool.cur_page_tools++;
|
||||||
|
updateToolSelection( global_vars.tool.cur_page_tools - 1, type );
|
||||||
|
break;
|
||||||
|
case ToolType::MOD:
|
||||||
|
global_vars.tool.cur_page_mods++;
|
||||||
|
updateToolSelection( global_vars.tool.cur_page_mods - 1, type );
|
||||||
|
break;
|
||||||
|
case ToolType::CHARACTER:
|
||||||
|
global_vars.tool.cur_page_characters++;
|
||||||
|
updateToolSelection( global_vars.tool.cur_page_characters - 1, type );
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO add red outline to currently selected tool
|
// TODO add red outline to currently selected tool
|
||||||
// add WSAD navigation for the red highlight
|
// add WSAD navigation for the red highlight
|
||||||
// add mouse wheel navigation
|
// add mouse wheel navigation
|
||||||
void selectPrevTool() {
|
void selectPrevTool() {
|
||||||
|
int multiplier = 0;
|
||||||
|
switch(global_vars.tool.type) {
|
||||||
|
case ToolType::BLOCK:
|
||||||
|
multiplier = 2*TOOLS_WIDTH;
|
||||||
|
break;
|
||||||
|
case ToolType::MOD:
|
||||||
|
multiplier = 2*MOD_WIDTH;
|
||||||
|
break;
|
||||||
|
case ToolType::CHARACTER:
|
||||||
|
multiplier = 2*CHARACTER_WIDTH;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
if ( global_vars.tool.index == 0 )
|
if ( global_vars.tool.index == 0 )
|
||||||
return;
|
return;
|
||||||
if ( global_vars.tool.index % 8 == 0 ) {
|
if ( global_vars.tool.index % multiplier == 0 ) {
|
||||||
moveToolsLeft();
|
moveToolsLeft(global_vars.tool.type);
|
||||||
}
|
}
|
||||||
global_vars.tool.index--;
|
global_vars.tool.index--;
|
||||||
updateTool();
|
updateTool();
|
||||||
}
|
}
|
||||||
|
|
||||||
void selectNextTool() {
|
void selectNextTool() {
|
||||||
if ( global_vars.tool.index == global_vars.tools.size() - 1 )
|
int multiplier = 0;
|
||||||
|
size_t max_index = 0;
|
||||||
|
switch(global_vars.tool.type) {
|
||||||
|
case ToolType::BLOCK:
|
||||||
|
multiplier = 2*TOOLS_WIDTH;
|
||||||
|
max_index = global_vars.tools.size() - 1;
|
||||||
|
break;
|
||||||
|
case ToolType::MOD:
|
||||||
|
multiplier = 2*MOD_WIDTH;
|
||||||
|
max_index = global_vars.mods.size() - 1;
|
||||||
|
break;
|
||||||
|
case ToolType::CHARACTER:
|
||||||
|
multiplier = 2*CHARACTER_WIDTH;
|
||||||
|
max_index = global_vars.characters.size() - 1;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ( global_vars.tool.index == max_index )
|
||||||
return;
|
return;
|
||||||
if ( global_vars.tool.index % 8 == 7 ) {
|
if ( global_vars.tool.index % multiplier == (multiplier-1) ) {
|
||||||
moveToolsRight();
|
moveToolsRight(global_vars.tool.type);
|
||||||
}
|
}
|
||||||
global_vars.tool.index++;
|
global_vars.tool.index++;
|
||||||
updateTool();
|
updateTool();
|
||||||
@ -196,6 +308,7 @@ void getMousePositionFlags( SDLPP::Scene &scene ) {
|
|||||||
global_vars.mouse.cur_flags = visitor.getFlags();
|
global_vars.mouse.cur_flags = visitor.getFlags();
|
||||||
global_vars.mouse.edit_box = visitor.getEditBoxIndexes();
|
global_vars.mouse.edit_box = visitor.getEditBoxIndexes();
|
||||||
global_vars.mouse.tool_box = visitor.getToolBoxIndexes();
|
global_vars.mouse.tool_box = visitor.getToolBoxIndexes();
|
||||||
|
global_vars.mouse.tool_type = static_cast<ToolType::Value>(visitor.getToolType());
|
||||||
// if we found an edit box, move tool icon to that box
|
// if we found an edit box, move tool icon to that box
|
||||||
if ( visitor.foundEditBox() ) {
|
if ( visitor.foundEditBox() ) {
|
||||||
const auto &box = global_vars.mouse.edit_box;
|
const auto &box = global_vars.mouse.edit_box;
|
||||||
@ -221,14 +334,34 @@ void mouseUpAction( uint64_t flags, SDLPP::Scene &scene ) {
|
|||||||
scene.moveEverything( -BLOCK_SIZE, 0 );
|
scene.moveEverything( -BLOCK_SIZE, 0 );
|
||||||
}
|
}
|
||||||
if ( MouseVisitor::moveToolsLeft( flags ) &&
|
if ( MouseVisitor::moveToolsLeft( flags ) &&
|
||||||
global_vars.tool.cur_page != 0 ) {
|
global_vars.tool.cur_page_tools != 0 ) {
|
||||||
global_vars.tool.cur_page--;
|
global_vars.tool.cur_page_tools--;
|
||||||
updateToolSelection( global_vars.tool.cur_page + 1 );
|
updateToolSelection( global_vars.tool.cur_page_tools + 1, ToolType::BLOCK );
|
||||||
}
|
}
|
||||||
if ( MouseVisitor::moveToolsRight( flags ) &&
|
if ( MouseVisitor::moveToolsRight( flags ) &&
|
||||||
global_vars.tool.cur_page != global_vars.tool.max_page ) {
|
global_vars.tool.cur_page_tools != global_vars.tool.max_page_tools ) {
|
||||||
global_vars.tool.cur_page++;
|
global_vars.tool.cur_page_tools++;
|
||||||
updateToolSelection( global_vars.tool.cur_page - 1 );
|
updateToolSelection( global_vars.tool.cur_page_tools - 1, ToolType::BLOCK );
|
||||||
|
}
|
||||||
|
if ( MouseVisitor::moveModsLeft( flags ) &&
|
||||||
|
global_vars.tool.cur_page_mods != 0 ) {
|
||||||
|
global_vars.tool.cur_page_mods--;
|
||||||
|
updateToolSelection( global_vars.tool.cur_page_mods + 1, ToolType::MOD );
|
||||||
|
}
|
||||||
|
if ( MouseVisitor::moveModsRight( flags ) &&
|
||||||
|
global_vars.tool.cur_page_mods != global_vars.tool.max_page_mods ) {
|
||||||
|
global_vars.tool.cur_page_mods++;
|
||||||
|
updateToolSelection( global_vars.tool.cur_page_mods - 1, ToolType::MOD );
|
||||||
|
}
|
||||||
|
if ( MouseVisitor::moveCharactersLeft( flags ) &&
|
||||||
|
global_vars.tool.cur_page_characters != 0 ) {
|
||||||
|
global_vars.tool.cur_page_characters--;
|
||||||
|
updateToolSelection( global_vars.tool.cur_page_characters + 1, ToolType::CHARACTER );
|
||||||
|
}
|
||||||
|
if ( MouseVisitor::moveCharactersRight( flags ) &&
|
||||||
|
global_vars.tool.cur_page_characters != global_vars.tool.max_page_characters ) {
|
||||||
|
global_vars.tool.cur_page_characters++;
|
||||||
|
updateToolSelection( global_vars.tool.cur_page_characters - 1, ToolType::CHARACTER );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,10 +441,8 @@ void placeTool( SDLPP::Scene &scene ) {
|
|||||||
// TODO BlockRole::Character
|
// TODO BlockRole::Character
|
||||||
} else {
|
} else {
|
||||||
// TODO data
|
// TODO data
|
||||||
std::cout << "Want to set: " << (int)std::get< MapObject::MODIFIER_TYPE >( obj ) << std::endl;
|
|
||||||
std::get< MapObject::MODIFIER_TYPE >( obj ) = global_vars.current_tool->getId();
|
std::get< MapObject::MODIFIER_TYPE >( obj ) = global_vars.current_tool->getId();
|
||||||
std::get< MapObject::MODIFIER_DATA >( obj ) = 0;
|
std::get< MapObject::MODIFIER_DATA >( obj ) = 0;
|
||||||
std::cout << "SET MODIFIER_TYPE: " << (int)std::get< MapObject::MODIFIER_TYPE >( obj ) << std::endl;
|
|
||||||
new_obj = createTerrainBlock(
|
new_obj = createTerrainBlock(
|
||||||
global_vars.current_tool->getId(), LandType::OVERWORLD,
|
global_vars.current_tool->getId(), LandType::OVERWORLD,
|
||||||
renderer, 1 + global_vars.mouse.edit_box.getX(),
|
renderer, 1 + global_vars.mouse.edit_box.getX(),
|
||||||
@ -357,10 +488,31 @@ void pollEvents( SDLPP::Scene &scene ) {
|
|||||||
}
|
}
|
||||||
if ( global_vars.mouse.tool_box.getX() != -1 ) {
|
if ( global_vars.mouse.tool_box.getX() != -1 ) {
|
||||||
auto &tool_box = global_vars.mouse.tool_box;
|
auto &tool_box = global_vars.mouse.tool_box;
|
||||||
size_t index = tool_box.getY() * 4 + tool_box.getX();
|
int multiplier = 0;
|
||||||
if ( index < global_vars.tools.size() ) {
|
size_t max_index = 0;
|
||||||
global_vars.tool.index =
|
size_t cur_page = 0;
|
||||||
global_vars.tool.cur_page * 8 + index;
|
switch(global_vars.mouse.tool_type) {
|
||||||
|
case ToolType::BLOCK:
|
||||||
|
multiplier = 2*TOOLS_WIDTH;
|
||||||
|
max_index = global_vars.tools.size();
|
||||||
|
cur_page = global_vars.tool.cur_page_tools;
|
||||||
|
break;
|
||||||
|
case ToolType::MOD:
|
||||||
|
multiplier = 2*MOD_WIDTH;
|
||||||
|
max_index = global_vars.mods.size();
|
||||||
|
cur_page = global_vars.tool.cur_page_mods;
|
||||||
|
break;
|
||||||
|
case ToolType::CHARACTER:
|
||||||
|
multiplier = 2*CHARACTER_WIDTH;
|
||||||
|
max_index = global_vars.characters.size();
|
||||||
|
cur_page = global_vars.tool.cur_page_characters;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
global_vars.tool.type = global_vars.mouse.tool_type;
|
||||||
|
size_t index = tool_box.getY() * (multiplier/2) + tool_box.getX();
|
||||||
|
if ( index < max_index ) {
|
||||||
|
global_vars.tool.index = cur_page * multiplier + index;
|
||||||
updateTool();
|
updateTool();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -392,6 +544,7 @@ int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
|||||||
#else
|
#else
|
||||||
int main() {
|
int main() {
|
||||||
#endif
|
#endif
|
||||||
|
//TODO the code setting up UI is terrible, terrible mess, make it cleaner
|
||||||
SDLPP::init();
|
SDLPP::init();
|
||||||
SDLPP::Window w( "Mario editor!" );
|
SDLPP::Window w( "Mario editor!" );
|
||||||
w.setResizable( true );
|
w.setResizable( true );
|
||||||
@ -495,47 +648,38 @@ int main() {
|
|||||||
scene->addObject( mouse );
|
scene->addObject( mouse );
|
||||||
global_vars.map.max_page = global_vars.objects.size() - MAP_WIDTH;
|
global_vars.map.max_page = global_vars.objects.size() - MAP_WIDTH;
|
||||||
|
|
||||||
|
global_vars.tool.max_page_tools = ( possibleBlocks.size() - 1 ) / (2*TOOLS_WIDTH);
|
||||||
|
global_vars.tool.max_page_mods = ( possibleMods.size() - 1 ) / (2*MOD_WIDTH);
|
||||||
|
global_vars.tool.max_page_characters = ( possibleCharacters.size() - 1 ) / (2*CHARACTER_WIDTH);
|
||||||
// tools
|
// tools
|
||||||
global_vars.tool.max_page = ( possibleBlocks.size() - 1 ) / 8;
|
for ( int i = 0; i < TOOLS_WIDTH; i++ ) {
|
||||||
for ( int i = 0; i < 4; i++ ) {
|
auto tool_box1 = std::make_shared< ToolBox >( i, 0,
|
||||||
auto tool_box1 = std::make_shared< ToolBox >( i, 0, MAP_WIDTH,
|
(MAP_WIDTH - TOOLS_WIDTH) * BLOCK_SIZE, BLOCK_SIZE, renderer );
|
||||||
MAP_HEIGHT, renderer );
|
auto tool_box2 = std::make_shared< ToolBox >( i, 1, (MAP_WIDTH - TOOLS_WIDTH) * BLOCK_SIZE,
|
||||||
auto tool_box2 = std::make_shared< ToolBox >( i, 1, MAP_WIDTH,
|
BLOCK_SIZE, renderer );
|
||||||
MAP_HEIGHT, renderer );
|
tool_box1->setType(ToolType::BLOCK);
|
||||||
|
tool_box2->setType(ToolType::BLOCK);
|
||||||
scene->addObject( tool_box1 );
|
scene->addObject( tool_box1 );
|
||||||
scene->addObject( tool_box2 );
|
scene->addObject( tool_box2 );
|
||||||
// std::cout << "TOOL BOX POS: " << tool_box1->getPos().getX() <<
|
|
||||||
// ", " << tool_box1->getPos().getY() << std::endl; std::cout <<
|
|
||||||
// "TOOL BOX POS: " << tool_box2->getPos().getX() << ", " <<
|
|
||||||
// tool_box2->getPos().getY() << std::endl;
|
|
||||||
}
|
}
|
||||||
int tool_index = 0;
|
int tool_index = 0;
|
||||||
for ( auto &block : possibleBlocks ) {
|
for ( auto &block : possibleBlocks ) {
|
||||||
if ( block == MARIO_ID ) {
|
global_vars.tools.push_back( createTerrainBlock(
|
||||||
global_vars.tools.push_back(
|
block, LandType::OVERWORLD, renderer, false ) );
|
||||||
createMario( LandType::OVERWORLD, renderer, 0, 0 ) );
|
|
||||||
} else {
|
|
||||||
global_vars.tools.push_back( createTerrainBlock(
|
|
||||||
block, LandType::OVERWORLD, renderer, false ) );
|
|
||||||
}
|
|
||||||
global_vars.tools.back()->setHidden( true );
|
global_vars.tools.back()->setHidden( true );
|
||||||
global_vars.tools.back()->setPermanent();
|
global_vars.tools.back()->setPermanent();
|
||||||
auto x = tool_index % 4;
|
auto x = tool_index % TOOLS_WIDTH;
|
||||||
auto y = tool_index / 4;
|
auto y = tool_index / TOOLS_WIDTH;
|
||||||
// TODO add 14 and 1 as constants somewhere
|
global_vars.tools.back()->setPos( ( MAP_WIDTH - TOOLS_WIDTH ) * BLOCK_SIZE +
|
||||||
// TODO investigate when not permanent requires `-1` on x position
|
|
||||||
global_vars.tools.back()->setPos( ( MAP_WIDTH - 4 ) * BLOCK_SIZE +
|
|
||||||
x * BLOCK_SIZE,
|
x * BLOCK_SIZE,
|
||||||
BLOCK_SIZE + y * BLOCK_SIZE );
|
BLOCK_SIZE + y * BLOCK_SIZE );
|
||||||
// std::cout << "TOOL POS: " << tools.back()->getPos().getX() <<
|
|
||||||
// ", " << tools.back()->getPos().getY() << std::endl;
|
|
||||||
scene->addObject( global_vars.tools.back() );
|
scene->addObject( global_vars.tools.back() );
|
||||||
tool_index = ( tool_index + 1 ) % 8;
|
tool_index = ( tool_index + 1 ) % (2*TOOLS_WIDTH);
|
||||||
}
|
}
|
||||||
for ( int i = 0; i < 5; i++ ) {
|
for ( int i = 0; i <= TOOLS_WIDTH; i++ ) {
|
||||||
auto line = std::make_shared< SDLPP::LineRenderer >(
|
auto line = std::make_shared< SDLPP::LineRenderer >(
|
||||||
( MAP_WIDTH - 4 ) * BLOCK_SIZE + i * BLOCK_SIZE, BLOCK_SIZE,
|
( MAP_WIDTH - TOOLS_WIDTH ) * BLOCK_SIZE + i * BLOCK_SIZE, BLOCK_SIZE,
|
||||||
( MAP_WIDTH - 4 ) * BLOCK_SIZE + i * BLOCK_SIZE, 3 * BLOCK_SIZE,
|
( MAP_WIDTH - TOOLS_WIDTH ) * BLOCK_SIZE + i * BLOCK_SIZE, 3 * BLOCK_SIZE,
|
||||||
renderer, "#282828" );
|
renderer, "#282828" );
|
||||||
line->setPermanent();
|
line->setPermanent();
|
||||||
line->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
line->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||||
@ -543,23 +687,116 @@ int main() {
|
|||||||
}
|
}
|
||||||
for ( int i = 0; i < 3; i++ ) {
|
for ( int i = 0; i < 3; i++ ) {
|
||||||
auto line = std::make_shared< SDLPP::LineRenderer >(
|
auto line = std::make_shared< SDLPP::LineRenderer >(
|
||||||
( MAP_WIDTH - 4 ) * BLOCK_SIZE, BLOCK_SIZE + i * BLOCK_SIZE,
|
( MAP_WIDTH - TOOLS_WIDTH ) * BLOCK_SIZE, BLOCK_SIZE + i * BLOCK_SIZE,
|
||||||
( MAP_WIDTH - 4 ) * BLOCK_SIZE + 4 * BLOCK_SIZE,
|
( MAP_WIDTH - TOOLS_WIDTH ) * BLOCK_SIZE + TOOLS_WIDTH * BLOCK_SIZE,
|
||||||
|
BLOCK_SIZE + i * BLOCK_SIZE, renderer, "#282828" );
|
||||||
|
line->setPermanent();
|
||||||
|
line->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||||
|
scene->addObject( line );
|
||||||
|
}
|
||||||
|
//mods
|
||||||
|
for ( int i = 0; i < MOD_WIDTH; i++ ) {
|
||||||
|
auto mod_box1 = std::make_shared< ToolBox >( i, 0, BLOCK_SIZE,
|
||||||
|
BLOCK_SIZE, renderer );
|
||||||
|
auto mod_box2 = std::make_shared< ToolBox >( i, 1, BLOCK_SIZE,
|
||||||
|
BLOCK_SIZE, renderer );
|
||||||
|
mod_box1->setType(ToolType::MOD);
|
||||||
|
mod_box2->setType(ToolType::MOD);
|
||||||
|
scene->addObject( mod_box1 );
|
||||||
|
scene->addObject( mod_box2 );
|
||||||
|
}
|
||||||
|
tool_index = 0;
|
||||||
|
for ( auto &block : possibleMods ) {
|
||||||
|
//TODO createModBlock
|
||||||
|
global_vars.mods.push_back( createTerrainBlock(
|
||||||
|
block, LandType::OVERWORLD, renderer, false ) );
|
||||||
|
global_vars.mods.back()->setHidden( true );
|
||||||
|
global_vars.mods.back()->setPermanent();
|
||||||
|
auto x = tool_index % MOD_WIDTH;
|
||||||
|
auto y = tool_index / MOD_WIDTH;
|
||||||
|
global_vars.mods.back()->setPos( BLOCK_SIZE +
|
||||||
|
x * BLOCK_SIZE,
|
||||||
|
BLOCK_SIZE + y * BLOCK_SIZE );
|
||||||
|
scene->addObject( global_vars.mods.back() );
|
||||||
|
tool_index = ( tool_index + 1 ) % (2*MOD_WIDTH);
|
||||||
|
}
|
||||||
|
for ( int i = 0; i <= MOD_WIDTH; i++ ) {
|
||||||
|
auto line = std::make_shared< SDLPP::LineRenderer >(
|
||||||
|
BLOCK_SIZE + i * BLOCK_SIZE, BLOCK_SIZE,
|
||||||
|
BLOCK_SIZE + i * BLOCK_SIZE, 3 * BLOCK_SIZE,
|
||||||
|
renderer, "#282828" );
|
||||||
|
line->setPermanent();
|
||||||
|
line->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||||
|
scene->addObject( line );
|
||||||
|
}
|
||||||
|
for ( int i = 0; i < 3; i++ ) {
|
||||||
|
auto line = std::make_shared< SDLPP::LineRenderer >(
|
||||||
|
BLOCK_SIZE, BLOCK_SIZE + i * BLOCK_SIZE,
|
||||||
|
BLOCK_SIZE + MOD_WIDTH * BLOCK_SIZE,
|
||||||
|
BLOCK_SIZE + i * BLOCK_SIZE, renderer, "#282828" );
|
||||||
|
line->setPermanent();
|
||||||
|
line->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||||
|
scene->addObject( line );
|
||||||
|
}
|
||||||
|
//characters
|
||||||
|
for ( int i = 0; i < CHARACTER_WIDTH; i++ ) {
|
||||||
|
auto char_box1 = std::make_shared< ToolBox >( i, 0, (MOD_WIDTH+4)*BLOCK_SIZE,
|
||||||
|
BLOCK_SIZE, renderer );
|
||||||
|
auto char_box2 = std::make_shared< ToolBox >( i, 1, (MOD_WIDTH+4)*BLOCK_SIZE,
|
||||||
|
BLOCK_SIZE, renderer );
|
||||||
|
char_box1->setType(ToolType::CHARACTER);
|
||||||
|
char_box2->setType(ToolType::CHARACTER);
|
||||||
|
scene->addObject( char_box1 );
|
||||||
|
scene->addObject( char_box2 );
|
||||||
|
}
|
||||||
|
tool_index = 0;
|
||||||
|
for ( auto &block : possibleCharacters ) {
|
||||||
|
//TODO createCharacterBlock
|
||||||
|
if ( block == MARIO_ID ) {
|
||||||
|
global_vars.characters.push_back(
|
||||||
|
createMario( LandType::OVERWORLD, renderer, 0, 0 ) );
|
||||||
|
} else {
|
||||||
|
global_vars.characters.push_back( createTerrainBlock(
|
||||||
|
block, LandType::OVERWORLD, renderer, false ) );
|
||||||
|
}
|
||||||
|
global_vars.characters.back()->setHidden( true );
|
||||||
|
global_vars.characters.back()->setPermanent();
|
||||||
|
auto x = tool_index % CHARACTER_WIDTH;
|
||||||
|
auto y = tool_index / CHARACTER_WIDTH;
|
||||||
|
global_vars.characters.back()->setPos( (MOD_WIDTH + 4) * BLOCK_SIZE +
|
||||||
|
x * BLOCK_SIZE,
|
||||||
|
BLOCK_SIZE + y * BLOCK_SIZE );
|
||||||
|
scene->addObject( global_vars.characters.back() );
|
||||||
|
tool_index = ( tool_index + 1 ) % (2*CHARACTER_WIDTH);
|
||||||
|
}
|
||||||
|
for ( int i = 0; i <= CHARACTER_WIDTH; i++ ) {
|
||||||
|
auto line = std::make_shared< SDLPP::LineRenderer >(
|
||||||
|
(MOD_WIDTH + 4) * BLOCK_SIZE + i * BLOCK_SIZE, BLOCK_SIZE,
|
||||||
|
(MOD_WIDTH + 4) * BLOCK_SIZE + i * BLOCK_SIZE, 3 * BLOCK_SIZE,
|
||||||
|
renderer, "#282828" );
|
||||||
|
line->setPermanent();
|
||||||
|
line->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||||
|
scene->addObject( line );
|
||||||
|
}
|
||||||
|
for ( int i = 0; i < 3; i++ ) {
|
||||||
|
auto line = std::make_shared< SDLPP::LineRenderer >(
|
||||||
|
(MOD_WIDTH + 4) * BLOCK_SIZE, BLOCK_SIZE + i * BLOCK_SIZE,
|
||||||
|
(MOD_WIDTH + 4) * BLOCK_SIZE + CHARACTER_WIDTH * BLOCK_SIZE,
|
||||||
BLOCK_SIZE + i * BLOCK_SIZE, renderer, "#282828" );
|
BLOCK_SIZE + i * BLOCK_SIZE, renderer, "#282828" );
|
||||||
line->setPermanent();
|
line->setPermanent();
|
||||||
line->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
line->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||||
scene->addObject( line );
|
scene->addObject( line );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// white rectangles
|
||||||
auto tool_rect1 = std::make_shared< SDLPP::RectangleRender >(
|
auto tool_rect1 = std::make_shared< SDLPP::RectangleRender >(
|
||||||
( MAP_WIDTH - 5 ) * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE,
|
( MAP_WIDTH - TOOLS_WIDTH - 1 ) * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE,
|
||||||
renderer, "#FFFFFF88", true );
|
renderer, "#FFFFFF88", true );
|
||||||
tool_rect1->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
tool_rect1->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||||
tool_rect1->setId( EDITOR_LEFT_TOOL_ID );
|
tool_rect1->setId( EDITOR_LEFT_TOOL_ID );
|
||||||
tool_rect1->setPermanent();
|
tool_rect1->setPermanent();
|
||||||
tool_rect1->addCollision( SDLPP::RectColider( 0, 0, 1, 1 ) );
|
tool_rect1->addCollision( SDLPP::RectColider( 0, 0, 1, 1 ) );
|
||||||
scene->addObject( tool_rect1 );
|
scene->addObject( tool_rect1 );
|
||||||
// white rectangles
|
|
||||||
auto tool_rect2 = std::make_shared< SDLPP::RectangleRender >(
|
auto tool_rect2 = std::make_shared< SDLPP::RectangleRender >(
|
||||||
MAP_WIDTH * BLOCK_SIZE, 1 * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE,
|
MAP_WIDTH * BLOCK_SIZE, 1 * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE,
|
||||||
renderer, "#FFFFFF88", true );
|
renderer, "#FFFFFF88", true );
|
||||||
@ -568,8 +805,9 @@ int main() {
|
|||||||
tool_rect2->setPermanent();
|
tool_rect2->setPermanent();
|
||||||
tool_rect2->addCollision( SDLPP::RectColider( 0, 0, 1, 1 ) );
|
tool_rect2->addCollision( SDLPP::RectColider( 0, 0, 1, 1 ) );
|
||||||
scene->addObject( tool_rect2 );
|
scene->addObject( tool_rect2 );
|
||||||
|
// arrows
|
||||||
auto left_tool = std::make_shared< SDLPP::TextRenderer >(
|
auto left_tool = std::make_shared< SDLPP::TextRenderer >(
|
||||||
( MAP_WIDTH - 5 ) * BLOCK_SIZE, 1.5 * BLOCK_SIZE, BLOCK_SIZE,
|
( MAP_WIDTH - TOOLS_WIDTH - 1 ) * BLOCK_SIZE, 1.5 * BLOCK_SIZE, BLOCK_SIZE,
|
||||||
BLOCK_SIZE, renderer, "<", font_config );
|
BLOCK_SIZE, renderer, "<", font_config );
|
||||||
left_tool->setId( 0 );
|
left_tool->setId( 0 );
|
||||||
left_tool->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
left_tool->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||||
@ -582,6 +820,70 @@ int main() {
|
|||||||
right_tool->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
right_tool->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||||
right_tool->setPermanent();
|
right_tool->setPermanent();
|
||||||
scene->addObject( right_tool );
|
scene->addObject( right_tool );
|
||||||
|
// white rectangles
|
||||||
|
auto mod_rect1 = std::make_shared< SDLPP::RectangleRender >(
|
||||||
|
0, BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE,
|
||||||
|
renderer, "#FFFFFF88", true );
|
||||||
|
mod_rect1->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||||
|
mod_rect1->setId( EDITOR_LEFT_MOD_ID );
|
||||||
|
mod_rect1->setPermanent();
|
||||||
|
mod_rect1->addCollision( SDLPP::RectColider( 0, 0, 1, 1 ) );
|
||||||
|
scene->addObject( mod_rect1 );
|
||||||
|
auto mod_rect2 = std::make_shared< SDLPP::RectangleRender >(
|
||||||
|
(MOD_WIDTH + 1) * BLOCK_SIZE, 1 * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE,
|
||||||
|
renderer, "#FFFFFF88", true );
|
||||||
|
mod_rect2->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||||
|
mod_rect2->setId( EDITOR_RIGHT_MOD_ID );
|
||||||
|
mod_rect2->setPermanent();
|
||||||
|
mod_rect2->addCollision( SDLPP::RectColider( 0, 0, 1, 1 ) );
|
||||||
|
scene->addObject( mod_rect2 );
|
||||||
|
// arrows
|
||||||
|
auto left_mod = std::make_shared< SDLPP::TextRenderer >(
|
||||||
|
0, 1.5 * BLOCK_SIZE, BLOCK_SIZE,
|
||||||
|
BLOCK_SIZE, renderer, "<", font_config );
|
||||||
|
left_mod->setId( 0 );
|
||||||
|
left_mod->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||||
|
left_mod->setPermanent();
|
||||||
|
scene->addObject( left_mod );
|
||||||
|
auto right_mod = std::make_shared< SDLPP::TextRenderer >(
|
||||||
|
(MOD_WIDTH + 1) * BLOCK_SIZE, 1.5 * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE,
|
||||||
|
renderer, ">", font_config );
|
||||||
|
right_mod->setId( 0 );
|
||||||
|
right_mod->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||||
|
right_mod->setPermanent();
|
||||||
|
scene->addObject( right_mod );
|
||||||
|
// white rectangles
|
||||||
|
auto char_rect1 = std::make_shared< SDLPP::RectangleRender >(
|
||||||
|
( MOD_WIDTH + 3 ) * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE,
|
||||||
|
renderer, "#FFFFFF88", true );
|
||||||
|
char_rect1->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||||
|
char_rect1->setId( EDITOR_LEFT_CHARACTER_ID );
|
||||||
|
char_rect1->setPermanent();
|
||||||
|
char_rect1->addCollision( SDLPP::RectColider( 0, 0, 1, 1 ) );
|
||||||
|
scene->addObject( char_rect1 );
|
||||||
|
auto char_rect2 = std::make_shared< SDLPP::RectangleRender >(
|
||||||
|
(MOD_WIDTH + 4 + CHARACTER_WIDTH) * BLOCK_SIZE, 1 * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE,
|
||||||
|
renderer, "#FFFFFF88", true );
|
||||||
|
char_rect2->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||||
|
char_rect2->setId( EDITOR_RIGHT_CHARACTER_ID );
|
||||||
|
char_rect2->setPermanent();
|
||||||
|
char_rect2->addCollision( SDLPP::RectColider( 0, 0, 1, 1 ) );
|
||||||
|
scene->addObject( char_rect2 );
|
||||||
|
// arrows
|
||||||
|
auto left_char = std::make_shared< SDLPP::TextRenderer >(
|
||||||
|
( MOD_WIDTH + 3 ) * BLOCK_SIZE, 1.5 * BLOCK_SIZE, BLOCK_SIZE,
|
||||||
|
BLOCK_SIZE, renderer, "<", font_config );
|
||||||
|
left_char->setId( 0 );
|
||||||
|
left_char->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||||
|
left_char->setPermanent();
|
||||||
|
scene->addObject( left_char );
|
||||||
|
auto right_char = std::make_shared< SDLPP::TextRenderer >(
|
||||||
|
(MOD_WIDTH + 4 + CHARACTER_WIDTH) * BLOCK_SIZE, 1.5 * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE,
|
||||||
|
renderer, ">", font_config );
|
||||||
|
right_char->setId( 0 );
|
||||||
|
right_char->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
||||||
|
right_char->setPermanent();
|
||||||
|
scene->addObject( right_char );
|
||||||
|
|
||||||
global_vars.translucent_terrain_texture =
|
global_vars.translucent_terrain_texture =
|
||||||
std::make_shared< SDLPP::Texture >( renderer, "sprites/terrain.png",
|
std::make_shared< SDLPP::Texture >( renderer, "sprites/terrain.png",
|
||||||
@ -604,18 +906,27 @@ int main() {
|
|||||||
SDL_initFramerate( &gFPS );
|
SDL_initFramerate( &gFPS );
|
||||||
SDL_setFramerate( &gFPS, 60 );
|
SDL_setFramerate( &gFPS, 60 );
|
||||||
|
|
||||||
updateToolSelection( 0 );
|
updateToolSelection( 0, ToolType::BLOCK );
|
||||||
|
updateToolSelection( 0, ToolType::MOD );
|
||||||
|
updateToolSelection( 0, ToolType::CHARACTER );
|
||||||
|
|
||||||
auto base = SDL_GetTicks();
|
auto base = SDL_GetTicks();
|
||||||
int frames = 0;
|
int frames = 0;
|
||||||
std::thread inputThread( doInput, scene );
|
std::thread inputThread( doInput, scene );
|
||||||
inputThread.detach();
|
inputThread.detach();
|
||||||
setFlag( UPDATE_FLAG );
|
setFlag( UPDATE_FLAG );
|
||||||
|
global_vars.tool.cur_page_tools = 0;
|
||||||
|
global_vars.tool.cur_page_mods = 0;
|
||||||
|
global_vars.tool.cur_page_characters = 0;
|
||||||
// required for initial correct rendering
|
// required for initial correct rendering
|
||||||
setFlag( MAP_LEFT_ENABLED_FLAG );
|
setFlag( MAP_LEFT_ENABLED_FLAG );
|
||||||
setFlag( MAP_RIGHT_ENABLED_FLAG );
|
setFlag( MAP_RIGHT_ENABLED_FLAG );
|
||||||
setFlag( TOOL_LEFT_ENABLED_FLAG );
|
setFlag( TOOL_LEFT_ENABLED_FLAG );
|
||||||
setFlag( TOOL_RIGHT_ENABLED_FLAG );
|
setFlag( TOOL_RIGHT_ENABLED_FLAG );
|
||||||
|
setFlag( MOD_LEFT_ENABLED_FLAG );
|
||||||
|
setFlag( MOD_RIGHT_ENABLED_FLAG );
|
||||||
|
setFlag( CHARACTER_LEFT_ENABLED_FLAG );
|
||||||
|
setFlag( CHARACTER_RIGHT_ENABLED_FLAG );
|
||||||
while ( !getFlag( QUIT_FLAG ) ) {
|
while ( !getFlag( QUIT_FLAG ) ) {
|
||||||
SDL_PumpEvents();
|
SDL_PumpEvents();
|
||||||
SDL_framerateDelay( &gFPS );
|
SDL_framerateDelay( &gFPS );
|
||||||
@ -652,28 +963,73 @@ int main() {
|
|||||||
right->setTextColor( font, "#000000", "#282828", 0.05 );
|
right->setTextColor( font, "#000000", "#282828", 0.05 );
|
||||||
right->changeText( ">" );
|
right->changeText( ">" );
|
||||||
}
|
}
|
||||||
if ( global_vars.tool.cur_page == 0 &&
|
//TODO
|
||||||
|
if ( global_vars.tool.cur_page_tools == 0 &&
|
||||||
getFlag( TOOL_LEFT_ENABLED_FLAG ) ) {
|
getFlag( TOOL_LEFT_ENABLED_FLAG ) ) {
|
||||||
setFlag( UPDATE_FLAG );
|
setFlag( UPDATE_FLAG );
|
||||||
unsetFlag( TOOL_LEFT_ENABLED_FLAG );
|
unsetFlag( TOOL_LEFT_ENABLED_FLAG );
|
||||||
left_tool->setTextColor( font, "#CCCCCC", "#CCCCCC", 0.05 );
|
left_tool->setTextColor( font, "#CCCCCC", "#CCCCCC", 0.05 );
|
||||||
} else if ( global_vars.tool.cur_page != 0 &&
|
} else if ( global_vars.tool.cur_page_tools != 0 &&
|
||||||
!getFlag( TOOL_LEFT_ENABLED_FLAG ) ) {
|
!getFlag( TOOL_LEFT_ENABLED_FLAG ) ) {
|
||||||
setFlag( UPDATE_FLAG );
|
setFlag( UPDATE_FLAG );
|
||||||
setFlag( TOOL_LEFT_ENABLED_FLAG );
|
setFlag( TOOL_LEFT_ENABLED_FLAG );
|
||||||
left_tool->setTextColor( font, "#000000", "#282828", 0.05 );
|
left_tool->setTextColor( font, "#000000", "#282828", 0.05 );
|
||||||
}
|
}
|
||||||
if ( global_vars.tool.cur_page == global_vars.tool.max_page &&
|
if ( global_vars.tool.cur_page_tools == global_vars.tool.max_page_tools &&
|
||||||
getFlag( TOOL_RIGHT_ENABLED_FLAG ) ) {
|
getFlag( TOOL_RIGHT_ENABLED_FLAG ) ) {
|
||||||
setFlag( UPDATE_FLAG );
|
setFlag( UPDATE_FLAG );
|
||||||
unsetFlag( TOOL_RIGHT_ENABLED_FLAG );
|
unsetFlag( TOOL_RIGHT_ENABLED_FLAG );
|
||||||
right_tool->setTextColor( font, "#CCCCCC", "#CCCCCC", 0.05 );
|
right_tool->setTextColor( font, "#CCCCCC", "#CCCCCC", 0.05 );
|
||||||
} else if ( global_vars.tool.cur_page != global_vars.tool.max_page &&
|
} else if ( global_vars.tool.cur_page_tools != global_vars.tool.max_page_tools &&
|
||||||
!getFlag( TOOL_RIGHT_ENABLED_FLAG ) ) {
|
!getFlag( TOOL_RIGHT_ENABLED_FLAG ) ) {
|
||||||
setFlag( UPDATE_FLAG );
|
setFlag( UPDATE_FLAG );
|
||||||
setFlag( TOOL_RIGHT_ENABLED_FLAG );
|
setFlag( TOOL_RIGHT_ENABLED_FLAG );
|
||||||
right_tool->setTextColor( font, "#000000", "#282828", 0.05 );
|
right_tool->setTextColor( font, "#000000", "#282828", 0.05 );
|
||||||
}
|
}
|
||||||
|
if ( global_vars.tool.cur_page_mods == 0 &&
|
||||||
|
getFlag( MOD_LEFT_ENABLED_FLAG ) ) {
|
||||||
|
setFlag( UPDATE_FLAG );
|
||||||
|
unsetFlag( MOD_LEFT_ENABLED_FLAG );
|
||||||
|
left_mod->setTextColor( font, "#CCCCCC", "#CCCCCC", 0.05 );
|
||||||
|
} else if ( global_vars.tool.cur_page_mods != 0 &&
|
||||||
|
!getFlag( MOD_LEFT_ENABLED_FLAG ) ) {
|
||||||
|
setFlag( UPDATE_FLAG );
|
||||||
|
setFlag( MOD_LEFT_ENABLED_FLAG );
|
||||||
|
left_mod->setTextColor( font, "#000000", "#282828", 0.05 );
|
||||||
|
}
|
||||||
|
if ( global_vars.tool.cur_page_mods == global_vars.tool.max_page_mods &&
|
||||||
|
getFlag( MOD_RIGHT_ENABLED_FLAG ) ) {
|
||||||
|
setFlag( UPDATE_FLAG );
|
||||||
|
unsetFlag( MOD_RIGHT_ENABLED_FLAG );
|
||||||
|
right_mod->setTextColor( font, "#CCCCCC", "#CCCCCC", 0.05 );
|
||||||
|
} else if ( global_vars.tool.cur_page_mods != global_vars.tool.max_page_mods &&
|
||||||
|
!getFlag( MOD_RIGHT_ENABLED_FLAG ) ) {
|
||||||
|
setFlag( UPDATE_FLAG );
|
||||||
|
setFlag( MOD_RIGHT_ENABLED_FLAG );
|
||||||
|
right_mod->setTextColor( font, "#000000", "#282828", 0.05 );
|
||||||
|
}
|
||||||
|
if ( global_vars.tool.cur_page_characters == 0 &&
|
||||||
|
getFlag( CHARACTER_LEFT_ENABLED_FLAG ) ) {
|
||||||
|
setFlag( UPDATE_FLAG );
|
||||||
|
unsetFlag( CHARACTER_LEFT_ENABLED_FLAG );
|
||||||
|
left_char->setTextColor( font, "#CCCCCC", "#CCCCCC", 0.05 );
|
||||||
|
} else if ( global_vars.tool.cur_page_characters != 0 &&
|
||||||
|
!getFlag( CHARACTER_LEFT_ENABLED_FLAG ) ) {
|
||||||
|
setFlag( UPDATE_FLAG );
|
||||||
|
setFlag( CHARACTER_LEFT_ENABLED_FLAG );
|
||||||
|
left_char->setTextColor( font, "#000000", "#282828", 0.05 );
|
||||||
|
}
|
||||||
|
if ( global_vars.tool.cur_page_characters == global_vars.tool.max_page_characters &&
|
||||||
|
getFlag( CHARACTER_RIGHT_ENABLED_FLAG ) ) {
|
||||||
|
setFlag( UPDATE_FLAG );
|
||||||
|
unsetFlag( CHARACTER_RIGHT_ENABLED_FLAG );
|
||||||
|
right_char->setTextColor( font, "#CCCCCC", "#CCCCCC", 0.05 );
|
||||||
|
} else if ( global_vars.tool.cur_page_characters != global_vars.tool.max_page_characters &&
|
||||||
|
!getFlag( CHARACTER_RIGHT_ENABLED_FLAG ) ) {
|
||||||
|
setFlag( UPDATE_FLAG );
|
||||||
|
setFlag( CHARACTER_RIGHT_ENABLED_FLAG );
|
||||||
|
right_char->setTextColor( font, "#000000", "#282828", 0.05 );
|
||||||
|
}
|
||||||
if ( getFlag( UPDATE_FLAG ) ) {
|
if ( getFlag( UPDATE_FLAG ) ) {
|
||||||
scene->updateSizeAndPosition();
|
scene->updateSizeAndPosition();
|
||||||
unsetFlag( UPDATE_FLAG );
|
unsetFlag( UPDATE_FLAG );
|
||||||
|
@ -6,12 +6,14 @@
|
|||||||
|
|
||||||
#define SELECTED_LEFT_MAP 0x00000001
|
#define SELECTED_LEFT_MAP 0x00000001
|
||||||
#define SELECTED_RIGHT_MAP 0x00000002
|
#define SELECTED_RIGHT_MAP 0x00000002
|
||||||
#define SELECTED_LEFT_SELECT 0x00000004
|
#define SELECTED_REMOVE_BLOCK 0x00000004
|
||||||
#define SELECTED_RIGHT_SELECT 0x00000004
|
#define SELECTED_REMOVE_MODIFIER 0x00000008
|
||||||
#define SELECTED_REMOVE_BLOCK 0x00000008
|
#define SELECTED_RIGHT_TOOL 0x00000010
|
||||||
#define SELECTED_REMOVE_MODIFIER 0x00000010
|
#define SELECTED_LEFT_TOOL 0x00000020
|
||||||
#define SELECTED_RIGHT_TOOL 0x00000020
|
#define SELECTED_RIGHT_MOD 0x00000040
|
||||||
#define SELECTED_LEFT_TOOL 0x00000040
|
#define SELECTED_LEFT_MOD 0x00000080
|
||||||
|
#define SELECTED_RIGHT_CHARACTER 0x00000100
|
||||||
|
#define SELECTED_LEFT_CHARACTER 0x00000200
|
||||||
|
|
||||||
void MouseVisitor::visit( const SDLPP::RenderObject &obj ) {
|
void MouseVisitor::visit( const SDLPP::RenderObject &obj ) {
|
||||||
auto id = obj.getId();
|
auto id = obj.getId();
|
||||||
@ -28,6 +30,18 @@ void MouseVisitor::visit( const SDLPP::RenderObject &obj ) {
|
|||||||
case EDITOR_RIGHT_TOOL_ID:
|
case EDITOR_RIGHT_TOOL_ID:
|
||||||
select_flags |= SELECTED_RIGHT_TOOL;
|
select_flags |= SELECTED_RIGHT_TOOL;
|
||||||
break;
|
break;
|
||||||
|
case EDITOR_LEFT_MOD_ID:
|
||||||
|
select_flags |= SELECTED_LEFT_MOD;
|
||||||
|
break;
|
||||||
|
case EDITOR_RIGHT_MOD_ID:
|
||||||
|
select_flags |= SELECTED_RIGHT_MOD;
|
||||||
|
break;
|
||||||
|
case EDITOR_LEFT_CHARACTER_ID:
|
||||||
|
select_flags |= SELECTED_LEFT_CHARACTER;
|
||||||
|
break;
|
||||||
|
case EDITOR_RIGHT_CHARACTER_ID:
|
||||||
|
select_flags |= SELECTED_RIGHT_CHARACTER;
|
||||||
|
break;
|
||||||
case EDITOR_EDIT_SQUARE:
|
case EDITOR_EDIT_SQUARE:
|
||||||
edit_box = true;
|
edit_box = true;
|
||||||
edit_box_location = dynamic_cast< const EditBox & >( obj ).getIndexes();
|
edit_box_location = dynamic_cast< const EditBox & >( obj ).getIndexes();
|
||||||
@ -35,6 +49,7 @@ void MouseVisitor::visit( const SDLPP::RenderObject &obj ) {
|
|||||||
case EDITOR_TOOL_ID:
|
case EDITOR_TOOL_ID:
|
||||||
tool_box = true;
|
tool_box = true;
|
||||||
tool_box_location = dynamic_cast< const ToolBox & >( obj ).getIndexes();
|
tool_box_location = dynamic_cast< const ToolBox & >( obj ).getIndexes();
|
||||||
|
tool_box_type = dynamic_cast< const ToolBox & >( obj ).getType();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
@ -57,6 +72,22 @@ bool MouseVisitor::moveToolsRight( uint64_t flags ) {
|
|||||||
return flags & SELECTED_RIGHT_TOOL;
|
return flags & SELECTED_RIGHT_TOOL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MouseVisitor::moveModsLeft( uint64_t flags ) {
|
||||||
|
return flags & SELECTED_LEFT_MOD;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MouseVisitor::moveModsRight( uint64_t flags ) {
|
||||||
|
return flags & SELECTED_RIGHT_MOD;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MouseVisitor::moveCharactersLeft( uint64_t flags ) {
|
||||||
|
return flags & SELECTED_LEFT_CHARACTER;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MouseVisitor::moveCharactersRight( uint64_t flags ) {
|
||||||
|
return flags & SELECTED_RIGHT_CHARACTER;
|
||||||
|
}
|
||||||
|
|
||||||
void ToolVisitor::visit( const SDLPP::RenderObject &obj ) {
|
void ToolVisitor::visit( const SDLPP::RenderObject &obj ) {
|
||||||
auto id = obj.getCollisions()[0]->getId();
|
auto id = obj.getCollisions()[0]->getId();
|
||||||
switch ( id ) {
|
switch ( id ) {
|
||||||
|
@ -41,11 +41,18 @@ public:
|
|||||||
virtual uint64_t getVisitorType() override {
|
virtual uint64_t getVisitorType() override {
|
||||||
return _type;
|
return _type;
|
||||||
}
|
}
|
||||||
|
uint64_t getToolType() {
|
||||||
|
return tool_box_type;
|
||||||
|
}
|
||||||
|
|
||||||
static bool moveMapLeft( uint64_t flags );
|
static bool moveMapLeft( uint64_t flags );
|
||||||
static bool moveMapRight( uint64_t flags );
|
static bool moveMapRight( uint64_t flags );
|
||||||
static bool moveToolsLeft( uint64_t flags );
|
static bool moveToolsLeft( uint64_t flags );
|
||||||
static bool moveToolsRight( uint64_t flags );
|
static bool moveToolsRight( uint64_t flags );
|
||||||
|
static bool moveModsLeft( uint64_t flags );
|
||||||
|
static bool moveModsRight( uint64_t flags );
|
||||||
|
static bool moveCharactersLeft( uint64_t flags );
|
||||||
|
static bool moveCharactersRight( uint64_t flags );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint64_t select_flags = 0;
|
uint64_t select_flags = 0;
|
||||||
@ -54,6 +61,7 @@ private:
|
|||||||
SDLPP::Vec2D< int > edit_box_location = { -1, -1 };
|
SDLPP::Vec2D< int > edit_box_location = { -1, -1 };
|
||||||
SDLPP::Vec2D< int > tool_box_location = { -1, -1 };
|
SDLPP::Vec2D< int > tool_box_location = { -1, -1 };
|
||||||
uint64_t _type;
|
uint64_t _type;
|
||||||
|
uint64_t tool_box_type = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ToolVisitor : public SDLPP::Visitor {
|
class ToolVisitor : public SDLPP::Visitor {
|
||||||
|
@ -17,9 +17,9 @@ Mario::Mario(const std::shared_ptr< SDLPP::Renderer > &renderer) : SDLPP::Rectan
|
|||||||
bottom_detect.setMinHeight(1);
|
bottom_detect.setMinHeight(1);
|
||||||
addCollision(bottom_detect);
|
addCollision(bottom_detect);
|
||||||
addCollision(
|
addCollision(
|
||||||
SDLPP::RectColider( 0, 0.1, 0.1, 0.85, MARIO_LEFT_SIDE_DETECT ) );
|
SDLPP::RectColider( 0, 0.25, 0.1, 0.6, MARIO_LEFT_SIDE_DETECT ) );
|
||||||
addCollision(
|
addCollision(
|
||||||
SDLPP::RectColider( 0.9, 0.1, 0.1, 0.85, MARIO_RIGHT_SIDE_DETECT ) );
|
SDLPP::RectColider( 0.9, 0.25, 0.1, 0.6, MARIO_RIGHT_SIDE_DETECT ) );
|
||||||
addCollision(
|
addCollision(
|
||||||
SDLPP::RectColider( 0, 0, 0.1, 0.1, MARIO_TOP_LEFT_DETECT ) );
|
SDLPP::RectColider( 0, 0, 0.1, 0.1, MARIO_TOP_LEFT_DETECT ) );
|
||||||
addCollision(
|
addCollision(
|
||||||
|
@ -87,6 +87,10 @@
|
|||||||
#define EDITOR_LEFT_TOOL_ID 0xF007
|
#define EDITOR_LEFT_TOOL_ID 0xF007
|
||||||
#define EDITOR_RIGHT_TOOL_ID 0xF008
|
#define EDITOR_RIGHT_TOOL_ID 0xF008
|
||||||
#define EDITOR_CHARACTER_ID 0xF009
|
#define EDITOR_CHARACTER_ID 0xF009
|
||||||
|
#define EDITOR_LEFT_MOD_ID 0xF00A
|
||||||
|
#define EDITOR_RIGHT_MOD_ID 0xF00B
|
||||||
|
#define EDITOR_LEFT_CHARACTER_ID 0xF00C
|
||||||
|
#define EDITOR_RIGHT_CHARACTER_ID 0xF00D
|
||||||
|
|
||||||
#define MOUSE_VISITOR_TYPE 0xE003
|
#define MOUSE_VISITOR_TYPE 0xE003
|
||||||
#define MARIO_VISITOR_TYPE 0xE004
|
#define MARIO_VISITOR_TYPE 0xE004
|
||||||
|
@ -3,7 +3,8 @@
|
|||||||
#include "blocks.hpp"
|
#include "blocks.hpp"
|
||||||
#include "sprites.hpp"
|
#include "sprites.hpp"
|
||||||
|
|
||||||
ToolBox::ToolBox(int x, int y, int map_width, int map_height, std::shared_ptr<SDLPP::Renderer> renderer) : SDLPP::RectangleRender((map_width - 4)*BLOCK_SIZE + x*BLOCK_SIZE, 1*BLOCK_SIZE + y*BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, renderer) {
|
ToolBox::ToolBox(int x, int y, double start_x, double start_y, std::shared_ptr<SDLPP::Renderer> renderer) : SDLPP::RectangleRender(start_x + x*BLOCK_SIZE, start_y + y*BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, renderer) {
|
||||||
|
std::cout << "X: " << start_x + x * BLOCK_SIZE << ", " << start_y + y * BLOCK_SIZE << std::endl;
|
||||||
_x = x;
|
_x = x;
|
||||||
_y = y;
|
_y = y;
|
||||||
setId(EDITOR_TOOL_ID);
|
setId(EDITOR_TOOL_ID);
|
||||||
|
@ -5,11 +5,18 @@
|
|||||||
|
|
||||||
class ToolBox : public SDLPP::RectangleRender {
|
class ToolBox : public SDLPP::RectangleRender {
|
||||||
public:
|
public:
|
||||||
ToolBox(int x, int y, int map_width, int map_height, std::shared_ptr<SDLPP::Renderer> renderer);
|
ToolBox(int x, int y, double start_x, double start_y, std::shared_ptr<SDLPP::Renderer> renderer);
|
||||||
virtual SDLPP::Vec2D<int> getIndexes() const;
|
virtual SDLPP::Vec2D<int> getIndexes() const;
|
||||||
virtual void visit( SDLPP::Visitor &visitor ) override;
|
virtual void visit( SDLPP::Visitor &visitor ) override;
|
||||||
|
uint64_t getType() const {
|
||||||
|
return _type;
|
||||||
|
}
|
||||||
|
void setType(uint64_t type) {
|
||||||
|
_type = type;
|
||||||
|
}
|
||||||
private:
|
private:
|
||||||
int _x;
|
int _x;
|
||||||
int _y;
|
int _y;
|
||||||
|
uint64_t _type;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user