Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/Ext/Sidebar/SWSidebar/SWColumnClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}
Expand All @@ -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();
}
45 changes: 34 additions & 11 deletions src/Ext/Sidebar/SWSidebar/SWSidebarClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -59,7 +58,6 @@ void SWSidebarClass::InitClear()
{
this->ToggleButton = nullptr;
GScreenClass::Instance->RemoveButton(toggleButton);
DLLDelete(toggleButton);
}

auto& columns = this->Columns;
Expand All @@ -68,7 +66,6 @@ void SWSidebarClass::InitClear()
{
column->ClearButtons();
GScreenClass::Instance->RemoveButton(column);
DLLDelete(column);
}

columns.clear();
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<ToggleSWButtonClass>(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<ToggleSWButtonClass>(SWButtonClass::StartID + SuperWeaponTypeClass::Array->Count, 0, 0, width, height))
{
toggleButton->Zap();
GScreenClass::Instance->AddButton(toggleButton);
SWSidebarClass::Instance.ToggleButton = toggleButton;
toggleButton->UpdatePosition();
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Phobos.INI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading