/// <summary> /// 选择确定 /// </summary> /// <param name="sender">事件发送者</param> /// <param name="e">事件参数</param> private void buttonX1_Click(object sender, EventArgs e) { if (tabControl1.SelectedTabIndex == 0) // 当前是否在编辑脚本 { if (!AIDiagramHelper.CheckScript(codeEditBox, codeEditBox.Text)) // 检查脚本 { if (MessageBox.Show("没有通过脚本检查,是否重新编辑脚本?", "脚本检查", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { return; } } } // 保存数据 FlowChartInteractor it = Interactor.GetInteractor().CurrentFlowChartInteractor; if (codeEditBox.Text != "") { it.CustomText = codeEditBox.Text; } this.DialogResult = DialogResult.OK; this.Close(); }
/// <summary> /// 查询对象 /// </summary> /// <param name="sender">事件发送者</param> /// <param name="e">事件参数</param> private void codeEditBox_queryObjects(object sender, luaEditor.QueryEventsArgs e) { AIDiagramHelper.QueryObjects(sender, e); }
/// <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(); }