You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
216 lines
7.7 KiB
216 lines
7.7 KiB
8 years ago
|
// This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus).
|
||
|
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
|
||
9 years ago
|
|
||
10 years ago
|
using UnityEngine;
|
||
|
|
||
|
namespace Fungus
|
||
|
{
|
||
8 years ago
|
/// <summary>
|
||
|
/// Controls a character portrait.
|
||
|
/// </summary>
|
||
8 years ago
|
[CommandInfo("Narrative",
|
||
|
"Portrait",
|
||
8 years ago
|
"Controls a character portrait.")]
|
||
8 years ago
|
public class Portrait : ControlWithDisplay<DisplayType>
|
||
|
{
|
||
|
[Tooltip("Stage to display portrait on")]
|
||
8 years ago
|
[SerializeField] protected Stage stage;
|
||
8 years ago
|
public virtual Stage _Stage { get { return stage; } set { stage = value; } }
|
||
8 years ago
|
|
||
8 years ago
|
[Tooltip("Character to display")]
|
||
8 years ago
|
[SerializeField] protected Character character;
|
||
8 years ago
|
public virtual Character _Character { get { return character; } set { character = value; } }
|
||
8 years ago
|
|
||
8 years ago
|
[Tooltip("Character to swap with")]
|
||
8 years ago
|
[SerializeField] protected Character replacedCharacter;
|
||
8 years ago
|
|
||
|
[Tooltip("Portrait to display")]
|
||
8 years ago
|
[SerializeField] protected Sprite portrait;
|
||
8 years ago
|
public virtual Sprite _Portrait { get { return portrait; } set { portrait = value; } }
|
||
8 years ago
|
|
||
8 years ago
|
[Tooltip("Move the portrait from/to this offset position")]
|
||
8 years ago
|
[SerializeField] protected PositionOffset offset;
|
||
8 years ago
|
public virtual PositionOffset Offset { get { return offset; } set { offset = value; } }
|
||
8 years ago
|
|
||
8 years ago
|
[Tooltip("Move the portrait from this position")]
|
||
8 years ago
|
[SerializeField] protected RectTransform fromPosition;
|
||
8 years ago
|
public virtual RectTransform FromPosition { get { return fromPosition; } set { fromPosition = value;} }
|
||
8 years ago
|
|
||
|
[Tooltip("Move the portrait to this positoin")]
|
||
8 years ago
|
[SerializeField] protected RectTransform toPosition;
|
||
8 years ago
|
public virtual RectTransform ToPosition { get { return toPosition; } set { toPosition = value;} }
|
||
8 years ago
|
|
||
|
[Tooltip("Direction character is facing")]
|
||
8 years ago
|
[SerializeField] protected FacingDirection facing;
|
||
8 years ago
|
public virtual FacingDirection Facing { get { return facing; } set { facing = value; } }
|
||
8 years ago
|
|
||
8 years ago
|
[Tooltip("Use Default Settings")]
|
||
8 years ago
|
[SerializeField] protected bool useDefaultSettings = true;
|
||
8 years ago
|
public virtual bool UseDefaultSettings { get { return useDefaultSettings; } set { useDefaultSettings = value; } }
|
||
8 years ago
|
|
||
8 years ago
|
[Tooltip("Fade Duration")]
|
||
8 years ago
|
[SerializeField] protected float fadeDuration = 0.5f;
|
||
8 years ago
|
|
||
|
[Tooltip("Movement Duration")]
|
||
8 years ago
|
[SerializeField] protected float moveDuration = 1f;
|
||
8 years ago
|
|
||
|
[Tooltip("Shift Offset")]
|
||
8 years ago
|
[SerializeField] protected Vector2 shiftOffset;
|
||
8 years ago
|
|
||
|
[Tooltip("Move")]
|
||
8 years ago
|
[SerializeField] protected bool move;
|
||
8 years ago
|
public virtual bool Move { get { return move; } set { move = value; } }
|
||
8 years ago
|
|
||
8 years ago
|
[Tooltip("Start from offset")]
|
||
8 years ago
|
[SerializeField] protected bool shiftIntoPlace;
|
||
8 years ago
|
public virtual bool ShiftIntoPlace { get { return shiftIntoPlace; } set { shiftIntoPlace = value; } }
|
||
8 years ago
|
|
||
8 years ago
|
[Tooltip("Wait until the tween has finished before executing the next command")]
|
||
8 years ago
|
[SerializeField] protected bool waitUntilFinished = false;
|
||
8 years ago
|
|
||
|
public override void OnEnter()
|
||
|
{
|
||
|
// Selected "use default Portrait Stage"
|
||
|
if (stage == null)
|
||
|
{
|
||
|
// If no default specified, try to get any portrait stage in the scene
|
||
|
stage = FindObjectOfType<Stage>();
|
||
|
// If portrait stage does not exist, do nothing
|
||
|
if (stage == null)
|
||
|
{
|
||
|
Continue();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
// If no display specified, do nothing
|
||
|
if (IsDisplayNone(display))
|
||
|
{
|
||
|
Continue();
|
||
|
return;
|
||
|
}
|
||
|
|
||
|
PortraitOptions options = new PortraitOptions();
|
||
|
|
||
|
options.character = character;
|
||
|
options.replacedCharacter = replacedCharacter;
|
||
|
options.portrait = portrait;
|
||
|
options.display = display;
|
||
|
options.offset = offset;
|
||
|
options.fromPosition = fromPosition;
|
||
|
options.toPosition = toPosition;
|
||
|
options.facing = facing;
|
||
|
options.useDefaultSettings = useDefaultSettings;
|
||
|
options.fadeDuration = fadeDuration;
|
||
|
options.moveDuration = moveDuration;
|
||
|
options.shiftOffset = shiftOffset;
|
||
|
options.move = move;
|
||
|
options.shiftIntoPlace = shiftIntoPlace;
|
||
|
options.waitUntilFinished = waitUntilFinished;
|
||
|
|
||
|
stage.RunPortraitCommand(options, Continue);
|
||
|
|
||
|
}
|
||
|
|
||
|
public override string GetSummary()
|
||
|
{
|
||
|
if (display == DisplayType.None && character == null)
|
||
|
{
|
||
|
return "Error: No character or display selected";
|
||
|
}
|
||
|
else if (display == DisplayType.None)
|
||
|
{
|
||
|
return "Error: No display selected";
|
||
|
}
|
||
|
else if (character == null)
|
||
|
{
|
||
|
return "Error: No character selected";
|
||
|
}
|
||
|
|
||
|
string displaySummary = "";
|
||
|
string characterSummary = "";
|
||
|
string fromPositionSummary = "";
|
||
|
string toPositionSummary = "";
|
||
|
string stageSummary = "";
|
||
|
string portraitSummary = "";
|
||
|
string facingSummary = "";
|
||
|
|
||
|
displaySummary = StringFormatter.SplitCamelCase(display.ToString());
|
||
|
|
||
|
if (display == DisplayType.Replace)
|
||
|
{
|
||
|
if (replacedCharacter != null)
|
||
|
{
|
||
|
displaySummary += " \"" + replacedCharacter.name + "\" with";
|
||
|
}
|
||
|
}
|
||
|
|
||
|
characterSummary = character.name;
|
||
|
if (stage != null)
|
||
|
{
|
||
|
stageSummary = " on \"" + stage.name + "\"";
|
||
|
}
|
||
|
|
||
|
if (portrait != null)
|
||
|
{
|
||
|
portraitSummary = " " + portrait.name;
|
||
|
}
|
||
|
|
||
|
if (shiftIntoPlace)
|
||
|
{
|
||
|
if (offset != 0)
|
||
|
{
|
||
|
fromPositionSummary = offset.ToString();
|
||
|
fromPositionSummary = " from " + "\"" + fromPositionSummary + "\"";
|
||
|
}
|
||
|
}
|
||
|
else if (fromPosition != null)
|
||
|
{
|
||
|
fromPositionSummary = " from " + "\"" + fromPosition.name + "\"";
|
||
|
}
|
||
|
|
||
|
if (toPosition != null)
|
||
|
{
|
||
|
string toPositionPrefixSummary = "";
|
||
|
if (move)
|
||
|
{
|
||
|
toPositionPrefixSummary = " to ";
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
toPositionPrefixSummary = " at ";
|
||
|
}
|
||
|
|
||
|
toPositionSummary = toPositionPrefixSummary + "\"" + toPosition.name + "\"";
|
||
|
}
|
||
|
|
||
|
if (facing != FacingDirection.None)
|
||
|
{
|
||
|
if (facing == FacingDirection.Left)
|
||
|
{
|
||
|
facingSummary = "<--";
|
||
|
}
|
||
|
if (facing == FacingDirection.Right)
|
||
|
{
|
||
|
facingSummary = "-->";
|
||
|
}
|
||
|
|
||
|
facingSummary = " facing \"" + facingSummary + "\"";
|
||
|
}
|
||
|
|
||
|
return displaySummary + " \"" + characterSummary + portraitSummary + "\"" + stageSummary + facingSummary + fromPositionSummary + toPositionSummary;
|
||
|
}
|
||
|
|
||
|
public override Color GetButtonColor()
|
||
|
{
|
||
|
return new Color32(230, 200, 250, 255);
|
||
|
}
|
||
|
|
||
|
public override void OnCommandAdded(Block parentBlock)
|
||
|
{
|
||
|
//Default to display type: show
|
||
|
display = DisplayType.Show;
|
||
|
}
|
||
|
}
|
||
10 years ago
|
}
|