diff --git a/src/Ext/Sidebar/SWSidebar/SWColumnClass.cpp b/src/Ext/Sidebar/SWSidebar/SWColumnClass.cpp index 9b809a8073..4f2bf2cca5 100644 --- a/src/Ext/Sidebar/SWSidebar/SWColumnClass.cpp +++ b/src/Ext/Sidebar/SWSidebar/SWColumnClass.cpp @@ -35,13 +35,15 @@ bool SWColumnClass::Draw(bool forced) if (const auto pTopPCX = pSideExt->SuperWeaponSidebar_TopPCX.GetSurface()) { - RectangleStruct drawRect { this->X, this->Y, cameoBackgroundWidth, 20 }; + const int height = pTopPCX->GetHeight(); + RectangleStruct drawRect { this->X, this->Y, cameoBackgroundWidth, height }; PCX::Instance->BlitToSurface(&drawRect, DSurface::Composite, pTopPCX); } if (const auto pBottomPCX = pSideExt->SuperWeaponSidebar_BottomPCX.GetSurface()) { - RectangleStruct drawRect { this->X, this->Y + this->Height - 20, cameoBackgroundWidth, 20 }; + const int height = pBottomPCX->GetHeight(); + RectangleStruct drawRect { this->X, this->Y + this->Height - height, cameoBackgroundWidth, height }; PCX::Instance->BlitToSurface(&drawRect, DSurface::Composite, pBottomPCX); } @@ -116,6 +118,10 @@ bool SWColumnClass::AddButton(int superIdx) button->Zap(); GScreenClass::Instance->AddButton(button); SWSidebarClass::Instance.SortButtons(); + + if (const auto toggleButton = SWSidebarClass::Instance.ToggleButton) + toggleButton->UpdatePosition(); + return true; } @@ -131,7 +137,6 @@ bool SWColumnClass::RemoveButton(int superIdx) AnnounceInvalidPointer(SWSidebarClass::Instance.CurrentButton, *it); GScreenClass::Instance->RemoveButton(*it); - DLLDelete(*it); buttons.erase(it); return true; } @@ -153,5 +158,11 @@ void SWColumnClass::SetHeight(int height) { const auto pSideExt = SideExt::ExtMap.Find(SideClass::Array->Items[ScenarioClass::Instance->PlayerSideIndex]); - this->Height = height + (pSideExt->SuperWeaponSidebar_TopPCX.GetSurface() ? 20 : 0) + (pSideExt->SuperWeaponSidebar_BottomPCX.GetSurface() ? 20 : 0); + this->Height = height; + + if (const auto pTopPCX = pSideExt->SuperWeaponSidebar_TopPCX.GetSurface()) + this->Height += pTopPCX->GetHeight(); + + if (const auto pBottomPCX = pSideExt->SuperWeaponSidebar_BottomPCX.GetSurface()) + this->Height += pBottomPCX->GetHeight(); } diff --git a/src/Ext/Sidebar/SWSidebar/SWSidebarClass.cpp b/src/Ext/Sidebar/SWSidebar/SWSidebarClass.cpp index dd7f9b4ec3..7bc8d4db69 100644 --- a/src/Ext/Sidebar/SWSidebar/SWSidebarClass.cpp +++ b/src/Ext/Sidebar/SWSidebar/SWSidebarClass.cpp @@ -42,7 +42,6 @@ bool SWSidebarClass::RemoveColumn() AnnounceInvalidPointer(SWSidebarClass::Instance.CurrentColumn, backColumn); GScreenClass::Instance->RemoveButton(backColumn); - DLLDelete(backColumn); columns.erase(columns.end() - 1); return true; } @@ -59,7 +58,6 @@ void SWSidebarClass::InitClear() { this->ToggleButton = nullptr; GScreenClass::Instance->RemoveButton(toggleButton); - DLLDelete(toggleButton); } auto& columns = this->Columns; @@ -68,7 +66,6 @@ void SWSidebarClass::InitClear() { column->ClearButtons(); GScreenClass::Instance->RemoveButton(column); - DLLDelete(column); } columns.clear(); @@ -168,9 +165,6 @@ void SWSidebarClass::SortButtons() for (const auto column : columns) column->SetHeight(column->Buttons.size() * Phobos::UI::SuperWeaponSidebar_CameoHeight); - - if (const auto toggleButton = this->ToggleButton) - toggleButton->UpdatePosition(); } int SWSidebarClass::GetMaximumButtonCount() @@ -241,6 +235,9 @@ DEFINE_HOOK(0x4F92FB, HouseClass_UpdateTechTree_SWSidebar, 0x7) for (; removes > 0; --removes) sidebar.RemoveColumn(); + + if (const auto toggleButton = sidebar.ToggleButton) + toggleButton->UpdatePosition(); } return SkipGameCode; @@ -283,12 +280,38 @@ DEFINE_HOOK(0x6A5839, SidebarClass_InitIO_InitializeSWSidebar, 0x5) if (const auto pSideExt = SideExt::ExtMap.Find(SideClass::Array->Items[ScenarioClass::Instance->PlayerSideIndex])) { - if (const auto toggleButton = DLLCreate(SWButtonClass::StartID + SuperWeaponTypeClass::Array->Count, 0, 0, 10, 50)) + const auto pOnPCX = pSideExt->SuperWeaponSidebar_OnPCX.GetSurface(); + const auto pOffPCX = pSideExt->SuperWeaponSidebar_OffPCX.GetSurface(); + int width = 0, height = 0; + + if (pOnPCX) { - toggleButton->Zap(); - GScreenClass::Instance->AddButton(toggleButton); - SWSidebarClass::Instance.ToggleButton = toggleButton; - toggleButton->UpdatePosition(); + if (pOffPCX) + { + width = std::max(pOnPCX->GetWidth(), pOffPCX->GetWidth()); + height = std::max(pOnPCX->GetHeight(), pOffPCX->GetHeight()); + } + else + { + width = pOnPCX->GetWidth(); + height = pOnPCX->GetHeight(); + } + } + else if (pOffPCX) + { + width = pOffPCX->GetWidth(); + height = pOffPCX->GetHeight(); + } + + if (width > 0 && height > 0) + { + if (const auto toggleButton = DLLCreate(SWButtonClass::StartID + SuperWeaponTypeClass::Array->Count, 0, 0, width, height)) + { + toggleButton->Zap(); + GScreenClass::Instance->AddButton(toggleButton); + SWSidebarClass::Instance.ToggleButton = toggleButton; + toggleButton->UpdatePosition(); + } } } diff --git a/src/Phobos.INI.cpp b/src/Phobos.INI.cpp index 0f6c01342a..621d4c2e9b 100644 --- a/src/Phobos.INI.cpp +++ b/src/Phobos.INI.cpp @@ -190,9 +190,9 @@ DEFINE_HOOK(0x5FACDF, OptionsClass_LoadSettings_LoadPhobosSettings, 0x5) const int screenHeight = GameOptionsClass::Instance->ScreenHeight; if (Phobos::UI::SuperWeaponSidebar_Max > 0) - Phobos::UI::SuperWeaponSidebar_Max = std::min(Phobos::UI::SuperWeaponSidebar_Max, (screenHeight - 40) / Phobos::UI::SuperWeaponSidebar_CameoHeight); + Phobos::UI::SuperWeaponSidebar_Max = std::min(Phobos::UI::SuperWeaponSidebar_Max, screenHeight / Phobos::UI::SuperWeaponSidebar_CameoHeight); else - Phobos::UI::SuperWeaponSidebar_Max = (screenHeight - 40) / Phobos::UI::SuperWeaponSidebar_CameoHeight; + Phobos::UI::SuperWeaponSidebar_Max = screenHeight / Phobos::UI::SuperWeaponSidebar_CameoHeight; Phobos::UI::SuperWeaponSidebar_MaxColumns = ini_uimd.ReadInteger(SIDEBAR_SECTION, "SuperWeaponSidebar.MaxColumns", Phobos::UI::SuperWeaponSidebar_MaxColumns);