Mario editor: can paginate blocks now

This commit is contained in:
zv0n 2021-05-07 10:08:41 +02:00
parent f89d36c177
commit e084ed6f86
4 changed files with 81 additions and 5 deletions

View File

@ -70,6 +70,17 @@ void updateTool() {
current_tool->getCollisions()[0]->setId(possibleBlocks[current_block]);
}
void updateToolSelection(int prev_index) {
auto prev = prev_index * 8;
auto cur = current_tool_index * 8;
for(int i = prev; i < (tools.size() < prev + 8 ? tools.size() : prev + 8); i++) {
tools[i]->setHidden(true);
}
for(int i = cur; i < (tools.size() < cur + 8 ? tools.size() : cur + 8); i++) {
tools[i]->setHidden(false);
}
}
void handleKeyUp( SDL_Keycode key ) {
switch ( key ) {
case SDLK_a:
@ -132,6 +143,14 @@ void pollEvents( SDLPP::Scene &scene ) {
current_start_index += 1;
scene.moveEverything(-BLOCK_SIZE,0);
}
if(previous_selected_flags == current_selected_flags && MouseVisitor::moveToolsLeft(current_selected_flags) && current_tool_index != 0) {
current_tool_index -= 1;
updateToolSelection(current_tool_index + 1);
}
if(previous_selected_flags == current_selected_flags && MouseVisitor::moveToolsRight(current_selected_flags) && current_tool_index != max_tool_index) {
current_tool_index += 1;
updateToolSelection(current_tool_index - 1);
}
if(current_box.getX() != -1) {
std::lock_guard<std::mutex> lock(destruction_mutex);
@ -155,7 +174,7 @@ void pollEvents( SDLPP::Scene &scene ) {
if(current_tool_box.getX() != -1) {
auto index = current_tool_index + current_tool_box.getY() * 4 + current_tool_box.getX();
if(index < tools.size()) {
current_block = index;
current_block = (current_tool_index * 8 - 1) + index;
updateTool();
}
}
@ -187,7 +206,7 @@ int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
int main() {
#endif
SDLPP::init();
SDLPP::Window w( "Mario clone!" );
SDLPP::Window w( "Mario editor!" );
w.setResizable( true );
BLOCK_SIZE = 1.0 / 20;
@ -277,6 +296,7 @@ int main() {
current_max_index = objects.size() - 18;
// tools
max_tool_index = (possibleBlocks.size() - 1) / 8;
for(int i = 0; i < 4; i++) {
auto tool_box1 = std::make_shared<ToolBox>(i, 0, renderer);
auto tool_box2 = std::make_shared<ToolBox>(i, 1, renderer);
@ -313,6 +333,34 @@ int main() {
scene->addObject(line);
}
auto tool_rect1 = std::make_shared< SDLPP::RectangleRender >(
13*BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE, renderer, "#FFFFFF88", true);
tool_rect1->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
tool_rect1->setId(EDITOR_LEFT_TOOL_ID);
tool_rect1->setPermanent();
tool_rect1->addCollision(SDLPP::RectColider(0, 0, 1, 1));
scene->addObject(tool_rect1);
// white rectangles
auto tool_rect2 = std::make_shared< SDLPP::RectangleRender >(
18*BLOCK_SIZE, 1 * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE, renderer, "#FFFFFF88", true);
tool_rect2->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
tool_rect2->setId(EDITOR_RIGHT_TOOL_ID);
tool_rect2->setPermanent();
tool_rect2->addCollision(SDLPP::RectColider(0, 0, 1, 1));
scene->addObject(tool_rect2);
auto left_tool = std::make_shared< SDLPP::TextRenderer >(
13*BLOCK_SIZE, 1.5 * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, renderer, "<", font_config);
left_tool->setId(0);
left_tool->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
left_tool->setPermanent();
scene->addObject(left_tool);
auto right_tool = std::make_shared< SDLPP::TextRenderer >(
18*BLOCK_SIZE, 1.5 * BLOCK_SIZE, BLOCK_SIZE, BLOCK_SIZE, renderer, ">", font_config);
right_tool->setId(0);
right_tool->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
right_tool->setPermanent();
scene->addObject(right_tool);
g_placeholder_texture = std::make_shared< SDLPP::Texture >(
renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY );
current_tool = createTerrainBlock(possibleBlocks[current_block], OVERWORLD, renderer, g_placeholder_texture, false);
@ -327,9 +375,7 @@ int main() {
SDL_initFramerate( &gFPS );
SDL_setFramerate( &gFPS, 60 );
for(int i = current_tool_index; i < (tools.size() < current_tool_index + 8 ? tools.size() : current_tool_index + 8); i++) {
tools[i]->setHidden(false);
}
updateToolSelection(0);
auto base = SDL_GetTicks();
int frames = 0;
@ -359,6 +405,16 @@ int main() {
right->setTextColor(font, "#000000", "#282828", 0.05);
right->changeText(">");
}
if(current_tool_index == 0) {
left_tool->setTextColor(font, "#CCCCCC", "#CCCCCC", 0.05);
} else {
left_tool->setTextColor(font, "#000000", "#282828", 0.05);
}
if(current_tool_index == max_tool_index) {
right_tool->setTextColor(font, "#CCCCCC", "#CCCCCC", 0.05);
} else {
right_tool->setTextColor(font, "#000000", "#282828", 0.05);
}
if(update_size) {
scene->updateSizeAndPosition();
}

View File

@ -10,6 +10,8 @@
#define SELECTED_RIGHT_SELECT 0x00000004
#define SELECTED_REMOVE_BLOCK 0x00000008
#define SELECTED_REMOVE_MODIFIER 0x00000010
#define SELECTED_RIGHT_TOOL 0x00000020
#define SELECTED_LEFT_TOOL 0x00000040
void MouseVisitor::visit( const SDLPP::RenderObject &obj ) {
auto id = obj.getId();
@ -20,6 +22,12 @@ void MouseVisitor::visit( const SDLPP::RenderObject &obj ) {
case EDITOR_RIGHT_MAP_ID:
select_flags |= SELECTED_RIGHT_MAP;
break;
case EDITOR_LEFT_TOOL_ID:
select_flags |= SELECTED_LEFT_TOOL;
break;
case EDITOR_RIGHT_TOOL_ID:
select_flags |= SELECTED_RIGHT_TOOL;
break;
case EDITOR_EDIT_SQUARE:
edit_box = true;
edit_box_location = dynamic_cast<const EditBox&>(obj).getIndexes();
@ -41,6 +49,14 @@ bool MouseVisitor::moveMapRight(uint64_t flags) {
return flags & SELECTED_RIGHT_MAP;
}
bool MouseVisitor::moveToolsLeft(uint64_t flags) {
return flags & SELECTED_LEFT_TOOL;
}
bool MouseVisitor::moveToolsRight(uint64_t flags) {
return flags & SELECTED_RIGHT_TOOL;
}
void ToolVisitor::visit( const SDLPP::RenderObject &obj ) {
auto id = obj.getCollisions()[0]->getId();
switch ( id ) {

View File

@ -35,6 +35,8 @@ public:
static bool moveMapLeft(uint64_t flags);
static bool moveMapRight(uint64_t flags);
static bool moveToolsLeft(uint64_t flags);
static bool moveToolsRight(uint64_t flags);
private:
uint64_t select_flags = 0;

View File

@ -35,6 +35,8 @@
#define EDITOR_RIGHT_MAP_ID 0xF004
#define EDITOR_TERRAIN_ID 0xF005
#define EDITOR_TOOL_ID 0xF006
#define EDITOR_LEFT_TOOL_ID 0xF007
#define EDITOR_RIGHT_TOOL_ID 0xF008
#define TOOL_VISITOR_TYPE 0xE001
#define MOUSE_VISITOR_TYPE 0xE002