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

View File

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

View File

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

View File

@@ -69,7 +69,7 @@ namespace globalInputs
// Comprueba si se sale con el teclado
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;
}
@@ -107,7 +107,7 @@ namespace globalInputs
// Comprueba si se sale con el mando
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;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -188,6 +188,7 @@ void Title::checkEvents()
if (event.type == SDL_QUIT)
{
section::name = section::Name::QUIT;
section::options = section::Options::QUIT_FROM_EVENT;
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 << text1;
std::cout.width(70 - text1.length() - text3.length());
std::cout.width(50 - text1.length() - text3.length());
std::cout.fill('.');
std::cout << text2;