yaze 0.2.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
popup_manager.cc
Go to the documentation of this file.
1#include "popup_manager.h"
2
4#include "app/gui/style.h"
5#include "app/gui/icons.h"
6#include "util/hex.h"
7#include "imgui/misc/cpp/imgui_stdlib.h"
8
9namespace yaze {
10namespace editor {
11
12using namespace ImGui;
13
15 : editor_manager_(editor_manager), status_(absl::OkStatus()) {}
16
18 // Register all popups
19 popups_["About"] = {"About", false, [this]() { DrawAboutPopup(); }};
20 popups_["ROM Information"] = {"ROM Information", false, [this]() { DrawRomInfoPopup(); }};
21 popups_["Save As.."] = {"Save As..", false, [this]() { DrawSaveAsPopup(); }};
22 popups_["New Project"] = {"New Project", false, [this]() { DrawNewProjectPopup(); }};
23 popups_["Supported Features"] = {"Supported Features", false, [this]() { DrawSupportedFeaturesPopup(); }};
24 popups_["Open a ROM"] = {"Open a ROM", false, [this]() { DrawOpenRomHelpPopup(); }};
25 popups_["Manage Project"] = {"Manage Project", false, [this]() { DrawManageProjectPopup(); }};
26}
27
29 // Draw status popup if needed
31
32 // Draw all registered popups
33 for (auto& [name, params] : popups_) {
34 if (params.is_visible) {
35 OpenPopup(name.c_str());
36 if (BeginPopupModal(name.c_str(), nullptr, ImGuiWindowFlags_AlwaysAutoResize)) {
37 params.draw_function();
38 EndPopup();
39 }
40 }
41 }
42}
43
44void PopupManager::Show(const char* name) {
45 auto it = popups_.find(name);
46 if (it != popups_.end()) {
47 it->second.is_visible = true;
48 }
49}
50
51void PopupManager::Hide(const char* name) {
52 auto it = popups_.find(name);
53 if (it != popups_.end()) {
54 it->second.is_visible = false;
55 CloseCurrentPopup();
56 }
57}
58
59bool PopupManager::IsVisible(const char* name) const {
60 auto it = popups_.find(name);
61 if (it != popups_.end()) {
62 return it->second.is_visible;
63 }
64 return false;
65}
66
67void PopupManager::SetStatus(const absl::Status& status) {
68 if (!status.ok()) {
69 show_status_ = true;
70 prev_status_ = status;
71 status_ = status;
72 }
73}
74
75bool PopupManager::BeginCentered(const char* name) {
76 ImGuiIO const& io = GetIO();
77 ImVec2 pos(io.DisplaySize.x * 0.5f, io.DisplaySize.y * 0.5f);
78 SetNextWindowPos(pos, ImGuiCond_Always, ImVec2(0.5f, 0.5f));
79 ImGuiWindowFlags flags =
80 ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoDecoration |
81 ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings;
82 return Begin(name, nullptr, flags);
83}
84
86 if (show_status_ && BeginCentered("StatusWindow")) {
87 Text("%s", ICON_MD_ERROR);
88 Text("%s", prev_status_.ToString().c_str());
89 Spacing();
90 NextColumn();
91 Columns(1);
92 Separator();
93 NewLine();
94 SameLine(128);
95 if (Button("OK", gui::kDefaultModalSize) || IsKeyPressed(ImGuiKey_Space)) {
96 show_status_ = false;
97 status_ = absl::OkStatus();
98 }
99 SameLine();
100 if (Button(ICON_MD_CONTENT_COPY, ImVec2(50, 0))) {
101 SetClipboardText(prev_status_.ToString().c_str());
102 }
103 End();
104 }
105}
106
108 Text("Yet Another Zelda3 Editor - v%s", editor_manager_->version().c_str());
109 Text("Written by: scawful");
110 Spacing();
111 Text("Special Thanks: Zarby89, JaredBrian");
112 Separator();
113
114 if (Button("Close", gui::kDefaultModalSize)) {
115 Hide("About");
116 }
117}
118
120 auto* current_rom = editor_manager_->GetCurrentRom();
121 if (!current_rom) return;
122
123 Text("Title: %s", current_rom->title().c_str());
124 Text("ROM Size: %s", util::HexLongLong(current_rom->size()).c_str());
125
126 if (Button("Close", gui::kDefaultModalSize) || IsKeyPressed(ImGuiKey_Escape)) {
127 Hide("ROM Information");
128 }
129}
130
132 static std::string save_as_filename = "";
133 InputText("Filename", &save_as_filename);
134 if (Button("Save", gui::kDefaultModalSize)) {
135 // Call the save function from editor manager
136 // This will need to be implemented in the editor manager
137 Hide("Save As..");
138 }
139 SameLine();
140 if (Button("Cancel", gui::kDefaultModalSize)) {
141 Hide("Save As..");
142 }
143}
144
146 static std::string save_as_filename = "";
147 InputText("Project Name", &save_as_filename);
148
149 // These would need to be implemented in the editor manager
150 if (Button("Destination Filepath", gui::kDefaultModalSize)) {
151 // Call file dialog
152 }
153 SameLine();
154 Text("%s", "filepath"); // This would be from the editor manager
155
156 if (Button("ROM File", gui::kDefaultModalSize)) {
157 // Call file dialog
158 }
159 SameLine();
160 Text("%s", "rom_filename"); // This would be from the editor manager
161
162 if (Button("Labels File", gui::kDefaultModalSize)) {
163 // Call file dialog
164 }
165 SameLine();
166 Text("%s", "labels_filename"); // This would be from the editor manager
167
168 if (Button("Code Folder", gui::kDefaultModalSize)) {
169 // Call file dialog
170 }
171 SameLine();
172 Text("%s", "code_folder"); // This would be from the editor manager
173
174 Separator();
175 if (Button("Create", gui::kDefaultModalSize)) {
176 // Create project
177 Hide("New Project");
178 }
179 SameLine();
180 if (Button("Cancel", gui::kDefaultModalSize)) {
181 Hide("New Project");
182 }
183}
184
186 Text("Overworld");
187 BulletText("LW/DW/SW Tilemap Editing");
188 BulletText("LW/DW/SW Map Properties");
189 BulletText("Create/Delete/Update Entrances");
190 BulletText("Create/Delete/Update Exits");
191 BulletText("Create/Delete/Update Sprites");
192 BulletText("Create/Delete/Update Items");
193
194 Text("Dungeon");
195 BulletText("View Room Header Properties");
196 BulletText("View Entrance Properties");
197
198 Text("Graphics");
199 BulletText("View Decompressed Graphics Sheets");
200 BulletText("View/Update Graphics Groups");
201
202 Text("Palettes");
203 BulletText("View Palette Groups");
204
205 Text("Saveable");
206 BulletText("All Listed Overworld Features");
207 BulletText("Hex Editor Changes");
208
209 if (Button("Close", gui::kDefaultModalSize)) {
210 Hide("Supported Features");
211 }
212}
213
215 Text("File -> Open");
216 Text("Select a ROM file to open");
217 Text("Supported ROMs (headered or unheadered):");
218 Text("The Legend of Zelda: A Link to the Past");
219 Text("US Version 1.0");
220 Text("JP Version 1.0");
221
222 if (Button("Close", gui::kDefaultModalSize)) {
223 Hide("Open a ROM");
224 }
225}
226
228 Text("Project Menu");
229 Text("Create a new project or open an existing one.");
230 Text("Save the project to save the current state of the project.");
231 TextWrapped(
232 "To save a project, you need to first open a ROM and initialize your "
233 "code path and labels file. Label resource manager can be found in "
234 "the View menu. Code path is set in the Code editor after opening a "
235 "folder.");
236
237 if (Button("Close", gui::kDefaultModalSize)) {
238 Hide("Manage Project");
239 }
240}
241
242} // namespace editor
243} // namespace yaze
The EditorManager controls the main editor window and manages the various editor classes.
void SetStatus(const absl::Status &status)
bool IsVisible(const char *name) const
void Show(const char *name)
void Hide(const char *name)
PopupManager(EditorManager *editor_manager)
std::unordered_map< std::string, PopupParams > popups_
EditorManager * editor_manager_
bool BeginCentered(const char *name)
#define ICON_MD_ERROR
Definition icons.h:684
#define ICON_MD_CONTENT_COPY
Definition icons.h:463
Editors are the view controllers for the application.
constexpr ImVec2 kDefaultModalSize
Definition input.h:21
std::string HexLongLong(uint64_t qword, HexStringParams params)
Definition hex.cc:72
Main namespace for the application.
Definition controller.cc:18