Mario Editor: Tool selection alpha

This commit is contained in:
2021-05-07 09:43:57 +02:00
parent c383654349
commit f89d36c177
9 changed files with 123 additions and 10 deletions
+59 -4
View File
@@ -19,6 +19,7 @@
#include "../sdlpp/sdlpp_mouse.hpp"
#include "edit_box.hpp"
#include "editor_visitor.hpp"
#include "tool_box.hpp"
std::shared_ptr< SDLPP::Renderer > renderer = nullptr;
bool quit = false;
@@ -32,7 +33,12 @@ int current_start_index = 0;
int current_max_index = 0;
uint64_t current_block = 0;
SDLPP::Vec2D<int> current_box = {0, 0};
SDLPP::Vec2D<int> current_tool_box = {0, 0};
std::vector<std::shared_ptr<SDLPP::RenderObject>> tools{};
std::shared_ptr<SDLPP::RenderObject> current_tool = nullptr;
int current_tool_index = 0;
int max_tool_index = 0;
std::shared_ptr<SDLPP::Texture> g_placeholder_texture = nullptr;
@@ -67,12 +73,12 @@ void updateTool() {
void handleKeyUp( SDL_Keycode key ) {
switch ( key ) {
case SDLK_a:
current_block = (current_block + possibleBlocks.size() - 1) % possibleBlocks.size();
updateTool();
// current_block = (current_block + possibleBlocks.size() - 1) % possibleBlocks.size();
// updateTool();
break;
case SDLK_d:
current_block = (current_block + 1) % possibleBlocks.size();
updateTool();
// current_block = (current_block + 1) % possibleBlocks.size();
// updateTool();
break;
case SDLK_w:
case SDLK_s:
@@ -110,6 +116,7 @@ void pollEvents( SDLPP::Scene &scene ) {
if(visitor.foundEditBox()) {
current_tool->setPos(BLOCK_SIZE + current_box.getX() * BLOCK_SIZE, 4*BLOCK_SIZE + current_box.getY() * BLOCK_SIZE);
}
current_tool_box = visitor.getToolBoxIndexes();
}
break;
case SDL_MOUSEBUTTONUP:
@@ -145,6 +152,13 @@ void pollEvents( SDLPP::Scene &scene ) {
scene.setZIndex(obj, 1);
}
}
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;
updateTool();
}
}
break;
case SDL_MOUSEBUTTONDOWN:
previous_selected_flags = current_selected_flags;
@@ -262,6 +276,43 @@ int main() {
scene->addObject( mouse );
current_max_index = objects.size() - 18;
// tools
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);
scene->addObject(tool_box1);
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;
for(auto &block : possibleBlocks) {
tools.push_back(createTerrainBlock(block, OVERWORLD, renderer, false));
tools.back()->setHidden(true);
auto x = tool_index % 4;
auto y = tool_index / 4;
// TODO add 14 and 1 as constants somewhere
// TODO investigate
tools.back()->setPos(13*BLOCK_SIZE + x*BLOCK_SIZE, BLOCK_SIZE + y*BLOCK_SIZE);
// std::cout << "TOOL POS: " << tools.back()->getPos().getX() << ", " << tools.back()->getPos().getY() << std::endl;
scene->addObject(tools.back());
tool_index = (tool_index + 1) % 8;
}
for(int i = 0; i < 5; i++) {
auto line = std::make_shared<SDLPP::LineRenderer>(
14*BLOCK_SIZE + i*BLOCK_SIZE, BLOCK_SIZE, 14 * 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>(
14*BLOCK_SIZE, BLOCK_SIZE + i*BLOCK_SIZE, 14 * BLOCK_SIZE + 4*BLOCK_SIZE, BLOCK_SIZE + i*BLOCK_SIZE, renderer, "#282828");
line->setPermanent();
line->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
scene->addObject(line);
}
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);
@@ -276,6 +327,10 @@ 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);
}
auto base = SDL_GetTicks();
int frames = 0;
std::thread inputThread( doInput, scene );