Skip to content

Commit 0efe1c7

Browse files
authored
Merge pull request #174 from ifBars/release/3.1.2
chore(release): bump S1API to 3.1.2
2 parents 5379d40 + 009a534 commit 0efe1c7

3 files changed

Lines changed: 62 additions & 13 deletions

File tree

S1API/PhoneApp/PhoneApp.cs

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
13
using System.IO;
2-
using UnityEngine;
3-
using UnityEngine.UI;
4-
using Object = UnityEngine.Object;
4+
using HarmonyLib;
5+
using MelonLoader;
56
using S1API.Internal.Abstraction;
67
using S1API.Internal.Patches;
78
using S1API.Internal.Utils;
8-
using System;
9-
using MelonLoader;
9+
using UnityEngine;
10+
using UnityEngine.UI;
11+
using Object = UnityEngine.Object;
1012
#if IL2CPPMELON
1113
using Il2CppScheduleOne.UI;
1214
using Il2CppScheduleOne.UI.Phone;
@@ -325,16 +327,14 @@ internal void SpawnIcon(HomeScreen homeScreenInstance)
325327
return;
326328
}
327329

328-
// Find the LAST icon (the one most recently added)
329-
Transform? lastIcon = appIcons.transform.childCount > 0 ? appIcons.transform.GetChild(appIcons.transform.childCount - 1) : null;
330-
if (lastIcon == null)
330+
GameObject? iconObj = CreateAppIcon(homeScreenInstance, appIcons.transform);
331+
if (iconObj == null)
331332
{
332-
Logger.Error("No icons found in AppIcons.");
333+
Logger.Error($"Failed to create an icon for {AppName}.");
333334
return;
334335
}
335336

336-
GameObject iconObj = lastIcon.gameObject;
337-
iconObj.name = AppName; // Rename it now
337+
iconObj.name = AppName;
338338

339339
// Cache icon image for future updates
340340
Transform imageTransform = iconObj.transform.Find("Mask/Image");
@@ -375,6 +375,55 @@ internal void SpawnIcon(HomeScreen homeScreenInstance)
375375
}
376376
}
377377

378+
/// <summary>
379+
/// Creates and registers an independent home-screen icon using the native icon prefab.
380+
/// </summary>
381+
private static GameObject? CreateAppIcon(HomeScreen homeScreenInstance, Transform parent)
382+
{
383+
#if IL2CPPMELON
384+
GameObject? iconPrefab = homeScreenInstance.appIconPrefab;
385+
#else
386+
GameObject? iconPrefab = AccessTools.Field(
387+
typeof(HomeScreen),
388+
"appIconPrefab")?.GetValue(homeScreenInstance) as GameObject;
389+
#endif
390+
if (iconPrefab == null)
391+
{
392+
Logger.Error("HomeScreen appIconPrefab was unavailable.");
393+
return null;
394+
}
395+
396+
GameObject iconObject = Object.Instantiate(iconPrefab, parent);
397+
Button? button = iconObject.GetComponent<Button>();
398+
UISelectable? selectable = iconObject.GetComponent<UISelectable>();
399+
if (button == null || selectable == null)
400+
{
401+
Logger.Error("Native phone app icon prefab is missing Button or UISelectable.");
402+
Object.Destroy(iconObject);
403+
return null;
404+
}
405+
406+
#if IL2CPPMELON
407+
var nativeButtons = homeScreenInstance.appIcons;
408+
var uiPanel = homeScreenInstance.uiPanel;
409+
#else
410+
var appIconsField = AccessTools.Field(typeof(HomeScreen), "appIcons");
411+
var uiPanelField = AccessTools.Field(typeof(HomeScreen), "uiPanel");
412+
var nativeButtons = appIconsField?.GetValue(homeScreenInstance) as List<Button>;
413+
var uiPanel = uiPanelField?.GetValue(homeScreenInstance) as UIPanel;
414+
#endif
415+
if (nativeButtons == null || uiPanel == null)
416+
{
417+
Logger.Error("HomeScreen icon registration fields were unavailable.");
418+
Object.Destroy(iconObject);
419+
return null;
420+
}
421+
422+
nativeButtons.Add(button);
423+
uiPanel.AddSelectable(selectable);
424+
return iconObject;
425+
}
426+
378427
/// <summary>
379428
/// Opens this phone application, managing proper app state transitions.
380429
/// </summary>

S1API/S1API.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
using S1API.Lifecycle;
1212
using S1API.Map;
1313

14-
[assembly: MelonInfo(typeof(S1API.S1API), "S1API (Forked by Bars)", "3.1.1", "KaBooMa")]
14+
[assembly: MelonInfo(typeof(S1API.S1API), "S1API (Forked by Bars)", "3.1.2", "KaBooMa")]
1515
[assembly: MelonPriority(Int32.MinValue)]
1616
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
1717
namespace S1API

S1API/S1API.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<NoWarn>$(NoWarn);1591</NoWarn>
2424
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
2525
<LangVersion>latest</LangVersion>
26-
<Version>3.1.1</Version>
26+
<Version>3.1.2</Version>
2727
</PropertyGroup>
2828

2929
<PropertyGroup Condition="'$(Configuration)' == 'MonoMelon'">

0 commit comments

Comments
 (0)