예제 #1
0
        bool OnBaseTextEvent(TextEvent textEvent, Action continuation)
        {
            var conversationResult = _conversation?.OnText(textEvent, continuation);

            if (conversationResult.HasValue)
            {
                return(conversationResult.Value);
            }

            var tf = Resolve <ITextFormatter>();

            switch (textEvent.Location)
            {
            case null:
            case TextLocation.NoPortrait:
            {
                var dialog = AttachChild(new TextDialog(tf.Format(textEvent.ToId())));
                dialog.Closed += (sender, _) => continuation();
                return(true);
            }

            case TextLocation.PortraitLeft:
            case TextLocation.PortraitLeft2:
            case TextLocation.PortraitLeft3:
            {
                var portraitId = GetPortrait(textEvent.CharacterId);
                if (textEvent.Location == TextLocation.PortraitLeft2)     // TODO: ??? work out how this is meant to work.
                {
                    portraitId = Base.Portrait.Rainer;
                }
                var text   = tf.Ink(FontColor.Yellow).Format(textEvent.ToId());
                var dialog = AttachChild(new TextDialog(text, portraitId));
                dialog.Closed += (sender, _) => continuation();
                return(true);
            }

            case TextLocation.QuickInfo:
                Raise(new DescriptionTextEvent(tf.Format(textEvent.ToId())));
                continuation();
                return(true);

            case TextLocation.Conversation:
            case TextLocation.ConversationQuery:
            case TextLocation.ConversationOptions:
            case TextLocation.StandardOptions:
                break;     // Handled by Conversation

            default:
                Raise(new DescriptionTextEvent(tf.Format(textEvent.ToId())));     // TODO:
                continuation();
                return(true);
            }

            return(false);
        }
예제 #2
0
        public bool?OnText(TextEvent textEvent, Action continuation)
        {
            if (textEvent == null)
            {
                throw new ArgumentNullException(nameof(textEvent));
            }
            if (continuation == null)
            {
                throw new ArgumentNullException(nameof(continuation));
            }
            var tf = Resolve <ITextFormatter>();

            switch (textEvent.Location)
            {
            case TextLocation.Conversation:
            case TextLocation.NoPortrait:
            {
                void OnConversationClicked()
                {
                    _textWindow.Clicked -= OnConversationClicked;
                    continuation();
                }

                var text = tf.Ink(FontColor.Yellow).Format(textEvent.ToId());
                DiscoverTopics(text.GetBlocks().SelectMany(x => x.Words));
                _textWindow.Text     = text;
                _textWindow.Clicked += OnConversationClicked;
                return(true);
            }

            case TextLocation.ConversationOptions:
            {
                var text = tf.Ink(FontColor.Yellow).Format(textEvent.ToId());
                DiscoverTopics(text.GetBlocks().SelectMany(x => x.Words));
                _textWindow.Text = text;

                var options = new List <(IText, int?, Action)>();
                var blocks  = text.GetBlocks().Select(x => x.BlockId).Distinct();
                foreach (var blockId in blocks.Where(x => x > 0))
                {
                    options.Add((text, blockId, () => BlockClicked(blockId, textEvent.TextId)));
                }

                var standardOptions = GetStandardOptions(tf);
                _optionsWindow.SetOptions(options, standardOptions);
                _optionsWindow.IsActive = true;
                continuation();
                return(true);
            }

            case TextLocation.ConversationQuery:
            {
                var text = tf.Ink(FontColor.Yellow).Format(textEvent.ToId());

                DiscoverTopics(text.GetBlocks().SelectMany(x => x.Words));

                void OnQueryClicked()
                {
                    _textWindow.Clicked -= OnQueryClicked;

                    var options = new List <(IText, int?, Action)>();
                    var blocks  = text.GetBlocks().Select(x => x.BlockId).Distinct();

                    foreach (var blockId in blocks.Where(x => x > 0))
                    {
                        options.Add((text, blockId, () => BlockClicked(blockId, textEvent.TextId)));
                    }
                    _optionsWindow.SetOptions(options, null);
                    _optionsWindow.IsActive = true;

                    continuation();
                }

                _textWindow.Text     = text;
                _textWindow.Clicked += OnQueryClicked;
                return(true);
            }

            case TextLocation.StandardOptions:
            {
                _optionsWindow.SetOptions(null, GetStandardOptions(tf));
                _optionsWindow.IsActive = true;
                continuation();
                return(true);
            }
            }

            // Actions to check: StartDialogue, DialogueLine #,#, DialogueLine WORD, EndDialogue

            /*
             *  Enumerable.Empty<(IText, IEvent)>(), true
             *  ));
             *
             * if(addStandardOptions)
             * {
             * }
             */
            return(null);
        }