diff --git a/S1API/Internal/Patches/PhoneAppPatches.cs b/S1API/Internal/Patches/PhoneAppPatches.cs index 0f73aeb2..30804bfb 100644 --- a/S1API/Internal/Patches/PhoneAppPatches.cs +++ b/S1API/Internal/Patches/PhoneAppPatches.cs @@ -26,11 +26,11 @@ internal static class PhoneAppPatches /// The loading mode used by the SceneManager. static void Postfix(Scene scene, LoadSceneMode mode) { - if (_loaded || scene.name != "Main") return; - _loaded = true; + if (scene.name != "Main") return; - var phoneApps = ReflectionUtils.GetDerivedClasses(); - foreach (var type in phoneApps) + // Re-register all PhoneApps every time the Main scene loads + var phoneApp = ReflectionUtils.GetDerivedClasses(); + foreach (var type in phoneApp) { if (type.GetConstructor(Type.EmptyTypes) == null) continue; diff --git a/S1API/PhoneApp/PhoneApp.cs b/S1API/PhoneApp/PhoneApp.cs index 388a345d..44385db8 100644 --- a/S1API/PhoneApp/PhoneApp.cs +++ b/S1API/PhoneApp/PhoneApp.cs @@ -148,7 +148,7 @@ private IEnumerator InitApp() AppCreated = true; } - AppPanel.SetActive(false); + AppPanel.SetActive(true); if (!IconModified) { diff --git a/S1API/UI/UIFactory.cs b/S1API/UI/UIFactory.cs index 4faac1ba..894b5652 100644 --- a/S1API/UI/UIFactory.cs +++ b/S1API/UI/UIFactory.cs @@ -7,17 +7,19 @@ using UnityEngine.UI; #endif +using System; using UnityEngine.Events; using System.Collections.Generic; namespace S1API.UI { /// - /// Utility class for creating and managing UI elements in Unity projects. + /// Static utility class for dynamically generating and managing UI elements within Unity applications. /// /// - /// Provides static methods to dynamically generate UI components such as panels, buttons, text blocks, and layouts. - /// Includes utilities for configuring and organizing UI elements in a hierarchy. + /// Contains methods for creating reusable and customizable UI components, such as panels, buttons, text elements, layouts, + /// and more. Designed to facilitate rapid development and organization of UI hierarchies, with options + /// for styling and behavior configuration. /// public static class UIFactory { @@ -28,8 +30,9 @@ public static class UIFactory /// The minimum anchor point of the RectTransform. Defaults to (0.5, 0.5) if not specified. /// The maximum anchor point of the RectTransform. Defaults to (0.5, 0.5) if not specified. /// Whether to stretch the panel across the entire parent RectTransform. Overrides anchorMin and anchorMax if true. - /// The created GameObject representing the panel. - public static GameObject Panel(string name, Transform parent, Color bgColor, Vector2? anchorMin = null, Vector2? anchorMax = null, bool fullAnchor = false) + /// The GameObject representing the created UI panel. + public static GameObject Panel(string name, Transform parent, Color bgColor, Vector2? anchorMin = null, + Vector2? anchorMax = null, bool fullAnchor = false) { GameObject go = new GameObject(name); go.transform.SetParent(parent, false); @@ -61,7 +64,8 @@ public static GameObject Panel(string name, Transform parent, Color bgColor, Vec /// The alignment of the text within its RectTransform. Defaults to `TextAnchor.UpperLeft`. /// The font style of the text. Defaults to `FontStyle.Normal`. /// The created Text component with the specified properties applied. - public static Text Text(string name, string content, Transform parent, int fontSize = 14, TextAnchor anchor = TextAnchor.UpperLeft, FontStyle style = FontStyle.Normal) + public static Text Text(string name, string content, Transform parent, int fontSize = 14, + TextAnchor anchor = TextAnchor.UpperLeft, FontStyle style = FontStyle.Normal) { GameObject go = new GameObject(name); go.transform.SetParent(parent, false); @@ -79,15 +83,11 @@ public static Text Text(string name, string content, Transform parent, int fontS return txt; } - /// Creates a scrollable vertical list UI component with its child hierarchy configured for Unity UI. - /// The created hierarchy includes: - /// - A parent GameObject containing a ScrollRect component. - /// - A child "Viewport" GameObject for clipping and masking. - /// - A "Content" GameObject inside the viewport with a vertical layout and content size fitter. + /// Creates a scrollable vertical list UI component with a configured child hierarchy, allowing vertical scrolling of dynamically added items. /// The name of the scrollable list GameObject. /// The parent transform where the scrollable list will be added. /// Outputs the ScrollRect component associated with the created scrollable list. - /// Returns the RectTransform of the "Content" GameObject, which items can be added to. + /// Returns the RectTransform of the "Content" GameObject, allowing items to be added to the scrollable list. public static RectTransform ScrollableVerticalList(string name, Transform parent, out ScrollRect scrollRect) { var scrollGO = new GameObject(name); @@ -143,18 +143,21 @@ public static void FitContentHeight(RectTransform content) fitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize; } - /// Creates a button with a label inside a parent UI element. + /// Creates a button with a label and specified dimensions inside a parent UI element. /// The name of the button GameObject. /// The text to display on the button. /// The Transform to which the button will be attached. /// The background color of the button. + /// The width of the button. + /// The height of the button. /// A tuple containing the button's GameObject, Button component, and Text component. - public static (GameObject, Button, Text) ButtonWithLabel(string name, string label, Transform parent, Color bgColor) + public static (GameObject, Button, Text) ButtonWithLabel(string name, string label, Transform parent, + Color bgColor, float Width, float Height) { GameObject go = new GameObject(name); go.transform.SetParent(parent, false); var rt = go.AddComponent(); - rt.sizeDelta = new Vector2(160f, 40f); + rt.sizeDelta = new Vector2(Height, Width); var img = go.AddComponent(); img.color = bgColor; @@ -186,8 +189,8 @@ public static (GameObject, Button, Text) ButtonWithLabel(string name, string lab /// /// Sets an icon as a child of the specified parent transform with the given sprite. /// - /// The sprite to use for the icon. - /// The transform to set as the parent of the icon. + /// The sprite to be used as the icon. + /// The transform that will act as the parent of the icon. public static void SetIcon(Sprite sprite, Transform parent) { var icon = new GameObject("Icon"); @@ -208,24 +211,20 @@ public static void SetIcon(Sprite sprite, Transform parent) /// The parent transform where the text block will be added. /// The title text of the text block, displayed in bold. /// The subtitle text of the text block, displayed below the title. - /// - /// A boolean indicating whether the text block represents a completed state. - /// If true, an additional label indicating "Already Delivered" will be added. - /// + /// A boolean indicating whether the text block represents a completed state. If true, an additional label indicating "Already Delivered" will be added. public static void CreateTextBlock(Transform parent, string title, string subtitle, bool isCompleted) { Text(parent.name + "Title", title, parent, 16, TextAnchor.MiddleLeft, FontStyle.Bold); Text(parent.name + "Subtitle", subtitle, parent, 14, TextAnchor.UpperLeft); if (isCompleted) - Text("CompletedLabel", "Already Delivered", parent, 12, TextAnchor.UpperLeft); + Text("CompletedLabel", "Already Delivered", parent, 12, + TextAnchor.UpperLeft); } - /// - /// Adds a clickable button component to the specified game object and sets its interactions and event handling. - /// + /// Adds a button component to the specified game object, sets its target graphic, and configures its interaction settings. /// The game object to which the button component is added. /// The UnityAction to invoke when the button is clicked. - /// A boolean value indicating whether the button should be interactable. + /// Determines whether the button is interactable. public static void CreateRowButton(GameObject go, UnityAction clickHandler, bool enabled) { var btn = go.AddComponent