2021-05-02 12:14:11 +00:00
|
|
|
#include "editor_visitor.hpp"
|
|
|
|
#include "../sdlpp/sdlpp_renderobject.hpp"
|
2021-05-31 12:03:11 +00:00
|
|
|
#include "blocks.hpp"
|
2021-05-02 12:14:11 +00:00
|
|
|
#include "objectids.hpp"
|
|
|
|
#include "edit_box.hpp"
|
2021-05-07 07:43:57 +00:00
|
|
|
#include "tool_box.hpp"
|
2021-05-02 12:14:11 +00:00
|
|
|
|
|
|
|
#define SELECTED_LEFT_MAP 0x00000001
|
|
|
|
#define SELECTED_RIGHT_MAP 0x00000002
|
2021-05-28 17:51:02 +00:00
|
|
|
#define SELECTED_REMOVE_BLOCK 0x00000004
|
|
|
|
#define SELECTED_REMOVE_MODIFIER 0x00000008
|
|
|
|
#define SELECTED_RIGHT_TOOL 0x00000010
|
|
|
|
#define SELECTED_LEFT_TOOL 0x00000020
|
|
|
|
#define SELECTED_RIGHT_MOD 0x00000040
|
|
|
|
#define SELECTED_LEFT_MOD 0x00000080
|
|
|
|
#define SELECTED_RIGHT_CHARACTER 0x00000100
|
|
|
|
#define SELECTED_LEFT_CHARACTER 0x00000200
|
2021-05-02 12:14:11 +00:00
|
|
|
|
|
|
|
void MouseVisitor::visit( const SDLPP::RenderObject &obj ) {
|
|
|
|
auto id = obj.getId();
|
|
|
|
switch ( id ) {
|
|
|
|
case EDITOR_LEFT_MAP_ID:
|
|
|
|
select_flags |= SELECTED_LEFT_MAP;
|
|
|
|
break;
|
|
|
|
case EDITOR_RIGHT_MAP_ID:
|
|
|
|
select_flags |= SELECTED_RIGHT_MAP;
|
|
|
|
break;
|
2021-05-07 08:08:41 +00:00
|
|
|
case EDITOR_LEFT_TOOL_ID:
|
|
|
|
select_flags |= SELECTED_LEFT_TOOL;
|
|
|
|
break;
|
|
|
|
case EDITOR_RIGHT_TOOL_ID:
|
|
|
|
select_flags |= SELECTED_RIGHT_TOOL;
|
|
|
|
break;
|
2021-05-28 17:51:02 +00:00
|
|
|
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;
|
2021-05-02 12:14:11 +00:00
|
|
|
case EDITOR_EDIT_SQUARE:
|
|
|
|
edit_box = true;
|
2021-05-08 22:46:10 +00:00
|
|
|
edit_box_location = dynamic_cast< const EditBox & >( obj ).getIndexes();
|
2021-05-02 12:14:11 +00:00
|
|
|
break;
|
2021-05-07 07:43:57 +00:00
|
|
|
case EDITOR_TOOL_ID:
|
|
|
|
tool_box = true;
|
2021-05-08 22:46:10 +00:00
|
|
|
tool_box_location = dynamic_cast< const ToolBox & >( obj ).getIndexes();
|
2021-05-28 17:51:02 +00:00
|
|
|
tool_box_type = dynamic_cast< const ToolBox & >( obj ).getType();
|
2021-05-07 07:43:57 +00:00
|
|
|
break;
|
2021-05-02 12:14:11 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-08 22:46:10 +00:00
|
|
|
bool MouseVisitor::moveMapLeft( uint64_t flags ) {
|
2021-05-02 12:14:11 +00:00
|
|
|
return flags & SELECTED_LEFT_MAP;
|
|
|
|
}
|
|
|
|
|
2021-05-08 22:46:10 +00:00
|
|
|
bool MouseVisitor::moveMapRight( uint64_t flags ) {
|
2021-05-02 12:14:11 +00:00
|
|
|
return flags & SELECTED_RIGHT_MAP;
|
|
|
|
}
|
|
|
|
|
2021-05-08 22:46:10 +00:00
|
|
|
bool MouseVisitor::moveToolsLeft( uint64_t flags ) {
|
2021-05-07 08:08:41 +00:00
|
|
|
return flags & SELECTED_LEFT_TOOL;
|
|
|
|
}
|
|
|
|
|
2021-05-08 22:46:10 +00:00
|
|
|
bool MouseVisitor::moveToolsRight( uint64_t flags ) {
|
2021-05-07 08:08:41 +00:00
|
|
|
return flags & SELECTED_RIGHT_TOOL;
|
|
|
|
}
|
|
|
|
|
2021-05-28 17:51:02 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2021-05-02 12:14:11 +00:00
|
|
|
void ToolVisitor::visit( const SDLPP::RenderObject &obj ) {
|
|
|
|
auto id = obj.getCollisions()[0]->getId();
|
|
|
|
switch ( id ) {
|
2021-05-31 12:03:11 +00:00
|
|
|
case EDITOR_TERRAIN_ID: {
|
2021-08-07 10:13:23 +00:00
|
|
|
const auto &m_obj = dynamic_cast<const MarioBlock&>(obj);
|
2021-05-02 12:14:11 +00:00
|
|
|
remove_block = true;
|
2021-05-08 22:46:10 +00:00
|
|
|
if ( obj.getId() == source_id &&
|
2021-08-07 10:13:23 +00:00
|
|
|
((m_obj.getType() == source_type &&
|
|
|
|
getVisitorType() == VisitorType::Terrain) || ( m_obj.getData() == _data && getVisitorType() == VisitorType::Modifier))) {
|
2021-05-07 21:17:05 +00:00
|
|
|
add_block = false;
|
|
|
|
}
|
2021-05-31 12:03:11 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case EDITOR_CHARACTER_ID: {
|
2021-08-07 10:13:23 +00:00
|
|
|
const auto &m_obj = dynamic_cast<const MarioBlock&>(obj);
|
2021-05-07 21:17:05 +00:00
|
|
|
remove_block = true;
|
2021-05-08 22:46:10 +00:00
|
|
|
if ( obj.getId() == source_id &&
|
2021-05-31 12:03:11 +00:00
|
|
|
m_obj.getType() == source_type &&
|
2021-08-08 19:22:00 +00:00
|
|
|
getVisitorType() == VisitorType::Character ) {
|
2021-05-02 12:14:11 +00:00
|
|
|
add_block = false;
|
|
|
|
}
|
2021-05-31 12:03:11 +00:00
|
|
|
}
|
2021-05-02 12:14:11 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-08-07 10:13:23 +00:00
|
|
|
bool ToolVisitor::addBlock() const {
|
2021-05-02 12:14:11 +00:00
|
|
|
return add_block;
|
|
|
|
}
|
2021-08-07 10:13:23 +00:00
|
|
|
bool ToolVisitor::removeBlock() const {
|
2021-05-02 12:14:11 +00:00
|
|
|
return remove_block;
|
|
|
|
}
|