From 6ee1e9271c4bf06d08bf1edcd2f7d6d0f3d3701c Mon Sep 17 00:00:00 2001 From: Stepland Date: Wed, 16 Jan 2019 22:10:20 +0100 Subject: [PATCH] Switched to using events for shortcuts --- EditorState.cpp | 4 ++-- EditorState.h | 10 ++++++---- Toolbox.cpp | 15 --------------- Toolbox.h | 3 ++- main.cpp | 38 ++++++++++++++++++++++---------------- 5 files changed, 32 insertions(+), 38 deletions(-) diff --git a/EditorState.cpp b/EditorState.cpp index ba8651b..bde577b 100644 --- a/EditorState.cpp +++ b/EditorState.cpp @@ -11,7 +11,7 @@ #include "tinyfiledialogs.h" #include "Toolbox.h" -EditorState::EditorState(Fumen &fumen) : fumen(fumen), markerEndingState(MISS) { +EditorState::EditorState(Fumen &fumen) : fumen(fumen) { reloadFromFumen(); } @@ -304,7 +304,7 @@ std::vector EditorState::getVisibleNotes() { std::vector visibleNotes; float minPos; - if (this->markerEndingState == MISS) { + if (this->playfield.markerEndingState == MISS) { minPos = playbackPosition.asSeconds() - 8.f/30.f; } else { minPos = playbackPosition.asSeconds() - 16.f/30.f; diff --git a/EditorState.h b/EditorState.h index e2eecd7..a922ce8 100644 --- a/EditorState.h +++ b/EditorState.h @@ -16,11 +16,13 @@ class EditorState { public: Fumen fumen; - Widgets::Playfield playfield; - MarkerEndingState markerEndingState; - std::optional music; - std::optional jacket; std::optional selectedChart; // Ok this was a pretty terrible design choice, be EXTRA careful about this still being in sync with what's actually in the std::map of fumen + Widgets::Playfield playfield; + + std::optional music; + float musicVolume = 100.f; // 0 -> 100 + + std::optional jacket; sf::Time playbackPosition; sf::Time chartRuntime; // Timing at which the playback stops diff --git a/Toolbox.cpp b/Toolbox.cpp index 7d149a7..a49f9fd 100644 --- a/Toolbox.cpp +++ b/Toolbox.cpp @@ -10,20 +10,6 @@ #include #include "Toolbox.h" -bool Toolbox::isShortcutPressed(std::initializer_list anyOf, std::initializer_list allOf) { - for (auto key : allOf) { - if (not sf::Keyboard::isKeyPressed(key)) { - return false; - } - } - for (auto key : anyOf) { - if (sf::Keyboard::isKeyPressed(key)) { - return true; - } - } - return false; -} - void Toolbox::pushNewRecentFile(std::filesystem::path path) { std::ifstream readFile(std::filesystem::path("settings/recent files.txt")); std::list recent; @@ -108,4 +94,3 @@ bool Toolbox::InputTextColored(bool isValid, const std::string& hoverHelpText, c } return return_value; } - diff --git a/Toolbox.h b/Toolbox.h index 021d89d..06d4d0b 100644 --- a/Toolbox.h +++ b/Toolbox.h @@ -8,7 +8,9 @@ #define IM_MAX(_A,_B) (((_A) >= (_B)) ? (_A) : (_B)) #include +#include #include +#include "EditorState.h" namespace Toolbox { @@ -20,7 +22,6 @@ namespace Toolbox { ImColor FrameBgHovered_Red = {0.980f, 0.261f, 0.261f, 0.400f}; ImColor FrameBgActive_Red = {0.980f, 0.261f, 0.261f, 0.671f}; }; - bool isShortcutPressed(std::initializer_list anyOf, std::initializer_list allOf); void pushNewRecentFile(std::filesystem::path path); std::vector getRecentFiles(); diff --git a/main.cpp b/main.cpp index 17042da..6e3ef95 100644 --- a/main.cpp +++ b/main.cpp @@ -18,6 +18,9 @@ int main(int argc, char** argv) { // TODO : Edition des notes à la souris (mode suppression / mode ajout) // TODO : Bruit différent si clap simple ou chord // TODO : Density graph sur la timeline + // TODO : Système de notifs + // TODO : Undo / Redo + // TODO : set pitch // Création de la fenêtre sf::RenderWindow window(sf::VideoMode(800, 600), "FEIS"); @@ -87,8 +90,27 @@ int main(int argc, char** argv) { } } break; + case sf::Keyboard::O: + if (event.key.control) { + ESHelper::open(editorState); + } + break; + case sf::Keyboard::P: + if (event.key.shift) { + editorState->showProperties = true; + } + break; + case sf::Keyboard::S: + if (event.key.control) { + ESHelper::save(*editorState); + } + break; + default: + break; } break; + default: + break; } } @@ -177,22 +199,6 @@ int main(int argc, char** argv) { bg.render(window); } - // TODO : Use events instead - // Gestion des Raccourcis Clavier - - // Ctrl+S - if (editorState and Toolbox::isShortcutPressed({sf::Keyboard::LControl,sf::Keyboard::RControl},{sf::Keyboard::S})) { - ESHelper::save(*editorState); - - // Ctrl+O - } else if (Toolbox::isShortcutPressed({sf::Keyboard::LControl,sf::Keyboard::RControl},{sf::Keyboard::O})) { - ESHelper::open(editorState); - - // Shift+P - } else if (editorState and Toolbox::isShortcutPressed({sf::Keyboard::LShift,sf::Keyboard::RShift},{sf::Keyboard::P})) { - editorState->showProperties = true; - } - // Dessin de l'interface ImGui::BeginMainMenuBar(); {