aboutsummaryrefslogtreecommitdiff
path: root/core/src/UI/UI_Items.cpp
blob: a990a962e72726c6b6724d4a5e41752bfc854921 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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>

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);
	}
}