Make LoadGraphics public, add mutable ow map props

This commit is contained in:
scawful
2023-11-26 16:47:43 -05:00
parent 7fedea14ac
commit 6e6576b364
2 changed files with 114 additions and 36 deletions

View File

@@ -36,8 +36,6 @@ using ImGui::Text;
absl::Status OverworldEditor::Update() { absl::Status OverworldEditor::Update() {
if (rom()->isLoaded() && !all_gfx_loaded_) { if (rom()->isLoaded() && !all_gfx_loaded_) {
// Initialize overworld graphics, maps, and palettes
RETURN_IF_ERROR(LoadGraphics())
RETURN_IF_ERROR(tile16_editor_.InitBlockset( RETURN_IF_ERROR(tile16_editor_.InitBlockset(
tile16_blockset_bmp_, current_gfx_bmp_, tile16_individual_)); tile16_blockset_bmp_, current_gfx_bmp_, tile16_individual_));
gfx_group_editor_.InitBlockset(tile16_blockset_bmp_); gfx_group_editor_.InitBlockset(tile16_blockset_bmp_);
@@ -65,6 +63,12 @@ absl::Status OverworldEditor::Update() {
ImGui::EndTable(); ImGui::EndTable();
} }
if (!status_.ok()) {
auto temp = status_;
status_ = absl::OkStatus();
return temp;
}
return absl::OkStatus(); return absl::OkStatus();
} }
@@ -80,12 +84,12 @@ absl::Status OverworldEditor::DrawToolset() {
NEXT_COLUMN() NEXT_COLUMN()
if (ImGui::Button(ICON_MD_UNDO)) { if (ImGui::Button(ICON_MD_UNDO)) {
RETURN_IF_ERROR(Undo()) status_ = Undo();
} }
NEXT_COLUMN() NEXT_COLUMN()
if (ImGui::Button(ICON_MD_REDO)) { if (ImGui::Button(ICON_MD_REDO)) {
RETURN_IF_ERROR(Redo()) status_ = Redo();
} }
TEXT_COLUMN(ICON_MD_MORE_VERT) // Separator TEXT_COLUMN(ICON_MD_MORE_VERT) // Separator
@@ -97,21 +101,43 @@ absl::Status OverworldEditor::DrawToolset() {
if (ImGui::Button(ICON_MD_DRAW)) { if (ImGui::Button(ICON_MD_DRAW)) {
current_mode = EditingMode::DRAW_TILE; current_mode = EditingMode::DRAW_TILE;
} }
HOVER_HINT("Draw Tile")
NEXT_COLUMN() NEXT_COLUMN()
if (ImGui::Button(ICON_MD_DOOR_FRONT)) { if (ImGui::Button(ICON_MD_DOOR_FRONT)) {
current_mode = EditingMode::ENTRANCES; current_mode = EditingMode::ENTRANCES;
} }
HOVER_HINT("Entrances")
NEXT_COLUMN() NEXT_COLUMN()
if (ImGui::Button(ICON_MD_DOOR_BACK)) { if (ImGui::Button(ICON_MD_DOOR_BACK)) {
current_mode = EditingMode::EXITS; current_mode = EditingMode::EXITS;
} }
HOVER_HINT("Exits")
BUTTON_COLUMN(ICON_MD_GRASS) // Items NEXT_COLUMN()
BUTTON_COLUMN(ICON_MD_PEST_CONTROL_RODENT) // Sprites if (ImGui::Button(ICON_MD_GRASS)) {
BUTTON_COLUMN(ICON_MD_ADD_LOCATION) // Transports current_mode = EditingMode::ITEMS;
BUTTON_COLUMN(ICON_MD_MUSIC_NOTE) // Music }
HOVER_HINT("Items")
NEXT_COLUMN()
if (ImGui::Button(ICON_MD_PEST_CONTROL_RODENT)) {
current_mode = EditingMode::SPRITES;
}
HOVER_HINT("Sprites")
NEXT_COLUMN()
if (ImGui::Button(ICON_MD_ADD_LOCATION)) {
current_mode = EditingMode::TRANSPORTS;
}
HOVER_HINT("Transports")
NEXT_COLUMN()
if (ImGui::Button(ICON_MD_MUSIC_NOTE)) {
current_mode = EditingMode::MUSIC;
}
HOVER_HINT("Music")
TableNextColumn(); TableNextColumn();
if (ImGui::Button(ICON_MD_GRID_VIEW)) { if (ImGui::Button(ICON_MD_GRID_VIEW)) {
@@ -163,42 +189,41 @@ void OverworldEditor::DrawOverworldMapSettings() {
ImGui::TableSetupColumn(name.data()); ImGui::TableSetupColumn(name.data());
TableNextColumn(); TableNextColumn();
ImGui::SetNextItemWidth(100.f); ImGui::SetNextItemWidth(120.f);
ImGui::Combo("##world", &current_world_, kWorldList.data(), 3); ImGui::Combo("##world", &current_world_, kWorldList.data(), 3);
TableNextColumn(); TableNextColumn();
Text("GFX"); gui::InputHexByte(
ImGui::SameLine(); "Gfx",
ImGui::SetNextItemWidth(kInputFieldSize); overworld_.mutable_overworld_map(current_map_)->mutable_area_graphics(),
ImGui::InputText("##mapGFX", map_gfx_, kByteSize); kInputFieldSize);
TableNextColumn(); TableNextColumn();
Text("Palette"); gui::InputHexByte(
ImGui::SameLine(); "Palette",
ImGui::SetNextItemWidth(kInputFieldSize); overworld_.mutable_overworld_map(current_map_)->mutable_area_palette(),
ImGui::InputText("##mapPal", map_palette_, kByteSize); kInputFieldSize);
TableNextColumn(); TableNextColumn();
Text("Spr GFX"); gui::InputHexByte("Spr Gfx",
ImGui::SameLine(); overworld_.mutable_overworld_map(current_map_)
ImGui::SetNextItemWidth(kInputFieldSize); ->mutable_sprite_graphics(game_state_),
ImGui::InputText("##sprGFX", spr_gfx_, kByteSize); kInputFieldSize);
TableNextColumn(); TableNextColumn();
Text("Spr Palette"); gui::InputHexByte("Spr Palette",
ImGui::SameLine(); overworld_.mutable_overworld_map(current_map_)
ImGui::SetNextItemWidth(kInputFieldSize); ->mutable_sprite_palette(game_state_),
ImGui::InputText("##sprPal", spr_palette_, kByteSize); kInputFieldSize);
TableNextColumn(); TableNextColumn();
Text("Msg ID"); gui::InputHexByte(
ImGui::SameLine(); "Msg Id",
ImGui::SetNextItemWidth(50.f); overworld_.mutable_overworld_map(current_map_)->mutable_message_id(),
ImGui::InputText("##msgid", spr_palette_, kMessageIdSize); kInputFieldSize);
TableNextColumn(); TableNextColumn();
ImGui::SetNextItemWidth(100.f); ImGui::SetNextItemWidth(100.f);
// ImGui::Combo("##world", &game_state_, "Part 0\0Part 1\0Part 2\0", 3);
ImGui::Combo("##World", &game_state_, kGamePartComboString, 3); ImGui::Combo("##World", &game_state_, kGamePartComboString, 3);
TableNextColumn(); TableNextColumn();
@@ -357,7 +382,7 @@ void OverworldEditor::RenderUpdatedMapBitmap(const ImVec2 &click_position,
} }
// Render the updated bitmap to the canvas // Render the updated bitmap to the canvas
rom()->RenderBitmap(&current_bitmap); rom()->UpdateBitmap(&current_bitmap);
} }
void OverworldEditor::QueueROMChanges(int index, ushort new_tile16) { void OverworldEditor::QueueROMChanges(int index, ushort new_tile16) {
@@ -389,11 +414,56 @@ void OverworldEditor::CheckForOverworldEdits() {
} }
} }
void OverworldEditor::CheckForCurrentMap() {
// DetermineActiveMap(ImGui::GetIO().MousePos);
// 4096x4096, 512x512 maps and some are larges maps 1024x1024
auto current_map_x = current_map_ % 8;
auto current_map_y = current_map_ / 8;
auto large_map_size = 1024;
auto map_size = 512;
auto mouse_position = ImGui::GetIO().MousePos;
// Assuming each small map is 256x256 pixels (adjust as needed)
constexpr int small_map_size = 512;
// Calculate which small map the mouse is currently over
int map_x = mouse_position.x / small_map_size;
int map_y = mouse_position.y / small_map_size;
// Calculate the index of the map in the `maps_bmp_` vector
current_map_ = map_x + map_y * 8;
if (overworld_.overworld_map(current_map_).IsLargeMap()) {
// Draw an outline around the current map
ow_map_canvas_.DrawOutline(current_map_x * large_map_size,
current_map_y * large_map_size, large_map_size,
large_map_size);
} else {
// Draw an outline around the current map
ow_map_canvas_.DrawOutline(current_map_x * map_size,
current_map_y * map_size, map_size, map_size);
}
static int prev_map_;
if (current_map_ != prev_map_) {
// Update the current map's tile16 blockset
// core::BuildAndRenderBitmapPipeline(
// 0x80, 0x2000, 0x80, maps_bmp_[current_map_].mutable_data(), *rom(),
// maps_bmp_[current_map_], palette_);
prev_map_ = current_map_;
}
}
// Overworld Editor canvas // Overworld Editor canvas
// Allows the user to make changes to the overworld map. // Allows the user to make changes to the overworld map.
void OverworldEditor::DrawOverworldCanvas() { void OverworldEditor::DrawOverworldCanvas() {
DrawOverworldMapSettings(); if (all_gfx_loaded_) {
Separator(); DrawOverworldMapSettings();
Separator();
}
if (ImGuiID child_id = ImGui::GetID((void *)(intptr_t)7); if (ImGuiID child_id = ImGui::GetID((void *)(intptr_t)7);
ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true, ImGui::BeginChild(child_id, ImGui::GetContentRegionAvail(), true,
ImGuiWindowFlags_AlwaysVerticalScrollbar | ImGuiWindowFlags_AlwaysVerticalScrollbar |
@@ -407,6 +477,7 @@ void OverworldEditor::DrawOverworldCanvas() {
if (flags()->kDrawOverworldSprites) { if (flags()->kDrawOverworldSprites) {
DrawOverworldSprites(); DrawOverworldSprites();
} }
CheckForCurrentMap();
CheckForOverworldEdits(); CheckForOverworldEdits();
} }
ow_map_canvas_.DrawGrid(64.0f); ow_map_canvas_.DrawGrid(64.0f);

View File

@@ -14,8 +14,8 @@
#include "app/core/editor.h" #include "app/core/editor.h"
#include "app/core/pipeline.h" #include "app/core/pipeline.h"
#include "app/editor/modules/gfx_group_editor.h" #include "app/editor/modules/gfx_group_editor.h"
#include "app/editor/modules/tile16_editor.h"
#include "app/editor/modules/palette_editor.h" #include "app/editor/modules/palette_editor.h"
#include "app/editor/modules/tile16_editor.h"
#include "app/gfx/bitmap.h" #include "app/gfx/bitmap.h"
#include "app/gfx/snes_palette.h" #include "app/gfx/snes_palette.h"
#include "app/gfx/snes_tile.h" #include "app/gfx/snes_tile.h"
@@ -72,6 +72,8 @@ class OverworldEditor : public Editor,
absl::Status Copy() { return absl::UnimplementedError("Copy"); } absl::Status Copy() { return absl::UnimplementedError("Copy"); }
absl::Status Paste() { return absl::UnimplementedError("Paste"); } absl::Status Paste() { return absl::UnimplementedError("Paste"); }
auto overworld() { return &overworld_; }
void Shutdown() { void Shutdown() {
for (auto &bmp : tile16_individual_) { for (auto &bmp : tile16_individual_) {
bmp.Cleanup(); bmp.Cleanup();
@@ -87,6 +89,8 @@ class OverworldEditor : public Editor,
} }
} }
absl::Status LoadGraphics();
private: private:
absl::Status DrawToolset(); absl::Status DrawToolset();
void DrawOverworldMapSettings(); void DrawOverworldMapSettings();
@@ -101,12 +105,13 @@ class OverworldEditor : public Editor,
void QueueROMChanges(int index, ushort new_tile16); void QueueROMChanges(int index, ushort new_tile16);
void DetermineActiveMap(const ImVec2 &mouse_position); void DetermineActiveMap(const ImVec2 &mouse_position);
void CheckForOverworldEdits(); void CheckForOverworldEdits();
void CheckForCurrentMap();
void DrawOverworldCanvas(); void DrawOverworldCanvas();
void DrawTile8Selector(); void DrawTile8Selector();
void DrawTileSelector(); void DrawTileSelector();
absl::Status LoadGraphics();
absl::Status LoadSpriteGraphics(); absl::Status LoadSpriteGraphics();
absl::Status DrawExperimentalModal(); absl::Status DrawExperimentalModal();
@@ -185,6 +190,8 @@ class OverworldEditor : public Editor,
gfx::BitmapTable graphics_bin_; gfx::BitmapTable graphics_bin_;
gfx::BitmapTable current_graphics_set_; gfx::BitmapTable current_graphics_set_;
gfx::BitmapTable sprite_previews_; gfx::BitmapTable sprite_previews_;
absl::Status status_;
}; };
} // namespace editor } // namespace editor
} // namespace app } // namespace app