Skip to content

Commit 75ef4fd

Browse files
committed
Add tabs and dungeon room props to DungeonEditor
1 parent 3c92b58 commit 75ef4fd

File tree

2 files changed

+108
-3
lines changed

2 files changed

+108
-3
lines changed

Diff for: src/app/editor/dungeon_editor.cc

+104-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "app/core/common.h"
66
#include "app/gui/canvas.h"
77
#include "app/gui/icons.h"
8+
#include "app/gui/input.h"
89
#include "app/rom.h"
910
#include "app/zelda3/dungeon/room_names.h"
1011
#include "zelda3/dungeon/room.h"
@@ -14,6 +15,15 @@ namespace app {
1415
namespace editor {
1516

1617
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+
1727
DrawToolset();
1828

1929
ImGui::Separator();
@@ -31,24 +41,116 @@ void DungeonEditor::Update() {
3141
if (ImGuiID child_id = ImGui::GetID((void *)(intptr_t)9);
3242
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
3343
ImGuiWindowFlags_AlwaysVerticalScrollbar)) {
44+
int i = 0;
3445
for (const auto each_room_name : zelda3::dungeon::kRoomNames) {
3546
ImGui::Button(each_room_name.data());
47+
if (ImGui::IsItemClicked()) {
48+
active_rooms_.push_back(i);
49+
}
50+
i += 1;
3651
}
3752
}
3853
ImGui::EndChild();
3954
}
4055

4156
ImGui::TableNextColumn();
42-
DrawDungeonCanvas();
57+
DrawDungeonTabView();
4358
ImGui::TableNextColumn();
4459
DrawTileSelector();
4560
ImGui::EndTable();
4661
}
4762
}
4863

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+
50151
canvas_.DrawBackground();
51152
canvas_.DrawContextMenu();
153+
canvas_.DrawBitmap(rooms_[room_id].current_graphics_, 2, is_loaded_);
52154
canvas_.DrawGrid();
53155
canvas_.DrawOverlay();
54156
}

Diff for: src/app/editor/dungeon_editor.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,17 @@ class DungeonEditor : public SharedROM {
2020
private:
2121
void DrawToolset();
2222

23-
void DrawDungeonCanvas();
23+
void DrawDungeonTabView();
24+
void DrawDungeonCanvas(int room_id);
2425
void DrawRoomGraphics();
2526
void DrawTileSelector();
2627

2728
bool is_loaded_ = false;
2829

2930
gfx::Bitmap room_gfx_bmp_;
3031

32+
ImVector<int> active_rooms_;
33+
3134
std::vector<zelda3::dungeon::Room> rooms_;
3235

3336
gui::Canvas canvas_;

0 commit comments

Comments
 (0)