152 lines
6.0 KiB
C++
152 lines
6.0 KiB
C++
#include "core/input/global_inputs.hpp"
|
|
|
|
#include <string>
|
|
|
|
#include "core/input/input.h"
|
|
#include "core/locale/lang.h"
|
|
#include "core/rendering/notifications.hpp"
|
|
#include "core/rendering/screen.h"
|
|
#include "game/options.hpp"
|
|
#include "utils/defines.hpp"
|
|
#include "version.h"
|
|
|
|
namespace GlobalInputs {
|
|
|
|
namespace {
|
|
// Índexs de Lang per a les notificacions de hotkey
|
|
constexpr int LANG_ZOOM = 96;
|
|
constexpr int LANG_FULLSCREEN = 97;
|
|
constexpr int LANG_WINDOW = 98;
|
|
constexpr int LANG_SHADER = 99;
|
|
constexpr int LANG_PRESET = 100;
|
|
constexpr int LANG_EXIT_CONFIRM = 101;
|
|
|
|
// Patró de doble pulsació: la primera pulsació d'EXIT mostra una
|
|
// notificació en vermell i obre una finestra de confirmació; una
|
|
// segona pulsació dins la finestra activa `quit_requested`. La
|
|
// finestra coincideix amb la durada del missatge perquè usuari i
|
|
// sistema sempre estiguin sincronitzats.
|
|
Uint32 exit_window_until_ticks = 0;
|
|
bool quit_requested = false;
|
|
|
|
void notifyZoom() {
|
|
const std::string MSG = Lang::get()->getText(LANG_ZOOM) + " " + std::to_string(Options::window.zoom) + "x";
|
|
Notifications::show(MSG, Notifications::Palette::INFO, Notifications::STANDARD_MS);
|
|
}
|
|
|
|
void notifyFullscreen() {
|
|
const int IDX = Options::video.fullscreen ? LANG_FULLSCREEN : LANG_WINDOW;
|
|
Notifications::show(Lang::get()->getText(IDX), Notifications::Palette::INFO, Notifications::STANDARD_MS);
|
|
}
|
|
|
|
void notifyShaderEnabled() {
|
|
const std::string STATE = Screen::isShaderEnabled() ? "ON" : "OFF";
|
|
const std::string MSG = Lang::get()->getText(LANG_SHADER) + " " + STATE;
|
|
Notifications::show(MSG, Notifications::Palette::TOGGLE, Notifications::STANDARD_MS);
|
|
}
|
|
|
|
void notifyShaderType() {
|
|
const bool IS_CRTPI = Options::video.shader.current_shader == Rendering::ShaderType::CRTPI;
|
|
const std::string MSG = Lang::get()->getText(LANG_SHADER) + " " + (IS_CRTPI ? "CRTPI" : "POSTFX");
|
|
Notifications::show(MSG, Notifications::Palette::CHOICE, Notifications::STANDARD_MS);
|
|
}
|
|
|
|
void notifyPreset() {
|
|
const std::string MSG = Lang::get()->getText(LANG_PRESET) + " " + Screen::get()->getCurrentPresetName();
|
|
Notifications::show(MSG, Notifications::Palette::SUCCESS, Notifications::STANDARD_MS);
|
|
}
|
|
|
|
void notifyVersion() {
|
|
// Format: "<APP_NAME> v<VERSION> (<GIT_HASH>)"
|
|
const std::string MSG = std::string(Version::APP_NAME) + " v" + Texts::VERSION + " (" + Version::GIT_HASH + ")";
|
|
Notifications::show(MSG, Notifications::Palette::TOGGLE, Notifications::LONG_MS);
|
|
}
|
|
|
|
void notifyVSync() {
|
|
const std::string STATE = Options::video.vsync ? "ON" : "OFF";
|
|
const std::string MSG = std::string("VSync ") + STATE;
|
|
Notifications::show(MSG, Notifications::Palette::TOGGLE, Notifications::STANDARD_MS);
|
|
}
|
|
|
|
void notifyPresentationMode() {
|
|
const std::string MSG = std::string("Mode ") + Screen::getPresentationModeName();
|
|
Notifications::show(MSG, Notifications::Palette::CHOICE, Notifications::STANDARD_MS);
|
|
}
|
|
|
|
void onExit() {
|
|
const Uint32 NOW = SDL_GetTicks();
|
|
if (NOW < exit_window_until_ticks) {
|
|
quit_requested = true;
|
|
return;
|
|
}
|
|
exit_window_until_ticks = NOW + Notifications::CONFIRM_MS;
|
|
Notifications::show(Lang::get()->getText(LANG_EXIT_CONFIRM), Notifications::Palette::DANGER, Notifications::CONFIRM_MS);
|
|
}
|
|
} // namespace
|
|
|
|
auto handle() -> bool {
|
|
if (Screen::get() == nullptr || Input::get() == nullptr) { return false; }
|
|
|
|
if (Input::get()->checkInput(Input::Action::EXIT, Input::Repeat::OFF)) {
|
|
onExit();
|
|
return true;
|
|
}
|
|
if (Input::get()->checkInput(Input::Action::WINDOW_FULLSCREEN, Input::Repeat::OFF)) {
|
|
Screen::get()->toggleVideoMode();
|
|
notifyFullscreen();
|
|
return true;
|
|
}
|
|
if (Input::get()->checkInput(Input::Action::WINDOW_DEC_ZOOM, Input::Repeat::OFF)) {
|
|
if (Screen::get()->decWindowZoom()) {
|
|
notifyZoom();
|
|
}
|
|
return true;
|
|
}
|
|
if (Input::get()->checkInput(Input::Action::WINDOW_INC_ZOOM, Input::Repeat::OFF)) {
|
|
if (Screen::get()->incWindowZoom()) {
|
|
notifyZoom();
|
|
}
|
|
return true;
|
|
}
|
|
if (Input::get()->checkInput(Input::Action::TOGGLE_SHADER, Input::Repeat::OFF)) {
|
|
Screen::get()->toggleShaderEnabled();
|
|
notifyShaderEnabled();
|
|
return true;
|
|
}
|
|
if (Input::get()->checkInput(Input::Action::SHOW_VERSION, Input::Repeat::OFF)) {
|
|
notifyVersion();
|
|
return true;
|
|
}
|
|
if (Input::get()->checkInput(Input::Action::TOGGLE_VSYNC, Input::Repeat::OFF)) {
|
|
Screen::get()->toggleVSync();
|
|
notifyVSync();
|
|
return true;
|
|
}
|
|
if (Input::get()->checkInput(Input::Action::NEXT_PRESENTATION_MODE, Input::Repeat::OFF)) {
|
|
Screen::get()->nextPresentationMode();
|
|
notifyPresentationMode();
|
|
return true;
|
|
}
|
|
// F5/F6 només actuen quan el post-procesado està actiu.
|
|
if (Screen::isShaderEnabled()) {
|
|
if (Input::get()->checkInput(Input::Action::TOGGLE_SHADER_TYPE, Input::Repeat::OFF)) {
|
|
Screen::get()->toggleActiveShader();
|
|
notifyShaderType();
|
|
return true;
|
|
}
|
|
if (Input::get()->checkInput(Input::Action::NEXT_SHADER_PRESET, Input::Repeat::OFF)) {
|
|
if (Screen::get()->nextPreset()) {
|
|
notifyPreset();
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
auto wantsQuit() -> bool {
|
|
return quit_requested;
|
|
}
|
|
|
|
} // namespace GlobalInputs
|