2021-04-30 19:02:14 +00:00
|
|
|
#include "../sdlpp/sdlpp.hpp"
|
|
|
|
#include "sprites.hpp"
|
|
|
|
#ifdef _WIN32
|
|
|
|
#include "../sdlpp/SDL2/SDL2_framerate.h"
|
|
|
|
#include <ctime>
|
|
|
|
#include <string>
|
|
|
|
#include <windows.h>
|
|
|
|
#else
|
|
|
|
#include <SDL2/SDL2_framerate.h>
|
|
|
|
#endif // UNIX
|
|
|
|
|
2021-05-07 06:35:01 +00:00
|
|
|
#include <array>
|
2021-04-30 19:02:14 +00:00
|
|
|
#include <thread>
|
2021-05-02 12:14:11 +00:00
|
|
|
#include <mutex>
|
2021-04-30 19:02:14 +00:00
|
|
|
#include "global_vars.hpp"
|
|
|
|
#include "objectids.hpp"
|
|
|
|
#include "blocks.hpp"
|
|
|
|
#include "maploader.hpp"
|
2021-05-01 19:55:43 +00:00
|
|
|
#include "../sdlpp/sdlpp_mouse.hpp"
|
2021-05-02 12:14:11 +00:00
|
|
|
#include "edit_box.hpp"
|
|
|
|
#include "editor_visitor.hpp"
|
2021-05-07 07:43:57 +00:00
|
|
|
#include "tool_box.hpp"
|
2021-07-24 17:59:25 +00:00
|
|
|
#include "blocks/coineditorblock.hpp"
|
2021-04-30 19:02:14 +00:00
|
|
|
|
2021-06-01 08:18:33 +00:00
|
|
|
#define MAP_WIDTH 24
|
2021-05-09 18:45:52 +00:00
|
|
|
#define MAP_HEIGHT 16
|
|
|
|
|
2021-05-22 20:13:22 +00:00
|
|
|
#define QUIT_FLAG 0x00000001
|
|
|
|
#define UPDATE_FLAG 0x00000002
|
|
|
|
#define MAP_LEFT_ENABLED_FLAG 0x00000004
|
|
|
|
#define MAP_RIGHT_ENABLED_FLAG 0x00000008
|
|
|
|
#define TOOL_LEFT_ENABLED_FLAG 0x00000010
|
|
|
|
#define TOOL_RIGHT_ENABLED_FLAG 0x00000020
|
2021-05-28 17:51:02 +00:00
|
|
|
#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
|
2021-06-01 08:18:33 +00:00
|
|
|
#define CHARACTER_WIDTH 3
|
2021-05-31 12:03:11 +00:00
|
|
|
#define MOD_WIDTH 2
|
|
|
|
#define OVERWORLD_WIDTH 2
|
2021-05-28 17:51:02 +00:00
|
|
|
|
|
|
|
struct ToolType {
|
|
|
|
enum Value {
|
|
|
|
BLOCK,
|
|
|
|
MOD,
|
|
|
|
CHARACTER,
|
2021-05-31 12:03:11 +00:00
|
|
|
WORLD,
|
2021-05-28 17:51:02 +00:00
|
|
|
};
|
|
|
|
};
|
2021-05-22 20:13:22 +00:00
|
|
|
|
2021-05-08 22:43:53 +00:00
|
|
|
struct MouseInfo {
|
2021-08-07 10:13:23 +00:00
|
|
|
uint64_t cur_flags{};
|
|
|
|
uint64_t prev_flags{};
|
2021-05-22 20:13:22 +00:00
|
|
|
SDLPP::Vec2D< int > edit_box;
|
|
|
|
SDLPP::Vec2D< int > tool_box;
|
2021-08-07 10:13:23 +00:00
|
|
|
ToolType::Value tool_type{};
|
2021-05-08 22:43:53 +00:00
|
|
|
};
|
|
|
|
|
2021-05-09 18:21:53 +00:00
|
|
|
struct MapInfo {
|
2021-05-22 20:13:22 +00:00
|
|
|
int cur_page;
|
|
|
|
int max_page;
|
2021-05-09 18:21:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ToolInfo {
|
2021-05-28 17:51:02 +00:00
|
|
|
ToolType::Value type;
|
2021-05-22 20:13:22 +00:00
|
|
|
uint64_t index;
|
2021-07-24 17:59:25 +00:00
|
|
|
SDL_Rect texture_src;
|
2021-05-28 17:51:02 +00:00
|
|
|
int cur_page_tools;
|
|
|
|
int max_page_tools;
|
|
|
|
int cur_page_mods;
|
|
|
|
int max_page_mods;
|
|
|
|
int cur_page_characters;
|
|
|
|
int max_page_characters;
|
2021-05-09 18:21:53 +00:00
|
|
|
};
|
|
|
|
|
2021-05-22 20:13:22 +00:00
|
|
|
struct GlobalVars {
|
2021-08-07 10:13:23 +00:00
|
|
|
MouseInfo mouse{};
|
|
|
|
MapInfo map{};
|
|
|
|
ToolInfo tool{};
|
|
|
|
uint64_t flags{};
|
2021-05-22 20:13:22 +00:00
|
|
|
std::vector< mapColumnType > objects;
|
2021-07-24 17:59:25 +00:00
|
|
|
std::vector< std::shared_ptr< MarioBlock > > tools;
|
|
|
|
std::vector< std::shared_ptr< MarioBlock > > mods;
|
|
|
|
std::vector< std::shared_ptr< MarioBlock > > characters;
|
2021-05-29 17:17:45 +00:00
|
|
|
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;
|
2021-08-07 10:13:23 +00:00
|
|
|
enum LandType::Value current_world_type{};
|
2021-07-22 22:08:05 +00:00
|
|
|
std::shared_ptr< MarioBlock > coin_tool;
|
|
|
|
std::shared_ptr< MarioBlock > generic_tool;
|
|
|
|
std::shared_ptr< MarioBlock > current_tool;
|
2021-05-22 20:13:22 +00:00
|
|
|
std::shared_ptr< SDLPP::Texture > translucent_terrain_texture;
|
|
|
|
std::shared_ptr< SDLPP::Texture > translucent_mario_texture;
|
2021-06-24 18:53:58 +00:00
|
|
|
std::shared_ptr< SDLPP::Texture > translucent_mod_texture;
|
2021-08-08 19:22:00 +00:00
|
|
|
std::shared_ptr< SDLPP::Texture > translucent_enemies_texture;
|
2021-05-22 20:13:22 +00:00
|
|
|
std::shared_ptr< SDLPP::RenderObject > mario;
|
|
|
|
SDLPP::Vec2D< int > mario_pos;
|
|
|
|
};
|
2021-05-07 21:17:05 +00:00
|
|
|
|
2021-05-22 20:13:22 +00:00
|
|
|
GlobalVars global_vars;
|
|
|
|
std::mutex destruction_mutex;
|
2021-05-02 12:28:17 +00:00
|
|
|
|
2021-05-08 22:43:53 +00:00
|
|
|
void updateTool() {
|
2021-05-22 20:13:22 +00:00
|
|
|
auto tool_index = global_vars.tool.index;
|
2021-05-28 17:51:02 +00:00
|
|
|
uint64_t tool_id = 0;
|
2021-05-29 17:24:47 +00:00
|
|
|
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;
|
2021-05-28 17:51:02 +00:00
|
|
|
}
|
|
|
|
auto tool_role = getBlockRole( tool_id );
|
2021-05-08 22:46:10 +00:00
|
|
|
std::shared_ptr< SDLPP::Texture > target_texture = nullptr;
|
2021-07-24 17:59:25 +00:00
|
|
|
SDL_Rect target_src;
|
2021-05-08 22:46:10 +00:00
|
|
|
switch ( tool_role ) {
|
|
|
|
case BlockRole::TERRAIN:
|
2021-05-22 20:13:22 +00:00
|
|
|
target_texture = global_vars.translucent_terrain_texture;
|
2021-07-24 17:59:25 +00:00
|
|
|
target_src = global_vars.tools[global_vars.tool.index]->getTextureSourceRect();
|
2021-05-08 22:46:10 +00:00
|
|
|
break;
|
|
|
|
case BlockRole::MARIO:
|
2021-05-22 20:13:22 +00:00
|
|
|
target_texture = global_vars.translucent_mario_texture;
|
2021-07-24 17:59:25 +00:00
|
|
|
target_src = global_vars.characters[global_vars.tool.index]->getTextureSourceRect();
|
2021-05-08 22:46:10 +00:00
|
|
|
break;
|
|
|
|
case BlockRole::MODIFIER:
|
2021-06-24 18:53:58 +00:00
|
|
|
target_texture = global_vars.translucent_mod_texture;
|
2021-07-24 17:59:25 +00:00
|
|
|
target_src = global_vars.mods[global_vars.tool.index]->getTextureSourceRect();
|
2021-05-08 22:46:10 +00:00
|
|
|
break;
|
|
|
|
case BlockRole::CHARACTER:
|
2021-08-08 19:22:00 +00:00
|
|
|
target_texture = global_vars.translucent_enemies_texture;
|
2021-07-24 17:59:25 +00:00
|
|
|
target_src = global_vars.characters[global_vars.tool.index]->getTextureSourceRect();
|
2021-05-08 22:46:10 +00:00
|
|
|
break;
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
2021-07-24 17:59:25 +00:00
|
|
|
global_vars.current_tool->setHidden( true );
|
|
|
|
if ( tool_id == COIN_MODIFIER_ID ) {
|
|
|
|
global_vars.coin_tool->setPos( global_vars.current_tool->getPos() );
|
2021-07-22 22:08:05 +00:00
|
|
|
global_vars.current_tool = global_vars.coin_tool;
|
|
|
|
} else {
|
2021-07-24 17:59:25 +00:00
|
|
|
global_vars.generic_tool->setPos( global_vars.current_tool->getPos() );
|
2021-07-22 22:08:05 +00:00
|
|
|
global_vars.current_tool = global_vars.generic_tool;
|
2021-07-24 17:59:25 +00:00
|
|
|
global_vars.current_tool->setTexture( target_texture, target_src );
|
2021-07-22 22:08:05 +00:00
|
|
|
global_vars.current_tool->setId( tool_id );
|
|
|
|
global_vars.current_tool->getCollisions()[0]->setId( tool_id );
|
|
|
|
}
|
2021-07-24 17:59:25 +00:00
|
|
|
global_vars.current_tool->setHidden( false );
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void removeMario() {
|
2021-08-07 10:13:23 +00:00
|
|
|
if ( !global_vars.mario ) {
|
2021-05-08 22:43:53 +00:00
|
|
|
return;
|
2021-08-07 10:13:23 +00:00
|
|
|
}
|
2021-05-22 20:13:22 +00:00
|
|
|
global_vars
|
2021-06-07 21:48:28 +00:00
|
|
|
.objects[global_vars.mario_pos.getX()][global_vars.mario_pos.getY()]
|
|
|
|
.unsetCharacter();
|
2021-05-22 20:13:22 +00:00
|
|
|
global_vars.mario->destroy();
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
|
|
|
|
2021-05-29 17:24:47 +00:00
|
|
|
void setToolColor( const std::string &color ) {
|
2021-08-07 10:13:23 +00:00
|
|
|
std::vector< std::shared_ptr< SDLPP::RenderObject > > *store = nullptr;
|
2021-05-29 17:17:45 +00:00
|
|
|
int multiplier = 0;
|
2021-05-29 17:24:47 +00:00
|
|
|
switch ( global_vars.tool.type ) {
|
|
|
|
case ToolType::BLOCK:
|
|
|
|
multiplier = TOOLS_WIDTH;
|
|
|
|
store = &global_vars.tool_boxes;
|
|
|
|
break;
|
|
|
|
case ToolType::MOD:
|
|
|
|
multiplier = MOD_WIDTH;
|
|
|
|
store = &global_vars.mod_boxes;
|
|
|
|
break;
|
|
|
|
case ToolType::CHARACTER:
|
|
|
|
multiplier = CHARACTER_WIDTH;
|
|
|
|
store = &global_vars.character_boxes;
|
|
|
|
default:
|
|
|
|
break;
|
2021-05-29 17:17:45 +00:00
|
|
|
}
|
2021-08-07 10:13:23 +00:00
|
|
|
if ( store == nullptr ) {
|
2021-06-04 12:49:24 +00:00
|
|
|
return;
|
2021-08-07 10:13:23 +00:00
|
|
|
}
|
2021-05-29 17:24:47 +00:00
|
|
|
auto index = global_vars.tool.index % ( 2 * multiplier );
|
|
|
|
store->at( index )->setColor( color );
|
2021-05-29 17:17:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void setToolColor() {
|
2021-05-29 17:24:47 +00:00
|
|
|
setToolColor( "#FFFF8888" );
|
2021-05-29 17:17:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void unsetToolColor() {
|
2021-05-29 17:24:47 +00:00
|
|
|
setToolColor( "#FFFFFF00" );
|
2021-05-29 17:17:45 +00:00
|
|
|
}
|
|
|
|
|
2021-05-28 17:51:02 +00:00
|
|
|
void updateToolSelection( int prev_index, ToolType::Value type ) {
|
2021-05-29 17:17:45 +00:00
|
|
|
unsetToolColor();
|
|
|
|
size_t cur_page = 0;
|
2021-05-28 17:51:02 +00:00
|
|
|
size_t multiplier = 0;
|
2021-07-24 17:59:25 +00:00
|
|
|
std::vector< std::shared_ptr< MarioBlock > > *tool_vec = nullptr;
|
2021-05-29 17:24:47 +00:00
|
|
|
switch ( type ) {
|
|
|
|
case ToolType::BLOCK:
|
|
|
|
cur_page = global_vars.tool.cur_page_tools;
|
|
|
|
multiplier = 2 * TOOLS_WIDTH;
|
|
|
|
tool_vec = &global_vars.tools;
|
|
|
|
break;
|
|
|
|
case ToolType::MOD:
|
|
|
|
cur_page = global_vars.tool.cur_page_mods;
|
|
|
|
multiplier = 2 * MOD_WIDTH;
|
|
|
|
tool_vec = &global_vars.mods;
|
|
|
|
break;
|
|
|
|
case ToolType::CHARACTER:
|
|
|
|
cur_page = global_vars.tool.cur_page_characters;
|
|
|
|
multiplier = 2 * CHARACTER_WIDTH;
|
|
|
|
tool_vec = &global_vars.characters;
|
|
|
|
default:
|
|
|
|
break;
|
2021-05-28 17:51:02 +00:00
|
|
|
}
|
2021-08-07 10:13:23 +00:00
|
|
|
if ( tool_vec == nullptr ) {
|
2021-06-04 12:49:24 +00:00
|
|
|
return;
|
2021-08-07 10:13:23 +00:00
|
|
|
}
|
2021-05-29 17:17:45 +00:00
|
|
|
auto cur = cur_page * multiplier;
|
2021-05-28 17:51:02 +00:00
|
|
|
size_t prev = prev_index * multiplier;
|
2021-05-08 22:46:10 +00:00
|
|
|
for ( size_t i = prev;
|
2021-05-29 17:24:47 +00:00
|
|
|
i < ( tool_vec->size() < prev + multiplier ? tool_vec->size()
|
|
|
|
: prev + multiplier );
|
2021-05-22 20:13:22 +00:00
|
|
|
i++ ) {
|
2021-05-29 17:24:47 +00:00
|
|
|
tool_vec->at( i )->setHidden( true );
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
2021-05-08 22:46:10 +00:00
|
|
|
for ( size_t i = cur;
|
2021-05-28 17:51:02 +00:00
|
|
|
i < ( tool_vec->size() < cur + multiplier ? tool_vec->size()
|
2021-05-29 17:24:47 +00:00
|
|
|
: cur + multiplier );
|
2021-05-22 20:13:22 +00:00
|
|
|
i++ ) {
|
2021-05-29 17:24:47 +00:00
|
|
|
tool_vec->at( i )->setHidden( false );
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
2021-06-04 12:49:24 +00:00
|
|
|
if ( global_vars.tool.index / multiplier == cur_page ) {
|
2021-05-29 17:17:45 +00:00
|
|
|
setToolColor();
|
2021-06-04 12:49:24 +00:00
|
|
|
}
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
|
|
|
|
2021-05-29 17:24:47 +00:00
|
|
|
void moveToolsLeft( ToolType::Value type ) {
|
|
|
|
switch ( type ) {
|
|
|
|
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;
|
2021-05-28 17:51:02 +00:00
|
|
|
}
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
|
|
|
|
2021-05-29 17:24:47 +00:00
|
|
|
void moveToolsRight( ToolType::Value type ) {
|
|
|
|
switch ( type ) {
|
|
|
|
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;
|
2021-05-28 17:51:02 +00:00
|
|
|
}
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
|
|
|
|
2021-06-04 12:49:24 +00:00
|
|
|
void updateToolIndex( uint64_t new_index, ToolType::Value new_type ) {
|
2021-05-28 17:51:02 +00:00
|
|
|
int multiplier = 0;
|
2021-05-29 17:17:45 +00:00
|
|
|
int *page = nullptr;
|
2021-07-24 17:59:25 +00:00
|
|
|
switch ( new_type ) {
|
2021-05-29 17:24:47 +00:00
|
|
|
case ToolType::BLOCK:
|
|
|
|
multiplier = 2 * TOOLS_WIDTH;
|
|
|
|
page = &global_vars.tool.cur_page_tools;
|
|
|
|
break;
|
|
|
|
case ToolType::MOD:
|
|
|
|
multiplier = 2 * MOD_WIDTH;
|
|
|
|
page = &global_vars.tool.cur_page_mods;
|
|
|
|
break;
|
|
|
|
case ToolType::CHARACTER:
|
|
|
|
multiplier = 2 * CHARACTER_WIDTH;
|
|
|
|
page = &global_vars.tool.cur_page_characters;
|
|
|
|
default:
|
|
|
|
break;
|
2021-05-29 17:17:45 +00:00
|
|
|
}
|
|
|
|
unsetToolColor();
|
2021-06-04 12:49:24 +00:00
|
|
|
global_vars.tool.type = new_type;
|
2021-05-29 17:17:45 +00:00
|
|
|
global_vars.tool.index = new_index;
|
|
|
|
setToolColor();
|
|
|
|
updateTool();
|
2021-05-29 17:24:47 +00:00
|
|
|
if ( new_index / multiplier != static_cast< uint64_t >( *page ) ) {
|
2021-05-29 17:17:45 +00:00
|
|
|
auto prev = *page;
|
|
|
|
*page = new_index / multiplier;
|
2021-05-29 17:24:47 +00:00
|
|
|
updateToolSelection( prev, global_vars.tool.type );
|
2021-05-29 17:17:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-04 12:49:24 +00:00
|
|
|
void updateToolIndex( uint64_t new_index ) {
|
2021-06-07 21:48:28 +00:00
|
|
|
updateToolIndex( new_index, global_vars.tool.type );
|
2021-06-04 12:49:24 +00:00
|
|
|
}
|
|
|
|
|
2021-05-29 17:17:45 +00:00
|
|
|
void selectLowerTool() {
|
|
|
|
int multiplier = 0;
|
|
|
|
size_t max_index = 0;
|
2021-05-29 17:24:47 +00:00
|
|
|
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;
|
2021-05-28 17:51:02 +00:00
|
|
|
}
|
2021-05-29 17:24:47 +00:00
|
|
|
if ( global_vars.tool.index % multiplier >=
|
|
|
|
static_cast< uint64_t >( multiplier / 2 ) ||
|
|
|
|
global_vars.tool.index + multiplier / 2 > max_index ) {
|
2021-05-08 22:43:53 +00:00
|
|
|
return;
|
2021-05-29 17:24:47 +00:00
|
|
|
}
|
|
|
|
updateToolIndex( global_vars.tool.index + multiplier / 2 );
|
2021-05-29 17:17:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void selectUpperTool() {
|
|
|
|
int multiplier = 0;
|
2021-05-29 17:24:47 +00:00
|
|
|
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;
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
2021-05-29 17:24:47 +00:00
|
|
|
if ( global_vars.tool.index % multiplier <
|
|
|
|
static_cast< uint64_t >( multiplier / 2 ) ) {
|
2021-05-29 17:17:45 +00:00
|
|
|
return;
|
2021-05-29 17:24:47 +00:00
|
|
|
}
|
|
|
|
updateToolIndex( global_vars.tool.index - multiplier / 2 );
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
|
|
|
|
2021-05-29 17:17:45 +00:00
|
|
|
void selectPrevTool() {
|
2021-05-28 17:51:02 +00:00
|
|
|
int multiplier = 0;
|
2021-05-29 17:24:47 +00:00
|
|
|
switch ( global_vars.tool.type ) {
|
|
|
|
case ToolType::BLOCK:
|
|
|
|
multiplier = TOOLS_WIDTH;
|
|
|
|
break;
|
|
|
|
case ToolType::MOD:
|
|
|
|
multiplier = MOD_WIDTH;
|
|
|
|
break;
|
|
|
|
case ToolType::CHARACTER:
|
|
|
|
multiplier = CHARACTER_WIDTH;
|
|
|
|
default:
|
|
|
|
break;
|
2021-05-29 17:17:45 +00:00
|
|
|
}
|
|
|
|
int subtraction = 1;
|
2021-08-07 10:13:23 +00:00
|
|
|
if ( global_vars.tool.index % multiplier == 0 ) {
|
2021-05-29 17:17:45 +00:00
|
|
|
subtraction = multiplier + 1;
|
2021-08-07 10:13:23 +00:00
|
|
|
}
|
2021-05-29 17:24:47 +00:00
|
|
|
if ( global_vars.tool.index == 0 ||
|
|
|
|
global_vars.tool.index - subtraction >
|
|
|
|
static_cast< uint64_t >( -multiplier ) ) {
|
2021-05-29 17:17:45 +00:00
|
|
|
return;
|
2021-05-29 17:24:47 +00:00
|
|
|
}
|
|
|
|
updateToolIndex( global_vars.tool.index - subtraction );
|
2021-05-29 17:17:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void selectNextTool() {
|
2021-05-28 17:51:02 +00:00
|
|
|
size_t max_index = 0;
|
2021-05-29 17:17:45 +00:00
|
|
|
int multiplier = 0;
|
2021-05-29 17:24:47 +00:00
|
|
|
switch ( global_vars.tool.type ) {
|
|
|
|
case ToolType::BLOCK:
|
|
|
|
max_index = global_vars.tools.size() - 1;
|
|
|
|
multiplier = TOOLS_WIDTH;
|
|
|
|
break;
|
|
|
|
case ToolType::MOD:
|
|
|
|
max_index = global_vars.mods.size() - 1;
|
|
|
|
multiplier = MOD_WIDTH;
|
|
|
|
break;
|
|
|
|
case ToolType::CHARACTER:
|
|
|
|
max_index = global_vars.characters.size() - 1;
|
|
|
|
multiplier = CHARACTER_WIDTH;
|
|
|
|
default:
|
|
|
|
break;
|
2021-05-28 17:51:02 +00:00
|
|
|
}
|
2021-05-29 17:17:45 +00:00
|
|
|
int addition = 1;
|
2021-05-31 14:08:14 +00:00
|
|
|
if ( global_vars.tool.index % multiplier ==
|
2021-08-07 10:13:23 +00:00
|
|
|
static_cast< uint64_t >( multiplier - 1 ) ) {
|
2021-05-29 17:17:45 +00:00
|
|
|
addition = multiplier + 1;
|
2021-08-07 10:13:23 +00:00
|
|
|
}
|
|
|
|
if ( global_vars.tool.index == max_index ) {
|
2021-05-08 22:43:53 +00:00
|
|
|
return;
|
2021-08-07 10:13:23 +00:00
|
|
|
}
|
|
|
|
if ( global_vars.tool.index + addition > max_index ) {
|
2021-05-29 17:17:45 +00:00
|
|
|
addition = 1;
|
2021-08-07 10:13:23 +00:00
|
|
|
}
|
2021-05-29 17:24:47 +00:00
|
|
|
updateToolIndex( global_vars.tool.index + addition );
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
|
|
|
|
2021-05-22 20:13:22 +00:00
|
|
|
void setFlag( uint64_t flag ) {
|
|
|
|
global_vars.flags |= flag;
|
|
|
|
}
|
|
|
|
void unsetFlag( uint64_t flag ) {
|
|
|
|
global_vars.flags &= ~flag;
|
|
|
|
}
|
|
|
|
bool getFlag( uint64_t flag ) {
|
|
|
|
return global_vars.flags & flag;
|
|
|
|
}
|
|
|
|
|
2021-05-31 12:03:11 +00:00
|
|
|
void updateWorld() {
|
2021-05-31 12:04:28 +00:00
|
|
|
for ( auto &block : global_vars.tools ) {
|
2021-07-24 17:59:25 +00:00
|
|
|
block->setType( global_vars.current_world_type );
|
2021-05-31 12:03:11 +00:00
|
|
|
}
|
2021-05-31 12:04:28 +00:00
|
|
|
for ( auto &block : global_vars.characters ) {
|
2021-07-24 17:59:25 +00:00
|
|
|
block->setType( global_vars.current_world_type );
|
2021-05-31 12:03:11 +00:00
|
|
|
}
|
2021-07-24 17:59:25 +00:00
|
|
|
if ( getBlockRole( global_vars.current_tool->getId() ) !=
|
|
|
|
BlockRole::MODIFIER ) {
|
2021-07-22 22:08:05 +00:00
|
|
|
global_vars.current_tool->setType( global_vars.current_world_type );
|
|
|
|
}
|
2021-05-31 12:03:11 +00:00
|
|
|
}
|
|
|
|
|
2021-05-29 17:17:45 +00:00
|
|
|
// TODO add mouse wheel control for modifiers
|
2021-05-08 22:43:53 +00:00
|
|
|
void handleKeyUp( SDL_Keycode key, SDLPP::Scene &scene ) {
|
2021-04-30 19:02:14 +00:00
|
|
|
switch ( key ) {
|
|
|
|
case SDLK_ESCAPE:
|
2021-05-22 20:13:22 +00:00
|
|
|
setFlag( QUIT_FLAG );
|
2021-04-30 19:02:14 +00:00
|
|
|
break;
|
|
|
|
case SDLK_a:
|
2021-05-08 22:43:53 +00:00
|
|
|
selectPrevTool();
|
2021-04-30 19:02:14 +00:00
|
|
|
break;
|
|
|
|
case SDLK_d:
|
2021-05-08 22:43:53 +00:00
|
|
|
selectNextTool();
|
2021-04-30 19:02:14 +00:00
|
|
|
break;
|
2021-05-29 17:17:45 +00:00
|
|
|
case SDLK_w:
|
|
|
|
selectUpperTool();
|
|
|
|
break;
|
|
|
|
case SDLK_s:
|
|
|
|
selectLowerTool();
|
|
|
|
break;
|
2021-05-31 12:03:11 +00:00
|
|
|
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;
|
2021-04-30 19:02:14 +00:00
|
|
|
case SDLK_r:
|
|
|
|
scene.getRenderer().setRenderColiders(
|
|
|
|
!scene.getRenderer().getRenderColiders() );
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-08 22:46:10 +00:00
|
|
|
void getMousePositionFlags( SDLPP::Scene &scene ) {
|
|
|
|
auto mouse = scene.getObjects( { EDITOR_MOUSE_ID } )[0];
|
2021-05-08 22:43:53 +00:00
|
|
|
// move mouse colider to mouse position
|
2021-05-08 22:46:10 +00:00
|
|
|
mouse->setPos( SDLPP::Mouse::getMousePositionDouble(
|
|
|
|
scene.getRenderer(), SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER ) );
|
2021-05-02 12:28:17 +00:00
|
|
|
|
2021-05-08 22:43:53 +00:00
|
|
|
MouseVisitor visitor;
|
2021-05-08 22:46:10 +00:00
|
|
|
scene.visitCollisions( *mouse, visitor );
|
2021-05-22 20:13:22 +00:00
|
|
|
global_vars.mouse.cur_flags = visitor.getFlags();
|
2021-05-31 14:08:14 +00:00
|
|
|
// + 1 because the left map arrow is on position 0
|
|
|
|
global_vars.mouse.edit_box =
|
|
|
|
visitor.getEditBoxIndexes() + SDLPP::Vec2D< int >( 1, 0 );
|
2021-05-22 20:13:22 +00:00
|
|
|
global_vars.mouse.tool_box = visitor.getToolBoxIndexes();
|
2021-05-29 17:24:47 +00:00
|
|
|
global_vars.mouse.tool_type =
|
|
|
|
static_cast< ToolType::Value >( visitor.getToolType() );
|
2021-05-08 22:43:53 +00:00
|
|
|
// if we found an edit box, move tool icon to that box
|
2021-05-08 22:46:10 +00:00
|
|
|
if ( visitor.foundEditBox() ) {
|
2021-05-22 20:13:22 +00:00
|
|
|
const auto &box = global_vars.mouse.edit_box;
|
2021-05-31 14:08:14 +00:00
|
|
|
global_vars.current_tool->setPos( box.getX() * BLOCK_SIZE,
|
2021-06-01 08:18:33 +00:00
|
|
|
1 - MAP_HEIGHT * BLOCK_SIZE +
|
2021-05-22 20:13:22 +00:00
|
|
|
box.getY() * BLOCK_SIZE );
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
2021-05-07 21:17:05 +00:00
|
|
|
}
|
|
|
|
|
2021-05-08 22:46:10 +00:00
|
|
|
void mouseUpAction( uint64_t flags, SDLPP::Scene &scene ) {
|
2021-05-22 20:13:22 +00:00
|
|
|
if ( MouseVisitor::moveMapLeft( flags ) && global_vars.map.cur_page != 0 ) {
|
|
|
|
global_vars.map.cur_page--;
|
2021-05-08 22:46:10 +00:00
|
|
|
scene.moveEverything( BLOCK_SIZE, 0 );
|
2021-05-07 08:08:41 +00:00
|
|
|
}
|
2021-05-08 22:46:10 +00:00
|
|
|
if ( MouseVisitor::moveMapRight( flags ) ) {
|
2021-05-22 20:13:22 +00:00
|
|
|
if ( global_vars.map.cur_page == global_vars.map.max_page ) {
|
2021-05-08 22:43:53 +00:00
|
|
|
// add column
|
2021-05-22 20:13:22 +00:00
|
|
|
global_vars.objects.resize( global_vars.objects.size() + 1 );
|
|
|
|
global_vars.map.max_page++;
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
2021-05-22 20:13:22 +00:00
|
|
|
global_vars.map.cur_page += 1;
|
2021-05-08 22:46:10 +00:00
|
|
|
scene.moveEverything( -BLOCK_SIZE, 0 );
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
2021-05-22 20:13:22 +00:00
|
|
|
if ( MouseVisitor::moveToolsLeft( flags ) &&
|
2021-05-28 17:51:02 +00:00
|
|
|
global_vars.tool.cur_page_tools != 0 ) {
|
|
|
|
global_vars.tool.cur_page_tools--;
|
2021-05-29 17:24:47 +00:00
|
|
|
updateToolSelection( global_vars.tool.cur_page_tools + 1,
|
|
|
|
ToolType::BLOCK );
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
2021-05-08 22:46:10 +00:00
|
|
|
if ( MouseVisitor::moveToolsRight( flags ) &&
|
2021-05-28 17:51:02 +00:00
|
|
|
global_vars.tool.cur_page_tools != global_vars.tool.max_page_tools ) {
|
|
|
|
global_vars.tool.cur_page_tools++;
|
2021-05-29 17:24:47 +00:00
|
|
|
updateToolSelection( global_vars.tool.cur_page_tools - 1,
|
|
|
|
ToolType::BLOCK );
|
2021-05-28 17:51:02 +00:00
|
|
|
}
|
|
|
|
if ( MouseVisitor::moveModsLeft( flags ) &&
|
|
|
|
global_vars.tool.cur_page_mods != 0 ) {
|
|
|
|
global_vars.tool.cur_page_mods--;
|
2021-05-29 17:24:47 +00:00
|
|
|
updateToolSelection( global_vars.tool.cur_page_mods + 1,
|
|
|
|
ToolType::MOD );
|
2021-05-28 17:51:02 +00:00
|
|
|
}
|
|
|
|
if ( MouseVisitor::moveModsRight( flags ) &&
|
|
|
|
global_vars.tool.cur_page_mods != global_vars.tool.max_page_mods ) {
|
|
|
|
global_vars.tool.cur_page_mods++;
|
2021-05-29 17:24:47 +00:00
|
|
|
updateToolSelection( global_vars.tool.cur_page_mods - 1,
|
|
|
|
ToolType::MOD );
|
2021-05-28 17:51:02 +00:00
|
|
|
}
|
|
|
|
if ( MouseVisitor::moveCharactersLeft( flags ) &&
|
|
|
|
global_vars.tool.cur_page_characters != 0 ) {
|
|
|
|
global_vars.tool.cur_page_characters--;
|
2021-05-29 17:24:47 +00:00
|
|
|
updateToolSelection( global_vars.tool.cur_page_characters + 1,
|
|
|
|
ToolType::CHARACTER );
|
2021-05-28 17:51:02 +00:00
|
|
|
}
|
|
|
|
if ( MouseVisitor::moveCharactersRight( flags ) &&
|
2021-05-29 17:24:47 +00:00
|
|
|
global_vars.tool.cur_page_characters !=
|
|
|
|
global_vars.tool.max_page_characters ) {
|
2021-05-28 17:51:02 +00:00
|
|
|
global_vars.tool.cur_page_characters++;
|
2021-05-29 17:24:47 +00:00
|
|
|
updateToolSelection( global_vars.tool.cur_page_characters - 1,
|
|
|
|
ToolType::CHARACTER );
|
2021-05-07 08:08:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-31 14:10:19 +00:00
|
|
|
SDLPP::Vec2D< int > getSelectedObjectIndexes() {
|
2021-05-31 14:08:14 +00:00
|
|
|
// -1 because we're indexing edit boxes from 1 (due to left arrow on map)
|
2021-05-22 20:13:22 +00:00
|
|
|
return global_vars.mouse.edit_box +
|
2021-05-31 14:08:14 +00:00
|
|
|
SDLPP::Vec2D< int >( global_vars.map.cur_page - 1, 0 );
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
|
|
|
|
2021-06-07 21:48:28 +00:00
|
|
|
MapObject &getSelectedObject() {
|
2021-05-31 14:10:19 +00:00
|
|
|
auto pos = getSelectedObjectIndexes();
|
2021-05-22 20:13:22 +00:00
|
|
|
return global_vars.objects[pos.getX()][pos.getY()];
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
|
|
|
|
2021-05-08 22:46:10 +00:00
|
|
|
void placeTool( SDLPP::Scene &scene ) {
|
2021-05-22 20:13:22 +00:00
|
|
|
std::lock_guard< std::mutex > lock( destruction_mutex );
|
2021-05-08 22:43:53 +00:00
|
|
|
|
|
|
|
ToolVisitor visitor;
|
2021-05-31 12:04:28 +00:00
|
|
|
visitor.setSourceType( global_vars.current_world_type );
|
2021-08-07 10:13:23 +00:00
|
|
|
visitor.setSourceData( global_vars.current_tool->getData() );
|
2021-05-22 20:13:22 +00:00
|
|
|
auto tool_type = getBlockRole( global_vars.current_tool->getId() );
|
2021-05-08 22:46:10 +00:00
|
|
|
switch ( tool_type ) {
|
|
|
|
case BlockRole::TERRAIN:
|
|
|
|
visitor.setVisitorType( VisitorType::Terrain );
|
|
|
|
break;
|
2021-08-08 19:22:00 +00:00
|
|
|
case BlockRole::CHARACTER:
|
|
|
|
case BlockRole::MARIO:
|
|
|
|
visitor.setVisitorType( VisitorType::Character );
|
|
|
|
break;
|
2021-05-08 22:46:10 +00:00
|
|
|
default:
|
|
|
|
visitor.setVisitorType( VisitorType::Modifier );
|
|
|
|
break;
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
|
|
|
|
2021-05-22 20:13:22 +00:00
|
|
|
scene.visitCollisions( *global_vars.current_tool, visitor );
|
2021-06-07 21:48:28 +00:00
|
|
|
auto &obj = getSelectedObject();
|
2021-05-08 22:46:10 +00:00
|
|
|
if ( visitor.removeBlock() && !visitor.addBlock() ) {
|
|
|
|
switch ( visitor.getVisitorType() ) {
|
|
|
|
case VisitorType::Terrain:
|
2021-06-07 21:48:28 +00:00
|
|
|
obj.unsetTerrain();
|
2021-05-08 22:46:10 +00:00
|
|
|
break;
|
2021-08-08 19:22:00 +00:00
|
|
|
case VisitorType::Character:
|
|
|
|
obj.unsetCharacter();
|
|
|
|
break;
|
2021-05-08 22:46:10 +00:00
|
|
|
case VisitorType::Modifier:
|
2021-06-07 21:48:28 +00:00
|
|
|
obj.unsetModifier();
|
2021-05-08 22:46:10 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
2021-05-08 22:46:10 +00:00
|
|
|
} else if ( visitor.addBlock() ) {
|
2021-05-22 20:13:22 +00:00
|
|
|
auto renderer = scene.getRendererShared();
|
2021-08-07 10:13:23 +00:00
|
|
|
uint64_t z_index = 1;
|
2021-07-22 22:08:05 +00:00
|
|
|
std::shared_ptr< MarioBlock > new_obj = nullptr;
|
2021-05-08 22:46:10 +00:00
|
|
|
switch ( visitor.getVisitorType() ) {
|
|
|
|
case VisitorType::Terrain:
|
2021-06-07 21:48:28 +00:00
|
|
|
obj.setTerrain( global_vars.current_tool->getId(),
|
|
|
|
global_vars.current_world_type );
|
|
|
|
new_obj = createTerrainBlock(
|
2021-07-24 17:59:25 +00:00
|
|
|
obj.getTerrainId(), obj.getTerrainType(), renderer,
|
2021-06-07 21:48:28 +00:00
|
|
|
global_vars.mouse.edit_box.getX(),
|
|
|
|
global_vars.mouse.edit_box.getY(), false, true );
|
2021-05-08 22:46:10 +00:00
|
|
|
new_obj->getCollisions()[0]->setId( EDITOR_TERRAIN_ID );
|
|
|
|
break;
|
2021-08-08 19:22:00 +00:00
|
|
|
case VisitorType::Character:
|
2021-05-29 17:24:47 +00:00
|
|
|
if ( tool_type == BlockRole::MARIO ) {
|
2021-07-24 17:59:25 +00:00
|
|
|
obj.setCharacter( MARIO_ID, global_vars.current_world_type );
|
|
|
|
new_obj =
|
|
|
|
createMario( global_vars.current_world_type, renderer,
|
|
|
|
global_vars.mouse.edit_box.getX(),
|
|
|
|
global_vars.mouse.edit_box.getY(), true );
|
2021-05-25 22:46:19 +00:00
|
|
|
// remove mario if exists
|
|
|
|
removeMario();
|
|
|
|
global_vars.mario = new_obj;
|
2021-05-31 15:28:26 +00:00
|
|
|
global_vars.mario_pos = getSelectedObjectIndexes();
|
2021-05-25 22:46:19 +00:00
|
|
|
new_obj->getCollisions()[0]->setId( EDITOR_CHARACTER_ID );
|
|
|
|
z_index = scene.getObjects().size() - 1;
|
|
|
|
} else {
|
2021-08-08 19:22:00 +00:00
|
|
|
obj.setCharacter(global_vars.current_tool->getId(), global_vars.current_world_type);
|
|
|
|
new_obj = createTerrainBlock(obj.getCharacterId(), obj.getCharacterType(), renderer, global_vars.mouse.edit_box.getX(), global_vars.mouse.edit_box.getY(), false, true);
|
|
|
|
new_obj->getCollisions()[0]->setId(EDITOR_CHARACTER_ID);
|
2021-05-29 17:24:47 +00:00
|
|
|
dynamic_cast< MarioBlock * >( new_obj.get() )
|
|
|
|
->setTerrain( false );
|
2021-05-25 22:46:19 +00:00
|
|
|
z_index = scene.getObjects().size() - 1;
|
|
|
|
}
|
2021-05-08 22:46:10 +00:00
|
|
|
break;
|
2021-08-08 19:22:00 +00:00
|
|
|
case VisitorType::Modifier:
|
|
|
|
obj.setModifier( global_vars.current_tool->getId(),
|
|
|
|
global_vars.current_tool->getData() );
|
|
|
|
new_obj = createTerrainBlock(
|
|
|
|
obj.getModifierId(), LandType::OVERWORLD, renderer,
|
|
|
|
global_vars.mouse.edit_box.getX(),
|
|
|
|
global_vars.mouse.edit_box.getY(), false, true );
|
|
|
|
new_obj->setTextureKeepSRC(
|
|
|
|
global_vars.translucent_mod_texture );
|
|
|
|
new_obj->setData( global_vars.current_tool->getData() );
|
|
|
|
new_obj->getCollisions()[0]->setId( EDITOR_TERRAIN_ID );
|
|
|
|
// TODO createModifierBlock
|
|
|
|
dynamic_cast< MarioBlock * >( new_obj.get() )
|
|
|
|
->setTerrain( false );
|
|
|
|
z_index = scene.getObjects().size() - 1;
|
|
|
|
break;
|
2021-05-08 22:46:10 +00:00
|
|
|
default:
|
|
|
|
break;
|
2021-05-08 22:43:53 +00:00
|
|
|
}
|
2021-05-08 22:46:10 +00:00
|
|
|
scene.addObject( new_obj );
|
|
|
|
scene.setZIndex( new_obj, z_index );
|
2021-04-30 19:02:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void pollEvents( SDLPP::Scene &scene ) {
|
|
|
|
SDL_Event event;
|
|
|
|
while ( SDLPP::getSDLEvent( event ) ) {
|
|
|
|
switch ( event.type ) {
|
|
|
|
case SDL_QUIT:
|
2021-05-22 20:13:22 +00:00
|
|
|
setFlag( QUIT_FLAG );
|
2021-04-30 19:02:14 +00:00
|
|
|
break;
|
|
|
|
case SDL_KEYUP:
|
2021-05-08 22:43:53 +00:00
|
|
|
handleKeyUp( event.key.keysym.sym, scene );
|
2021-04-30 19:02:14 +00:00
|
|
|
break;
|
|
|
|
case SDL_WINDOWEVENT:
|
|
|
|
if ( event.window.event == SDL_WINDOWEVENT_RESIZED ) {
|
2021-05-22 20:13:22 +00:00
|
|
|
setFlag( UPDATE_FLAG );
|
2021-05-01 19:55:43 +00:00
|
|
|
}
|
|
|
|
break;
|
2021-05-08 22:43:53 +00:00
|
|
|
case SDL_MOUSEMOTION:
|
2021-05-08 22:46:10 +00:00
|
|
|
getMousePositionFlags( scene );
|
2021-05-01 19:55:43 +00:00
|
|
|
break;
|
|
|
|
case SDL_MOUSEBUTTONUP:
|
2021-05-22 20:13:22 +00:00
|
|
|
if ( global_vars.mouse.cur_flags == global_vars.mouse.prev_flags ) {
|
|
|
|
mouseUpAction( global_vars.mouse.cur_flags, scene );
|
2021-05-01 19:55:43 +00:00
|
|
|
}
|
2021-05-31 14:08:14 +00:00
|
|
|
if ( global_vars.mouse.edit_box.getX() != 0 ) {
|
2021-05-08 22:46:10 +00:00
|
|
|
placeTool( scene );
|
2021-04-30 19:02:14 +00:00
|
|
|
}
|
2021-05-22 20:13:22 +00:00
|
|
|
if ( global_vars.mouse.tool_box.getX() != -1 ) {
|
|
|
|
auto &tool_box = global_vars.mouse.tool_box;
|
2021-05-28 17:51:02 +00:00
|
|
|
int multiplier = 0;
|
|
|
|
size_t max_index = 0;
|
|
|
|
size_t cur_page = 0;
|
2021-05-29 17:24:47 +00:00
|
|
|
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;
|
2021-05-31 12:03:11 +00:00
|
|
|
break;
|
|
|
|
case ToolType::WORLD:
|
|
|
|
multiplier = 2 * OVERWORLD_WIDTH;
|
2021-05-29 17:24:47 +00:00
|
|
|
default:
|
|
|
|
break;
|
2021-05-28 17:51:02 +00:00
|
|
|
}
|
2021-05-29 17:24:47 +00:00
|
|
|
size_t index =
|
|
|
|
tool_box.getY() * ( multiplier / 2 ) + tool_box.getX();
|
2021-05-31 12:04:28 +00:00
|
|
|
if ( global_vars.mouse.tool_type == ToolType::WORLD ) {
|
2021-05-31 12:03:11 +00:00
|
|
|
global_vars.current_world_type = possibleLands[index];
|
|
|
|
updateWorld();
|
|
|
|
} else if ( index < max_index ) {
|
2021-06-07 21:48:28 +00:00
|
|
|
updateToolIndex( cur_page * multiplier + index,
|
|
|
|
global_vars.mouse.tool_type );
|
2021-05-07 07:43:57 +00:00
|
|
|
}
|
|
|
|
}
|
2021-05-01 19:55:43 +00:00
|
|
|
break;
|
|
|
|
case SDL_MOUSEBUTTONDOWN:
|
2021-05-08 22:43:53 +00:00
|
|
|
// store current mouse flags in previous mouse flags
|
2021-05-22 20:13:22 +00:00
|
|
|
global_vars.mouse.prev_flags = global_vars.mouse.cur_flags;
|
2021-05-01 19:55:43 +00:00
|
|
|
break;
|
2021-07-22 22:08:05 +00:00
|
|
|
case SDL_MOUSEWHEEL:
|
2021-07-24 17:59:25 +00:00
|
|
|
if ( event.wheel.y > 0 ) {
|
2021-07-22 22:08:05 +00:00
|
|
|
global_vars.current_tool->onScrollUp();
|
2021-07-24 17:59:25 +00:00
|
|
|
} else if ( event.wheel.y < 0 ) {
|
2021-07-22 22:08:05 +00:00
|
|
|
global_vars.current_tool->onScrollDown();
|
|
|
|
}
|
|
|
|
break;
|
2021-04-30 19:02:14 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void doInput( std::shared_ptr< SDLPP::Scene > scene ) {
|
|
|
|
FPSmanager gFPS;
|
|
|
|
SDL_initFramerate( &gFPS );
|
|
|
|
SDL_setFramerate( &gFPS, 200 );
|
|
|
|
while ( true ) {
|
|
|
|
SDL_framerateDelay( &gFPS );
|
|
|
|
pollEvents( *scene );
|
|
|
|
scene->updateScene();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-29 17:24:47 +00:00
|
|
|
void createGrid( double start_x, double start_y, int count_x, int count_y,
|
|
|
|
std::shared_ptr< SDLPP::Scene > &scene ) {
|
2021-05-29 09:38:45 +00:00
|
|
|
auto renderer = scene->getRendererShared();
|
|
|
|
auto width = count_x * BLOCK_SIZE;
|
|
|
|
auto height = count_y * BLOCK_SIZE;
|
|
|
|
for ( int i = 0; i < count_x + 1; i++ ) {
|
|
|
|
auto line_vertical = std::make_shared< SDLPP::LineRenderer >(
|
2021-05-29 17:24:47 +00:00
|
|
|
start_x + i * BLOCK_SIZE, start_y, start_x + i * BLOCK_SIZE,
|
|
|
|
start_y + height, renderer, "#282828" );
|
2021-05-29 09:38:45 +00:00
|
|
|
line_vertical->setPermanent();
|
|
|
|
line_vertical->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
|
|
|
scene->addObject( line_vertical );
|
|
|
|
}
|
2021-05-29 17:24:47 +00:00
|
|
|
for ( int i = 0; i < count_y + 1; i++ ) {
|
2021-05-29 09:38:45 +00:00
|
|
|
auto line_horizontal = std::make_shared< SDLPP::LineRenderer >(
|
2021-05-29 17:24:47 +00:00
|
|
|
start_x, start_y + i * BLOCK_SIZE, start_x + width,
|
|
|
|
start_y + i * BLOCK_SIZE, renderer, "#282828" );
|
2021-05-29 09:38:45 +00:00
|
|
|
line_horizontal->setPermanent();
|
2021-05-29 17:24:47 +00:00
|
|
|
line_horizontal->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
2021-05-29 09:38:45 +00:00
|
|
|
scene->addObject( line_horizontal );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-29 17:24:47 +00:00
|
|
|
std::pair< std::shared_ptr< SDLPP::TextRenderer >,
|
|
|
|
std::shared_ptr< SDLPP::TextRenderer > >
|
|
|
|
createArrowControls(
|
|
|
|
double left_x, double right_x, double start_y, double height,
|
|
|
|
uint64_t left_id, uint64_t right_id, std::shared_ptr< SDLPP::Scene > &scene,
|
|
|
|
std::shared_ptr< SDLPP::FontConfiguration > &font_config ) {
|
2021-05-29 09:38:45 +00:00
|
|
|
auto renderer = scene->getRendererShared();
|
|
|
|
// white rectangles
|
|
|
|
auto rectangle1 = std::make_shared< SDLPP::RectangleRender >(
|
|
|
|
left_x, start_y, BLOCK_SIZE, height, renderer, "#FFFFFF88", true );
|
|
|
|
rectangle1->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
|
|
|
rectangle1->setId( left_id );
|
|
|
|
rectangle1->setPermanent();
|
|
|
|
rectangle1->addCollision( SDLPP::RectColider( 0, 0, 1, 1 ) );
|
|
|
|
scene->addObject( rectangle1 );
|
|
|
|
// white rectangles
|
|
|
|
auto rectangle2 = std::make_shared< SDLPP::RectangleRender >(
|
|
|
|
right_x, start_y, BLOCK_SIZE, height, renderer, "#FFFFFF88", true );
|
|
|
|
rectangle2->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
|
|
|
rectangle2->setId( right_id );
|
|
|
|
rectangle2->setPermanent();
|
|
|
|
rectangle2->addCollision( SDLPP::RectColider( 0, 0, 1, 1 ) );
|
|
|
|
scene->addObject( rectangle2 );
|
|
|
|
|
|
|
|
auto left = std::make_shared< SDLPP::TextRenderer >(
|
2021-05-29 17:24:47 +00:00
|
|
|
left_x, start_y + height / 2.0 - 0.5 * BLOCK_SIZE, BLOCK_SIZE,
|
|
|
|
BLOCK_SIZE, renderer, "<", font_config );
|
2021-05-29 09:38:45 +00:00
|
|
|
left->setId( 0 );
|
|
|
|
left->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
|
|
|
left->setPermanent();
|
|
|
|
scene->addObject( left );
|
|
|
|
auto right = std::make_shared< SDLPP::TextRenderer >(
|
|
|
|
right_x, start_y + height / 2.0 - 0.5 * BLOCK_SIZE, BLOCK_SIZE,
|
|
|
|
BLOCK_SIZE, renderer, ">", font_config );
|
|
|
|
right->setId( 0 );
|
|
|
|
right->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
|
|
|
right->setPermanent();
|
|
|
|
scene->addObject( right );
|
2021-05-29 17:24:47 +00:00
|
|
|
return { left, right };
|
2021-05-29 09:38:45 +00:00
|
|
|
}
|
|
|
|
|
2021-05-29 17:24:47 +00:00
|
|
|
void populateToolGrid(
|
|
|
|
int count_x, int count_y, float start_x, float start_y,
|
|
|
|
ToolType::Value type, const std::vector< uint64_t > &blocks,
|
2021-07-24 17:59:25 +00:00
|
|
|
std::vector< std::shared_ptr< MarioBlock > > &tool_store,
|
2021-05-29 17:24:47 +00:00
|
|
|
std::vector< std::shared_ptr< SDLPP::RenderObject > > &tool_box_store,
|
2021-05-31 12:04:28 +00:00
|
|
|
std::shared_ptr< SDLPP::Scene > &scene, const std::string &title,
|
|
|
|
const std::shared_ptr< SDLPP::FontConfiguration > &font_config ) {
|
2021-05-29 11:21:01 +00:00
|
|
|
auto renderer = scene->getRendererShared();
|
2021-05-29 17:24:47 +00:00
|
|
|
for ( int j = 0; j < count_y; j++ ) {
|
2021-05-29 17:17:45 +00:00
|
|
|
for ( int i = 0; i < count_x; i++ ) {
|
2021-05-29 17:24:47 +00:00
|
|
|
auto tool_box = std::make_shared< ToolBox >( i, j, start_x, start_y,
|
|
|
|
renderer, false );
|
2021-05-29 11:21:01 +00:00
|
|
|
scene->addObject( tool_box );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int tool_index = 0;
|
|
|
|
for ( auto &block : blocks ) {
|
2021-05-29 17:24:47 +00:00
|
|
|
switch ( type ) {
|
|
|
|
case ToolType::CHARACTER:
|
2021-06-24 18:53:58 +00:00
|
|
|
if ( block == MARIO_ID ) {
|
2021-05-31 12:04:28 +00:00
|
|
|
tool_store.push_back( createMario(
|
2021-07-22 22:08:05 +00:00
|
|
|
global_vars.current_world_type, renderer, 0, 0, true ) );
|
2021-06-24 18:53:58 +00:00
|
|
|
break;
|
|
|
|
}
|
2021-07-24 17:59:25 +00:00
|
|
|
// fall through
|
|
|
|
case ToolType::MOD:
|
|
|
|
tool_store.push_back(
|
|
|
|
createTerrainBlock( block, global_vars.current_world_type,
|
|
|
|
renderer, false, true ) );
|
|
|
|
break;
|
|
|
|
case ToolType::BLOCK:
|
|
|
|
tool_store.push_back(
|
|
|
|
createTerrainBlock( block, global_vars.current_world_type,
|
|
|
|
renderer, false, true ) );
|
|
|
|
break;
|
2021-05-31 12:04:28 +00:00
|
|
|
default:
|
|
|
|
break;
|
2021-05-29 11:21:01 +00:00
|
|
|
}
|
|
|
|
tool_store.back()->setHidden( true );
|
|
|
|
tool_store.back()->setPermanent();
|
2021-08-08 19:22:00 +00:00
|
|
|
tool_store.back()->pauseAnimation();
|
2021-05-29 11:21:01 +00:00
|
|
|
auto x = tool_index % count_x;
|
|
|
|
auto y = tool_index / count_x;
|
2021-05-29 17:24:47 +00:00
|
|
|
tool_store.back()->setPos( start_x + x * BLOCK_SIZE,
|
|
|
|
start_y + y * BLOCK_SIZE );
|
2021-05-29 11:21:01 +00:00
|
|
|
scene->addObject( tool_store.back() );
|
2021-05-29 17:24:47 +00:00
|
|
|
tool_index = ( tool_index + 1 ) % ( 2 * count_x );
|
2021-05-29 11:21:01 +00:00
|
|
|
}
|
2021-05-29 17:24:47 +00:00
|
|
|
for ( int j = 0; j < count_y; j++ ) {
|
2021-05-29 17:17:45 +00:00
|
|
|
for ( int i = 0; i < count_x; i++ ) {
|
2021-05-29 17:24:47 +00:00
|
|
|
auto tool_box =
|
|
|
|
std::make_shared< ToolBox >( i, j, start_x, start_y, renderer );
|
|
|
|
tool_box->setType( type );
|
2021-05-29 17:17:45 +00:00
|
|
|
scene->addObject( tool_box );
|
2021-05-29 17:24:47 +00:00
|
|
|
tool_box->setColor( "#00000000" );
|
|
|
|
tool_box_store.push_back( tool_box );
|
2021-05-29 17:17:45 +00:00
|
|
|
}
|
|
|
|
}
|
2021-05-31 12:04:28 +00:00
|
|
|
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 );
|
2021-05-31 12:03:11 +00:00
|
|
|
tool_text->setPermanent();
|
2021-05-31 12:04:28 +00:00
|
|
|
scene->addObject( tool_text );
|
2021-05-31 12:03:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void populateWorldType(
|
|
|
|
int count_x, int count_y, float start_x, float start_y,
|
2021-05-31 12:04:28 +00:00
|
|
|
std::shared_ptr< SDLPP::Scene > &scene, const std::string &title,
|
|
|
|
const std::shared_ptr< SDLPP::FontConfiguration > &font_config ) {
|
2021-05-31 12:03:11 +00:00
|
|
|
auto renderer = scene->getRendererShared();
|
|
|
|
for ( int j = 0; j < count_y; j++ ) {
|
|
|
|
for ( int i = 0; i < count_x; i++ ) {
|
2021-05-31 12:04:28 +00:00
|
|
|
auto tool_box =
|
|
|
|
std::make_shared< ToolBox >( i, j, start_x, start_y, renderer );
|
|
|
|
tool_box->setType( ToolType::WORLD );
|
2021-05-31 12:03:11 +00:00
|
|
|
scene->addObject( tool_box );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int tool_index = 0;
|
|
|
|
for ( auto &type : possibleLands ) {
|
2021-05-31 16:54:59 +00:00
|
|
|
auto land = createTerrainBlock( BRICK_ID, type, renderer, false, true );
|
2021-05-31 12:03:11 +00:00
|
|
|
auto x = tool_index % count_x;
|
|
|
|
auto y = tool_index / count_x;
|
2021-05-31 12:04:28 +00:00
|
|
|
land->setId( EDITOR_WORLD_CHANGE_ID );
|
2021-05-31 12:03:11 +00:00
|
|
|
land->setPermanent();
|
2021-05-31 12:04:28 +00:00
|
|
|
land->setPos( start_x + x * BLOCK_SIZE, start_y + y * BLOCK_SIZE );
|
2021-05-31 12:03:11 +00:00
|
|
|
scene->addObject( land );
|
|
|
|
tool_index = ( tool_index + 1 ) % ( 2 * count_x );
|
|
|
|
}
|
2021-05-31 12:04:28 +00:00
|
|
|
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 );
|
2021-05-31 12:03:11 +00:00
|
|
|
tool_text->setPermanent();
|
2021-05-31 12:04:28 +00:00
|
|
|
scene->addObject( tool_text );
|
2021-05-29 11:21:01 +00:00
|
|
|
}
|
|
|
|
|
2021-05-29 17:24:47 +00:00
|
|
|
void checkArrowsEnabled( uint64_t cur_page, uint64_t max_page,
|
|
|
|
uint64_t left_flag, uint64_t right_flag,
|
|
|
|
std::shared_ptr< SDLPP::TextRenderer > &left_arrow,
|
|
|
|
std::shared_ptr< SDLPP::TextRenderer > &right_arrow,
|
|
|
|
std::shared_ptr< SDLPP::Font > &font,
|
|
|
|
bool map = false ) {
|
|
|
|
if ( cur_page == 0 && getFlag( left_flag ) ) {
|
2021-05-29 11:21:01 +00:00
|
|
|
setFlag( UPDATE_FLAG );
|
|
|
|
unsetFlag( left_flag );
|
|
|
|
left_arrow->setTextColor( font, "#CCCCCC", "#CCCCCC", 0.05 );
|
2021-05-29 17:24:47 +00:00
|
|
|
} else if ( cur_page != 0 && !getFlag( left_flag ) ) {
|
2021-05-29 11:21:01 +00:00
|
|
|
setFlag( UPDATE_FLAG );
|
|
|
|
setFlag( left_flag );
|
|
|
|
left_arrow->setTextColor( font, "#000000", "#282828", 0.05 );
|
|
|
|
}
|
2021-05-29 17:24:47 +00:00
|
|
|
if ( cur_page == max_page && getFlag( right_flag ) ) {
|
2021-05-29 11:21:01 +00:00
|
|
|
setFlag( UPDATE_FLAG );
|
|
|
|
unsetFlag( right_flag );
|
2021-05-29 17:24:47 +00:00
|
|
|
if ( map ) {
|
2021-05-29 11:21:01 +00:00
|
|
|
right_arrow->setTextColor( font, "#00FF00", "#000000", 0.1 );
|
|
|
|
right_arrow->changeText( "+" );
|
|
|
|
} else {
|
|
|
|
right_arrow->setTextColor( font, "#CCCCCC", "#CCCCCC", 0.05 );
|
|
|
|
}
|
2021-05-29 17:24:47 +00:00
|
|
|
} else if ( cur_page != max_page && !getFlag( right_flag ) ) {
|
2021-05-29 11:21:01 +00:00
|
|
|
setFlag( UPDATE_FLAG );
|
|
|
|
setFlag( right_flag );
|
|
|
|
right_arrow->setTextColor( font, "#000000", "#282828", 0.05 );
|
2021-05-29 17:24:47 +00:00
|
|
|
if ( map ) {
|
2021-05-29 11:21:01 +00:00
|
|
|
right_arrow->changeText( ">" );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-30 19:02:14 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
|
|
|
|
PWSTR szCmdLine, int nCmdShow ) {
|
|
|
|
#else
|
|
|
|
int main() {
|
|
|
|
#endif
|
|
|
|
SDLPP::init();
|
2021-05-07 08:08:41 +00:00
|
|
|
SDLPP::Window w( "Mario editor!" );
|
2021-04-30 19:02:14 +00:00
|
|
|
w.setResizable( true );
|
2021-06-01 08:18:33 +00:00
|
|
|
BLOCK_SIZE = 1.0 / 26;
|
2021-04-30 19:02:14 +00:00
|
|
|
|
2021-07-22 22:08:05 +00:00
|
|
|
auto font = std::make_shared< SDLPP::Font >( "testfont.ttf", 36 );
|
|
|
|
auto font_config = std::make_shared< SDLPP::FontConfiguration >(
|
|
|
|
font, "#000000", "#282828", 0.05 );
|
|
|
|
g_text_config = std::make_shared< SDLPP::FontConfiguration >(
|
|
|
|
font, "#FFFFFF", "#000000", 0.15 );
|
|
|
|
|
2021-05-22 20:13:22 +00:00
|
|
|
auto renderer = std::make_shared< SDLPP::Renderer >( w );
|
|
|
|
renderer->setBlendMode( SDL_BLENDMODE_BLEND );
|
2021-04-30 19:02:14 +00:00
|
|
|
|
|
|
|
// prepare global vars
|
|
|
|
g_terrain_texture = std::make_shared< SDLPP::Texture >(
|
2021-05-22 20:13:22 +00:00
|
|
|
renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY );
|
2021-05-01 19:55:43 +00:00
|
|
|
g_mario_texture = std::make_shared< SDLPP::Texture >(
|
2021-05-22 20:13:22 +00:00
|
|
|
renderer, "sprites/mario.png", MARIO_OVERWORLD_COLORKEY );
|
2021-07-24 17:59:25 +00:00
|
|
|
g_mod_texture =
|
|
|
|
std::make_shared< SDLPP::Texture >( renderer, "sprites/mods.png" );
|
2021-08-08 19:22:00 +00:00
|
|
|
g_enemies_texture = std::make_shared< SDLPP::Texture >(
|
|
|
|
renderer, "sprites/enemies.png", MARIO_OVERWORLD_COLORKEY );
|
2021-05-29 17:24:47 +00:00
|
|
|
g_translucent_terrain_texture = std::make_shared< SDLPP::Texture >(
|
|
|
|
renderer, "sprites/terrain.png", MARIO_OVERWORLD_COLORKEY );
|
2021-05-25 22:46:19 +00:00
|
|
|
g_translucent_terrain_texture->setAlpha( 100 );
|
2021-07-24 17:59:25 +00:00
|
|
|
g_translucent_mod_texture =
|
|
|
|
std::make_shared< SDLPP::Texture >( renderer, "sprites/mods.png" );
|
2021-06-24 18:53:58 +00:00
|
|
|
g_translucent_mod_texture->setAlpha( 100 );
|
2021-08-08 19:22:00 +00:00
|
|
|
g_translucent_enemies_texture = std::make_shared< SDLPP::Texture >(
|
|
|
|
renderer, "sprites/enemies.png", MARIO_OVERWORLD_COLORKEY );
|
|
|
|
g_translucent_enemies_texture->setAlpha( 100 );
|
2021-04-30 19:02:14 +00:00
|
|
|
|
2021-05-22 20:13:22 +00:00
|
|
|
auto scene = std::make_shared< SDLPP::Scene >( renderer );
|
2021-04-30 19:02:14 +00:00
|
|
|
auto bg = std::make_shared< SDLPP::RectangleRender >(
|
2021-05-22 20:13:22 +00:00
|
|
|
0, 0, 10, 10, renderer, MARIO_OVERWORLD_COLORKEY, true );
|
2021-05-01 19:55:43 +00:00
|
|
|
bg->setPermanent();
|
2021-04-30 19:02:14 +00:00
|
|
|
bg->setId( 1 );
|
|
|
|
scene->addObject( bg );
|
|
|
|
|
2021-05-31 12:03:11 +00:00
|
|
|
global_vars.current_world_type = LandType::OVERWORLD;
|
|
|
|
|
2021-05-29 09:38:45 +00:00
|
|
|
// TODO file name
|
2021-07-24 17:59:25 +00:00
|
|
|
loadMap( scene, global_vars.mario, "test_binary.bin", global_vars.objects,
|
|
|
|
true, MAP_WIDTH );
|
2021-04-30 21:12:53 +00:00
|
|
|
|
2021-05-29 11:21:01 +00:00
|
|
|
// create grids and arrow controls
|
|
|
|
// map
|
2021-05-29 17:24:47 +00:00
|
|
|
auto arrows = createArrowControls(
|
2021-06-07 21:48:28 +00:00
|
|
|
0, ( MAP_WIDTH + 1 ) * BLOCK_SIZE, 1 - MAP_HEIGHT * BLOCK_SIZE,
|
|
|
|
MAP_HEIGHT * BLOCK_SIZE, EDITOR_LEFT_MAP_ID, EDITOR_RIGHT_MAP_ID, scene,
|
|
|
|
font_config );
|
2021-05-29 11:21:01 +00:00
|
|
|
auto left_map_arrow = arrows.first;
|
|
|
|
auto right_map_arrow = arrows.second;
|
2021-05-29 17:24:47 +00:00
|
|
|
createGrid( BLOCK_SIZE, 1 - MAP_HEIGHT * BLOCK_SIZE, MAP_WIDTH, MAP_HEIGHT,
|
|
|
|
scene );
|
2021-05-29 11:21:01 +00:00
|
|
|
// edit blocks on map
|
2021-05-09 18:45:52 +00:00
|
|
|
for ( int i = 0; i < MAP_WIDTH; i++ ) {
|
|
|
|
for ( int j = 0; j < MAP_HEIGHT; j++ ) {
|
2021-05-22 20:13:22 +00:00
|
|
|
scene->addObject( std::make_shared< EditBox >(
|
2021-06-07 21:48:28 +00:00
|
|
|
i, j, BLOCK_SIZE, 1 - MAP_HEIGHT * BLOCK_SIZE, MAP_WIDTH,
|
|
|
|
MAP_HEIGHT, renderer ) );
|
2021-05-01 19:55:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-29 11:21:01 +00:00
|
|
|
// tools
|
2021-05-29 17:24:47 +00:00
|
|
|
populateToolGrid( TOOLS_WIDTH, 2, ( MAP_WIDTH - TOOLS_WIDTH ) * BLOCK_SIZE,
|
2021-06-07 21:48:28 +00:00
|
|
|
1 - ( MAP_HEIGHT + 3 ) * BLOCK_SIZE, ToolType::BLOCK,
|
|
|
|
possibleBlocks, global_vars.tools, global_vars.tool_boxes,
|
|
|
|
scene, "TERRAIN", font_config );
|
|
|
|
arrows = createArrowControls(
|
|
|
|
( MAP_WIDTH - TOOLS_WIDTH - 1 ) * BLOCK_SIZE, MAP_WIDTH * BLOCK_SIZE,
|
|
|
|
1 - ( MAP_HEIGHT + 3 ) * BLOCK_SIZE, 2 * BLOCK_SIZE,
|
|
|
|
EDITOR_LEFT_TOOL_ID, EDITOR_RIGHT_TOOL_ID, scene, font_config );
|
2021-05-29 11:21:01 +00:00
|
|
|
auto left_tool_arrow = arrows.first;
|
|
|
|
auto right_tool_arrow = arrows.second;
|
2021-06-07 21:48:28 +00:00
|
|
|
createGrid( ( MAP_WIDTH - TOOLS_WIDTH ) * BLOCK_SIZE,
|
|
|
|
1 - ( MAP_HEIGHT + 3 ) * BLOCK_SIZE, TOOLS_WIDTH, 2, scene );
|
2021-05-29 11:21:01 +00:00
|
|
|
// mods
|
2021-06-07 21:48:28 +00:00
|
|
|
populateToolGrid( MOD_WIDTH, 2, 5 * BLOCK_SIZE,
|
|
|
|
1 - ( MAP_HEIGHT + 3 ) * BLOCK_SIZE, ToolType::MOD,
|
2021-05-29 17:24:47 +00:00
|
|
|
possibleMods, global_vars.mods, global_vars.mod_boxes,
|
2021-05-31 12:03:11 +00:00
|
|
|
scene, "MODS", font_config );
|
2021-06-07 21:48:28 +00:00
|
|
|
arrows = createArrowControls(
|
|
|
|
4 * BLOCK_SIZE, ( MOD_WIDTH + 5 ) * BLOCK_SIZE,
|
|
|
|
1 - ( MAP_HEIGHT + 3 ) * BLOCK_SIZE, 2 * BLOCK_SIZE, EDITOR_LEFT_MOD_ID,
|
|
|
|
EDITOR_RIGHT_MOD_ID, scene, font_config );
|
2021-05-29 11:21:01 +00:00
|
|
|
auto left_mod_arrow = arrows.first;
|
|
|
|
auto right_mod_arrow = arrows.second;
|
2021-06-07 21:48:28 +00:00
|
|
|
createGrid( 5 * BLOCK_SIZE, 1 - ( MAP_HEIGHT + 3 ) * BLOCK_SIZE, MOD_WIDTH,
|
|
|
|
2, scene );
|
2021-05-29 11:21:01 +00:00
|
|
|
// characters
|
2021-06-01 08:18:33 +00:00
|
|
|
populateToolGrid( CHARACTER_WIDTH, 2, ( MOD_WIDTH + 8 ) * BLOCK_SIZE,
|
2021-06-07 21:48:28 +00:00
|
|
|
1 - ( MAP_HEIGHT + 3 ) * BLOCK_SIZE, ToolType::CHARACTER,
|
|
|
|
possibleCharacters, global_vars.characters,
|
|
|
|
global_vars.character_boxes, scene, "CHARACTERS",
|
|
|
|
font_config );
|
|
|
|
arrows =
|
|
|
|
createArrowControls( ( MOD_WIDTH + 7 ) * BLOCK_SIZE,
|
|
|
|
( MOD_WIDTH + 8 + CHARACTER_WIDTH ) * BLOCK_SIZE,
|
|
|
|
1 - ( MAP_HEIGHT + 3 ) * BLOCK_SIZE,
|
|
|
|
2 * BLOCK_SIZE, EDITOR_LEFT_CHARACTER_ID,
|
|
|
|
EDITOR_RIGHT_CHARACTER_ID, scene, font_config );
|
2021-05-29 11:21:01 +00:00
|
|
|
auto left_char_arrow = arrows.first;
|
|
|
|
auto right_char_arrow = arrows.second;
|
2021-06-07 21:48:28 +00:00
|
|
|
createGrid( ( MOD_WIDTH + 8 ) * BLOCK_SIZE,
|
|
|
|
1 - ( MAP_HEIGHT + 3 ) * BLOCK_SIZE, CHARACTER_WIDTH, 2,
|
2021-05-29 17:24:47 +00:00
|
|
|
scene );
|
2021-05-29 11:21:01 +00:00
|
|
|
|
2021-05-31 12:03:11 +00:00
|
|
|
// world type
|
2021-06-07 21:48:28 +00:00
|
|
|
populateWorldType( OVERWORLD_WIDTH, 2, BLOCK_SIZE,
|
|
|
|
1 - ( MAP_HEIGHT + 3 ) * BLOCK_SIZE, scene, "WORLD",
|
2021-05-31 12:04:28 +00:00
|
|
|
font_config );
|
2021-06-07 21:48:28 +00:00
|
|
|
createGrid( BLOCK_SIZE, 1 - ( MAP_HEIGHT + 3 ) * BLOCK_SIZE,
|
|
|
|
OVERWORLD_WIDTH, 2, scene );
|
2021-05-31 12:03:11 +00:00
|
|
|
|
2021-05-29 11:21:01 +00:00
|
|
|
global_vars.map.max_page = global_vars.objects.size() - MAP_WIDTH;
|
|
|
|
|
2021-05-29 17:24:47 +00:00
|
|
|
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 );
|
2021-05-29 11:21:01 +00:00
|
|
|
|
2021-05-08 22:46:10 +00:00
|
|
|
auto mouse = std::make_shared< SDLPP::RectangleRender >( 0.01, 0.01, 0, 0,
|
2021-05-22 20:13:22 +00:00
|
|
|
renderer );
|
2021-05-08 22:46:10 +00:00
|
|
|
mouse->setMinWidth( 1 );
|
|
|
|
mouse->setMinHeight( 1 );
|
2021-05-01 19:55:43 +00:00
|
|
|
mouse->setAlignment( SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER );
|
2021-05-02 12:14:11 +00:00
|
|
|
mouse->setId( EDITOR_MOUSE_ID );
|
2021-05-08 22:46:10 +00:00
|
|
|
mouse->setColiderColor( "#00FF00" );
|
|
|
|
mouse->addCollision( SDLPP::RectColider( { 0, 0 }, { 1, 1 } ) );
|
2021-05-01 19:55:43 +00:00
|
|
|
scene->addObject( mouse );
|
2021-05-07 08:08:41 +00:00
|
|
|
|
2021-08-08 19:22:00 +00:00
|
|
|
global_vars.translucent_terrain_texture = g_translucent_terrain_texture;
|
2021-05-22 20:13:22 +00:00
|
|
|
global_vars.translucent_mario_texture = std::make_shared< SDLPP::Texture >(
|
|
|
|
renderer, "sprites/mario.png", MARIO_OVERWORLD_COLORKEY );
|
|
|
|
global_vars.translucent_mario_texture->setAlpha( 100 );
|
2021-07-24 17:59:25 +00:00
|
|
|
global_vars.generic_tool =
|
|
|
|
createTerrainBlock( possibleBlocks[global_vars.tool.index],
|
|
|
|
global_vars.current_world_type, renderer, false );
|
|
|
|
global_vars.generic_tool->setTextureKeepSRC(
|
|
|
|
global_vars.translucent_terrain_texture );
|
2021-07-22 22:08:05 +00:00
|
|
|
global_vars.generic_tool->removeCollisions();
|
|
|
|
global_vars.generic_tool->addCollision(
|
|
|
|
SDLPP::RectColider( 0.1, 0.1, 0.8, 0.8 ) );
|
|
|
|
global_vars.current_tool = global_vars.generic_tool;
|
|
|
|
|
2021-07-24 17:59:25 +00:00
|
|
|
global_vars.coin_tool = createTerrainBlock(
|
|
|
|
COIN_MODIFIER_ID, LandType::OVERWORLD, renderer, 0, 0, false, true );
|
|
|
|
global_vars.coin_tool->setData( 1 );
|
2021-07-22 22:08:05 +00:00
|
|
|
global_vars.coin_tool->removeCollisions();
|
|
|
|
global_vars.coin_tool->addCollision(
|
2021-05-22 20:13:22 +00:00
|
|
|
SDLPP::RectColider( 0.1, 0.1, 0.8, 0.8 ) );
|
2021-06-24 18:53:58 +00:00
|
|
|
global_vars.translucent_mod_texture = g_translucent_mod_texture;
|
2021-08-08 19:22:00 +00:00
|
|
|
global_vars.translucent_enemies_texture = g_translucent_enemies_texture;
|
2021-05-22 20:13:22 +00:00
|
|
|
dynamic_cast< MarioBlock & >( *global_vars.current_tool ).setTool();
|
|
|
|
scene->addObject( global_vars.current_tool );
|
2021-07-22 22:08:05 +00:00
|
|
|
scene->addObject( global_vars.coin_tool );
|
2021-07-24 17:59:25 +00:00
|
|
|
global_vars.coin_tool->setHidden( true );
|
2021-05-22 20:13:22 +00:00
|
|
|
scene->moveZTop( global_vars.current_tool );
|
2021-07-22 22:08:05 +00:00
|
|
|
scene->moveZTop( global_vars.coin_tool );
|
2021-05-08 22:46:10 +00:00
|
|
|
|
|
|
|
scene->moveEverything( BLOCK_SIZE, 0 );
|
2021-04-30 19:02:14 +00:00
|
|
|
FPSmanager gFPS;
|
|
|
|
SDL_initFramerate( &gFPS );
|
|
|
|
SDL_setFramerate( &gFPS, 60 );
|
|
|
|
|
2021-05-28 17:51:02 +00:00
|
|
|
updateToolSelection( 0, ToolType::BLOCK );
|
|
|
|
updateToolSelection( 0, ToolType::MOD );
|
|
|
|
updateToolSelection( 0, ToolType::CHARACTER );
|
2021-05-29 17:17:45 +00:00
|
|
|
setToolColor();
|
2021-05-07 07:43:57 +00:00
|
|
|
|
2021-04-30 19:02:14 +00:00
|
|
|
auto base = SDL_GetTicks();
|
|
|
|
int frames = 0;
|
|
|
|
std::thread inputThread( doInput, scene );
|
|
|
|
inputThread.detach();
|
2021-05-22 20:13:22 +00:00
|
|
|
setFlag( UPDATE_FLAG );
|
2021-05-28 17:51:02 +00:00
|
|
|
global_vars.tool.cur_page_tools = 0;
|
|
|
|
global_vars.tool.cur_page_mods = 0;
|
|
|
|
global_vars.tool.cur_page_characters = 0;
|
2021-05-22 20:13:22 +00:00
|
|
|
// required for initial correct rendering
|
2021-05-29 11:21:01 +00:00
|
|
|
setFlag( MAP_LEFT_ENABLED_FLAG | MAP_RIGHT_ENABLED_FLAG |
|
|
|
|
TOOL_LEFT_ENABLED_FLAG | TOOL_RIGHT_ENABLED_FLAG |
|
|
|
|
MOD_LEFT_ENABLED_FLAG | MOD_RIGHT_ENABLED_FLAG |
|
|
|
|
CHARACTER_LEFT_ENABLED_FLAG | CHARACTER_RIGHT_ENABLED_FLAG );
|
|
|
|
|
2021-08-08 19:22:00 +00:00
|
|
|
SDL_PumpEvents();
|
|
|
|
scene->updateSizeAndPosition();
|
|
|
|
scene->renderScene();
|
|
|
|
renderer->presentRenderer();
|
|
|
|
setFlag(UPDATE_FLAG);
|
|
|
|
|
2021-05-22 20:13:22 +00:00
|
|
|
while ( !getFlag( QUIT_FLAG ) ) {
|
2021-04-30 19:02:14 +00:00
|
|
|
SDL_framerateDelay( &gFPS );
|
2021-08-08 19:22:00 +00:00
|
|
|
SDL_PumpEvents();
|
2021-05-22 20:13:22 +00:00
|
|
|
std::lock_guard< std::mutex > lock( destruction_mutex );
|
2021-04-30 19:02:14 +00:00
|
|
|
scene->renderScene();
|
2021-05-22 20:13:22 +00:00
|
|
|
renderer->presentRenderer();
|
2021-04-30 19:02:14 +00:00
|
|
|
frames++;
|
|
|
|
if ( SDL_GetTicks() - base >= 1000 ) {
|
|
|
|
std::cout << "FPS: " << frames << std::endl;
|
|
|
|
frames = 0;
|
|
|
|
base = SDL_GetTicks();
|
|
|
|
}
|
2021-05-29 17:24:47 +00:00
|
|
|
checkArrowsEnabled( global_vars.map.cur_page, global_vars.map.max_page,
|
|
|
|
MAP_LEFT_ENABLED_FLAG, MAP_RIGHT_ENABLED_FLAG,
|
|
|
|
left_map_arrow, right_map_arrow, font, true );
|
|
|
|
checkArrowsEnabled( global_vars.tool.cur_page_tools,
|
|
|
|
global_vars.tool.max_page_tools,
|
|
|
|
TOOL_LEFT_ENABLED_FLAG, TOOL_RIGHT_ENABLED_FLAG,
|
|
|
|
left_tool_arrow, right_tool_arrow, font );
|
|
|
|
checkArrowsEnabled( global_vars.tool.cur_page_mods,
|
|
|
|
global_vars.tool.max_page_mods,
|
|
|
|
MOD_LEFT_ENABLED_FLAG, MOD_RIGHT_ENABLED_FLAG,
|
|
|
|
left_mod_arrow, right_mod_arrow, font );
|
|
|
|
checkArrowsEnabled( global_vars.tool.cur_page_characters,
|
|
|
|
global_vars.tool.max_page_characters,
|
|
|
|
CHARACTER_LEFT_ENABLED_FLAG,
|
|
|
|
CHARACTER_RIGHT_ENABLED_FLAG, left_char_arrow,
|
|
|
|
right_char_arrow, font );
|
2021-05-22 20:13:22 +00:00
|
|
|
if ( getFlag( UPDATE_FLAG ) ) {
|
2021-05-01 19:55:43 +00:00
|
|
|
scene->updateSizeAndPosition();
|
2021-05-22 20:13:22 +00:00
|
|
|
unsetFlag( UPDATE_FLAG );
|
2021-05-01 19:55:43 +00:00
|
|
|
}
|
2021-04-30 19:02:14 +00:00
|
|
|
}
|
2021-05-22 20:13:22 +00:00
|
|
|
saveMap( "test_binary2.bin", global_vars.objects );
|
2021-04-30 19:02:14 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|