Modificats, estructurats i ben formatats alguns missatges de consola

Canvis en els codis d'eixida del programa
This commit is contained in:
2024-10-20 11:37:26 +02:00
parent a4b4e188cd
commit 8bca5095da
12 changed files with 36 additions and 25 deletions

View File

@@ -1,12 +1,12 @@
#include "define_buttons.h" #include "define_buttons.h"
#include <utility> // for move #include <utility> // for move
#include "input.h" // for Input, InputType #include "input.h" // for Input, InputType
#include "lang.h" // for getText #include "lang.h" // for getText
#include "options.h" // for options #include "options.h" // for options
#include "param.h" // for param #include "param.h" // for param
#include "section.h" // for Name, Options, name, options #include "section.h" // for Name, Options, name, options
#include "text.h" // for Text #include "text.h" // for Text
#include "utils.h" // for OptionsController, Options, Param, ParamGame #include "utils.h" // for OptionsController, Options, Param, ParamGame
// Constructor // Constructor
DefineButtons::DefineButtons(std::unique_ptr<Text> text_) DefineButtons::DefineButtons(std::unique_ptr<Text> text_)
@@ -106,7 +106,7 @@ void DefineButtons::checkInput()
case SDL_QUIT: case SDL_QUIT:
{ {
section::name = section::Name::QUIT; section::name = section::Name::QUIT;
section::options = section::Options::QUIT_NORMAL; section::options = section::Options::QUIT_WITH_KEYBOARD;
break; break;
} }
@@ -157,7 +157,7 @@ void DefineButtons::incIndexButton()
// Guarda los cambios en las opciones // Guarda los cambios en las opciones
saveBindingsToOptions(); saveBindingsToOptions();
//input_->allActive(index_controller_); // input_->allActive(index_controller_);
// Reinicia variables // Reinicia variables
index_button_ = 0; index_button_ = 0;

View File

@@ -134,6 +134,8 @@ Director::~Director()
SDL_DestroyWindow(window_); SDL_DestroyWindow(window_);
SDL_Quit(); SDL_Quit();
std::cout << "\nBye!" << std::endl;
} }
// Asigna los botones y teclas al objeto Input // Asigna los botones y teclas al objeto Input
@@ -658,19 +660,20 @@ int Director::run()
#ifdef ARCADE #ifdef ARCADE
// Comprueba si ha de apagar el sistema // Comprueba si ha de apagar el sistema
if (section::options == section::Options::QUIT_SHUTDOWN) if (section::options == section::Options::QUIT_WITH_CONTROLLER)
shutdownSystem(); shutdownSystem();
#endif #endif
const auto return_code = (section::options == section::Options::QUIT_NORMAL) ? "keyboard" : "controller"; const auto return_code = (section::options == section::Options::QUIT_WITH_KEYBOARD) ? "with keyboard" : (section::options == section::Options::QUIT_WITH_CONTROLLER) ? "with controller"
std::cout << "\nGame end with " << return_code << std::endl; : "from event";
std::cout << "\nGame end " << return_code << std::endl;
#ifndef VERBOSE #ifndef VERBOSE
// Habilita de nuevo los std::cout // Habilita de nuevo los std::cout
std::cout.rdbuf(orig_buf); std::cout.rdbuf(orig_buf);
#endif #endif
return (return_code == std::string("keyboard")) ? 0 : 1; return (section::options == section::Options::QUIT_WITH_CONTROLLER) ? 1 : 0;
} }
// Obtiene una fichero a partir de un lang::Code // Obtiene una fichero a partir de un lang::Code

View File

@@ -1970,6 +1970,7 @@ void Game::checkEvents()
if (event.type == SDL_QUIT) if (event.type == SDL_QUIT)
{ {
section::name = section::Name::QUIT; section::name = section::Name::QUIT;
section::options = section::Options::QUIT_FROM_EVENT;
break; break;
} }

View File

@@ -69,7 +69,7 @@ namespace globalInputs
// Comprueba si se sale con el teclado // Comprueba si se sale con el teclado
if (Input::get()->checkInput(InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD)) if (Input::get()->checkInput(InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_KEYBOARD))
{ {
quit(section::Options::QUIT_NORMAL); quit(section::Options::QUIT_WITH_KEYBOARD);
return; return;
} }
@@ -107,7 +107,7 @@ namespace globalInputs
// Comprueba si se sale con el mando // Comprueba si se sale con el mando
if (Input::get()->checkModInput(InputType::SERVICE, InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i)) if (Input::get()->checkModInput(InputType::SERVICE, InputType::EXIT, INPUT_DO_NOT_ALLOW_REPEAT, INPUT_USE_GAMECONTROLLER, i))
{ {
quit(section::Options::QUIT_SHUTDOWN); quit(section::Options::QUIT_WITH_CONTROLLER);
return; return;
} }

View File

@@ -188,6 +188,7 @@ void HiScoreTable::checkEvents()
if (event.type == SDL_QUIT) if (event.type == SDL_QUIT)
{ {
section::name = section::Name::QUIT; section::name = section::Name::QUIT;
section::options = section::Options::QUIT_FROM_EVENT;
break; break;
} }

View File

@@ -416,10 +416,9 @@ bool Input::discoverGameControllers()
} }
} }
{ std::cout << "\n** LOOKING FOR GAME CONTROLLERS" << std::endl;
std::cout << "\nChecking for game controllers...\n"; // std::cout << " " << num_joysticks_ << " joysticks found" << std::endl;
std::cout << num_joysticks_ << " joysticks found, " << num_gamepads_ << " are gamepads\n"; std::cout << "Gamepads found: " << num_gamepads_ << std::endl;
}
if (num_gamepads_ > 0) if (num_gamepads_ > 0)
{ {
@@ -434,7 +433,7 @@ bool Input::discoverGameControllers()
connected_controllers_.push_back(pad); connected_controllers_.push_back(pad);
const std::string name = SDL_GameControllerNameForIndex(i); const std::string name = SDL_GameControllerNameForIndex(i);
{ {
std::cout << name << std::endl; std::cout << "#" << i << ": " << name << std::endl;
} }
controller_names_.push_back(name); controller_names_.push_back(name);
} }
@@ -449,6 +448,8 @@ bool Input::discoverGameControllers()
SDL_GameControllerEventState(SDL_ENABLE); SDL_GameControllerEventState(SDL_ENABLE);
} }
std::cout << "\n** FINISHED LOOKING FOR GAME CONTROLLERS" << std::endl;
return found; return found;
} }

View File

@@ -297,6 +297,7 @@ void Instructions::checkEvents()
if (event.type == SDL_QUIT) if (event.type == SDL_QUIT)
{ {
section::name = section::Name::QUIT; section::name = section::Name::QUIT;
section::options = section::Options::QUIT_FROM_EVENT;
break; break;
} }

View File

@@ -170,6 +170,7 @@ void Intro::checkEvents()
case SDL_QUIT: case SDL_QUIT:
{ {
section::name = section::Name::QUIT; section::name = section::Name::QUIT;
section::options = section::Options::QUIT_FROM_EVENT;
break; break;
} }

View File

@@ -73,6 +73,7 @@ void Logo::checkEvents()
if (event.type == SDL_QUIT) if (event.type == SDL_QUIT)
{ {
section::name = section::Name::QUIT; section::name = section::Name::QUIT;
section::options = section::Options::QUIT_FROM_EVENT;
break; break;
} }

View File

@@ -23,9 +23,10 @@ namespace section
GAME_PLAY_2P = 1, GAME_PLAY_2P = 1,
TITLE_1 = 2, TITLE_1 = 2,
TITLE_2 = 3, TITLE_2 = 3,
QUIT_NORMAL = 4, QUIT_WITH_KEYBOARD = 4,
QUIT_SHUTDOWN = 5, QUIT_WITH_CONTROLLER = 5,
NONE = 6, QUIT_FROM_EVENT = 6,
NONE = 7,
}; };
extern Name name; extern Name name;

View File

@@ -188,6 +188,7 @@ void Title::checkEvents()
if (event.type == SDL_QUIT) if (event.type == SDL_QUIT)
{ {
section::name = section::Name::QUIT; section::name = section::Name::QUIT;
section::options = section::Options::QUIT_FROM_EVENT;
break; break;
} }

View File

@@ -197,7 +197,7 @@ void printWithDots(const std::string &text1, const std::string &text2, const std
std::cout.setf(std::ios::left, std::ios::adjustfield); std::cout.setf(std::ios::left, std::ios::adjustfield);
std::cout << text1; std::cout << text1;
std::cout.width(70 - text1.length() - text3.length()); std::cout.width(50 - text1.length() - text3.length());
std::cout.fill('.'); std::cout.fill('.');
std::cout << text2; std::cout << text2;