4#include <unordered_map>
7#include "absl/status/status.h"
8#include "absl/strings/str_format.h"
23#include "imgui/imgui.h"
31using ImGui::BeginChild;
32using ImGui::BeginTabBar;
33using ImGui::BeginTabItem;
34using ImGui::BeginTable;
35using ImGui::BeginTooltip;
39using ImGui::EndTabBar;
40using ImGui::EndTabItem;
42using ImGui::EndTooltip;
43using ImGui::IsItemHovered;
45using ImGui::PopStyleColor;
46using ImGui::PushStyleColor;
48using ImGui::Selectable;
49using ImGui::Separator;
50using ImGui::TableHeadersRow;
51using ImGui::TableNextColumn;
52using ImGui::TableNextRow;
53using ImGui::TableSetupColumn;
78 static bool use_work_area =
true;
79 static ImGuiWindowFlags
flags = ImGuiWindowFlags_NoDecoration |
80 ImGuiWindowFlags_NoMove |
81 ImGuiWindowFlags_NoSavedSettings;
82 const ImGuiViewport *viewport = ImGui::GetMainViewport();
83 ImGui::SetNextWindowPos(use_work_area ? viewport->WorkPos : viewport->Pos);
84 ImGui::SetNextWindowSize(use_work_area ? viewport->WorkSize : viewport->Size);
95 static bool show_gfx_group =
false;
96 static bool show_properties =
false;
99 for (
const auto &name : kToolsetColumnNames)
100 ImGui::TableSetupColumn(name.data());
185 show_gfx_group = !show_gfx_group;
193 std::vector<uint8_t> png_data;
199 "Failed to convert overworld map surface to PNG");
210 Checkbox(
"Properties", &show_properties);
218 ImGuiWindowFlags_MenuBar);
223 if (show_gfx_group) {
229 if (show_properties) {
230 ImGui::Begin(
"Properties", &show_properties);
236 if (!ImGui::IsAnyItemActive()) {
237 if (ImGui::IsKeyDown(ImGuiKey_1)) {
239 }
else if (ImGui::IsKeyDown(ImGuiKey_2)) {
241 }
else if (ImGui::IsKeyDown(ImGuiKey_3)) {
243 }
else if (ImGui::IsKeyDown(ImGuiKey_4)) {
245 }
else if (ImGui::IsKeyDown(ImGuiKey_5)) {
247 }
else if (ImGui::IsKeyDown(ImGuiKey_6)) {
249 }
else if (ImGui::IsKeyDown(ImGuiKey_7)) {
251 }
else if (ImGui::IsKeyDown(ImGuiKey_8)) {
258 "##WorldId",
"##GfxId",
"##PalId",
"##SprGfxId",
259 "##5thCol",
"##6thCol",
"##7thCol",
"##8thCol"};
264 ImGui::TableSetupColumn(name);
267 ImGui::SetNextItemWidth(120.f);
274 ->mutable_area_graphics(),
285 ->mutable_area_palette(),
318 ImGui::SetNextItemWidth(100.f);
325 HOVER_HINT(
"Enable Mosaic effect for the current map");
334 ImGui::TableSetupColumn(name);
337 ImGui::SetNextItemWidth(120.f);
340 static const std::array<std::string, 8> kCustomMapSettingsColumnNames = {
341 "TileGfx0",
"TileGfx1",
"TileGfx2",
"TileGfx3",
342 "TileGfx4",
"TileGfx5",
"TileGfx6",
"TileGfx7"};
343 for (
int i = 0; i < 8; ++i) {
348 ->mutable_custom_tileset(i),
360 ->mutable_area_palette(),
393 ImGui::SetNextItemWidth(100.f);
400 HOVER_HINT(
"Enable Mosaic effect for the current map");
409 for (
int i = 0; i < 0x40; i++) {
442 int mouse_x = mouse_position.x;
443 int mouse_y = mouse_position.y;
449 auto &selected_world =
454 int index_x = superX * 32 + tile16_x;
455 int index_y = superY * 32 + tile16_y;
461 const ImVec2 &click_position,
const std::vector<uint8_t> &tile_data) {
469 ImVec2 start_position;
500 if (ImGui::IsMouseClicked(ImGuiMouseButton_Left) ||
501 ImGui::IsMouseDragging(ImGuiMouseButton_Left)) {
502 auto &selected_world =
517 if (start_x > end_x) std::swap(start_x, end_x);
518 if (start_y > end_y) std::swap(start_y, end_y);
520 constexpr int local_map_size = 512;
522 constexpr int tiles_per_local_map = local_map_size /
kTile16Size;
524 for (
int y = start_y, i = 0; y <= end_y; y +=
kTile16Size) {
525 for (
int x = start_x; x <= end_x; x +=
kTile16Size, ++i) {
527 int local_map_x = x / local_map_size;
528 int local_map_y = y / local_map_size;
535 int index_x = local_map_x * tiles_per_local_map + tile16_x;
536 int index_y = local_map_y * tiles_per_local_map + tile16_y;
539 selected_world[index_x][index_y] = tile16_id;
558 static std::vector<int> tile16_ids;
561 if (tile16_ids.size() != 0) {
577 const auto mouse_position = ImGui::GetIO().MousePos;
578 const int large_map_size = 1024;
598 const int highlight_parent =
600 const int parent_map_x = highlight_parent % 8;
601 const int parent_map_y = highlight_parent / 8;
606 const int current_map_x = current_highlighted_map % 8;
607 const int current_map_y = current_highlighted_map / 8;
614 ImGui::IsMouseClicked(ImGuiMouseButton_Right)) {
621 return absl::OkStatus();
625 if (ImGui::IsMouseDragging(ImGuiMouseButton_Middle)) {
631 if (ImGui::IsMouseReleased(ImGuiMouseButton_Middle) &&
679 if (ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows) &&
680 ImGui::IsMouseDragging(ImGuiMouseButton_Middle)) {
681 ImGui::SetScrollX(ImGui::GetScrollX() + ImGui::GetIO().MouseWheelH * 16.0f);
682 ImGui::SetScrollY(ImGui::GetScrollY() + ImGui::GetIO().MouseWheel * 16.0f);
700 int grid_x =
static_cast<int>(tile_pos.x / 32);
701 int grid_y =
static_cast<int>(tile_pos.y / 32);
702 int id = grid_x + grid_y * 8;
718 return absl::OkStatus();
726 for (
auto &value :
rom()->gfx_sheets()) {
727 int offset = 0x40 * (key + 1);
732 auto texture = value.texture();
772 return absl::OkStatus();
777 ImGuiTabBarFlags_FittingPolicyScroll)) {
778 if (BeginTabItem(
"Tile16")) {
782 if (BeginTabItem(
"Tile8")) {
790 if (BeginTabItem(
"Area Graphics")) {
796 return absl::OkStatus();
805 auto color = ImVec4(255, 255, 0, 100);
807 color = ImVec4(255, 255, 255, 200);
817 ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
822 ImGui::IsMouseClicked(ImGuiMouseButton_Right)) {
839 entrance.entrance_id_ = deleted_entrance_id;
842 entrance.deleted =
false;
846 const auto is_hovering =
849 if (!is_hovering && ImGui::IsMouseClicked(ImGuiMouseButton_Right)) {
850 ImGui::OpenPopup(
"Entrance Inserter");
871 ImVec4(255, 255, 255, 150));
879 ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) {
884 ImGui::IsMouseClicked(ImGuiMouseButton_Right)) {
889 ImGui::OpenPopup(
"Exit editor");
905 if (!hovering && ImGui::IsMouseClicked(ImGuiMouseButton_Right)) {
906 ImGui::OpenPopup(
"Exit Inserter");
932 if (hovering && ImGui::IsMouseClicked(ImGuiMouseButton_Right)) {
938 std::string item_name =
"";
942 item_name = absl::StrFormat(
"0x%02X", item.id_);
955 if (!hovering && ImGui::IsMouseClicked(ImGuiMouseButton_Right)) {
956 ImGui::OpenPopup(
"Item Inserter");
969 if (!sprite.deleted()) {
979 int map_x = sprite.map_x();
980 int map_y = sprite.map_y();
987 ImVec4(255, 0, 255, 150));
994 ImGui::IsMouseClicked(ImGuiMouseButton_Right)) {
1011 if (!hovering && ImGui::IsMouseClicked(ImGuiMouseButton_Right)) {
1012 ImGui::OpenPopup(
"Sprite Inserter");
1042 return absl::OkStatus();
1076 tile_data[position] = value;
1101 return absl::OkStatus();
1106 for (
int i = 0; i < 3; i++)
1108 int width = sprite.Width();
1109 int height = sprite.Height();
1111 auto spr_gfx = sprite.PreviewGraphics();
1116 return absl::OkStatus();
1130 maps_bmp_[map_index].set_modified(
true);
1135 std::vector<std::future<void>> futures;
1138 auto refresh_map_async = [
this](
int map_index) {
1147 for (
int i = 1; i < 4; i++) {
1149 if (i >= 2) sibling_index += 6;
1151 std::async(std::launch::async, refresh_map_async, sibling_index));
1152 indices[i] = sibling_index;
1155 indices[0] = source_map_id;
1157 std::async(std::launch::async, refresh_map_async, source_map_id));
1159 for (
auto &each : futures) {
1162 int n = is_large ? 4 : 1;
1164 for (
int i = 0; i < n; ++i) {
1176 for (
int i = 1; i < 4; i++) {
1178 if (i >= 2) sibling_index += 6;
1182 maps_bmp_[sibling_index].ApplyPalette(current_map_palette));
1187 return absl::OkStatus();
1192 if (current_ow_map.is_large_map()) {
1194 for (
int i = 1; i < 4; i++) {
1195 int sibling_index = current_ow_map.parent() + i;
1200 map.set_area_graphics(current_ow_map.area_graphics());
1201 map.set_area_palette(current_ow_map.area_palette());
1206 map.set_message_id(current_ow_map.message_id());
1214 return absl::OkStatus();
1227 std::vector<std::future<void>> futures;
1230 futures.push_back(std::async(
1233 std::vector<uint8_t> tile_data(16 * 16, 0x00);
1234 for (
int ty = 0; ty < 16; ty++) {
1235 for (
int tx = 0; tx < 16; tx++) {
1236 int position = tx + (ty * 0x10);
1238 tile16_data[(index % 8 * 16) + (index / 8 * 16 * 0x80) +
1240 tile_data[position] = value;
1248 for (
auto &future : futures) {
1258 return absl::OkStatus();
1262 static bool init_properties =
false;
1264 if (!init_properties) {
1265 for (
int i = 0; i < 0x40; i++) {
1266 std::string area_graphics_str = absl::StrFormat(
1269 ->push_back(area_graphics_str);
1271 area_graphics_str = absl::StrFormat(
1274 ->push_back(area_graphics_str);
1276 std::string area_palette_str =
1279 ->push_back(area_palette_str);
1281 area_palette_str = absl::StrFormat(
1284 ->push_back(area_palette_str);
1285 std::string sprite_gfx_str = absl::StrFormat(
1288 ->push_back(sprite_gfx_str);
1290 sprite_gfx_str = absl::StrFormat(
1293 ->push_back(sprite_gfx_str);
1295 sprite_gfx_str = absl::StrFormat(
1298 ->push_back(sprite_gfx_str);
1300 sprite_gfx_str = absl::StrFormat(
1303 ->push_back(sprite_gfx_str);
1305 std::string sprite_palette_str = absl::StrFormat(
1308 ->push_back(sprite_palette_str);
1310 sprite_palette_str = absl::StrFormat(
1313 ->push_back(sprite_palette_str);
1315 sprite_palette_str = absl::StrFormat(
1318 ->push_back(sprite_palette_str);
1320 sprite_palette_str = absl::StrFormat(
1323 ->push_back(sprite_palette_str);
1325 init_properties =
true;
1328 Text(
"Area Gfx LW/DW");
1336 Text(
"Sprite Gfx LW/DW");
1350 Text(
"Area Pal LW/DW");
1357 static bool show_gfx_group =
false;
1358 Checkbox(
"Show Gfx Group Editor", &show_gfx_group);
1359 if (show_gfx_group) {
1367 if (BeginTable(
"UsageStatsTable", 3,
kOWEditFlags, ImVec2(0, 0))) {
1368 TableSetupColumn(
"Entrances");
1369 TableSetupColumn(
"Grid", ImGuiTableColumnFlags_WidthStretch,
1370 ImGui::GetContentRegionAvail().x);
1371 TableSetupColumn(
"Usage", ImGuiTableColumnFlags_WidthFixed, 256);
1376 if (BeginChild(
"UnusedSpritesetScroll", ImVec2(0, 0),
true,
1377 ImGuiWindowFlags_HorizontalScrollbar)) {
1378 for (
int i = 0; i < 0x81; i++) {
1379 auto entrance_name =
rom()->resource_label()->GetLabel(
1381 std::string str = absl::StrFormat(
"%#x - %s", i, entrance_name);
1384 ? ImGuiSelectableFlags_Disabled
1390 if (IsItemHovered()) {
1392 Text(
"Entrance ID: %d", i);
1413 return absl::OkStatus();
1418 int totalSquares = 128;
1419 int squaresWide = 8;
1420 int squaresTall = (totalSquares + squaresWide - 1) /
1424 for (
int row = 0; row < squaresTall; ++row) {
1427 for (
int col = 0; col < squaresWide; ++col) {
1428 if (row * squaresWide + col >= totalSquares) {
1438 ImVec4(1.0f, 0.5f, 0.0f, 1.0f));
1442 if (Button(
"##square", ImVec2(20, 20))) {
1454 if (IsItemHovered()) {
1469 Text(
"Current Tile16 Drawn Position (Relative): %d, %d", relative_x,
1473 Text(
"Light World Map Tiles: %d",
1475 Text(
"Dark World Map Tiles: %d",
1477 Text(
"Special World Map Tiles: %d",
1480 static bool view_lw_map_tiles =
false;
1481 static MemoryEditor mem_edit;
1483 if (Button(
"View Light World Map Tiles")) {
1484 view_lw_map_tiles = !view_lw_map_tiles;
1487 if (view_lw_map_tiles) {
1488 mem_edit.DrawContents(
1501 [
this]() { DrawOverworldCanvas(); });
1503 [
this]() { status_ = DrawTileSelector(); });
1505 if (rom()->is_loaded()) {
1506 status_ = UpdateUsageStats();
1510 [
this]() { DrawToolset(); });
1512 if (rom()->is_loaded()) {
1513 status_ = tile16_editor_.Update();
1516 gui::zeml::Bind(&*layout_node_.GetNode(
"OwGfxGroupEditor"), [
this]() {
1517 if (rom()->is_loaded()) {
1518 status_ = gfx_group_editor_.Update();
static Renderer & GetInstance()
void RenderBitmap(gfx::Bitmap *bitmap)
Used to render a bitmap to the screen.
void UpdateBitmap(gfx::Bitmap *bitmap, bool use_sdl_update=false)
Used to update a bitmap on the screen.
absl::Status LoadEntranceTileTypes(Rom &rom)
void RefreshMapProperties()
absl::Status Redo() override
zelda3::overworld::OverworldItem current_item_
gui::Canvas blockset_canvas_
absl::Status Update() final
EditingMode previous_mode
zelda3::GameEntity * current_entity_
std::vector< gfx::Bitmap > tile16_individual_
zelda3::GameEntity * dragged_entity_
std::vector< std::vector< uint8_t > > tile16_individual_data_
gfx::BitmapTable current_graphics_set_
void DrawOverworldItems()
Tile16Editor tile16_editor_
gfx::SnesPalette palette_
zelda3::Sprite current_sprite_
GfxGroupEditor gfx_group_editor_
gui::Canvas graphics_bin_canvas_
void DrawOverworldCanvas()
Allows the user to make changes to the overworld map.
void DrawCustomOverworldMapSettings()
void DrawOverworldEntrances(ImVec2 canvas_p, ImVec2 scrolling, bool holes=false)
void DrawFullscreenCanvas()
Draws the canvas, tile16 selector, and toolset in fullscreen.
absl::Status CheckForCurrentMap()
Check for changes to the overworld map. Calls RefreshOverworldMap and RefreshTile16Blockset on the cu...
gui::Canvas ow_map_canvas_
void CheckForSelectRectangle()
Draw and create the tile16 IDs that are currently selected.
absl::Status DrawAreaGraphics()
gui::Canvas current_gfx_canvas_
zelda3::overworld::Overworld overworld_
absl::Status UpdateUsageStats()
gfx::BitmapTable maps_bmp_
absl::Status Undo() override
absl::Status LoadSpriteGraphics()
void DrawOverworldEdits()
absl::Status RefreshTile16Blockset()
bool map_blockset_loaded_
bool middle_mouse_dragging_
void DrawOverworldSprites()
absl::Status RefreshMapPalette()
void RefreshChildMap(int i)
zelda3::overworld::OverworldExit current_exit_
gui::Canvas properties_canvas_
gui::zeml::Node layout_node_
gfx::Bitmap current_gfx_bmp_
zelda3::overworld::OverworldEntrance current_entrance_
gfx::BitmapTable sprite_previews_
void DrawOverworldProperties()
void DrawOverworldExits(ImVec2 zero, ImVec2 scrolling)
absl::Status DrawTile16Selector()
void RenderUpdatedMapBitmap(const ImVec2 &click_position, const std::vector< uint8_t > &tile_data)
void RefreshOverworldMap()
void CheckForOverworldEdits()
Check for changes to the overworld map.
absl::Status LoadGraphics()
Load the Bitmap objects for each OverworldMap.
void DrawToolset()
Toolset for entrances, exits, items, sprites, and transports.
bool overworld_canvas_fullscreen_
gfx::Bitmap tile16_blockset_bmp_
absl::Status DrawTileSelector()
void DrawOverworldMapSettings()
Draws the overworld map settings. Graphics, palettes, etc.
absl::Status SetCurrentTile(int id)
absl::Status InitBlockset(const gfx::Bitmap &tile16_blockset_bmp, const gfx::Bitmap ¤t_gfx_bmp, const std::vector< gfx::Bitmap > &tile16_individual, uint8_t all_tiles_types[0x200])
Represents a bitmap image.
absl::Status ApplyPalette(const SnesPalette &palette)
Copy color data from the SnesPalette into the SDL_Palette.
void WriteToPixel(int position, uchar value)
void set_modified(bool modified)
bool DrawTileSelector(int size)
void DrawOutline(int x, int y, int w, int h)
void DrawBackground(ImVec2 canvas_size=ImVec2(0, 0), bool drag=false)
void DrawRect(int x, int y, int w, int h, ImVec4 color)
void UpdateInfoGrid(ImVec2 bg_size, int tile_size, float scale=1.0f, float grid_size=64.0f, int label_id=0)
void DrawGrid(float grid_step=64.0f, int tile_id_offset=8)
void DrawBitmapGroup(std::vector< int > &group, std::vector< gfx::Bitmap > &tile16_individual_, int tile_size, float scale=1.0f)
void DrawText(std::string text, int x, int y)
auto hover_mouse_pos() const
void DrawBitmap(const Bitmap &bitmap, int border_offset=0, bool ready=true)
auto set_draggable(bool value)
auto selected_tile_pos() const
auto selected_points() const
auto mutable_labels(int i)
void DrawSelectRect(int current_map, int tile_size=0x10, float scale=1.0f)
auto drawn_tile_position() const
auto set_selected_tile_pos(ImVec2 pos)
auto global_scale() const
bool DrawTilePainter(const Bitmap &bitmap, int size, float scale=1.0f)
auto selected_tiles() const
bool select_rect_active() const
void DrawContextMenu(gfx::Bitmap *bitmap=nullptr)
auto set_highlight_tile_id(int i)
auto mutable_deleted_entrances()
auto mutable_sprites(int state)
absl::Status SaveMap32Tiles()
auto current_graphics() const
absl::Status CreateTile32Tilemap()
void set_current_map(int i)
OWBlockset & GetMapTiles(int world_type)
absl::Status SaveMap16Tiles()
absl::Status SaveOverworldMaps()
auto deleted_entrances() const
absl::Status SaveEntrances()
auto mutable_overworld_map(int i)
absl::Status Load(Rom &rom)
auto tile16_blockset_data() const
std::vector< gfx::Tile16 > tiles16() const
auto overworld_map(int i) const
int GetTileFromPosition(ImVec2 position) const
auto sprites(int state) const
auto mutable_all_tiles_types()
auto current_area_palette() const
auto current_map_bitmap_data() const
absl::Status SaveMapProperties()
#define PRINT_IF_ERROR(expression)
#define RETURN_IF_ERROR(expression)
#define HOVER_HINT(string)
#define ICON_MD_GRID_VIEW
#define ICON_MD_MORE_VERT
#define ICON_MD_OPEN_IN_FULL
#define ICON_MD_TABLE_CHART
#define ICON_MD_DOOR_BACK
#define ICON_MD_MUSIC_NOTE
#define ICON_MD_DOOR_FRONT
#define ICON_MD_ADD_LOCATION
#define ICON_MD_PEST_CONTROL_RODENT
#define ICON_MD_CONTENT_COPY
#define ICON_MD_PAN_TOOL_ALT
void CopyImageToClipboard(const std::vector< uint8_t > &data)
std::string UppercaseHexByte(uint8_t byte, bool leading)
constexpr uint kOverworldMapSize
constexpr absl::string_view kTileSelectorTab
void DrawSpriteInserterPopup()
constexpr absl::string_view kOWMapTable
bool IsMouseHoveringOverEntity(const zelda3::GameEntity &entity, ImVec2 canvas_p0, ImVec2 scrolling)
constexpr std::array< const char *, 8 > kMapSettingsColumnNames
bool DrawEntranceInserterPopup()
bool DrawExitEditorPopup(zelda3::overworld::OverworldExit &exit)
constexpr ImGuiTableFlags kOWMapFlags
constexpr absl::string_view kGamePartComboString
bool DrawOverworldEntrancePopup(zelda3::overworld::OverworldEntrance &entrance)
bool DrawSpriteEditorPopup(zelda3::Sprite &sprite)
constexpr int kTile16Size
void DrawItemInsertPopup()
void DrawExitInserterPopup()
constexpr ImGuiTableFlags kOWEditFlags
constexpr ImGuiTableFlags kToolsetTableFlags
constexpr absl::string_view kWorldList
void HandleEntityDragging(zelda3::GameEntity *entity, ImVec2 canvas_p0, ImVec2 scrolling, bool &is_dragging_entity, zelda3::GameEntity *&dragged_entity, zelda3::GameEntity *¤t_entity, bool free_movement)
bool DrawItemEditorPopup(zelda3::overworld::OverworldItem &item)
constexpr float kInputFieldSize
absl::Status DisplayPalette(gfx::SnesPalette &palette, bool loaded)
Node Parse(const std::string &yazon_input, const std::map< std::string, void * > &data_bindings)
Parse a zeml string.
void Bind(Node *node, std::function< void()> callback)
Bind a callback to a node.
void Render(Node &node)
Render a zeml tree.
std::string LoadFile(const std::string &filename)
bool InputHexByte(const char *label, uint8_t *data, float input_width, bool no_step)
void BeginChildWithScrollbar(const char *str_id)
void BeginWindowWithDisplaySettings(const char *id, bool *active, const ImVec2 &size, ImGuiWindowFlags flags)
void BeginChildBothScrollbars(int id)
bool InputHexWord(const char *label, uint16_t *data, float input_width, bool no_step)
void EndWindowWithDisplaySettings()
constexpr int kNumTile16Individual
constexpr int kNumOverworldMaps
const std::vector< std::string > kSecretItemNames
Node * GetNode(const std::string &searchId)