diff --git a/source/common_windows.cpp b/source/common_windows.cpp index 9bcc39d4..f6494966 100644 --- a/source/common_windows.cpp +++ b/source/common_windows.cpp @@ -529,7 +529,7 @@ EVT_CHOICE(wxID_ANY, ExportMiniMapWindow::OnExportTypeChange) END_EVENT_TABLE() ExportMiniMapWindow::ExportMiniMapWindow(wxWindow* parent, Editor &editor) : - wxDialog(parent, wxID_ANY, "Export Minimap", wxDefaultPosition, wxSize(400, 300)), + wxDialog(parent, wxID_ANY, "Export Minimap", wxDefaultPosition, wxSize(400, 350)), editor(editor) { wxSizer* sizer = newd wxBoxSizer(wxVERTICAL); wxSizer* tmpsizer; @@ -550,6 +550,18 @@ ExportMiniMapWindow::ExportMiniMapWindow(wxWindow* parent, Editor &editor) : tmpsizer->Add(newd wxButton(this, MAP_WINDOW_FILE_BUTTON, "Browse"), 0, wxALL, 5); sizer->Add(tmpsizer, 0, wxALL | wxEXPAND, 5); + // Format options + wxArrayString imageFormatChoices; + imageFormatChoices.Add("1024x1024"); + imageFormatChoices.Add("2048x2048"); + imageFormatChoices.Add("4096x4096"); + imageSizeOptions = new wxChoice(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, imageFormatChoices); + imageSizeOptions->SetSelection(0); + imageSizeOptions->Disable(); + tmpsizer = newd wxStaticBoxSizer(wxHORIZONTAL, this, "Image Size"); + tmpsizer->Add(imageSizeOptions, 1, wxALL, 5); + sizer->Add(tmpsizer, 0, wxALL | wxEXPAND, 5); + // File name wxString mapName(editor.getMap().getName().c_str(), wxConvUTF8); file_name_text_field = newd wxTextCtrl(this, wxID_ANY, mapName.BeforeLast('.'), wxDefaultPosition, wxDefaultSize); @@ -602,6 +614,7 @@ ExportMiniMapWindow::ExportMiniMapWindow(wxWindow* parent, Editor &editor) : ExportMiniMapWindow::~ExportMiniMapWindow() = default; void ExportMiniMapWindow::OnExportTypeChange(wxCommandEvent &event) { + imageSizeOptions->Enable(event.GetSelection() > 0); floor_number->Enable(event.GetSelection() == 2); } @@ -627,6 +640,14 @@ void ExportMiniMapWindow::OnFileNameChanged(wxKeyEvent &event) { void ExportMiniMapWindow::OnClickOK(wxCommandEvent &WXUNUSED(event)) { g_gui.CreateLoadBar("Exporting minimap..."); + const auto imageSizeSelection = imageSizeOptions->GetSelection(); + auto imageSize = 1024; + if (imageSizeSelection == 1) { + imageSize = 2048; + } else if (imageSizeSelection == 2) { + imageSize = 4096; + } + auto format = static_cast(format_options->GetSelection()); auto mode = static_cast(floor_options->GetSelection()); std::string directory = directory_text_field->GetValue().ToStdString(); @@ -635,7 +656,7 @@ void ExportMiniMapWindow::OnClickOK(wxCommandEvent &WXUNUSED(event)) { g_settings.setString(Config::MINIMAP_EXPORT_DIR, directory); - IOMinimap io(&editor, format, mode, true); + IOMinimap io(&editor, format, mode, true, imageSize); if (!io.saveMinimap(directory, file_name, floor)) { g_gui.PopupDialog("Error", io.getError(), wxOK); } diff --git a/source/common_windows.h b/source/common_windows.h index aec203ba..d84ce064 100644 --- a/source/common_windows.h +++ b/source/common_windows.h @@ -126,6 +126,7 @@ class ExportMiniMapWindow : public wxDialog { Editor &editor; + wxChoice* imageSizeOptions; wxChoice* format_options; wxStaticText* error_field; wxTextCtrl* directory_text_field; diff --git a/source/iominimap.cpp b/source/iominimap.cpp index d518f259..51c52794 100644 --- a/source/iominimap.cpp +++ b/source/iominimap.cpp @@ -31,11 +31,12 @@ void MinimapBlock::updateTile(int x, int y, const MinimapTile &tile) { m_tiles[getTileIndex(x, y)] = tile; } -IOMinimap::IOMinimap(Editor* editor, MinimapExportFormat format, MinimapExportMode mode, bool updateLoadbar) : +IOMinimap::IOMinimap(Editor* editor, MinimapExportFormat format, MinimapExportMode mode, bool updateLoadbar, int imageSize /* = 1024 */) : m_editor(editor), m_format(format), m_mode(mode), - m_updateLoadbar(updateLoadbar) { + m_updateLoadbar(updateLoadbar), + m_imageSize(imageSize) { } bool IOMinimap::saveMinimap(const std::string &directory, const std::string &name, int floor) { @@ -188,10 +189,9 @@ bool IOMinimap::exportMinimap(const std::string &directory) { totalTiles++; } - constexpr int image_size = 1024; - constexpr int pixels_size = image_size * image_size * rme::PixelFormatRGB; + int pixels_size = m_imageSize * m_imageSize * rme::PixelFormatRGB; uint8_t* pixels = new uint8_t[pixels_size]; - auto image = new wxImage(image_size, image_size, pixels, true); + auto image = new wxImage(m_imageSize, m_imageSize, pixels, true); int processedTiles = 0; int lastShownProgress = -1; @@ -201,8 +201,8 @@ bool IOMinimap::exportMinimap(const std::string &directory) { continue; } - for (int h = 0; h < rme::MapMaxHeight; h += image_size) { - for (int w = 0; w < rme::MapMaxWidth; w += image_size) { + for (int h = 0; h < rme::MapMaxHeight; h += m_imageSize) { + for (int w = 0; w < rme::MapMaxWidth; w += m_imageSize) { if (w < rect.x || w > rect.width || h < rect.y || h > rect.height) { continue; } @@ -211,8 +211,8 @@ bool IOMinimap::exportMinimap(const std::string &directory) { memset(pixels, 0, pixels_size); int index = 0; - for (int y = 0; y < image_size; y++) { - for (int x = 0; x < image_size; x++) { + for (int y = 0; y < m_imageSize; y++) { + for (int x = 0; x < m_imageSize; x++) { auto tile = map.getTile(w + x, h + y, z); if (!tile || (!tile->ground && tile->items.empty())) { index += rme::PixelFormatRGB; @@ -243,7 +243,7 @@ bool IOMinimap::exportMinimap(const std::string &directory) { wxBitmapType type = m_format == MinimapExportFormat::Png ? wxBITMAP_TYPE_PNG : wxBITMAP_TYPE_BMP; wxString extension_wx = wxString::FromAscii(extension.mb_str()); wxFileName file = wxString::Format("%s-%s-%s.%s", std::to_string(h), std::to_string(w), std::to_string(z), extension_wx); - file.Normalize(wxPATH_NORM_DOTS | wxPATH_NORM_TILDE | wxPATH_NORM_CASE, directory); + file.Normalize(wxPATH_NORM_DOTS | wxPATH_NORM_TILDE | wxPATH_NORM_CASE | wxPATH_NORM_ABSOLUTE, directory); image->SaveFile(file.GetFullPath(), type); } } diff --git a/source/iominimap.h b/source/iominimap.h index 214cdc18..4ddc7dfc 100644 --- a/source/iominimap.h +++ b/source/iominimap.h @@ -72,7 +72,7 @@ class MinimapBlock { class IOMinimap { public: - IOMinimap(Editor* editor, MinimapExportFormat format, MinimapExportMode mode, bool updateLoadbar); + IOMinimap(Editor* editor, MinimapExportFormat format, MinimapExportMode mode, bool updateLoadbar, int imageSize = 1024); bool saveMinimap(const std::string &directory, const std::string &name, int floor = -1); @@ -95,6 +95,7 @@ class IOMinimap { MinimapExportMode m_mode; bool m_updateLoadbar = false; int m_floor = -1; + int m_imageSize = 1024; std::unordered_map m_blocks[rme::MapLayers]; std::string m_error; };