コード例 #1
0
        public ListItemUi AddDialogOption(Dialog.DialogOption option, bool scrollAllTheWayDown)
        {
            if (!initialized)
            {
                Init();
            }
            ListItemUi li = null;

            switch (option)
            {
            case Dialog.Choice c: AddDialogOption_Choice(c, out li, option); break;

            case Dialog.Text t: AddDialogOption_Text(t, out li, option); break;

            case Dialog.Command cmd: AddDialogOption_Command(cmd, out li, option); break;
            }
            if (li != null)
            {
                Dialog.Text txt = option as Dialog.Text;
                if (txt != null)
                {
                    li.TextAlignment = txt.anchorText;
                }
            }
            if (scrollAllTheWayDown && !goingToScrollAllTheWayDown)
            {
                goingToScrollAllTheWayDown = true;
                // we want scroll all the way down, and can't control when the UI updates enough to realize it can scroll
                Proc.Delay(100, () => {
                    goingToScrollAllTheWayDown = false; scrollRect.verticalNormalizedPosition = 0;
                });
                // 100ms (1/10th of a second) is not bad for UI lag, and should be enough time for the UI to update itself
            }
            return(li);
        }
コード例 #2
0
        private void PossiblyAddParseCommandOutputToDialog(Dialog.DialogOption option)
        {
            if (Print_commandOutput.Length == 0)
            {
                return;
            }
            string     str = Print_commandOutput.ToString();
            ListItemUi li  = listUi.AddItem(option, str, null, prefab_textUi);

            Print_commandOutput.Clear();
        }
コード例 #3
0
        public void SetDialog(object src, Tokenizer tok, Dialog dialog, UiPolicy uiPolicy)
        {
            if (!initialized)
            {
                Init();
            }
            bool isScrolledAllTheWayDown = !scrollRect.verticalScrollbar.gameObject.activeInHierarchy ||
                                           scrollRect.verticalNormalizedPosition < 1f / 1024; // keep scrolling down if really close to bottom

            switch (uiPolicy)
            {
            case UiPolicy.StartOver: RemoveDialogElements(); break;

            case UiPolicy.DisablePrev: DeactivateDialogChoices(); break;

            case UiPolicy.Continue: break;
            }
            if (dialog == null)
            {
                tok.AddError("missing dialog"); return;
            }
            if (dialog.options != null)
            {
                for (int i = 0; i < dialog.options.Length; ++i)
                {
                    Dialog.DialogOption opt = dialog.options[i];
                    //NonStandard.Show.Log("checking opt " + NonStandard.Show.Stringify(opt, false));
                    ScriptedDictionaryManager m = Global.Get <ScriptedDictionaryManager>();
                    if (opt.Available(tok, m.Main))
                    {
                        AddDialogOption(opt, isScrolledAllTheWayDown);
                        //NonStandard.Show.Log("added" + NonStandard.Show.Stringify(opt, false));
                    }
                    else
                    {
                        //NonStandard.Show.Log("ignored" + NonStandard.Show.Stringify(opt, false));
                    }
                }
            }
            ShowErrors(tok.errors);
            onDialog?.Invoke();
        }
コード例 #4
0
        private void AddDialogOption_Choice(Dialog.Choice c, out ListItemUi listItem, Dialog.DialogOption option)
        {
            ListItemUi li = null;

            li = listItem = listUi.AddItem(option, DialogManager.Instance.GetScriptScope().Format(c.text), () => {
                //NonStandard.Show.Log("------- "+c.command);
                Tokenizer tok = new Tokenizer();
                Commander.Instance.ParseCommand(new Instruction(c.command, li), Print, out tok);
                //NonStandard.Show.Log("/////// " + c.command);
                if (tok?.HasError() ?? false)
                {
                    Print(tok.GetErrorString());
                }
                PossiblyAddParseCommandOutputToDialog(option);
            }, prefab_buttonUi);
            currentChoices.Add(li);
        }
コード例 #5
0
        private void AddDialogOption_Command(Dialog.Command cmd, out ListItemUi listItem, Dialog.DialogOption option)
        {
            //NonStandard.Show.Log("executing command "+cmd.command);
            Tokenizer tok = new Tokenizer();

            Commander.Instance.ParseCommand(new Instruction(cmd.command, option), Print, out tok);
            if (tok?.HasError() ?? false)
            {
                Print(Col.r() + tok.GetErrorString());
            }
            PossiblyAddParseCommandOutputToDialog(option);
            listItem = null;
        }
コード例 #6
0
 private void AddDialogOption_Text(Dialog.Text t, out ListItemUi listItem, Dialog.DialogOption option)
 {
     listItem = listUi.AddItem(option, DialogManager.Instance.GetScriptScope().Format(t.text), null, prefab_textUi);
 }