Skip to content

Commit

Permalink
Simplified button creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Osmodium committed May 11, 2024
1 parent 87f60c9 commit 21fa335
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 73 deletions.
13 changes: 7 additions & 6 deletions SpeechMod/Patches/TutorialWindowView_Patch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ namespace SpeechMod.Patches;
[HarmonyPatch(typeof(TutorialHintWindowPCView), "SetContent")]
public class TutorialWindowView_Patch_Small
{
private const string TUTORIAL_SMALL_TITLE_PATH = "/CommonPCView(Clone)/CommonCanvas/TutorialPCView/SmallWindowpPCView/Window/Content/Header/Title";
private const string TUTORIAL_SMALL_TEXT_PATH = "/CommonPCView(Clone)/CommonCanvas/TutorialPCView/SmallWindowpPCView/Window/Content/Body/ScrollView/Viewport/Content/TutorialText";

private const string TUTORIAL_SMALL_TITLE_PATH = "/CommonPCView(Clone)/CommonCanvas/TutorialPCView/SmallWindowpPCView(Clone)/Window/Content/Header/Title";
private const string TUTORIAL_SMALL_TEXT_PATH = "/CommonPCView(Clone)/CommonCanvas/TutorialPCView/SmallWindowPCView(Clone)/Window/Content/Body/ScrollView/Viewport/Content/TutorialText";

public static void Postfix()
{
if (!Main.Enabled)
return;

#if DEBUG
//Debug.Log($"{nameof(TutorialHintWindowPCView)}_SetContent_Postfix");
Debug.Log($"{nameof(TutorialHintWindowPCView)}_SetContent_Postfix");
#endif

Hooks.HookUpTextToSpeechOnTransformWithPath(TUTORIAL_SMALL_TITLE_PATH);
Expand All @@ -30,16 +31,16 @@ public static void Postfix()
[HarmonyPatch(typeof(TutorialModalWindowPCView), "BindViewImplementation")]
public class TutorialWindowView_Patch_Big
{
private const string TUTORIAL_BIG_TITLE_PATH = "/CommonPCView(Clone)/CommonCanvas/TutorialPCView/BigWindowPCView/Window/Content/Header/TitleGroup/Title";
private const string TUTORIAL_BIG_TEXT_PATH = "/CommonPCView(Clone)/CommonCanvas/TutorialPCView/BigWindowPCView/Window/Content/Body/Bottom/ScrollView/Viewport/Content/TutorialText";
private const string TUTORIAL_BIG_TITLE_PATH = "/CommonPCView(Clone)/CommonCanvas/TutorialPCView/BigWindowPCView(Clone)/Window/Content/Header/TitleGroup/Title";
private const string TUTORIAL_BIG_TEXT_PATH = "/CommonPCView(Clone)/CommonCanvas/TutorialPCView/BigWindowPCView(Clone)/Window/Content/Body/Bottom/ScrollView/Viewport/Content/TutorialText";

public static void Postfix()
{
if (!Main.Enabled)
return;

#if DEBUG
//Debug.Log($"{nameof(TutorialModalWindowPCView)}_BindViewImplementation_Postfix");
Debug.Log($"{nameof(TutorialModalWindowPCView)}_BindViewImplementation_Postfix");
#endif

Hooks.HookUpTextToSpeechOnTransformWithPath(TUTORIAL_BIG_TITLE_PATH);
Expand Down
77 changes: 10 additions & 67 deletions SpeechMod/Unity/ButtonFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,81 +22,24 @@ public static class ButtonFactory

private static GameObject ArrowButton => UIHelper.TryFind(ARROW_BUTTON_PATH)?.gameObject;

private static GameObject s_ArrowButtonPrefab;
private static GameObject s_SpaceUITempArrowButtonPrefab;

private static bool IsArrowButtonAvailable()
private static GameObject CreatePlayButton(Transform parent, UnityAction action, string text, string toolTip)
{
if (s_ArrowButtonPrefab != null)
{
return true;
}

s_ArrowButtonPrefab = GameObject.Find(ARROW_BUTTON_PREFAB_NAME);

if (s_ArrowButtonPrefab != null)
{
return true;
}
GameObject buttonGameObject;

if (ArrowButton != null)
{
SetupArrowPrefab(ArrowButton);
buttonGameObject = Object.Instantiate(ArrowButton, parent);
buttonGameObject!.name = ARROW_BUTTON_PREFAB_NAME;
}

return s_ArrowButtonPrefab != null;
}

private static void LoadArrowButtonPrefabFromResource()
{
Debug.LogWarning("Load surface ui asset...");
// "6dda9b696601b7847996fe3926c42b50" is the GUID of the assets inside the "surfacepcview.res" resource file
var asset = ResourcesLibrary.TryGetResource<GameObject>("6dda9b696601b7847996fe3926c42b50");

var arrow = asset?.transform.TryFind(TEMP_ARROW_BUTTON_PATH)?.gameObject;
if (arrow != null)
else
{
s_SpaceUITempArrowButtonPrefab = Object.Instantiate(arrow);
s_SpaceUITempArrowButtonPrefab!.name = TEMP_ARROW_BUTTON_PREFAB_NAME;
s_SpaceUITempArrowButtonPrefab.transform!.localRotation = Quaternion.Euler(0, 0, 270);
}
}

private static void SetupArrowPrefab(GameObject arrowPrefab)
{
s_ArrowButtonPrefab = Object.Instantiate(arrowPrefab);
s_ArrowButtonPrefab!.name = ARROW_BUTTON_PREFAB_NAME;
s_ArrowButtonPrefab.transform!.localRotation = Quaternion.Euler(0, 0, 270);
Object.DontDestroyOnLoad(s_ArrowButtonPrefab);
}

private static GameObject CreateTemporaryPlayButton(Transform parent)
{
#if DEBUG
Debug.Log("Creating temporary play button...");
#endif
s_SpaceUITempArrowButtonPrefab = GameObject.Find(TEMP_ARROW_BUTTON_PREFAB_NAME);

if (s_SpaceUITempArrowButtonPrefab == null)
{
LoadArrowButtonPrefabFromResource();
}

return Object.Instantiate(s_SpaceUITempArrowButtonPrefab, parent);
}

private static GameObject CreatePlayButton(Transform parent, UnityAction action, string text, string toolTip)
{
if (!IsArrowButtonAvailable())
{
var temporaryPlayButton = CreateTemporaryPlayButton(parent);

SetupOwlcatMultiButton(temporaryPlayButton, action, text, toolTip);

return temporaryPlayButton;
var asset = ResourcesLibrary.TryGetResource<GameObject>("6dda9b696601b7847996fe3926c42b50");
var button = asset?.transform.TryFind(TEMP_ARROW_BUTTON_PATH)?.gameObject;
buttonGameObject = Object.Instantiate(button, parent);
buttonGameObject!.name = TEMP_ARROW_BUTTON_PREFAB_NAME;
}

var buttonGameObject = Object.Instantiate(s_ArrowButtonPrefab, parent);
buttonGameObject.transform!.localRotation = Quaternion.Euler(0, 0, 270);

SetupOwlcatMultiButton(buttonGameObject, action, text, toolTip);

Expand Down
4 changes: 4 additions & 0 deletions Todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ And doesn't work, in general, also does't work with the stop shortcut, as the ke

✅ Add keybind to toggle barks

✅ Fix tutorial
/CommonPCView(Clone)/CommonCanvas/TutorialPCView/SmallWindowPCView(Clone)/Window/Content/Body/ScrollView/Viewport/Content/TutorialText
/CommonPCView(Clone)/CommonCanvas/TutorialPCView/BigWindowPCView(Clone)/Window/Content/Body/Bottom/ScrollView/Viewport/Content/TutorialText

🔲 Look into journal/rumors/contracts
/SurfacePCView(Clone)/SurfaceStaticPartPCView/StaticCanvas/ServiceWindowsPCView/JournalView/Device/ContentGroup/Screen_view/ItemView/JournalQuestPCView/BodyGroup/ContentGroup/ContentGroup/DescriptionItem
/SurfacePCView(Clone)/SurfaceStaticPartPCView/StaticCanvas/ServiceWindowsPCView/JournalView/Device/ContentGroup/Screen_view/ItemView/JournalQuestPCView/HeaderGroup/Title/TitleGroup/Text
Expand Down

0 comments on commit 21fa335

Please sign in to comment.