/// <summary>
 /// 根据现有数据创建控件
 /// </summary>
 /// <param name="parent">父控件</param>
 /// <param name="dialoguePoints">节点关系对象</param>
 private void CreateControlByData(IDialoguePointID parent, params DialoguePoint[] dialoguePoints)
 {
     foreach (DialoguePoint dialoguePoint in dialoguePoints)
     {
         DialogueValue dialogueValue = dialogueAnalysisData.GetDialoguePointByID(dialoguePoint.dialogueID);
         if (dialogueValue == null)
         {
             continue;
         }
         DialoguePointControl dialoguePointControl = AddNewChildNode(parent as ISelectedControl, dialogueValue, false);//添加一个子节点
         if (dialoguePoint.childDialoguePoints != null && dialoguePoint.childDialoguePoints.Length > 0)
         {
             CreateControlByData(dialoguePointControl, dialoguePoint.childDialoguePoints);
         }
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// 将controls的数据设置到TreeNode中
 /// </summary>
 /// <param name="treeNode"></param>
 /// <param name="controls"></param>
 private void SetControlToTreeNode(TreeNode treeNode, params Control[] controls)
 {
     foreach (Control control in controls)
     {
         DialoguePointControl dialoguePointControl = control as DialoguePointControl;
         if (dialoguePointControl != null)
         {
             DialogueValue dialogueValue = dialoguePointControl.GetDialogueValue();
             TreeNode      childTreeNode = new TreeNode();
             treeNode.Nodes.Add(childTreeNode);
             childTreeNode.Tag  = dialogueValue;
             childTreeNode.Text = "ID:[" + dialogueValue.dialogueID +
                                  "];NPC ID:[" + dialogueValue.npcID +
                                  "];Title:[" + dialogueValue.titleValue +
                                  "];Value:[" + dialogueValue.showValue + "]";
             if (dialoguePointControl.Tag != null && (dialoguePointControl.Tag as List <Control>) != null && (dialoguePointControl.Tag as List <Control>).Count > 0)
             {
                 SetControlToTreeNode(childTreeNode, (dialoguePointControl.Tag as List <Control>).ToArray());
             }
         }
     }
 }
        /// <summary>
        /// 设置(重建)对话节点的子节点数据
        /// </summary>
        /// <param name="parent">对话节点对象</param>
        /// <param name="childControls">子控件</param>
        private void SetDialoguePointData_Child(DialoguePoint parent, params Control[] childControls)
        {
            List <DialoguePoint> tempDialoguePointList = new List <DialoguePoint>();

            foreach (Control childControl in childControls)
            {
                DialoguePointControl pointControl = childControl as DialoguePointControl;
                if (pointControl == null)
                {
                    continue;
                }
                DialoguePoint childPoint = new DialoguePoint();
                childPoint.dialogueID = pointControl.GetDialogueValue().dialogueID;
                tempDialoguePointList.Add(childPoint);
                if (childControl.Tag != null &&
                    childControl.Tag.GetType().Equals(typeof(List <Control>)) &&
                    (childControl.Tag as List <Control>).Count > 0)
                {
                    SetDialoguePointData_Child(childPoint, (childControl.Tag as List <Control>).ToArray());
                }
            }
            parent.childDialoguePoints = tempDialoguePointList.ToArray();
        }
        /// <summary>
        /// 添加一个子节点
        /// </summary>
        /// <param name="iSelectedControlNow">要添加子节点的节点</param>
        private DialoguePointControl AddNewChildNode(ISelectedControl iSelectedControlNow, DialogueValue dialogueValue = null, bool updateControl = true)
        {
            IDialoguePointID iDialoguePointID = iSelectedControlNow as IDialoguePointID;

            if (iDialoguePointID.GetType().Equals(typeof(DialogueConditionControl)))//顶层节点(关系关系)只能添加一个子节点(数据节点)
            {
                if (iDialoguePointID.GetDialogueNextPointID.Length > 0)
                {
                    return(null);
                }
            }
            if (iDialoguePointID != null)
            {
                DialoguePointControl dialoguePointControl = new DialoguePointControl(dialogueValue);
                dialoguePointControl.Size = dialoguePointControl.StopSize;
                dialoguePointControl.SetListenControlSelected(ListenControlSelected);
                dialoguePointControl.SetLiestenOpenStop(AddListenOpenStop);
                dialoguePointControl.Tag = new List <Control>();
                Control        iSelectedControl = iSelectedControlNow as Control;
                List <Control> childControl     = iSelectedControl.Tag as List <Control>;
                childControl.Add(dialoguePointControl);
                Control parentControl = iSelectedControlNow.GetParent();
                parentControl.Controls.Add(dialoguePointControl);
                iDialoguePointID.AddNextPointID(dialoguePointControl);
                if (updateControl)
                {
                    ResetControlRect(parentControl);
                }
                if (searchNodeForm != null)
                {
                    searchNodeForm.NodeChanged = true;
                }
                return(dialoguePointControl);
            }
            return(null);
        }
        /// <summary>
        /// 保存方案
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 保存方案ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //重建对话关系数据集合以及对话数据字典
            List <DialogueCondition>        dialogueConditionList = new List <DialogueCondition>();
            Dictionary <int, DialogueValue> dialogueValueDic      = new Dictionary <int, DialogueValue>();

            foreach (Panel panel in FlowLayoutPanel_Main.Controls.OfType <Panel>())
            {
                DialogueConditionControl dialogueConditionContorl = panel.Controls.OfType <DialogueConditionControl>().FirstOrDefault();
                if (dialogueConditionContorl == null)
                {
                    continue;
                }
                //对话条件
                DialogueCondition dialogueCondition = dialogueConditionContorl.GetDialogueCondition();
                //对话关系
                if (dialogueConditionContorl.Tag != null &&
                    dialogueConditionContorl.Tag.GetType().Equals(typeof(List <Control>)) &&
                    (dialogueConditionContorl.Tag as List <Control>).Count > 0)
                {
                    List <Control>       childControlList = dialogueConditionContorl.Tag as List <Control>;
                    DialoguePointControl topPointControl  = childControlList[0] as DialoguePointControl;
                    if (topPointControl != null)
                    {
                        DialoguePoint topPoint = new DialoguePoint();
                        topPoint.dialogueID = topPointControl.GetDialogueValue().dialogueID;
                        if (childControlList[0].Tag != null &&
                            childControlList[0].Tag.GetType().Equals(typeof(List <Control>)) &&
                            (childControlList[0].Tag as List <Control>).Count > 0)
                        {
                            SetDialoguePointData_Child(topPoint, (childControlList[0].Tag as List <Control>).ToArray());
                        }
                        dialogueCondition.topPoint = topPoint;
                    }
                }
                else
                {
                    dialogueCondition.topPoint = null;
                }
                dialogueConditionList.Add(dialogueCondition);
                //对话数据
                foreach (DialoguePointControl dialoguePointControl in panel.Controls.OfType <DialoguePointControl>())
                {
                    DialoguePointControl topPointControl = dialoguePointControl as DialoguePointControl;
                    if (topPointControl != null)
                    {
                        if (!dialogueValueDic.ContainsKey(topPointControl.GetDialogueValue().dialogueID))
                        {
                            dialogueValueDic.Add(topPointControl.GetDialogueValue().dialogueID, topPointControl.GetDialogueValue());
                        }
                    }
                }
            }
            dialogueAnalysisData.ResetData(dialogueConditionList, dialogueValueDic);
            string dialogueConditionStr, dialogueValueStr;

            dialogueAnalysisData.GetData(out dialogueConditionStr, out dialogueValueStr);
            //保存
            string folderPath = Path.GetDirectoryName(projectPath);

            File.WriteAllText(folderPath + "\\" + dialogueConditionFileName + ".txt", dialogueConditionStr, Encoding.UTF8);
            File.WriteAllText(folderPath + "\\" + dialogueValueFileName + ".txt", dialogueValueStr, Encoding.UTF8);
        }