aboutsummaryrefslogtreecommitdiff
path: root/core/src/UI
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2021-06-07 12:19:51 -0700
committerrtk0c <[email protected]>2021-06-07 12:19:51 -0700
commitd7ee2efaca226fc478e3f0c78abdbe86a887f17a (patch)
tree81670fefb7cdba3c5fa0ab890f7d84e24c194bdb /core/src/UI
parenta180e1b56025c6b7d81d2e587ad90531d29de44c (diff)
Complete asset loading/saving and UI management logic
Diffstat (limited to 'core/src/UI')
-rw-r--r--core/src/UI/UI_Templates.cpp41
-rw-r--r--core/src/UI/UI_Workflows.cpp54
2 files changed, 36 insertions, 59 deletions
diff --git a/core/src/UI/UI_Templates.cpp b/core/src/UI/UI_Templates.cpp
index 7ebb9e1..def50d9 100644
--- a/core/src/UI/UI_Templates.cpp
+++ b/core/src/UI/UI_Templates.cpp
@@ -140,7 +140,7 @@ void UI::TemplatesTab()
bool openedDummy = true;
static std::unique_ptr<TemplateUI> openTemplate;
- static AssetList::DrawState state;
+ static AssetList::ListState state;
// Toolbar item: close
if (ImGui::Button(ls->Close.Get(), openTemplate == nullptr)) {
@@ -156,8 +156,8 @@ void UI::TemplatesTab()
project.Templates.DrawDetails(state);
if (state.SelectedAsset) {
- auto kind = state.SelectedAsset->Kind;
- auto tmpl = state.SelectedAsset->LoadFromDisk();
+ auto kind = static_cast<Template::Kind>(state.SelectedAsset->Payload);
+ auto tmpl = project.Templates.Load(*state.SelectedAsset);
openTemplate = TemplateUI::CreateByKind(kind, std::move(tmpl));
}
@@ -186,8 +186,7 @@ void UI::TemplatesTab()
newNameError = NameSelectionError::Empty;
}
- auto& templates = gs.GetCurrentProject()->GetTemplates();
- if (templates.find(newName) != templates.end()) {
+ if (project.Templates.FindByName(newName)) {
newNameError = NameSelectionError::Duplicated;
}
};
@@ -233,13 +232,10 @@ void UI::TemplatesTab()
}
if (ImGui::Button(ls->DialogConfirm.Get(), IsInputValid())) {
- project.InsertTemplate(
- newName,
- TemplateInfo{
- .Path = project.GetTemplatePath(newName),
- .Name = newName, // Don't std::move here because evaluation order of `newName` (as parameter of InsertTemplate()) and this is unspecified
- .Kind = newKind,
- });
+ project.Templates.Create(SavedAsset{
+ .Name = newName,
+ .Payload = static_cast<uint64_t>(newKind),
+ });
openTemplate = TemplateUI::CreateByKind(newKind);
}
@@ -255,7 +251,7 @@ void UI::TemplatesTab()
}
ImGui::SameLine();
- if (ImGui::Button(ls->Rename.Get(), state.SelectedTemplate == nullptr)) {
+ if (ImGui::Button(ls->Rename.Get(), state.SelectedAsset == nullptr)) {
ImGui::OpenPopup("Rename template");
newName.clear();
}
@@ -265,14 +261,12 @@ void UI::TemplatesTab()
}
if (ImGui::Button(ls->DialogConfirm.Get(), IsInputValid())) {
- auto& project = *gs.GetCurrentProject();
-
- project.Templates.Rename(
- state.SelectedTemplate->Name,
+ auto tmpl = project.Templates.Rename(
+ state.SelectedAsset->Name,
newName);
- // We mutated the map, the pointer may be invalid now
- state.SelectedTemplate = &project.GetTemplates().at(newName);
+ // Update the selected pointer to the new location (we mutated the map, the pointer may be invalid now)
+ state.SelectedAsset = tmpl;
}
ImGui::SameLine();
if (ImGui::Button(ls->DialogCancel.Get())) {
@@ -285,14 +279,15 @@ void UI::TemplatesTab()
}
ImGui::SameLine();
- if (ImGui::Button(ls->Delete.Get(), state.SelectedTemplate == nullptr)) {
+ if (ImGui::Button(ls->Delete.Get(), state.SelectedAsset == nullptr)) {
ImGui::OpenPopup("Delete confirmation");
}
if (ImGui::BeginPopupModal("Delete confirmation")) {
- assert(state.SelectedTemplate != nullptr);
-
if (ImGui::Button(ls->DialogConfirm.Get())) {
- gs.GetCurrentProject()->RemoveTemplate(state.SelectedTemplate->Name);
+ auto& assetName = state.SelectedAsset->Name;
+ project.Templates.Remove(assetName);
+
+ state.SelectedAsset = nullptr;
}
ImGui::SameLine();
if (ImGui::Button(ls->DialogCancel.Get())) {
diff --git a/core/src/UI/UI_Workflows.cpp b/core/src/UI/UI_Workflows.cpp
index 51cc4f8..7b2de2a 100644
--- a/core/src/UI/UI_Workflows.cpp
+++ b/core/src/UI/UI_Workflows.cpp
@@ -358,39 +358,17 @@ public:
ImNodes::End();
}
};
-
-struct DrawTemplateList_State
-{
- const WorkflowInfo* SelectedWorkflow = nullptr;
-};
-
-void DrawTemplateList(DrawTemplateList_State& state)
-{
- auto& gs = GlobalStates::GetInstance();
- auto& workflows = gs.GetCurrentProject()->GetWorkflows();
-
- // TODO sort the list
- for (auto& info : workflows) {
- if (ImGui::Selectable(info.Name.c_str(), state.SelectedWorkflow == &info)) {
- state.SelectedWorkflow = &info;
- }
- if (ImGui::IsItemHovered()) {
- ImGui::BeginTooltip();
- ImGui::Text("Path: %s", info.PathStringCache.c_str());
- ImGui::EndTooltip();
- }
- }
-}
} // namespace
void UI::WorkflowsTab()
{
auto ls = LocaleStrings::Instance.get();
auto& gs = GlobalStates::GetInstance();
+ auto& project = *gs.GetCurrentProject();
bool openedDummy = true;
static std::unique_ptr<WorkflowUI> openWorkflow;
- static DrawTemplateList_State state;
+ static AssetList::ListState state;
// Toolbar item: close
if (ImGui::Button(ls->Close.Get(), openWorkflow == nullptr)) {
@@ -403,10 +381,10 @@ void UI::WorkflowsTab()
ImGui::OpenPopup(ls->OpenWorkflowDialogTitle.Get());
}
if (ImGui::BeginPopupModal(ls->OpenWorkflowDialogTitle.Get(), &openedDummy, ImGuiWindowFlags_AlwaysAutoResize)) {
- DrawTemplateList(state);
+ project.Workflows.DrawDetails(state);
- if (state.SelectedWorkflow) {
- auto workflow = state.SelectedWorkflow->LoadFromDisk();
+ if (state.SelectedAsset) {
+ auto workflow = project.Workflows.Load(*state.SelectedAsset);
openWorkflow = std::make_unique<WorkflowUI>(std::move(workflow));
}
@@ -419,7 +397,7 @@ void UI::WorkflowsTab()
ImGui::OpenPopup(ls->ManageWorkflowsDialogTitle.Get());
}
if (ImGui::BeginPopupModal(ls->ManageWorkflowsDialogTitle.Get(), &openedDummy, ImGuiWindowFlags_AlwaysAutoResize)) {
- DrawTemplateList(state);
+ project.Workflows.DrawDetails(state);
enum class NameSelectionError
{
@@ -429,7 +407,7 @@ void UI::WorkflowsTab()
};
static std::string newName;
static NameSelectionError newNameError;
- if (ImGui::Button(ls->Rename.Get(), state.SelectedWorkflow == nullptr)) {
+ if (ImGui::Button(ls->Rename.Get(), state.SelectedAsset == nullptr)) {
ImGui::OpenPopup("Rename workflow");
newName.clear();
}
@@ -439,16 +417,17 @@ void UI::WorkflowsTab()
newNameError = NameSelectionError::Empty;
}
- auto& workflows = gs.GetCurrentProject()->GetWorkflows();
- if (workflows.find(newName) != workflows.end()) {
+ if (project.Workflows.FindByName(newName)) {
newNameError = NameSelectionError::Duplicated;
}
}
if (ImGui::Button(ls->DialogConfirm.Get(), newName.empty())) {
- auto project = gs.GetCurrentProject();
- project->RenameWorkflow(state.SelectedWorkflow->Name, newName);
- state.SelectedWorkflow = &project->GetWorkflows().at(newName);
+ auto workflow = project.Workflows.Rename(
+ state.SelectedAsset->Name,
+ newName);
+
+ state.SelectedAsset = workflow;
}
ImGui::SameLine();
if (ImGui::Button(ls->DialogCancel.Get())) {
@@ -468,12 +447,15 @@ void UI::WorkflowsTab()
ImGui::EndPopup();
}
- if (ImGui::Button(ls->Delete.Get(), state.SelectedWorkflow == nullptr)) {
+ if (ImGui::Button(ls->Delete.Get(), state.SelectedAsset == nullptr)) {
ImGui::OpenPopup("Delete confirmation");
}
if (ImGui::BeginPopupModal("Delete confirmation")) {
if (ImGui::Button(ls->DialogConfirm.Get())) {
- gs.GetCurrentProject()->RemoveWorkflow(state.SelectedWorkflow->Name);
+ auto& assetName = state.SelectedAsset->Name;
+ project.Workflows.Remove(assetName);
+
+ state.SelectedAsset = nullptr;
}
ImGui::SameLine();
if (ImGui::Button(ls->DialogCancel.Get())) {