Suppression d'objets en drag&drop dans éditeur
This commit is contained in:
parent
b4b8aaedac
commit
2daa1e8aa6
|
@ -5,7 +5,7 @@
|
||||||
#include "level.hpp"
|
#include "level.hpp"
|
||||||
#include "util/widget_timer.hpp"
|
#include "util/widget_timer.hpp"
|
||||||
|
|
||||||
enum class DragMode {NONE, PLACE_OBJECTS, SELECT_RECT, SELECT_BULK};
|
enum class DragMode {NONE, PLACE, SELECT_RECT, SELECT_BULK, REMOVE};
|
||||||
enum class SelectionMode {REPLACE, FLIP, ADD};
|
enum class SelectionMode {REPLACE, FLIP, ADD};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -67,20 +67,25 @@ bool Editor::processEvent(const sf::Event& event) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// clic gauche dans le vide : démarrage du placement
|
// clic gauche dans le vide : démarrage du placement en drag&drop
|
||||||
// en drag&ndrop
|
|
||||||
drag_start = position;
|
drag_start = position;
|
||||||
drag_end = position;
|
drag_end = position;
|
||||||
drag_mode = DragMode::PLACE_OBJECTS;
|
drag_mode = DragMode::PLACE;
|
||||||
|
|
||||||
select(addObject(position), SelectionMode::REPLACE);
|
select(addObject(position), SelectionMode::REPLACE);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (event.mouseButton.button == sf::Mouse::Right) {
|
if (event.mouseButton.button == sf::Mouse::Right) {
|
||||||
// clic droit : on supprime l'objet pointé
|
// clic droit sur un objet : démarrage de la suppression en drag&drop
|
||||||
removeObject(pointed_object);
|
if (pointed_object != nullptr) {
|
||||||
return true;
|
drag_start = position;
|
||||||
|
drag_end = position;
|
||||||
|
drag_mode = DragMode::REMOVE;
|
||||||
|
|
||||||
|
removeObject(pointed_object);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,11 +96,17 @@ bool Editor::processEvent(const sf::Event& event) {
|
||||||
drag_end = position;
|
drag_end = position;
|
||||||
|
|
||||||
// mode placement d'objets
|
// mode placement d'objets
|
||||||
if (drag_mode == DragMode::PLACE_OBJECTS && pointed_object == nullptr) {
|
if (drag_mode == DragMode::PLACE && pointed_object == nullptr) {
|
||||||
select(addObject(position), SelectionMode::ADD);
|
select(addObject(position), SelectionMode::ADD);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// mode suppression d'objets
|
||||||
|
if (drag_mode == DragMode::REMOVE && pointed_object != nullptr) {
|
||||||
|
removeObject(pointed_object);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// mode sélection libre : on l'objet à la sélection
|
// mode sélection libre : on l'objet à la sélection
|
||||||
if (drag_mode == DragMode::SELECT_BULK) {
|
if (drag_mode == DragMode::SELECT_BULK) {
|
||||||
select(position, SelectionMode::ADD);
|
select(position, SelectionMode::ADD);
|
||||||
|
@ -113,7 +124,7 @@ bool Editor::processEvent(const sf::Event& event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
drag_mode = DragMode::NONE;
|
drag_mode = DragMode::NONE;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// gestion des touches
|
// gestion des touches
|
||||||
|
@ -228,7 +239,7 @@ void Editor::removeObject(ObjectPtr object) {
|
||||||
// on supprime l'objet de la liste d'objets
|
// on supprime l'objet de la liste d'objets
|
||||||
objects.erase(std::remove(
|
objects.erase(std::remove(
|
||||||
objects.begin(), objects.end(), object
|
objects.begin(), objects.end(), object
|
||||||
), selection.end());
|
), objects.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::removeObject(sf::Vector2f position) {
|
void Editor::removeObject(sf::Vector2f position) {
|
||||||
|
|
Loading…
Reference in New Issue