- SelectionManagerImpl -> SelectionManager - EditorContextImpl -> EditorContext - Removed unused SceneManagerImpl and ISceneManager The Impl suffix was inconsistent with Unity naming conventions.
87 lines
2.4 KiB
C++
87 lines
2.4 KiB
C++
#pragma once
|
|
|
|
#include "ISelectionManager.h"
|
|
#include "EventBus.h"
|
|
#include "EditorEvents.h"
|
|
#include <vector>
|
|
#include <algorithm>
|
|
|
|
namespace XCEngine {
|
|
namespace Editor {
|
|
|
|
class SelectionManager : public ISelectionManager {
|
|
public:
|
|
explicit SelectionManager(EventBus& eventBus) : m_eventBus(eventBus) {}
|
|
|
|
void SetSelectedEntity(uint64_t entityId) override {
|
|
if (m_selectedEntities.empty()) {
|
|
m_selectedEntities.push_back(entityId);
|
|
} else {
|
|
m_selectedEntities[0] = entityId;
|
|
m_selectedEntities.resize(1);
|
|
}
|
|
PublishSelectionChanged();
|
|
}
|
|
|
|
void SetSelectedEntities(const std::vector<uint64_t>& entityIds) override {
|
|
m_selectedEntities = entityIds;
|
|
PublishSelectionChanged();
|
|
}
|
|
|
|
void AddToSelection(uint64_t entityId) override {
|
|
if (entityId != 0 && !IsSelected(entityId)) {
|
|
m_selectedEntities.push_back(entityId);
|
|
PublishSelectionChanged();
|
|
}
|
|
}
|
|
|
|
void RemoveFromSelection(uint64_t entityId) override {
|
|
auto it = std::find(m_selectedEntities.begin(), m_selectedEntities.end(), entityId);
|
|
if (it != m_selectedEntities.end()) {
|
|
m_selectedEntities.erase(it);
|
|
PublishSelectionChanged();
|
|
}
|
|
}
|
|
|
|
void ClearSelection() override {
|
|
if (!m_selectedEntities.empty()) {
|
|
m_selectedEntities.clear();
|
|
PublishSelectionChanged();
|
|
}
|
|
}
|
|
|
|
uint64_t GetSelectedEntity() const override {
|
|
return m_selectedEntities.empty() ? 0 : m_selectedEntities.back();
|
|
}
|
|
|
|
const std::vector<uint64_t>& GetSelectedEntities() const override {
|
|
return m_selectedEntities;
|
|
}
|
|
|
|
bool HasSelection() const override {
|
|
return !m_selectedEntities.empty();
|
|
}
|
|
|
|
size_t GetSelectionCount() const override {
|
|
return m_selectedEntities.size();
|
|
}
|
|
|
|
bool IsSelected(uint64_t entityId) const override {
|
|
return std::find(m_selectedEntities.begin(), m_selectedEntities.end(), entityId) != m_selectedEntities.end();
|
|
}
|
|
|
|
private:
|
|
void PublishSelectionChanged() {
|
|
SelectionChangedEvent event;
|
|
event.selectedObjects = m_selectedEntities;
|
|
event.primarySelection = GetSelectedEntity();
|
|
m_eventBus.Publish(event);
|
|
}
|
|
|
|
EventBus& m_eventBus;
|
|
std::vector<uint64_t> m_selectedEntities;
|
|
};
|
|
|
|
}
|
|
}
|