Mario: formatting
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
zvon 2022-07-21 20:17:24 +02:00
parent 6558329547
commit 58fd1a37a8
9 changed files with 373 additions and 302 deletions

View File

@ -24,55 +24,55 @@ using char_t = char;
namespace FSLib { namespace FSLib {
bool exists( const string &path ); bool exists(const string &path);
bool isDirectory( const string &path ); bool isDirectory(const string &path);
bool rename( const string &file_a, const string &file_b ); bool rename(const string &file_a, const string &file_b);
bool deleteFile( const string &file ); bool deleteFile(const string &file);
string canonical( const string &path ); string canonical(const string &path);
bool createDirectoryFull( const string &path ); bool createDirectoryFull(const string &path);
string getContainingDirectory( const string &path ); string getContainingDirectory(const string &path);
string getFileName( const string &path ); string getFileName(const string &path);
string getFileExtension( const string &path ); string getFileExtension(const string &path);
extern char dir_divisor; extern char dir_divisor;
class Directory { class Directory {
public: public:
Directory() = delete; Directory() = delete;
explicit Directory( const string &path_ ); explicit Directory(const string &path_);
explicit Directory( const Directory &d ) = default; explicit Directory(const Directory &d) = default;
explicit Directory( Directory &&d ) = default; explicit Directory(Directory &&d) = default;
class Iterator { class Iterator {
public: public:
explicit Iterator( const Directory &d_ ); explicit Iterator(const Directory &d_);
~Iterator(); ~Iterator();
#ifdef _WIN32 #ifdef _WIN32
explicit Iterator( bool ended_ ); explicit Iterator(bool ended_);
#else #else
Iterator( const Directory &d_, const struct dirent *current_entry_ ); Iterator(const Directory &d_, const struct dirent *current_entry_);
#endif #endif
Iterator() = delete; Iterator() = delete;
Iterator( const Iterator &i ) = default; Iterator(const Iterator &i) = default;
Iterator( Iterator &&i ) = default; Iterator(Iterator &&i) = default;
char_t const *operator*() const; char_t const *operator*() const;
Iterator &operator++(); Iterator &operator++();
bool operator==( const Iterator &i_other ) const; bool operator==(const Iterator &i_other) const;
Iterator operator++( int ) { Iterator operator++(int) {
Iterator ret( *this ); Iterator ret(*this);
operator++(); operator++();
return ret; return ret;
} }
bool operator!=( const Iterator &i_other ) const { bool operator!=(const Iterator &i_other) const {
return !( i_other == *this ); return !(i_other == *this);
} }
private: private:
@ -94,11 +94,11 @@ public:
const_iterator end() const; const_iterator end() const;
iterator begin() { iterator begin() {
return Iterator( *this ); return Iterator(*this);
} }
const_iterator begin() const { const_iterator begin() const {
return Iterator( *this ); return Iterator(*this);
} }
const_iterator cbegin() const { const_iterator cbegin() const {
@ -115,7 +115,7 @@ public:
#ifdef _WIN32 #ifdef _WIN32
const char_t *validPath() const { const char_t *validPath() const {
return dir_path.substr( 0, dir_path.length() - 2 ).c_str(); return dir_path.substr(0, dir_path.length() - 2).c_str();
} }
#endif #endif

View File

@ -10,44 +10,42 @@
char FSLib::dir_divisor = '/'; char FSLib::dir_divisor = '/';
FSLib::Directory::Directory( const string &path_ ) : dir_path( path_ ) {} FSLib::Directory::Directory(const string &path_) : dir_path(path_) {}
FSLib::Directory::Iterator::Iterator( const Directory &d_ ) FSLib::Directory::Iterator::Iterator(const Directory &d_)
: d( opendir( d_.path() ) ) { : d(opendir(d_.path())) {
if ( !exists( d_.path() ) || !isDirectory( d_.path() ) ) { if (!exists(d_.path()) || !isDirectory(d_.path())) {
throw std::runtime_error( throw std::runtime_error(std::string("Directory ") + d_.path() +
std::string( "Directory " ) + d_.path() + " either doesn't exist or isn't a directory");
" either doesn't exist or isn't a directory" );
} }
current_entry = readdir( d ); current_entry = readdir(d);
// skip "." and ".." // skip "." and ".."
if ( current_entry != nullptr && if (current_entry != nullptr && (!strcmp(current_entry->d_name, ".") ||
( !strcmp( current_entry->d_name, "." ) || !strcmp(current_entry->d_name, "..")))
!strcmp( current_entry->d_name, ".." ) ) ) ++(*this);
++( *this );
} }
FSLib::Directory::Iterator::Iterator( const Directory &d_, FSLib::Directory::Iterator::Iterator(const Directory &d_,
const struct dirent *current_entry_ ) const struct dirent *current_entry_)
: d( opendir( d_.path() ) ), current_entry( current_entry_ ) {} : d(opendir(d_.path())), current_entry(current_entry_) {}
FSLib::Directory::Iterator::~Iterator() { FSLib::Directory::Iterator::~Iterator() {
if ( d ) if (d)
closedir( d ); closedir(d);
} }
bool FSLib::exists( const string &path ) { bool FSLib::exists(const string &path) {
struct stat path_stat; struct stat path_stat;
return stat( path.c_str(), &path_stat ) == 0; return stat(path.c_str(), &path_stat) == 0;
} }
string FSLib::canonical( const string &path ) { string FSLib::canonical(const string &path) {
char_t *canonical_path = new char_t[PATH_MAX]; char_t *canonical_path = new char_t[PATH_MAX];
auto failed = realpath( path.c_str(), canonical_path ) == nullptr; auto failed = realpath(path.c_str(), canonical_path) == nullptr;
if ( failed ) { if (failed) {
delete[] canonical_path; delete[] canonical_path;
return string(); return string();
} }
@ -57,76 +55,76 @@ string FSLib::canonical( const string &path ) {
return canonical_string; return canonical_string;
} }
bool FSLib::isDirectory( const string &path ) { bool FSLib::isDirectory(const string &path) {
struct stat path_stat; struct stat path_stat;
if ( stat( path.c_str(), &path_stat ) != 0 ) if (stat(path.c_str(), &path_stat) != 0)
return false; return false;
return S_ISDIR( path_stat.st_mode ); return S_ISDIR(path_stat.st_mode);
} }
bool FSLib::rename( const string &file_a, const string &file_b ) { bool FSLib::rename(const string &file_a, const string &file_b) {
// TODO log // TODO log
std::cout << file_a << " -> " << file_b << std::endl; std::cout << file_a << " -> " << file_b << std::endl;
return ::rename( file_a.c_str(), file_b.c_str() ) == 0; return ::rename(file_a.c_str(), file_b.c_str()) == 0;
} }
// TODO do windows version // TODO do windows version
bool deleteRecursive(const string &dir) { bool deleteRecursive(const string &dir) {
for(const auto &file : FSLib::Directory(dir)) { for (const auto &file : FSLib::Directory(dir)) {
auto path = dir + "/" + file; auto path = dir + "/" + file;
if(FSLib::isDirectory(path)) { if (FSLib::isDirectory(path)) {
if(!deleteRecursive(path)) { if (!deleteRecursive(path)) {
return false; return false;
} }
} else if(unlink(path.c_str()) != 0) { } else if (unlink(path.c_str()) != 0) {
return false; return false;
} }
} }
return rmdir(dir.c_str()) == 0; return rmdir(dir.c_str()) == 0;
} }
bool FSLib::deleteFile( const string &file ) { bool FSLib::deleteFile(const string &file) {
// TODO log // TODO log
auto canon = canonical( file ); auto canon = canonical(file);
if(canon.empty()) { if (canon.empty()) {
return false; return false;
} }
if(isDirectory(canon)) { if (isDirectory(canon)) {
return deleteRecursive(canon); return deleteRecursive(canon);
} }
return unlink(canon.c_str()) == 0; return unlink(canon.c_str()) == 0;
} }
bool FSLib::createDirectoryFull( const string &path ) { bool FSLib::createDirectoryFull(const string &path) {
uint64_t pos{}; uint64_t pos{};
// go through all directories leading to the last one // go through all directories leading to the last one
// and create them if they don't exist // and create them if they don't exist
do { do {
// get partial directory path // get partial directory path
pos = path.find_first_of( "/", pos ); pos = path.find_first_of("/", pos);
if ( pos > 0 ) { if (pos > 0) {
auto dirname = path.substr( 0, pos ); auto dirname = path.substr(0, pos);
// create it if it doesn't exist // create it if it doesn't exist
if ( !FSLib::exists( dirname ) ) { if (!FSLib::exists(dirname)) {
if ( mkdir( dirname.c_str(), if (mkdir(dirname.c_str(),
S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH ) != 0 ) S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0)
return false; return false;
} }
} }
pos++; pos++;
} while ( pos < path.length() && pos != 0 ); } while (pos < path.length() && pos != 0);
return true; return true;
} }
FSLib::Directory::iterator FSLib::Directory::end() { FSLib::Directory::iterator FSLib::Directory::end() {
return Iterator( *this, nullptr ); return Iterator(*this, nullptr);
} }
FSLib::Directory::const_iterator FSLib::Directory::end() const { FSLib::Directory::const_iterator FSLib::Directory::end() const {
return Iterator( *this, nullptr ); return Iterator(*this, nullptr);
} }
char_t const *FSLib::Directory::Iterator::operator*() const { char_t const *FSLib::Directory::Iterator::operator*() const {
@ -134,40 +132,39 @@ char_t const *FSLib::Directory::Iterator::operator*() const {
} }
FSLib::Directory::Iterator &FSLib::Directory::Iterator::operator++() { FSLib::Directory::Iterator &FSLib::Directory::Iterator::operator++() {
if ( current_entry == nullptr ) if (current_entry == nullptr)
return *this; return *this;
current_entry = readdir( d ); current_entry = readdir(d);
// skip . and .. // skip . and ..
if ( current_entry != nullptr && if (current_entry != nullptr && (!strcmp(current_entry->d_name, ".") ||
( !strcmp( current_entry->d_name, "." ) || !strcmp(current_entry->d_name, "..")))
!strcmp( current_entry->d_name, ".." ) ) )
return operator++(); return operator++();
return *this; return *this;
} }
bool FSLib::Directory::Iterator::operator==( const Iterator &i_other ) const { bool FSLib::Directory::Iterator::operator==(const Iterator &i_other) const {
return i_other.current_entry == current_entry; return i_other.current_entry == current_entry;
} }
string FSLib::getContainingDirectory( const string &path ) { string FSLib::getContainingDirectory(const string &path) {
auto pos = path.find_last_of('/'); auto pos = path.find_last_of('/');
if(pos == string::npos) { if (pos == string::npos) {
return "."; return ".";
} }
return path.substr(0, pos); return path.substr(0, pos);
} }
string FSLib::getFileName( const string &path ) { string FSLib::getFileName(const string &path) {
auto pos = path.find_last_of('/'); auto pos = path.find_last_of('/');
if(pos == string::npos) { if (pos == string::npos) {
return path; return path;
} }
return path.substr(pos+1); return path.substr(pos + 1);
} }
string FSLib::getFileExtension( const string &path ) { string FSLib::getFileExtension(const string &path) {
auto pos = path.find_last_of('.'); auto pos = path.find_last_of('.');
if(pos == string::npos) { if (pos == string::npos) {
return ""; return "";
} }
return path.substr(pos + 1); return path.substr(pos + 1);

View File

@ -6,21 +6,20 @@
char FSLib::dir_divisor = '\\'; char FSLib::dir_divisor = '\\';
FSLib::Directory::Directory( const string &path_ ) : dir_path( path_ ) { FSLib::Directory::Directory(const string &path_) : dir_path(path_) {
// need to append \\* for windows to search files in directory // need to append \\* for windows to search files in directory
dir_path.append( L"\\*" ); dir_path.append(L"\\*");
} }
FSLib::Directory::Iterator::Iterator( const Directory &d_ ) { FSLib::Directory::Iterator::Iterator(const Directory &d_) {
if ( !exists( d_.validPath() ) || !isDirectory( d_.validPath() ) ) { if (!exists(d_.validPath()) || !isDirectory(d_.validPath())) {
throw std::runtime_error( throw std::runtime_error(
"Directory either doesn't exist or isn't a directory" ); "Directory either doesn't exist or isn't a directory");
} }
hFind = FindFirstFileW( d_.path(), &data ); hFind = FindFirstFileW(d_.path(), &data);
if ( hFind != INVALID_HANDLE_VALUE ) { if (hFind != INVALID_HANDLE_VALUE) {
if ( !wcscmp( data.cFileName, L"." ) || if (!wcscmp(data.cFileName, L".") || !wcscmp(data.cFileName, L"..")) {
!wcscmp( data.cFileName, L".." ) ) { ++(*this);
++( *this );
} }
} else { } else {
ended = true; ended = true;
@ -28,37 +27,37 @@ FSLib::Directory::Iterator::Iterator( const Directory &d_ ) {
} }
FSLib::Directory::Iterator::~Iterator() { FSLib::Directory::Iterator::~Iterator() {
if ( hFind ) if (hFind)
FindClose( hFind ); FindClose(hFind);
} }
// this is definitely not a good way to create the "end" iterator // this is definitely not a good way to create the "end" iterator
// but it was the only way I thought of with my limited knowledge of // but it was the only way I thought of with my limited knowledge of
// windows.h // windows.h
FSLib::Directory::Iterator::Iterator( bool ended_ ) : ended( ended_ ) {} FSLib::Directory::Iterator::Iterator(bool ended_) : ended(ended_) {}
bool FSLib::exists( const string &path ) { bool FSLib::exists(const string &path) {
struct _stat path_stat; struct _stat path_stat;
return _wstat( path.c_str(), &path_stat ) == 0; return _wstat(path.c_str(), &path_stat) == 0;
} }
string FSLib::canonical( const string &path ) { string FSLib::canonical(const string &path) {
char_t *full_path = new char_t[MAX_PATH]; char_t *full_path = new char_t[MAX_PATH];
char_t *canonical_path = new char_t[MAX_PATH]; char_t *canonical_path = new char_t[MAX_PATH];
auto failed = !GetFullPathName( path.c_str(), MAX_PATH, full_path, NULL ); auto failed = !GetFullPathName(path.c_str(), MAX_PATH, full_path, NULL);
if ( failed ) { if (failed) {
delete[] canonical_path; delete[] canonical_path;
delete[] full_path; delete[] full_path;
return string(); return string();
} }
failed = !PathCanonicalizeW( canonical_path, full_path ); failed = !PathCanonicalizeW(canonical_path, full_path);
delete[] full_path; delete[] full_path;
if ( failed ) { if (failed) {
delete[] canonical_path; delete[] canonical_path;
return string(); return string();
} }
@ -68,46 +67,46 @@ string FSLib::canonical( const string &path ) {
return canonical_string; return canonical_string;
} }
bool FSLib::isDirectory( const string &path ) { bool FSLib::isDirectory(const string &path) {
struct _stat path_stat; struct _stat path_stat;
if ( _wstat( path.c_str(), &path_stat ) != 0 ) if (_wstat(path.c_str(), &path_stat) != 0)
return false; return false;
return path_stat.st_mode & _S_IFDIR; return path_stat.st_mode & _S_IFDIR;
} }
bool FSLib::rename( const string &file_a, const string &file_b ) { bool FSLib::rename(const string &file_a, const string &file_b) {
return MoveFileExW( file_a.c_str(), file_b.c_str(), return MoveFileExW(file_a.c_str(), file_b.c_str(),
MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING ); MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING);
} }
bool FSLib::createDirectoryFull( const string &path ) { bool FSLib::createDirectoryFull(const string &path) {
uint64_t pos = path.find_first_of( L":", 0 ) + 2; uint64_t pos = path.find_first_of(L":", 0) + 2;
if ( pos == string::npos ) if (pos == string::npos)
pos = 0; pos = 0;
// go through all directories leading to the last one // go through all directories leading to the last one
// and create them if they don't exist // and create them if they don't exist
do { do {
// get partial directory path // get partial directory path
pos = path.find_first_of( L"\\", pos ); pos = path.find_first_of(L"\\", pos);
auto dirname = path.substr( 0, pos ); auto dirname = path.substr(0, pos);
// create it if it doesn't exist // create it if it doesn't exist
if ( !FSLib::exists( dirname ) ) { if (!FSLib::exists(dirname)) {
if ( !CreateDirectoryW( dirname.c_str(), NULL ) ) if (!CreateDirectoryW(dirname.c_str(), NULL))
return false; return false;
} }
pos++; pos++;
} while ( pos < path.length() && pos != 0 ); } while (pos < path.length() && pos != 0);
return true; return true;
} }
FSLib::Directory::iterator FSLib::Directory::end() { FSLib::Directory::iterator FSLib::Directory::end() {
return Iterator( true ); return Iterator(true);
} }
FSLib::Directory::const_iterator FSLib::Directory::end() const { FSLib::Directory::const_iterator FSLib::Directory::end() const {
return Iterator( true ); return Iterator(true);
} }
char_t const *FSLib::Directory::Iterator::operator*() const { char_t const *FSLib::Directory::Iterator::operator*() const {
@ -115,41 +114,41 @@ char_t const *FSLib::Directory::Iterator::operator*() const {
} }
FSLib::Directory::Iterator &FSLib::Directory::Iterator::operator++() { FSLib::Directory::Iterator &FSLib::Directory::Iterator::operator++() {
if ( ended == true ) if (ended == true)
return *this; return *this;
// skip . and .. // skip . and ..
if ( FindNextFileW( hFind, &data ) == 0 ) { if (FindNextFileW(hFind, &data) == 0) {
ended = true; ended = true;
} else if ( !wcscmp( data.cFileName, L"." ) || } else if (!wcscmp(data.cFileName, L".") ||
!wcscmp( data.cFileName, L".." ) ) { !wcscmp(data.cFileName, L"..")) {
return operator++(); return operator++();
} }
return *this; return *this;
} }
bool FSLib::Directory::Iterator::operator==( const Iterator &i_other ) const { bool FSLib::Directory::Iterator::operator==(const Iterator &i_other) const {
return i_other.ended == ended; return i_other.ended == ended;
} }
string FSLib::getContainingDirectory( const string &path ) { string FSLib::getContainingDirectory(const string &path) {
auto pos = path.find_last_of('\\'); auto pos = path.find_last_of('\\');
if(pos == string::npos) { if (pos == string::npos) {
return "."; return ".";
} }
return path.substr(0, pos); return path.substr(0, pos);
} }
string FSLib::getFileName( const string &path ) { string FSLib::getFileName(const string &path) {
auto pos = path.find_last_of('\\'); auto pos = path.find_last_of('\\');
if(pos == string::npos) { if (pos == string::npos) {
return path; return path;
} }
return path.substr(pos+1); return path.substr(pos + 1);
} }
string FSLib::getFileExtension( const string &path ) { string FSLib::getFileExtension(const string &path) {
auto pos = path.find_last_of('.'); auto pos = path.find_last_of('.');
if(pos == string::npos) { if (pos == string::npos) {
return ""; return "";
} }
return path.substr(pos + 1); return path.substr(pos + 1);

View File

@ -33,8 +33,9 @@ public:
std::shared_ptr<SDLPP::Renderer> &r, const std::string &text, std::shared_ptr<SDLPP::Renderer> &r, const std::string &text,
const ButtonConfig &config, const ButtonConfig &config,
std::function<void(void *, Button *)> click_fun, void *input) std::function<void(void *, Button *)> click_fun, void *input)
: TextRenderer(x, y, w, h, r, g_text_config->getFont(), text, config.font_color, : TextRenderer(x, y, w, h, r, g_text_config->getFont(), text,
config.font_outline_color, config.outline), config.font_color, config.font_outline_color,
config.outline),
click_fun(std::move(click_fun)), func_input(input), click_fun(std::move(click_fun)), func_input(input),
config(config), button_text(text) { config(config), button_text(text) {
setColor(config.bg_color); setColor(config.bg_color);
@ -48,60 +49,60 @@ public:
} }
void setFontColor(const std::string &color) { void setFontColor(const std::string &color) {
config.font_color = color; config.font_color = color;
if(!highlighted && !disabled) { if (!highlighted && !disabled) {
should_update_color = true; should_update_color = true;
} }
} }
void setFontColorHighlight(const std::string &color) { void setFontColorHighlight(const std::string &color) {
config.font_color_highlight = color; config.font_color_highlight = color;
if(highlighted && !disabled) { if (highlighted && !disabled) {
should_update_color = true; should_update_color = true;
} }
} }
void setFontColorDisabled(const std::string &color) { void setFontColorDisabled(const std::string &color) {
config.font_color_disabled = color; config.font_color_disabled = color;
if(disabled) { if (disabled) {
should_update_color = true; should_update_color = true;
} }
} }
void setFontOutlineColor(const std::string &color) { void setFontOutlineColor(const std::string &color) {
config.font_outline_color = color; config.font_outline_color = color;
if(!highlighted && !disabled) { if (!highlighted && !disabled) {
should_update_color = true; should_update_color = true;
} }
} }
void setFontOutlineColorHighlight(const std::string &color) { void setFontOutlineColorHighlight(const std::string &color) {
config.font_outline_color_highlight = color; config.font_outline_color_highlight = color;
if(highlighted && !disabled) { if (highlighted && !disabled) {
should_update_color = true; should_update_color = true;
} }
} }
void setFontOutlineColorDisabled(const std::string &color) { void setFontOutlineColorDisabled(const std::string &color) {
config.font_outline_color_disabled = color; config.font_outline_color_disabled = color;
if(disabled) { if (disabled) {
should_update_color = true; should_update_color = true;
} }
} }
void setBackgroundColor(const std::string &color) { void setBackgroundColor(const std::string &color) {
config.bg_color = color; config.bg_color = color;
if(!highlighted && !disabled) { if (!highlighted && !disabled) {
setColor(color); setColor(color);
} }
} }
void setBackgroundColorHighlight(const std::string &color) { void setBackgroundColorHighlight(const std::string &color) {
config.bg_color_highlight = color; config.bg_color_highlight = color;
if(highlighted && !disabled) { if (highlighted && !disabled) {
setColor(color); setColor(color);
} }
} }
void setBackgroundColorDisabled(const std::string &color) { void setBackgroundColorDisabled(const std::string &color) {
config.bg_color_disabled = color; config.bg_color_disabled = color;
if(disabled) { if (disabled) {
setColor(color); setColor(color);
} }
} }
void performFunction() { void performFunction() {
if(!disabled) { if (!disabled) {
click_fun(func_input, this); click_fun(func_input, this);
} }
} }
@ -112,7 +113,7 @@ public:
_id = id; _id = id;
} }
void setHighlight() { void setHighlight() {
if(!disabled) { if (!disabled) {
setColor(config.bg_color_highlight); setColor(config.bg_color_highlight);
should_update_color = true; should_update_color = true;
state = HIGHLIGHTED; state = HIGHLIGHTED;
@ -120,7 +121,7 @@ public:
highlighted = true; highlighted = true;
} }
void unsetHighlight() { void unsetHighlight() {
if(!disabled) { if (!disabled) {
setColor(config.bg_color); setColor(config.bg_color);
should_update_color = true; should_update_color = true;
state = NORMAL; state = NORMAL;
@ -134,7 +135,7 @@ public:
disabled = true; disabled = true;
} }
void enable() { void enable() {
if(!highlighted) { if (!highlighted) {
setColor(config.bg_color); setColor(config.bg_color);
should_update_color = true; should_update_color = true;
state = NORMAL; state = NORMAL;
@ -147,24 +148,30 @@ public:
} }
void update() { void update() {
if(should_update_color) { if (should_update_color) {
switch(state) { switch (state) {
case NORMAL: case NORMAL:
setTextColor(g_text_config->getFont(), config.font_color, config.font_outline_color, config.outline); setTextColor(g_text_config->getFont(), config.font_color,
break; config.font_outline_color, config.outline);
case HIGHLIGHTED: break;
setTextColor(g_text_config->getFont(), config.font_color_highlight, config.font_outline_color_highlight, config.outline); case HIGHLIGHTED:
break; setTextColor(
case DISABLED: g_text_config->getFont(), config.font_color_highlight,
setTextColor(g_text_config->getFont(), config.font_color_disabled, config.font_outline_color_disabled, config.outline); config.font_outline_color_highlight, config.outline);
default: break;
break; case DISABLED:
setTextColor(
g_text_config->getFont(), config.font_color_disabled,
config.font_outline_color_disabled, config.outline);
default:
break;
} }
} }
if(should_update_text) { if (should_update_text) {
changeText(button_text); changeText(button_text);
} }
} }
private: private:
std::function<void(void *, Button *)> click_fun; std::function<void(void *, Button *)> click_fun;
void *func_input; void *func_input;

View File

@ -14,10 +14,10 @@
#define FILE_VERSION 0x01 #define FILE_VERSION 0x01
void loadMapV01(std::shared_ptr<SDLPP::Scene> &scene, void loadMapV01(std::shared_ptr<SDLPP::Scene> &scene,
std::shared_ptr<SDLPP::RenderObject> &mario, std::shared_ptr<SDLPP::RenderObject> &mario,
std::ifstream &map_file, std::vector<mapColumnType> &objects, std::ifstream &map_file, std::vector<mapColumnType> &objects,
bool editor, size_t editor_width, bool editor, size_t editor_width,
std::shared_ptr<SDLPP::Renderer> &renderer); std::shared_ptr<SDLPP::Renderer> &renderer);
void loadMap(std::shared_ptr<SDLPP::Scene> &scene, void loadMap(std::shared_ptr<SDLPP::Scene> &scene,
std::shared_ptr<SDLPP::RenderObject> mario, std::shared_ptr<SDLPP::RenderObject> mario,
@ -96,7 +96,7 @@ MapObject parseBlock(std::ifstream &map_file) {
modifier_id, modifier_data); modifier_id, modifier_data);
} }
void loadEmptyMap( std::vector<mapColumnType> &objects, size_t editor_width) { void loadEmptyMap(std::vector<mapColumnType> &objects, size_t editor_width) {
objects.resize(editor_width); objects.resize(editor_width);
} }
@ -106,7 +106,7 @@ void loadMap(std::shared_ptr<SDLPP::Scene> &scene,
std::shared_ptr<SDLPP::RenderObject> &mario, std::shared_ptr<SDLPP::RenderObject> &mario,
const std::string &file, std::vector<mapColumnType> &objects, const std::string &file, std::vector<mapColumnType> &objects,
bool editor, size_t editor_width) { bool editor, size_t editor_width) {
if(!FSLib::exists(file)) { if (!FSLib::exists(file)) {
// create empty array large enough for initial editor window // create empty array large enough for initial editor window
loadEmptyMap(objects, editor_width); loadEmptyMap(objects, editor_width);
return; return;
@ -116,20 +116,21 @@ void loadMap(std::shared_ptr<SDLPP::Scene> &scene,
map_file.open(file, std::ios::in | std::ios::binary); map_file.open(file, std::ios::in | std::ios::binary);
uint16_t version; uint16_t version;
map_file.read((char *)&version, sizeof(uint16_t) / sizeof(char)); map_file.read((char *)&version, sizeof(uint16_t) / sizeof(char));
switch(version) { switch (version) {
case 0x01: case 0x01:
loadMapV01(scene, mario, map_file, objects, editor, editor_width, renderer); loadMapV01(scene, mario, map_file, objects, editor, editor_width,
break; renderer);
default: break;
throw "Invalid file version"; default:
throw "Invalid file version";
} }
} }
void loadMapV01(std::shared_ptr<SDLPP::Scene> &scene, void loadMapV01(std::shared_ptr<SDLPP::Scene> &scene,
std::shared_ptr<SDLPP::RenderObject> &mario, std::shared_ptr<SDLPP::RenderObject> &mario,
std::ifstream &map_file, std::vector<mapColumnType> &objects, std::ifstream &map_file, std::vector<mapColumnType> &objects,
bool editor, size_t editor_width, bool editor, size_t editor_width,
std::shared_ptr<SDLPP::Renderer> &renderer) { std::shared_ptr<SDLPP::Renderer> &renderer) {
uint16_t cols; uint16_t cols;
map_file.read((char *)&cols, sizeof(uint16_t) / sizeof(char)); map_file.read((char *)&cols, sizeof(uint16_t) / sizeof(char));
if (editor) { if (editor) {
@ -222,14 +223,13 @@ void loadMapV01(std::shared_ptr<SDLPP::Scene> &scene,
if (editor && objects.size() < editor_width) { if (editor && objects.size() < editor_width) {
objects.resize(editor_width); objects.resize(editor_width);
} }
} }
// TODO catch exception in calling func // TODO catch exception in calling func
void saveMap(const std::string &file, std::vector<mapColumnType> &objects) { void saveMap(const std::string &file, std::vector<mapColumnType> &objects) {
std::ofstream output_file; std::ofstream output_file;
output_file.open(file, std::ios::out | std::ios::binary); output_file.open(file, std::ios::out | std::ios::binary);
if(!output_file.is_open()) { if (!output_file.is_open()) {
throw "Could not open file '" + file + "'"; throw "Could not open file '" + file + "'";
} }
const uint16_t version = FILE_VERSION; const uint16_t version = FILE_VERSION;

View File

@ -14,7 +14,7 @@ void loadMap(std::shared_ptr<SDLPP::Scene> &scene,
std::shared_ptr<SDLPP::RenderObject> &mario, std::shared_ptr<SDLPP::RenderObject> &mario,
const std::string &file, std::vector<mapColumnType> &objects, const std::string &file, std::vector<mapColumnType> &objects,
bool editor = false, size_t editor_width = 0); bool editor = false, size_t editor_width = 0);
void loadEmptyMap( std::vector<mapColumnType> &objects, size_t editor_width); void loadEmptyMap(std::vector<mapColumnType> &objects, size_t editor_width);
void saveMap(const std::string &file, std::vector<mapColumnType> &objects); void saveMap(const std::string &file, std::vector<mapColumnType> &objects);
#endif #endif

View File

@ -121,12 +121,13 @@ std::mutex render_mutex;
std::vector<moveStruct> arrowInputs{}; std::vector<moveStruct> arrowInputs{};
std::shared_ptr<SDLPP::Scene> editorScene; std::shared_ptr<SDLPP::Scene> editorScene;
SceneStruct mainMenuScene; SceneStruct mainMenuScene;
//SceneStruct fileChoiceScene; // SceneStruct fileChoiceScene;
std::shared_ptr<SDLPP::TextRenderer> global_test_text{}; std::shared_ptr<SDLPP::TextRenderer> global_test_text{};
std::string global_test_text_text{}; std::string global_test_text_text{};
void openMapEditor(std::shared_ptr<SDLPP::Scene> &scene, const std::string &filename); void openMapEditor(std::shared_ptr<SDLPP::Scene> &scene,
const std::string &filename);
void setFlag(uint64_t flag) { void setFlag(uint64_t flag) {
global_vars.flags |= flag; global_vars.flags |= flag;
@ -138,18 +139,18 @@ bool getFlag(uint64_t flag) {
return global_vars.flags & flag; return global_vars.flags & flag;
} }
void saveMapCallback(void */*UNUSED*/, Button */*UNUSED*/) { void saveMapCallback(void * /*UNUSED*/, Button * /*UNUSED*/) {
std::cout << "SAVING" << std::endl; std::cout << "SAVING" << std::endl;
// TODO filename // TODO filename
saveMap("test_binary2.bin", global_vars.objects); saveMap("test_binary2.bin", global_vars.objects);
} }
void loadMapDialogCallback(void */*UNUSED*/, Button */*UNUSED*/) { void loadMapDialogCallback(void * /*UNUSED*/, Button * /*UNUSED*/) {
std::cout << "LOADING" << std::endl; std::cout << "LOADING" << std::endl;
setFlag(LOAD_MAP_FLAG); setFlag(LOAD_MAP_FLAG);
// TODO filename // TODO filename
/* editorScene->resetScene(); /* editorScene->resetScene();
openMapEditor(editorScene, "test_binary.bin");*/ openMapEditor(editorScene, "test_binary.bin");*/
} }
void updateTool() { void updateTool() {
@ -249,14 +250,15 @@ void unsetToolColor() {
setToolColor("#FFFFFF00"); setToolColor("#FFFFFF00");
} }
void toolMoveUpdateButtons(Button *left, Button *right, int &cur_page, int &max_page, bool canAdd) { void toolMoveUpdateButtons(Button *left, Button *right, int &cur_page,
if(cur_page == 0) { int &max_page, bool canAdd) {
if (cur_page == 0) {
left->disable(); left->disable();
} else { } else {
left->enable(); left->enable();
} }
if(cur_page != max_page) { if (cur_page != max_page) {
if(canAdd) { if (canAdd) {
// TOOD global button config // TOOD global button config
right->changeText(">"); right->changeText(">");
right->setFontColor("#000000"); right->setFontColor("#000000");
@ -267,7 +269,7 @@ void toolMoveUpdateButtons(Button *left, Button *right, int &cur_page, int &max_
right->enable(); right->enable();
} }
} else { } else {
if(canAdd) { if (canAdd) {
right->changeText("+"); right->changeText("+");
right->setFontColor("#00FF00"); right->setFontColor("#00FF00");
right->setFontOutlineColor("#000000"); right->setFontOutlineColor("#000000");
@ -289,19 +291,26 @@ void updateToolSelection(int prev_index, ToolType::Value type) {
cur_page = global_vars.tool.cur_page_tools; cur_page = global_vars.tool.cur_page_tools;
multiplier = 2 * TOOLS_WIDTH; multiplier = 2 * TOOLS_WIDTH;
tool_vec = &global_vars.tools; tool_vec = &global_vars.tools;
toolMoveUpdateButtons(global_vars.tool.button_left_tools.get(), global_vars.tool.button_right_tools.get(), cur_page, global_vars.tool.max_page_tools, false); toolMoveUpdateButtons(global_vars.tool.button_left_tools.get(),
global_vars.tool.button_right_tools.get(),
cur_page, global_vars.tool.max_page_tools, false);
break; break;
case ToolType::MOD: case ToolType::MOD:
cur_page = global_vars.tool.cur_page_mods; cur_page = global_vars.tool.cur_page_mods;
multiplier = 2 * MOD_WIDTH; multiplier = 2 * MOD_WIDTH;
tool_vec = &global_vars.mods; tool_vec = &global_vars.mods;
toolMoveUpdateButtons(global_vars.tool.button_left_mods.get(), global_vars.tool.button_right_mods.get(), cur_page, global_vars.tool.max_page_mods, false); toolMoveUpdateButtons(global_vars.tool.button_left_mods.get(),
global_vars.tool.button_right_mods.get(),
cur_page, global_vars.tool.max_page_mods, false);
break; break;
case ToolType::CHARACTER: case ToolType::CHARACTER:
cur_page = global_vars.tool.cur_page_characters; cur_page = global_vars.tool.cur_page_characters;
multiplier = 2 * CHARACTER_WIDTH; multiplier = 2 * CHARACTER_WIDTH;
tool_vec = &global_vars.characters; tool_vec = &global_vars.characters;
toolMoveUpdateButtons(global_vars.tool.button_left_characters.get(), global_vars.tool.button_right_characters.get(), cur_page, global_vars.tool.max_page_characters, false); toolMoveUpdateButtons(global_vars.tool.button_left_characters.get(),
global_vars.tool.button_right_characters.get(),
cur_page, global_vars.tool.max_page_characters,
false);
default: default:
break; break;
} }
@ -519,7 +528,7 @@ void handleKeyUp(SDL_Keycode key, SDLPP::Scene &scene) {
switch (key) { switch (key) {
case SDLK_ESCAPE: case SDLK_ESCAPE:
std::cout << "Eskape" << std::endl; std::cout << "Eskape" << std::endl;
//setFlag(QUIT_FLAG); // setFlag(QUIT_FLAG);
game_scenes.push_back(mainMenuScene); game_scenes.push_back(mainMenuScene);
break; break;
case SDLK_a: case SDLK_a:
@ -566,11 +575,12 @@ void getMousePositionFlags(SDLPP::Scene &scene) {
MouseVisitor visitor; MouseVisitor visitor;
scene.visitCollisions(*mouse, visitor); scene.visitCollisions(*mouse, visitor);
if(visitor.getCurButton() != global_vars.mouse.cur_button_index) { if (visitor.getCurButton() != global_vars.mouse.cur_button_index) {
if(global_vars.mouse.cur_button_index != (uint64_t)-1) { if (global_vars.mouse.cur_button_index != (uint64_t)-1) {
global_vars.buttons[global_vars.mouse.cur_button_index]->unsetHighlight(); global_vars.buttons[global_vars.mouse.cur_button_index]
->unsetHighlight();
} }
if(visitor.getCurButton() != (uint64_t)-1) { if (visitor.getCurButton() != (uint64_t)-1) {
global_vars.buttons[visitor.getCurButton()]->setHighlight(); global_vars.buttons[visitor.getCurButton()]->setHighlight();
} }
} }
@ -591,76 +601,89 @@ void getMousePositionFlags(SDLPP::Scene &scene) {
} }
} }
void toolMoveLeft(Button *left, Button *right, int &cur_page, int &max_page, bool canAdd) { void toolMoveLeft(Button *left, Button *right, int &cur_page, int &max_page,
bool canAdd) {
cur_page--; cur_page--;
toolMoveUpdateButtons(left, right, cur_page, max_page, canAdd); toolMoveUpdateButtons(left, right, cur_page, max_page, canAdd);
} }
void toolMoveRight(Button *left, Button *right, int &cur_page, int &max_page, bool canAdd) { void toolMoveRight(Button *left, Button *right, int &cur_page, int &max_page,
bool canAdd) {
cur_page += 1; cur_page += 1;
toolMoveUpdateButtons(left, right, cur_page, max_page, canAdd); toolMoveUpdateButtons(left, right, cur_page, max_page, canAdd);
} }
void moveMapLeft(void *input, Button *caller) { void moveMapLeft(void *input, Button *caller) {
auto actual_input = static_cast<moveStruct*>(input); auto actual_input = static_cast<moveStruct *>(input);
actual_input->scene->moveEverything(BLOCK_SIZE, 0); actual_input->scene->moveEverything(BLOCK_SIZE, 0);
toolMoveLeft(caller, actual_input->other_button.get(), global_vars.map.cur_page, global_vars.map.max_page, true); toolMoveLeft(caller, actual_input->other_button.get(),
global_vars.map.cur_page, global_vars.map.max_page, true);
} }
void moveMapRight(void *input, Button *caller) { void moveMapRight(void *input, Button *caller) {
auto actual_input = static_cast<moveStruct*>(input); auto actual_input = static_cast<moveStruct *>(input);
if (global_vars.map.cur_page == global_vars.map.max_page) { // add column if (global_vars.map.cur_page == global_vars.map.max_page) { // add column
global_vars.objects.resize(global_vars.objects.size() + 1); global_vars.objects.resize(global_vars.objects.size() + 1);
global_vars.map.max_page++; global_vars.map.max_page++;
} }
toolMoveRight(actual_input->other_button.get(), caller, global_vars.map.cur_page, global_vars.map.max_page, true); toolMoveRight(actual_input->other_button.get(), caller,
global_vars.map.cur_page, global_vars.map.max_page, true);
actual_input->scene->moveEverything(-BLOCK_SIZE, 0); actual_input->scene->moveEverything(-BLOCK_SIZE, 0);
} }
void moveToolsLeftButton(void *input, Button *caller) { void moveToolsLeftButton(void *input, Button *caller) {
auto actual_input = static_cast<moveStruct*>(input); auto actual_input = static_cast<moveStruct *>(input);
toolMoveLeft(caller, actual_input->other_button.get(), global_vars.tool.cur_page_tools, global_vars.tool.max_page_tools, false); toolMoveLeft(caller, actual_input->other_button.get(),
updateToolSelection(global_vars.tool.cur_page_tools + 1, global_vars.tool.cur_page_tools,
ToolType::BLOCK); global_vars.tool.max_page_tools, false);
updateToolSelection(global_vars.tool.cur_page_tools + 1, ToolType::BLOCK);
} }
void moveToolsRightButton(void *input, Button *caller) { void moveToolsRightButton(void *input, Button *caller) {
auto actual_input = static_cast<moveStruct*>(input); auto actual_input = static_cast<moveStruct *>(input);
toolMoveRight(actual_input->other_button.get(), caller, global_vars.tool.cur_page_tools, global_vars.tool.max_page_tools, false); toolMoveRight(actual_input->other_button.get(), caller,
updateToolSelection(global_vars.tool.cur_page_tools - 1, global_vars.tool.cur_page_tools,
ToolType::BLOCK); global_vars.tool.max_page_tools, false);
updateToolSelection(global_vars.tool.cur_page_tools - 1, ToolType::BLOCK);
} }
void moveModsLeft(void *input, Button *caller) { void moveModsLeft(void *input, Button *caller) {
auto actual_input = static_cast<moveStruct*>(input); auto actual_input = static_cast<moveStruct *>(input);
toolMoveLeft(caller, actual_input->other_button.get(), global_vars.tool.cur_page_mods, global_vars.tool.max_page_mods, false); toolMoveLeft(caller, actual_input->other_button.get(),
updateToolSelection(global_vars.tool.cur_page_tools + 1, global_vars.tool.cur_page_mods, global_vars.tool.max_page_mods,
ToolType::MOD); false);
updateToolSelection(global_vars.tool.cur_page_tools + 1, ToolType::MOD);
} }
void moveModsRight(void *input, Button *caller) { void moveModsRight(void *input, Button *caller) {
auto actual_input = static_cast<moveStruct*>(input); auto actual_input = static_cast<moveStruct *>(input);
toolMoveRight(actual_input->other_button.get(), caller, global_vars.tool.cur_page_mods, global_vars.tool.max_page_mods, false); toolMoveRight(actual_input->other_button.get(), caller,
updateToolSelection(global_vars.tool.cur_page_tools - 1, global_vars.tool.cur_page_mods,
ToolType::MOD); global_vars.tool.max_page_mods, false);
updateToolSelection(global_vars.tool.cur_page_tools - 1, ToolType::MOD);
} }
void moveCharsLeft(void *input, Button *caller) { void moveCharsLeft(void *input, Button *caller) {
auto actual_input = static_cast<moveStruct*>(input); auto actual_input = static_cast<moveStruct *>(input);
toolMoveLeft(caller, actual_input->other_button.get(), global_vars.tool.cur_page_characters, global_vars.tool.max_page_characters, false); toolMoveLeft(caller, actual_input->other_button.get(),
global_vars.tool.cur_page_characters,
global_vars.tool.max_page_characters, false);
updateToolSelection(global_vars.tool.cur_page_tools + 1, updateToolSelection(global_vars.tool.cur_page_tools + 1,
ToolType::CHARACTER); ToolType::CHARACTER);
} }
void moveCharsRight(void *input, Button *caller) { void moveCharsRight(void *input, Button *caller) {
auto actual_input = static_cast<moveStruct*>(input); auto actual_input = static_cast<moveStruct *>(input);
toolMoveRight(actual_input->other_button.get(), caller, global_vars.tool.cur_page_characters, global_vars.tool.max_page_characters, false); toolMoveRight(actual_input->other_button.get(), caller,
global_vars.tool.cur_page_characters,
global_vars.tool.max_page_characters, false);
updateToolSelection(global_vars.tool.cur_page_tools - 1, updateToolSelection(global_vars.tool.cur_page_tools - 1,
ToolType::CHARACTER); ToolType::CHARACTER);
} }
void mouseUpAction(uint64_t flags) { void mouseUpAction(uint64_t flags) {
if(MouseVisitor::button(flags)) { if (MouseVisitor::button(flags)) {
global_vars.buttons[global_vars.mouse.cur_button_index]->performFunction(); global_vars.buttons[global_vars.mouse.cur_button_index]
->performFunction();
} }
} }
@ -779,24 +802,28 @@ void pollEvents(std::shared_ptr<SDLPP::Scene> &scene) {
setFlag(QUIT_FLAG); setFlag(QUIT_FLAG);
break; break;
case SDL_KEYUP: case SDL_KEYUP:
if(!getFlag(TEXT_INPUT_FLAG)) { if (!getFlag(TEXT_INPUT_FLAG)) {
handleKeyUp(event.key.keysym.sym, *scene); handleKeyUp(event.key.keysym.sym, *scene);
} else { } else {
if ( event.key.keysym.sym == SDLK_ESCAPE || event.key.keysym.sym == SDLK_RETURN ) { if (event.key.keysym.sym == SDLK_ESCAPE ||
event.key.keysym.sym == SDLK_RETURN) {
SDL_StopTextInput(); SDL_StopTextInput();
unsetFlag(TEXT_INPUT_FLAG); unsetFlag(TEXT_INPUT_FLAG);
} }
} }
break; break;
case SDL_KEYDOWN: case SDL_KEYDOWN:
if(getFlag(TEXT_INPUT_FLAG)) { if (getFlag(TEXT_INPUT_FLAG)) {
if( event.key.keysym.sym == SDLK_BACKSPACE && !global_test_text_text.empty() ) { if (event.key.keysym.sym == SDLK_BACKSPACE &&
!global_test_text_text.empty()) {
global_test_text_text.pop_back(); global_test_text_text.pop_back();
setFlag(TEXT_UPDATE_FLAG); setFlag(TEXT_UPDATE_FLAG);
} else if( event.key.keysym.sym == SDLK_c && SDL_GetModState() & KMOD_CTRL ) { } else if (event.key.keysym.sym == SDLK_c &&
SDL_GetModState() & KMOD_CTRL) {
// handle copy // handle copy
SDL_SetClipboardText( global_test_text_text.c_str() ); SDL_SetClipboardText(global_test_text_text.c_str());
} else if( event.key.keysym.sym == SDLK_v && SDL_GetModState() & KMOD_CTRL ) { } else if (event.key.keysym.sym == SDLK_v &&
SDL_GetModState() & KMOD_CTRL) {
// handle paste // handle paste
global_test_text_text += SDL_GetClipboardText(); global_test_text_text += SDL_GetClipboardText();
setFlag(TEXT_UPDATE_FLAG); setFlag(TEXT_UPDATE_FLAG);
@ -998,12 +1025,13 @@ void populateWorldType(
scene->addObject(tool_text); scene->addObject(tool_text);
} }
void testButtonFunc(void */*UNUSED*/, Button */*UNUSED*/) { void testButtonFunc(void * /*UNUSED*/, Button * /*UNUSED*/) {
setFlag(TEXT_INPUT_FLAG); setFlag(TEXT_INPUT_FLAG);
SDL_StartTextInput(); SDL_StartTextInput();
} }
void openMapEditor(std::shared_ptr<SDLPP::Scene> &scene, const std::string &filename) { void openMapEditor(std::shared_ptr<SDLPP::Scene> &scene,
const std::string &filename) {
auto renderer = scene->getRendererShared(); auto renderer = scene->getRendererShared();
auto font = std::make_shared<SDLPP::Font>("testfont.ttf", 36); auto font = std::make_shared<SDLPP::Font>("testfont.ttf", 36);
auto font_config = std::make_shared<SDLPP::FontConfiguration>( auto font_config = std::make_shared<SDLPP::FontConfiguration>(
@ -1016,11 +1044,11 @@ void openMapEditor(std::shared_ptr<SDLPP::Scene> &scene, const std::string &file
global_vars.current_world_type = LandType::OVERWORLD; global_vars.current_world_type = LandType::OVERWORLD;
if(filename.empty()) { if (filename.empty()) {
loadEmptyMap(global_vars.objects, MAP_WIDTH); loadEmptyMap(global_vars.objects, MAP_WIDTH);
} else { } else {
loadMap(scene, global_vars.mario, "test_binary.bin", global_vars.objects, loadMap(scene, global_vars.mario, "test_binary.bin",
true, MAP_WIDTH); global_vars.objects, true, MAP_WIDTH);
} }
// map // map
@ -1064,15 +1092,17 @@ void openMapEditor(std::shared_ptr<SDLPP::Scene> &scene, const std::string &file
2, scene); 2, scene);
global_test_text = std::make_shared<SDLPP::TextRenderer>( global_test_text = std::make_shared<SDLPP::TextRenderer>(
0.3, 0.05, BLOCK_SIZE*4, BLOCK_SIZE*2, 0.3, 0.05, BLOCK_SIZE * 4, BLOCK_SIZE * 2, renderer, "TEST TEXT",
renderer, "TEST TEXT", font_config, SDLPP_TEXT_CENTER); font_config, SDLPP_TEXT_CENTER);
global_test_text->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER); global_test_text->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER);
global_test_text->setPermanent(); global_test_text->setPermanent();
scene->addObject(global_test_text); scene->addObject(global_test_text);
global_vars.map.max_page = global_vars.objects.size() - MAP_WIDTH; global_vars.map.max_page = global_vars.objects.size() - MAP_WIDTH;
// arrowInputs[1] - rightMapInput, arrowInputs[0] - leftMapInput // arrowInputs[1] - rightMapInput, arrowInputs[0] - leftMapInput
toolMoveUpdateButtons(arrowInputs[1].other_button.get(), arrowInputs[0].other_button.get(), global_vars.map.cur_page, global_vars.map.max_page, true); toolMoveUpdateButtons(
arrowInputs[1].other_button.get(), arrowInputs[0].other_button.get(),
global_vars.map.cur_page, global_vars.map.max_page, true);
auto mouse = auto mouse =
std::make_shared<SDLPP::RectangleRender>(0.01, 0.01, 0, 0, renderer); std::make_shared<SDLPP::RectangleRender>(0.01, 0.01, 0, 0, renderer);
@ -1119,7 +1149,7 @@ void openMapEditor(std::shared_ptr<SDLPP::Scene> &scene, const std::string &file
updateToolSelection(0, ToolType::CHARACTER); updateToolSelection(0, ToolType::CHARACTER);
setToolColor(); setToolColor();
for(auto &button : global_vars.buttons) { for (auto &button : global_vars.buttons) {
scene->addObject(button); scene->addObject(button);
} }
@ -1129,7 +1159,8 @@ void openMapEditor(std::shared_ptr<SDLPP::Scene> &scene, const std::string &file
global_vars.tool.cur_page_characters = 0; global_vars.tool.cur_page_characters = 0;
} }
std::shared_ptr<SDLPP::Scene> createEditorMainScene(std::shared_ptr<SDLPP::Renderer> &renderer) { std::shared_ptr<SDLPP::Scene>
createEditorMainScene(std::shared_ptr<SDLPP::Renderer> &renderer) {
auto scene = std::make_shared<SDLPP::Scene>(renderer); auto scene = std::make_shared<SDLPP::Scene>(renderer);
global_vars.tool.max_page_tools = global_vars.tool.max_page_tools =
@ -1160,7 +1191,8 @@ std::shared_ptr<SDLPP::Scene> createEditorMainScene(std::shared_ptr<SDLPP::Rende
global_vars.buttons.emplace_back(std::make_shared<Button>( global_vars.buttons.emplace_back(std::make_shared<Button>(
0, 1 - MAP_HEIGHT * BLOCK_SIZE, BLOCK_SIZE, MAP_HEIGHT * BLOCK_SIZE, 0, 1 - MAP_HEIGHT * BLOCK_SIZE, BLOCK_SIZE, MAP_HEIGHT * BLOCK_SIZE,
renderer, "<", default_button_theme, moveMapLeft, &left_map_input)); renderer, "<", default_button_theme, moveMapLeft, &left_map_input));
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER); global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER,
SDLPP::OBJ_CENTER);
global_vars.buttons.back()->setPermanent(); global_vars.buttons.back()->setPermanent();
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1); global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
// right map arrow // right map arrow
@ -1168,23 +1200,29 @@ std::shared_ptr<SDLPP::Scene> createEditorMainScene(std::shared_ptr<SDLPP::Rende
right_map_input.scene = scene; right_map_input.scene = scene;
right_map_input.other_button = global_vars.buttons.back(); right_map_input.other_button = global_vars.buttons.back();
global_vars.buttons.emplace_back(std::make_shared<Button>( global_vars.buttons.emplace_back(std::make_shared<Button>(
(MAP_WIDTH + 1) * BLOCK_SIZE, 1 - MAP_HEIGHT * BLOCK_SIZE, BLOCK_SIZE, MAP_HEIGHT * BLOCK_SIZE, (MAP_WIDTH + 1) * BLOCK_SIZE, 1 - MAP_HEIGHT * BLOCK_SIZE, BLOCK_SIZE,
renderer, ">", default_button_theme, moveMapRight, &right_map_input)); MAP_HEIGHT * BLOCK_SIZE, renderer, ">", default_button_theme,
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER); moveMapRight, &right_map_input));
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER,
SDLPP::OBJ_CENTER);
global_vars.buttons.back()->setPermanent(); global_vars.buttons.back()->setPermanent();
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1); global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
left_map_input.other_button = global_vars.buttons.back(); left_map_input.other_button = global_vars.buttons.back();
// ensure disabled/enabled properly // ensure disabled/enabled properly
toolMoveUpdateButtons(right_map_input.other_button.get(), global_vars.buttons.back().get(), global_vars.map.cur_page, global_vars.map.max_page, true); toolMoveUpdateButtons(
right_map_input.other_button.get(), global_vars.buttons.back().get(),
global_vars.map.cur_page, global_vars.map.max_page, true);
// left tool arrow // left tool arrow
auto &left_tool_input = arrowInputs[2]; auto &left_tool_input = arrowInputs[2];
left_tool_input.scene = scene; left_tool_input.scene = scene;
left_tool_input.other_button = nullptr; left_tool_input.other_button = nullptr;
global_vars.buttons.emplace_back(std::make_shared<Button>( global_vars.buttons.emplace_back(std::make_shared<Button>(
(MAP_WIDTH - TOOLS_WIDTH - 1) * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE, (MAP_WIDTH - TOOLS_WIDTH - 1) * BLOCK_SIZE,
renderer, "<", default_button_theme, moveToolsLeftButton, &left_tool_input)); 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE, renderer,
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER); "<", default_button_theme, moveToolsLeftButton, &left_tool_input));
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER,
SDLPP::OBJ_CENTER);
global_vars.buttons.back()->setPermanent(); global_vars.buttons.back()->setPermanent();
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1); global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
global_vars.tool.button_left_tools = global_vars.buttons.back(); global_vars.tool.button_left_tools = global_vars.buttons.back();
@ -1193,24 +1231,31 @@ std::shared_ptr<SDLPP::Scene> createEditorMainScene(std::shared_ptr<SDLPP::Rende
right_tool_input.scene = scene; right_tool_input.scene = scene;
right_tool_input.other_button = global_vars.buttons.back(); right_tool_input.other_button = global_vars.buttons.back();
global_vars.buttons.emplace_back(std::make_shared<Button>( global_vars.buttons.emplace_back(std::make_shared<Button>(
MAP_WIDTH * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE, MAP_WIDTH * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, BLOCK_SIZE,
renderer, ">", default_button_theme, moveToolsRightButton, &right_tool_input)); 2 * BLOCK_SIZE, renderer, ">", default_button_theme,
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER); moveToolsRightButton, &right_tool_input));
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER,
SDLPP::OBJ_CENTER);
global_vars.buttons.back()->setPermanent(); global_vars.buttons.back()->setPermanent();
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1); global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
left_tool_input.other_button = global_vars.buttons.back(); left_tool_input.other_button = global_vars.buttons.back();
global_vars.tool.button_right_tools = global_vars.buttons.back(); global_vars.tool.button_right_tools = global_vars.buttons.back();
// ensure disabled/enabled properly // ensure disabled/enabled properly
toolMoveUpdateButtons(right_tool_input.other_button.get(), global_vars.buttons.back().get(), global_vars.tool.cur_page_tools, global_vars.tool.max_page_tools, false); toolMoveUpdateButtons(right_tool_input.other_button.get(),
global_vars.buttons.back().get(),
global_vars.tool.cur_page_tools,
global_vars.tool.max_page_tools, false);
// left mod arrow // left mod arrow
auto &left_mod_input = arrowInputs[4]; auto &left_mod_input = arrowInputs[4];
left_mod_input.scene = scene; left_mod_input.scene = scene;
left_mod_input.other_button = nullptr; left_mod_input.other_button = nullptr;
global_vars.buttons.emplace_back(std::make_shared<Button>( global_vars.buttons.emplace_back(std::make_shared<Button>(
4 * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE, 4 * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, BLOCK_SIZE,
renderer, "<", default_button_theme, moveModsLeft, &left_mod_input)); 2 * BLOCK_SIZE, renderer, "<", default_button_theme, moveModsLeft,
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER); &left_mod_input));
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER,
SDLPP::OBJ_CENTER);
global_vars.buttons.back()->setPermanent(); global_vars.buttons.back()->setPermanent();
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1); global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
global_vars.tool.button_left_mods = global_vars.buttons.back(); global_vars.tool.button_left_mods = global_vars.buttons.back();
@ -1219,24 +1264,30 @@ std::shared_ptr<SDLPP::Scene> createEditorMainScene(std::shared_ptr<SDLPP::Rende
right_mod_input.scene = scene; right_mod_input.scene = scene;
right_mod_input.other_button = global_vars.buttons.back(); right_mod_input.other_button = global_vars.buttons.back();
global_vars.buttons.emplace_back(std::make_shared<Button>( global_vars.buttons.emplace_back(std::make_shared<Button>(
(MOD_WIDTH + 5) * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE, (MOD_WIDTH + 5) * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE,
renderer, ">", default_button_theme, moveModsRight, &right_mod_input)); BLOCK_SIZE, 2 * BLOCK_SIZE, renderer, ">", default_button_theme,
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER); moveModsRight, &right_mod_input));
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER,
SDLPP::OBJ_CENTER);
global_vars.buttons.back()->setPermanent(); global_vars.buttons.back()->setPermanent();
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1); global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
left_mod_input.other_button = global_vars.buttons.back(); left_mod_input.other_button = global_vars.buttons.back();
global_vars.tool.button_right_mods = global_vars.buttons.back(); global_vars.tool.button_right_mods = global_vars.buttons.back();
// ensure disabled/enabled properly // ensure disabled/enabled properly
toolMoveUpdateButtons(right_mod_input.other_button.get(), global_vars.buttons.back().get(), global_vars.tool.cur_page_mods, global_vars.tool.max_page_mods, false); toolMoveUpdateButtons(
right_mod_input.other_button.get(), global_vars.buttons.back().get(),
global_vars.tool.cur_page_mods, global_vars.tool.max_page_mods, false);
// left character arrow // left character arrow
auto &left_character_input = arrowInputs[6]; auto &left_character_input = arrowInputs[6];
left_character_input.scene = scene; left_character_input.scene = scene;
left_character_input.other_button = nullptr; left_character_input.other_button = nullptr;
global_vars.buttons.emplace_back(std::make_shared<Button>( global_vars.buttons.emplace_back(std::make_shared<Button>(
(MOD_WIDTH + 7) * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE, (MOD_WIDTH + 7) * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE,
renderer, "<", default_button_theme, moveCharsLeft, &left_character_input)); BLOCK_SIZE, 2 * BLOCK_SIZE, renderer, "<", default_button_theme,
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER); moveCharsLeft, &left_character_input));
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER,
SDLPP::OBJ_CENTER);
global_vars.buttons.back()->setPermanent(); global_vars.buttons.back()->setPermanent();
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1); global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
global_vars.tool.button_left_characters = global_vars.buttons.back(); global_vars.tool.button_left_characters = global_vars.buttons.back();
@ -1245,17 +1296,24 @@ std::shared_ptr<SDLPP::Scene> createEditorMainScene(std::shared_ptr<SDLPP::Rende
right_character_input.scene = scene; right_character_input.scene = scene;
right_character_input.other_button = global_vars.buttons.back(); right_character_input.other_button = global_vars.buttons.back();
global_vars.buttons.emplace_back(std::make_shared<Button>( global_vars.buttons.emplace_back(std::make_shared<Button>(
(MOD_WIDTH + 8 + CHARACTER_WIDTH) * BLOCK_SIZE, 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE, (MOD_WIDTH + 8 + CHARACTER_WIDTH) * BLOCK_SIZE,
renderer, ">", default_button_theme, moveCharsRight, &right_character_input)); 1 - (MAP_HEIGHT + 3) * BLOCK_SIZE, BLOCK_SIZE, 2 * BLOCK_SIZE, renderer,
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER); ">", default_button_theme, moveCharsRight, &right_character_input));
global_vars.buttons.back()->setAlignment(SDLPP::OBJ_CENTER,
SDLPP::OBJ_CENTER);
global_vars.buttons.back()->setPermanent(); global_vars.buttons.back()->setPermanent();
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1); global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
global_vars.tool.button_right_characters = global_vars.buttons.back(); global_vars.tool.button_right_characters = global_vars.buttons.back();
// ensure disabled/enabled properly // ensure disabled/enabled properly
toolMoveUpdateButtons(right_character_input.other_button.get(), global_vars.buttons.back().get(), global_vars.tool.cur_page_characters, global_vars.tool.max_page_characters, false); toolMoveUpdateButtons(right_character_input.other_button.get(),
global_vars.buttons.back().get(),
global_vars.tool.cur_page_characters,
global_vars.tool.max_page_characters, false);
left_character_input.other_button = global_vars.buttons.back(); left_character_input.other_button = global_vars.buttons.back();
global_vars.buttons.emplace_back(std::make_shared<Button>(0, 0, 0.2, 0.2, renderer, "Write Button", default_button_theme, testButtonFunc, nullptr)); global_vars.buttons.emplace_back(std::make_shared<Button>(
0, 0, 0.2, 0.2, renderer, "Write Button", default_button_theme,
testButtonFunc, nullptr));
global_vars.buttons.back()->setPermanent(); global_vars.buttons.back()->setPermanent();
global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1); global_vars.buttons.back()->setButtonIndex(global_vars.buttons.size() - 1);
@ -1266,7 +1324,7 @@ std::shared_ptr<SDLPP::Scene> createEditorMainScene(std::shared_ptr<SDLPP::Rende
void editorAdditionalRender(std::shared_ptr<SDLPP::Scene> &scene) { void editorAdditionalRender(std::shared_ptr<SDLPP::Scene> &scene) {
g_quit = getFlag(QUIT_FLAG); g_quit = getFlag(QUIT_FLAG);
for(auto &button : global_vars.buttons) { for (auto &button : global_vars.buttons) {
button->update(); button->update();
} }
if (getFlag(UPDATE_FLAG)) { if (getFlag(UPDATE_FLAG)) {
@ -1294,6 +1352,6 @@ SceneStruct createEditorScene(std::shared_ptr<SDLPP::Renderer> &renderer) {
editorScene = ret.scene; editorScene = ret.scene;
mainMenuScene = createEditorMainMenuScene(renderer); mainMenuScene = createEditorMainMenuScene(renderer);
// fileChoiceScene = createEditorFileChoiceScene(renderer); // fileChoiceScene = createEditorFileChoiceScene(renderer);
return ret; return ret;
} }

View File

@ -21,11 +21,11 @@ void resumeMainMenu() {
__quit_scenes_main_menu = true; __quit_scenes_main_menu = true;
} }
void quitMainMenuCallback(void */*UNUSED*/, Button */*UNUSED*/) { void quitMainMenuCallback(void * /*UNUSED*/, Button * /*UNUSED*/) {
quitMainMenu(); quitMainMenu();
} }
void resumeMainMenuCallback(void */*UNUSED*/, Button */*UNUSED*/) { void resumeMainMenuCallback(void * /*UNUSED*/, Button * /*UNUSED*/) {
resumeMainMenu(); resumeMainMenu();
} }
@ -35,12 +35,12 @@ void resetGlobals() {
__cur_button_index_main_menu = -1; __cur_button_index_main_menu = -1;
__cur_button_index_main_menu_down = -1; __cur_button_index_main_menu_down = -1;
__mouse_main_menu->setPos(0, 0); __mouse_main_menu->setPos(0, 0);
for(auto &button : __buttons_main_menu) { for (auto &button : __buttons_main_menu) {
button->unsetHighlight(); button->unsetHighlight();
} }
} }
void handleKeyUpMainMenu(SDL_Keycode key, SDLPP::Scene &/*UNUSED*/) { void handleKeyUpMainMenu(SDL_Keycode key, SDLPP::Scene & /*UNUSED*/) {
switch (key) { switch (key) {
case SDLK_ESCAPE: case SDLK_ESCAPE:
resumeMainMenu(); resumeMainMenu();
@ -50,10 +50,11 @@ void handleKeyUpMainMenu(SDL_Keycode key, SDLPP::Scene &/*UNUSED*/) {
} }
} }
std::shared_ptr<SDLPP::Scene> createSceneMainMenu(std::shared_ptr<SDLPP::Renderer> &renderer) { std::shared_ptr<SDLPP::Scene>
createSceneMainMenu(std::shared_ptr<SDLPP::Renderer> &renderer) {
auto scene = std::make_shared<SDLPP::Scene>(renderer); auto scene = std::make_shared<SDLPP::Scene>(renderer);
auto bg = std::make_shared<SDLPP::RectangleRender>( auto bg = std::make_shared<SDLPP::RectangleRender>(0, 0, 10, 10, renderer,
0, 0, 10, 10, renderer, "#00000088", true); "#00000088", true);
bg->setPermanent(); bg->setPermanent();
bg->setId(1); bg->setId(1);
scene->addObject(bg); scene->addObject(bg);
@ -80,38 +81,42 @@ std::shared_ptr<SDLPP::Scene> createSceneMainMenu(std::shared_ptr<SDLPP::Rendere
default_button_theme.outline = 0.1; default_button_theme.outline = 0.1;
// buttons // buttons
__buttons_main_menu.emplace_back(std::make_shared<Button>( __buttons_main_menu.emplace_back(std::make_shared<Button>(
0.2, 0.25, 0.6, 0.1, 0.2, 0.25, 0.6, 0.1, renderer, "SAVE", default_button_theme,
renderer, "SAVE", default_button_theme, saveMapCallback, nullptr)); saveMapCallback, nullptr));
__buttons_main_menu.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER); __buttons_main_menu.back()->setAlignment(SDLPP::OBJ_CENTER,
SDLPP::OBJ_CENTER);
__buttons_main_menu.back()->setPermanent(); __buttons_main_menu.back()->setPermanent();
__buttons_main_menu.back()->setButtonIndex(__buttons_main_menu.size() - 1); __buttons_main_menu.back()->setButtonIndex(__buttons_main_menu.size() - 1);
__buttons_main_menu.emplace_back(std::make_shared<Button>( __buttons_main_menu.emplace_back(std::make_shared<Button>(
0.2, 0.4, 0.6, 0.1, 0.2, 0.4, 0.6, 0.1, renderer, "LOAD", default_button_theme,
renderer, "LOAD", default_button_theme, loadMapDialogCallback, nullptr)); loadMapDialogCallback, nullptr));
__buttons_main_menu.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER); __buttons_main_menu.back()->setAlignment(SDLPP::OBJ_CENTER,
SDLPP::OBJ_CENTER);
__buttons_main_menu.back()->setPermanent(); __buttons_main_menu.back()->setPermanent();
__buttons_main_menu.back()->setButtonIndex(__buttons_main_menu.size() - 1); __buttons_main_menu.back()->setButtonIndex(__buttons_main_menu.size() - 1);
__buttons_main_menu.emplace_back(std::make_shared<Button>( __buttons_main_menu.emplace_back(std::make_shared<Button>(
0.2, 0.55, 0.6, 0.1, 0.2, 0.55, 0.6, 0.1, renderer, "RESUME", default_button_theme,
renderer, "RESUME", default_button_theme, resumeMainMenuCallback, nullptr)); resumeMainMenuCallback, nullptr));
__buttons_main_menu.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER); __buttons_main_menu.back()->setAlignment(SDLPP::OBJ_CENTER,
SDLPP::OBJ_CENTER);
__buttons_main_menu.back()->setPermanent(); __buttons_main_menu.back()->setPermanent();
__buttons_main_menu.back()->setButtonIndex(__buttons_main_menu.size() - 1); __buttons_main_menu.back()->setButtonIndex(__buttons_main_menu.size() - 1);
__buttons_main_menu.emplace_back(std::make_shared<Button>( __buttons_main_menu.emplace_back(std::make_shared<Button>(
0.2, 0.7, 0.6, 0.1, 0.2, 0.7, 0.6, 0.1, renderer, "QUIT", default_button_theme,
renderer, "QUIT", default_button_theme, quitMainMenuCallback, nullptr)); quitMainMenuCallback, nullptr));
__buttons_main_menu.back()->setAlignment(SDLPP::OBJ_CENTER, SDLPP::OBJ_CENTER); __buttons_main_menu.back()->setAlignment(SDLPP::OBJ_CENTER,
SDLPP::OBJ_CENTER);
__buttons_main_menu.back()->setPermanent(); __buttons_main_menu.back()->setPermanent();
__buttons_main_menu.back()->setButtonIndex(__buttons_main_menu.size() - 1); __buttons_main_menu.back()->setButtonIndex(__buttons_main_menu.size() - 1);
for(auto &button : __buttons_main_menu) { for (auto &button : __buttons_main_menu) {
scene->addObject(button); scene->addObject(button);
} }
return scene; return scene;
} }
void additionalRenderMainMenu(std::shared_ptr<SDLPP::Scene> &/*UNUSED*/) { void additionalRenderMainMenu(std::shared_ptr<SDLPP::Scene> & /*UNUSED*/) {
if (__update_scenes_main_menu) { if (__update_scenes_main_menu) {
for(auto &_scene : game_scenes) { for (auto &_scene : game_scenes) {
_scene.scene->updateSizeAndPosition(); _scene.scene->updateSizeAndPosition();
} }
if (__started_main_menu) { if (__started_main_menu) {
@ -134,11 +139,11 @@ void getMousePositionFlagsMainMenu(SDLPP::Scene &scene) {
MouseVisitor visitor; MouseVisitor visitor;
scene.visitCollisions(*mouse, visitor); scene.visitCollisions(*mouse, visitor);
if(visitor.getCurButton() != __cur_button_index_main_menu) { if (visitor.getCurButton() != __cur_button_index_main_menu) {
if(__cur_button_index_main_menu != (uint64_t)-1) { if (__cur_button_index_main_menu != (uint64_t)-1) {
__buttons_main_menu[__cur_button_index_main_menu]->unsetHighlight(); __buttons_main_menu[__cur_button_index_main_menu]->unsetHighlight();
} }
if(visitor.getCurButton() != (uint64_t)-1) { if (visitor.getCurButton() != (uint64_t)-1) {
__buttons_main_menu[visitor.getCurButton()]->setHighlight(); __buttons_main_menu[visitor.getCurButton()]->setHighlight();
} }
} }
@ -164,9 +169,11 @@ void pollEventsMainMenu(std::shared_ptr<SDLPP::Scene> &scene) {
getMousePositionFlagsMainMenu(*scene); getMousePositionFlagsMainMenu(*scene);
break; break;
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
if (__cur_button_index_main_menu_down == __cur_button_index_main_menu && if (__cur_button_index_main_menu_down ==
__cur_button_index_main_menu &&
__cur_button_index_main_menu != (uint64_t)-1) { __cur_button_index_main_menu != (uint64_t)-1) {
__buttons_main_menu[__cur_button_index_main_menu]->performFunction(); __buttons_main_menu[__cur_button_index_main_menu]
->performFunction();
} }
break; break;
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
@ -179,7 +186,8 @@ void pollEventsMainMenu(std::shared_ptr<SDLPP::Scene> &scene) {
} }
} }
SceneStruct createEditorMainMenuScene(std::shared_ptr<SDLPP::Renderer> &renderer) { SceneStruct
createEditorMainMenuScene(std::shared_ptr<SDLPP::Renderer> &renderer) {
SceneStruct ret{}; SceneStruct ret{};
ret.scene = createSceneMainMenu(renderer); ret.scene = createSceneMainMenu(renderer);
ret.additionalRender = additionalRenderMainMenu; ret.additionalRender = additionalRenderMainMenu;

View File

@ -7,8 +7,8 @@
struct SceneStruct { struct SceneStruct {
std::shared_ptr<SDLPP::Scene> scene; std::shared_ptr<SDLPP::Scene> scene;
std::function<void(std::shared_ptr<SDLPP::Scene>&)> doInput; std::function<void(std::shared_ptr<SDLPP::Scene> &)> doInput;
std::function<void(std::shared_ptr<SDLPP::Scene>&)> additionalRender; std::function<void(std::shared_ptr<SDLPP::Scene> &)> additionalRender;
}; };
extern std::mutex render_mutex; extern std::mutex render_mutex;
@ -18,7 +18,9 @@ void saveMapCallback(void *input, Button *caller);
void loadMapDialogCallback(void *input, Button *caller); void loadMapDialogCallback(void *input, Button *caller);
SceneStruct createEditorScene(std::shared_ptr<SDLPP::Renderer> &renderer); SceneStruct createEditorScene(std::shared_ptr<SDLPP::Renderer> &renderer);
SceneStruct createEditorMainMenuScene(std::shared_ptr<SDLPP::Renderer> &renderer); SceneStruct
SceneStruct createEditorFileChoiceScene(std::shared_ptr<SDLPP::Renderer> &renderer); createEditorMainMenuScene(std::shared_ptr<SDLPP::Renderer> &renderer);
SceneStruct
createEditorFileChoiceScene(std::shared_ptr<SDLPP::Renderer> &renderer);
#endif #endif