Implement LoadBinaryGfx functionality: Refactor GFX loading from BIN file into a separate method, improve error handling, and update UI button for better user experience
This commit is contained in:
@@ -41,8 +41,7 @@ absl::Status ScreenEditor::Update() {
|
|||||||
DrawTitleScreenEditor();
|
DrawTitleScreenEditor();
|
||||||
DrawNamingScreenEditor();
|
DrawNamingScreenEditor();
|
||||||
END_TAB_BAR()
|
END_TAB_BAR()
|
||||||
|
return status_;
|
||||||
return absl::OkStatus();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScreenEditor::DrawInventoryMenuEditor() {
|
void ScreenEditor::DrawInventoryMenuEditor() {
|
||||||
@@ -319,7 +318,7 @@ void ScreenEditor::DrawDungeonMapsTabs() {
|
|||||||
|
|
||||||
gui::InputHexWord("Boss Room", ¤t_dungeon.boss_room);
|
gui::InputHexWord("Boss Room", ¤t_dungeon.boss_room);
|
||||||
|
|
||||||
const ImVec2 button_size = ImVec2(120, 0);
|
const ImVec2 button_size = ImVec2(130, 0);
|
||||||
|
|
||||||
// Add Floor Button
|
// Add Floor Button
|
||||||
if (ImGui::Button("Add Floor", button_size) &&
|
if (ImGui::Button("Add Floor", button_size) &&
|
||||||
@@ -421,6 +420,7 @@ void ScreenEditor::DrawDungeonMapsEditor() {
|
|||||||
if (!screen_canvas_.points().empty()) {
|
if (!screen_canvas_.points().empty()) {
|
||||||
dungeon_maps_[selected_dungeon]
|
dungeon_maps_[selected_dungeon]
|
||||||
.floor_gfx[floor_number][selected_room] = selected_tile16_;
|
.floor_gfx[floor_number][selected_room] = selected_tile16_;
|
||||||
|
tilesheet_canvas_.mutable_points()->clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -432,38 +432,42 @@ void ScreenEditor::DrawDungeonMapsEditor() {
|
|||||||
tilemap_canvas_.DrawBitmapTable(sheets_);
|
tilemap_canvas_.DrawBitmapTable(sheets_);
|
||||||
tilemap_canvas_.DrawGrid();
|
tilemap_canvas_.DrawGrid();
|
||||||
tilemap_canvas_.DrawOverlay();
|
tilemap_canvas_.DrawOverlay();
|
||||||
|
ImGui::Separator();
|
||||||
if (ImGui::Button("Load GFX from BIN file")) {
|
if (ImGui::Button("Load GFX from BIN file")) LoadBinaryGfx();
|
||||||
std::string bin_file = core::FileDialogWrapper::ShowOpenFileDialog();
|
|
||||||
if (!bin_file.empty()) {
|
|
||||||
std::ifstream file(bin_file, std::ios::binary);
|
|
||||||
if (file.is_open()) {
|
|
||||||
// Read the gfx data into a buffer
|
|
||||||
std::vector<uint8_t> bin_data((std::istreambuf_iterator<char>(file)),
|
|
||||||
std::istreambuf_iterator<char>());
|
|
||||||
auto converted_bin = gfx::SnesTo8bppSheet(bin_data, 4, 4);
|
|
||||||
tile16_sheet_.clear();
|
|
||||||
LoadDungeonMapTile16(converted_bin, true);
|
|
||||||
sheets_.clear();
|
|
||||||
std::vector<std::vector<uint8_t>> gfx_sheets;
|
|
||||||
|
|
||||||
// Divide the bin into 4 sheets
|
|
||||||
for (int i = 0; i < 4; i++) {
|
|
||||||
gfx_sheets.emplace_back(converted_bin.begin() + (i * 0x1000),
|
|
||||||
converted_bin.begin() + ((i + 1) * 0x1000));
|
|
||||||
sheets_.emplace(i, gfx::Bitmap(128, 32, 8, gfx_sheets[i]));
|
|
||||||
sheets_[i].ApplyPalette(*rom()->mutable_dungeon_palette(3));
|
|
||||||
Renderer::GetInstance().RenderBitmap(&sheets_[i]);
|
|
||||||
}
|
|
||||||
file.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::EndTable();
|
ImGui::EndTable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScreenEditor::LoadBinaryGfx() {
|
||||||
|
std::string bin_file = core::FileDialogWrapper::ShowOpenFileDialog();
|
||||||
|
if (!bin_file.empty()) {
|
||||||
|
std::ifstream file(bin_file, std::ios::binary);
|
||||||
|
if (file.is_open()) {
|
||||||
|
// Read the gfx data into a buffer
|
||||||
|
std::vector<uint8_t> bin_data((std::istreambuf_iterator<char>(file)),
|
||||||
|
std::istreambuf_iterator<char>());
|
||||||
|
auto converted_bin = gfx::SnesTo8bppSheet(bin_data, 4, 4);
|
||||||
|
tile16_sheet_.clear();
|
||||||
|
if (LoadDungeonMapTile16(converted_bin, true).ok()) {
|
||||||
|
sheets_.clear();
|
||||||
|
std::vector<std::vector<uint8_t>> gfx_sheets;
|
||||||
|
for (int i = 0; i < 4; i++) {
|
||||||
|
gfx_sheets.emplace_back(converted_bin.begin() + (i * 0x1000),
|
||||||
|
converted_bin.begin() + ((i + 1) * 0x1000));
|
||||||
|
sheets_.emplace(i, gfx::Bitmap(128, 32, 8, gfx_sheets[i]));
|
||||||
|
sheets_[i].ApplyPalette(*rom()->mutable_dungeon_palette(3));
|
||||||
|
Renderer::GetInstance().RenderBitmap(&sheets_[i]);
|
||||||
|
}
|
||||||
|
binary_gfx_loaded_ = true;
|
||||||
|
} else {
|
||||||
|
status_ = absl::InternalError("Failed to load dungeon map tile16");
|
||||||
|
}
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ScreenEditor::DrawTitleScreenEditor() {
|
void ScreenEditor::DrawTitleScreenEditor() {
|
||||||
TAB_ITEM("Title Screen")
|
TAB_ITEM("Title Screen")
|
||||||
END_TAB_ITEM()
|
END_TAB_ITEM()
|
||||||
|
|||||||
@@ -64,11 +64,15 @@ class ScreenEditor : public SharedRom, public Editor {
|
|||||||
void DrawInventoryToolset();
|
void DrawInventoryToolset();
|
||||||
|
|
||||||
absl::Status LoadDungeonMaps();
|
absl::Status LoadDungeonMaps();
|
||||||
absl::Status LoadDungeonMapTile16(const std::vector<uint8_t>& gfx_data, bool bin_mode = false);
|
absl::Status LoadDungeonMapTile16(const std::vector<uint8_t>& gfx_data,
|
||||||
|
bool bin_mode = false);
|
||||||
void DrawDungeonMapsTabs();
|
void DrawDungeonMapsTabs();
|
||||||
void DrawDungeonMapsEditor();
|
void DrawDungeonMapsEditor();
|
||||||
|
|
||||||
|
void LoadBinaryGfx();
|
||||||
|
|
||||||
bool dungeon_maps_loaded_ = false;
|
bool dungeon_maps_loaded_ = false;
|
||||||
|
bool binary_gfx_loaded_ = false;
|
||||||
|
|
||||||
uint8_t selected_room = 0;
|
uint8_t selected_room = 0;
|
||||||
uint8_t boss_room = 0;
|
uint8_t boss_room = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user