diff --git a/Editor/Space.cpp b/Editor/Space.cpp index e58f87b90..211fca6ad 100644 --- a/Editor/Space.cpp +++ b/Editor/Space.cpp @@ -6,6 +6,10 @@ namespace URDE { static LogVisor::LogModule Log("URDE::Space"); +Space::Space(ViewManager& vm, Class cls, Space* parent) +: m_spaceMenuNode(*this), m_spaceSelectBind(*this), + m_vm(vm), m_class(cls), m_parent(parent) {} + Specter::View* Space::buildSpaceView(Specter::ViewResources& res) { if (usesToolbar()) @@ -13,7 +17,12 @@ Specter::View* Space::buildSpaceView(Specter::ViewResources& res) m_spaceView.reset(new Specter::Space(res, m_vm.rootView(), *this, Specter::Toolbar::Position::Bottom)); Specter::View* sview = buildContentView(res); m_spaceView->setContentView(sview); - buildToolbarView(res, *m_spaceView->toolbar()); + Specter::Toolbar& tb = *m_spaceView->toolbar(); + const std::string* classStr = SpaceMenuNode::lookupClassString(m_class); + m_spaceSelectButton.reset(new Specter::Button(res, tb, &m_spaceSelectBind, + classStr?*classStr:"Unknown Class")); + tb.push_back(m_spaceSelectButton.get()); + buildToolbarView(res, tb); return m_spaceView.get(); } else @@ -25,6 +34,25 @@ Specter::View* Space::buildSpaceView(Specter::ViewResources& res) } } +std::vector Space::SpaceMenuNode::s_subNodeDats = +{ + {Class::ResourceBrowser, "resource_browser", "Resource Browser"} +}; +std::string Space::SpaceMenuNode::s_text = "Space Types"; + +void Space::SpaceMenuNode::initializeStrings(ViewManager& vm) +{ + s_text = vm.translateOr("space_types", s_text.c_str()); + for (SubNodeData& sn : s_subNodeDats) + sn.m_text = vm.translateOr(sn.m_key, sn.m_text.c_str()); +} + +std::unique_ptr Space::SpaceSelectBind::buildMenu(const Specter::Button* button) +{ + return std::unique_ptr(new Specter::Menu(m_space.m_vm.rootView().viewRes(), + *m_space.m_spaceView, &m_space.m_spaceMenuNode)); +} + Specter::View* RootSpace::buildSpaceView(Specter::ViewResources& res) { Specter::View* newRoot = buildContentView(res); diff --git a/Editor/Space.hpp b/Editor/Space.hpp index 616edcbd6..0f180983c 100644 --- a/Editor/Space.hpp +++ b/Editor/Space.hpp @@ -38,6 +38,67 @@ public: static Space* NewSpaceFromConfigStream(ViewManager& vm, Space* parent, ConfigReader& r); static RootSpace* NewRootSpaceFromConfigStream(ViewManager& vm, ConfigReader& r); + struct SpaceMenuNode : Specter::IMenuNode + { + struct SubNodeData : Specter::IMenuNode + { + Class m_cls; + std::string m_key; + std::string m_text; + const std::string* text() const {return &m_text;} + void activated(const boo::SWindowCoord& coord) {} + + SubNodeData(Class cls, const char* key, const char* text) + : m_cls(cls), m_key(key), m_text(text) {} + }; + static std::vector s_subNodeDats; + + struct SubNode : Specter::IMenuNode + { + Space& m_space; + const SubNodeData& m_data; + const std::string* text() const {return &m_data.m_text;} + void activated(const boo::SWindowCoord& coord) {} + + SubNode(Space& space, const SubNodeData& data) : m_space(space), m_data(data) {} + }; + std::vector m_subNodes; + + SpaceMenuNode(Space& space) + { + m_subNodes.reserve(s_subNodeDats.size()); + for (const SubNodeData& sn : s_subNodeDats) + m_subNodes.emplace_back(space, sn); + } + + static std::string s_text; + const std::string* text() const {return &s_text;} + + size_t subNodeCount() const {return m_subNodes.size();} + IMenuNode* subNode(size_t idx) {return &m_subNodes[idx];} + + static void initializeStrings(ViewManager& vm); + static const std::string* lookupClassString(Class cls) + { + for (const SubNodeData& sn : s_subNodeDats) + if (sn.m_cls == cls) + return &sn.m_text; + return nullptr; + } + } m_spaceMenuNode; + + struct SpaceSelectBind : Specter::IButtonBinding + { + Space& m_space; + const char* name(const Specter::Control* control) const {return SpaceMenuNode::s_text.c_str();} + + MenuStyle menuStyle(const Specter::Button* button) const {return MenuStyle::Primary;} + std::unique_ptr buildMenu(const Specter::Button* button); + + SpaceSelectBind(Space& space) : m_space(space) {} + } m_spaceSelectBind; + std::unique_ptr m_spaceSelectButton; + protected: friend class ViewManager; friend class RootSpace; @@ -45,7 +106,7 @@ protected: Class m_class = Class::None; Space* m_parent; std::unique_ptr m_spaceView; - Space(ViewManager& vm, Class cls, Space* parent) : m_vm(vm), m_class(cls), m_parent(parent) {} + Space(ViewManager& vm, Class cls, Space* parent); /* Allows common Space code to access DNA-encoded state */ virtual const Space::State& spaceState() const=0; diff --git a/Editor/ViewManager.cpp b/Editor/ViewManager.cpp index c83fa04f1..b37a74860 100644 --- a/Editor/ViewManager.cpp +++ b/Editor/ViewManager.cpp @@ -80,6 +80,7 @@ ViewManager::ViewManager(HECL::Runtime::FileStoreManager& fileMgr, HECL::CVarMan m_recentProjectsPath(HECL::SysFormat(_S("%s/recent_projects.txt"), fileMgr.getStoreRoot().c_str())), m_recentFilesPath(HECL::SysFormat(_S("%s/recent_files.txt"), fileMgr.getStoreRoot().c_str())) { + Space::SpaceMenuNode::initializeStrings(*this); char path[2048]; HECL::Sstat theStat; diff --git a/hecl b/hecl index c964328bd..a6c4d4296 160000 --- a/hecl +++ b/hecl @@ -1 +1 @@ -Subproject commit c964328bd3c286e6d87d1375549103777045fad8 +Subproject commit a6c4d42965764850e362dbbfef47bd3022af91cd