Arrangement des boutons d'objets dans la toolbar
This commit is contained in:
		
							parent
							
								
									2d2fe5a784
								
							
						
					
					
						commit
						f67e95306d
					
				|  | @ -2,11 +2,11 @@ | ||||||
| #define __SKIZZLE_TOOLBAR_HPP__ | #define __SKIZZLE_TOOLBAR_HPP__ | ||||||
| 
 | 
 | ||||||
| #include <SFGUI/Widgets.hpp> | #include <SFGUI/Widgets.hpp> | ||||||
| #include <SFGUI/RadioButtonGroup.hpp> |  | ||||||
| #include <SFML/Graphics.hpp> | #include <SFML/Graphics.hpp> | ||||||
| #include <map> | #include <map> | ||||||
| #include <functional> | #include <functional> | ||||||
| #include "object.hpp" | #include "object.hpp" | ||||||
|  | #include "object_button.hpp" | ||||||
| #include "level.hpp" | #include "level.hpp" | ||||||
| 
 | 
 | ||||||
| class Editor; | class Editor; | ||||||
|  | @ -29,10 +29,23 @@ private: | ||||||
|     sfg::ComboBox::Ptr music_combo; |     sfg::ComboBox::Ptr music_combo; | ||||||
| 
 | 
 | ||||||
|     // types d'objets de la barre d'outils
 |     // types d'objets de la barre d'outils
 | ||||||
|     sfg::RadioButtonGroup::Ptr objects_group; |     sfg::RadioButtonGroup::Ptr creators_group; | ||||||
|     std::map<sfg::RadioButton::Ptr, std::function<Object::Ptr()>> creators; |     sfg::Table::Ptr creators_table; | ||||||
|  |     std::map<ObjectButton::Ptr, std::function<Object::Ptr()>> creators; | ||||||
| 
 | 
 | ||||||
|     void addCreator(sf::String label, std::function<Object::Ptr()> creator); |     int creators_table_pos_x, creators_table_pos_y; | ||||||
|  | 
 | ||||||
|  |     /**
 | ||||||
|  |      * Nombre d'objets en largeur dans la liste des | ||||||
|  |      * créateurs | ||||||
|  |      */ | ||||||
|  |     static const int CREATORS_TABLE_WIDTH; | ||||||
|  | 
 | ||||||
|  |     /**
 | ||||||
|  |      * Ajoute un nouveau créateur d'objet au dictionnaire | ||||||
|  |      * des créateurs et ajoute son image à l'interface | ||||||
|  |      */ | ||||||
|  |     void addCreator(std::string path, std::function<Object::Ptr()> creator); | ||||||
| 
 | 
 | ||||||
|     Object::Ptr createBlock(); |     Object::Ptr createBlock(); | ||||||
|     Object::Ptr createMovableBlock(); |     Object::Ptr createMovableBlock(); | ||||||
|  |  | ||||||
|  | @ -8,10 +8,12 @@ | ||||||
| #include "kill_block.hpp" | #include "kill_block.hpp" | ||||||
| #include "finish_block.hpp" | #include "finish_block.hpp" | ||||||
| 
 | 
 | ||||||
|  | const int Toolbar::CREATORS_TABLE_WIDTH = 3; | ||||||
|  | 
 | ||||||
| Toolbar::Toolbar(Editor& editor) : editor(editor) { | Toolbar::Toolbar(Editor& editor) : editor(editor) { | ||||||
|     // création de la boîte de la barre d'outils
 |     // création de la boîte de la barre d'outils
 | ||||||
|     toolbar_box = sfg::Box::Create(sfg::Box::Orientation::VERTICAL, 5.f); |     toolbar_box = sfg::Box::Create(sfg::Box::Orientation::VERTICAL, 5.f); | ||||||
|     objects_group = sfg::RadioButtonGroup::Create(); |     creators_group = sfg::RadioButtonGroup::Create(); | ||||||
| 
 | 
 | ||||||
|     // ajout des boutons de contrôle
 |     // ajout des boutons de contrôle
 | ||||||
|     sfg::Button::Ptr test_button = sfg::Button::Create(L"Tester"); |     sfg::Button::Ptr test_button = sfg::Button::Create(L"Tester"); | ||||||
|  | @ -40,17 +42,17 @@ Toolbar::Toolbar(Editor& editor) : editor(editor) { | ||||||
|     path_entry = sfg::Entry::Create("chemin niveau test"); |     path_entry = sfg::Entry::Create("chemin niveau test"); | ||||||
| 
 | 
 | ||||||
|     background_combo = sfg::ComboBox::Create(); |     background_combo = sfg::ComboBox::Create(); | ||||||
|     background_combo->AppendItem("background niveau test"); |     background_combo->AppendItem("background"); | ||||||
| 
 | 
 | ||||||
|     music_combo = sfg::ComboBox::Create(); |     music_combo = sfg::ComboBox::Create(); | ||||||
|     music_combo->AppendItem("music niveau test"); |     music_combo->AppendItem("music"); | ||||||
| 
 | 
 | ||||||
|     toolbar_box->PackEnd(name_entry); |     toolbar_box->PackEnd(name_entry); | ||||||
|     toolbar_box->PackEnd(path_entry); |     toolbar_box->PackEnd(path_entry); | ||||||
|     toolbar_box->PackEnd(background_combo); |     toolbar_box->PackEnd(background_combo); | ||||||
|     toolbar_box->PackEnd(music_combo); |     toolbar_box->PackEnd(music_combo); | ||||||
| 
 | 
 | ||||||
|     // ajout des créateurs de blocs
 |     // mise en place de la liste des créateurs d'objets
 | ||||||
| 	sfg::Alignment::Ptr creators_spacer = sfg::Alignment::Create(); | 	sfg::Alignment::Ptr creators_spacer = sfg::Alignment::Create(); | ||||||
| 	creators_spacer->SetRequisition(sf::Vector2f(1, 5)); | 	creators_spacer->SetRequisition(sf::Vector2f(1, 5)); | ||||||
| 
 | 
 | ||||||
|  | @ -58,29 +60,36 @@ Toolbar::Toolbar(Editor& editor) : editor(editor) { | ||||||
|     toolbar_box->PackEnd(sfg::Label::Create(L"Choix de l'objet")); |     toolbar_box->PackEnd(sfg::Label::Create(L"Choix de l'objet")); | ||||||
|     toolbar_box->PackEnd(sfg::Separator::Create()); |     toolbar_box->PackEnd(sfg::Separator::Create()); | ||||||
| 
 | 
 | ||||||
|     addCreator(L"Bloc normal", std::bind(&Toolbar::createBlock, this)); |     creators_table = sfg::Table::Create(); | ||||||
|     addCreator(L"Caisse", std::bind(&Toolbar::createMovableBlock, this)); |     creators_table_pos_x = creators_table_pos_y = 0; | ||||||
|     addCreator(L"Joueur", std::bind(&Toolbar::createPlayer, this)); |  | ||||||
|     addCreator(L"Bloc changeur", std::bind(&Toolbar::createSwitchBlock, this)); |  | ||||||
|     addCreator(L"Bloc de fin", std::bind(&Toolbar::createFinishBlock, this)); |  | ||||||
|     addCreator(L"Bloc tueur", std::bind(&Toolbar::createKillBlock, this)); |  | ||||||
| 
 | 
 | ||||||
|     addCreator(L"Bloc de gravité nord", std::bind( |     addCreator("player", std::bind(&Toolbar::createPlayer, this)); | ||||||
|  | 
 | ||||||
|  |     addCreator("block", std::bind(&Toolbar::createBlock, this)); | ||||||
|  |     addCreator("movable_block", std::bind(&Toolbar::createMovableBlock, this)); | ||||||
|  |     addCreator("switch_block", std::bind(&Toolbar::createSwitchBlock, this)); | ||||||
|  |     addCreator("finish_block", std::bind(&Toolbar::createFinishBlock, this)); | ||||||
|  |     addCreator("kill_block", std::bind(&Toolbar::createKillBlock, this)); | ||||||
|  | 
 | ||||||
|  |     addCreator("gravity_block_north", std::bind( | ||||||
|         &Toolbar::createGravityBlock, this, GravityDirection::NORTH |         &Toolbar::createGravityBlock, this, GravityDirection::NORTH | ||||||
|     )); |     )); | ||||||
| 
 | 
 | ||||||
|     addCreator(L"Bloc de gravité est", std::bind( |     addCreator("gravity_block_east", std::bind( | ||||||
|         &Toolbar::createGravityBlock, this, GravityDirection::EAST |         &Toolbar::createGravityBlock, this, GravityDirection::EAST | ||||||
|     )); |     )); | ||||||
| 
 | 
 | ||||||
|     addCreator(L"Bloc de gravité sud", std::bind( |     addCreator("gravity_block_south", std::bind( | ||||||
|         &Toolbar::createGravityBlock, this, GravityDirection::SOUTH |         &Toolbar::createGravityBlock, this, GravityDirection::SOUTH | ||||||
|     )); |     )); | ||||||
| 
 | 
 | ||||||
|     addCreator(L"Bloc de gravité ouest", std::bind( |     addCreator("gravity_block_west", std::bind( | ||||||
|         &Toolbar::createGravityBlock, this, GravityDirection::WEST |         &Toolbar::createGravityBlock, this, GravityDirection::WEST | ||||||
|     )); |     )); | ||||||
| 
 | 
 | ||||||
|  |     // attachement de la liste des créateurs à l'interface
 | ||||||
|  |     toolbar_box->PackEnd(creators_table); | ||||||
|  | 
 | ||||||
|     // on sélectionne le premier créateur par défaut
 |     // on sélectionne le premier créateur par défaut
 | ||||||
|     creators.begin()->first->SetActive(true); |     creators.begin()->first->SetActive(true); | ||||||
| 
 | 
 | ||||||
|  | @ -97,10 +106,27 @@ Toolbar::Toolbar(Editor& editor) : editor(editor) { | ||||||
|     toolbar_window->Add(scrolled_zone); |     toolbar_window->Add(scrolled_zone); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Toolbar::addCreator(sf::String label, std::function<Object::Ptr()> creator) { | void Toolbar::addCreator(std::string path, std::function<Object::Ptr()> creator) { | ||||||
|     sfg::RadioButton::Ptr radio = sfg::RadioButton::Create(label, objects_group); |     // on crée un bouton d'objet correspondant au créateur donné
 | ||||||
|     creators[radio] = creator; |     ObjectButton::Ptr button = ObjectButton::Create( | ||||||
|     toolbar_box->PackEnd(radio); |         sfg::Image::Create( | ||||||
|  |             *editor.getResourceManager().getImage("toolbar_" + path + ".tga") | ||||||
|  |         ), creators_group | ||||||
|  |     ); | ||||||
|  | 
 | ||||||
|  |     creators[button] = creator; | ||||||
|  | 
 | ||||||
|  |     // on ajoute le bouton d'objet à la liste des créateurs
 | ||||||
|  |     creators_table->Attach(button, sf::Rect<sf::Uint32>( | ||||||
|  |         creators_table_pos_x, creators_table_pos_y, 1, 1 | ||||||
|  |     )); | ||||||
|  | 
 | ||||||
|  |     creators_table_pos_x++; | ||||||
|  | 
 | ||||||
|  |     if (creators_table_pos_x >= Toolbar::CREATORS_TABLE_WIDTH) { | ||||||
|  |         creators_table_pos_x = 0; | ||||||
|  |         creators_table_pos_y++; | ||||||
|  |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| Object::Ptr Toolbar::createBlock() { | Object::Ptr Toolbar::createBlock() { | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue