From e3351404e90bef331965e592ac6b7be038e2b0d7 Mon Sep 17 00:00:00 2001 From: AgustinSRG Date: Fri, 17 Jan 2025 19:01:50 +0100 Subject: [PATCH] Improve materials window Show all the color variants for each material, depending on the selected build method. #1 --- src/minecraft/mc_colors.cpp | 24 ++++++++ src/minecraft/mc_colors.h | 9 +++ src/wx/main_window.cpp | 14 +++-- src/wx/materials_window.cpp | 114 ++++++++++++++++++++++++++++++------ src/wx/materials_window.h | 31 +++++++++- 5 files changed, 167 insertions(+), 25 deletions(-) diff --git a/src/minecraft/mc_colors.cpp b/src/minecraft/mc_colors.cpp index 6517f36..14cf137 100644 --- a/src/minecraft/mc_colors.cpp +++ b/src/minecraft/mc_colors.cpp @@ -76,6 +76,30 @@ Color minecraft::getMinecraftColor(std::vector &baseColors, size_t index, return color; } +Color minecraft::getMinecraftColorFromBase(colors::Color baseColor, McColorType colorType) +{ + Color color = baseColor; + switch (colorType) + { + case McColorType::NORMAL: + color.red = applyColorDarkness(color.red, COLOR_DARKESS_NORMAL); + color.green = applyColorDarkness(color.green, COLOR_DARKESS_NORMAL); + color.blue = applyColorDarkness(color.blue, COLOR_DARKESS_NORMAL); + break; + case McColorType::DARK: + color.red = applyColorDarkness(color.red, COLOR_DARKESS_DARK); + color.green = applyColorDarkness(color.green, COLOR_DARKESS_DARK); + color.blue = applyColorDarkness(color.blue, COLOR_DARKESS_DARK); + break; + case McColorType::DARKER: + color.red = applyColorDarkness(color.red, COLOR_DARKESS_DARKER); + color.green = applyColorDarkness(color.green, COLOR_DARKESS_DARKER); + color.blue = applyColorDarkness(color.blue, COLOR_DARKESS_DARKER); + break; + } + return color; +} + std::vector minecraft::loadBaseColors(McVersion version) { std::vector baseColors(52); diff --git a/src/minecraft/mc_colors.h b/src/minecraft/mc_colors.h index 59bb8d8..dd3734a 100644 --- a/src/minecraft/mc_colors.h +++ b/src/minecraft/mc_colors.h @@ -58,6 +58,15 @@ namespace minecraft */ colors::Color getMinecraftColor(std::vector &baseColors, size_t index, McColorType colorType); + /** + * @brief Get a minecraft final color from a base color + * @note + * @param baseColor: The base color + * @param colorType: Colort type + * @retval The final color + */ + colors::Color getMinecraftColorFromBase(colors::Color baseColor, McColorType colorType); + /** * @brief Base colors * @note diff --git a/src/wx/main_window.cpp b/src/wx/main_window.cpp index e4a41c7..045f6c9 100644 --- a/src/wx/main_window.cpp +++ b/src/wx/main_window.cpp @@ -378,7 +378,7 @@ void MainWindow::onCustomBlocks(wxCommandEvent &evt) materialsWindow = new MaterialsWindow(this); materialsWindow->Show(); materialsWindow->displayCountMaterials(countsMats); - materialsWindow->setMaterialsConf(project.version, project.colorSetConf); + materialsWindow->setMaterialsConf(project.version, project.buildMethod, project.colorSetConf); } else { @@ -392,7 +392,7 @@ void MainWindow::onChangeVersion(wxCommandEvent &evt) project.version = static_cast(evt.GetId() - VERSION_ID_PREFIX); if (materialsWindow != NULL) { - materialsWindow->setMaterialsConf(project.version, project.colorSetConf); + materialsWindow->setMaterialsConf(project.version, project.buildMethod, project.colorSetConf); } dirty = true; RequestPreviewGeneration(); @@ -401,6 +401,10 @@ void MainWindow::onChangeVersion(wxCommandEvent &evt) void MainWindow::onChangeBuildMethod(wxCommandEvent &evt) { project.buildMethod = static_cast(evt.GetId() - BUILD_METHOD_ID_PREFIX); + if (materialsWindow != NULL) + { + materialsWindow->setMaterialsConf(project.version, project.buildMethod, project.colorSetConf); + } dirty = true; RequestPreviewGeneration(); } @@ -530,7 +534,7 @@ void MainWindow::handleDropFile(wxDropFilesEvent &event) if (materialsWindow != NULL) { - materialsWindow->setMaterialsConf(project.version, project.colorSetConf); + materialsWindow->setMaterialsConf(project.version, project.buildMethod, project.colorSetConf); } // Not dirty @@ -731,7 +735,7 @@ void MainWindow::resetProject() if (materialsWindow != NULL) { - materialsWindow->setMaterialsConf(project.version, project.colorSetConf); + materialsWindow->setMaterialsConf(project.version, project.buildMethod, project.colorSetConf); } // Map params @@ -755,7 +759,7 @@ void MainWindow::loadProject(std::string path) if (materialsWindow != NULL) { - materialsWindow->setMaterialsConf(project.version, project.colorSetConf); + materialsWindow->setMaterialsConf(project.version, project.buildMethod, project.colorSetConf); } // Not dirty diff --git a/src/wx/materials_window.cpp b/src/wx/materials_window.cpp index 1848010..de60546 100644 --- a/src/wx/materials_window.cpp +++ b/src/wx/materials_window.cpp @@ -1,15 +1,15 @@ /* * This file is part of ImageToMapMC project - * + * * Copyright (c) 2021 Agustin San Roman - * + * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of * the Software, and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: - * + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. @@ -70,6 +70,85 @@ BEGIN_EVENT_TABLE(MaterialsPanel, wxScrolledWindow) EVT_TIMER(ID_Timer, MaterialsPanel::onCountRefreshTimer) END_EVENT_TABLE() +BEGIN_EVENT_TABLE(ColorDisplayPanel, wxPanel) +EVT_PAINT(ColorDisplayPanel::paintEvent) +END_EVENT_TABLE() + +ColorDisplayPanel::ColorDisplayPanel(wxWindow *parent, unsigned int index, colors::Color baseColor, mapart::MapBuildMethod buildMethod) : wxPanel(parent, MIN_ID_PANEL + index, wxPoint(5, 5), wxSize(48, 48)) +{ + this->buildMethod = buildMethod; + this->colorLight = minecraft::getMinecraftColorFromBase(baseColor, McColorType::LIGHT); + this->colorNormal = minecraft::getMinecraftColorFromBase(baseColor, McColorType::NORMAL); + this->colorDark = minecraft::getMinecraftColorFromBase(baseColor, McColorType::DARK); + this->colorDarker = minecraft::getMinecraftColorFromBase(baseColor, McColorType::DARKER); +} + +ColorDisplayPanel::~ColorDisplayPanel() +{ +} + +void ColorDisplayPanel::setBuildMethod(mapart::MapBuildMethod buildMethod) +{ + this->mu.Lock(); + this->buildMethod = buildMethod; + this->mu.Unlock(); + + this->Refresh(); +} + +void ColorDisplayPanel::paintEvent(wxPaintEvent &evt) +{ + // depending on your system you may need to look at double-buffered dcs + wxPaintDC dc(this); + render(dc); +} + +void ColorDisplayPanel::paintNow() +{ + // depending on your system you may need to look at double-buffered dcs + wxClientDC dc(this); + render(dc); +} + +void ColorDisplayPanel::render(wxDC &dc) +{ + this->mu.Lock(); + + dc.Clear(); + + switch (this->buildMethod) + { + case MapBuildMethod::Chaos: + case MapBuildMethod::Staircased: + dc.SetBrush(wxBrush(wxColour(this->colorLight.red, this->colorLight.green, this->colorLight.blue))); + dc.DrawRectangle(wxPoint(0, 0), wxSize(48, 16)); + dc.SetBrush(wxBrush(wxColour(this->colorNormal.red, this->colorNormal.green, this->colorNormal.blue))); + dc.DrawRectangle(wxPoint(0, 16), wxSize(48, 16)); + dc.SetBrush(wxBrush(wxColour(this->colorDark.red, this->colorDark.green, this->colorDark.blue))); + dc.DrawRectangle(wxPoint(0, 32), wxSize(48, 16)); + break; + case MapBuildMethod::None: + dc.SetBrush(wxBrush(wxColour(this->colorLight.red, this->colorLight.green, this->colorLight.blue))); + dc.DrawRectangle(wxPoint(0, 0), wxSize(48, 12)); + dc.SetBrush(wxBrush(wxColour(this->colorNormal.red, this->colorNormal.green, this->colorNormal.blue))); + dc.DrawRectangle(wxPoint(0, 12), wxSize(48, 12)); + dc.SetBrush(wxBrush(wxColour(this->colorDark.red, this->colorDark.green, this->colorDark.blue))); + dc.DrawRectangle(wxPoint(0, 24), wxSize(48, 12)); + dc.SetBrush(wxBrush(wxColour(this->colorDarker.red, this->colorDarker.green, this->colorDarker.blue))); + dc.DrawRectangle(wxPoint(0, 36), wxSize(48, 12)); + break; + case MapBuildMethod::Flat: + dc.SetBrush(wxBrush(wxColour(this->colorNormal.red, this->colorNormal.green, this->colorNormal.blue))); + dc.DrawRectangle(wxPoint(0, 0), wxSize(48, 48)); + break; + default: + dc.SetBrush(wxBrush(wxColour(this->colorLight.red, this->colorLight.green, this->colorLight.blue))); + dc.DrawRectangle(wxPoint(0, 0), wxSize(48, 48)); + } + + this->mu.Unlock(); +} + MaterialsPanel::MaterialsPanel(MaterialsWindow *matWin) : wxScrolledWindow(matWin, wxID_ANY, wxPoint(0, 0), matWin->GetClientSize()) { materialsWindow = matWin; @@ -89,14 +168,13 @@ MaterialsPanel::MaterialsPanel(MaterialsWindow *matWin) : wxScrolledWindow(matWi groups[i].checkBox->Bind(wxEVT_CHECKBOX, &MaterialsPanel::onCheckBoxChanged, this); sizer->Add(groups[i].checkBox, wxSizerFlags(0).Border(wxALL, 10).Align(wxALIGN_CENTER_VERTICAL)); - groups[i].colorPanel = new wxPanel(this, MIN_ID_PANEL + i, wxPoint(5, 5), wxSize(48, 48)); if (i < colors.size()) { - groups[i].colorPanel->SetBackgroundColour(wxColour(colors[i].red, colors[i].green, colors[i].blue)); + groups[i].colorPanel = new ColorDisplayPanel(this, i, colors[i], this->buildMethod); } else { - groups[i].colorPanel->SetBackgroundColour(wxColour(0, 0, 0)); + groups[i].colorPanel = new ColorDisplayPanel(this, i, colors::Color{0, 0, 0}, this->buildMethod); } sizer->Add(groups[i].colorPanel, wxSizerFlags(0).Border(wxALL, 10).Align(wxALIGN_CENTER_VERTICAL)); @@ -271,9 +349,10 @@ void MaterialsPanel::setBlacklistMode(bool blacklist) } } -void MaterialsPanel::setMaterialsConf(minecraft::McVersion version, std::string conf) +void MaterialsPanel::setMaterialsConf(minecraft::McVersion version, mapart::MapBuildMethod buildMethod, std::string conf) { this->version = version; + this->buildMethod = buildMethod; baseColors = minecraft::loadBaseColors(version); colorSet = minecraft::loadFinalColors(baseColors); blockSet = loadBlocks(baseColors); @@ -298,6 +377,7 @@ void MaterialsPanel::setMaterialsConf(minecraft::McVersion version, std::string { groups[i].checkBox->Show(); groups[i].colorLabel->Show(); + groups[i].colorPanel->setBuildMethod(this->buildMethod); groups[i].colorPanel->Show(); groups[i].combo->Show(); groups[i].countLabel->Show(); @@ -356,9 +436,9 @@ void MaterialsPanel::setMaterialsConf(minecraft::McVersion version, std::string } } -void MaterialsWindow::setMaterialsConf(minecraft::McVersion version, std::string conf) +void MaterialsWindow::setMaterialsConf(minecraft::McVersion version, mapart::MapBuildMethod buildMethod, std::string conf) { - panel->setMaterialsConf(version, conf); + panel->setMaterialsConf(version, buildMethod, conf); } void MaterialsWindow::onLoadFile(wxCommandEvent &evt) @@ -369,7 +449,7 @@ void MaterialsWindow::onLoadFile(wxCommandEvent &evt) if (openFileDialog.ShowModal() == wxID_CANCEL) return; // the user changed idea... - panel->setMaterialsConf(panel->version, tools::readTextFile(openFileDialog.GetPath().ToStdString())); + panel->setMaterialsConf(panel->version, panel->buildMethod, tools::readTextFile(openFileDialog.GetPath().ToStdString())); mainWindow->changeColorSetConf(panel->getMaterialsConf()); } @@ -405,25 +485,25 @@ void MaterialsWindow::usePreset(wxCommandEvent &evt) switch (evt.GetId()) { case ID_Preset_everything: - panel->setMaterialsConf(panel->version, "MODE(BLACKLIST)"); + panel->setMaterialsConf(panel->version, panel->buildMethod, "MODE(BLACKLIST)"); break; case ID_Preset_bw: - panel->setMaterialsConf(panel->version, "MODE(WHITELIST)\nADD(SNOW,white_concrete)\nADD(COLOR_BLACK,black_concrete)"); + panel->setMaterialsConf(panel->version, panel->buildMethod, "MODE(WHITELIST)\nADD(SNOW,white_concrete)\nADD(COLOR_BLACK,black_concrete)"); break; case ID_Preset_gray: - panel->setMaterialsConf(panel->version, "MODE(WHITELIST)\nADD(WOOL)\nADD(METAL)\nADD(SNOW)\nADD(STONE)\nADD(COLOR_GRAY)\nADD(COLOR_LIGHT_GRAY)\nADD(COLOR_BLACK)\nADD(DEEPSLATE)"); + panel->setMaterialsConf(panel->version, panel->buildMethod, "MODE(WHITELIST)\nADD(WOOL)\nADD(METAL)\nADD(SNOW)\nADD(STONE)\nADD(COLOR_GRAY)\nADD(COLOR_LIGHT_GRAY)\nADD(COLOR_BLACK)\nADD(DEEPSLATE)"); break; case ID_Preset_carpets: - panel->setMaterialsConf(panel->version, "MODE(WHITELIST)\nADD(SNOW,white_carpet)\nADD(COLOR_MAGENTA,magenta_carpet)\nADD(COLOR_LIGHT_BLUE,light_blue_carpet)\nADD(COLOR_YELLOW,yellow_carpet)\nADD(COLOR_LIGHT_GREEN,lime_carpet)\nADD(COLOR_PINK,pink_carpet)\nADD(COLOR_GRAY,gray_carpet)\nADD(COLOR_LIGHT_GRAY,light_gray_carpet)\nADD(COLOR_CYAN,cyan_carpet)\nADD(COLOR_PURPLE,purple_carpet)\nADD(COLOR_BLUE,blue_carpet)\nADD(COLOR_BROWN,brown_carpet)\nADD(COLOR_GREEN,green_carpet)\nADD(COLOR_RED,red_carpet)\nADD(COLOR_BLACK,black_carpet)"); + panel->setMaterialsConf(panel->version, panel->buildMethod, "MODE(WHITELIST)\nADD(SNOW,white_carpet)\nADD(COLOR_MAGENTA,magenta_carpet)\nADD(COLOR_LIGHT_BLUE,light_blue_carpet)\nADD(COLOR_YELLOW,yellow_carpet)\nADD(COLOR_LIGHT_GREEN,lime_carpet)\nADD(COLOR_PINK,pink_carpet)\nADD(COLOR_GRAY,gray_carpet)\nADD(COLOR_LIGHT_GRAY,light_gray_carpet)\nADD(COLOR_CYAN,cyan_carpet)\nADD(COLOR_PURPLE,purple_carpet)\nADD(COLOR_BLUE,blue_carpet)\nADD(COLOR_BROWN,brown_carpet)\nADD(COLOR_GREEN,green_carpet)\nADD(COLOR_RED,red_carpet)\nADD(COLOR_BLACK,black_carpet)"); break; case ID_Preset_concrete: - panel->setMaterialsConf(panel->version, "MODE(WHITELIST)\nADD(SNOW,white_concrete)\nADD(COLOR_MAGENTA,magenta_concrete)\nADD(COLOR_LIGHT_BLUE,light_blue_concrete)\nADD(COLOR_YELLOW,yellow_concrete)\nADD(COLOR_LIGHT_GREEN,lime_concrete)\nADD(COLOR_PINK,pink_concrete)\nADD(COLOR_GRAY,gray_concrete)\nADD(COLOR_LIGHT_GRAY,light_gray_concrete)\nADD(COLOR_CYAN,cyan_concrete)\nADD(COLOR_PURPLE,purple_concrete)\nADD(COLOR_BLUE,blue_concrete)\nADD(COLOR_BROWN,brown_concrete)\nADD(COLOR_GREEN,green_concrete)\nADD(COLOR_RED,red_concrete)\nADD(COLOR_BLACK,black_concrete)"); + panel->setMaterialsConf(panel->version, panel->buildMethod, "MODE(WHITELIST)\nADD(SNOW,white_concrete)\nADD(COLOR_MAGENTA,magenta_concrete)\nADD(COLOR_LIGHT_BLUE,light_blue_concrete)\nADD(COLOR_YELLOW,yellow_concrete)\nADD(COLOR_LIGHT_GREEN,lime_concrete)\nADD(COLOR_PINK,pink_concrete)\nADD(COLOR_GRAY,gray_concrete)\nADD(COLOR_LIGHT_GRAY,light_gray_concrete)\nADD(COLOR_CYAN,cyan_concrete)\nADD(COLOR_PURPLE,purple_concrete)\nADD(COLOR_BLUE,blue_concrete)\nADD(COLOR_BROWN,brown_concrete)\nADD(COLOR_GREEN,green_concrete)\nADD(COLOR_RED,red_concrete)\nADD(COLOR_BLACK,black_concrete)"); break; case ID_Preset_wool: - panel->setMaterialsConf(panel->version, "MODE(WHITELIST)\nADD(SNOW,white_wool)\nADD(COLOR_MAGENTA)\nADD(COLOR_LIGHT_BLUE)\nADD(COLOR_YELLOW)\nADD(COLOR_LIGHT_GREEN)\nADD(COLOR_PINK)\nADD(COLOR_GRAY)\nADD(COLOR_LIGHT_GRAY)\nADD(COLOR_CYAN)\nADD(COLOR_PURPLE)\nADD(COLOR_BLUE)\nADD(COLOR_BROWN)\nADD(COLOR_GREEN)\nADD(COLOR_RED)\nADD(COLOR_BLACK)"); + panel->setMaterialsConf(panel->version, panel->buildMethod, "MODE(WHITELIST)\nADD(SNOW,white_wool)\nADD(COLOR_MAGENTA)\nADD(COLOR_LIGHT_BLUE)\nADD(COLOR_YELLOW)\nADD(COLOR_LIGHT_GREEN)\nADD(COLOR_PINK)\nADD(COLOR_GRAY)\nADD(COLOR_LIGHT_GRAY)\nADD(COLOR_CYAN)\nADD(COLOR_PURPLE)\nADD(COLOR_BLUE)\nADD(COLOR_BROWN)\nADD(COLOR_GREEN)\nADD(COLOR_RED)\nADD(COLOR_BLACK)"); break; case ID_Preset_no_minerals: - panel->setMaterialsConf(panel->version, "MODE(BLACKLIST)\nADD(FIRE,tnt)\nREMOVE(METAL)\nREMOVE(GOLD)\nREMOVE(LAPIS)\nREMOVE(EMERALD)\nREMOVE(RAW_IRON)"); + panel->setMaterialsConf(panel->version, panel->buildMethod, "MODE(BLACKLIST)\nADD(FIRE,tnt)\nREMOVE(METAL)\nREMOVE(GOLD)\nREMOVE(LAPIS)\nREMOVE(EMERALD)\nREMOVE(RAW_IRON)"); break; } panel->onConfigChanged(); diff --git a/src/wx/materials_window.h b/src/wx/materials_window.h index d94a4e8..e4e4373 100644 --- a/src/wx/materials_window.h +++ b/src/wx/materials_window.h @@ -36,10 +36,34 @@ #include "main_window.h" +class ColorDisplayPanel : public wxPanel +{ +public: + ColorDisplayPanel(wxWindow *parent, unsigned int index, colors::Color baseColor, mapart::MapBuildMethod buildMethod); + ~ColorDisplayPanel(); + + void setBuildMethod(mapart::MapBuildMethod buildMethod); + + void paintEvent(wxPaintEvent &evt); + void paintNow(); + + void render(wxDC &dc); + + DECLARE_EVENT_TABLE() +private: + wxMutex mu; + mapart::MapBuildMethod buildMethod; + + colors::Color colorNormal; + colors::Color colorLight; + colors::Color colorDark; + colors::Color colorDarker; +}; + struct MaterialCustomGroup { wxCheckBox *checkBox; - wxPanel *colorPanel; + ColorDisplayPanel *colorPanel; wxStaticText *colorLabel; wxComboBox *combo; wxStaticText *countLabel; @@ -57,7 +81,7 @@ class MaterialsPanel : public wxScrolledWindow void onCountRefreshTimer(wxTimerEvent& event); - void setMaterialsConf(minecraft::McVersion version, std::string conf); + void setMaterialsConf(minecraft::McVersion version, mapart::MapBuildMethod buildMethod, std::string conf); std::string getMaterialsConf(); @@ -67,6 +91,7 @@ class MaterialsPanel : public wxScrolledWindow bool blacklist; minecraft::McVersion version; + mapart::MapBuildMethod buildMethod; void displayCountMaterials(std::vector &counts); private: @@ -106,7 +131,7 @@ class MaterialsWindow : public wxFrame void usePreset(wxCommandEvent &evt); - void setMaterialsConf(minecraft::McVersion version, std::string conf); + void setMaterialsConf(minecraft::McVersion version, mapart::MapBuildMethod buildMethod, std::string conf); void displayCountMaterials(std::vector &counts);