pasaeta loca de clang-format (despres m'arrepentiré pero bueno)
This commit is contained in:
@@ -1,34 +1,30 @@
|
||||
#include "define_buttons.h"
|
||||
|
||||
#include "input.h" // Para Input, InputAction
|
||||
#include "lang.h" // Para getText
|
||||
#include "options.h" // Para OptionsController, Options, options
|
||||
#include "param.h" // Para Param, param, ParamGame, ParamTitle
|
||||
#include "resource.h" // Para Resource
|
||||
#include "text.h" // Para Text
|
||||
#include "input.h" // Para Input, InputAction
|
||||
#include "lang.h" // Para getText
|
||||
#include "options.h" // Para OptionsController, Options, options
|
||||
#include "param.h" // Para Param, param, ParamGame, ParamTitle
|
||||
#include "resource.h" // Para Resource
|
||||
#include "text.h" // Para Text
|
||||
|
||||
// Constructor
|
||||
DefineButtons::DefineButtons()
|
||||
: input_(Input::get()),
|
||||
text_(Resource::get()->getText("8bithud"))
|
||||
{
|
||||
text_(Resource::get()->getText("8bithud")) {
|
||||
// Inicializa variables
|
||||
x_ = param.game.width / 2;
|
||||
y_ = param.title.press_start_position;
|
||||
|
||||
clearButtons();
|
||||
|
||||
for (int i = 0; i < input_->getNumControllers(); ++i)
|
||||
{
|
||||
for (int i = 0; i < input_->getNumControllers(); ++i) {
|
||||
controller_names_.emplace_back(input_->getControllerName(i));
|
||||
}
|
||||
}
|
||||
|
||||
// Dibuja el objeto en pantalla
|
||||
void DefineButtons::render()
|
||||
{
|
||||
if (enabled_)
|
||||
{
|
||||
void DefineButtons::render() {
|
||||
if (enabled_) {
|
||||
text_->writeCentered(x_, y_ - 10, Lang::getText("[DEFINE_BUTTONS] PLAYER") + std::to_string(Options::controllers.at(index_controller_).player_id));
|
||||
text_->writeCentered(x_, y_, controller_names_.at(index_controller_));
|
||||
text_->writeCentered(x_, y_ + 10, buttons_.at(index_button_).label);
|
||||
@@ -36,27 +32,22 @@ void DefineButtons::render()
|
||||
}
|
||||
|
||||
// Comprueba el botón que se ha pulsado
|
||||
void DefineButtons::doControllerButtonDown(const SDL_GamepadButtonEvent &event)
|
||||
{
|
||||
void DefineButtons::doControllerButtonDown(const SDL_GamepadButtonEvent &event) {
|
||||
// Solo pilla botones del mando que toca
|
||||
if (input_->getJoyIndex(event.which) != static_cast<int>(index_controller_))
|
||||
{
|
||||
if (input_->getJoyIndex(event.which) != static_cast<int>(index_controller_)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto button = static_cast<SDL_GamepadButton>(event.button);
|
||||
if (checkButtonNotInUse(button))
|
||||
{
|
||||
if (checkButtonNotInUse(button)) {
|
||||
buttons_.at(index_button_).button = button;
|
||||
incIndexButton();
|
||||
}
|
||||
}
|
||||
|
||||
// Asigna los botones definidos al input_
|
||||
void DefineButtons::bindButtons()
|
||||
{
|
||||
for (const auto &button : buttons_)
|
||||
{
|
||||
void DefineButtons::bindButtons() {
|
||||
for (const auto &button : buttons_) {
|
||||
input_->bindGameControllerButton(index_controller_, button.input, button.button);
|
||||
}
|
||||
|
||||
@@ -66,29 +57,24 @@ void DefineButtons::bindButtons()
|
||||
}
|
||||
|
||||
// Comprueba los eventos
|
||||
void DefineButtons::checkEvents(const SDL_Event &event)
|
||||
{
|
||||
if (enabled_)
|
||||
{
|
||||
switch (event.type)
|
||||
{
|
||||
case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
|
||||
doControllerButtonDown(event.gbutton);
|
||||
break;
|
||||
case SDL_EVENT_GAMEPAD_BUTTON_UP:
|
||||
checkEnd();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
void DefineButtons::checkEvents(const SDL_Event &event) {
|
||||
if (enabled_) {
|
||||
switch (event.type) {
|
||||
case SDL_EVENT_GAMEPAD_BUTTON_DOWN:
|
||||
doControllerButtonDown(event.gbutton);
|
||||
break;
|
||||
case SDL_EVENT_GAMEPAD_BUTTON_UP:
|
||||
checkEnd();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Habilita el objeto
|
||||
bool DefineButtons::enable(int index)
|
||||
{
|
||||
if (index < input_->getNumControllers())
|
||||
{
|
||||
bool DefineButtons::enable(int index) {
|
||||
if (index < input_->getNumControllers()) {
|
||||
enabled_ = true;
|
||||
finished_ = false;
|
||||
index_controller_ = index;
|
||||
@@ -104,37 +90,28 @@ bool DefineButtons::enable(int index)
|
||||
bool DefineButtons::isEnabled() const { return enabled_; }
|
||||
|
||||
// Incrementa el indice de los botones
|
||||
void DefineButtons::incIndexButton()
|
||||
{
|
||||
if (index_button_ < buttons_.size() - 1)
|
||||
{
|
||||
void DefineButtons::incIndexButton() {
|
||||
if (index_button_ < buttons_.size() - 1) {
|
||||
++index_button_;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
finished_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Guarda los cambios en las opciones
|
||||
void DefineButtons::saveBindingsToOptions()
|
||||
{
|
||||
void DefineButtons::saveBindingsToOptions() {
|
||||
// Modifica las opciones para colocar los valores asignados
|
||||
auto &controller = Options::controllers.at(index_controller_);
|
||||
controller.name = input_->getControllerName(index_controller_);
|
||||
for (size_t j = 0; j < controller.inputs.size(); ++j)
|
||||
{
|
||||
for (size_t j = 0; j < controller.inputs.size(); ++j) {
|
||||
controller.buttons.at(j) = input_->getControllerBinding(index_controller_, controller.inputs.at(j));
|
||||
}
|
||||
}
|
||||
|
||||
// Comprueba que un botón no esté ya asignado
|
||||
bool DefineButtons::checkButtonNotInUse(SDL_GamepadButton button)
|
||||
{
|
||||
for (const auto &b : buttons_)
|
||||
{
|
||||
if (b.button == button)
|
||||
{
|
||||
bool DefineButtons::checkButtonNotInUse(SDL_GamepadButton button) {
|
||||
for (const auto &b : buttons_) {
|
||||
if (b.button == button) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -142,8 +119,7 @@ bool DefineButtons::checkButtonNotInUse(SDL_GamepadButton button)
|
||||
}
|
||||
|
||||
// Limpia la asignación de botones
|
||||
void DefineButtons::clearButtons()
|
||||
{
|
||||
void DefineButtons::clearButtons() {
|
||||
buttons_.clear();
|
||||
buttons_.emplace_back(Lang::getText("[DEFINE_BUTTONS] FIRE_LEFT"), InputAction::FIRE_LEFT, SDL_GAMEPAD_BUTTON_INVALID);
|
||||
buttons_.emplace_back(Lang::getText("[DEFINE_BUTTONS] FIRE_UP"), InputAction::FIRE_CENTER, SDL_GAMEPAD_BUTTON_INVALID);
|
||||
@@ -153,11 +129,9 @@ void DefineButtons::clearButtons()
|
||||
}
|
||||
|
||||
// Comprueba si ha finalizado
|
||||
void DefineButtons::checkEnd()
|
||||
{
|
||||
void DefineButtons::checkEnd() {
|
||||
// Comprueba si ha finalizado
|
||||
if (finished_)
|
||||
{
|
||||
if (finished_) {
|
||||
// Asigna los botones definidos al input_
|
||||
bindButtons();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user