diff options
| author | Seth Riley <17361645+Qudix@users.noreply.github.com> | 2020-11-06 12:02:43 -0600 |
|---|---|---|
| committer | Seth Riley <17361645+Qudix@users.noreply.github.com> | 2020-11-06 12:02:43 -0600 |
| commit | ed1085d5673e0d307a6172eaaa1be1e9d70e2234 (patch) | |
| tree | 1e068a2f08e106c8ce15be7034f19336836cc17a /src/createinstancedialog.h | |
| parent | 34e1d05c28bf4676ed8d3e97e969187a05d215b6 (diff) | |
| parent | b909677c3fc6a7b7a1993d341a2bd420715e292a (diff) | |
Merge branch 'master' of https://github.com/ModOrganizer2/modorganizer into master
Diffstat (limited to 'src/createinstancedialog.h')
| -rw-r--r-- | src/createinstancedialog.h | 138 |
1 files changed, 138 insertions, 0 deletions
diff --git a/src/createinstancedialog.h b/src/createinstancedialog.h new file mode 100644 index 00000000..25e383eb --- /dev/null +++ b/src/createinstancedialog.h @@ -0,0 +1,138 @@ +#ifndef MODORGANIZER_CREATEINSTANCEDIALOG_INCLUDED +#define MODORGANIZER_CREATEINSTANCEDIALOG_INCLUDED + +#include <QDialog> + +namespace MOBase { class IPluginGame; } +namespace Ui { class CreateInstanceDialog; }; +namespace cid { class Page; } + +class PluginContainer; +class Settings; + +class CreateInstanceDialog : public QDialog +{ + Q_OBJECT + +public: + enum Types + { + NoType = 0, + Global, + Portable + }; + + struct Paths + { + QString base; + QString downloads; + QString mods; + QString profiles; + QString overwrite; + QString ini; + + auto operator<=>(const Paths&) const = default; + }; + + struct CreationInfo + { + Types type; + MOBase::IPluginGame* game; + QString gameLocation; + QString gameVariant; + QString instanceName; + QString dataPath; + QString iniPath; + Paths paths; + }; + + + CreateInstanceDialog( + const PluginContainer& pc, Settings* s, QWidget *parent = nullptr); + + ~CreateInstanceDialog(); + + Ui::CreateInstanceDialog* getUI(); + + const PluginContainer& pluginContainer(); + Settings* settings(); + + template <class Page> + void setSinglePage(const QString& instanceName) + { + for (auto&& p : m_pages) { + if (auto* tp=dynamic_cast<Page*>(p.get())) { + tp->setSkip(false); + } else { + p->setSkip(true); + } + } + + setSinglePageImpl(instanceName); + } + + template <class Page> + Page* getPage() + { + for (auto&& p : m_pages) { + if (auto* tp=dynamic_cast<Page*>(p.get())) { + return tp; + } + } + + return nullptr; + } + + void next(); + void back(); + void selectPage(std::size_t i); + void changePage(int d); + void finish(); + + void updateNavigation(); + bool isOnLastPage() const; + + Types instanceType() const; + MOBase::IPluginGame* game() const; + QString gameLocation() const; + QString gameVariant() const; + QString instanceName() const; + QString dataPath() const; + Paths paths() const; + bool switching() const; + + CreationInfo creationInfo() const; + +private: + std::unique_ptr<Ui::CreateInstanceDialog> ui; + const PluginContainer& m_pc; + Settings* m_settings; + std::vector<std::unique_ptr<cid::Page>> m_pages; + QString m_originalNext; + bool m_switching; + bool m_singlePage; + + + void setSinglePageImpl(const QString& instanceName); + + template <class T> + T getSelected(T (cid::Page::*mf)() const) const + { + for (auto&& p : m_pages) { + const auto t = (p.get()->*mf)(); + if (t != T()) { + return t; + } + } + + return T(); + } + + void logCreation(const QString& s); + void logCreation(const std::wstring& s); + + bool canNext() const; + bool canBack() const; +}; + +#endif // MODORGANIZER_CREATEINSTANCEDIALOG_INCLUDED |
