diff --git a/include/gui/toolbar.hpp b/include/gui/toolbar.hpp index f9e68ec..8624255 100644 --- a/include/gui/toolbar.hpp +++ b/include/gui/toolbar.hpp @@ -25,9 +25,20 @@ private: // zones de texte pour les métadonnées sfg::Entry::Ptr name_entry; sfg::Entry::Ptr path_entry; + + // listes de sélection pour le fond et la musique sfg::ComboBox::Ptr background_combo; sfg::ComboBox::Ptr music_combo; + /** + * Mise à jour de l'éditeur selon les modifications + * faites dans l'interface + */ + void updateEditorName(); + void updateEditorPath(); + void updateEditorBackground(); + void updateEditorMusic(); + // types d'objets de la barre d'outils sfg::RadioButtonGroup::Ptr creators_group; sfg::Table::Ptr creators_table; @@ -68,6 +79,11 @@ public: */ sfg::Window::Ptr getWindow(); + /** + * Met à jour l'état de la toolbar selon l'état de l'éditeur + */ + void update(); + /** * Récupère la taille désirée par la barre d'outils */ diff --git a/include/states/editor.hpp b/include/states/editor.hpp index c201d48..e8ace1f 100644 --- a/include/states/editor.hpp +++ b/include/states/editor.hpp @@ -88,17 +88,17 @@ public: /** * Active l'état */ - virtual void enable(); + void enable() override; /** * Traite l'événement donné */ - virtual void processEvent(const sf::Event& event); + void processEvent(const sf::Event& event) override; /** * Demande le dessin d'une frame */ - virtual void frame(); + void frame() override; /** * Lance le test du niveau diff --git a/include/states/level.hpp b/include/states/level.hpp index f3ca4a2..6575495 100644 --- a/include/states/level.hpp +++ b/include/states/level.hpp @@ -116,7 +116,7 @@ public: /** * Modifie la musique du niveau */ - virtual void setMusic(std::string set_music); + void setMusic(std::string set_music); /** * Récupère le fond du niveau diff --git a/src/gui/toolbar.cpp b/src/gui/toolbar.cpp index 1854107..bb4bfd5 100644 --- a/src/gui/toolbar.cpp +++ b/src/gui/toolbar.cpp @@ -1,3 +1,4 @@ +#include #include "resource_manager.hpp" #include "states/editor.hpp" #include "objects/block.hpp" @@ -38,17 +39,53 @@ Toolbar::Toolbar(Editor& editor) : editor(editor) { toolbar_box->PackEnd(sfg::Label::Create(L"Informations")); toolbar_box->PackEnd(sfg::Separator::Create()); - name_entry = sfg::Entry::Create("nom niveau test"); - path_entry = sfg::Entry::Create("chemin niveau test"); + name_entry = sfg::Entry::Create(); + path_entry = sfg::Entry::Create(); - background_combo = sfg::ComboBox::Create(); - background_combo->AppendItem("background"); + name_entry->GetSignal(sfg::Entry::OnTextChanged).Connect( + std::bind(&Toolbar::updateEditorName, this) + ); - music_combo = sfg::ComboBox::Create(); - music_combo->AppendItem("music"); + path_entry->GetSignal(sfg::Entry::OnTextChanged).Connect( + std::bind(&Toolbar::updateEditorPath, this) + ); toolbar_box->PackEnd(name_entry); toolbar_box->PackEnd(path_entry); + + // construction des choix de fonds et musiques pour le niveau + ResourceManager& res = ResourceManager::get(); + std::vector backgrounds_list = + res.getFiles(res.getTexturesPath() / "levels"); + std::vector musics_list = + res.getFiles(res.getMusicsPath() / "levels"); + + background_combo = sfg::ComboBox::Create(); + music_combo = sfg::ComboBox::Create(); + + background_combo->AppendItem("Aucun fond"); + background_combo->SelectItem(0); + music_combo->AppendItem("Aucune musique"); + music_combo->SelectItem(0); + + for (const auto &background_path : backgrounds_list) { + std::string choice_value = background_path.filename().string(); + background_combo->AppendItem(choice_value); + } + + for (const auto &music_path : musics_list) { + std::string choice_value = music_path.filename().string(); + music_combo->AppendItem(choice_value); + } + + background_combo->GetSignal(sfg::ComboBox::OnSelect).Connect( + std::bind(&Toolbar::updateEditorBackground, this) + ); + + music_combo->GetSignal(sfg::ComboBox::OnSelect).Connect( + std::bind(&Toolbar::updateEditorMusic, this) + ); + toolbar_box->PackEnd(background_combo); toolbar_box->PackEnd(music_combo); @@ -176,6 +213,47 @@ Object::Ptr Toolbar::createObject() { return nullptr; } +void Toolbar::updateEditorName() { + editor.setName(name_entry->GetText()); +} + +void Toolbar::updateEditorPath() { + editor.setPath(path_entry->GetText()); +} + +void Toolbar::updateEditorBackground() { + if (background_combo->GetSelectedItem() == 0) { + editor.setBackground(""); + } else { + editor.setBackground(background_combo->GetSelectedText().toAnsiString()); + } +} + +void Toolbar::updateEditorMusic() { + if (music_combo->GetSelectedItem() == 0) { + editor.setMusic(""); + } else { + editor.setMusic(music_combo->GetSelectedText().toAnsiString()); + } +} + +void Toolbar::update() { + name_entry->SetText(editor.getName()); + path_entry->SetText(editor.getPath()); + + for (int i = 0; i < background_combo->GetItemCount(); i++) { + if (background_combo->GetItem(i).toAnsiString() == editor.getBackground()) { + background_combo->SelectItem(i); + } + } + + for (int i = 0; i < music_combo->GetItemCount(); i++) { + if (music_combo->GetItem(i).toAnsiString() == editor.getMusic()) { + music_combo->SelectItem(i); + } + } +} + sfg::Window::Ptr Toolbar::getWindow() { return toolbar_window; } diff --git a/src/states/editor.cpp b/src/states/editor.cpp index 066c817..6f604a1 100644 --- a/src/states/editor.cpp +++ b/src/states/editor.cpp @@ -53,6 +53,7 @@ void Editor::enable() { ResourceManager::get().playMusic("editor.ogg"); // on affiche la toolbar de l'éditeur + toolbar.update(); toolbar.getWindow()->Show(true); } @@ -250,6 +251,9 @@ void Editor::processEvent(const sf::Event& event) { void Editor::frame() { // dessin de la frame draw(); + + // màj du titre de la fenêtre + getManager().setTitle(sf::String(L"Édition de ") + getName()); } void Editor::draw() { diff --git a/src/states/level.cpp b/src/states/level.cpp index 0df6991..706be87 100644 --- a/src/states/level.cpp +++ b/src/states/level.cpp @@ -239,7 +239,7 @@ std::string Level::getPath() { return path; } -void Level::setPath(std::string set_path ){ +void Level::setPath(std::string set_path) { path = set_path; }