Exemple #1
0
        /// <summary>
        /// Shows character at a named position in the stage
        /// </summary>
        /// <param name="character"></param>
        /// <param name="position">Named position on stage</param>
        public virtual void Show(Character character, string position)
        {
            PortraitOptions options = new PortraitOptions(true);

            options.character    = character;
            options.fromPosition = options.toPosition = stage.GetPosition(position);

            Show(options);
        }
Exemple #2
0
        /// <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())
            {
                var      facingDirection = FacingDirection.None;
                DynValue v = table.Get("facing");
                if (v.Type == DataType.String)
                {
                    if (string.Compare(v.String, "left", true) == 0)
                    {
                        facingDirection = FacingDirection.Left;
                    }
                    else if (string.Compare(v.String, "right", true) == 0)
                    {
                        facingDirection = FacingDirection.Right;
                    }
                }
                else
                {
                    facingDirection = table.Get("facing").ToObject <FacingDirection>();
                }

                options.facing = 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);
        }
Exemple #3
0
        /// <summary>
        /// Using the string of say parameters before the ':',
        /// set the current character, position and portrait if provided.
        /// </summary>
        /// <returns>The conversation item.</returns>
        /// <param name="sayParams">The list of say parameters.</param>
        /// <param name="text">The text for the character to say.</param>
        /// <param name="currentCharacter">The currently speaking character.</param>
        protected virtual ConversationItem CreateConversationItem(string[] sayParams, string text, Character currentCharacter)
        {
            var item = new ConversationItem();

            // Populate the story text to be written
            item.Text = text;

            if (sayParams == null || sayParams.Length == 0)
            {
                // Text only, no params - early out.
                return(item);
            }

            // try to find the character param first, since we need to get its portrait
            int characterIndex = -1;

            if (characters == null)
            {
                PopulateCharacterCache();
            }

            for (int i = 0; item.Character == null && i < sayParams.Length; i++)
            {
                for (int j = 0; j < characters.Length; j++)
                {
                    if (characters[j].NameStartsWith(sayParams[i]))
                    {
                        characterIndex = i;
                        item.Character = characters[j];
                        break;
                    }
                }
            }

            // Assume last used character if none is specified now
            if (item.Character == null)
            {
                item.Character = currentCharacter;
            }

            // Check if there's a Hide parameter
            int hideIndex = -1;

            if (item.Character != null)
            {
                for (int i = 0; i < sayParams.Length; i++)
                {
                    if (i != characterIndex &&
                        string.Compare(sayParams[i], "hide", true) == 0)
                    {
                        hideIndex = i;
                        item.Hide = true;
                        break;
                    }
                }
            }

            int flipIndex = -1;

            if (item.Character != null)
            {
                for (int i = 0; i < sayParams.Length; i++)
                {
                    if (i != characterIndex &&
                        i != hideIndex &&
                        (string.Compare(sayParams[i], ">>>", true) == 0 ||
                         string.Compare(sayParams[i], "<<<", true) == 0))
                    {
                        if (string.Compare(sayParams[i], ">>>", true) == 0)
                        {
                            item.FacingDirection = FacingDirection.Right;
                        }
                        if (string.Compare(sayParams[i], "<<<", true) == 0)
                        {
                            item.FacingDirection = FacingDirection.Left;
                        }
                        flipIndex = i;
                        item.Flip = true;
                        break;
                    }
                }
            }

            // Next see if we can find a portrait for this character
            int portraitIndex = -1;

            if (item.Character != null)
            {
                for (int i = 0; i < sayParams.Length; i++)
                {
                    if (item.Portrait == null &&
                        item.Character != null &&
                        i != characterIndex &&
                        i != hideIndex &&
                        i != flipIndex)
                    {
                        Sprite s = item.Character.GetPortrait(sayParams[i]);
                        if (s != null)
                        {
                            portraitIndex = i;
                            item.Portrait = s;
                            break;
                        }
                    }
                }
            }

            // Next check if there's a position parameter
            Stage stage = Stage.GetActiveStage();

            if (stage != null)
            {
                for (int i = 0; i < sayParams.Length; i++)
                {
                    if (i != characterIndex &&
                        i != portraitIndex &&
                        i != hideIndex)
                    {
                        RectTransform r = stage.GetPosition(sayParams[i]);
                        if (r != null)
                        {
                            item.Position = r;
                            break;
                        }
                    }
                }
            }

            return(item);
        }
        /// <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();
            }

            //TODO: Make the next lua command wait when this options is true
            if (!table.Get("waitUntilFinished").IsNil())
            {
                options.waitUntilFinished = table.Get("waitUntilFinished").CastToBool();
            }

            return(options);
        }
        /// <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();
            }

            //TODO: Make the next lua command wait when this options is true
            if (!table.Get("waitUntilFinished").IsNil())
            {
                options.waitUntilFinished = table.Get("waitUntilFinished").CastToBool();
            }

            return options;
        }
Exemple #6
0
        /// <summary>
        /// Using the string of say parameters before the ':',
        /// set the current character, position and portrait if provided.
        /// </summary>
        /// <returns>The conversation item.</returns>
        /// <param name="sayParams">The list of say parameters.</param>
        /// <param name="text">The text for the character to say.</param>
        /// <param name="currentCharacter">The currently speaking character.</param>
        protected virtual ConversationItem CreateConversationItem(string[] sayParams, string text, Character currentCharacter)
        {
            var item = new ConversationItem();

            item.ClearPrev    = ClearPrev;
            item.FadeDone     = FadeDone;
            item.WaitForInput = WaitForInput;

            // Populate the story text to be written
            item.Text = text;

            if (WaitForSeconds > 0)
            {
                item.Text += "{w=" + WaitForSeconds.ToString() + "}";
            }

            if (sayParams == null || sayParams.Length == 0)
            {
                // Text only, no params - early out.
                return(item);
            }

            //TODO this needs a refactor
            for (int i = 0; i < sayParams.Length; i++)
            {
                if (string.Compare(sayParams[i], "clear", true) == 0)
                {
                    item.ClearPrev = true;
                }
                else if (string.Compare(sayParams[i], "noclear", true) == 0)
                {
                    item.ClearPrev = false;
                }
                else if (string.Compare(sayParams[i], "fade", true) == 0)
                {
                    item.FadeDone = true;
                }
                else if (string.Compare(sayParams[i], "nofade", true) == 0)
                {
                    item.FadeDone = false;
                }
                else if (string.Compare(sayParams[i], "wait", true) == 0)
                {
                    item.WaitForInput = true;
                }
                else if (string.Compare(sayParams[i], "nowait", true) == 0)
                {
                    item.WaitForInput = false;
                }
            }

            // try to find the character param first, since we need to get its portrait
            int       characterIndex             = -1;
            int       characterParamIndexPartial = characterIndex;
            Character partialCharacter           = null;

            if (characters == null)
            {
                PopulateCharacterCache();
            }

            for (int i = 0; item.Character == null && i < sayParams.Length; i++)
            {
                for (int j = 0; j < characters.Length; j++)
                {
                    if (characters[j].NameMatch(sayParams[i]))
                    {
                        characterIndex = i;
                        item.Character = characters[j];
                        break;
                    }
                    else if (characters[j].NameStartsWith(sayParams[i]))
                    {
                        characterParamIndexPartial = i;
                        partialCharacter           = characters[j];
                    }
                }
            }

            //if still no charcter was found but we found a partial we use it for backcompat but warn user
            if (item.Character == null && partialCharacter != null)
            {
                Debug.LogWarning("Conversation Manager Character Partial Match; found '" + sayParams[characterParamIndexPartial] +
                                 "' and will use " + partialCharacter.NameText + "\n Recommend modifying conversation and characters so they match exactly.");

                characterIndex = characterParamIndexPartial;
                item.Character = partialCharacter;
            }

            // Assume last used character if none is specified now
            if (item.Character == null)
            {
                item.Character = currentCharacter;
            }

            // Check if there's a Hide parameter
            int hideIndex = -1;

            if (item.Character != null)
            {
                for (int i = 0; i < sayParams.Length; i++)
                {
                    if (i != characterIndex &&
                        string.Compare(sayParams[i], "hide", true) == 0)
                    {
                        hideIndex = i;
                        item.Hide = true;
                        break;
                    }
                }
            }

            int flipIndex = -1;

            if (item.Character != null)
            {
                for (int i = 0; i < sayParams.Length; i++)
                {
                    if (i != characterIndex &&
                        i != hideIndex &&
                        (string.Compare(sayParams[i], ">>>", true) == 0 ||
                         string.Compare(sayParams[i], "<<<", true) == 0))
                    {
                        if (string.Compare(sayParams[i], ">>>", true) == 0)
                        {
                            item.FacingDirection = FacingDirection.Right;
                        }
                        if (string.Compare(sayParams[i], "<<<", true) == 0)
                        {
                            item.FacingDirection = FacingDirection.Left;
                        }
                        flipIndex = i;
                        item.Flip = true;
                        break;
                    }
                }
            }

            // Next see if we can find a portrait for this character
            int portraitIndex = -1;

            if (item.Character != null)
            {
                for (int i = 0; i < sayParams.Length; i++)
                {
                    if (item.Portrait == null &&
                        item.Character != null &&
                        i != characterIndex &&
                        i != hideIndex &&
                        i != flipIndex)
                    {
                        Sprite s = item.Character.GetPortrait(sayParams[i]);
                        if (s != null)
                        {
                            portraitIndex = i;
                            item.Portrait = s;
                            break;
                        }
                    }
                }
            }

            // Next check if there's a position parameter
            Stage stage = Stage.GetActiveStage();

            if (stage != null)
            {
                for (int i = 0; i < sayParams.Length; i++)
                {
                    if (i != characterIndex &&
                        i != portraitIndex &&
                        i != hideIndex)
                    {
                        RectTransform r = stage.GetPosition(sayParams[i]);
                        if (r != null)
                        {
                            item.Position = r;
                            break;
                        }
                    }
                }
            }

            return(item);
        }
Exemple #7
0
        /// <summary>
        /// Using the string of say parameters before the ':',
        /// set the current character, position and portrait if provided.
        /// </summary>
        /// <returns>The conversation item.</returns>
        /// <param name="sayParams">The list of say parameters.</param>
        /// <param name="text">The text for the character to say.</param>
        /// <param name="currentCharacter">The currently speaking character.</param>
        protected virtual ConversationItem CreateConversationItem(string[] sayParams, string text, Character currentCharacter, string[] links)
        {
            var item = new ConversationItem();

            // Populate the story text to be written
            item.Text = text;
            item.ClearPreviousLine = true;

            if (links != null)
            {
                string[]      linkSplit;
                List <string> responseList = new List <string>();
                List <string> linkList     = new List <string>();
                for (int i = 0; i < links.Length; i++)
                {
                    linkSplit = links[i].Split('=');
                    if (!string.IsNullOrEmpty(linkSplit[0]) || !string.IsNullOrEmpty(linkSplit[1]))
                    {
                        linkList.Add(linkSplit[0]);
                        responseList.Add(linkSplit[1]);
                    }
                }
                if (linkList.Count > 0)
                {
                    item.ResponseLinks = linkList.ToArray();
                    item.ResponseTexts = responseList.ToArray();
                }
            }

            if (sayParams == null || sayParams.Length == 0)
            {
                // Text only, no params - early out.
                return(item);
            }

            // try to find the character param first, since we need to get its portrait
            int characterIndex = -1;

            for (int i = 0; item.Character == null && i < sayParams.Length; i++)
            {
                Character c = GetCharacter(sayParams[i]);
                if (c != null)
                {
                    characterIndex = i;
                    item.Character = c;
                    break;
                }
            }

            // Assume last used character if none is specified now
            if (item.Character == null)
            {
                item.Character = currentCharacter;
            }

            for (int i = 0; i < sayParams.Length; i++)
            {
                if (sayParams[i].Contains("="))
                {
                    item.Condition = sayParams[i];
                }
                if (sayParams[i] == "kill")
                {
                    item.Kill = true;
                }
                if (sayParams[i] == "invite")
                {
                    item.Invite = true;
                }
                if (sayParams[i] == "playerkill")
                {
                    item.PlayerKill = true;
                }
                if (sayParams[i] == "guest")
                {
                    item.Guest = true;
                }
            }

            // Check if there's a Hide parameter
            int hideIndex = -1;

            if (item.Character != null)
            {
                for (int i = 0; i < sayParams.Length; i++)
                {
                    if (i != characterIndex &&
                        string.Compare(sayParams[i], "hide", true) == 0)
                    {
                        hideIndex = i;
                        item.Hide = true;
                        break;
                    }
                }
            }

            int flipIndex = -1;

            if (item.Character != null)
            {
                for (int i = 0; i < sayParams.Length; i++)
                {
                    if (i != characterIndex &&
                        i != hideIndex &&
                        (string.Compare(sayParams[i], ">>>", true) == 0 ||
                         string.Compare(sayParams[i], "<<<", true) == 0))
                    {
                        if (string.Compare(sayParams[i], ">>>", true) == 0)
                        {
                            item.FacingDirection = FacingDirection.Right;
                        }
                        if (string.Compare(sayParams[i], "<<<", true) == 0)
                        {
                            item.FacingDirection = FacingDirection.Left;
                        }
                        flipIndex = i;
                        item.Flip = true;
                        break;
                    }
                }
            }

            // Next see if we can find a portrait for this character
            int portraitIndex = -1;

            if (item.Character != null)
            {
                for (int i = 0; i < sayParams.Length; i++)
                {
                    if (item.Portrait == null &&
                        item.Character != null &&
                        i != characterIndex &&
                        i != hideIndex &&
                        i != flipIndex)
                    {
                        Character.PortraitData p = item.Character.GetPortrait(sayParams[i]);
                        if (p != null)
                        {
                            portraitIndex = i;
                            item.Portrait = p;
                            break;
                        }
                    }
                }
            }

            // Next check if there's a position parameter
            int   pos1Index = -1;
            int   pos2Index = -1;
            Stage stage     = Stage.GetActiveStage();

            if (stage != null)
            {
                for (int i = 0; i < sayParams.Length; i++)
                {
                    if (i != characterIndex &&
                        i != portraitIndex &&
                        i != flipIndex &&
                        i != hideIndex)
                    {
                        RectTransform r = stage.GetPosition(sayParams[i]);
                        if (r != null)
                        {
                            if (pos1Index == -1)
                            {
                                pos1Index       = i;
                                item.ToPosition = r;
                            }
                            else
                            {
                                pos2Index         = i;
                                item.FromPosition = item.ToPosition;
                                item.ToPosition   = r;
                                break;
                            }
                        }
                    }
                }
            }

            //check if we should clear or not
            for (int i = 0; i < sayParams.Length; i++)
            {
                if (i != characterIndex &&
                    i != portraitIndex &&
                    i != hideIndex &&
                    i != flipIndex &&
                    i != pos1Index &&
                    i != pos2Index)
                {
                    if (string.Compare(sayParams[i], "noclear", true) == 0)
                    {
                        item.ClearPreviousLine = false;
                    }
                }
            }

            return(item);
        }
        /// <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())
            {
                var facingDirection = FacingDirection.None;
                DynValue v = table.Get("facing");
                if (v.Type == DataType.String)
                {
                    if (string.Compare(v.String, "left", true) == 0)
                    {
                        facingDirection = FacingDirection.Left;
                    }
                    else if (string.Compare(v.String, "right", true) == 0)
                    {
                        facingDirection = FacingDirection.Right;
                    }
                }
                else
                {
                    facingDirection = table.Get("facing").ToObject<FacingDirection>();
                }

                options.facing = 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;
        }