9#include "absl/status/statusor.h"
10#include "absl/strings/str_format.h"
11#include "absl/strings/string_view.h"
21#include "imgui/imgui.h"
34 if (
rom()->is_loaded()) {
44 return absl::OkStatus();
50 static bool create =
false;
51 if (!create &&
rom()->is_loaded()) {
59 if (ImGui::BeginTable(
"InventoryScreen", 3, ImGuiTableFlags_Resizable)) {
60 ImGui::TableSetupColumn(
"Canvas");
61 ImGui::TableSetupColumn(
"Tiles");
62 ImGui::TableSetupColumn(
"Palette");
63 ImGui::TableHeadersRow();
65 ImGui::TableNextColumn();
72 ImGui::TableNextColumn();
79 ImGui::TableNextColumn();
89 if (ImGui::BeginTable(
"InventoryToolset", 8, ImGuiTableFlags_SizingFixedFit,
91 ImGui::TableSetupColumn(
"#drawTool");
92 ImGui::TableSetupColumn(
"#sep1");
93 ImGui::TableSetupColumn(
"#zoomOut");
94 ImGui::TableSetupColumn(
"#zoomIN");
95 ImGui::TableSetupColumn(
"#sep2");
96 ImGui::TableSetupColumn(
"#bg2Tool");
97 ImGui::TableSetupColumn(
"#bg3Tool");
98 ImGui::TableSetupColumn(
"#itemTool");
114 std::vector<std::array<uint8_t, 25>> current_floor_rooms_d;
115 std::vector<std::array<uint8_t, 25>> current_floor_gfx_d;
118 uint8_t nbr_basement_d;
120 for (
int d = 0; d < 14; d++) {
121 current_floor_rooms_d.clear();
122 current_floor_gfx_d.clear();
142 nbr_basement_d &= 0x0F;
148 nbr_floor_d = nbr_floor_d >> 4;
150 total_floors_d = nbr_basement_d + nbr_floor_d;
155 for (
int i = 0; i < total_floors_d; i++) {
158 std::array<uint8_t, 25> rdata;
159 std::array<uint8_t, 25> gdata;
162 for (
int j = 0; j < 25; j++) {
165 rdata[j] =
rom()->data()[pcPtr + j + (i * 25)];
167 if (rdata[j] == 0x0F) {
170 gdata[j] =
rom()->data()[pcPtrGFX++];
177 current_floor_gfx_d.push_back(gdata);
178 current_floor_rooms_d.push_back(rdata);
181 dungeon_maps_.emplace_back(bossRoomD, nbr_floor_d, nbr_basement_d,
182 current_floor_rooms_d, current_floor_gfx_d);
185 return absl::OkStatus();
189 for (
int d = 0; d < 14; d++) {
197 for (
int i = 0; i < nbr_floors + nbr_basements; i++) {
198 for (
int j = 0; j < 25; j++) {
208 return absl::OkStatus();
214 for (
int i = 0; i < 186; i++) {
236 *
rom()->mutable_dungeon_palette(3)));
247 return absl::OkStatus();
252 if (ImGui::BeginTabBar(
"##DungeonMapTabs")) {
254 current_dungeon.nbr_of_floor + current_dungeon.nbr_of_basement;
255 for (
int i = 0; i < nbr_floors; i++) {
256 std::string tab_name = absl::StrFormat(
"Floor %d", i + 1);
257 if (i >= current_dungeon.nbr_of_floor) {
258 tab_name = absl::StrFormat(
"Basement %d",
259 i - current_dungeon.nbr_of_floor + 1);
262 if (ImGui::BeginTabItem(tab_name.c_str())) {
269 auto boss_room = current_dungeon.boss_room;
270 for (
int j = 0; j < 25; j++) {
271 if (current_dungeon.floor_rooms[
floor_number][j] != 0x0F) {
272 int tile16_id = current_dungeon.floor_rooms[
floor_number][j];
273 int posX = ((j % 5) * 32);
274 int posY = ((j / 5) * 32);
278 std::cout <<
"Tile16: " << tile16_id << std::endl;
316 if (ImGui::Button(
"Copy Floor", ImVec2(100, 0))) {
320 if (ImGui::Button(
"Paste Floor", ImVec2(100, 0))) {
335 ImGui::Text(
"Failed to load dungeon map tile16");
338 ImGui::Text(
"Failed to load dungeon maps");
342 static std::vector<std::string> dungeon_names = {
343 "Sewers/Sanctuary",
"Hyrule Castle",
"Eastern Palace",
344 "Desert Palace",
"Tower of Hera",
"Agahnim's Tower",
345 "Palace of Darkness",
"Swamp Palace",
"Skull Woods",
346 "Thieves' Town",
"Ice Palace",
"Misery Mire",
347 "Turtle Rock",
"Ganon's Tower"};
349 if (ImGui::BeginTable(
"DungeonMapsTable", 4, ImGuiTableFlags_Resizable)) {
350 ImGui::TableSetupColumn(
"Dungeon");
351 ImGui::TableSetupColumn(
"Map");
352 ImGui::TableSetupColumn(
"Rooms Gfx");
353 ImGui::TableSetupColumn(
"Tiles Gfx");
354 ImGui::TableHeadersRow();
357 ImGui::TableNextColumn();
358 for (
int i = 0; i < dungeon_names.size(); i++) {
359 rom()->resource_label()->SelectableLabelWithNameEdit(
362 if (ImGui::IsItemClicked()) {
368 ImGui::TableNextColumn();
371 ImGui::TableNextColumn();
372 if (ImGui::BeginChild(
"##DungeonMapTiles", ImVec2(0, 0),
true)) {
387 ImGui::TableNextColumn();
412 static bool show_bg1 =
true;
413 static bool show_bg2 =
true;
414 static bool show_bg3 =
true;
416 static bool drawing_bg1 =
true;
417 static bool drawing_bg2 =
false;
418 static bool drawing_bg3 =
false;
420 ImGui::Checkbox(
"Show BG1", &show_bg1);
422 ImGui::Checkbox(
"Show BG2", &show_bg2);
424 ImGui::Checkbox(
"Draw BG1", &drawing_bg1);
426 ImGui::Checkbox(
"Draw BG2", &drawing_bg2);
428 ImGui::Checkbox(
"Draw BG3", &drawing_bg3);
static Renderer & GetInstance()
void RenderBitmap(gfx::Bitmap *bitmap)
Used to render a bitmap to the screen.
gui::Canvas tilemap_canvas_
std::vector< std::vector< std::array< std::string, 25 > > > dungeon_map_labels_
void DrawInventoryMenuEditor()
gui::Canvas screen_canvas_
absl::Status LoadDungeonMapTile16()
bool dungeon_maps_loaded_
absl::Status Update() override
gfx::Tilesheet tile16_sheet_
zelda3::screen::Inventory inventory_
void DrawTitleScreenEditor()
void DrawDungeonMapsEditor()
absl::Status SaveDungeonMaps()
gfx::SnesPalette palette_
void DrawOverworldMapEditor()
bool paste_button_pressed
void DrawDungeonMapsTabs()
absl::Status LoadDungeonMaps()
void DrawNamingScreenEditor()
gui::Canvas tilesheet_canvas_
void DrawInventoryToolset()
std::vector< zelda3::screen::DungeonMap > dungeon_maps_
std::unordered_map< int, gfx::Bitmap > tile16_individual_
SNES 16-bit tile metadata container.
void Init(int width, int height, TileType tile_type)
Bitmap GetTile16(int tile_x, int tile_y)
void ComposeTile16(const std::vector< uint8_t > &graphics_buffer, const TileInfo &top_left, const TileInfo &top_right, const TileInfo &bottom_left, const TileInfo &bottom_right)
bool DrawTileSelector(int size)
void DrawBackground(ImVec2 canvas_size=ImVec2(0, 0), bool drag=false)
void DrawGrid(float grid_step=64.0f, int tile_id_offset=8)
void DrawText(std::string text, int x, int y)
void DrawBitmap(const Bitmap &bitmap, int border_offset=0, bool ready=true)
void DrawOutlineWithColor(int x, int y, int w, int h, ImVec4 color)
void DrawBitmapTable(const BitmapTable &gfx_bin)
void DrawContextMenu(gfx::Bitmap *bitmap=nullptr)
#define RETURN_IF_ERROR(expression)
#define ASSIGN_OR_RETURN(type_variable_name, expression)
#define ICON_MD_MORE_VERT
uint32_t SnesToPc(uint32_t addr) noexcept
std::string UppercaseHexByte(uint8_t byte, bool leading)
constexpr uint32_t kRedPen
TileInfo WordToTileInfo(uint16_t word)
bool InputHexByte(const char *label, uint8_t *data, float input_width, bool no_step)
absl::Status DisplayPalette(app::gfx::SnesPalette &palette, bool loaded)
bool InputHexWord(const char *label, uint16_t *data, float input_width, bool no_step)
constexpr int kDungeonMapTile16Expanded
constexpr int kDungeonMapGfxPtr
constexpr int kDungeonMapBossRooms
constexpr int kDungeonMapTile16
constexpr int kDungeonMapFloors
constexpr int kDungeonMapRoomsPtr
constexpr int kDungeonMapExpCheck