Example #1
0
        /// <summary>
        /// 复制拷贝
        /// </summary>
        /// <returns>拷贝对象</returns>
        public object Clone()
        {
            AI_SingleAction sig = new AI_SingleAction();

            sig.Action = this.Action.Clone() as AI_Action;

            return(sig);
        }
Example #2
0
        /// <summary>
        /// 初始化自定义动作自动命名的种子
        /// </summary>
        /// <param name="aiSingleAction">ai动作</param>
        private void InitActionIndex(AI_SingleAction aiSingleAction)
        {
            int maxID = 0;

            if (aiSingleAction != null)
            {
                string actionName = aiSingleAction.Action.Ename;
                int    index      = actionName.LastIndexOf("_");

                if (index > 0)
                {
                    int tempID = -1;

                    if (int.TryParse(actionName.Substring(index + 1, actionName.Length - index - 1), out tempID))
                    {
                        maxID = tempID + 1;
                    }
                }
            }
            else
            {
                foreach (object o in listBox1.Items)
                {
                    AI_SingleAction singleAction = o as AI_SingleAction;

                    if (singleAction != null)
                    {
                        AI_Action aiAction = singleAction.Action;

                        if (int.Parse(aiAction.ActionID) > 2000)
                        {
                            string actionName = aiAction.Ename;
                            int    index      = actionName.LastIndexOf("_");

                            if (index > 0)
                            {
                                int tempID = -1;

                                if (int.TryParse(actionName.Substring(index + 1, actionName.Length - index - 1), out tempID))
                                {
                                    maxID = tempID + 1;
                                }
                            }
                        }
                    }
                }
            }

            groupIndex = maxID;
        }
Example #3
0
        /// <summary>
        /// 添加动作
        /// </summary>
        /// <param name="sender">事件发送者</param>
        /// <param name="e">事件参数</param>
        private void btnAdd_Click(object sender, EventArgs e)
        {
            // 初始化自动重命名种子
            InitActionIndex(null);

            AI_SingleAction  singleAction     = new AI_SingleAction();
            SingleActionForm singleActionForm = new SingleActionForm();

            singleActionForm.GraphElementID = graphElementID;
            singleActionForm.InActionGroup  = true;
            singleActionForm.GroupIndex     = groupIndex;
            singleActionForm.Reload(singleAction);
            singleActionForm.ShowDialog();

            if (singleActionForm.EditSuccess)
            {
                listBox1.Items.Add(singleAction);
            }
        }
Example #4
0
        /// <summary>
        ///  获取Tip字符串
        /// </summary>
        /// <returns>Tip字符串</returns>
        public string ToFullText()
        {
            StringBuilder toolTipText = new StringBuilder();

            if (ActionList != null)
            {
                for (int i = 0; i < ActionList.Count; i++)
                {
                    AI_SingleAction singleAction = ActionList[i];

                    toolTipText.AppendLine(string.Format("<bold>动作{0}\r\n{1}\r\n<split>\r\n{2}\r\n<split>\r\n<split>",
                                                         i + 1, singleAction.Action.Name, singleAction.ToFullText()));
                }

                if (toolTipText.Length > 0)
                {
                    toolTipText.Remove(toolTipText.Length - 20, 20);
                }
            }

            return(toolTipText.ToString());
        }
Example #5
0
        /// <summary>
        /// 编辑动作
        /// </summary>
        /// <param name="sender">事件发送者</param>
        /// <param name="e">事件参数</param>
        private void listBox1_DoubleClick(object sender, EventArgs e)
        {
            AI_SingleAction singleAction = this.listBox1.SelectedItem as AI_SingleAction;

            if (singleAction != null)
            {
                // 初始化自动重命名种子
                InitActionIndex(singleAction);

                SingleActionForm saForm = new SingleActionForm();
                saForm.GraphElementID = graphElementID;
                saForm.InActionGroup  = true;
                saForm.GroupIndex     = groupIndex;
                saForm.Reload(singleAction);
                saForm.ShowDialog();

                if (saForm.EditSuccess)
                {
                    int ind = listBox1.SelectedIndex;
                    listBox1.Items.RemoveAt(ind);
                    listBox1.Items.Insert(ind, singleAction);
                }
            }
        }
Example #6
0
        /// <summary>
        /// 获取数据元信息
        /// </summary>
        /// <returns>数据元信息哈希表</returns>
        public override System.Collections.Hashtable GetOutputArgs()
        {
            Hashtable infoTable = new Hashtable();

            infoTable["DataType"] = this.dataType;

            switch (this.dataType)
            {
            case "AIStateNode":     // 状态结点
            {
                AI_State state = this.data as AI_State;

                if (state != null)
                {
                    infoTable["Name"]        = state.Name;
                    infoTable["EnglishName"] = state.Ename;
                }

                break;
            }

            case "AIActionNode":     // 动作结点
            {
                AI_SingleAction action = this.data as AI_SingleAction;

                if (action != null && action.Action != null)
                {
                    infoTable["Name"]        = action.Action.Name;
                    infoTable["EnglishName"] = action.Action.Ename;

                    if (int.Parse(action.Action.ActionID) > 2000)
                    {
                        infoTable["Script"] = action.Action.Info;
                    }
                }

                break;
            }

            case "AIActionsNode":     // 动作组结点
            {
                AI_MultiAction multiAction = this.data as AI_MultiAction;

                if (multiAction != null)
                {
                    List <string> scriptList = new List <string>();

                    foreach (AI_SingleAction singleAction in multiAction.ActionList)
                    {
                        if (singleAction.Action != null && int.Parse(singleAction.Action.ActionID) > 2000)
                        {
                            if (!string.IsNullOrEmpty(singleAction.Action.Info))
                            {
                                scriptList.Add(singleAction.Action.Info);
                            }
                        }
                    }

                    infoTable["ScriptList"] = scriptList;
                }

                break;
            }

            case "AILine":     // 连接线
            {
                // 无需求,暂时忽略

                break;
            }
            }

            return(infoTable);
        }
Example #7
0
        private static StateNodeForm stateForm = new StateNodeForm(); // 状态结点编辑窗体

        // [NonSerialized]
        // private static SingleActionForm singleActionForm = new SingleActionForm(); // 单动作结点编辑窗体

        /// <summary>
        /// 编辑数据
        /// </summary>
        /// <param name="table">数据哈希表</param>
        /// <returns>是否编辑成功</returns>
        public override bool EditData(System.Collections.Hashtable table)
        {
            switch (this.DataType)
            {
            case "AIStateNode":     // 状态结点
            {
                AI_State state = table["data"] as AI_State;

                if (state == null)
                {
                    state = new AI_State();
                }

                // 优化窗体显示
                stateForm.GraphElementID = id;
                stateForm.Reload(state);
                stateForm.ShowDialog();

                if (stateForm.EditSuccess)         // 编辑成功
                {
                    this.Data = state;

                    // 清空连接线
                    List <AI_Event> elist       = state.EventList;
                    Hashtable       outlineList = (table["next_data"] as Hashtable);
                    foreach (DataElement de in outlineList.Values)
                    {
                        if (!elist.Contains(de.Data as AI_Event))
                        {
                            de.Data        = null;
                            de.Text        = "";
                            de.TooltipText = "";
                        }
                    }
                    this.Text        = state.ToString();
                    this.TooltipText = state.ToFullText();
                }
                else
                {
                    return(false);
                }

                break;
            }

            case "AIActionNode":     // 动作结点
            {
                AI_SingleAction action = table["data"] as AI_SingleAction;

                if (action == null)
                {
                    action = new AI_SingleAction();
                }

                // 优化窗体显示
                SingleActionForm singleActionForm = new SingleActionForm();
                singleActionForm.GraphElementID = id;
                singleActionForm.InActionGroup  = false;
                singleActionForm.Reload(action);
                singleActionForm.ShowDialog();

                if (singleActionForm.EditSuccess)         // 编辑成功
                {
                    this.Data = action;

                    // 清空连接线
                    List <string> eventList   = action.Action.RetList;
                    Hashtable     outLineList = (table["next_data"] as Hashtable);

                    foreach (DataElement dataElement in outLineList.Values)
                    {
                        if (!eventList.Contains(dataElement.Data as string))
                        {
                            dataElement.Data        = null;
                            dataElement.Text        = "";
                            dataElement.TooltipText = "";
                        }
                    }

                    this.Text        = action.ToString();
                    this.TooltipText = action.ToFullText();
                }
                else
                {
                    return(false);
                }

                break;
            }

            case "AIActionsNode":     // 动作组结点
            {
                AI_MultiAction multiAction = table["data"] as AI_MultiAction;

                if (multiAction == null)
                {
                    multiAction = new AI_MultiAction();
                }

                MultiActionForm multiActionForm = new MultiActionForm(multiAction);
                multiActionForm.GraphElementID = id;

                if (multiActionForm.ShowDialog() == DialogResult.OK)
                {
                    this.Data = multiAction;

                    //清空连接线
                    Hashtable outlineList = (table["next_data"] as Hashtable);
                    if (multiAction.ActionList.Count == 0)
                    {
                        foreach (DataElement dataElement in outlineList.Values)
                        {
                            dataElement.Data        = null;
                            dataElement.Text        = "";
                            dataElement.TooltipText = "";
                        }
                    }
                    else
                    {
                        List <string> elist = multiAction.ActionList[multiAction.ActionList.Count - 1].Action.RetList;
                        foreach (DataElement dataElement in outlineList.Values)
                        {
                            if (!elist.Contains(dataElement.Data as string))
                            {
                                dataElement.Data        = null;
                                dataElement.Text        = "";
                                dataElement.TooltipText = "";
                            }
                        }
                    }
                    this.Text        = multiAction.ToString();
                    this.TooltipText = multiAction.ToFullText();
                }
                else
                {
                    return(false);
                }

                break;
            }

            case "AILine":     // 连接线
            {
                Hashtable ht_prev_data      = table["prev_data"] as Hashtable;
                Hashtable ht_neightbor_data = table["neighbor_data"] as Hashtable;

                if (ht_prev_data.Count == 0)
                {
                    return(false);
                }

                object      prev_data           = null;
                DataElement previousDataElement = null;

                foreach (object o in ht_prev_data.Values)
                {
                    DataElement dataElement = o as DataElement;

                    if (dataElement.Data != null)
                    {
                        previousDataElement = dataElement;
                        prev_data           = dataElement.Data;
                        break;
                    }
                }

                if (previousDataElement == null || prev_data == null)
                {
                    return(false);
                }

                switch (previousDataElement.DataType)
                {
                case "AIStateNode":             // 状态结点连出的线
                {
                    AI_State        state         = prev_data as AI_State;
                    List <AI_Event> selectionList = new List <AI_Event>(state.EventList);

                    foreach (DataElement de in ht_neightbor_data.Values)                 // 剔除已经选择过了的事件
                    {
                        if ((de.Data as AI_Event) != null)
                        {
                            selectionList.Remove(de.Data as AI_Event);
                        }
                    }

                    this.data = LineForm <AI_Event> .ShowSelect(table["data"] as AI_Event, selectionList);

                    if (this.data == null)
                    {
                        this.Text = "";
                    }
                    else
                    {
                        this.Text = this.Data.ToString();
                    }

                    break;
                }

                case "AIActionNode":
                {
                    AI_Action action = (prev_data as AI_SingleAction).Action;

                    if (action == null)
                    {
                        return(false);
                    }

                    List <string> selectionList = new List <string>(action.RetList);
                    EditLine(selectionList, ht_neightbor_data);

                    break;
                }

                case "AIActionsNode":
                {
                    List <AI_SingleAction> actionList = (prev_data as AI_MultiAction).ActionList;

                    if (actionList.Count == 0)
                    {
                        return(false);
                    }

                    AI_Action action = actionList[actionList.Count - 1].Action;

                    if (action == null)
                    {
                        return(false);
                    }

                    List <string> selectionList = new List <string>(action.RetList);
                    EditLine(selectionList, ht_neightbor_data);

                    break;
                }

                case "InnerChart":
                {
                    Hashtable infoTable   = prev_data as Hashtable;
                    Hashtable outSlotInfo = infoTable["outSlotInfo"] as Hashtable;

                    List <string> selectionList = new List <string>();

                    foreach (string id in outSlotInfo.Keys)
                    {
                        string interfaceName = outSlotInfo[id] as string;

                        if (interfaceName == null)
                        {
                            interfaceName = "未命名";
                        }

                        selectionList.Add(string.Format("{0}:{1}", id, interfaceName));
                    }

                    EditLine(selectionList, ht_neightbor_data);

                    break;
                }

                case "InterfaceNode":
                {
                    this.data = "1:下一步";
                    this.text = "";

                    break;
                }
                }

                break;
            }
            }

            return(true);
        }
Example #8
0
        /// <summary>
        /// 刷新数据
        /// </summary>
        /// <param name="sigaction">AId动作</param>
        public void Reload(AI_SingleAction sigaction)
        {
            actionTree.SelectedNode     = null;
            actionComboBox.SelectedItem = null;
            editSuccess = false;

            // 保存传进来的参数
            this.singleAction = sigaction;
            AI_Action action = sigaction.Action;

            // 本文件内的自定义脚本动作
            string actionNameID = graphElementID.ToString();

            if (inActionGroup)
            {
                actionNameID = string.Format("{0}_{1}", graphElementID.ToString(), groupIndex.ToString());
            }

            if (action.ActionID != null)
            {
                int      actionID = int.Parse(action.ActionID);
                string[] returnValueArray;

                if (actionID > 2000) // 本绘图内自定义动作
                {
                    actionNameBox.Text = action.Name;
                    codeEditBox.Text   = action.Info;

                    returnValueArray = action.rettype.Split(splitReturnValueArray, StringSplitOptions.RemoveEmptyEntries);

                    for (int i = 0; i < 3; i++)
                    {
                        if (i < returnValueArray.Length)
                        {
                            returnValueBoxArray[i].Text = returnValueArray[i];
                        }
                        else
                        {
                            returnValueBoxArray[i].Text = "";
                        }
                    }

                    tabControl1.SelectedTabIndex = 1;
                }
                else // 系统库自定义动作
                {
                    tabControl1.SelectedTabIndex = 0;

                    // 选中当前动作
                    foreach (Node classNode in actionTree.Nodes)
                    {
                        if (classNode.Text == action.ActionType)
                        {
                            foreach (Node childNode in classNode.Nodes)
                            {
                                if (childNode.Tag.ToString() == action.DBID)
                                {
                                    actionTree.SelectedNode = childNode;
                                    break;
                                }
                            }

                            break;
                        }
                    }

                    // 自定义动作加上初始值
                    actionNameBox.Text   = string.Format("自定义动作{0}", actionNameID);
                    returnValue1Box.Text = "成功";
                    returnValue2Box.Text = "";
                    returnValue3Box.Text = "";

                    StringBuilder code = new StringBuilder();
                    code.Append(string.Format("function CustomAction{0}(npc, actionData)\r\n", actionNameID));
                    code.Append("    -- 输入自定义动作实现脚本\r\n\r\n");
                    code.Append("    return 1\r\n");
                    code.Append("end");
                    codeEditBox.Text = code.ToString();
                }
            }
            else
            {
                tabControl1.SelectedTabIndex = 0;

                // 自定义动作加上初始值
                actionNameBox.Text   = string.Format("自定义动作{0}", actionNameID);
                returnValue1Box.Text = "成功";
                returnValue2Box.Text = "";
                returnValue3Box.Text = "";

                StringBuilder code = new StringBuilder();
                code.Append(string.Format("function CustomAction{0}(npc, actionData)\r\n", actionNameID));
                code.Append("    -- 输入自定义动作实现脚本\r\n\r\n");
                code.Append("    return 1\r\n");
                code.Append("end");
                codeEditBox.Text = code.ToString();
            }
        }