/// <summary> /// 获取Action的信息 /// </summary> /// <param name="data">Action的数据</param> /// <returns>Action的信息</returns> public static string[] GetActionInformation(object data) { if (data == null || !(data is AI_SingleAction)) { return(null); } AI_SingleAction saction = data as AI_SingleAction; AI_Action action = saction.Action; //获取参数 string strRet = ""; foreach (AI_Parm parm in action.Args) { strRet += parm.Value.GetCode() + ", "; } strRet = strRet.TrimEnd((new char[] { ',', ' ' })); // 返回值包含3个字符串: // 0: Action名 // 1: 参数字符串,已经用,分隔开了 // 2: ActionID // 3: ActionInfo return(new string[] { action.Ename.Trim(), strRet, action.ActionID, action.Info }); }
/// <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; }
/// <summary> /// 获取动作结点返回值个数 /// </summary> /// <param name="data">动作结点数据</param> /// <returns>返回值个数</returns> public static int GetActionRetCount(object data) { int count = 0; if (data != null) { AI_SingleAction saction = data as AI_SingleAction; if (saction != null) { AI_Action action = saction.Action; count = action.RetList.Count; } } return(count); }
/// <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(); } }
/// <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); } }