5#include "ImGuiFileDialog/ImGuiFileDialog.h"
6#include "absl/status/status.h"
7#include "absl/status/statusor.h"
21#include "imgui/imgui.h"
29using ImGui::BeginChild;
30using ImGui::BeginMenu;
31using ImGui::BeginMenuBar;
32using ImGui::BeginTabBar;
33using ImGui::BeginTabItem;
34using ImGui::BeginTable;
40using ImGui::EndMenuBar;
41using ImGui::EndTabBar;
42using ImGui::EndTabItem;
44using ImGui::GetContentRegionAvail;
45using ImGui::Separator;
46using ImGui::TableHeadersRow;
47using ImGui::TableNextColumn;
48using ImGui::TableNextRow;
49using ImGui::TableSetupColumn;
54 const std::vector<gfx::Bitmap>& tile16_individual,
55 uint8_t all_tiles_types[0x200]) {
61 ImVector<std::string> tile16_names;
62 for (
int i = 0; i < 0x200; ++i) {
64 tile16_names.push_back(str);
69 return absl::OkStatus();
74 return absl::InvalidArgumentError(
"Blockset not initialized, open a ROM.");
78 if (BeginTabBar(
"Tile16 Editor Tabs")) {
84 return absl::OkStatus();
89 if (BeginMenu(
"View")) {
90 Checkbox(
"Show Collision Types",
98 return absl::OkStatus();
102 if (BeginTabItem(
"Tile16 Editing")) {
105 TableSetupColumn(
"Blockset", ImGuiTableColumnFlags_WidthFixed,
106 GetContentRegionAvail().x);
107 TableSetupColumn(
"Properties", ImGuiTableColumnFlags_WidthStretch,
108 GetContentRegionAvail().x);
119 if (
status_ != absl::OkStatus()) {
150 auto ow_main_pal_group =
rom()->palette_group().overworld_main;
157 return absl::OkStatus();
161 constexpr int tile8_size = 8;
162 constexpr int tile16_size = 16;
166 int tile_index_x =
static_cast<int>(click_position.x) / tile8_size;
167 int tile_index_y =
static_cast<int>(click_position.y) / tile8_size;
168 std::cout <<
"Tile Index X: " << tile_index_x << std::endl;
169 std::cout <<
"Tile Index Y: " << tile_index_y << std::endl;
172 ImVec2 start_position;
173 start_position.x = tile_index_x * 0x40;
174 start_position.y = tile_index_y * 0x40;
175 std::cout <<
"Start Position X: " << start_position.x << std::endl;
176 std::cout <<
"Start Position Y: " << start_position.y << std::endl;
179 for (
int y = 0; y < tile8_size; ++y) {
180 for (
int x = 0; x < tile8_size; ++x) {
182 (start_position.y + y) * tile16_size + ((start_position.x) + x);
183 int gfx_pixel_index = y * tile8_size + x;
190 return absl::OkStatus();
194 auto ow_main_pal_group =
rom()->palette_group().overworld_main;
196 if (BeginChild(
"Tile8 Selector", ImVec2(GetContentRegionAvail().x, 0x175),
226 if (BeginChild(
"Tile16 Editor Options",
227 ImVec2(GetContentRegionAvail().x, 0x50),
true)) {
243 return absl::OkStatus();
275 Checkbox(
"X Flip", &
x_flip);
276 Checkbox(
"Y Flip", &
y_flip);
279 return absl::OkStatus();
283 auto ow_main_pal_group =
rom()->palette_group().overworld_main;
287 for (
int index = 0; index < 1024; index++) {
288 std::vector<uint8_t> tile_data(0x40, 0x00);
291 for (
int ty = 0; ty < 8; ty++) {
292 for (
int tx = 0; tx < 8; tx++) {
296 int position = tx + (ty * 0x08);
300 int x = (index % num_columns) * 8 + tx;
301 int y = (index / num_columns) * 8 + ty;
302 int gfx_position = x + (y * 0x100);
311 tile_data[position] = value;
324 return absl::OkStatus();
330 auto ow_main_pal_group =
rom()->palette_group().overworld_main;
334 return absl::OkStatus();
337#pragma mark - Tile16Transfer
340 if (BeginTabItem(
"Tile16 Transfer")) {
343 TableSetupColumn(
"Current ROM Tiles", ImGuiTableColumnFlags_WidthFixed,
344 GetContentRegionAvail().x / 2);
345 TableSetupColumn(
"Transfer ROM Tiles", ImGuiTableColumnFlags_WidthFixed,
346 GetContentRegionAvail().x / 2);
361 return absl::OkStatus();
366 if (Button(
"Load ROM")) {
367 ImGuiFileDialog::Instance()->OpenDialog(
368 "ChooseTransferFileDlgKey",
"Open Transfer ROM",
".sfc,.smc",
".");
371 "ChooseTransferFileDlgKey",
".sfc,.smc", std::nullopt, [&]() {
372 std::string filePathName =
373 ImGuiFileDialog::Instance()->GetFilePathName();
399 return absl::OkStatus();
static std::unordered_map< uint8_t, gfx::Paletteset > palettesets_
absl::Status LoadAllGraphicsData(bool defer_render=false)
This function iterates over all graphics sheets in the Rom and loads them into memory....
absl::Status LoadFromFile(const std::string &filename, bool z3_load=true)
void UpdateBitmap(gfx::Bitmap *bitmap)
Used to update a bitmap on the screen.
static Renderer & GetInstance()
void RenderBitmap(gfx::Bitmap *bitmap)
Used to render a bitmap to the screen.
core::NotifyValue< uint8_t > notify_palette
gui::Canvas tile8_source_canvas_
absl::Status UpdateBlockset()
gfx::Bitmap transfer_blockset_bmp_
absl::Status UpdateTile16Edit()
bool map_blockset_loaded_
gui::Canvas tile16_edit_canvas_
std::vector< gfx::Bitmap > current_gfx_individual_
absl::Status UpdateTransferTileCanvas()
gfx::Bitmap current_gfx_bmp_
absl::Status DrawToCurrentTile16(ImVec2 pos)
absl::Status transfer_status_
gfx::Bitmap current_tile16_bmp_
absl::Status UpdateTile16Transfer()
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])
gui::Canvas transfer_canvas_
std::vector< gfx::Bitmap > tile16_individual_
zelda3::overworld::Overworld transfer_overworld_
bool transfer_blockset_loaded_
core::NotifyValue< uint32_t > notify_tile16
uint8_t * all_tiles_types_
gfx::Bitmap tile16_blockset_bmp_
gui::Canvas blockset_canvas_
gfx::SnesPalette palette_
absl::Status DrawTileEditControls()
Represents a bitmap image.
absl::Status ApplyPaletteWithTransparent(const SnesPalette &palette, size_t index, int length=7)
absl::Status ApplyPalette(const SnesPalette &palette)
Copy color data from the SnesPalette into the SDL_Palette.
void WriteToPixel(int position, uchar value)
bool DrawTileSelector(int size)
void DrawBackground(ImVec2 canvas_size=ImVec2(0, 0), bool drag=false)
int GetTileIdFromMousePos()
void DrawGrid(float grid_step=64.0f, int tile_id_offset=8)
void DrawBitmap(const Bitmap &bitmap, int border_offset=0, bool ready=true)
auto mutable_labels(int i)
auto drawn_tile_position() const
bool DrawTilePainter(const Bitmap &bitmap, int size, float scale=1.0f)
void DrawContextMenu(gfx::Bitmap *bitmap=nullptr)
auto custom_labels_enabled()
void set_current_map(int i)
absl::Status Load(Rom &rom)
auto tile16_blockset_data() const
auto current_area_palette() const
#define TABLE_BORDERS_RESIZABLE
#define PRINT_IF_ERROR(expression)
#define RETURN_IF_ERROR(expression)
std::string UppercaseHexByte(uint8_t byte, bool leading)
bool InputHexByte(const char *label, uint8_t *data, float input_width, bool no_step)
void FileDialogPipeline(absl::string_view display_key, absl::string_view file_extensions, std::optional< absl::string_view > button_text, std::function< void()> callback)
void BeginChildWithScrollbar(const char *str_id)
void BitmapCanvasPipeline(gui::Canvas &canvas, const gfx::Bitmap &bitmap, int width, int height, int tile_size, bool is_loaded, bool scrollbar, int canvas_id)