Séparation des deux barres d'outils
This commit is contained in:
parent
dd59bb2b45
commit
4e824e92dc
|
@ -0,0 +1,41 @@
|
||||||
|
#ifndef __SKIZZLE_ACTION_TOOLBAR_HPP__
|
||||||
|
#define __SKIZZLE_ACTION_TOOLBAR_HPP__
|
||||||
|
|
||||||
|
#include <SFGUI/Widgets.hpp>
|
||||||
|
#include <SFML/Graphics.hpp>
|
||||||
|
#include "../objects/object.hpp"
|
||||||
|
#include "../states/level.hpp"
|
||||||
|
#include "object_button.hpp"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Barre d'outils pour les actions en jeu
|
||||||
|
*/
|
||||||
|
class ActionToolbar {
|
||||||
|
private:
|
||||||
|
// widgets de la barre
|
||||||
|
sfg::Window::Ptr toolbar_window;
|
||||||
|
sfg::Box::Ptr toolbar_box;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ActionToolbar();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Ajoute un nouveau bouton d'action à la barre d'outils
|
||||||
|
*/
|
||||||
|
void addButton(
|
||||||
|
sf::Image image,
|
||||||
|
std::function<void()> callback = std::function<void()>()
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récupère la fenêtre de la barre d'outils
|
||||||
|
*/
|
||||||
|
sfg::Window::Ptr getWindow();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Récupère la taille désirée par la barre d'outils
|
||||||
|
*/
|
||||||
|
float getHeight();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
|
@ -1,44 +1,23 @@
|
||||||
#ifndef __SKIZZLE_TOOLBAR_HPP__
|
#ifndef __SKIZZLE_OBJECT_TOOLBAR_HPP__
|
||||||
#define __SKIZZLE_TOOLBAR_HPP__
|
#define __SKIZZLE_OBJECT_TOOLBAR_HPP__
|
||||||
|
|
||||||
#include <SFGUI/Widgets.hpp>
|
#include <SFGUI/Widgets.hpp>
|
||||||
#include <SFML/Graphics.hpp>
|
#include <SFML/Graphics.hpp>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include "../objects/object.hpp"
|
|
||||||
#include "../states/level.hpp"
|
#include "../states/level.hpp"
|
||||||
|
#include "../objects/object.hpp"
|
||||||
#include "object_button.hpp"
|
#include "object_button.hpp"
|
||||||
|
|
||||||
class Editor;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Barre d'outils pour l'éditeur
|
* Barre d'outils qui affiche une liste d'objets à choisir
|
||||||
*/
|
*/
|
||||||
class Toolbar {
|
class ObjectToolbar {
|
||||||
private:
|
private:
|
||||||
Editor& editor;
|
|
||||||
|
|
||||||
// widgets de la barre
|
// widgets de la barre
|
||||||
sfg::Window::Ptr toolbar_window;
|
sfg::Window::Ptr toolbar_window;
|
||||||
sfg::Box::Ptr toolbar_box;
|
sfg::Box::Ptr toolbar_box;
|
||||||
|
|
||||||
// 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
|
// 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;
|
||||||
|
@ -67,7 +46,7 @@ private:
|
||||||
Object::Ptr createGravityBlock(GravityDirection direction);
|
Object::Ptr createGravityBlock(GravityDirection direction);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Toolbar(Editor& editor);
|
ObjectToolbar();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Crée un nouvel objet du type actuellement sélectionné
|
* Crée un nouvel objet du type actuellement sélectionné
|
||||||
|
@ -79,11 +58,6 @@ 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
|
||||||
*/
|
*/
|
|
@ -0,0 +1,38 @@
|
||||||
|
#include "gui/action_toolbar.hpp"
|
||||||
|
|
||||||
|
ActionToolbar::ActionToolbar() {
|
||||||
|
// création de la boîte de la barre d'outils
|
||||||
|
toolbar_box = sfg::Box::Create(sfg::Box::Orientation::HORIZONTAL, 5.f);
|
||||||
|
|
||||||
|
// création de la fenêtre
|
||||||
|
toolbar_window = sfg::Window::Create(
|
||||||
|
sfg::Window::Style::BACKGROUND |
|
||||||
|
sfg::Window::Style::SHADOW
|
||||||
|
);
|
||||||
|
|
||||||
|
toolbar_window->Add(toolbar_box);
|
||||||
|
|
||||||
|
// pour les styles
|
||||||
|
toolbar_window->SetId("action_toolbar");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ActionToolbar::addButton(sf::Image image, std::function<void()> callback) {
|
||||||
|
// création d'un bouton avec pour image l'image passée
|
||||||
|
ObjectButton::Ptr button = ObjectButton::Create(sfg::Image::Create(image));
|
||||||
|
|
||||||
|
// liaison du bouton avec la callback, s'il y en a une
|
||||||
|
if (callback) {
|
||||||
|
button->GetSignal(sfg::Widget::OnLeftClick).Connect(callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ajout du bouton à la barre
|
||||||
|
toolbar_box->PackEnd(button, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
sfg::Window::Ptr ActionToolbar::getWindow() {
|
||||||
|
return toolbar_window;
|
||||||
|
}
|
||||||
|
|
||||||
|
float ActionToolbar::getHeight() {
|
||||||
|
return toolbar_window->GetRequisition().y;
|
||||||
|
}
|
|
@ -0,0 +1,145 @@
|
||||||
|
#include "resource_manager.hpp"
|
||||||
|
#include "objects/block.hpp"
|
||||||
|
#include "objects/player.hpp"
|
||||||
|
#include "objects/switch_block.hpp"
|
||||||
|
#include "objects/gravity_block.hpp"
|
||||||
|
#include "objects/kill_block.hpp"
|
||||||
|
#include "objects/finish_block.hpp"
|
||||||
|
#include "gui/object_toolbar.hpp"
|
||||||
|
|
||||||
|
const int ObjectToolbar::CREATORS_TABLE_WIDTH = 2;
|
||||||
|
|
||||||
|
ObjectToolbar::ObjectToolbar() {
|
||||||
|
// création de la boîte de la barre d'outils
|
||||||
|
toolbar_box = sfg::Box::Create(sfg::Box::Orientation::VERTICAL, 5.f);
|
||||||
|
|
||||||
|
// mise en place de la liste des créateurs d'objets
|
||||||
|
creators_group = sfg::RadioButtonGroup::Create();
|
||||||
|
toolbar_box->PackEnd(sfg::Label::Create(L"Objets"));
|
||||||
|
toolbar_box->PackEnd(sfg::Separator::Create());
|
||||||
|
|
||||||
|
creators_table = sfg::Table::Create();
|
||||||
|
creators_table_pos_x = creators_table_pos_y = 0;
|
||||||
|
|
||||||
|
addCreator("block", std::bind(&ObjectToolbar::createBlock, this));
|
||||||
|
addCreator("movable_block", std::bind(&ObjectToolbar::createMovableBlock, this));
|
||||||
|
addCreator("player", std::bind(&ObjectToolbar::createPlayer, this));
|
||||||
|
addCreator("switch_block", std::bind(&ObjectToolbar::createSwitchBlock, this));
|
||||||
|
addCreator("finish_block", std::bind(&ObjectToolbar::createFinishBlock, this));
|
||||||
|
addCreator("kill_block", std::bind(&ObjectToolbar::createKillBlock, this));
|
||||||
|
|
||||||
|
addCreator("gravity_block_north", std::bind(
|
||||||
|
&ObjectToolbar::createGravityBlock, this, GravityDirection::NORTH
|
||||||
|
));
|
||||||
|
|
||||||
|
addCreator("gravity_block_east", std::bind(
|
||||||
|
&ObjectToolbar::createGravityBlock, this, GravityDirection::EAST
|
||||||
|
));
|
||||||
|
|
||||||
|
addCreator("gravity_block_south", std::bind(
|
||||||
|
&ObjectToolbar::createGravityBlock, this, GravityDirection::SOUTH
|
||||||
|
));
|
||||||
|
|
||||||
|
addCreator("gravity_block_west", std::bind(
|
||||||
|
&ObjectToolbar::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
|
||||||
|
creators.begin()->first->SetActive(true);
|
||||||
|
|
||||||
|
// création de la fenêtre de la barre d'outils
|
||||||
|
sfg::ScrolledWindow::Ptr scrolled_zone = sfg::ScrolledWindow::Create();
|
||||||
|
toolbar_window = sfg::Window::Create(sfg::Window::Style::BACKGROUND);
|
||||||
|
|
||||||
|
scrolled_zone->SetScrollbarPolicy(
|
||||||
|
sfg::ScrolledWindow::ScrollbarPolicy::VERTICAL_AUTOMATIC |
|
||||||
|
sfg::ScrolledWindow::ScrollbarPolicy::HORIZONTAL_NEVER
|
||||||
|
);
|
||||||
|
|
||||||
|
scrolled_zone->AddWithViewport(toolbar_box);
|
||||||
|
toolbar_window->Add(scrolled_zone);
|
||||||
|
|
||||||
|
// pour les styles
|
||||||
|
toolbar_window->SetId("object_toolbar");
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectToolbar::addCreator(std::string path, std::function<Object::Ptr()> creator) {
|
||||||
|
// on crée un bouton d'objet correspondant au créateur donné
|
||||||
|
ObjectButton::Ptr button = ObjectButton::Create(
|
||||||
|
sfg::Image::Create(
|
||||||
|
*ResourceManager::get().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 >= ObjectToolbar::CREATORS_TABLE_WIDTH) {
|
||||||
|
creators_table_pos_x = 0;
|
||||||
|
creators_table_pos_y++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Object::Ptr ObjectToolbar::createBlock() {
|
||||||
|
return Object::Ptr(new Block);
|
||||||
|
}
|
||||||
|
|
||||||
|
Object::Ptr ObjectToolbar::createMovableBlock() {
|
||||||
|
Object::Ptr movable = Object::Ptr(new Block);
|
||||||
|
movable->setMass(2.f);
|
||||||
|
return movable;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object::Ptr ObjectToolbar::createPlayer() {
|
||||||
|
Object::Ptr player = Object::Ptr(new Player);
|
||||||
|
player->setMass(1.f);
|
||||||
|
return player;
|
||||||
|
}
|
||||||
|
|
||||||
|
Object::Ptr ObjectToolbar::createSwitchBlock() {
|
||||||
|
return Object::Ptr(new SwitchBlock);
|
||||||
|
}
|
||||||
|
|
||||||
|
Object::Ptr ObjectToolbar::createFinishBlock() {
|
||||||
|
return Object::Ptr(new FinishBlock);
|
||||||
|
}
|
||||||
|
|
||||||
|
Object::Ptr ObjectToolbar::createKillBlock() {
|
||||||
|
return Object::Ptr(new KillBlock);
|
||||||
|
}
|
||||||
|
|
||||||
|
Object::Ptr ObjectToolbar::createGravityBlock(GravityDirection direction) {
|
||||||
|
GravityBlock::Ptr gravity_block = GravityBlock::Ptr(new GravityBlock);
|
||||||
|
gravity_block->setGravityDirection(direction);
|
||||||
|
return std::dynamic_pointer_cast<Object>(gravity_block);
|
||||||
|
}
|
||||||
|
|
||||||
|
Object::Ptr ObjectToolbar::createObject() {
|
||||||
|
for (auto const &creator : creators) {
|
||||||
|
// on recherche le bouton actif actuellement, si on
|
||||||
|
// le trouve, on appelle le créateur associé
|
||||||
|
if (creator.first->IsActive()) {
|
||||||
|
return creator.second();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// on n'a aucun bouton actif, on renvoie nullptr
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
sfg::Window::Ptr ObjectToolbar::getWindow() {
|
||||||
|
return toolbar_window;
|
||||||
|
}
|
||||||
|
|
||||||
|
float ObjectToolbar::getWidth() {
|
||||||
|
return toolbar_window->GetRequisition().x;
|
||||||
|
}
|
|
@ -1,267 +0,0 @@
|
||||||
#include <boost/filesystem.hpp>
|
|
||||||
#include "resource_manager.hpp"
|
|
||||||
#include "states/editor.hpp"
|
|
||||||
#include "objects/block.hpp"
|
|
||||||
#include "objects/player.hpp"
|
|
||||||
#include "objects/switch_block.hpp"
|
|
||||||
#include "objects/gravity_block.hpp"
|
|
||||||
#include "objects/kill_block.hpp"
|
|
||||||
#include "objects/finish_block.hpp"
|
|
||||||
#include "gui/toolbar.hpp"
|
|
||||||
|
|
||||||
const int Toolbar::CREATORS_TABLE_WIDTH = 3;
|
|
||||||
|
|
||||||
Toolbar::Toolbar(Editor& editor) : editor(editor) {
|
|
||||||
// création de la boîte de la barre d'outils
|
|
||||||
toolbar_box = sfg::Box::Create(sfg::Box::Orientation::VERTICAL, 5.f);
|
|
||||||
creators_group = sfg::RadioButtonGroup::Create();
|
|
||||||
|
|
||||||
// ajout des boutons de contrôle
|
|
||||||
sfg::Button::Ptr test_button = sfg::Button::Create(L"Tester");
|
|
||||||
sfg::Button::Ptr save_button = sfg::Button::Create(L"Sauvegarder");
|
|
||||||
|
|
||||||
test_button->GetSignal(sfg::Widget::OnLeftClick).Connect(
|
|
||||||
std::bind(&Editor::test, &editor)
|
|
||||||
);
|
|
||||||
|
|
||||||
save_button->GetSignal(sfg::Widget::OnLeftClick).Connect(
|
|
||||||
std::bind(&Editor::save, &editor)
|
|
||||||
);
|
|
||||||
|
|
||||||
toolbar_box->PackEnd(test_button);
|
|
||||||
toolbar_box->PackEnd(save_button);
|
|
||||||
|
|
||||||
// ajout des zones de textes pour les métadonnées
|
|
||||||
sfg::Alignment::Ptr info_spacer = sfg::Alignment::Create();
|
|
||||||
info_spacer->SetRequisition(sf::Vector2f(1, 5));
|
|
||||||
|
|
||||||
toolbar_box->PackEnd(info_spacer);
|
|
||||||
toolbar_box->PackEnd(sfg::Label::Create(L"Informations"));
|
|
||||||
toolbar_box->PackEnd(sfg::Separator::Create());
|
|
||||||
|
|
||||||
name_entry = sfg::Entry::Create();
|
|
||||||
path_entry = sfg::Entry::Create();
|
|
||||||
|
|
||||||
name_entry->GetSignal(sfg::Entry::OnTextChanged).Connect(
|
|
||||||
std::bind(&Toolbar::updateEditorName, this)
|
|
||||||
);
|
|
||||||
|
|
||||||
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<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(music_combo);
|
|
||||||
|
|
||||||
// mise en place de la liste des créateurs d'objets
|
|
||||||
sfg::Alignment::Ptr creators_spacer = sfg::Alignment::Create();
|
|
||||||
creators_spacer->SetRequisition(sf::Vector2f(1, 5));
|
|
||||||
|
|
||||||
toolbar_box->PackEnd(creators_spacer);
|
|
||||||
toolbar_box->PackEnd(sfg::Label::Create(L"Choix de l'objet"));
|
|
||||||
toolbar_box->PackEnd(sfg::Separator::Create());
|
|
||||||
|
|
||||||
creators_table = sfg::Table::Create();
|
|
||||||
creators_table_pos_x = creators_table_pos_y = 0;
|
|
||||||
|
|
||||||
addCreator("block", std::bind(&Toolbar::createBlock, this));
|
|
||||||
addCreator("movable_block", std::bind(&Toolbar::createMovableBlock, this));
|
|
||||||
addCreator("player", std::bind(&Toolbar::createPlayer, 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
|
|
||||||
));
|
|
||||||
|
|
||||||
addCreator("gravity_block_east", std::bind(
|
|
||||||
&Toolbar::createGravityBlock, this, GravityDirection::EAST
|
|
||||||
));
|
|
||||||
|
|
||||||
addCreator("gravity_block_south", std::bind(
|
|
||||||
&Toolbar::createGravityBlock, this, GravityDirection::SOUTH
|
|
||||||
));
|
|
||||||
|
|
||||||
addCreator("gravity_block_west", std::bind(
|
|
||||||
&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
|
|
||||||
creators.begin()->first->SetActive(true);
|
|
||||||
|
|
||||||
// création de la fenêtre de la barre d'outils
|
|
||||||
sfg::ScrolledWindow::Ptr scrolled_zone = sfg::ScrolledWindow::Create();
|
|
||||||
toolbar_window = sfg::Window::Create(sfg::Window::Style::BACKGROUND);
|
|
||||||
|
|
||||||
scrolled_zone->SetScrollbarPolicy(
|
|
||||||
sfg::ScrolledWindow::ScrollbarPolicy::VERTICAL_AUTOMATIC |
|
|
||||||
sfg::ScrolledWindow::ScrollbarPolicy::HORIZONTAL_NEVER
|
|
||||||
);
|
|
||||||
|
|
||||||
scrolled_zone->AddWithViewport(toolbar_box);
|
|
||||||
toolbar_window->Add(scrolled_zone);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Toolbar::addCreator(std::string path, std::function<Object::Ptr()> creator) {
|
|
||||||
// on crée un bouton d'objet correspondant au créateur donné
|
|
||||||
ObjectButton::Ptr button = ObjectButton::Create(
|
|
||||||
sfg::Image::Create(
|
|
||||||
*ResourceManager::get().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() {
|
|
||||||
return Object::Ptr(new Block);
|
|
||||||
}
|
|
||||||
|
|
||||||
Object::Ptr Toolbar::createMovableBlock() {
|
|
||||||
Object::Ptr movable = Object::Ptr(new Block);
|
|
||||||
movable->setMass(2.f);
|
|
||||||
return movable;
|
|
||||||
}
|
|
||||||
|
|
||||||
Object::Ptr Toolbar::createPlayer() {
|
|
||||||
Object::Ptr player = Object::Ptr(new Player);
|
|
||||||
player->setMass(1.f);
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
|
|
||||||
Object::Ptr Toolbar::createSwitchBlock() {
|
|
||||||
return Object::Ptr(new SwitchBlock);
|
|
||||||
}
|
|
||||||
|
|
||||||
Object::Ptr Toolbar::createFinishBlock() {
|
|
||||||
return Object::Ptr(new FinishBlock);
|
|
||||||
}
|
|
||||||
|
|
||||||
Object::Ptr Toolbar::createKillBlock() {
|
|
||||||
return Object::Ptr(new KillBlock);
|
|
||||||
}
|
|
||||||
|
|
||||||
Object::Ptr Toolbar::createGravityBlock(GravityDirection direction) {
|
|
||||||
GravityBlock::Ptr gravity_block = GravityBlock::Ptr(new GravityBlock);
|
|
||||||
gravity_block->setGravityDirection(direction);
|
|
||||||
return std::dynamic_pointer_cast<Object>(gravity_block);
|
|
||||||
}
|
|
||||||
|
|
||||||
Object::Ptr Toolbar::createObject() {
|
|
||||||
for (auto const &creator : creators) {
|
|
||||||
// on recherche le bouton actif actuellement, si on
|
|
||||||
// le trouve, on appelle le créateur associé
|
|
||||||
if (creator.first->IsActive()) {
|
|
||||||
return creator.second();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// on n'a aucun bouton actif, on renvoie 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() {
|
|
||||||
if (name_entry->GetText() != editor.getName()) {
|
|
||||||
name_entry->SetText(editor.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (path_entry->GetText().toAnsiString() != editor.getPath()) {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
float Toolbar::getWidth() {
|
|
||||||
return toolbar_window->GetRequisition().x;
|
|
||||||
}
|
|
Loading…
Reference in New Issue