Example #1
0
        /// <summary>
        /// 选择选择框
        /// </summary>
        /// <param name="sender">事件发送者</param>
        /// <param name="e">事件参数</param>
        private void actionComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            AI_Action currentAction = actionComboBox.Items_SelectedItem as AI_Action;

            if (beginEdit && currentAction != null)
            {
                string actionID     = currentAction.DBID;
                Node   selectedNode = null;

                foreach (Node classNode in actionTree.Nodes)
                {
                    foreach (Node actionNode in classNode.Nodes)
                    {
                        if (actionNode.Tag.ToString() == actionID)
                        {
                            selectedNode = actionNode;
                            break;
                        }
                    }

                    if (selectedNode != null)
                    {
                        break;
                    }
                }

                actionTree.SelectedNode = selectedNode;
            }
        }
Example #2
0
        /// <summary>
        /// 初始化数据
        /// </summary>
        private static void Init()
        {
            if (!inited)
            {
                DataTable actionInfo = DBManager.DataBaseManager.GetDataBaseManager().GetTable_AI_Action_Define();

                foreach (DataRow dataRow in actionInfo.Rows)
                {
                    AI_Action aiAction = new AI_Action();
                    aiAction.DBID       = dataRow["id"].ToString();
                    aiAction.ActionID   = dataRow["actionid"].ToString();
                    aiAction.Name       = dataRow["name"].ToString();
                    aiAction.Ename      = dataRow["ename"].ToString();
                    aiAction.Info       = dataRow["info"].ToString();
                    aiAction.ActionType = dataRow["class"].ToString();
                    aiAction.rettype    = dataRow["rettype"].ToString();

                    string parms = dataRow["parms"].ToString();

                    foreach (string line in parms.Split(parameterSpliter, StringSplitOptions.RemoveEmptyEntries))
                    {
                        // line: 姓名,-2,"张三"
                        string   sline   = line + ",";
                        string[] strlist = sline.Split(parameterInfoSpliter);
                        aiAction.Args.Add(new AI_Parm(strlist[0], strlist[2] == "" ? null : strlist[2], int.Parse(strlist[1]), false));
                    }

                    actionList.Add(aiAction);
                    actionDictionary[aiAction.DBID] = aiAction;
                }

                inited = true;
            }
        }
Example #3
0
        /// <summary>
        /// 检查是否需要重新编辑
        /// </summary>
        /// <returns>是否需要重新编辑</returns>
        public bool RequestEdit()
        {
            bool      result = false;
            AI_Action action = ActionTable.FindItemByDBID(this.DBID);

            if (action != null)
            {
                if (this.Args.Count == action.Args.Count)
                {
                    for (int i = 0; i < this.Args.Count; i++)
                    {
                        AI_Parm parameter1 = this.Args[i];
                        AI_Parm parameter2 = action.Args[i];

                        if (parameter1.m_type != parameter2.m_type)
                        {
                            result = true;
                            break;
                        }
                    }
                }
                else
                {
                    result = true;
                }
            }

            return(result);
        }
Example #4
0
        /// <summary>
        /// 选中了某个Action
        /// </summary>
        /// <param name="sender">事件发送者</param>
        /// <param name="e">事件参数</param>
        private void RefreshActionInfo(object sender, AdvTreeNodeEventArgs e)
        {
            Node currentNode = actionTree.SelectedNode;

            if (currentNode != null && currentNode.Level == 1)
            {
                AI_Action act = actionTable[currentNode.Tag.ToString()] as AI_Action;

                if (act != null)
                {
                    if (act.Equals(singleAction.Action))
                    {
                        ShowActionData(singleAction.Action);
                    }
                    else
                    {
                        ShowActionData(act);
                    }
                }
            }
            else
            {
                for (int i = 0; i < 5; i++)
                {
                    labelArray[i].Text       = "-";
                    comboBoxArray[i].Text    = "";
                    comboBoxArray[i].Enabled = false;
                }
            }
        }
Example #5
0
        /// <summary>
        /// 比较对象
        /// </summary>
        /// <param name="obj">对象</param>
        /// <returns>是否相等</returns>
        public override bool Equals(object obj)
        {
            bool result = false;

            AI_Action action = obj as AI_Action;

            if (action != null && this.DBID == action.DBID)
            {
                result = true;
            }

            return(result);
        }
Example #6
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 #7
0
        /// <summary>
        /// 刷新动作数据
        /// </summary>
        public void Reload()
        {
            AI_Action action = ActionTable.FindItemByDBID(this.DBID);

            if (action != null)
            {
                this.ActionID   = action.ActionID;
                this.Name       = action.Name;
                this.Ename      = action.Ename;
                this.Info       = action.Info;
                this.ActionType = action.ActionType;
                this.rettype    = action.rettype;
            }
        }
Example #8
0
        /// <summary>
        /// 索引动作数据
        /// </summary>
        /// <param name="DBID">KeyID</param>
        /// <returns>动作数据</returns>
        public static AI_Action FindItemByDBID(string databaseID)
        {
            AI_Action aiAction = null;

            if (!string.IsNullOrEmpty(databaseID))
            {
                Init();

                if (!actionDictionary.TryGetValue(databaseID, out aiAction))
                {
                    aiAction = null;
                }
            }

            return(aiAction);
        }
Example #9
0
        /// <summary>
        /// 初始化数据
        /// </summary>
        private void Init()
        {
            // 初始化控件
            codeEditBox.ForWho  = "GameLuaEditor";
            labelArray          = new LabelX[] { labelX2, labelX3, labelX4, labelX5, labelX6 };
            comboBoxArray       = new ComboBoxEx[] { comboBoxEx1, comboBoxEx2, comboBoxEx3, comboBoxEx4, comboBoxEx5 };
            checkBoxArray       = new CheckBoxX[] { checkBoxX1, checkBoxX2, checkBoxX3, checkBoxX4, checkBoxX5 };
            returnValueBoxArray = new TextBox[] { returnValue1Box, returnValue2Box, returnValue3Box };

            foreach (AI_Action action in ActionTable.ActionItems)
            {
                Node classNode = null;

                foreach (Node node in actionTree.Nodes)
                {
                    if (node.Text == action.ActionType)
                    {
                        classNode = node;
                        break;
                    }
                }

                if (classNode == null)
                {
                    classNode      = new Node();
                    classNode.Text = action.ActionType;
                    actionTree.Nodes.Add(classNode);
                }

                Node newNode = new Node();
                newNode.Text = action.Name;
                newNode.Tag  = action.DBID;
                classNode.Nodes.Add(newNode);

                AI_Action newAction = action.Clone() as AI_Action;
                actionTable[action.DBID] = newAction;
                actionComboBox.Items_Add(newAction);
            }

            // 展开所有的分类结点
            foreach (Node classNode in actionTree.Nodes)
            {
                classNode.Expand();
            }

            beginEdit = true;
        }
Example #10
0
        public List <AI_Parm> Args = new List <AI_Parm>(); //保存动作输入的参数的值

        // 复制AI动作
        public object Clone()
        {
            AI_Action action = new AI_Action();

            action.DBID       = this.DBID;
            action.ActionID   = this.ActionID;
            action.Name       = this.Name;
            action.Ename      = this.Ename;
            action.Info       = this.Info;
            action.rettype    = this.rettype;
            action.ActionType = this.ActionType;

            foreach (AI_Parm parm in this.Args)
            {
                action.Args.Add(parm.Clone() as AI_Parm);
            }

            return(action);
        }
Example #11
0
 /// <summary>
 /// 构造函数
 /// </summary>
 public AI_SingleAction()
 {
     Action = new AI_Action();
 }
Example #12
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();
            }
        }
Example #13
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 #14
0
        /// <summary>
        /// 选择确定
        /// </summary>
        /// <param name="sender">事件发送者</param>
        /// <param name="e">事件参数</param>
        private void buttonX1_Click(object sender, EventArgs e)
        {
            AI_Action newAction = null;

            if (tabControl1.SelectedTabIndex == 0) // 选择系统Action
            {
                Node currentNode = actionTree.SelectedNode;

                if (currentNode != null && currentNode.Level == 1)
                {
                    AI_Action selectedAction = actionTable[currentNode.Tag.ToString()] as AI_Action;                

                    if (selectedAction != null)
                    {                   
                        // 第一步,检查输入数据正确性
                        for (int i = 0; i < selectedAction.Args.Count; i++)
                        {
                            if (!CheckParameterValid(selectedAction.Args[i].m_type, comboBoxArray[i].Text, checkBoxArray[i].Checked))
                            {
                                MessageBox.Show(string.Format("{0}参数值无效!", labelArray[i].Text), "参数检查",
                                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                                comboBoxArray[i].Focus();

                                return;
                            }
                        }

                        // 第二步,把输入数据存到Action里
                        newAction = selectedAction.Clone() as AI_Action;

                        for (int i = 0; i < newAction.Args.Count; i++)
                        {
                            AI_Parm parm = newAction.Args[i];
                            object objSelect = comboBoxArray[i].SelectedItem;

                            if (comboBoxArray[i].Text.StartsWith("<") && comboBoxArray[i].Text.EndsWith(">")) // 模板参数
                            {
                                if (checkBoxArray[i].Checked)
                                {
                                    MessageBox.Show("模板参数不能为变量类型!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    comboBoxArray[i].Focus();

                                    return;
                                }

                                parm.m_IsTemplateParm = true;
                                AI_TemplateParmItem tpitem = objSelect as AI_TemplateParmItem;

                                if (objSelect == null)
                                {
                                    MessageBox.Show("参数错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    comboBoxArray[i].Focus();

                                    return;
                                }

                                int index = AI_TemplateParmTable.GetAIParamTemplateTable().GetAIParamIndex(tpitem.Name);
                                parm.SetTemplateValue(index.ToString());
                            }
                            else // 非模板参数
                            {
                                parm.m_IsTemplateParm = false;

                                if (objSelect == null) // 是填的,不是选的,那就是字符串或者数字了
                                {
                                    parm.m_Value = comboBoxArray[i].Text;
                                }
                                else if (objSelect is EnumItem) // 是枚举
                                {
                                    EnumItem ei = objSelect as EnumItem;
                                    parm.m_Value = ei.m_asParentsPos.ToString();
                                }
                            }

                            // 记录下是否是变量类型
                            parm.IsVar = checkBoxArray[i].Checked;
                        }                                                
                    }
                }
                else
                {
                    MessageBox.Show("请先选择动作!", "参数检查", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }                
            }
            else // 选择自定义Action
            {
                string functionName = actionNameBox.Text;
                string functionText = codeEditBox.Text;
                string returnValue = "";

                if (functionName == "")
                {
                    MessageBox.Show("动作名不能为空!", "参数检查", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (functionText == "")
                {
                    MessageBox.Show("自定义脚本不能为空!", "参数检查", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                for (int i = 0; i < 3; i++)
                {
                    if (returnValueBoxArray[i].Text.Trim() != "")
                    {
                        returnValue += string.Format("{0},", returnValueBoxArray[i].Text.Trim());
                    }
                    else
                    {
                        break;
                    }
                }
                returnValue = returnValue.TrimEnd(new char[] { ',' });

                if (returnValue == "")
                {
                    MessageBox.Show("至少需要有一个返回值!", "参数检查", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }               
                
                int actionID = graphElementID + 2000;

                if (inActionGroup) // 动作组内的自定义动作需要重新分配ID
                {
                    actionID = (graphElementID + 2000) * 10 + groupIndex;
                }

                string englishName = GetFunctionName(functionText);

                if (!CheckScriptValid(functionText)) // 检查脚本有效性
                {
                    MessageBox.Show("脚本必须在最后明确返回执行结果(如:return 1)!", "脚本检查", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (!AIDiagramHelper.CheckScript(codeEditBox, functionText)) // 没有通过脚本检查
                {
                    if (MessageBox.Show("没有通过脚本检查,是否重新编辑脚本?", "脚本检查", 
                                        MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                    {
                        return;
                    }
                }

                newAction = new AI_Action();
                newAction.ActionID = actionID.ToString();
                newAction.Name = functionName;
                newAction.Info = functionText;
                newAction.Ename = englishName;
                newAction.Args = new List<AI_Parm>();
                newAction.rettype = returnValue;
            }

            singleAction.Action = newAction;
            editSuccess = true;
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
Example #15
0
        /// <summary>
        /// 显示AI动作的数据
        /// </summary>
        /// <param name="action">AI动作</param>
        private void ShowActionData(AI_Action action)
        {            
            this.textBoxX1.Text = action.Info;

            for (int i = 0 ; i < 5; i++)
            {
                // 多余的参数,禁止掉
                if (i >= action.Args.Count)
                {
                    labelArray[i].Text = "-";
                    comboBoxArray[i].Text = "";
                    comboBoxArray[i].Enabled = false;
                    checkBoxArray[i].Checked = false;
                    checkBoxArray[i].Enabled = false;
                }
                else
                {
                    AI_Parm parm = action.Args[i];

                    // 步骤1:初始化枚举(常数)列表 如果是枚举,则添加枚举项进来。
                    comboBoxArray[i].Enabled = true;
                    comboBoxArray[i].Items.Clear();

                    if (parm.m_type > 0)
                    {
                        comboBoxArray[i].Items.AddRange(EnumTable.GetEnumTypeByID(parm.m_type.ToString()).Items.ToArray());
                    }

                    // 改标签
                    string strLab = null ;

                    switch (parm.m_type)
                    {
                        case -1:
                            {
                                strLab = "数字";

                                // 目前只支持数字的变量类型
                                checkBoxArray[i].Enabled = true;

                                break;
                            }
                        case -2:
                            {
                                strLab = "字符串";

                                // 暂时不支持字符串的变量类型
                                checkBoxArray[i].Enabled = false;

                                break;
                            }
                        default: 
                            {
                                strLab = "枚举";

                                // 暂时不支持枚举的变量类型
                                checkBoxArray[i].Enabled = false;

                                break;
                            }
                    }

                    if (parm.Name.Length > 10)
                    {
                        labelArray[i].Text = string.Format("{0}... ({1})", parm.Name.Substring(0, 8), strLab);
                    }
                    else
                    {
                        labelArray[i].Text = string.Format("{0} ({1})", parm.Name, strLab);
                    }

                    // 步骤2:初始化 模板参数,如果定义了这种类型的模板变量,就加进来。    
                    comboBoxArray[i].Items.AddRange(AI_TemplateParmTable.GetAIParamTemplateTable().AIParamItemList.ToArray());

                    // 步骤3:设值
                    if (parm.Value != null)
                    {
                        comboBoxArray[i].Text = parm.Value.ToString();
                    }
                    else
                    {
                        comboBoxArray[i].Text = "";
                    }

                    // 步骤4:读取参数类型
                    checkBoxArray[i].Checked = parm.IsVar;
                }                
            } 
        }
Example #16
0
        /// <summary>
        /// 初始化数据
        /// </summary>
        private static void Init()
        {
            if (!inited)
            {
                DataTable actionInfo = DBManager.DataBaseManager.GetDataBaseManager().GetTable_AI_Action_Define();

                foreach (DataRow dataRow in actionInfo.Rows)
                {
                    AI_Action aiAction = new AI_Action();
                    aiAction.DBID = dataRow["id"].ToString();
                    aiAction.ActionID = dataRow["actionid"].ToString();
                    aiAction.Name = dataRow["name"].ToString();
                    aiAction.Ename = dataRow["ename"].ToString();
                    aiAction.Info = dataRow["info"].ToString();
                    aiAction.ActionType = dataRow["class"].ToString();
                    aiAction.rettype = dataRow["rettype"].ToString();

                    string parms = dataRow["parms"].ToString();

                    foreach (string line in parms.Split(parameterSpliter, StringSplitOptions.RemoveEmptyEntries))
                    {
                        // line: 姓名,-2,"张三"
                        string sline = line + ",";
                        string[] strlist = sline.Split(parameterInfoSpliter);
                        aiAction.Args.Add(new AI_Parm(strlist[0], strlist[2] == "" ? null : strlist[2], int.Parse(strlist[1]), false));
                    }

                    actionList.Add(aiAction);
                    actionDictionary[aiAction.DBID] = aiAction;
                }

                inited = true;
            }
        }
Example #17
0
        public List<AI_Parm> Args = new List<AI_Parm>(); //保存动作输入的参数的值

        // 复制AI动作
        public object Clone()
        {
            AI_Action action = new AI_Action();
            action.DBID = this.DBID;
            action.ActionID = this.ActionID;
            action.Name = this.Name;
            action.Ename = this.Ename;
            action.Info = this.Info;
            action.rettype = this.rettype;
            action.ActionType = this.ActionType;

            foreach (AI_Parm parm in this.Args)
            {
                action.Args.Add(parm.Clone() as AI_Parm);
            }

            return action;
        }
Example #18
0
 /// <summary>
 /// 重命名AI动作
 /// </summary>
 /// <param name="singleAction">AI动作</param>
 /// <param name="newName">新的动作名</param>
 /// <param name="actionID">新的动作ID</param>
 private void RenameAIAction(AI_Action aiAction, string newName, int actionID)
 {
     if (int.Parse(aiAction.ActionID) > 2000) // 脚本自定义动作,需要重命名
     {
         string script = aiAction.Info;
         string actionName = aiAction.Ename;
         aiAction.Info = script.Replace(aiAction.Ename, newName);
         aiAction.Ename = newName;
         aiAction.ActionID = actionID.ToString();
     }
 }
Example #19
0
        /// <summary>
        /// 选择确定
        /// </summary>
        /// <param name="sender">事件发送者</param>
        /// <param name="e">事件参数</param>
        private void buttonX1_Click(object sender, EventArgs e)
        {
            AI_Action newAction = null;

            if (tabControl1.SelectedTabIndex == 0) // 选择系统Action
            {
                Node currentNode = actionTree.SelectedNode;

                if (currentNode != null && currentNode.Level == 1)
                {
                    AI_Action selectedAction = actionTable[currentNode.Tag.ToString()] as AI_Action;

                    if (selectedAction != null)
                    {
                        // 第一步,检查输入数据正确性
                        for (int i = 0; i < selectedAction.Args.Count; i++)
                        {
                            if (!CheckParameterValid(selectedAction.Args[i].m_type, comboBoxArray[i].Text, checkBoxArray[i].Checked))
                            {
                                MessageBox.Show(string.Format("{0}参数值无效!", labelArray[i].Text), "参数检查",
                                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                                comboBoxArray[i].Focus();

                                return;
                            }
                        }

                        // 第二步,把输入数据存到Action里
                        newAction = selectedAction.Clone() as AI_Action;

                        for (int i = 0; i < newAction.Args.Count; i++)
                        {
                            AI_Parm parm      = newAction.Args[i];
                            object  objSelect = comboBoxArray[i].SelectedItem;

                            if (comboBoxArray[i].Text.StartsWith("<") && comboBoxArray[i].Text.EndsWith(">")) // 模板参数
                            {
                                if (checkBoxArray[i].Checked)
                                {
                                    MessageBox.Show("模板参数不能为变量类型!", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    comboBoxArray[i].Focus();

                                    return;
                                }

                                parm.m_IsTemplateParm = true;
                                AI_TemplateParmItem tpitem = objSelect as AI_TemplateParmItem;

                                if (objSelect == null)
                                {
                                    MessageBox.Show("参数错误", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    comboBoxArray[i].Focus();

                                    return;
                                }

                                int index = AI_TemplateParmTable.GetAIParamTemplateTable().GetAIParamIndex(tpitem.Name);
                                parm.SetTemplateValue(index.ToString());
                            }
                            else // 非模板参数
                            {
                                parm.m_IsTemplateParm = false;

                                if (objSelect == null) // 是填的,不是选的,那就是字符串或者数字了
                                {
                                    parm.m_Value = comboBoxArray[i].Text;
                                }
                                else if (objSelect is EnumItem) // 是枚举
                                {
                                    EnumItem ei = objSelect as EnumItem;
                                    parm.m_Value = ei.m_asParentsPos.ToString();
                                }
                            }

                            // 记录下是否是变量类型
                            parm.IsVar = checkBoxArray[i].Checked;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("请先选择动作!", "参数检查", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
            }
            else // 选择自定义Action
            {
                string functionName = actionNameBox.Text;
                string functionText = codeEditBox.Text;
                string returnValue  = "";

                if (functionName == "")
                {
                    MessageBox.Show("动作名不能为空!", "参数检查", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (functionText == "")
                {
                    MessageBox.Show("自定义脚本不能为空!", "参数检查", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                for (int i = 0; i < 3; i++)
                {
                    if (returnValueBoxArray[i].Text.Trim() != "")
                    {
                        returnValue += string.Format("{0},", returnValueBoxArray[i].Text.Trim());
                    }
                    else
                    {
                        break;
                    }
                }
                returnValue = returnValue.TrimEnd(new char[] { ',' });

                if (returnValue == "")
                {
                    MessageBox.Show("至少需要有一个返回值!", "参数检查", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                int actionID = graphElementID + 2000;

                if (inActionGroup) // 动作组内的自定义动作需要重新分配ID
                {
                    actionID = (graphElementID + 2000) * 10 + groupIndex;
                }

                string englishName = GetFunctionName(functionText);

                if (!CheckScriptValid(functionText)) // 检查脚本有效性
                {
                    MessageBox.Show("脚本必须在最后明确返回执行结果(如:return 1)!", "脚本检查", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (!AIDiagramHelper.CheckScript(codeEditBox, functionText)) // 没有通过脚本检查
                {
                    if (MessageBox.Show("没有通过脚本检查,是否重新编辑脚本?", "脚本检查",
                                        MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
                    {
                        return;
                    }
                }

                newAction          = new AI_Action();
                newAction.ActionID = actionID.ToString();
                newAction.Name     = functionName;
                newAction.Info     = functionText;
                newAction.Ename    = englishName;
                newAction.Args     = new List <AI_Parm>();
                newAction.rettype  = returnValue;
            }

            singleAction.Action = newAction;
            editSuccess         = true;
            this.DialogResult   = DialogResult.OK;
            this.Close();
        }
Example #20
0
        /// <summary>
        /// 显示AI动作的数据
        /// </summary>
        /// <param name="action">AI动作</param>
        private void ShowActionData(AI_Action action)
        {
            this.textBoxX1.Text = action.Info;

            for (int i = 0; i < 5; i++)
            {
                // 多余的参数,禁止掉
                if (i >= action.Args.Count)
                {
                    labelArray[i].Text       = "-";
                    comboBoxArray[i].Text    = "";
                    comboBoxArray[i].Enabled = false;
                    checkBoxArray[i].Checked = false;
                    checkBoxArray[i].Enabled = false;
                }
                else
                {
                    AI_Parm parm = action.Args[i];

                    // 步骤1:初始化枚举(常数)列表 如果是枚举,则添加枚举项进来。
                    comboBoxArray[i].Enabled = true;
                    comboBoxArray[i].Items.Clear();

                    if (parm.m_type > 0)
                    {
                        comboBoxArray[i].Items.AddRange(EnumTable.GetEnumTypeByID(parm.m_type.ToString()).Items.ToArray());
                    }

                    // 改标签
                    string strLab = null;

                    switch (parm.m_type)
                    {
                    case -1:
                    {
                        strLab = "数字";

                        // 目前只支持数字的变量类型
                        checkBoxArray[i].Enabled = true;

                        break;
                    }

                    case -2:
                    {
                        strLab = "字符串";

                        // 暂时不支持字符串的变量类型
                        checkBoxArray[i].Enabled = false;

                        break;
                    }

                    default:
                    {
                        strLab = "枚举";

                        // 暂时不支持枚举的变量类型
                        checkBoxArray[i].Enabled = false;

                        break;
                    }
                    }

                    if (parm.Name.Length > 10)
                    {
                        labelArray[i].Text = string.Format("{0}... ({1})", parm.Name.Substring(0, 8), strLab);
                    }
                    else
                    {
                        labelArray[i].Text = string.Format("{0} ({1})", parm.Name, strLab);
                    }

                    // 步骤2:初始化 模板参数,如果定义了这种类型的模板变量,就加进来。
                    comboBoxArray[i].Items.AddRange(AI_TemplateParmTable.GetAIParamTemplateTable().AIParamItemList.ToArray());

                    // 步骤3:设值
                    if (parm.Value != null)
                    {
                        comboBoxArray[i].Text = parm.Value.ToString();
                    }
                    else
                    {
                        comboBoxArray[i].Text = "";
                    }

                    // 步骤4:读取参数类型
                    checkBoxArray[i].Checked = parm.IsVar;
                }
            }
        }