yaze 0.2.0
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
overworld_editor.h
Go to the documentation of this file.
1#ifndef YAZE_APP_EDITOR_OVERWORLDEDITOR_H
2#define YAZE_APP_EDITOR_OVERWORLDEDITOR_H
3
4#include <cmath>
5#include <unordered_map>
6
7#include "absl/container/flat_hash_map.h"
8#include "absl/status/status.h"
9#include "absl/status/statusor.h"
10#include "absl/strings/str_format.h"
11#include "app/editor/editor.h"
16#include "app/gfx/bitmap.h"
18#include "app/gfx/snes_tile.h"
19#include "app/gui/canvas.h"
20#include "app/gui/icons.h"
21#include "app/gui/zeml.h"
22#include "app/rom.h"
24#include "imgui/imgui.h"
25
26namespace yaze {
27namespace app {
28namespace editor {
29
30constexpr uint k4BPP = 4;
31constexpr uint kByteSize = 3;
32constexpr uint kMessageIdSize = 5;
33constexpr uint kNumSheetsToLoad = 223;
35constexpr uint kOverworldMapSize = 0x200;
36constexpr float kInputFieldSize = 30.f;
39constexpr ImVec2 kCurrentGfxCanvasSize(0x100 + 1, 0x10 * 0x40 + 1);
40constexpr ImVec2 kBlocksetCanvasSize(0x100 + 1, 0x4000 + 1);
41constexpr ImVec2 kGraphicsBinCanvasSize(0x100 + 1, kNumSheetsToLoad * 0x40 + 1);
42
43constexpr ImGuiTableFlags kOWMapFlags =
44 ImGuiTableFlags_Borders | ImGuiTableFlags_Resizable;
45constexpr ImGuiTableFlags kToolsetTableFlags = ImGuiTableFlags_SizingFixedFit;
46constexpr ImGuiTableFlags kOWEditFlags =
47 ImGuiTableFlags_Resizable | ImGuiTableFlags_Reorderable |
48 ImGuiTableFlags_Hideable | ImGuiTableFlags_BordersOuter |
49 ImGuiTableFlags_BordersV;
50
51static constexpr absl::string_view kToolsetColumnNames[] = {
52 "#undoTool", "#redoTool", "#separator2", "#zoomOutTool",
53 "#zoomInTool", "#separator", "#drawTool", "#history",
54 "#entranceTool", "#exitTool", "#itemTool", "#spriteTool",
55 "#transportTool", "#musicTool", "#separator3", "#tilemapTool",
56 "propertiesTool", "#separator4", "#experimentalTool", "#properties",
57 "#separator5"};
58
59constexpr absl::string_view kWorldList =
60 "Light World\0Dark World\0Extra World\0";
61
62constexpr absl::string_view kGamePartComboString = "Part 0\0Part 1\0Part 2\0";
63
64constexpr absl::string_view kTileSelectorTab = "##TileSelectorTabBar";
65constexpr absl::string_view kOWEditTable = "##OWEditTable";
66constexpr absl::string_view kOWMapTable = "#MapSettingsTable";
67
68constexpr int kEntranceTileTypePtrLow = 0xDB8BF;
69constexpr int kEntranceTileTypePtrHigh = 0xDB917;
70constexpr int kNumEntranceTileTypes = 0x2C;
71
73 public:
74 absl::Status LoadEntranceTileTypes(Rom& rom) {
75 int offset_low = kEntranceTileTypePtrLow;
76 int offset_high = kEntranceTileTypePtrHigh;
77
78 for (int i = 0; i < kNumEntranceTileTypes; i++) {
79 // Load entrance tile types
80 ASSIGN_OR_RETURN(auto value_low, rom.ReadWord(offset_low + i));
81 entrance_tile_types_low_.push_back(value_low);
82 ASSIGN_OR_RETURN(auto value_high, rom.ReadWord(offset_high + i));
83 entrance_tile_types_low_.push_back(value_high);
84 }
85
86 return absl::OkStatus();
87 }
88
89 private:
90 std::vector<uint16_t> entrance_tile_types_low_;
91 std::vector<uint16_t> entrance_tile_types_high_;
92};
93
110class OverworldEditor : public Editor,
111 public SharedRom,
112 public EntranceContext,
113 public GfxContext,
114 public core::ExperimentFlags {
115 public:
117
118 void InitializeZeml();
119
120 absl::Status Update() final;
121 absl::Status Undo() override { return absl::UnimplementedError("Undo"); }
122 absl::Status Redo() override { return absl::UnimplementedError("Redo"); }
123 absl::Status Cut() override { return absl::UnimplementedError("Cut"); }
124 absl::Status Copy() override { return absl::UnimplementedError("Copy"); }
125 absl::Status Paste() override { return absl::UnimplementedError("Paste"); }
126 absl::Status Find() override {
127 return absl::UnimplementedError("Find Unused Tiles");
128 }
129 absl::Status Save();
130
131 auto overworld() { return &overworld_; }
132
136 int jump_to_tab() { return jump_to_tab_; }
137 int jump_to_tab_ = -1;
138
146 absl::Status LoadGraphics();
147
148 private:
153
157 void DrawToolset();
158
163
168
169 void RefreshChildMap(int i);
170 void RefreshOverworldMap();
171 absl::Status RefreshMapPalette();
173 absl::Status RefreshTile16Blockset();
174
175 void DrawOverworldEntrances(ImVec2 canvas_p, ImVec2 scrolling,
176 bool holes = false);
177 void DrawOverworldExits(ImVec2 zero, ImVec2 scrolling);
178 void DrawOverworldItems();
180
181 void DrawOverworldMaps();
182 void DrawOverworldEdits();
183 void RenderUpdatedMapBitmap(const ImVec2& click_position,
184 const std::vector<uint8_t>& tile_data);
185
195
200
206 absl::Status CheckForCurrentMap();
207 void CheckForMousePan();
208
212 void DrawOverworldCanvas();
213
214 absl::Status DrawTile16Selector();
215 void DrawTile8Selector();
216 absl::Status DrawAreaGraphics();
217 absl::Status DrawTileSelector();
218
219 absl::Status LoadSpriteGraphics();
220
222
223 absl::Status UpdateUsageStats();
224 void DrawUsageGrid();
225 void DrawDebugWindow();
226
227 enum class EditingMode {
228 DRAW_TILE,
229 ENTRANCES,
230 EXITS,
231 ITEMS,
232 SPRITES,
234 MUSIC,
235 PAN
236 };
237
240
255
264 int game_state_ = 1;
268
269 bool all_gfx_loaded_ = false;
276
277 std::vector<uint8_t> selected_tile_data_;
278 std::vector<std::vector<uint8_t>> tile16_individual_data_;
279 std::vector<gfx::Bitmap> tile16_individual_;
280
281 std::vector<std::vector<uint8_t>> tile8_individual_data_;
282 std::vector<gfx::Bitmap> tile8_individual_;
283
287
289
294
298
301
303
307
310
321 absl::Status status_;
322};
323} // namespace editor
324} // namespace app
325} // namespace yaze
326
327#endif
Shared graphical context across editors.
The Rom class is used to load, save, and modify Rom data.
Definition rom.h:136
absl::StatusOr< uint16_t > ReadWord(int offset)
Definition rom.h:257
A class to hold a shared pointer to a Rom object.
Definition rom.h:576
A class to manage experimental feature flags.
Definition common.h:36
Interface for editor classes.
Definition editor.h:54
std::vector< uint16_t > entrance_tile_types_low_
absl::Status LoadEntranceTileTypes(Rom &rom)
std::vector< uint16_t > entrance_tile_types_high_
Manage graphics group configurations in a Rom.
Manipulates the Overworld and OverworldMap data in a Rom.
zelda3::overworld::OverworldItem current_item_
std::vector< gfx::Bitmap > tile16_individual_
std::vector< std::vector< uint8_t > > tile16_individual_data_
void DrawOverworldCanvas()
Allows the user to make changes to the overworld map.
void DrawCustomOverworldMapSettings()
Draw the overworld settings for ZSCustomOverworld.
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...
void CheckForSelectRectangle()
Draw and create the tile16 IDs that are currently selected.
zelda3::overworld::Overworld overworld_
std::vector< gfx::Bitmap > tile8_individual_
std::vector< std::vector< uint8_t > > tile8_individual_data_
std::vector< uint8_t > selected_tile_data_
zelda3::overworld::OverworldExit current_exit_
zelda3::overworld::OverworldEntrance current_entrance_
void DrawOverworldExits(ImVec2 zero, ImVec2 scrolling)
void RenderUpdatedMapBitmap(const ImVec2 &click_position, const std::vector< uint8_t > &tile_data)
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.
void DrawOverworldMapSettings()
Draws the overworld map settings. Graphics, palettes, etc.
Allows the user to view and edit in game palettes.
Popup window to edit Tile16 data.
Represents a bitmap image.
Definition bitmap.h:67
Represents a palette of colors for the Super Nintendo Entertainment System (SNES).
Represents a canvas for drawing and manipulating graphics.
Definition canvas.h:34
Base class for all overworld and dungeon entities.
Definition common.h:35
A class for managing sprites in the overworld and underworld.
Definition sprite.h:280
Represents the full Overworld data, light and dark world.
Definition overworld.h:461
unsigned int uint
Definition constants.h:113
#define ASSIGN_OR_RETURN(type_variable_name, expression)
Definition constants.h:70
constexpr int kEntranceTileTypePtrHigh
constexpr uint kOverworldMapSize
constexpr absl::string_view kTileSelectorTab
constexpr ImVec2 kOverworldCanvasSize(kOverworldMapSize *8, kOverworldMapSize *8)
constexpr uint k4BPP
constexpr absl::string_view kOWMapTable
constexpr ImGuiTableFlags kOWMapFlags
constexpr int kEntranceTileTypePtrLow
constexpr uint kByteSize
constexpr absl::string_view kGamePartComboString
constexpr uint kTile8DisplayHeight
constexpr uint kNumSheetsToLoad
constexpr ImVec2 kGraphicsBinCanvasSize(0x100+1, kNumSheetsToLoad *0x40+1)
constexpr ImVec2 kBlocksetCanvasSize(0x100+1, 0x4000+1)
constexpr uint kMessageIdSize
constexpr ImGuiTableFlags kOWEditFlags
constexpr ImGuiTableFlags kToolsetTableFlags
constexpr absl::string_view kWorldList
constexpr ImVec2 kCurrentGfxCanvasSize(0x100+1, 0x10 *0x40+1)
constexpr int kNumEntranceTileTypes
constexpr float kInputFieldSize
Definition entity.cc:19
constexpr absl::string_view kOWEditTable
std::unordered_map< int, gfx::Bitmap > BitmapTable
Definition bitmap.h:214
std::vector< std::vector< uint16_t > > OWBlockset
Represents tile32 data for the overworld.
Definition common.h:19
Definition common.cc:22
Node for a zeml tree.
Definition zeml.h:125