diff options
-rw-r--r-- | core/CMakeLists.txt | 2 | ||||
-rw-r--r-- | core/locale/zh_CN.json | 11 | ||||
-rw-r--r-- | core/src/Entrypoint/main.cpp | 5 | ||||
-rw-r--r-- | core/src/Model/Project.cpp | 15 | ||||
-rw-r--r-- | core/src/Model/Project.hpp | 17 | ||||
-rw-r--r-- | core/src/Model/fwd.hpp | 3 | ||||
-rw-r--r-- | core/src/UI/Localization.hpp | 11 | ||||
-rw-r--r-- | core/src/UI/States.cpp | 13 | ||||
-rw-r--r-- | core/src/UI/States.hpp | 14 | ||||
-rw-r--r-- | core/src/UI/UI_MainWindow.cpp | 64 | ||||
-rw-r--r-- | core/src/UI/fwd.hpp | 3 | ||||
-rw-r--r-- | core/src/Utils/I18n.cpp | 4 | ||||
-rw-r--r-- | core/src/Utils/I18n.hpp | 2 |
13 files changed, 128 insertions, 36 deletions
diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index e39512d..3f8fb12 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -34,11 +34,13 @@ set(ENTRYPOINT_MODULE_SOURCES ) add_source_group(MODEL_MODULE_SOURCES + src/Model/Project.cpp src/Model/Stock.cpp ) add_source_group(UI_MODULE_SOURCES src/UI/Localization.cpp + src/UI/States.cpp src/UI/UI_DatabaseView.cpp src/UI/UI_Export.cpp src/UI/UI_Items.cpp diff --git a/core/locale/zh_CN.json b/core/locale/zh_CN.json index e986041..d455f61 100644 --- a/core/locale/zh_CN.json +++ b/core/locale/zh_CN.json @@ -1,11 +1,12 @@ { "$localized_name": "中文 - 中国", - "MenuBar.File": "文件", - "MenuBar.File.NewWindow": "新建窗口", - "MenuBar.File.NewProject": "新建项目...", - "MenuBar.File.OpenProject": "打开项目...", "MainWindow.Tab.Settings": "\uf013 设置", + "MainWindow.Tab.Project": "\uf15b 项目", "MainWindow.Tab.DatabaseView": "\uf1c0 数据", "MainWindow.Tab.Items": "\uf466 物品", - "MainWindow.Tab.Exports": "\uf56e 导出" + "MainWindow.Tab.Exports": "\uf56e 导出", + "Project.NewProject": "新建项目...", + "Project.OpenProject": "打开项目...", + "Project.Recents": "最近使用", + "Project.ClearRecents": "清空", }
\ No newline at end of file diff --git a/core/src/Entrypoint/main.cpp b/core/src/Entrypoint/main.cpp index 9f57a5e..39943d6 100644 --- a/core/src/Entrypoint/main.cpp +++ b/core/src/Entrypoint/main.cpp @@ -6,6 +6,7 @@ #include "Entrypoint/OpenGL3.hpp" #include "Entrypoint/Vulkan.hpp" #include "UI/Localization.hpp" +#include "UI/States.hpp" #include "UI/UI.hpp" #include "Utils/I18n.hpp" #include "Utils/Sigslot.hpp" @@ -137,11 +138,13 @@ int main(int argc, char* argv[]) { config.MergeMode = true; ImGui::GetIO().Fonts->AddFontFromFileTTF("fonts/FontAwesome5-Solid.otf", 14, &config, iconRanges); - I18n::reloadSignal.Connect([]() { LocaleStrings::Instance = std::make_unique<LocaleStrings>(); }); + I18n::OnReload.Connect([]() { LocaleStrings::Instance = std::make_unique<LocaleStrings>(); }); // Do i18n intialization after linking reload signals, so that when SetLanguage() is called, the locale strings will be initialized (without us writing the code another time outside the slot) I18n::Init(); I18n::SetLanguage("zh_CN"); + UIState::Init(); + auto window = backend->GetWindow(); while (!glfwWindowShouldClose(window)) { backend->BeginFrame(); diff --git a/core/src/Model/Project.cpp b/core/src/Model/Project.cpp new file mode 100644 index 0000000..f301bb8 --- /dev/null +++ b/core/src/Model/Project.cpp @@ -0,0 +1,15 @@ +#include "Project.hpp" + +#include <utility> + +const std::filesystem::path& Project::GetPath() const { + return mRootPath; +} + +const std::string& Project::GetName() const { + return mName; +} + +void Project::SetName(std::string name) { + mName = std::move(name); +} diff --git a/core/src/Model/Project.hpp b/core/src/Model/Project.hpp new file mode 100644 index 0000000..34ae1d7 --- /dev/null +++ b/core/src/Model/Project.hpp @@ -0,0 +1,17 @@ +#pragma once + +#include <filesystem> +#include <string> + +class Project { +public: + std::filesystem::path mRootPath; + std::string mName; + +public: + // Path to a *directory* that contains the project file. + const std::filesystem::path& GetPath() const; + + const std::string& GetName() const; + void SetName(std::string name); +}; diff --git a/core/src/Model/fwd.hpp b/core/src/Model/fwd.hpp index 6f70f09..f5a5818 100644 --- a/core/src/Model/fwd.hpp +++ b/core/src/Model/fwd.hpp @@ -1 +1,4 @@ #pragma once + +// Project.hpp +class Project; diff --git a/core/src/UI/Localization.hpp b/core/src/UI/Localization.hpp index a2ac09b..648dd6d 100644 --- a/core/src/UI/Localization.hpp +++ b/core/src/UI/Localization.hpp @@ -12,13 +12,14 @@ public: static std::unique_ptr<LocaleStrings> Instance; public: - BasicTranslation MenuBarFile{ "MenuBar.File"sv }; - BasicTranslation MenuBarNewWindow{ "MenuBar.File.NewWindow"sv }; - BasicTranslation MenuBarNewProject{ "MenuBar.File.NewProject"sv }; - BasicTranslation MenuBarOpenProject{ "MenuBar.File.OpenProject"sv }; - BasicTranslation TabSettings{ "MainWindow.Tab.Settings"sv }; + BasicTranslation TabProject{ "MainWindow.Tab.Project"sv }; BasicTranslation TabDatabaseView{ "MainWindow.Tab.DatabaseView"sv }; BasicTranslation TabItems{ "MainWindow.Tab.Items"sv }; BasicTranslation TabExport{ "MainWindow.Tab.Exports"sv }; + + BasicTranslation NewProject{ "Project.NewProject"sv }; + BasicTranslation OpenProject{ "Project.OpenProject"sv }; + BasicTranslation Recents{ "Project.Recents"sv }; + BasicTranslation ClearRecents{ "Project.ClearRecents"sv }; }; diff --git a/core/src/UI/States.cpp b/core/src/UI/States.cpp new file mode 100644 index 0000000..efae152 --- /dev/null +++ b/core/src/UI/States.cpp @@ -0,0 +1,13 @@ +#include "States.hpp" + +#include "Model/Project.hpp" + +static std::unique_ptr<UIState> uiStateInstance; + +void UIState::Init() { + uiStateInstance = std::make_unique<UIState>(); +} + +UIState& UIState::GetInstance() { + return *uiStateInstance; +} diff --git a/core/src/UI/States.hpp b/core/src/UI/States.hpp new file mode 100644 index 0000000..d1c1faf --- /dev/null +++ b/core/src/UI/States.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include "cplt_fwd.hpp" + +#include <memory> + +class UIState { +public: + static void Init(); + static UIState& GetInstance(); + +public: + std::unique_ptr<Project> CurrentProject; +}; diff --git a/core/src/UI/UI_MainWindow.cpp b/core/src/UI/UI_MainWindow.cpp index 8b1e71d..0c8e7b9 100644 --- a/core/src/UI/UI_MainWindow.cpp +++ b/core/src/UI/UI_MainWindow.cpp @@ -1,38 +1,44 @@ #include "UI.hpp" +#include "Model/Project.hpp" #include "UI/Localization.hpp" +#include "UI/States.hpp" #include <imgui.h> -void UI::MainWindow() { +namespace { +void ProjectTab_Normal() { + // TODO +} + +void ProjectTab_NoProject() { auto ls = LocaleStrings::Instance.get(); - float menuBarHeight; - ImGui::BeginMainMenuBar(); - { - menuBarHeight = ImGui::GetWindowHeight(); + if (ImGui::Button(ls->NewProject.Get())) { + // TODO + } + if (ImGui::Button(ls->OpenProject.Get())) { + // TODO + } - if (ImGui::BeginMenu(ls->MenuBarFile.Get())) { - if (ImGui::MenuItem(ls->MenuBarNewWindow.Get())) { - // TODO - } - if (ImGui::MenuItem(ls->MenuBarNewProject.Get())) { - // TODO - } + ImGui::Separator(); + ImGui::Text(ls->Recents.Get()); + ImGui::SameLine(); + if (ImGui::Button(ls->ClearRecents.Get())) { + // TODO + } - ImGui::Separator(); - if (ImGui::MenuItem(ls->MenuBarOpenProject.Get())) { - // TODO - } + // TODO +} +} // namespace - ImGui::EndMenu(); - } - } - ImGui::EndMainMenuBar(); +void UI::MainWindow() { + auto ls = LocaleStrings::Instance.get(); + auto& uis = UIState::GetInstance(); auto windowSize = ImGui::GetMainViewport()->Size; - ImGui::SetNextWindowSize({ windowSize.x, windowSize.y - menuBarHeight }); - ImGui::SetNextWindowPos({ 0, menuBarHeight }); + ImGui::SetNextWindowSize({ windowSize.x, windowSize.y }); + ImGui::SetNextWindowPos({ 0, 0 }); ImGui::Begin("##MainWindow", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize); if (ImGui::BeginTabBar("##MainWindowTabs")) { if (ImGui::BeginTabItem(ls->TabSettings.Get())) { @@ -40,6 +46,19 @@ void UI::MainWindow() { ImGui::EndTabItem(); } + if (ImGui::BeginTabItem(ls->TabProject.Get())) { + if (uis.CurrentProject) { + ProjectTab_Normal(); + } else { + ProjectTab_NoProject(); + } + ImGui::EndTabItem(); + } + if (!uis.CurrentProject) { + // No project open, simply skip all project specific tabs + goto endTab; + } + if (ImGui::BeginTabItem(ls->TabDatabaseView.Get())) { UI::DatabaseViewTab(); ImGui::EndTabItem(); @@ -55,6 +74,7 @@ void UI::MainWindow() { ImGui::EndTabItem(); } + endTab: ImGui::EndTabBar(); } ImGui::End(); diff --git a/core/src/UI/fwd.hpp b/core/src/UI/fwd.hpp index 714a443..e412524 100644 --- a/core/src/UI/fwd.hpp +++ b/core/src/UI/fwd.hpp @@ -2,3 +2,6 @@ // Localization.hpp class LocaleStrings; + +// States.hpp +class UIState; diff --git a/core/src/Utils/I18n.cpp b/core/src/Utils/I18n.cpp index f5a6a49..50edf67 100644 --- a/core/src/Utils/I18n.cpp +++ b/core/src/Utils/I18n.cpp @@ -78,11 +78,11 @@ void I18n::Shutdown() { // Nothing to do yet
}
-Signal<> I18n::reloadSignal{};
+Signal<> I18n::OnReload{};
void I18n::ReloadLocales() {
auto& state = I18nState::Get();
- reloadSignal();
+ OnReload();
}
std::string_view I18n::GetLanguage() {
diff --git a/core/src/Utils/I18n.hpp b/core/src/Utils/I18n.hpp index b9386be..de32cf8 100644 --- a/core/src/Utils/I18n.hpp +++ b/core/src/Utils/I18n.hpp @@ -16,7 +16,7 @@ public: static void Init();
static void Shutdown();
- static Signal<> reloadSignal;
+ static Signal<> OnReload;
static void ReloadLocales();
static std::string_view GetLanguage();
|