Beispiel #1
0
    public void nextAction()
    {
        frameIdx += 1;

        if (model.frames [frameIdx].DialogType == eDialogFrameType.CHANGE_TEXT)
        {
            DialogFrameText realFrame = model.frames [frameIdx] as DialogFrameText;
            cursorF = 0.0f;
            cursorI = 0;
            view.dialogContent.text = "";
            isReading          = true;
            view.nameText.text = realFrame.Name;
        }
        else if (model.frames [frameIdx].DialogType == eDialogFrameType.CHANGE_LIHUI)
        {
            isMovingLihui = false;
        }
        else if (model.frames [frameIdx].DialogType == eDialogFrameType.CHANGE_BG)
        {
            DialogFrameBG realFrame = model.frames [frameIdx] as DialogFrameBG;
            Debug.Log("change");
            //view.bg.sprite = null;
        }
        else if (model.frames [frameIdx].DialogType == eDialogFrameType.END)
        {
        }
        else if (model.frames [frameIdx].DialogType == eDialogFrameType.SHOW_BRANCH)
        {
            DialogFrameBranch realFrame = model.frames [frameIdx] as DialogFrameBranch;
            ShowBranch(realFrame.Choices);
        }
        else if (model.frames [frameIdx].DialogType == eDialogFrameType.EFFECT)
        {
            isEffecting = false;
        }
    }
Beispiel #2
0
    public DialogBlock ReadFromTxt(List <string> input)
    {
        List <DialogFrameBase> dialogs = new List <DialogFrameBase> ();
        int InstId = 0;

        foreach (string line in input)
        {
            if (string.IsNullOrEmpty(line))
            {
                continue;
            }
            DialogFrameBase dialogFrame;

            if (line.StartsWith("["))
            {
                dialogFrame            = new DialogFrameText();
                dialogFrame.DialogType = eDialogFrameType.CHANGE_TEXT;
                int i = 1;
                int j = i;
                while (j < line.Length && line [j] != ']')
                {
                    j++;
                }
                string speaker = line.Substring(i, j - i);

                if (speaker.Contains(","))
                {
                    ((DialogFrameText)dialogFrame).Name     = speaker.Substring(0, line.IndexOf(","));
                    ((DialogFrameText)dialogFrame).LihuiIdx = int.Parse(speaker.Substring(line.IndexOf(",") + 1));
                }
                else
                {
                    ((DialogFrameText)dialogFrame).Name = speaker;
                }

                i = line.IndexOf(":") + 1;
                string words = line.Substring(i);
                ((DialogFrameText)dialogFrame).TextLines = preHandleWords(words);
            }
            else if (line.StartsWith("Lihui"))
            {
                dialogFrame            = new DialogFrameLihui();
                dialogFrame.DialogType = eDialogFrameType.CHANGE_LIHUI;
                string   str  = line.Substring(6);
                string[] cmds = str.Split(',');
                foreach (string cmd in cmds)
                {
                    string[] args    = cmd.Trim().Split(' ');
                    string   Opt     = args [0];
                    string   Lid     = args [1];
                    int      SlotIdx = int.Parse(args [2]);
                    ((DialogFrameLihui)dialogFrame).Opts.Add(Opt);
                    ((DialogFrameLihui)dialogFrame).Lids.Add(Lid);
                    ((DialogFrameLihui)dialogFrame).SlotIdxs.Add(SlotIdx);
                }
            }
            else if (line.StartsWith("BG"))
            {
                dialogFrame            = new DialogFrameBG();
                dialogFrame.DialogType = eDialogFrameType.CHANGE_BG;
                string   str  = line.Substring(3);
                string[] args = str.Trim().Split(' ');
                if (args.Length > 1)
                {
                    ((DialogFrameBG)dialogFrame).BGM = args [1];
                }
                ((DialogFrameBG)dialogFrame).BG = args [0];
            }
            else if (line.StartsWith("Effect"))
            {
                dialogFrame            = new DialogFrameEffect();
                dialogFrame.DialogType = eDialogFrameType.EFFECT;
                string str = line.Substring(7);

                ((DialogFrameEffect)dialogFrame).EffectId = str;
            }
            else if (line.StartsWith("End"))
            {
                dialogFrame            = new DialogFrameEnd();
                dialogFrame.DialogType = eDialogFrameType.END;
            }
            else if (line.StartsWith("Branch"))
            {
                dialogFrame            = new DialogFrameBranch();
                dialogFrame.DialogType = eDialogFrameType.SHOW_BRANCH;

                string   str      = line.Substring(7);
                string[] branches = str.Split(',');
                foreach (string branch in branches)
                {
                    string[] ops = branch.Split(' ');
                    ((DialogFrameBranch)dialogFrame).Choices.Add(ops[0]);
                }
            }
            else
            {
                throw new UnityException("not defined dialog type");
            }
            dialogFrame.Index = InstId++;
            dialogs.Add(dialogFrame);
        }
        DialogBlock ret = new DialogBlock();

        ret.frames = dialogs;
        return(ret);
    }
Beispiel #3
0
 public void Inject(GameplayManager gameplayManager)
 {
     input           = gameplayManager.input;
     dialogFrameText = gameplayManager.tutorialUI.dialogFrameText;
 }
Beispiel #4
0
    public override void Tick(float dTime)
    {
        if (frameIdx < 0 || frameIdx >= model.frames.Count)
        {
            return;
        }

        if (model.frames [frameIdx].DialogType == eDialogFrameType.CHANGE_TEXT)
        {
            if (!isReading)
            {
                return;
            }

            DialogFrameText realFrame = model.frames [frameIdx] as DialogFrameText;

            if (cursorI >= realFrame.TextLines.Count)
            {
                isReading = false;
                return;
            }

            cursorF += Time.deltaTime * wordSpeed;

            int newCursorIdx = (int)cursorF;
            if (newCursorIdx == cursorI)
            {
                return;
            }

            if (newCursorIdx > realFrame.TextLines.Count)
            {
                newCursorIdx = realFrame.TextLines.Count;
            }

            for (int i = cursorI; i < newCursorIdx; i++)
            {
                textAppend(realFrame.TextLines[i]);
            }
            cursorI = newCursorIdx;
        }
        else if (model.frames [frameIdx].DialogType == eDialogFrameType.CHANGE_LIHUI)
        {
            if (!isMovingLihui)
            {
                DialogFrameLihui realFrame = model.frames [frameIdx] as DialogFrameLihui;

                for (int i = 0; i < view.LihuiList.Count; i++)
                {
                    view.LihuiList [i].NeedMove = true;
                }
                numLihuiNeedMove = 0;
                for (int i = 0; i < realFrame.Opts.Count; i++)
                {
                    if (realFrame.Opts [i] == "Enter")
                    {
                        if (realFrame.SlotIdxs [i] > model.LihuiIds.Count)
                        {
                            realFrame.SlotIdxs [i] = model.LihuiIds.Count;
                        }
                        model.LihuiIds.Insert(realFrame.SlotIdxs [i], realFrame.Lids [i]);
                        GameObject l = GameMain.GetInstance().GetModule <ResLoader> ().Instantiate("Dialog/LihuiView", view.LihuiContainer);
                        if (l == null)
                        {
                            Debug.Log("error");
                            continue;
                        }
                        LihuiView vv = new LihuiView();
                        vv.BindView(l.transform);
                        vv.NeedMove = false;
                        vv.Target   = Vector2.zero;

                        view.LihuiList.Insert(realFrame.SlotIdxs [i], vv);
                    }
                    else if (realFrame.Opts [i] == "Leave")
                    {
                        model.LihuiIds.RemoveAt(realFrame.SlotIdxs [i]);
                        LihuiView vv = view.LihuiList [realFrame.SlotIdxs [i]];
                        view.LihuiList.RemoveAt(realFrame.SlotIdxs [i]);
                        Vector2 target = vv.root.anchoredPosition + Vector2.up * 1000f;
                        Tween   tween  = DOTween.To
                                         (
                            () => vv.root.anchoredPosition,
                            (x) => vv.root.anchoredPosition = x,
                            target,
                            0.5f
                                         ).OnComplete(delegate() {
                            GameObject.Destroy(vv.root.gameObject);
                        });
                    }
                }

                for (int i = 0; i < view.LihuiList.Count; i++)
                {
                    Vector2 target = GetPosition(i);
                    view.LihuiList[i].root.SetSiblingIndex(i);

                    if (!view.LihuiList [i].NeedMove)
                    {
                        view.LihuiList [i].root.anchoredPosition = target;
                    }
                    else
                    {
                        LihuiView vv = view.LihuiList [i];
                        if ((vv.root.anchoredPosition - target).magnitude < 1f)
                        {
                            continue;
                        }
                        numLihuiNeedMove += 1;
                        Tween tween = DOTween.To
                                      (
                            () => vv.root.anchoredPosition,
                            (x) => vv.root.anchoredPosition = x,
                            target,
                            0.5f
                                      ).OnComplete(delegate() {
                            numLihuiNeedMove -= 1;
                        });
                    }
                }
                isMovingLihui = true;
            }
            else
            {
                if (numLihuiNeedMove <= 0)
                {
                    isMovingLihui = false;
                    nextAction();
                }
            }
        }
        else if (model.frames [frameIdx].DialogType == eDialogFrameType.CHANGE_BG)
        {
            nextAction();
        }
        else if (model.frames [frameIdx].DialogType == eDialogFrameType.EFFECT)
        {
            if (!isEffecting)
            {
                isEffecting = true;
            }
            if (isEffecting)
            {
                view.bg.color = new Color(view.bg.color.r, view.bg.color.g, view.bg.color.b, view.bg.color.a - 1f * dTime);
                if (view.bg.color.a <= 0)
                {
                    view.bg.color = new Color(view.bg.color.r, view.bg.color.g, view.bg.color.b, 1);
                    nextAction();
                    isEffecting = false;
                }
            }
        }
        else if (model.frames [frameIdx].DialogType == eDialogFrameType.END)
        {
            Debug.Log("has finished");

            finishDialog();
        }
        else if (model.frames [frameIdx].DialogType == eDialogFrameType.SHOW_BRANCH)
        {
            if (isBranchFlashing)
            {
            }
        }
    }