diff --git a/src/modes/classicmode/classicfactory.cpp b/src/modes/classicmode/classicfactory.cpp index a167b0f..9749635 100644 --- a/src/modes/classicmode/classicfactory.cpp +++ b/src/modes/classicmode/classicfactory.cpp @@ -16,7 +16,6 @@ std::unique_ptr classic::getGame(const std::shared_ptr(core_factory); const auto timeline = std::make_shared>(); - const auto selection_manager = std::make_shared(); const auto graphics_manager = std::make_shared>(timeline, factory, visibility_offset); return std::make_unique(timeline, graphics_manager); @@ -29,7 +28,7 @@ std::unique_ptr classic::getEditor(const std::shared_ptr(core_factory); const auto timeline = std::make_shared>(); - const auto selection_manager = std::make_shared(); + const auto selection_manager = std::make_shared>(); const auto graphics_manager = std::make_shared>(timeline, factory, visibility_offset); return std::make_unique(timeline, graphics_manager, selection_manager); diff --git a/src/modes/classicmode/editor/classiceditor.cpp b/src/modes/classicmode/editor/classiceditor.cpp index c307a70..f665447 100644 --- a/src/modes/classicmode/editor/classiceditor.cpp +++ b/src/modes/classicmode/editor/classiceditor.cpp @@ -13,7 +13,7 @@ ClassicEditor::ClassicEditor(const std::shared_ptr>& timeline, const std::shared_ptr& graphics_manager, - const std::shared_ptr& selection_manager) : + const std::shared_ptr>& selection_manager) : _timeline(timeline), _graphics_manager(graphics_manager), _selection_manager(selection_manager), @@ -165,7 +165,6 @@ void ClassicEditor::update(kku::UpdateData&& updatedata) void ClassicEditor::display() const { _graphics_manager->display(); - _selection_manager->display(); } void ClassicEditor::recalculate(const kku::microsec& timestamp) diff --git a/src/modes/classicmode/editor/classiceditor.h b/src/modes/classicmode/editor/classiceditor.h index c9c471a..e2aaa8d 100644 --- a/src/modes/classicmode/editor/classiceditor.h +++ b/src/modes/classicmode/editor/classiceditor.h @@ -4,19 +4,19 @@ #include "core/editor.h" #include "core/timeline.h" +#include "selectionmanager.h" #include "classicmocknote.h" #include "classicmode/classicactions.h" class ClassicGraphicsManager; -class SelectionManager; class ClassicEditor : public kku::Editor { public: explicit ClassicEditor(const std::shared_ptr>& timeline, const std::shared_ptr& graphics_manager, - const std::shared_ptr& selection_manager); + const std::shared_ptr>& selection_manager); virtual void input(kku::GameEvent&& input) override; virtual void update(kku::UpdateData&& updatedata) override; @@ -30,7 +30,7 @@ private: const std::shared_ptr> _timeline; const std::shared_ptr _graphics_manager; - const std::shared_ptr _selection_manager; + const std::shared_ptr> _selection_manager; Type _selected_type; kku::microsec _current_time; diff --git a/src/modes/classicmode/editor/classicmocknote.cpp b/src/modes/classicmode/editor/classicmocknote.cpp index b1e1e76..356e8a4 100644 --- a/src/modes/classicmode/editor/classicmocknote.cpp +++ b/src/modes/classicmode/editor/classicmocknote.cpp @@ -3,7 +3,7 @@ #include "graphics/animations/classicanimationscenario.h" #include "editor/selectionmanager.h" -ClassicMockNote::ClassicMockNote(ArrowNoteInitializer&& init, const std::shared_ptr& selection_manager) : +ClassicMockNote::ClassicMockNote(ArrowNoteInitializer&& init, const std::shared_ptr>& selection_manager) : ClassicNote(std::move(init.initializer)), _selection_manager(selection_manager) { @@ -93,3 +93,9 @@ std::vector& ClassicMockNote::getElements() { return _elements; } + +void ClassicMockNote::deselect() +{ + for (auto& element : _elements) + element.selected = false; +} diff --git a/src/modes/classicmode/editor/classicmocknote.h b/src/modes/classicmode/editor/classicmocknote.h index ded60ee..ee5ab3c 100644 --- a/src/modes/classicmode/editor/classicmocknote.h +++ b/src/modes/classicmode/editor/classicmocknote.h @@ -4,13 +4,12 @@ #include "mockelement.h" #include "classicmode/arrownoteinitializer.h" - -class SelectionManager; +#include "selectionmanager.h" class ClassicMockNote : public ClassicNote { public: - explicit ClassicMockNote(ArrowNoteInitializer&& init, const std::shared_ptr& selection_manager); + explicit ClassicMockNote(ArrowNoteInitializer&& init, const std::shared_ptr>& selection_manager); virtual ~ClassicMockNote() = default; virtual bool isActive(const kku::microsec& offset) const override; @@ -18,9 +17,10 @@ public: virtual void input(kku::GameEvent&& input) override; std::vector& getElements(); + void deselect(); private: - const std::shared_ptr _selection_manager; + const std::shared_ptr> _selection_manager; std::vector _elements; }; diff --git a/src/modes/classicmode/editor/selectionmanager.cpp b/src/modes/classicmode/editor/selectionmanager.cpp deleted file mode 100644 index 40276fd..0000000 --- a/src/modes/classicmode/editor/selectionmanager.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include "selectionmanager.h" -#include "classicmocknote.h" -#include "mockelement.h" -#include "graphics/classicselectiongraphics.h" -#include - -SelectionManager::SelectionManager() : - _multiselection_enabled(false) -{} - -void SelectionManager::discard() -{ - for (const auto& note : _selected_notes) - for (auto& element : note->getElements()) - element.selected = false; - - _selected_notes.clear(); -} - -void SelectionManager::fetch(ClassicMockNote * const note) -{ - bool already_there = std::any_of(_selected_notes.begin(), _selected_notes.end(), - [¬e](const auto& selected_note) - { - return note == selected_note; - }); - - if (!already_there) - _selected_notes.emplace_back(note); -} - -void SelectionManager::remove(ClassicMockNote * const note) -{ - for (std::size_t i = 0; i < _selected_notes.size(); ++i) - { - if (note == _selected_notes.at(i)) - { - _selected_notes[i] = std::move(_selected_notes.back()); - _selected_notes.pop_back(); - break; - } - } -} - -void SelectionManager::enableMultiselection(bool enable) -{ - _multiselection_enabled = enable; -} - -bool SelectionManager::isMultiselectionEnabled() const -{ - return _multiselection_enabled; -} - -void SelectionManager::display() const -{ - for (const auto& note : _selected_notes) - for (const auto& element : note->getElements()) - if (element.selected) - { - element.selection->display(); - } -} diff --git a/src/modes/classicmode/editor/selectionmanager.h b/src/modes/classicmode/editor/selectionmanager.h index 5ff3bbe..cd469c5 100644 --- a/src/modes/classicmode/editor/selectionmanager.h +++ b/src/modes/classicmode/editor/selectionmanager.h @@ -1,27 +1,68 @@ #pragma once -#include "classicmocknote.h" - -#include #include +#include +template class SelectionManager { public: - explicit SelectionManager(); + SelectionManager() : + _multiselection_enabled(false), + deselection([](T* thing) { thing->deselect(); }) + {} // Remove whole selection completely - void discard(); + void discard() + { + apply(deselection); + _selected_things.clear(); + } + + void fetch(T * const thing) + { + bool already_there = std::any_of(_selected_things.begin(), _selected_things.end(), + [&thing](const auto& selected_thing) + { + return thing == selected_thing; + }); + + if (!already_there) + _selected_things.emplace_back(thing); + } - void fetch(ClassicMockNote * const note); - void remove(ClassicMockNote * const note); + void remove(T * const thing) + { + for (std::size_t i = 0; i < _selected_things.size(); ++i) + { + if (thing == _selected_things.at(i)) + { + _selected_things[i] = std::move(_selected_things.back()); + _selected_things.pop_back(); + break; + } + } + } - void enableMultiselection(bool enable = true); - bool isMultiselectionEnabled() const; + void enableMultiselection(bool enable = true) + { + _multiselection_enabled = enable; + } - void display() const; + bool isMultiselectionEnabled() const + { + return _multiselection_enabled; + } + + void apply(const std::function& function) + { + for (auto& thing : _selected_things) + function(thing); + } private: - std::vector _selected_notes; + std::vector _selected_things; bool _multiselection_enabled; + + const std::function deselection; }; diff --git a/src/modes/classicmode/game/classicarrownote.cpp b/src/modes/classicmode/game/classicarrownote.cpp index a167e3c..49d4c70 100644 --- a/src/modes/classicmode/game/classicarrownote.cpp +++ b/src/modes/classicmode/game/classicarrownote.cpp @@ -1,8 +1,9 @@ #include "classicarrownote.h" -#include "graphics/classicscenegraphicsmanager.h" #include "graphics/animations/classicanimationscenario.h" #include "holdmanager.h" +#include + ClassicArrowNote::ClassicArrowNote(ArrowNoteInitializer&& init, const std::shared_ptr& hold_manager) : ClassicNote(std::move(init.initializer)), _evaluator(init.initializer.intervals, _perfect_offset), diff --git a/src/modes/classicmode/game/classicarrownote.h b/src/modes/classicmode/game/classicarrownote.h index 04a8956..b05ac3c 100644 --- a/src/modes/classicmode/game/classicarrownote.h +++ b/src/modes/classicmode/game/classicarrownote.h @@ -2,7 +2,6 @@ #include "arrowelement.h" #include "classicmode/classicnote.h" - #include "classicmode/arrownoteinitializer.h" class HoldManager;