Skip to content

Commit

Permalink
Fix playback button in dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
Osmodium committed Feb 20, 2024
1 parent 31e96b9 commit e1366ed
Showing 1 changed file with 19 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
using HarmonyLib;
using Kingmaker;
using Kingmaker.Code.UI.MVVM.View.Space.PC;
using Kingmaker.Code.UI.MVVM.View.Surface.PC;
using Kingmaker.Code.UI.MVVM.View.Dialog.Dialog;
using Kingmaker.Code.UI.MVVM.View.Dialog.SurfaceDialog;
using Kingmaker.GameModes;
using SpeechMod.Unity;
using SpeechMod.Unity.Extensions;
using UnityEngine;

namespace SpeechMod.Patches;

[HarmonyPatch]
public static class SurfaceStaticPartPCView_Patch
public static class DialogPCView_Patch
{
private const string SURFACE_SCROLL_VIEW_PATH = "/SurfacePCView(Clone)/SurfaceStaticPartPCView/StaticCanvas/SurfaceDialogPCView/LeftSide/CueAndHistoryPlace/ScrollView";
private const string SPACE_SCROLL_VIEW_PATH = "/SpacePCView(Clone)/SpaceStaticPartPCView/StaticCanvas/SurfaceDialogPCView/LeftSide/CueAndHistoryPlace/ScrollView";
private const string SPEECHMOD_DIALOGBUTTON_NAME = "SpeechMod_DialogButton";
private const string SURFACE_SCROLL_VIEW_PATH = "/SurfacePCView(Clone)/SurfaceStaticPartPCView/StaticCanvas/SurfaceDialogPCView(Clone)/LeftSide/CueAndHistoryPlace/ScrollView";
private const string SPACE_SCROLL_VIEW_PATH = "/SpacePCView(Clone)/SpaceStaticPartPCView/StaticCanvas/SurfaceDialogPCView(Clone)/LeftSide/CueAndHistoryPlace/ScrollView";

[HarmonyPatch(typeof(SurfaceStaticPartPCView), "Initialize")]
[HarmonyPatch(typeof(SurfaceDialogBaseView<DialogAnswerPCView>), "Initialize")]
[HarmonyPostfix]
public static void AddSurfaceDialogButton()
{
Expand All @@ -23,25 +25,10 @@ public static void AddSurfaceDialogButton()

#if DEBUG
var sceneName = Game.Instance!.CurrentlyLoadedArea!.ActiveUIScene!.SceneName;
Debug.Log($"{nameof(SurfaceStaticPartPCView)}_Initialize_Postfix @ {sceneName}");
Debug.Log($"{nameof(SurfaceDialogBaseView<DialogAnswerPCView>)}_Initialize_Postfix @ {sceneName}");
#endif

AddDialogSpeechButton(SURFACE_SCROLL_VIEW_PATH);
}

[HarmonyPatch(typeof(SpaceStaticPartPCView), "Initialize")]
[HarmonyPostfix]
public static void AddSpaceDialogButton()
{
if (!Main.Enabled)
return;

#if DEBUG
var sceneName = Game.Instance!.CurrentlyLoadedArea!.ActiveUIScene!.SceneName;
Debug.Log($"{nameof(SpaceStaticPartPCView)}_Initialize_Postfix @ {sceneName}");
#endif

AddDialogSpeechButton(SPACE_SCROLL_VIEW_PATH);
AddDialogSpeechButton(Game.Instance!.IsModeActive(GameModeType.StarSystem) ? SPACE_SCROLL_VIEW_PATH : SURFACE_SCROLL_VIEW_PATH);
}

private static void AddDialogSpeechButton(string path)
Expand All @@ -59,17 +46,24 @@ private static void AddDialogSpeechButton(string path)
return;
}


if (parent.TryFind(SPEECHMOD_DIALOGBUTTON_NAME) != null)
{
Debug.LogWarning("Button already exists!");
return;
}

var buttonGameObject = ButtonFactory.TryCreatePlayButton(parent, () =>
{
Main.Speech.SpeakDialog(Game.Instance?.DialogController?.CurrentCue?.DisplayText);
Main.Speech?.SpeakDialog(Game.Instance?.DialogController?.CurrentCue?.DisplayText);
});

if (buttonGameObject == null)
{
return;
}

buttonGameObject.name = "SpeechMod_DialogButton";
buttonGameObject.name = SPEECHMOD_DIALOGBUTTON_NAME;
buttonGameObject.RectAlignTopLeft(new Vector2(40, 10));
buttonGameObject.transform.localRotation = Quaternion.Euler(0, 0, 270);

Expand Down

0 comments on commit e1366ed

Please sign in to comment.