metaforce/Editor/SplashScreen.hpp

165 lines
6.9 KiB
C++
Raw Normal View History

2018-10-07 03:42:33 +00:00
#pragma once
2015-12-13 02:27:34 +00:00
2017-12-29 08:08:12 +00:00
#include "specter/View.hpp"
#include "specter/ModalWindow.hpp"
#include "specter/MultiLineTextView.hpp"
#include "specter/FileBrowser.hpp"
#include "specter/Menu.hpp"
#include "specter/Icon.hpp"
2016-07-16 19:21:12 +00:00
2015-12-13 02:27:34 +00:00
#include "ViewManager.hpp"
2021-04-10 08:42:06 +00:00
namespace metaforce {
2016-03-04 23:04:53 +00:00
static logvisor::Module Log("specter::SplashScreen");
2016-01-02 02:27:46 +00:00
2018-12-08 05:30:43 +00:00
class SplashScreen : public specter::ModalWindow {
ViewManager& m_vm;
zeus::CColor m_textColor;
zeus::CColor m_textColorClear;
std::unique_ptr<specter::TextView> m_title;
std::string m_buildInfoStr;
std::unique_ptr<specter::MultiLineTextView> m_buildInfo;
std::unique_ptr<specter::IconView> m_badgeIcon;
std::unique_ptr<specter::TextView> m_badgeText;
std::string m_newString;
specter::ViewChild<std::unique_ptr<specter::Button>> m_newButt;
std::string m_openString;
specter::ViewChild<std::unique_ptr<specter::Button>> m_openButt;
std::string m_extractString;
specter::ViewChild<std::unique_ptr<specter::Button>> m_extractButt;
specter::ViewChild<std::unique_ptr<specter::FileBrowser>> m_fileBrowser;
struct NewProjBinding : specter::IButtonBinding {
SplashScreen& m_splash;
hecl::SystemString m_deferPath;
NewProjBinding(SplashScreen& splash) : m_splash(splash) {}
std::string_view name(const specter::Control* control) const override { return m_splash.m_newString.c_str(); }
std::string_view help(const specter::Control* control) const override {
return "Creates an empty project at selected path";
}
void activated(const specter::Button* button, const boo::SWindowCoord& coord) override {
2018-12-08 05:30:43 +00:00
m_splash.m_fileBrowser.m_view.reset(new specter::FileBrowser(
m_splash.rootView().viewRes(), m_splash, m_splash.m_newString, specter::FileBrowser::Type::NewHECLProject,
[&](bool ok, hecl::SystemStringView path) {
if (ok)
m_deferPath = path;
}));
m_splash.updateSize();
m_splash.m_newButt.mouseLeave(coord);
}
} m_newProjBind;
struct OpenProjBinding : specter::IButtonBinding {
SplashScreen& m_splash;
hecl::SystemString m_deferPath;
OpenProjBinding(SplashScreen& splash) : m_splash(splash), m_openRecentMenuRoot(*this) {}
std::string_view name(const specter::Control* control) const override { return m_splash.m_openString.c_str(); }
std::string_view help(const specter::Control* control) const override {
2018-12-08 05:30:43 +00:00
return "Opens an existing project at selected path";
}
void activated(const specter::Button* button, const boo::SWindowCoord& coord) override {
2018-12-08 05:30:43 +00:00
m_splash.m_fileBrowser.m_view.reset(new specter::FileBrowser(
m_splash.rootView().viewRes(), m_splash, m_splash.m_openString, specter::FileBrowser::Type::OpenHECLProject,
[&](bool ok, hecl::SystemStringView path) {
if (ok)
m_deferPath = path;
}));
m_splash.updateSize();
m_splash.m_openButt.mouseLeave(coord);
}
struct OpenRecentMenuRoot : specter::IMenuNode {
OpenProjBinding& m_openProjBind;
OpenRecentMenuRoot(OpenProjBinding& openProjBind) : m_openProjBind(openProjBind) {}
std::string m_text;
const std::string* text() const override { return &m_text; }
2018-12-08 05:30:43 +00:00
struct OpenRecentMenuItem final : specter::IMenuNode {
OpenRecentMenuRoot& m_parent;
hecl::SystemString m_path;
std::string m_text;
const std::string* text() const override { return &m_text; }
void activated(const boo::SWindowCoord& coord) override {
2018-12-08 05:30:43 +00:00
m_parent.m_openProjBind.m_deferPath = m_path;
m_parent.m_openProjBind.m_splash.m_openButt.m_view->closeMenu(coord);
2015-12-13 21:01:32 +00:00
}
2016-01-15 03:38:03 +00:00
2018-12-08 05:30:43 +00:00
OpenRecentMenuItem(OpenRecentMenuRoot& parent, const hecl::SystemString& path)
: m_parent(parent), m_path(path) {
std::vector<hecl::SystemString> pathComps = specter::FileBrowser::PathComponents(path);
if (pathComps.size())
m_text = hecl::SystemUTF8Conv(pathComps.back()).str();
2016-01-15 03:38:03 +00:00
}
2018-12-08 05:30:43 +00:00
};
std::vector<OpenRecentMenuItem> m_items;
size_t subNodeCount() const override { return m_items.size(); }
specter::IMenuNode* subNode(size_t idx) override { return &m_items[idx]; }
2018-12-08 05:30:43 +00:00
void buildNodes(const std::vector<hecl::SystemString>* recentProjects) {
m_items.clear();
if (recentProjects) {
m_items.reserve(recentProjects->size());
for (const hecl::SystemString& path : *recentProjects)
m_items.emplace_back(*this, path);
2015-12-13 21:01:32 +00:00
}
2018-12-08 05:30:43 +00:00
}
} m_openRecentMenuRoot;
MenuStyle menuStyle(const specter::Button* button) const override { return MenuStyle::Auxiliary; }
std::unique_ptr<View> buildMenu(const specter::Button* button) override {
2018-12-08 05:30:43 +00:00
m_openRecentMenuRoot.buildNodes(m_splash.m_vm.recentProjects());
return std::unique_ptr<View>(new specter::Menu(m_splash.rootView().viewRes(), m_splash, &m_openRecentMenuRoot));
}
} m_openProjBind;
struct ExtractProjBinding : specter::IButtonBinding {
SplashScreen& m_splash;
hecl::SystemString m_deferPath;
ExtractProjBinding(SplashScreen& splash) : m_splash(splash) {}
std::string_view name(const specter::Control* control) const override { return m_splash.m_extractString.c_str(); }
std::string_view help(const specter::Control* control) const override {
2018-12-08 05:30:43 +00:00
return "Extracts game image as project at selected path";
}
void activated(const specter::Button* button, const boo::SWindowCoord& coord) override {
2018-12-08 05:30:43 +00:00
m_splash.m_fileBrowser.m_view.reset(
new specter::FileBrowser(m_splash.rootView().viewRes(), m_splash, m_splash.m_extractString,
specter::FileBrowser::Type::OpenFile, [&](bool ok, hecl::SystemStringView path) {
if (ok)
m_deferPath = path;
}));
m_splash.updateSize();
m_splash.m_extractButt.mouseLeave(coord);
}
} m_extractProjBind;
2015-12-13 21:01:32 +00:00
2015-12-13 02:27:34 +00:00
public:
2018-12-08 05:30:43 +00:00
SplashScreen(ViewManager& vm, specter::ViewResources& res);
void think() override;
void updateContentOpacity(float opacity) override;
void mouseDown(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey) override;
void mouseUp(const boo::SWindowCoord&, boo::EMouseButton, boo::EModifierKey) override;
void mouseMove(const boo::SWindowCoord&) override;
void mouseEnter(const boo::SWindowCoord&) override;
void mouseLeave(const boo::SWindowCoord&) override;
void scroll(const boo::SWindowCoord&, const boo::SScrollDelta&) override;
void touchDown(const boo::STouchCoord&, uintptr_t) override;
void touchUp(const boo::STouchCoord&, uintptr_t) override;
void touchMove(const boo::STouchCoord&, uintptr_t) override;
void charKeyDown(unsigned long, boo::EModifierKey, bool) override;
void specialKeyDown(boo::ESpecialKey, boo::EModifierKey, bool) override;
void resized(const boo::SWindowRect& root, const boo::SWindowRect& sub) override;
void draw(boo::IGraphicsCommandQueue* gfxQ) override;
2015-12-13 02:27:34 +00:00
};
2021-04-10 08:42:06 +00:00
} // namespace metaforce