Communication de données entre la toolbar et l'éditeur
This commit is contained in:
		
							parent
							
								
									14e4b045a6
								
							
						
					
					
						commit
						20d251752c
					
				|  | @ -25,9 +25,20 @@ private: | ||||||
|     // zones de texte pour les métadonnées
 |     // zones de texte pour les métadonnées
 | ||||||
|     sfg::Entry::Ptr name_entry; |     sfg::Entry::Ptr name_entry; | ||||||
|     sfg::Entry::Ptr path_entry; |     sfg::Entry::Ptr path_entry; | ||||||
|  | 
 | ||||||
|  |     // listes de sélection pour le fond et la musique
 | ||||||
|     sfg::ComboBox::Ptr background_combo; |     sfg::ComboBox::Ptr background_combo; | ||||||
|     sfg::ComboBox::Ptr music_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
 |     // types d'objets de la barre d'outils
 | ||||||
|     sfg::RadioButtonGroup::Ptr creators_group; |     sfg::RadioButtonGroup::Ptr creators_group; | ||||||
|     sfg::Table::Ptr creators_table; |     sfg::Table::Ptr creators_table; | ||||||
|  | @ -68,6 +79,11 @@ public: | ||||||
|      */ |      */ | ||||||
|     sfg::Window::Ptr getWindow(); |     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 |      * Récupère la taille désirée par la barre d'outils | ||||||
|      */ |      */ | ||||||
|  |  | ||||||
|  | @ -88,17 +88,17 @@ public: | ||||||
|     /**
 |     /**
 | ||||||
|      * Active l'état |      * Active l'état | ||||||
|      */ |      */ | ||||||
|     virtual void enable(); |     void enable() override; | ||||||
| 
 | 
 | ||||||
|     /**
 |     /**
 | ||||||
|      * Traite l'événement donné |      * 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 |      * Demande le dessin d'une frame | ||||||
|      */ |      */ | ||||||
|     virtual void frame(); |     void frame() override; | ||||||
| 
 | 
 | ||||||
|     /**
 |     /**
 | ||||||
|      * Lance le test du niveau |      * Lance le test du niveau | ||||||
|  |  | ||||||
|  | @ -116,7 +116,7 @@ public: | ||||||
|     /**
 |     /**
 | ||||||
|      * Modifie la musique du niveau |      * 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 |      * Récupère le fond du niveau | ||||||
|  |  | ||||||
|  | @ -1,3 +1,4 @@ | ||||||
|  | #include <boost/filesystem.hpp> | ||||||
| #include "resource_manager.hpp" | #include "resource_manager.hpp" | ||||||
| #include "states/editor.hpp" | #include "states/editor.hpp" | ||||||
| #include "objects/block.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::Label::Create(L"Informations")); | ||||||
|     toolbar_box->PackEnd(sfg::Separator::Create()); |     toolbar_box->PackEnd(sfg::Separator::Create()); | ||||||
| 
 | 
 | ||||||
|     name_entry = sfg::Entry::Create("nom niveau test"); |     name_entry = sfg::Entry::Create(); | ||||||
|     path_entry = sfg::Entry::Create("chemin niveau test"); |     path_entry = sfg::Entry::Create(); | ||||||
| 
 | 
 | ||||||
|     background_combo = sfg::ComboBox::Create(); |     name_entry->GetSignal(sfg::Entry::OnTextChanged).Connect( | ||||||
|     background_combo->AppendItem("background"); |         std::bind(&Toolbar::updateEditorName, this) | ||||||
|  |     ); | ||||||
| 
 | 
 | ||||||
|     music_combo = sfg::ComboBox::Create(); |     path_entry->GetSignal(sfg::Entry::OnTextChanged).Connect( | ||||||
|     music_combo->AppendItem("music"); |         std::bind(&Toolbar::updateEditorPath, this) | ||||||
|  |     ); | ||||||
| 
 | 
 | ||||||
|     toolbar_box->PackEnd(name_entry); |     toolbar_box->PackEnd(name_entry); | ||||||
|     toolbar_box->PackEnd(path_entry); |     toolbar_box->PackEnd(path_entry); | ||||||
|  | 
 | ||||||
|  |     // construction des choix de fonds et musiques pour le niveau
 | ||||||
|  |     ResourceManager& res = ResourceManager::get(); | ||||||
|  |     std::vector<boost::filesystem::path> backgrounds_list = | ||||||
|  |         res.getFiles(res.getTexturesPath() / "levels"); | ||||||
|  |     std::vector<boost::filesystem::path> 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(background_combo); | ||||||
|     toolbar_box->PackEnd(music_combo); |     toolbar_box->PackEnd(music_combo); | ||||||
| 
 | 
 | ||||||
|  | @ -176,6 +213,47 @@ Object::Ptr Toolbar::createObject() { | ||||||
|     return nullptr; |     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() { | sfg::Window::Ptr Toolbar::getWindow() { | ||||||
|     return toolbar_window; |     return toolbar_window; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -53,6 +53,7 @@ void Editor::enable() { | ||||||
|     ResourceManager::get().playMusic("editor.ogg"); |     ResourceManager::get().playMusic("editor.ogg"); | ||||||
| 
 | 
 | ||||||
|     // on affiche la toolbar de l'éditeur
 |     // on affiche la toolbar de l'éditeur
 | ||||||
|  |     toolbar.update(); | ||||||
|     toolbar.getWindow()->Show(true); |     toolbar.getWindow()->Show(true); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -250,6 +251,9 @@ void Editor::processEvent(const sf::Event& event) { | ||||||
| void Editor::frame() { | void Editor::frame() { | ||||||
|     // dessin de la frame
 |     // dessin de la frame
 | ||||||
|     draw(); |     draw(); | ||||||
|  | 
 | ||||||
|  |     // màj du titre de la fenêtre
 | ||||||
|  |     getManager().setTitle(sf::String(L"Édition de ") + getName()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Editor::draw() { | void Editor::draw() { | ||||||
|  |  | ||||||
|  | @ -239,7 +239,7 @@ std::string Level::getPath() { | ||||||
|     return path; |     return path; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Level::setPath(std::string set_path ){ | void Level::setPath(std::string set_path) { | ||||||
|     path = set_path; |     path = set_path; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue