diff --git a/CMakeLists.txt b/CMakeLists.txt index 560f144..092ede9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,7 +12,7 @@ SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${GCC_COVERAGE_LINK_FLAGS set(SOURCE_FILES main.cpp - screen.cpp + Widgets.cpp Marker.cpp Fumen.cpp Note.cpp diff --git a/EditorState.cpp b/EditorState.cpp index 0bce39a..4f72911 100644 --- a/EditorState.cpp +++ b/EditorState.cpp @@ -55,6 +55,9 @@ void EditorState::reloadJacket() { } +void EditorState::displayPlayfield() { +} + /* * Display all metadata in an editable form */ @@ -170,28 +173,27 @@ void EditorState::displayTimeline() { ImGui::PopStyleVar(3); } -void EditorState::save() { +void ESHelper::save(EditorState& ed) { try { - fumen.autoSaveAsMemon(); + ed.fumen.autoSaveAsMemon(); } catch (const std::exception& e) { tinyfd_messageBox("Error",e.what(),"ok","error",1); } } -void EditorState::open() { +void ESHelper::open(std::optional &ed) { const char* _filepath = tinyfd_openFileDialog("Open File",nullptr,0,nullptr,nullptr,false); if (_filepath != nullptr) { - openFromFile(_filepath); + ESHelper::openFromFile(ed,_filepath); } } -void EditorState::openFromFile(std::filesystem::path path) { +void ESHelper::openFromFile(std::optional &ed, std::filesystem::path path) { try { Fumen f(path); f.autoLoadFromMemon(); - fumen = f; - reloadFromFumen(); - Toolbox::pushNewRecentFile(std::filesystem::canonical(fumen.path)); + ed.emplace(f); + Toolbox::pushNewRecentFile(std::filesystem::canonical(ed->fumen.path)); } catch (const std::exception &e) { tinyfd_messageBox("Error", e.what(), "ok", "error", 1); } diff --git a/EditorState.h b/EditorState.h index d715d7e..dc75b91 100644 --- a/EditorState.h +++ b/EditorState.h @@ -9,11 +9,13 @@ #include #include #include "Fumen.h" +#include "Marker.h" class EditorState { public: Fumen fumen; + Marker marker; std::optional music; std::optional jacket; std::optional selectedChart; @@ -22,22 +24,26 @@ public: void reloadMusic(); void reloadJacket(); + bool showPlayfield = true; bool showProperties; bool showStatus; bool showPlaybackStatus = true; bool showTimeline = true; + void displayPlayfield(); void displayProperties(); void displayStatus(); void displayPlaybackStatus(); void displayTimeline(); - void save(); - void open(); - void openFromFile(std::filesystem::path path); - explicit EditorState(Fumen& fumen); }; +namespace ESHelper { + void save(EditorState& ed); + void open(std::optional& ed); + void openFromFile(std::optional& ed, std::filesystem::path path); +} + #endif //FEIS_EDITORSTATE_H diff --git a/Marker.cpp b/Marker.cpp index 481fd73..1502a91 100644 --- a/Marker.cpp +++ b/Marker.cpp @@ -41,7 +41,7 @@ Marker::Marker(std::string folder) { } } -sf::Sprite Marker::getSprite(Etat etat, int frame) { +sf::Texture Marker::getSprite(Etat etat, int frame) { int lower; int upper; @@ -60,7 +60,6 @@ sf::Sprite Marker::getSprite(Etat etat, int frame) { throw std::runtime_error("Requested access to a non-existent marker frame : " +std::to_string(frame)); } - sf::Sprite sprite; std::string tex_key; switch (etat) { case APPROCHE: @@ -84,8 +83,6 @@ sf::Sprite Marker::getSprite(Etat etat, int frame) { tex_key += "0"; } - sprite.setTexture(textures[tex_key+std::to_string(frame)]); - - return sprite; + return textures[tex_key+std::to_string(frame)]; } diff --git a/Marker.h b/Marker.h index 5bf33ee..f79e462 100644 --- a/Marker.h +++ b/Marker.h @@ -25,7 +25,7 @@ class Marker { public: Marker(std::string folder = "mk0013"); - sf::Sprite getSprite(Etat etat, int frame); + sf::Texture getSprite(Etat etat, int frame); private: diff --git a/Toolbox.h b/Toolbox.h index e1d11ba..455c640 100644 --- a/Toolbox.h +++ b/Toolbox.h @@ -5,6 +5,8 @@ #ifndef FEIS_TOOLBOX_H #define FEIS_TOOLBOX_H +#define IM_MAX(_A,_B) (((_A) >= (_B)) ? (_A) : (_B)) + #include #include @@ -12,6 +14,15 @@ namespace Toolbox { bool isShortcutPressed(std::initializer_list anyOf, std::initializer_list allOf); void pushNewRecentFile(std::filesystem::path path); std::vector getRecentFiles(); + + struct CustomConstraints { + static void ContentSquare(ImGuiSizeCallbackData* data) { + float TitlebarHeight = ImGui::GetFontSize() + ImGui::GetStyle().FramePadding.y * 2.f; + float y = data->DesiredSize.y - TitlebarHeight; + float x = data->DesiredSize.x; + data->DesiredSize = ImVec2(IM_MAX(x,y), IM_MAX(x,y) + TitlebarHeight); + } + }; } #endif //FEIS_TOOLBOX_H diff --git a/Widgets.cpp b/Widgets.cpp new file mode 100644 index 0000000..1e7cb29 --- /dev/null +++ b/Widgets.cpp @@ -0,0 +1,64 @@ +// +// Created by Syméon on 17/08/2017. +// + +#include "Widgets.h" +#include "Toolbox.h" + +Ecran_attente::Ecran_attente() : gris_de_fond(sf::Color(38,38,38)) { + + if(!tex_FEIS_logo.loadFromFile("assets/textures/FEIS_logo.png")) + { + throw std::string("Unable to load assets/textures/FEIS_logo.png"); + } + tex_FEIS_logo.setSmooth(true); + FEIS_logo.setTexture(tex_FEIS_logo); + FEIS_logo.setColor(sf::Color(255, 255, 255, 32)); // un huitième opaque + +} + +void Ecran_attente::render(sf::RenderWindow& window) { + // effacement de la fenêtre en noir + window.clear(gris_de_fond); + + // c'est ici qu'on dessine tout + FEIS_logo.setPosition(sf::Vector2f(static_cast((window.getSize().x-tex_FEIS_logo.getSize().x)/2), + static_cast((window.getSize().y-tex_FEIS_logo.getSize().y)/2))); + window.draw(FEIS_logo); +} + +Playfield::Playfield() { + + marker = Marker(); + if (!button.loadFromFile(button_path,{0,0,192,192})) { + std::cerr << "Unable to load texture " << button_path; + throw std::runtime_error("Unable to load texture " + button_path); + } + if (!button_pressed.loadFromFile(button_path,{192,0,192,192})) { + std::cerr << "Unable to load texture " << button_path; + throw std::runtime_error("Unable to load texture " + button_path); + } +} + +void Playfield::render(sf::RenderWindow &window, EditorState& editorState) { + + ImGui::SetNextWindowSizeConstraints(ImVec2(0,0),ImVec2(FLT_MAX,FLT_MAX),Toolbox::CustomConstraints::ContentSquare); + ImGui::Begin("Playfield",&editorState.showPlayfield,ImGuiWindowFlags_NoScrollbar); + { + float squareSize = ImGui::GetWindowSize().x / 4.f; + float TitlebarHeight = ImGui::GetWindowSize().y - ImGui::GetWindowSize().x; + for (int y = 0; y < 4; ++y) { + for (int x = 0; x < 4; ++x) { + ImGui::PushID(x+4*y); + ImGui::SetCursorPos({x*squareSize,TitlebarHeight + y*squareSize}); + ImGui::PushStyleColor(ImGuiCol_Button, (ImVec4)ImColor::HSV(0,0,0,0)); + ImGui::PushStyleColor(ImGuiCol_ButtonHovered, (ImVec4)ImColor::HSV(0,0,1.f,0.1f)); + ImGui::PushStyleColor(ImGuiCol_ButtonActive, (ImVec4)ImColor::HSV(0,0,1.f,0.5f)); + ImGui::ImageButton(button,{squareSize,squareSize},0); + ImGui::PopStyleColor(3); + ImGui::PopID(); + } + } + } + ImGui::End(); +} diff --git a/screen.h b/Widgets.h similarity index 62% rename from screen.h rename to Widgets.h index 16cc6f0..16b028f 100644 --- a/screen.h +++ b/Widgets.h @@ -7,17 +7,10 @@ #include #include +#include #include "Marker.h" #include "EditorState.h" -class Screen { - -public: - - virtual void render(sf::RenderWindow &window, EditorState editorState) = 0; - -}; - class Ecran_attente { public: @@ -33,18 +26,19 @@ private: }; -class Ecran_edition : public Screen { +class Playfield { public: - Ecran_edition(); - void render(sf::RenderWindow &window, EditorState editorState); + Playfield(); + void render(sf::RenderWindow &window, EditorState& editorState); + + Marker marker; + sf::Texture button; + sf::Texture button_pressed; private: - - sf::Color couleur_de_fond; - Marker marker; - + std::string button_path = "assets/textures/edit_textures/game_front_edit_tex_1.tex.png"; }; #endif //FEIS_SCREEN_H diff --git a/main.cpp b/main.cpp index 4575d56..e313fdf 100644 --- a/main.cpp +++ b/main.cpp @@ -2,7 +2,7 @@ #include #include #include -#include "screen.h" +#include "Widgets.h" #include "EditorState.h" #include "tinyfiledialogs.h" #include "Toolbox.h" @@ -24,6 +24,7 @@ int main(int argc, char** argv) { Ecran_attente bg; + Playfield playfield; std::optional editorState; sf::Clock deltaClock; @@ -63,6 +64,9 @@ int main(int argc, char** argv) { // Dessin du fond if (editorState) { + if (editorState->showPlayfield) { + playfield.render(window,*editorState); + } if (editorState->showProperties) { editorState->displayProperties(); } @@ -81,13 +85,21 @@ int main(int argc, char** argv) { } // Gestion des Raccourcis Clavier - if (Toolbox::isShortcutPressed({sf::Keyboard::LControl,sf::Keyboard::RControl},{sf::Keyboard::S})) { - editorState->save(); + + // 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 + // Dessin de l'interface ImGui::BeginMainMenuBar(); { if (ImGui::BeginMenu("File")) { @@ -106,25 +118,29 @@ int main(int argc, char** argv) { } } ImGui::Separator(); - if (ImGui::MenuItem("Open","Ctrl+O") or Toolbox::isShortcutPressed({sf::Keyboard::LControl,sf::Keyboard::RControl},{sf::Keyboard::O})) { - editorState->open(); + if (ImGui::MenuItem("Open","Ctrl+O")) { + ESHelper::open(editorState); } if (ImGui::BeginMenu("Recent Files")) { int i = 0; for (const auto& file : Toolbox::getRecentFiles()) { ImGui::PushID(i); if (ImGui::MenuItem(file.c_str())) { - editorState->openFromFile(file); + ESHelper::openFromFile(editorState,file); } ImGui::PopID(); ++i; } ImGui::EndMenu(); } - if (ImGui::MenuItem("Save","Ctrl+S")) { - editorState->save(); + if (ImGui::MenuItem("Close","",false,editorState.has_value())) { + editorState.reset(); } - if (ImGui::MenuItem("Save As")) { + ImGui::Separator(); + if (ImGui::MenuItem("Save","Ctrl+S",false,editorState.has_value())) { + ESHelper::save(*editorState); + } + if (ImGui::MenuItem("Save As","",false,editorState.has_value())) { char const * options[1] = {"*.memon"}; const char* _filepath(tinyfd_saveFileDialog("Save File",nullptr,1,options,nullptr)); if (_filepath != nullptr) { @@ -136,17 +152,18 @@ int main(int argc, char** argv) { } } } + ImGui::Separator(); + if (ImGui::MenuItem("Properties","Shift+P",false,editorState.has_value())) { + editorState->showProperties = true; + } ImGui::EndMenu(); } if (ImGui::BeginMenu("Edit")) { - if (ImGui::MenuItem("Properties",nullptr,false,editorState.has_value())) { - editorState->showProperties = true; - } ImGui::EndMenu(); } if (ImGui::BeginMenu("View",editorState.has_value())) { - if (ImGui::MenuItem("Editor Status",nullptr,editorState->showStatus)) { - editorState->showStatus = not editorState->showStatus; + if (ImGui::MenuItem("Playfield", nullptr,editorState->showPlayfield)) { + editorState->showPlayfield = not editorState->showPlayfield; } if (ImGui::MenuItem("Playback Status",nullptr,editorState->showPlaybackStatus)) { editorState->showPlaybackStatus = not editorState->showPlaybackStatus; @@ -154,6 +171,9 @@ int main(int argc, char** argv) { if (ImGui::MenuItem("Timeline",nullptr,editorState->showTimeline)) { editorState->showTimeline = not editorState->showTimeline; } + if (ImGui::MenuItem("Editor Status",nullptr,editorState->showStatus)) { + editorState->showStatus = not editorState->showStatus; + } ImGui::EndMenu(); } } diff --git a/screen.cpp b/screen.cpp deleted file mode 100644 index d9b8942..0000000 --- a/screen.cpp +++ /dev/null @@ -1,38 +0,0 @@ -// -// Created by Syméon on 17/08/2017. -// - -#include "screen.h" - -Ecran_attente::Ecran_attente() : gris_de_fond(sf::Color(38,38,38)) { - - if(!tex_FEIS_logo.loadFromFile("assets/textures/FEIS_logo.png")) - { - throw std::string("Unable to load assets/textures/FEIS_logo.png"); - } - tex_FEIS_logo.setSmooth(true); - FEIS_logo.setTexture(tex_FEIS_logo); - FEIS_logo.setColor(sf::Color(255, 255, 255, 32)); // un huitième opaque - -} - -void Ecran_attente::render(sf::RenderWindow& window) { - // effacement de la fenêtre en noir - window.clear(gris_de_fond); - - // c'est ici qu'on dessine tout - FEIS_logo.setPosition(sf::Vector2f(static_cast((window.getSize().x-tex_FEIS_logo.getSize().x)/2), - static_cast((window.getSize().y-tex_FEIS_logo.getSize().y)/2))); - window.draw(FEIS_logo); -} - -Ecran_edition::Ecran_edition() : couleur_de_fond(sf::Color(0,0,0)) { - - marker = Marker(); - -} - -void Ecran_edition::render(sf::RenderWindow &window, EditorState editorState) { - - -}