mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 09:10:06 +00:00
Update color table immediately on palette change
This commit is contained in:
parent
4425c53c8e
commit
34ec35caf0
1 changed files with 57 additions and 43 deletions
|
|
@ -135,6 +135,9 @@ public:
|
|||
|
||||
~MapWidgetImpl()
|
||||
{
|
||||
// Disconnect signals
|
||||
colorPaletteConnection_.disconnect();
|
||||
|
||||
DeinitializeCustomStyles();
|
||||
|
||||
// Set ImGui Context
|
||||
|
|
@ -182,6 +185,7 @@ public:
|
|||
std::optional<std::string> type);
|
||||
void SetRadarSite(const std::string& radarSite,
|
||||
bool checkProductAvailability = false);
|
||||
void UpdateColorTable(const std::string& colorPalette);
|
||||
void UpdateLoadedStyle();
|
||||
bool UpdateStoredMapParameters();
|
||||
void CheckLevel3Availability();
|
||||
|
|
@ -214,6 +218,8 @@ public:
|
|||
boost::uuids::uuid customStyleUrlChangedCallbackId_ {};
|
||||
boost::uuids::uuid customStyleDrawBelowChangedCallbackId_ {};
|
||||
|
||||
boost::signals2::scoped_connection colorPaletteConnection_ {};
|
||||
|
||||
ImGuiContext* imGuiContext_;
|
||||
std::string imGuiContextName_;
|
||||
bool imGuiRendererInitialized_;
|
||||
|
|
@ -901,6 +907,13 @@ void MapWidget::SelectRadarProduct(common::RadarProductGroup group,
|
|||
(group == common::RadarProductGroup::Level2) ?
|
||||
common::GetLevel2Palette(common::GetLevel2Product(productName)) :
|
||||
common::GetLevel3Palette(productCode);
|
||||
|
||||
auto& paletteSetting =
|
||||
settings::PaletteSettings::Instance().palette(palette);
|
||||
|
||||
p->colorPaletteConnection_ = paletteSetting.changed_signal().connect(
|
||||
[this, palette]() { p->UpdateColorTable(palette); });
|
||||
|
||||
p->InitializeNewRadarProductView(palette);
|
||||
}
|
||||
else if (update)
|
||||
|
|
@ -1953,43 +1966,13 @@ void MapWidgetImpl::RadarProductManagerDisconnect()
|
|||
void MapWidgetImpl::InitializeNewRadarProductView(
|
||||
const std::string& colorPalette)
|
||||
{
|
||||
boost::asio::post(
|
||||
threadPool_,
|
||||
boost::asio::post(threadPool_,
|
||||
[colorPalette, this]()
|
||||
{
|
||||
try
|
||||
{
|
||||
auto radarProductView = context_->radar_product_view();
|
||||
|
||||
auto& paletteSetting =
|
||||
settings::PaletteSettings::Instance().palette(colorPalette);
|
||||
|
||||
std::string colorTableFile = paletteSetting.GetValue();
|
||||
if (colorTableFile.empty())
|
||||
{
|
||||
colorTableFile = paletteSetting.GetDefault();
|
||||
}
|
||||
|
||||
std::unique_ptr<std::istream> colorTableStream =
|
||||
util::OpenFile(colorTableFile);
|
||||
if (colorTableStream->fail())
|
||||
{
|
||||
logger_->warn("Could not open color table {}", colorTableFile);
|
||||
colorTableStream = util::OpenFile(paletteSetting.GetDefault());
|
||||
}
|
||||
|
||||
std::shared_ptr<common::ColorTable> colorTable =
|
||||
common::ColorTable::Load(*colorTableStream);
|
||||
if (!colorTable->IsValid())
|
||||
{
|
||||
logger_->warn("Could not load color table {}", colorTableFile);
|
||||
colorTableStream = util::OpenFile(paletteSetting.GetDefault());
|
||||
colorTable = common::ColorTable::Load(*colorTableStream);
|
||||
}
|
||||
|
||||
radarProductView->LoadColorTable(colorTable);
|
||||
|
||||
radarProductView->Initialize();
|
||||
UpdateColorTable(colorPalette);
|
||||
context_->radar_product_view()->Initialize();
|
||||
}
|
||||
catch (const std::exception& ex)
|
||||
{
|
||||
|
|
@ -2116,6 +2099,37 @@ void MapWidgetImpl::Update()
|
|||
}
|
||||
}
|
||||
|
||||
void MapWidgetImpl::UpdateColorTable(const std::string& colorPalette)
|
||||
{
|
||||
auto& paletteSetting =
|
||||
settings::PaletteSettings::Instance().palette(colorPalette);
|
||||
|
||||
std::string colorTableFile = paletteSetting.GetValue();
|
||||
if (colorTableFile.empty())
|
||||
{
|
||||
colorTableFile = paletteSetting.GetDefault();
|
||||
}
|
||||
|
||||
std::unique_ptr<std::istream> colorTableStream =
|
||||
util::OpenFile(colorTableFile);
|
||||
if (colorTableStream->fail())
|
||||
{
|
||||
logger_->warn("Could not open color table {}", colorTableFile);
|
||||
colorTableStream = util::OpenFile(paletteSetting.GetDefault());
|
||||
}
|
||||
|
||||
std::shared_ptr<common::ColorTable> colorTable =
|
||||
common::ColorTable::Load(*colorTableStream);
|
||||
if (!colorTable->IsValid())
|
||||
{
|
||||
logger_->warn("Could not load color table {}", colorTableFile);
|
||||
colorTableStream = util::OpenFile(paletteSetting.GetDefault());
|
||||
colorTable = common::ColorTable::Load(*colorTableStream);
|
||||
}
|
||||
|
||||
context_->radar_product_view()->LoadColorTable(colorTable);
|
||||
}
|
||||
|
||||
bool MapWidgetImpl::UpdateStoredMapParameters()
|
||||
{
|
||||
bool changed = false;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue