Skip to content

Commit 6c2af20

Browse files
authored
[Minor] SWSidebar allows multiple additions of the same super weapon type (#1711)
Currently, when attempting add a super weapon into sw sidebar, it will check if any button has same type of sw. If it exist, the attempt will be droped; Now it will add normally.
1 parent 53fff4f commit 6c2af20

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

src/Ext/Sidebar/SWSidebar/SWColumnClass.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,13 @@ bool SWColumnClass::AddButton(int superIdx)
108108
sidebar.DisableEntry = false;
109109
}
110110

111+
int currentID = SWButtonClass::StartID;
112+
113+
for (const auto column : sidebar.Columns)
114+
currentID += static_cast<int>(column->Buttons.size());
115+
111116
const int cameoWidth = 60, cameoHeight = 48;
112-
const auto button = GameCreate<SWButtonClass>(SWButtonClass::StartID + superIdx, superIdx, 0, 0, cameoWidth, cameoHeight);
117+
const auto button = GameCreate<SWButtonClass>(currentID, superIdx, 0, 0, cameoWidth, cameoHeight);
113118

114119
if (!button)
115120
return false;

src/Ext/Sidebar/SWSidebar/SWColumnClass.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class SWColumnClass : public ControlClass
2323

2424
void SetHeight(int height);
2525

26+
static constexpr int StartID = 2101;
27+
2628
std::vector<SWButtonClass*> Buttons {};
2729
int MaxButtons { 0 };
2830
};

src/Ext/Sidebar/SWSidebar/SWSidebarClass.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ bool SWSidebarClass::AddColumn()
2626
return false;
2727

2828
const int cameoWidth = 60;
29-
const auto column = GameCreate<SWColumnClass>(SWButtonClass::StartID + SuperWeaponTypeClass::Array.Count + 1 + columnsCount, maxButtons, 0, 0, cameoWidth + Phobos::UI::SuperWeaponSidebar_Interval, Phobos::UI::SuperWeaponSidebar_CameoHeight);
29+
const auto column = GameCreate<SWColumnClass>(SWColumnClass::StartID + columnsCount, maxButtons, 0, 0, cameoWidth + Phobos::UI::SuperWeaponSidebar_Interval, Phobos::UI::SuperWeaponSidebar_CameoHeight);
3030

3131
if (!column)
3232
return false;
@@ -109,7 +109,7 @@ void SWSidebarClass::InitIO()
109109

110110
if (width > 0 && height > 0)
111111
{
112-
if (const auto toggleButton = GameCreate<ToggleSWButtonClass>(SWButtonClass::StartID + SuperWeaponTypeClass::Array.Count, 0, 0, width, height))
112+
if (const auto toggleButton = GameCreate<ToggleSWButtonClass>(SWColumnClass::StartID - 1, 0, 0, width, height))
113113
{
114114
toggleButton->Zap();
115115
GScreenClass::Instance.AddButton(toggleButton);
@@ -151,9 +151,6 @@ bool SWSidebarClass::AddButton(int superIdx)
151151
if (columns.empty() && !this->AddColumn())
152152
return false;
153153

154-
if (std::any_of(columns.begin(), columns.end(), [superIdx](SWColumnClass* column) { return std::any_of(column->Buttons.begin(), column->Buttons.end(), [superIdx](SWButtonClass* button) { return button->SuperIndex == superIdx; }); }))
155-
return true;
156-
157154
return columns.back()->AddButton(superIdx);
158155
}
159156

0 commit comments

Comments
 (0)