Pioneer
Loading...
Searching...
No Matches
SystemEditor.h
Go to the documentation of this file.
1// Copyright © 2008-2024 Pioneer Developers. See AUTHORS.txt for details
2// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
3
4#pragma once
5
7
8#include "Input.h"
9#include "Random.h"
10#include "RefCounted.h"
11#include "core/Application.h"
12#include "galaxy/SystemPath.h"
13#include "GalaxyEditAPI.h"
14
15#include <memory>
16
17// Forward declaration
18typedef unsigned int ImGuiID;
19
20namespace pfd {
21 class open_file;
22 class save_file;
23} // namespace pfd
24
25namespace FileSystem {
26 class FileInfo;
27} // namespace FileSystem
28
29class LuaNameGen;
30
31class Galaxy;
32class StarSystem;
33class SystemBody;
34class CustomSystem;
36
37namespace Editor {
38
39class EditorApp;
40class UndoSystem;
41class SystemEditorViewport;
42class ActionBinder;
43
44const char *GetBodyIcon(const SystemBody *body);
45
47public:
50
51 void NewSystem(SystemPath path);
52 bool LoadSystem(SystemPath path);
53 bool LoadSystemFromDisk(const std::string &absolutePath);
54
55 // Write the currently edited system out to disk as a JSON file
56 bool WriteSystem(const std::string &filepath);
57
58 Random &GetRng() { return m_random; }
60
61 void SetSelectedBody(SystemBody *body);
62 SystemBody *GetSelectedBody() { return m_selectedBody; }
63
65
66protected:
67 void Start() override;
68 void Update(float deltaTime) override;
69 void End() override;
70
71 void HandleInput();
72
73private:
74 bool LoadSystemFromFile(const FileSystem::FileInfo &file);
75 bool LoadCustomSystem(const CustomSystem *system);
76 void LoadSystemFromGalaxy(RefCountedPtr<StarSystem> system);
77 void ClearSystem();
78
79 void RegisterMenuActions();
80
81 bool HasUnsavedChanges();
82 void SaveCurrentFile();
83 void OnSaveComplete(bool success);
84
85 void ActivateOpenDialog();
86 void ActivateSaveDialog();
87 void ActivateNewSystemDialog();
88
89 void HandlePendingFileRequest();
90 void HandleBodyOperations();
91
92 void SetupLayout(ImGuiID dockspaceID);
93 void DrawInterface();
94
95 void DrawMenuBar();
96
97 bool DrawBodyNode(SystemBody *body, bool isRoot);
98 void HandleOutlinerDragDrop(SystemBody *refBody);
99 void DrawOutliner();
100
101 void DrawBodyProperties();
102 void DrawSystemProperties();
103
104 void EditName(const char *undo_label, std::string *name);
105
106 void DrawUndoDebug();
107
108 UndoSystem *GetUndo() { return m_undo.get(); }
109
110private:
111 class UndoSetSelection;
112
113 // Pending file actions which triggered an unsaved changes modal
114 enum FileRequestType {
115 FileRequest_None,
116 FileRequest_Open,
117 FileRequest_New,
118 FileRequest_Quit
119 };
120
121 // Pending actions to the body tree hierarchy that should
122 // be handled at the end of the frame
123 struct BodyRequest {
124 enum Type {
125 TYPE_None,
126 TYPE_Add,
127 TYPE_Delete,
128 TYPE_Reparent,
129 TYPE_Resort
130 };
131
132 Type type = TYPE_None;
133 uint32_t newBodyType = 0; // SystemBody::BodyType
134 SystemBody *parent = nullptr;
135 SystemBody *body = nullptr;
136 size_t idx = 0;
137 };
138
139 EditorApp *m_app;
140
141 RefCountedPtr<Galaxy> m_galaxy;
143 std::unique_ptr<CustomSystemsDatabase> m_systemLoader;
144
145 CustomSystemInfo m_systemInfo;
146
147 std::unique_ptr<SystemEditorViewport> m_viewport;
148
149 Random m_random;
150 std::unique_ptr<class LuaNameGen> m_nameGen;
151
152 std::unique_ptr<UndoSystem> m_undo;
153 size_t m_lastSavedUndoStack;
154
155 std::string m_filepath;
156 std::string m_filedir;
157
158 SystemBody *m_selectedBody;
159 SystemBody *m_contextBody;
160
161 BodyRequest m_pendingOp;
162
163 FileRequestType m_pendingFileReq;
164
165 std::unique_ptr<pfd::open_file> m_openFile;
166 std::unique_ptr<pfd::save_file> m_saveFile;
167
168 SystemPath m_openSystemPath;
169
170 RefCountedPtr<FileActionOpenModal> m_fileActionModal;
171 RefCountedPtr<UnsavedFileModal> m_unsavedFileModal;
172 RefCountedPtr<NewSystemModal> m_newSystemModal;
173
174 SystemPath m_newSystemPath;
175
176 std::unique_ptr<ActionBinder> m_menuBinder;
177
178 bool m_metricsWindowOpen = false;
179 bool m_undoStackWindowOpen = false;
180 bool m_binderWindowOpen = false;
181 bool m_debugWindowOpen = false;
182
183 bool m_resetDockingLayout = false;
184};
185
186} // namespace Editor
unsigned int ImGuiID
Definition: Modal.h:9
unsigned int ImGuiID
Definition: SystemEditor.h:18
Definition: Application.h:21
Definition: CustomSystem.h:45
Definition: CustomSystem.h:91
Definition: EditorApp.h:20
Definition: SystemEditor.h:46
bool WriteSystem(const std::string &filepath)
Definition: SystemEditor.cpp:241
void Update(float deltaTime) override
Definition: SystemEditor.cpp:555
Random & GetRng()
Definition: SystemEditor.h:58
RefCountedPtr< Galaxy > GetGalaxy()
Definition: SystemEditor.cpp:360
bool LoadSystem(SystemPath path)
Definition: SystemEditor.cpp:175
void End() override
Definition: SystemEditor.cpp:373
void NewSystem(SystemPath path)
Definition: SystemEditor.cpp:135
void HandleInput()
Definition: SystemEditor.cpp:550
void SetSelectedBody(SystemBody *body)
Definition: SystemEditor.cpp:362
bool LoadSystemFromDisk(const std::string &absolutePath)
Definition: SystemEditor.cpp:153
SystemBody * GetSelectedBody()
Definition: SystemEditor.h:62
void DrawBodyContextMenu(SystemBody *body)
Definition: SystemEditor.cpp:1031
~SystemEditor()
Definition: SystemEditor.cpp:131
void Start() override
Definition: SystemEditor.cpp:369
Definition: UndoSystem.h:112
Definition: FileSystem.h:78
Definition: Galaxy.h:18
Definition: LuaNameGen.h:14
Definition: Random.h:29
Definition: RefCounted.h:36
Definition: StarSystem.h:28
Definition: SystemBody.h:137
Definition: SystemPath.h:13
Definition: ActionBinder.h:14
const char * GetBodyIcon(const SystemBody *body)
Definition: SystemEditor.cpp:56
Definition: CityOnPlanet.h:28
Definition: SystemEditor.h:20