//通用,完整参数版 public ExpForm(Exp exp, GameEvent gameEvent, bool showThisEvent, TypeDefine requireRetType, VarExp vexp) { this.m_showThisEvent = showThisEvent; this.m_requireRetType = requireRetType; this.VExp = vexp; ExpForm_Show(exp, gameEvent); }
public SelectionForm(Exp selExp, List<Exp> list) { this.DialogResult = DialogResult.Cancel; InitializeComponent(); this.listBox1.Items.AddRange(list.ToArray()); listBox1.SelectedItem = selExp; }
private void buttonX1_Click(object sender, EventArgs e) { if(listBox1.SelectedItem != null) { this.ResultExp = listBox1.SelectedItem as Exp; this.DialogResult = DialogResult.OK; this.Close(); } }
public ConditionForm(Exp actexp, GameEvent gameEvent, List<Exp> ConditionList) { InitializeComponent(); this.m_actexp = actexp; this.m_elist = ConditionList; this.m_gameEvent = gameEvent; this.textBoxX1.Text = m_actexp.ToString(); this.listBox1.Items.AddRange(ConditionList.ToArray()); }
public static string ExpToString(Exp exp) { if(exp is ActionExp) { ActionExp aexp = exp as ActionExp; string strRet = string.Format("API.fun_{0}_{1}(",aexp.API.DBID, aexp.API.strName); if (aexp.API.isAsyn) { strRet += "context, "; } foreach ( Exp e in aexp.API.ArgValues) { strRet += ExpToString(e) + ", "; } strRet = strRet.TrimEnd(new char[] { ' ', ',' }); strRet += ")"; if (aexp.API.isAsyn) { strRet = "(function() local argslist = SaveArgsToID(arg) local tmp = " + strRet + " arg = RestoreArgsFromID(argslist) return tmp end)()"; } return strRet; } else if (exp is ConstExp) { ConstExp cexp = exp as ConstExp; /*int[] strIDList = new int[] { 04, 27, 13 ,28, 32, 33, 36, 37, 39, 40, 41, 45, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 80, 81, 82, 83, 85 }; //需要生成时加双引号的类型的ID List<int> l = new List<int>(); l.AddRange(strIDList); if (l.Contains(cexp.ReturnType.DBID)) //字符串,加引号 { return string.Format("\"{0}\"", cexp.DBValue.Replace("\"", "\\\"")); } else { return cexp.DBValue; }*/ if(cexp.ReturnType.genAsString) // 字符串加引号 { return string.Format("\"{0}\"", cexp.DBValue.Replace("\"", "\\\"")); } else { return cexp.DBValue; } } else if (exp is ObjectExp) { return string.Format("arg[{0}]", (exp as ObjectExp).AsEventArgPos + 1); //是事件的第几个参数, 0是第1个 } else if( exp is VarExp) { return "ret"; } else { return ""; } }
//根据表达式获取 常数列表 public static ArrayList GetConstCollectionFromExp(Exp exp) { ArrayList al_ret = new ArrayList(); if (exp is ActionExp) { ActionExp aexp = exp as ActionExp; if (aexp != null) { foreach (Exp e in aexp.API.ArgValues) { ArrayList al = GetConstCollectionFromExp(e); foreach (Exp expadd in al) { if (!al_ret.Contains(expadd)) al_ret.Add(expadd); } } } } else if (exp is ConstExp) { ConstExp cexp = exp as ConstExp; if (!al_ret.Contains(cexp)) al_ret.Add(cexp); } else if (exp is ObjectExp) { } else if (exp is VarExp) { } else { } return al_ret; }
public void ExpForm_Show(Exp exp, GameEvent gameEvent) { System.Diagnostics.Debug.Assert(exp != null); System.Diagnostics.Debug.Assert(gameEvent != null); InitializeComponent(); this.expControl1.VExp = this.VExp; enableAPIListChange = false; this.m_eventDefine = gameEvent; this.m_exp = exp.Clone() as Exp; if(exp.ReturnType == null) { this.Text = "任意表达式"; } else { this.Text = exp.ReturnType.ToString() + " 表达式"; } this.DialogResult = DialogResult.Cancel; // 刷新功能列表 GameAPIDefine[] ret; if(this.m_requireRetType == null) // 表达式类型未知,用于条件判断中输入未知类型的节点用。 { // 获取所有有返回值的API // ret = ExpManager.GetAPIDefineListExceptReturnType(TypeDefine.NilType); 如果只能选有返回值的API的话,那么几乎每个有返回值API都要做一个无返回值的版本才能在动作组里没选到, // 这样会带来很大的维护工作量,所以修正为可以选择所有的API。 ret = ExpManager.GetAPIDefine_All(); this.radioConst.Enabled = false; this.radioConstSel.Enabled = false; this.comboBoxConst.Enabled = false; this.txtConst.Enabled = false; this.btnSelect.Enabled = false; this.comboBoxAPI.TabIndex = 2; } else { // 专用API列出来 ret = ExpManager.GetAPIDefineByReturnType(exp.ReturnType); } if (ret != null) { comboBoxAPI.Items_AddRange(Helper.SortByToString(ret)); } // 刷新常数列表 if (exp.ReturnType != null) { if (exp.ReturnType.isEnum) { this.txtConst.Enabled = false; this.radioConst.Enabled = false; ConstExp[] const_ret = ExpManager.GetConstExpByReturnType(exp.ReturnType); if (const_ret != null) comboBoxConst.Items.AddRange(const_ret); if (comboBoxConst.Items.Count > 0) comboBoxConst.SelectedItem = comboBoxConst.Items[0]; if (!exp.ReturnType.ContainsValueEdit) this.btnSelect.Enabled = false; } else { this.comboBoxConst.Enabled = false; this.radioConstSel.Enabled = false; this.btnSelect.Enabled = false; if (exp.ReturnType.ContainsValueEdit) this.btnInput.Enabled = true; } } //刷新本事件列表 if(this.m_showThisEvent) { for (int i = 0; i < gameEvent.ArgList.Length; i++) { if (exp.ReturnType == null || gameEvent.ArgList[i].ArgType.DBID == exp.ReturnType.DBID) { comboBoxEventArg.Items.Add(gameEvent.GetArgExp(i + 1)); } if (comboBoxEventArg.Items.Count > 0) comboBoxEventArg.SelectedItem = comboBoxEventArg.Items[0]; } //对任意类型的支持,在这里可以选到 if (this.VExp != null) { if (exp.ReturnType == null || this.VExp.ReturnType== null || this.VExp.ReturnType.DBID == exp.ReturnType.DBID) { comboBoxEventArg.Items.Add(this.VExp); } } } //灰掉某些东东 if (comboBoxAPI.Items_Count == 0) { //灰掉API comboBoxAPI.Enabled = false; radioExp.Enabled = false; } //灰掉常数 if (comboBoxConst.Items.Count == 0)// && exp.ReturnType.m_isEnum) comboBoxConst.Enabled = false; if (exp.ReturnType == null || !exp.ReturnType.isDuplicate) txtConst.Enabled = false; if (txtConst.Enabled == false && comboBoxConst.Enabled == false) radioConst.Enabled = false; //灰掉本事件 if (comboBoxEventArg.Items.Count == 0) { comboBoxEventArg.Enabled = false; radioEventArg.Enabled = false; } //自动选中API if (m_exp is ActionExp) { foreach (GameAPIDefine apidefine in comboBoxAPI.Items_All) { if (apidefine.DBID == (m_exp as ActionExp).API.DBID) { this.comboBoxAPI.Text = apidefine.ToString() + " "; //this.comboBoxAPI.Items; break; } } this.expControl1.SetComboText(m_exp as ActionExp, this.m_eventDefine); this.expControl1.VExp = this.VExp; this.radioExp.Checked = true; //this.expControl1.Focus(); this.m_FousedControl = this.expControl1; } //自动选中常数 if (m_exp is ConstExp) { ConstExp conExp = m_exp as ConstExp; if (conExp.ReturnType.isEnum) { if(conExp.ReturnType.ContainsValueEdit) //使用lua脚本编辑 { this.comboBoxConst.Items.Clear(); this.comboBoxConst.Items.Add(conExp); this.comboBoxConst.SelectedItem = conExp; //this.comboBoxConst.Enabled = true; } else //使用下拉菜单编辑 { foreach (ConstExp ex in comboBoxConst.Items) { if (ex.DBValue == conExp.DBValue) { this.comboBoxConst.SelectedItem = ex; break; } } if (this.comboBoxConst.SelectedItem == null && comboBoxConst.Items.Count > 0) comboBoxConst.SelectedItem = comboBoxConst.Items[0]; } this.radioConstSel.Checked = true; this.m_FousedControl = this.radioConstSel; } else { this.txtConst.Text = m_exp.strText; this.radioConst.Checked = true; //this.radioConst.Focus(); //this.txtConst.Focus(); this.m_FousedControl = this.txtConst; } } //自动选中本事件 if (m_exp is ObjectExp) { ObjectExp oExp = m_exp as ObjectExp; foreach (ObjectExp ex in comboBoxEventArg.Items) { if (ex.AsEventArgPos == oExp.AsEventArgPos) { this.comboBoxEventArg.SelectedItem = ex; break; } } this.radioEventArg.Checked = true; //this.comboBoxEventArg.Focus(); this.m_FousedControl = this.comboBoxEventArg; } //自动选中无类型变量 if (m_exp is VarExp) { foreach (Exp ex in comboBoxEventArg.Items) { if (ex is VarExp) { this.comboBoxEventArg.SelectedItem = ex; } } this.radioEventArg.Checked = true; this.m_FousedControl = this.comboBoxEventArg; } if (!this.radioConst.Checked && !this.radioEventArg.Checked && !this.radioEventArg.Checked && !this.radioExp.Checked) { this.radioConst.Checked = true; this.m_FousedControl = txtConst; } enableAPIListChange = true; this.comboBoxAPI.SelectedIndexChanged += new System.EventHandler(this.comboBoxAPI_SelectedIndexChanged); }
private void btnOK_Click(object sender, EventArgs e) { if (!(this.radioConstSel.Checked || this.radioExp.Checked || this.radioConst.Checked || this.radioEventArg.Checked)) { MessageBox.Show("必须先选择一个。","错误",MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (this.radioExp.Checked) { //if (!expControl1.GetReady) //{ // MessageBox.Show("请输入完整", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); // return; //} this.m_exp = expControl1.ActionExp; } else if (this.radioConst.Checked) { if(txtConst.Text == "") { MessageBox.Show("请输入完整", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.m_exp = new ConstExp(txtConst.Text, m_exp.ReturnType); } else if (this.radioConstSel.Checked) { if (this.comboBoxConst.SelectedItem == null) { MessageBox.Show("输入不完整,请选择", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.m_exp = this.comboBoxConst.SelectedItem as Exp; } else if (this.radioEventArg.Checked) { if (this.comboBoxEventArg.SelectedItem == null) { MessageBox.Show("输入不完整,请选择", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } this.m_exp = this.comboBoxEventArg.SelectedItem as Exp; } this.DialogResult = DialogResult.OK; this.Close(); }
public virtual object Clone() { Exp e = new Exp(); e.ReturnType = this.ReturnType; return e; }
//从数据库中重读Exp的未序列化信息 public static void ReloadExp(Exp exp) { if(exp is ConstExp) { ConstExp cexp = exp as ConstExp; cexp.Reload(); cexp.ReturnType.Reload(); } if(exp is ObjectExp) { ObjectExp oexp = exp as ObjectExp; oexp.ReturnType.Reload(); oexp.Parent.Reload(); } if(exp is ActionExp) { ActionExp aexp = exp as ActionExp; aexp.API.Reload(); aexp.ReturnType.Reload(); foreach(Exp ex in aexp.API.ArgValues) { ReloadExp(ex); } } }
//扫描表达式的常量,保存到本图引用列表 public static void ScanConstantIntoHistory(Exp exp) { //保存结构: // ht_history = { type_id : ht } // ht = { dbvalue : const_exp } Hashtable ht_history = CacheManager.GetCacheManager().Global_Args_Table; if (exp is ConstExp) { ConstExp cexp = exp as ConstExp; if(!ht_history.ContainsKey(cexp.ReturnType.DBID)) { Hashtable ht = new Hashtable(); ht.Add(cexp.DBValue, cexp); ht_history.Add(cexp.ReturnType.DBID, ht); } else { Hashtable ht = ht_history[cexp.ReturnType.DBID] as Hashtable; if(!ht.ContainsKey(cexp.DBValue)) { ht.Add(cexp.DBValue, cexp); } } } if (exp is ObjectExp) { //do nothing } if (exp is ActionExp) { ActionExp aexp = exp as ActionExp; foreach (Exp ex in aexp.API.ArgValues) { ScanConstantIntoHistory(ex); } } }
//创建一个未知返回值的表达式 public static Exp CreateUnknownExp() { Exp e = new Exp(); e.ReturnType = null; return e; }
//创建一个空表达式 public static Exp CreateNewExp(TypeDefine returnType) { Exp e = new Exp(); e.ReturnType = returnType; return e; }
private void ModifyExp(int nAsPos, Exp exp) { this.m_actionExp.API.ArgValues[nAsPos] = exp; this.SetComboText(this.m_actionExp,this.m_eventDefine); //自动放置焦点 int n = 0; foreach(Control c in this.Controls) { if (c is LinkLabel) { n++; if (n > nAsPos) { (c as LinkLabel).Focus(); break; } } } }
private void btnExp_Click(object sender, EventArgs e) { ExpForm expform = new ExpForm(this.m_actexp, this.m_gameEvent, true, null, null); expform.StartPosition = FormStartPosition.CenterParent; if (expform.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (this.m_actexp.ReturnType != null && this.m_actexp.ReturnType.DBID != expform.RusultExp.ReturnType.DBID) { //清空连接线 this.listBox1.Items.Clear(); } this.m_actexp = expform.RusultExp; this.m_Vexp.ReturnType = this.m_actexp.ReturnType; //可变类型的返回值和表达式一致 this.textBoxX1.Text = this.m_actexp.ToString(); this.m_bChanged = true; } else { return; } //自动添加分支 if (this.m_actexp != null && this.m_actexp.ReturnType != null) { //尝试添加枚举的所有类型 if (this.m_actexp.ReturnType.isEnum) { ConstExp[] cexpArray = ExpManager.GetConstExpByReturnType(this.m_actexp.ReturnType); if (cexpArray != null) { foreach (ConstExp cexp in cexpArray) { ActionExp expa = ExpManager.CreateNewActionExp(new GameAPIDefine(FixedValueProvider.COMPARE_API_ID)); expa.API.ArgValues[0] = m_Vexp; //左值为可变类型 expa.API.ArgValues[1] = cexp; //右值为常数值 expa.strText = m_Vexp.ToString() + "==" + cexp.ToString(); if (!listBox1.Items.Contains(expa)) { this.listBox1.Items.Add(expa); this.m_bChanged = true; } } } } //尝试添加OpenWindow的选项 if (this.m_actexp is ActionExp) { ActionExp aexp = this.m_actexp as ActionExp; if (aexp.API.DBID == FixedValueProvider.OPENWINDOW_ID) //多选项窗口 { Exp dialogExp = aexp.API.ArgValues[2]; //第三个参数 if (dialogExp is ConstExp) //如果格式文本输入的是常数才处理 { string strDialog = (dialogExp as ConstExp).DBValue; Regex reg = new Regex(@"(?!=<)\$[^>]*(?=>)"); foreach (Match mat in reg.Matches(strDialog)) { string strSelection = mat.Value.TrimStart(new char[] { '$', 'C', ' ' }); ActionExp expa = ExpManager.CreateNewActionExp(new GameAPIDefine(FixedValueProvider.COMPARE_API_ID)); expa.API.ArgValues[0] = m_Vexp; //左值为可变类型 ConstExp cexp = new ConstExp(strSelection, new TypeDefine(FixedValueProvider.TYPE_STRING_ID)); m_Vexp.ReturnType = cexp.ReturnType; expa.API.ArgValues[1] = cexp; //右值为字符串 expa.strText = m_Vexp.ToString() + "==" + cexp.ToString(); if (!listBox1.Items.Contains(expa)) { this.listBox1.Items.Add(expa); this.m_bChanged = true; } } } } } } }