// Copyright (c) Pixel Crushers. All rights reserved.
using UnityEngine;
namespace PixelCrushers.DialogueSystem
{
///
/// Controls for UnityUIDialogueUI's alert message.
///
[System.Serializable]
public class UnityUIAlertControls : AbstractUIAlertControls
{
///
/// The panel containing the alert controls. A panel is optional, but you may want one
/// so you can include a background image, panel-wide effects, etc.
///
[Tooltip("Optional panel containing the alert line; can contain other doodads and effects, too")]
public UnityEngine.UI.Graphic panel;
///
/// The label used to show the alert message text.
///
[Tooltip("Shows the alert message text")]
public UnityEngine.UI.Text line;
///
/// Optional continue button to close the alert immediately.
///
[Tooltip("Optional continue button; configure OnClick to invoke dialogue UI's OnContinue method")]
public UnityEngine.UI.Button continueButton;
[Tooltip("Wait for previous alerts to finish before showing new alert; if unticked, new alerts replace old")]
public bool queueAlerts = false;
[Tooltip("Wait for the previous alert's Hide animation to finish before showing the next queued alert")]
public bool waitForHideAnimation = false;
[Tooltip("Optional animation transitions; panel should have an Animator")]
public UIAnimationTransitions animationTransitions = new UIAnimationTransitions();
///
/// Is an alert currently showing?
///
///
/// true if showing; otherwise, false.
///
public override bool isVisible { get { return showHideController.state != UIShowHideController.State.Hidden; } }
public bool IsHiding { get { return showHideController.state == UIShowHideController.State.Hiding; } }
private UIShowHideController m_showHideController = null;
private UIShowHideController showHideController
{
get
{
if (m_showHideController == null) m_showHideController = new UIShowHideController(null, panel, animationTransitions.transitionMode, animationTransitions.debug);
return m_showHideController;
}
}
///
/// Sets the alert controls active. If a hide animation is available, this method
/// depends on the hide animation to hide the controls.
///
///
/// true for active.
///
public override void SetActive(bool value)
{
if (value == true)
{
if (showHideController.state != UIShowHideController.State.Showing) ShowPanel();
}
else
{
if (showHideController.state != UIShowHideController.State.Hiding) HidePanel();
}
}
private void ShowPanel()
{
ActivateUIElements();
animationTransitions.ClearTriggers(showHideController);
showHideController.Show(animationTransitions.showTrigger, false, null);
}
private void HidePanel()
{
animationTransitions.ClearTriggers(showHideController);
showHideController.Hide(animationTransitions.hideTrigger, DeactivateUIElements);
}
public void ActivateUIElements()
{
Tools.SetGameObjectActive(panel, true);
Tools.SetGameObjectActive(line, true);
}
public void DeactivateUIElements()
{
Tools.SetGameObjectActive(panel, false);
Tools.SetGameObjectActive(line, false);
}
///
/// Sets the alert message UI Text.
///
///
/// Alert message.
///
///
/// Duration to show message.
///
public override void SetMessage(string message, float duration)
{
if (line != null) line.text = FormattedText.Parse(message, DialogueManager.masterDatabase.emphasisSettings).text;
}
///
/// Auto-focuses the continue button. Useful for gamepads.
///
public void AutoFocus(bool allowStealFocus = true)
{
UITools.Select(continueButton, allowStealFocus);
}
}
}