TerraForge3D  2.3.1
3D Terrain And Landscape Generator
MainMenu.cpp
1#include "Menu/MainMenu.h"
2
3#include "imgui/imgui.h"
4
5#include "Utils/Utils.h"
6#include "Misc/AppStyles.h"
7#include "Misc/ExportManager.h"
8#include "Data/ApplicationState.h"
9#include "Platform.h"
10
11static void ShowWindowMenuItem(const char *title, bool *val)
12{
13 ImGui::Checkbox(title, val);
14}
15
16
17
18MainMenu::MainMenu(ApplicationState *as)
19 :appState(as)
20{
21}
22
23MainMenu::~MainMenu()
24{
25}
26
27void MainMenu::ShowMainMenu()
28{
29 if (ImGui::BeginMainMenuBar())
30 {
31 if (ImGui::BeginMenu("File"))
32 {
33 ShowFileMenu();
34 ImGui::EndMenu();
35 }
36
37 if (ImGui::BeginMenu("Options"))
38 {
39 ShowOptionsMenu();
40 ImGui::EndMenu();
41 }
42
43 if (ImGui::BeginMenu("Windows"))
44 {
45 ShowWindowsMenu();
46 ImGui::EndMenu();
47 }
48
49 if (ImGui::BeginMenu("Help"))
50 {
51 ShowHelpMenu();
52 ImGui::EndMenu();
53 }
54
55 ImGui::EndMainMenuBar();
56 }
57}
58
59void MainMenu::ShowFileMenu()
60{
61 if (ImGui::MenuItem("Open"))
62 {
63 appState->serailizer->LoadFile(ShowOpenFileDialog("*.terr3d"));
64 }
65
66 if (ImGui::MenuItem("Save"))
67 {
68 appState->serailizer->LoadFile(ShowSaveFileDialog("*.terr3d"));
69 }
70
71 if (ImGui::MenuItem("Install Module"))
72 {
73// appState->modules.manager->InstallModule(ShowOpenFileDialog("*.terr3dmodule"));
74 }
75
76 Model *modelToExport;
77
78 switch (appState->mode)
79 {
80 case ApplicationMode::TERRAIN:
81 modelToExport = appState->models.coreTerrain;
82 break;
83
84 case ApplicationMode::CUSTOM_BASE:
85 modelToExport = appState->models.customBase;
86 break;
87
88 default:
89 modelToExport = appState->models.coreTerrain;
90 break;
91 }
92
93 if (ImGui::BeginMenu("Export Mesh As"))
94 {
95 if (ImGui::MenuItem("Wavefont OBJ"))
96 {
97 ExportModelAssimp(modelToExport, "obj", ShowSaveFileDialog(".obj\0"), "obj");
98 }
99
100 if (ImGui::MenuItem("FBX"))
101 {
102 ExportModelAssimp(modelToExport, "fbx", ShowSaveFileDialog(".fbx\0"), "fbx");
103 }
104
105 if (ImGui::MenuItem("GLTF v2"))
106 {
107 ExportModelAssimp(modelToExport, "gltf2", ShowSaveFileDialog(".gltf\0"), "gltf");
108 }
109
110 if (ImGui::MenuItem("GLB v2"))
111 {
112 ExportModelAssimp(modelToExport, "glb2", ShowSaveFileDialog(".glb\0"), "glb");
113 }
114
115 if (ImGui::MenuItem("JSON"))
116 {
117 ExportModelAssimp(modelToExport, "json", ShowSaveFileDialog(".json\0"));
118 }
119
120 if (ImGui::MenuItem("STL"))
121 {
122 ExportModelAssimp(modelToExport, "stl", ShowSaveFileDialog(".stl\0"));
123 }
124
125 if (ImGui::MenuItem("PLY"))
126 {
127 ExportModelAssimp(modelToExport, "ply", ShowSaveFileDialog(".ply\0"));
128 }
129
130 if (ImGui::MenuItem("Collada"))
131 {
132 ExportModelAssimp(modelToExport, "collada", ShowSaveFileDialog(".dae\0"), "dae");
133 }
134
135 ImGui::EndMenu();
136 }
137
138 if (ImGui::MenuItem("Close"))
139 {
140 appState->globals.currentOpenFilePath = "";
141 }
142
143 if (ImGui::MenuItem("Pack Project"))
144 {
145 appState->serailizer->PackProject(ShowSaveFileDialog("*.terr3dpack"));
146 }
147
148 if (ImGui::MenuItem("Load Packed Project"))
149 {
150 appState->serailizer->LoadPackedProject(ShowOpenFileDialog("*.terr3dpack"));
151 }
152
153 if (ImGui::MenuItem("Load Auto Saved Project"))
154 {
155 appState->serailizer->LoadFile(GetExecutableDir() + PATH_SEPARATOR "Data" PATH_SEPARATOR "cache" PATH_SEPARATOR "autosave" PATH_SEPARATOR "autosave.terr3d");
156 }
157
158 if (ImGui::MenuItem("Exit"))
159 {
160 exit(0);
161 }
162}
163
164void MainMenu::ShowOptionsMenu()
165{
166 if (ImGui::MenuItem("Toggle System Console"))
167 {
168 ToggleSystemConsole();
169 }
170
171 if (ImGui::MenuItem("Associate (.terr3d) File Type"))
172 {
173 AccocFileType();
174 }
175
176 if (ImGui::MenuItem("Copy Version Hash"))
177 {
178 char *output = new char[MD5File(GetExecutablePath()).ToString().size() + 1];
179 strcpy(output, MD5File(GetExecutablePath()).ToString().c_str());
180 const size_t len = strlen(output) + 1;
181#ifdef TERR3D_WIN32
182 HGLOBAL hMem = GlobalAlloc(GMEM_MOVEABLE, len);
183 memcpy(GlobalLock(hMem), output, len);
184 GlobalUnlock(hMem);
185 OpenClipboard(0);
186 EmptyClipboard();
187 SetClipboardData(CF_TEXT, hMem);
188 CloseClipboard();
189 delete[] output;
190#else
191 std::cout << "Version Hash : " << output << std::endl;
192#endif
193 }
194
195 if (ImGui::BeginMenu("Themes"))
196 {
197 if (ImGui::MenuItem("Default"))
198 {
199 LoadDefaultStyle();
200 }
201
202 if(ImGui::MenuItem("Maya Theme"))
203 {
204 LoadMayaStyle();
205 }
206
207 if (ImGui::MenuItem("Black & White"))
208 {
209 LoadBlackAndWhite();
210 }
211
212 if (ImGui::MenuItem("Cool Dark"))
213 {
214 LoadDarkCoolStyle();
215 }
216
217 if (ImGui::MenuItem("Light Orange"))
218 {
219 LoadLightOrngeStyle();
220 }
221
222 if (ImGui::MenuItem("Load Theme From File"))
223 {
224 LoadThemeFromFile(openfilename());
225 }
226
227 ImGui::EndMenu();
228 }
229}
230
231void MainMenu::ShowWindowsMenu()
232{
233 ShowWindowMenuItem("Statistics", &appState->windows.statsWindow);
234 ShowWindowMenuItem("Theme Editor", &appState->windows.styleEditor);
235 ShowWindowMenuItem("Foliage Manager", &appState->windows.foliageManager);
236 ShowWindowMenuItem("Texture Baker", &appState->windows.textureBaker);
237 ShowWindowMenuItem("Texture Store", &appState->windows.textureStore);
238 ShowWindowMenuItem("Sea Settings", &appState->windows.seaEditor);
239 ShowWindowMenuItem("Light Settings", &appState->windows.lightControls);
240 ShowWindowMenuItem("Camera Settings", &appState->windows.cameraControls);
241 ShowWindowMenuItem("Mesh Generators Settings", &appState->meshGenerator->windowStat);
242 ShowWindowMenuItem("Sky Settings", &appState->windows.skySettings);
243 ShowWindowMenuItem("Shading", &appState->windows.shadingManager);
244 ShowWindowMenuItem("Filters Manager", &appState->windows.filtersManager);
245 ShowWindowMenuItem("Module Manager", &appState->windows.modulesManager);
246 ShowWindowMenuItem("Supporters", &appState->windows.supportersTribute);
247 ShowWindowMenuItem("Open Source Liscenses", &appState->windows.osLisc);
248}
249
250void MainMenu::ShowHelpMenu()
251{
252 if (ImGui::MenuItem("Tutorial"))
253 {
254 OpenURL("https://www.youtube.com/playlist?list=PLl3xhxX__M4A74aaTj8fvqApu7vo3cOiZ");
255 }
256
257 if (ImGui::MenuItem("Social Handle"))
258 {
259 OpenURL("https://twitter.com/jaysmito101");
260 }
261
262 if (ImGui::MenuItem("Discord Server"))
263 {
264 OpenURL("https://discord.gg/AcgRafSfyB");
265 }
266
267 if (ImGui::MenuItem("GitHub Page"))
268 {
269 OpenURL("https://github.com/Jaysmito101/TerraForge3D");
270 }
271
272 if (ImGui::MenuItem("Documentation"))
273 {
274 OpenURL("https://github.com/Jaysmito101/TerraForge3D/wiki");
275 }
276
277 if (ImGui::MenuItem("Open Source Liscenses"))
278 {
279 appState->windows.osLisc = !appState->windows.osLisc;
280 }
281}
Definition: Model.h:9