masakitenchi / Hardcore-SK

Rimworld Hardcore SK project, our discord server:
https://discord.gg/FMPRSKr
1 stars 1 forks source link

Architect Sense #8

Closed masakitenchi closed 12 months ago

masakitenchi commented 1 year ago

Simple Storage Pallet has 12 subcategories:

<defNames>
    <li>JDS_Large_Pallet</li>
    <li>JDSPallet</li>
    <li>JDSPallet_Crate</li>
    <li>JDS_Large_A_Pallet</li>
    <li>JDS_Large_B_Pallet</li>
    <li>JDS_Large_C_Pallet</li>
    <li>JDS_Large_D_Pallet</li>
    <li>JDS_Large_E_Pallet</li>
    <li>JDSPallet_Can</li>
    <li>JDS_Large_Can_Pallet</li>
    <li>JDSPallet_Container</li>
    <li>JDSPallet_Box</li>
</defNames>

And will show a long list of menu like the pic below (Obviously its height is larger than screen reso): image

If add a line of debug message in its .ctor:

public FloatMenu_SubCategory(List<FloatMenuOption_SubCategory> options, string title, Vector2 optionSize, bool closeOnSelection = false)
: base(((IEnumerable<FloatMenuOption_SubCategory>)options).Select((Func<FloatMenuOption_SubCategory, FloatMenuOption>)((FloatMenuOption_SubCategory opt) => opt)).ToList(), title)
{
_options = options;
_optionSize = optionSize * Prefs.UIScale;
_closeOnSelection = closeOnSelection;
preventCameraMotion = false;
numColumns = 0;
do
{
    ++numColumns; 
    Log.Message($"TotalHeight: {TotalHeight}, Screen height:{Screen.height}, ScreenHeight:{Prefs.ScreenHeight}");
      }

      while ((double)TotalHeight > (double)Screen.height * 0.9);
windowRect.size = InitialSize;
windowRect.y -= windowRect.height;
if ((double)windowRect.xMax > (double)Screen.width)
{
    windowRect.x = (float)Screen.width - windowRect.width;
}
if (windowRect.yMin < 0f)
{
    windowRect.y -= windowRect.yMin;
}
if ((double)windowRect.yMax > (double)Screen.height)
{
    windowRect.y = (float)Screen.height - windowRect.height;
}
}

Each time it's clicked this line of message shows: TotalHeight: 1185, Screen height:1440, ScreenHeight:1440 We could calculate the actual value, assuming we know these two properties:

private float ColumnMaxOptionCount
{
        get
        {
            if (options.Count % numColumns == 0)
            {
                return options.Count / numColumns;
            }
            return options.Count / numColumns + 1;
        }
}

private float TotalHeight => ColumnMaxOptionCount * (_optionSize.y + 5f);

The hardcoded size is Vec2(75f,75f), and in 1.25x UI Scale it's 75 x 1.25 = 93.75; With only one column, the total height is (93.75 + 5) x 12 = 1185; I'm using 2560x1440 so Screen.height x 0.9 = 1440 x 0.9 = 1296, which explains the log message.

But the problem is, from the screenshot its total height is obvious larger than the screen. Where could go wrong?

masakitenchi commented 12 months ago

Fixed in https://github.com/skyarkhangel/Hardcore-SK/commit/e457188c1ec6646dc972b9261343b062091058f0