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
3
#include "
app/editor/editor_manager.h
"
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
9
namespace
yaze
{
10
namespace
editor
{
11
12
using namespace
ImGui;
13
14
PopupManager::PopupManager
(
EditorManager
* editor_manager)
15
:
editor_manager_
(editor_manager),
status_
(absl::OkStatus()) {}
16
17
void
PopupManager::Initialize
() {
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
28
void
PopupManager::DrawPopups
() {
29
// Draw status popup if needed
30
DrawStatusPopup
();
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
44
void
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
51
void
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
59
bool
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
67
void
PopupManager::SetStatus
(
const
absl::Status& status) {
68
if
(!status.ok()) {
69
show_status_
=
true
;
70
prev_status_
= status;
71
status_
= status;
72
}
73
}
74
75
bool
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
85
void
PopupManager::DrawStatusPopup
() {
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
107
void
PopupManager::DrawAboutPopup
() {
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
119
void
PopupManager::DrawRomInfoPopup
() {
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
131
void
PopupManager::DrawSaveAsPopup
() {
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
145
void
PopupManager::DrawNewProjectPopup
() {
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
185
void
PopupManager::DrawSupportedFeaturesPopup
() {
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
214
void
PopupManager::DrawOpenRomHelpPopup
() {
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
227
void
PopupManager::DrawManageProjectPopup
() {
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
yaze::editor::EditorManager
The EditorManager controls the main editor window and manages the various editor classes.
Definition
editor_manager.h:44
yaze::editor::PopupManager::SetStatus
void SetStatus(const absl::Status &status)
Definition
popup_manager.cc:67
yaze::editor::PopupManager::IsVisible
bool IsVisible(const char *name) const
Definition
popup_manager.cc:59
yaze::editor::PopupManager::DrawPopups
void DrawPopups()
Definition
popup_manager.cc:28
yaze::editor::PopupManager::Show
void Show(const char *name)
Definition
popup_manager.cc:44
yaze::editor::PopupManager::Hide
void Hide(const char *name)
Definition
popup_manager.cc:51
yaze::editor::PopupManager::DrawSupportedFeaturesPopup
void DrawSupportedFeaturesPopup()
Definition
popup_manager.cc:185
yaze::editor::PopupManager::Initialize
void Initialize()
Definition
popup_manager.cc:17
yaze::editor::PopupManager::PopupManager
PopupManager(EditorManager *editor_manager)
Definition
popup_manager.cc:14
yaze::editor::PopupManager::popups_
std::unordered_map< std::string, PopupParams > popups_
Definition
popup_manager.h:77
yaze::editor::PopupManager::editor_manager_
EditorManager * editor_manager_
Definition
popup_manager.h:76
yaze::editor::PopupManager::DrawStatusPopup
void DrawStatusPopup()
Definition
popup_manager.cc:85
yaze::editor::PopupManager::DrawSaveAsPopup
void DrawSaveAsPopup()
Definition
popup_manager.cc:131
yaze::editor::PopupManager::prev_status_
absl::Status prev_status_
Definition
popup_manager.h:80
yaze::editor::PopupManager::status_
absl::Status status_
Definition
popup_manager.h:78
yaze::editor::PopupManager::BeginCentered
bool BeginCentered(const char *name)
Definition
popup_manager.cc:75
yaze::editor::PopupManager::show_status_
bool show_status_
Definition
popup_manager.h:79
yaze::editor::PopupManager::DrawRomInfoPopup
void DrawRomInfoPopup()
Definition
popup_manager.cc:119
yaze::editor::PopupManager::DrawAboutPopup
void DrawAboutPopup()
Definition
popup_manager.cc:107
yaze::editor::PopupManager::DrawOpenRomHelpPopup
void DrawOpenRomHelpPopup()
Definition
popup_manager.cc:214
yaze::editor::PopupManager::DrawNewProjectPopup
void DrawNewProjectPopup()
Definition
popup_manager.cc:145
yaze::editor::PopupManager::DrawManageProjectPopup
void DrawManageProjectPopup()
Definition
popup_manager.cc:227
editor_manager.h
hex.h
icons.h
ICON_MD_ERROR
#define ICON_MD_ERROR
Definition
icons.h:684
ICON_MD_CONTENT_COPY
#define ICON_MD_CONTENT_COPY
Definition
icons.h:463
yaze::editor
Editors are the view controllers for the application.
Definition
assembly_editor.cc:13
yaze::gui::kDefaultModalSize
constexpr ImVec2 kDefaultModalSize
Definition
input.h:21
yaze::util::HexLongLong
std::string HexLongLong(uint64_t qword, HexStringParams params)
Definition
hex.cc:72
yaze
Main namespace for the application.
Definition
controller.cc:18
popup_manager.h
style.h
src
app
editor
system
popup_manager.cc
Generated by
1.13.2