Skip to content

Commit

Permalink
we can force pinning/unpinning in the script
Browse files Browse the repository at this point in the history
  • Loading branch information
levimhuillet committed Mar 20, 2024
1 parent 6d03a31 commit d5b435e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Assets/Code/Scripting/Runtime/ScriptPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ public override void OnNodeEnter(ScriptNode inNode, LeafThreadState<ScriptNode>
ip.Hide();
}
m_RuntimeState.DefaultDialogue.MarkNodeEntered();

// reset pin overrides at the start of a new node
m_RuntimeState.DefaultDialogue.ClearPinForces();

ZavalaGame.Events.Dispatch(GameEvents.DialogueStarted, new Zavala.Data.ScriptNodeData(inNode.FullName, !cutscene));
}

Expand Down
27 changes: 27 additions & 0 deletions Assets/Code/Scripting/ScriptRuntimeState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,33 @@ static public void ForcePolicyInstant(AdvisorType type) {
[LeafMember("ForceCloseDialogue")]
static public void ForceCloseDialogue() {
Runtime.DefaultDialogue.HideDialogueUI();
}

/// <summary>
/// Pins ALL following character dialogue if there is a location to pin to
/// </summary>
[LeafMember("ForcePinDialogue")]
static public void ForcePinDialogue()
{
Runtime.DefaultDialogue.ForcePinDialogue();
}

/// <summary>
/// Unpins ALL following character dialogue, even if there is a location to pin to
/// </summary>
[LeafMember("ForceUnpinDialogue")]
static public void ForceUnpinDialogue()
{
Runtime.DefaultDialogue.ForceUnpinDialogue();
}

/// <summary>
/// Restores default pin logic behavior
/// </summary>
[LeafMember("ClearPinForces")]
static public void ClearPinForces()
{
Runtime.DefaultDialogue.ClearPinForces();
}
}
}
31 changes: 27 additions & 4 deletions Assets/Code/UI/DialogueBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public class DialogueBox : MonoBehaviour, ITextDisplayer, IChoiceDisplayer, ISce
[NonSerialized] private bool m_FullyExpanded = false;
[NonSerialized] private bool m_IsActive;
[NonSerialized] public AdvisorType ForceAdvisorPolicies = AdvisorType.None;
[NonSerialized] public bool ForcePin;
[NonSerialized] public bool ForceUnpin;
[NonSerialized] public bool ShowHand = false;
[NonSerialized] public PolicyType CardsToShow;
[NonSerialized] private bool m_PoliciesActive;
Expand All @@ -89,9 +91,15 @@ private void Start() {
m_LocalHandler = new TagStringEventHandler();
m_LocalHandler.Register(LeafUtils.Events.Character, (d, o) => {
LeafEvalContext evalContext = LeafEvalContext.FromObject(o);
if (evalContext.Thread.Actor == null || m_CurrentDef == null || m_CurrentDef.IsAdvisor) {
if (evalContext.Thread.Actor == null || m_CurrentDef == null || ForceUnpin) {
Pin.Unpin();
} else {
} else if (ForcePin) {
Pin.PinTo(((EventActor)evalContext.Thread.Actor).transform);
}
else if (m_CurrentDef.IsAdvisor) {
Pin.Unpin();
}
else {
// only pin if inspector is not showing
if (((EventActor)evalContext.Thread.Actor).DisplayingPopup == null) {
Pin.PinTo(((EventActor)evalContext.Thread.Actor).transform);
Expand Down Expand Up @@ -215,6 +223,23 @@ public void ForceExpandPolicyUI(AdvisorType aType, bool nodeExiting = false) {
CollapsePolicyUI();
}

public void ForcePinDialogue()
{
ForcePin = true;
ForceUnpin = false;
}

public void ForceUnpinDialogue()
{
ForceUnpin = true;
ForcePin = false;
}

public void ClearPinForces()
{
ForcePin = ForceUnpin = false;
}

public void ExpandPolicyUI(AdvisorType advisorType) {
// Load relevant policy slot types according to advisor type
// TODO: room for more flexibility here, such as an adaptive number of slots
Expand Down Expand Up @@ -419,8 +444,6 @@ private void HandlePolicyCloseClicked() {
}

private void HandleAdvisorButtonClicked(AdvisorType advisorType) {
// TODO: should probably just disable advisor buttons when dialogue is showing

// If dialogue has completed when advisor button is clicked, hide this
if (m_FullyExpanded) {
m_TransitionRoutine.Replace(HideRoutine());
Expand Down

0 comments on commit d5b435e

Please sign in to comment.