Esempio n. 1
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="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);
        }