Skip to content

Commit 52e3a48

Browse files
authored
[Minor] Add rectangular arrangement for SWSidebar and fix tooltip drawing (#1703)
- `SuperWeaponSidebar.Pyramid` controls whether cameos are arranged in a pyramid or rectangle. - `SuperWeaponSidebar.Pyramid` 控制图标按照金字塔形状排列,否则按照矩形排列。 In `uimd.ini`: ```ini [Sidebar] SuperWeaponSidebar.Pyramid=true ; boolean ```
1 parent 7934631 commit 52e3a48

File tree

5 files changed

+35
-12
lines changed

5 files changed

+35
-12
lines changed

docs/User-Interface.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,8 +620,9 @@ Default position for weeds counter overlaps with [harvester counter](#harvester-
620620
![image](_static/images/sw_sidebar.png)
621621
*SuperWeapon Sidebar used with vanilla-like assets for from [Phobos supplementaries](https://github.com/Phobos-developers/PhobosSupplementaries)*
622622

623-
- It is possible to put superweapon cameos on the left of screen like C&C3 when `SuperWeaponSidebar` is true. Cameos are arranged in a pyramid shape.
623+
- It is possible to put superweapon cameos on the left of screen like C&C3 when `SuperWeaponSidebar` is true.
624624
- Superweapon Sidebar is compatible with Ares superweapons.
625+
- `SuperWeaponSidebar.Pyramid` controls whether cameos are arranged in a pyramid or rectangle.
625626
- `SuperWeaponSidebar.Interval` controls the distance between two column cameos (excluding the background). When you need to make a background, the width of the background should be (`SuperWeaponSidebar.Interval` + cameo fixed width 60).
626627
- `SuperWeaponSidebar.LeftOffset` controls the distance between the left side of cameo and the left side of its column (background). This should not be greater than `SuperWeaponSidebar.Interval`.
627628
- `SuperWeaponSidebar.CameoHeight` controls the distance from the top of the previous cameo to the top of the next cameo. That is, the space between the upper and lower cameos is (`SuperWeaponSidebar.CameoHeight` - cameo fixed height 48). This should not be less than 48. When you need to make a background, this is the height of the background.
@@ -648,6 +649,7 @@ In `uimd.ini`:
648649
```ini
649650
[Sidebar]
650651
SuperWeaponSidebar=false ; boolean
652+
SuperWeaponSidebar.Pyramid=true ; boolean
651653
SuperWeaponSidebar.Interval=0 ; integer, pixels
652654
SuperWeaponSidebar.LeftOffset=0 ; integer, pixels
653655
SuperWeaponSidebar.CameoHeight=48 ; integer, pixels

src/Ext/Sidebar/SWSidebar/SWSidebarClass.cpp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@ CommandClass* SWSidebarClass::Commands[10];
1414
bool SWSidebarClass::AddColumn()
1515
{
1616
auto& columns = this->Columns;
17+
const int columnsCount = static_cast<int>(columns.size());
1718

18-
if (static_cast<int>(columns.size()) >= Phobos::UI::SuperWeaponSidebar_MaxColumns)
19+
if (columnsCount >= Phobos::UI::SuperWeaponSidebar_MaxColumns)
1920
return false;
2021

21-
const int maxButtons = Phobos::UI::SuperWeaponSidebar_Max - static_cast<int>(columns.size());
22+
const int firstColumn = Phobos::UI::SuperWeaponSidebar_Max;
23+
const int maxButtons = Phobos::UI::SuperWeaponSidebar_Pyramid ? firstColumn - columnsCount : firstColumn;
2224

2325
if (maxButtons <= 0)
2426
return false;
2527

2628
const int cameoWidth = 60;
27-
const auto column = GameCreate<SWColumnClass>(SWButtonClass::StartID + SuperWeaponTypeClass::Array.Count + 1 + static_cast<int>(columns.size()), maxButtons, 0, 0, cameoWidth + Phobos::UI::SuperWeaponSidebar_Interval, Phobos::UI::SuperWeaponSidebar_CameoHeight);
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);
2830

2931
if (!column)
3032
return false;
@@ -196,9 +198,9 @@ void SWSidebarClass::SortButtons()
196198

197199
const int buttonCount = static_cast<int>(vec_Buttons.size());
198200
const int cameoWidth = 60, cameoHeight = 48;
199-
const int maximum = Phobos::UI::SuperWeaponSidebar_Max;
201+
const int firstColumn = Phobos::UI::SuperWeaponSidebar_Max;
200202
const int cameoHarfInterval = (Phobos::UI::SuperWeaponSidebar_CameoHeight - cameoHeight) / 2;
201-
int location_Y = (DSurface::ViewBounds.Height - std::min(buttonCount, maximum) * Phobos::UI::SuperWeaponSidebar_CameoHeight) / 2;
203+
int location_Y = (DSurface::ViewBounds.Height - std::min(buttonCount, firstColumn) * Phobos::UI::SuperWeaponSidebar_CameoHeight) / 2;
202204
Point2D location = { Phobos::UI::SuperWeaponSidebar_LeftOffset, location_Y + cameoHarfInterval };
203205
int rowIdx = 0, columnIdx = 0;
204206

@@ -217,11 +219,16 @@ void SWSidebarClass::SortButtons()
217219
button->SetPosition(location.X, location.Y);
218220
rowIdx++;
219221

220-
if (rowIdx >= maximum - columnIdx)
222+
const int currentCapacity = Phobos::UI::SuperWeaponSidebar_Pyramid ? firstColumn - columnIdx : firstColumn;
223+
224+
if (rowIdx >= currentCapacity)
221225
{
222226
rowIdx = 0;
223227
columnIdx++;
224-
location_Y += Phobos::UI::SuperWeaponSidebar_CameoHeight / 2;
228+
229+
if (Phobos::UI::SuperWeaponSidebar_Pyramid)
230+
location_Y += Phobos::UI::SuperWeaponSidebar_CameoHeight / 2;
231+
225232
location.X += cameoWidth + Phobos::UI::SuperWeaponSidebar_Interval;
226233
location.Y = location_Y + cameoHarfInterval;
227234
}
@@ -238,8 +245,14 @@ void SWSidebarClass::SortButtons()
238245
int SWSidebarClass::GetMaximumButtonCount()
239246
{
240247
const int firstColumn = Phobos::UI::SuperWeaponSidebar_Max;
241-
const int columns = std::min(firstColumn, Phobos::UI::SuperWeaponSidebar_MaxColumns);
242-
return (firstColumn + (firstColumn - (columns - 1))) * columns / 2;
248+
249+
if (Phobos::UI::SuperWeaponSidebar_Pyramid)
250+
{
251+
const int columns = std::min(firstColumn, Phobos::UI::SuperWeaponSidebar_MaxColumns);
252+
return (firstColumn + (firstColumn - (columns - 1))) * columns / 2;
253+
}
254+
255+
return firstColumn * Phobos::UI::SuperWeaponSidebar_MaxColumns;
243256
}
244257

245258
bool SWSidebarClass::IsEnabled()

src/Misc/PhobosToolTip.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,11 @@ DEFINE_HOOK(0x478FDC, CCToolTip_Draw2_FillRect, 0x5)
392392
393393
const int x = pColumn->X + pColumn->Width + 2;
394394
*/
395+
GET_STACK(int, textHeight, STACK_OFFSET(0x44, -0x28));
396+
395397
const auto pColumn = SWSidebarClass::Instance.Columns[pButton->ColumnIndex];
396398
const int x = pColumn->X + pColumn->Width + 2;
397-
const int y = pButton->Y + 3;
399+
const int y = std::clamp(pButton->Y + 3, 0, DSurface::ViewBounds.Height - textHeight);
398400
pRect->X = x;
399401
pTextRect->Right += (x - pTextRect->Left);
400402
pTextRect->Left = x;
@@ -414,9 +416,10 @@ DEFINE_HOOK(0x478FDC, CCToolTip_Draw2_FillRect, 0x5)
414416
else if (const auto pButton = SWSidebarClass::Instance.CurrentButton)
415417
{
416418
LEA_STACK(LTRBStruct*, pTextRect, STACK_OFFSET(0x44, -0x20));
419+
GET_STACK(int, textHeight, STACK_OFFSET(0x44, -0x28));
417420

418421
const int x = pButton->X + pButton->Width;
419-
const int y = pButton->Y + 43;
422+
const int y = std::clamp(pButton->Y + 43, 0, DSurface::ViewBounds.Height - textHeight);
420423
pRect->X = x;
421424
pTextRect->Right += (x - pTextRect->Left);
422425
pTextRect->Left = x;

src/Phobos.INI.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ double Phobos::UI::PowerDelta_ConditionYellow = 0.75;
3434
double Phobos::UI::PowerDelta_ConditionRed = 1.0;
3535
bool Phobos::UI::CenterPauseMenuBackground = false;
3636
bool Phobos::UI::SuperWeaponSidebar = false;
37+
bool Phobos::UI::SuperWeaponSidebar_Pyramid = true;
3738
int Phobos::UI::SuperWeaponSidebar_Interval = 0;
3839
int Phobos::UI::SuperWeaponSidebar_LeftOffset = 0;
3940
int Phobos::UI::SuperWeaponSidebar_CameoHeight = 48;
@@ -181,6 +182,9 @@ DEFINE_HOOK(0x5FACDF, OptionsClass_LoadSettings_LoadPhobosSettings, 0x5)
181182
Phobos::UI::SuperWeaponSidebar =
182183
ini_uimd.ReadBool(SIDEBAR_SECTION, "SuperWeaponSidebar", Phobos::UI::SuperWeaponSidebar);
183184

185+
Phobos::UI::SuperWeaponSidebar_Pyramid =
186+
ini_uimd.ReadBool(SIDEBAR_SECTION, "SuperWeaponSidebar.Pyramid", Phobos::UI::SuperWeaponSidebar_Pyramid);
187+
184188
Phobos::UI::SuperWeaponSidebar_Interval =
185189
ini_uimd.ReadInteger(SIDEBAR_SECTION, "SuperWeaponSidebar.Interval", Phobos::UI::SuperWeaponSidebar_Interval);
186190

src/Phobos.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class Phobos
5555
static double PowerDelta_ConditionRed;
5656
static bool CenterPauseMenuBackground;
5757
static bool SuperWeaponSidebar;
58+
static bool SuperWeaponSidebar_Pyramid;
5859
static int SuperWeaponSidebar_Interval;
5960
static int SuperWeaponSidebar_LeftOffset;
6061
static int SuperWeaponSidebar_CameoHeight;

0 commit comments

Comments
 (0)