5
5
#include " app/core/common.h"
6
6
#include " app/gui/canvas.h"
7
7
#include " app/gui/icons.h"
8
+ #include " app/gui/input.h"
8
9
#include " app/rom.h"
9
10
#include " app/zelda3/dungeon/room_names.h"
10
11
#include " zelda3/dungeon/room.h"
@@ -14,6 +15,15 @@ namespace app {
14
15
namespace editor {
15
16
16
17
void DungeonEditor::Update () {
18
+ if (!is_loaded_) {
19
+ for (int i = 0 ; i < 0x100 ; i++) {
20
+ rooms_.emplace_back (zelda3::dungeon::Room (i));
21
+ rooms_[i].LoadHeader ();
22
+ rooms_[i].LoadRoomGraphics (rooms_[i].blockset );
23
+ }
24
+ is_loaded_ = true ;
25
+ }
26
+
17
27
DrawToolset ();
18
28
19
29
ImGui::Separator ();
@@ -31,24 +41,116 @@ void DungeonEditor::Update() {
31
41
if (ImGuiID child_id = ImGui::GetID ((void *)(intptr_t )9 );
32
42
ImGui::BeginChild (child_id, ImGui::GetContentRegionAvail (), true ,
33
43
ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
44
+ int i = 0 ;
34
45
for (const auto each_room_name : zelda3::dungeon::kRoomNames ) {
35
46
ImGui::Button (each_room_name.data ());
47
+ if (ImGui::IsItemClicked ()) {
48
+ active_rooms_.push_back (i);
49
+ }
50
+ i += 1 ;
36
51
}
37
52
}
38
53
ImGui::EndChild ();
39
54
}
40
55
41
56
ImGui::TableNextColumn ();
42
- DrawDungeonCanvas ();
57
+ DrawDungeonTabView ();
43
58
ImGui::TableNextColumn ();
44
59
DrawTileSelector ();
45
60
ImGui::EndTable ();
46
61
}
47
62
}
48
63
49
- void DungeonEditor::DrawDungeonCanvas () {
64
+ // Using ImGui Custom Tabs show each individual room the user selects from the
65
+ // Buttons above to open a canvas for each individual room.
66
+ void DungeonEditor::DrawDungeonTabView () {
67
+ static int next_tab_id = 0 ;
68
+
69
+ // TabItemButton() and Leading/Trailing flags are distinct features which we
70
+ // will demo together. (It is possible to submit regular tabs with
71
+ // Leading/Trailing flags, or TabItemButton tabs without Leading/Trailing
72
+ // flags... but they tend to make more sense together)
73
+ static bool show_trailing_button = true ;
74
+ ImGui::Checkbox (" Show Trailing TabItemButton()" , &show_trailing_button);
75
+
76
+ // Expose some other flags which are useful to showcase how they interact with
77
+ // Leading/Trailing tabs
78
+ static ImGuiTabBarFlags tab_bar_flags =
79
+ ImGuiTabBarFlags_AutoSelectNewTabs | ImGuiTabBarFlags_Reorderable |
80
+ ImGuiTabBarFlags_FittingPolicyResizeDown |
81
+ ImGuiTabBarFlags_TabListPopupButton;
82
+
83
+ if (ImGui::CheckboxFlags (" ImGuiTabBarFlags_FittingPolicyResizeDown" ,
84
+ &tab_bar_flags,
85
+ ImGuiTabBarFlags_FittingPolicyResizeDown))
86
+ tab_bar_flags &= ~(ImGuiTabBarFlags_FittingPolicyMask_ ^
87
+ ImGuiTabBarFlags_FittingPolicyResizeDown);
88
+ if (ImGui::CheckboxFlags (" ImGuiTabBarFlags_FittingPolicyScroll" ,
89
+ &tab_bar_flags,
90
+ ImGuiTabBarFlags_FittingPolicyScroll))
91
+ tab_bar_flags &= ~(ImGuiTabBarFlags_FittingPolicyMask_ ^
92
+ ImGuiTabBarFlags_FittingPolicyScroll);
93
+
94
+ if (ImGui::BeginTabBar (" MyTabBar" , tab_bar_flags)) {
95
+ // Demo Trailing Tabs: click the "+" button to add a new tab (in your app
96
+ // you may want to use a font icon instead of the "+") Note that we submit
97
+ // it before the regular tabs, but because of the ImGuiTabItemFlags_Trailing
98
+ // flag it will always appear at the end.
99
+ if (show_trailing_button)
100
+ if (ImGui::TabItemButton (
101
+ " +" , ImGuiTabItemFlags_Trailing | ImGuiTabItemFlags_NoTooltip))
102
+ active_rooms_.push_back (next_tab_id++); // Add new tab
103
+
104
+ // Submit our regular tabs
105
+ for (int n = 0 ; n < active_rooms_.Size ;) {
106
+ bool open = true ;
107
+
108
+ if (ImGui::BeginTabItem (
109
+ zelda3::dungeon::kRoomNames [active_rooms_[n]].data (), &open ,
110
+ ImGuiTabItemFlags_None)) {
111
+ DrawDungeonCanvas (active_rooms_[n]);
112
+ ImGui::EndTabItem ();
113
+ }
114
+
115
+ if (!open )
116
+ active_rooms_.erase (active_rooms_.Data + n);
117
+ else
118
+ n++;
119
+ }
120
+
121
+ ImGui::EndTabBar ();
122
+ }
123
+ ImGui::Separator ();
124
+ }
125
+
126
+ void DungeonEditor::DrawDungeonCanvas (int room_id) {
127
+ ImGui::BeginGroup ();
128
+
129
+ gui::InputHexByte (" Layout" , &rooms_[room_id].layout );
130
+ ImGui::SameLine ();
131
+
132
+ gui::InputHexByte (" Blockset" , &rooms_[room_id].blockset );
133
+ ImGui::SameLine ();
134
+
135
+ gui::InputHexByte (" Spriteset" , &rooms_[room_id].spriteset );
136
+ ImGui::SameLine ();
137
+
138
+ gui::InputHexByte (" Palette" , &rooms_[room_id].palette );
139
+
140
+ gui::InputHexByte (" Floor1" , &rooms_[room_id].floor1 );
141
+ ImGui::SameLine ();
142
+
143
+ gui::InputHexByte (" Floor2" , &rooms_[room_id].floor2 );
144
+ ImGui::SameLine ();
145
+
146
+ gui::InputHexWord (" Message ID" , &rooms_[room_id].message_id_ );
147
+ ImGui::SameLine ();
148
+
149
+ ImGui::EndGroup ();
150
+
50
151
canvas_.DrawBackground ();
51
152
canvas_.DrawContextMenu ();
153
+ canvas_.DrawBitmap (rooms_[room_id].current_graphics_ , 2 , is_loaded_);
52
154
canvas_.DrawGrid ();
53
155
canvas_.DrawOverlay ();
54
156
}
0 commit comments