aboutsummaryrefslogtreecommitdiff
path: root/core/src/UI
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2021-03-30 19:40:11 -0700
committerrtk0c <[email protected]>2021-03-30 19:40:11 -0700
commit31950890c939862f79c817053c106bf711c63a64 (patch)
tree4e02abf37d69ab7d4f988f143b340cfd3d93331c /core/src/UI
parente75e26da92424528e190a2111acfcc49c657e894 (diff)
Product items and misc stuff
Diffstat (limited to 'core/src/UI')
-rw-r--r--core/src/UI/Localization.hpp22
-rw-r--r--core/src/UI/States.cpp9
-rw-r--r--core/src/UI/States.hpp1
-rw-r--r--core/src/UI/UI.hpp8
-rw-r--r--core/src/UI/UI_Items.cpp117
-rw-r--r--core/src/UI/UI_MainWindow.cpp67
-rw-r--r--core/src/UI/UI_Utils.cpp21
7 files changed, 208 insertions, 37 deletions
diff --git a/core/src/UI/Localization.hpp b/core/src/UI/Localization.hpp
index e604165..d5424ea 100644
--- a/core/src/UI/Localization.hpp
+++ b/core/src/UI/Localization.hpp
@@ -12,6 +12,9 @@ public:
static std::unique_ptr<LocaleStrings> Instance;
public:
+ BasicTranslation DialogConfirm{ "Generic.Dialog.Confirm"sv };
+ BasicTranslation DialogCancel{ "Generic.Dialog.Cancel"sv };
+
BasicTranslation TabSettings{ "MainWindow.Tab.Settings"sv };
BasicTranslation TabProject{ "MainWindow.Tab.Project"sv };
BasicTranslation TabDatabaseView{ "MainWindow.Tab.DatabaseView"sv };
@@ -19,9 +22,7 @@ public:
BasicTranslation TabExport{ "MainWindow.Tab.Exports"sv };
BasicTranslation NewProject{ "Project.New"sv };
- BasicTranslation NewProjectTitle{ "Project.New.DialogTitle"sv };
- BasicTranslation ConfirmNewProject{ "Project.New.Confirm"sv };
- BasicTranslation CancelNewProject{ "Project.New.Cancel"sv };
+ BasicTranslation NewProjectDialogTitle{ "Project.New.DialogTitle"sv };
BasicTranslation NewProjectNameHint{ "Project.New.Name"sv };
BasicTranslation NewProjectPathHint{ "Project.New.Path"sv };
BasicTranslation NewProjectPathDialogTitle{ "Project.New.Path.DialogTitle"sv };
@@ -36,4 +37,19 @@ public:
BasicTranslation NoRecentProjectsMessage{ "Project.Recents.NonePresent"sv };
BasicTranslation OpenRecentProjectTooltip{ "Project.Recents.Open.Tooltip"sv };
BasicTranslation DeleteRecentProjectTooltip{ "Project.Recents.Delete.Tooltip"sv };
+
+ BasicTranslation CloseActiveProject{ "ActiveProject.Close"sv };
+ BasicTranslation OpenActiveProjectInFileSystem{ "ActiveProject.OpenInFilesystem"sv };
+ BasicTranslation ActiveProjectName{ "ActiveProject.Info.Name"sv };
+ BasicTranslation ActiveProjectPath{ "ActiveProject.Info.Path"sv };
+
+ BasicTranslation AddItem{ "ItemEditor.Add"sv };
+ BasicTranslation AddItemDialogTitle{ "ItemEditor.Add.DialogTitle"sv };
+ BasicTranslation DeleteItem{ "ItemEditor.Delete"sv };
+
+ BasicTranslation ProductCategoryName{ "Item.Product.CategoryName"sv };
+ BasicTranslation ProductNameColumn{ "Item.Product.Column.Name"sv };
+ BasicTranslation ProductDescriptionColumn{ "Item.Product.Column.Description"sv };
+ BasicTranslation FactoryCategoryName{ "Item.Factory.CategoryName"sv };
+ BasicTranslation CustomerCategoryName{ "Item.Customer.CategoryName"sv };
};
diff --git a/core/src/UI/States.cpp b/core/src/UI/States.cpp
index 07bbcf7..dc7c37a 100644
--- a/core/src/UI/States.cpp
+++ b/core/src/UI/States.cpp
@@ -11,6 +11,13 @@ void UIState::Init() {
uiStateInstance = std::make_unique<UIState>();
}
+void UIState::Shutdown() {
+ if (uiStateInstance) {
+ uiStateInstance->CloseCurrentProject();
+ uiStateInstance = nullptr;
+ }
+}
+
UIState& UIState::GetInstance() {
return *uiStateInstance;
}
@@ -22,7 +29,7 @@ void UIState::SetCurrentProject(std::unique_ptr<Project> project) {
void UIState::CloseCurrentProject() {
if (CurrentProject) {
- // TODO save stuff
+ CurrentProject->WriteToDisk();
CurrentProject = nullptr;
}
}
diff --git a/core/src/UI/States.hpp b/core/src/UI/States.hpp
index cbb556f..de0510c 100644
--- a/core/src/UI/States.hpp
+++ b/core/src/UI/States.hpp
@@ -9,6 +9,7 @@
class UIState {
public:
static void Init();
+ static void Shutdown();
static UIState& GetInstance();
public:
diff --git a/core/src/UI/UI.hpp b/core/src/UI/UI.hpp
index b0c3aaa..52a2ca9 100644
--- a/core/src/UI/UI.hpp
+++ b/core/src/UI/UI.hpp
@@ -1,7 +1,15 @@
#pragma once
+#include <imgui.h>
+
namespace ImGui {
+void SetNextWindowSizeRelScreen(float xPercent, float yPercent, ImGuiCond_ cond = ImGuiCond_None);
+void SetNextWindowCentered(ImGuiCond_ cond = ImGuiCond_None);
+
+void PushDisabled();
+void PopDisabled();
+
void ErrorIcon();
void WarningIcon();
diff --git a/core/src/UI/UI_Items.cpp b/core/src/UI/UI_Items.cpp
index 371e682..a990a96 100644
--- a/core/src/UI/UI_Items.cpp
+++ b/core/src/UI/UI_Items.cpp
@@ -1,9 +1,124 @@
#include "UI.hpp"
+#include "Model/GlobalStates.hpp"
+#include "Model/Project.hpp"
#include "UI/Localization.hpp"
+#include "UI/States.hpp"
+#include <IconsFontAwesome.h>
#include <imgui.h>
+#include <imgui_stdlib.h>
-void UI::ItemsTab() {
+namespace {
+/// Specialized for each item type.
+template <class T>
+void AddToItemListDialog(ItemList<T>& list);
+/// Specialized for each item type.
+template <class T>
+void ItemListEntries(ItemList<T>& list);
+
+template <>
+void AddToItemListDialog<ProductItem>(ItemList<ProductItem>& list) {
+ static std::string productName;
+ static std::string description;
+
+ auto ls = LocaleStrings::Instance.get();
+ auto& uis = UIState::GetInstance();
+ ImGui::InputText(ls->ProductNameColumn.Get(), &productName);
+ ImGui::InputText(ls->ProductDescriptionColumn.Get(), &description);
+
+ if (ImGui::Button(ls->DialogConfirm.Get())) {
+ auto& product = uis.CurrentProject->Products.Insert(std::move(productName));
+ product.SetDescription(std::move(description));
+
+ productName.clear();
+ description.clear();
+
+ ImGui::CloseCurrentPopup();
+ }
+ ImGui::SameLine();
+ if (ImGui::Button(ls->DialogCancel.Get())) {
+ ImGui::CloseCurrentPopup();
+ }
+}
+
+template <>
+void AddToItemListDialog<FactoryItem>(ItemList<FactoryItem>& list) {
// TODO
}
+
+template <>
+void AddToItemListDialog<CustomerItem>(ItemList<CustomerItem>& list) {
+ // TODO
+}
+
+template <>
+void ItemListEntries<ProductItem>(ItemList<ProductItem>& list) {
+ auto ls = LocaleStrings::Instance.get();
+ if (ImGui::BeginTable("ItemListEntries", 2)) {
+
+ ImGui::TableSetupColumn(ls->ProductNameColumn.Get());
+ ImGui::TableSetupColumn(ls->ProductDescriptionColumn.Get());
+ ImGui::TableHeadersRow();
+
+ for (auto& entry : list) {
+ ImGui::TableNextRow();
+
+ ImGui::TableNextColumn();
+ ImGui::Text("%s", entry.GetName().c_str());
+ ImGui::TableNextColumn();
+ ImGui::Text("%.8s", entry.GetDescription().c_str());
+ if (ImGui::Button(ICON_FA_EDIT)) {
+ // TODO
+ }
+ }
+ ImGui::EndTable();
+ }
+}
+
+template <>
+void ItemListEntries<FactoryItem>(ItemList<FactoryItem>& list) {
+ // TODO
+}
+
+template <>
+void ItemListEntries<CustomerItem>(ItemList<CustomerItem>& list) {
+ // TODO
+}
+
+template <class T>
+void ItemListEditor(ItemList<T>& list) {
+ auto ls = LocaleStrings::Instance.get();
+
+ if (ImGui::Button(ls->AddItem.Get())) {
+ ImGui::SetNextWindowCentered();
+ ImGui::OpenPopup(ls->AddItemDialogTitle.Get());
+ }
+ if (ImGui::BeginPopupModal(ls->AddItemDialogTitle.Get())) {
+ AddToItemListDialog<T>(list);
+ ImGui::EndPopup();
+ }
+
+ ImGui::SameLine();
+ if (ImGui::Button(ls->DeleteItem.Get())) {
+ // TODO
+ }
+
+ ItemListEntries<T>(list);
+}
+} // namespace
+
+void UI::ItemsTab() {
+ auto ls = LocaleStrings::Instance.get();
+ auto& uis = UIState::GetInstance();
+
+ if (ImGui::CollapsingHeader(ls->ProductCategoryName.Get())) {
+ ItemListEditor(uis.CurrentProject->Products);
+ }
+ if (ImGui::CollapsingHeader(ls->FactoryCategoryName.Get())) {
+ ItemListEditor(uis.CurrentProject->Factories);
+ }
+ if (ImGui::CollapsingHeader(ls->CustomerCategoryName.Get())) {
+ ItemListEditor(uis.CurrentProject->Customers);
+ }
+}
diff --git a/core/src/UI/UI_MainWindow.cpp b/core/src/UI/UI_MainWindow.cpp
index de300e2..15c28ff 100644
--- a/core/src/UI/UI_MainWindow.cpp
+++ b/core/src/UI/UI_MainWindow.cpp
@@ -5,28 +5,38 @@
#include "UI/Localization.hpp"
#include "UI/States.hpp"
-#include <portable-file-dialogs.h>
-
#include <IconsFontAwesome.h>
#include <imgui.h>
-#include <imgui_internal.h>
#include <imgui_stdlib.h>
+#include <portable-file-dialogs.h>
#include <filesystem>
+#include <memory>
namespace fs = std::filesystem;
namespace {
void LoadProjectAt(const std::filesystem::path& path) {
auto& uis = UIState::GetInstance();
- auto& gs = GlobalStates::GetInstance();
-
auto project = Project::Load(path);
- auto uptr = std::unique_ptr<Project>(new Project(std::move(project)));
- uis.SetCurrentProject(std::move(uptr));
+ uis.SetCurrentProject(std::make_unique<Project>(std::move(project)));
}
void ProjectTab_Normal() {
- // TODO
+ auto ls = LocaleStrings::Instance.get();
+ auto& gs = GlobalStates::GetInstance();
+ auto& uis = UIState::GetInstance();
+
+ if (ImGui::Button(ls->CloseActiveProject.Get())) {
+ uis.CloseCurrentProject();
+ return;
+ }
+ ImGui::SameLine();
+ if (ImGui::Button(ls->OpenActiveProjectInFileSystem.Get())) {
+ // TODO
+ }
+
+ ImGui::Text("%s%s", ls->ActiveProjectName.Get(), uis.CurrentProject->GetName().c_str());
+ ImGui::Text("%s%s", ls->ActiveProjectPath.Get(), uis.CurrentProject->GetPathString().c_str());
}
void ProjectTab_NoProject() {
@@ -42,6 +52,7 @@ void ProjectTab_NoProject() {
auto TrySelectPath = [&](fs::path newPath) {
if (fs::exists(newPath)) {
dirNameIsValid = true;
+ dirName = newPath.string();
dirPath = std::move(newPath);
} else {
dirNameIsValid = false;
@@ -49,15 +60,14 @@ void ProjectTab_NoProject() {
};
if (ImGui::Button(ls->NewProject.Get())) {
- auto vs = ImGui::GetMainViewport()->Size; // Viewport Size
- ImGui::SetNextWindowSize({ vs.x * 0.5f, vs.y * 0.5f });
- ImGui::SetNextWindowPos({ vs.x / 2, vs.y / 2 }, ImGuiCond_Always, { 0.5f, 0.5f }); // Center window initially
- ImGui::OpenPopup(ls->NewProjectTitle.Get());
+ ImGui::SetNextWindowCentered();
+ ImGui::SetNextWindowSizeRelScreen(0.5f, 0.5f);
+ ImGui::OpenPopup(ls->NewProjectDialogTitle.Get());
}
// Make it so that the modal dialog has a close button
bool newProjectDialogDummyTrue = true;
- if (ImGui::BeginPopupModal(ls->NewProjectTitle.Get(), &newProjectDialogDummyTrue)) {
+ if (ImGui::BeginPopupModal(ls->NewProjectDialogTitle.Get(), &newProjectDialogDummyTrue)) {
ImGui::InputTextWithHint("##ProjectName", ls->NewProjectNameHint.Get(), &projectName);
if (ImGui::InputTextWithHint("##ProjectPath", ls->NewProjectPathHint.Get(), &dirName)) {
@@ -76,30 +86,26 @@ void ProjectTab_NoProject() {
ImGui::ErrorIcon();
ImGui::SameLine();
- ImGui::Text(ls->NewProjectEmptyNameError.Get());
+ ImGui::Text("%s", ls->NewProjectEmptyNameError.Get());
}
if (!dirNameIsValid) {
ImGui::ErrorIcon();
ImGui::SameLine();
- ImGui::Text(ls->NewProjectInvalidPathError.Get());
+ ImGui::Text("%s", ls->NewProjectInvalidPathError.Get());
}
ImGui::Spacing();
bool formValid = dirNameIsValid && !projectName.empty();
- if (!formValid) {
- ImGui::PushItemFlag(ImGuiItemFlags_Disabled, false);
- ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 0.5f * ImGui::GetStyle().Alpha);
- }
- if (ImGui::Button(ls->ConfirmNewProject.Get())) {
+ if (!formValid) ImGui::PushDisabled();
+ if (ImGui::Button(ls->DialogConfirm.Get())) {
ImGui::CloseCurrentPopup();
auto project = Project::Create(std::move(projectName), dirPath);
- auto uptr = std::unique_ptr<Project>(new Project(std::move(project)));
- uis.SetCurrentProject(std::move(uptr));
+ uis.SetCurrentProject(std::make_unique<Project>(std::move(project)));
// Dialog just got closed, reset states
projectName = "";
@@ -107,13 +113,10 @@ void ProjectTab_NoProject() {
dirPath = fs::path{};
dirNameIsValid = false;
}
- if (!formValid) {
- ImGui::PopItemFlag();
- ImGui::PopStyleVar();
- }
+ if (!formValid) ImGui::PopDisabled();
ImGui::SameLine();
- if (ImGui::Button(ls->CancelNewProject.Get())) {
+ if (ImGui::Button(ls->DialogCancel.Get())) {
ImGui::CloseCurrentPopup();
}
@@ -129,7 +132,7 @@ void ProjectTab_NoProject() {
}
ImGui::Separator();
- ImGui::Text(ls->RecentProjects.Get());
+ ImGui::Text("%s", ls->RecentProjects.Get());
ImGui::SameLine();
if (ImGui::Button(ls->ClearRecentProjects.Get())) {
gs.ClearRecentProjects();
@@ -137,18 +140,18 @@ void ProjectTab_NoProject() {
auto& recentProjects = gs.GetRecentProjects();
if (recentProjects.empty()) {
- ImGui::Text(ls->NoRecentProjectsMessage.Get());
+ ImGui::Text("%s", ls->NoRecentProjectsMessage.Get());
}
for (auto it = recentProjects.begin(); it != recentProjects.end(); ++it) {
auto& [path, recent] = *it;
- ImGui::Text(recent.c_str());
+ ImGui::Text("%s", recent.c_str());
ImGui::SameLine();
if (ImGui::Button(ICON_FA_EDIT)) {
LoadProjectAt(path);
}
if (ImGui::IsItemHovered()) {
- ImGui::SetTooltip(ls->OpenRecentProjectTooltip.Get());
+ ImGui::SetTooltip("%s", ls->OpenRecentProjectTooltip.Get());
}
ImGui::SameLine();
@@ -156,7 +159,7 @@ void ProjectTab_NoProject() {
gs.RemoveRecentProject(std::distance(recentProjects.begin(), it));
}
if (ImGui::IsItemHovered()) {
- ImGui::SetTooltip(ls->DeleteRecentProjectTooltip.Get());
+ ImGui::SetTooltip("%s", ls->DeleteRecentProjectTooltip.Get());
}
}
}
diff --git a/core/src/UI/UI_Utils.cpp b/core/src/UI/UI_Utils.cpp
index 61a62f0..615caae 100644
--- a/core/src/UI/UI_Utils.cpp
+++ b/core/src/UI/UI_Utils.cpp
@@ -2,6 +2,27 @@
#include <IconsFontAwesome.h>
#include <imgui.h>
+#include <imgui_internal.h>
+
+void ImGui::SetNextWindowSizeRelScreen(float xPercent, float yPercent, ImGuiCond_ cond) {
+ auto vs = ImGui::GetMainViewport()->Size;
+ ImGui::SetNextWindowSize({ vs.x * xPercent, vs.y * yPercent }, cond);
+}
+
+void ImGui::SetNextWindowCentered(ImGuiCond_ cond) {
+ auto vs = ImGui::GetMainViewport()->Size;
+ ImGui::SetNextWindowPos({ vs.x / 2, vs.y / 2 }, cond, { 0.5f, 0.5f });
+}
+
+void ImGui::PushDisabled() {
+ ImGui::PushItemFlag(ImGuiItemFlags_Disabled, false);
+ ImGui::PushStyleVar(ImGuiStyleVar_Alpha, 0.5f * ImGui::GetStyle().Alpha);
+}
+
+void ImGui::PopDisabled() {
+ ImGui::PopItemFlag();
+ ImGui::PopStyleVar();
+}
void ImGui::ErrorIcon() {
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4{ 237 / 255.0f, 67 / 255.0f, 55 / 255.0f, 1.0f }); // #ED4337