Christopher
9 years ago
5 changed files with 394 additions and 314 deletions
@ -0,0 +1,125 @@
|
||||
using UnityEngine; |
||||
using MoonSharp.Interpreter; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
/// <summary> |
||||
/// Types of display operations supported by portraits |
||||
/// </summary> |
||||
public enum DisplayType |
||||
{ |
||||
None, |
||||
Show, |
||||
Hide, |
||||
Replace, |
||||
MoveToFront |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Directions that character portraits can face. |
||||
/// </summary> |
||||
public enum FacingDirection |
||||
{ |
||||
None, |
||||
Left, |
||||
Right |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Offset direction for position. |
||||
/// </summary> |
||||
public enum PositionOffset |
||||
{ |
||||
None, |
||||
OffsetLeft, |
||||
OffsetRight |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Controls the Portrait sprites on stage |
||||
/// </summary> |
||||
public interface IPortraitController |
||||
{ |
||||
/// <summary> |
||||
/// Using all portrait options available, run any portrait command. |
||||
/// </summary> |
||||
/// <param name="options">Portrait Options</param> |
||||
/// <param name="onComplete">The function that will run once the portrait command finishes</param> |
||||
void RunPortraitCommand(PortraitOptions options, System.Action onComplete); |
||||
|
||||
/// <summary> |
||||
/// Moves Character in front of other characters on stage |
||||
/// </summary> |
||||
void MoveToFront(Character character); |
||||
|
||||
/// <summary> |
||||
/// Moves Character in front of other characters on stage |
||||
/// </summary> |
||||
void MoveToFront(PortraitOptions options); |
||||
|
||||
/// <summary> |
||||
/// Shows character at a named position in the stage |
||||
/// </summary> |
||||
/// <param name="character"></param> |
||||
/// <param name="position">Named position on stage</param> |
||||
void Show(Character character, string position); |
||||
|
||||
/// <summary> |
||||
/// Shows character moving from a position to a position |
||||
/// </summary> |
||||
/// <param name="character"></param> |
||||
/// <param name="portrait"></param> |
||||
/// <param name="fromPosition">Where the character will appear</param> |
||||
/// <param name="toPosition">Where the character will move to</param> |
||||
void Show(Character character, string portrait, string fromPosition, string toPosition); |
||||
|
||||
/// <summary> |
||||
/// From lua, you can pass an options table with named arguments |
||||
/// example: |
||||
/// stage.show{character=jill, portrait="happy", fromPosition="right", toPosition="left"} |
||||
/// Any option available in the PortraitOptions is available from Lua |
||||
/// </summary> |
||||
/// <param name="optionsTable">Moonsharp Table</param> |
||||
void Show(Table optionsTable); |
||||
|
||||
/// <summary> |
||||
/// Show portrait with the supplied portrait options |
||||
/// </summary> |
||||
/// <param name="options"></param> |
||||
void Show(PortraitOptions options); |
||||
|
||||
/// <summary> |
||||
/// Simple show command that shows the character with an available named portrait |
||||
/// </summary> |
||||
/// <param name="character">Character to show</param> |
||||
/// <param name="portrait">Named portrait to show for the character, i.e. "angry", "happy", etc</param> |
||||
void ShowPortrait(Character character, string portrait); |
||||
|
||||
/// <summary> |
||||
/// Simple character hide command |
||||
/// </summary> |
||||
/// <param name="character">Character to hide</param> |
||||
void Hide(Character character); |
||||
|
||||
/// <summary> |
||||
/// Move the character to a position then hide it |
||||
/// </summary> |
||||
/// <param name="character">Character to hide</param> |
||||
/// <param name="toPosition">Where the character will disapear to</param> |
||||
void Hide(Character character, string toPosition); |
||||
|
||||
/// <summary> |
||||
/// From lua, you can pass an options table with named arguments |
||||
/// example: |
||||
/// stage.hide{character=jill, toPosition="left"} |
||||
/// Any option available in the PortraitOptions is available from Lua |
||||
/// </summary> |
||||
/// <param name="optionsTable">Moonsharp Table</param> |
||||
void Hide(Table optionsTable); |
||||
|
||||
/// <summary> |
||||
/// Hide portrait with provided options |
||||
/// </summary> |
||||
void Hide(PortraitOptions options); |
||||
} |
||||
} |
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 51067f95c67324a0ba05a260dced682f |
||||
timeCreated: 1473685101 |
||||
licenseType: Free |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
@ -0,0 +1,156 @@
|
||||
using UnityEngine; |
||||
using UnityEngine.UI; |
||||
using MoonSharp.Interpreter; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
/// <summary> |
||||
/// Contains all options to run a portrait command. |
||||
/// </summary> |
||||
public class PortraitOptions |
||||
{ |
||||
public Character character; |
||||
public Character replacedCharacter; |
||||
public Sprite portrait; |
||||
public DisplayType display; |
||||
public PositionOffset offset; |
||||
public RectTransform fromPosition; |
||||
public RectTransform toPosition; |
||||
public FacingDirection facing; |
||||
public bool useDefaultSettings; |
||||
public float fadeDuration; |
||||
public float moveDuration; |
||||
public Vector2 shiftOffset; |
||||
public bool move; //sets to position to be the same as from |
||||
public bool shiftIntoPlace; |
||||
public bool waitUntilFinished; |
||||
public System.Action onComplete; |
||||
|
||||
public PortraitOptions(bool useDefaultSettings = true) |
||||
{ |
||||
character = null; |
||||
replacedCharacter = null; |
||||
portrait = null; |
||||
display = DisplayType.None; |
||||
offset = PositionOffset.None; |
||||
fromPosition = null; |
||||
toPosition = null; |
||||
facing = FacingDirection.None; |
||||
shiftOffset = new Vector2(0, 0); |
||||
move = false; |
||||
shiftIntoPlace = false; |
||||
waitUntilFinished = false; |
||||
onComplete = null; |
||||
|
||||
// Special values that can be overridden |
||||
fadeDuration = 0.5f; |
||||
moveDuration = 1f; |
||||
this.useDefaultSettings = useDefaultSettings; |
||||
} |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Represents the current state of a character portrait on the stage. |
||||
/// </summary> |
||||
public class PortraitState |
||||
{ |
||||
public bool onScreen; |
||||
public bool dimmed; |
||||
public DisplayType display; |
||||
public Sprite portrait; |
||||
public RectTransform position; |
||||
public FacingDirection facing; |
||||
public Image portraitImage; |
||||
} |
||||
|
||||
/// <summary> |
||||
/// Util functions for working with portraits. |
||||
/// </summary> |
||||
public static class PortraitUtil |
||||
{ |
||||
/// <summary> |
||||
/// Convert a Moonsharp table to portrait options |
||||
/// If the table returns a null for any of the parameters, it should keep the defaults |
||||
/// </summary> |
||||
/// <param name="table">Moonsharp Table</param> |
||||
/// <param name="stage">Stage</param> |
||||
/// <returns></returns> |
||||
public static PortraitOptions ConvertTableToPortraitOptions(Table table, Stage stage) |
||||
{ |
||||
PortraitOptions options = new PortraitOptions(true); |
||||
|
||||
// If the table supplies a nil, keep the default |
||||
options.character = table.Get("character").ToObject<Character>() |
||||
?? options.character; |
||||
|
||||
options.replacedCharacter = table.Get("replacedCharacter").ToObject<Character>() |
||||
?? options.replacedCharacter; |
||||
|
||||
if (!table.Get("portrait").IsNil()) |
||||
{ |
||||
options.portrait = options.character.GetPortrait(table.Get("portrait").CastToString()); |
||||
} |
||||
|
||||
if (!table.Get("display").IsNil()) |
||||
{ |
||||
options.display = table.Get("display").ToObject<DisplayType>(); |
||||
} |
||||
|
||||
if (!table.Get("offset").IsNil()) |
||||
{ |
||||
options.offset = table.Get("offset").ToObject<PositionOffset>(); |
||||
} |
||||
|
||||
if (!table.Get("fromPosition").IsNil()) |
||||
{ |
||||
options.fromPosition = stage.GetPosition(table.Get("fromPosition").CastToString()); |
||||
} |
||||
|
||||
if (!table.Get("toPosition").IsNil()) |
||||
{ |
||||
options.toPosition = stage.GetPosition(table.Get("toPosition").CastToString()); |
||||
} |
||||
|
||||
if (!table.Get("facing").IsNil()) |
||||
{ |
||||
options.facing = table.Get("facing").ToObject<FacingDirection>(); |
||||
} |
||||
|
||||
if (!table.Get("useDefaultSettings").IsNil()) |
||||
{ |
||||
options.useDefaultSettings = table.Get("useDefaultSettings").CastToBool(); |
||||
} |
||||
|
||||
if (!table.Get("fadeDuration").IsNil()) |
||||
{ |
||||
options.fadeDuration = table.Get("fadeDuration").ToObject<float>(); |
||||
} |
||||
|
||||
if (!table.Get("moveDuration").IsNil()) |
||||
{ |
||||
options.moveDuration = table.Get("moveDuration").ToObject<float>(); |
||||
} |
||||
|
||||
if (!table.Get("move").IsNil()) |
||||
{ |
||||
options.move = table.Get("move").CastToBool(); |
||||
} |
||||
else if (options.fromPosition != options.toPosition) |
||||
{ |
||||
options.move = true; |
||||
} |
||||
|
||||
if (!table.Get("shiftIntoPlace").IsNil()) |
||||
{ |
||||
options.shiftIntoPlace = table.Get("shiftIntoPlace").CastToBool(); |
||||
} |
||||
|
||||
if (!table.Get("waitUntilFinished").IsNil()) |
||||
{ |
||||
options.waitUntilFinished = table.Get("waitUntilFinished").CastToBool(); |
||||
} |
||||
|
||||
return options; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2 |
||||
guid: fb7c101397bef4707a151a471d0acbdf |
||||
timeCreated: 1473686219 |
||||
licenseType: Free |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
||||
assetBundleName: |
||||
assetBundleVariant: |
Loading…
Reference in new issue