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]) {
62 ImVector<std::string> tile16_names;
63 for (
int i = 0; i < 0x200; ++i) {
65 tile16_names.push_back(str);
70 return absl::OkStatus();
75 return absl::InvalidArgumentError(
"Blockset not initialized, open a ROM.");
79 if (BeginTabBar(
"Tile16 Editor Tabs")) {
85 return absl::OkStatus();
90 if (BeginMenu(
"View")) {
91 Checkbox(
"Show Collision Types",
99 return absl::OkStatus();
103 if (BeginTabItem(
"Tile16 Editing")) {
106 TableSetupColumn(
"Blockset", ImGuiTableColumnFlags_WidthFixed,
107 GetContentRegionAvail().x);
108 TableSetupColumn(
"Properties", ImGuiTableColumnFlags_WidthStretch,
109 GetContentRegionAvail().x);
120 if (
status_ != absl::OkStatus()) {
151 auto ow_main_pal_group =
rom()->palette_group().overworld_main;
158 return absl::OkStatus();
162 constexpr int tile8_size = 8;
163 constexpr int tile16_size = 16;
167 int tile_index_x =
static_cast<int>(click_position.x) / tile8_size;
168 int tile_index_y =
static_cast<int>(click_position.y) / tile8_size;
169 std::cout <<
"Tile Index X: " << tile_index_x << std::endl;
170 std::cout <<
"Tile Index Y: " << tile_index_y << std::endl;
173 ImVec2 start_position;
174 start_position.x = tile_index_x * 0x40;
175 start_position.y = tile_index_y * 0x40;
176 std::cout <<
"Start Position X: " << start_position.x << std::endl;
177 std::cout <<
"Start Position Y: " << start_position.y << std::endl;
180 for (
int y = 0; y < tile8_size; ++y) {
181 for (
int x = 0; x < tile8_size; ++x) {
183 (start_position.y + y) * tile16_size + ((start_position.x) + x);
184 int gfx_pixel_index = y * tile8_size + x;
191 return absl::OkStatus();
195 auto ow_main_pal_group =
rom()->palette_group().overworld_main;
197 if (BeginChild(
"Tile8 Selector", ImVec2(GetContentRegionAvail().x, 0x175),
227 if (BeginChild(
"Tile16 Editor Options",
228 ImVec2(GetContentRegionAvail().x, 0x50),
true)) {
244 return absl::OkStatus();
276 Checkbox(
"X Flip", &
x_flip);
277 Checkbox(
"Y Flip", &
y_flip);
280 return absl::OkStatus();
284 auto ow_main_pal_group =
rom()->palette_group().overworld_main;
288 for (
int index = 0; index < 1024; index++) {
289 std::vector<uint8_t> tile_data(0x40, 0x00);
292 for (
int ty = 0; ty < 8; ty++) {
293 for (
int tx = 0; tx < 8; tx++) {
297 int position = tx + (ty * 0x08);
301 int x = (index % num_columns) * 8 + tx;
302 int y = (index / num_columns) * 8 + ty;
303 int gfx_position = x + (y * 0x100);
312 tile_data[position] = value;
325 return absl::OkStatus();
331 auto ow_main_pal_group =
rom()->palette_group().overworld_main;
335 return absl::OkStatus();
338#pragma mark - Tile16Transfer
341 if (BeginTabItem(
"Tile16 Transfer")) {
344 TableSetupColumn(
"Current ROM Tiles", ImGuiTableColumnFlags_WidthFixed,
345 GetContentRegionAvail().x / 2);
346 TableSetupColumn(
"Transfer ROM Tiles", ImGuiTableColumnFlags_WidthFixed,
347 GetContentRegionAvail().x / 2);
362 return absl::OkStatus();
367 if (Button(
"Load ROM")) {
368 ImGuiFileDialog::Instance()->OpenDialog(
369 "ChooseTransferFileDlgKey",
"Open Transfer ROM",
".sfc,.smc",
".");
372 "ChooseTransferFileDlgKey",
".sfc,.smc", std::nullopt, [&]() {
373 std::string filePathName =
374 ImGuiFileDialog::Instance()->GetFilePathName();
400 return absl::OkStatus();
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)
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.
core::NotifyValue< uint8_t > notify_palette
gui::Canvas tile8_source_canvas_
absl::Status UpdateBlockset()
gfx::Bitmap transfer_blockset_bmp_
absl::Status UpdateTile16Edit()
std::vector< uint8_t > tile8_gfx_data_
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()
static std::unordered_map< uint8_t, gfx::Paletteset > palettesets_
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)