示例#1
0
        private void comboBoxAPI_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!enableAPIListChange)
            {
                return;
            }
            if (!radioExp.Checked)
            {
                radioExp.Checked = true;
            }

            if (comboBoxAPI.Items_SelectedItem == null)
            {
                return;
            }

            //创建一个空的动作表达式
            ActionExp expAction = ExpManager.CreateNewActionExp(comboBoxAPI.Items_SelectedItem as GameAPIDefine);

            //对比较API不默认赋值
            if (expAction.API.DBID != FixedValueProvider.COMPARE_API_ID)
            {
                //赋默认值(暂时只考虑本事件的参数、数字的情况)
                for (int i = 0; i < expAction.API.ArgList.Length; i++)
                {
                    ArgsDefine ad = expAction.API.ArgList[i];
                    if (!ad.ArgType.isDuplicate)
                    {
                        //本事件的参数
                        for (int j = 0; j < this.m_eventDefine.ArgList.Length; j++)
                        {
                            if (ad.ArgType.DBID == this.m_eventDefine.ArgList[j].ArgType.DBID)
                            {
                                expAction.API.ArgValues[i] = this.m_eventDefine.GetArgExp(j + 1);
                                break;
                            }
                        }
                    }
                    else
                    {
                        //数字、字符串等(其他)常数默认值
                        if (ad.DefaultValue != null && ad.DefaultValue != "-" && ad.DefaultValue != "")
                        {
                            expAction.API.ArgValues[i] = new ConstExp(ad.DefaultValue, ad.ArgType);
                        }
                    }
                }
            }

            //让控件显示这个表达式
            expControl1.SetComboText(expAction, this.m_eventDefine);
        }
示例#2
0
        //左击链接
        void link_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Left)
            {
                return;
            }
            LinkLabel link = sender as LinkLabel;

            if (link.LinkColor == Color.Gray)
            {
                return;                                         //灰色不响应
            }
            Hashtable  ht              = link.Tag as Hashtable;
            Exp        expEdit         = ht["exp"] as Exp;
            int        nAsPos          = Convert.ToInt32(ht["pos"].ToString());
            TypeDefine require_retType = null;

            if (expEdit != null)
            {
                require_retType = expEdit.ReturnType;
            }
            ExpForm expForm = new ExpForm(expEdit, this.m_eventDefine, m_showThisEvent, require_retType, this.VExp);

            //校准坐标
            expForm.Location = PointToScreen(new Point(link.Location.X, link.Location.Y + link.Height));
            int tx = expForm.Location.X;
            int ty = expForm.Location.Y;

            if (tx + expForm.Width > Screen.PrimaryScreen.Bounds.Width)
            {
                tx = tx - expForm.Width + link.Width;
            }
            if (ty + expForm.Height > Screen.PrimaryScreen.Bounds.Height)
            {
                ty = ty - expForm.Height - link.Height;
            }
            expForm.Location = new Point(tx, ty);
            //弹出窗口
            DialogResult dr = expForm.ShowDialog();

            if (dr == DialogResult.OK)
            {
                ExpManager.ScanConstantIntoHistory(expForm.RusultExp);          //把常数添加至历史
                ModifyExp(nAsPos, expForm.RusultExp);
            }
        }
示例#3
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //定义事件
            GameEvent evt = new GameEvent(2);

            //创建一个空的表达式
            Exp exp = ExpManager.CreateNewExp(TypeDefine.NilType);

            //手工创建一个完整的表达式
            ActionExp expa = new ActionExp();

            expa.ReturnType       = exp.ReturnType;
            expa.strText          = "设置 使用者 等于 true";
            expa.API              = new GameAPI(1);
            expa.API.ArgValues[0] = evt.GetArgExp(1);
            expa.API.ArgValues[1] = new ConstExp("true", TypeDefine.BoolType);

            Application.Run(new ExpForm(expa, evt, true, expa.ReturnType, null));
        }
示例#4
0
 public override void Reload()
 {
     base.Reload();
     if (m_eventAPI == null)
     {
         m_eventAPI = GetEventAPI();
     }
     else
     {
         m_eventAPI.Parent   = this;
         m_eventAPI.combText = this.combText;
         m_eventAPI.ArgList  = this.ArgList;
         if (m_eventAPI.ArgValues.Count != m_eventAPI.ArgList.Length)
         {
             //重读后发现事件参数个数变化
             if (m_eventAPI.ArgValues.Count < m_eventAPI.ArgList.Length)
             {
                 for (int i = 0; i < m_eventAPI.ArgList.Length - m_eventAPI.ArgValues.Count; i++)
                 {
                     m_eventAPI.ArgValues.Add(null);
                 }
                 throw new Exception("事件" + this.ToString() + "的参数个数变多了。");
             }
             else
             {
                 throw new Exception("事件" + this.ToString() + "的参数个数变少。原流程图末尾的参数将被删除。");
             }
         }
         foreach (Exp exp in m_eventAPI.ArgValues)
         {
             if (exp != null)
             {
                 ExpManager.ReloadExp(exp);
             }
         }
     }
 }
示例#5
0
        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);
        }
示例#6
0
        //根据表达式显示标签
        public void SetComboText(ActionExp expAction, GameEvent gameEvent)
        {
            Trace.Assert(expAction != null);
            Trace.Assert(gameEvent != null);
            this.m_eventDefine = gameEvent;
            this.m_actionExp   = expAction;
            GameAPI api = expAction.API;

            this.Controls.Clear();
            isReady                 = true;
            m_actionExp.strText     = "";
            m_actionExp.strFullText = "";

            string strComboText = "}" + api.combText;

            string[] tmp = strComboText.Split(new string[] { "{" }, StringSplitOptions.None);
            for (int i = -1; i < tmp.Length - 1; i++)
            {
                string[] strcs = tmp[i + 1].Split(new string[] { "}" }, StringSplitOptions.None);

                //添加热文本
                if (strcs[0] != "")
                {
                    LinkLabel link = new LinkLabel();
                    link.Margin   = new System.Windows.Forms.Padding(0);
                    link.AutoSize = true;
                    link.Tag      = new Hashtable();
                    int nReali = Convert.ToInt32(strcs[0].ToString()) - 1;

                    TypeDefine typed = api.ArgList[nReali].ArgType;
                    if (typed.isEnum || typed.DBID == FixedValueProvider.TYPE_STRING_ID)
                    {
                        //右键菜单
                        ConstExp[] exps = ExpManager.ScanConstantFromHistory(typed);
                        if (exps.Length > 0)
                        {
                            link.ContextMenu = new ContextMenu();
                            for (int it = 0; it < exps.Length; it++)
                            {
                                MenuItem mi = new MenuItem(exps[it].ToString());
                                mi.Tag    = new object[] { nReali, exps[it] };
                                mi.Click += new EventHandler(mi_Click);
                                link.ContextMenu.MenuItems.Add(mi);
                            }
                        }
                    }

                    if (/*api.ArgValues.Count <= i || */ api.ArgValues[nReali] == null)
                    {
                        link.Text      = "<" + api.ArgList[nReali].ArgName + ">";
                        link.LinkColor = Color.Red;
                        (link.Tag as Hashtable)["exp"] = ExpManager.CreateNewExp(api.ArgList[nReali].ArgType);
                        (link.Tag as Hashtable)["pos"] = nReali;
                        isReady = false;
                    }
                    else
                    {
                        link.Text      = api.ArgValues[nReali].ToString();
                        link.LinkColor = Color.Blue;
                        (link.Tag as Hashtable)["exp"] = api.ArgValues[nReali];
                        (link.Tag as Hashtable)["pos"] = nReali;
                    }

                    link.MouseClick     += new MouseEventHandler(link_MouseClick);
                    link.PreviewKeyDown += new PreviewKeyDownEventHandler(link_PreviewKeyDown);
                    this.Controls.Add(link);

                    //追加到显示内容区域
                    //if(link.Text.Length > 25)
                    //    m_actionExp.strText += link.Text.Substring(0,23) + "...";
                    //else
                    //    m_actionExp.strText += link.Text + "";
                    m_actionExp.strText     += link.Text;
                    m_actionExp.strFullText += link.Text;
                }

                //正常文本
                if (strcs[1] != "")
                {
                    Label l = new Label();
                    l.Margin   = new System.Windows.Forms.Padding(0);
                    l.AutoSize = true;
                    l.Text     = strcs[1];
                    this.Controls.Add(l);
                    m_actionExp.strText     += l.Text + "";
                    m_actionExp.strFullText += l.Text;
                    l.Text = l.Text.Replace("\r\n", "");
                }
            }

            //添加换行
            Control br = new Label();

            br.Width  = this.Width - 23;
            br.Height = 0;
            this.Controls.Add(br);

            //添加Tip注释
            Control ltip = new Label();

            ltip.Text      = "\r\n" + expAction.API.strTip;
            ltip.ForeColor = Color.Gray;
            ltip.AutoSize  = true;
            this.Controls.Add(ltip);

            //专门处理比较API
            if (expAction.API.DBID == FixedValueProvider.COMPARE_API_ID)
            {
                LinkLabel left    = this.Controls[0] as LinkLabel;
                LinkLabel right   = this.Controls[2] as LinkLabel;
                Hashtable htleft  = left.Tag as Hashtable;
                Hashtable htright = right.Tag as Hashtable;
                if (left.LinkColor == Color.Red)
                {
                    //左值类型清空
                    htleft["exp"] = ExpManager.CreateUnknownExp();

                    //右侧变灰
                    right.LinkColor = Color.Gray;
                }
                else
                {
                    //右侧的类型跟左侧走
                    (htright["exp"] as Exp).ReturnType = (htleft["exp"] as Exp).ReturnType;

                    //右侧变红
                    if ((htright["exp"] as Exp).strText == null)
                    {
                        right.LinkColor = Color.Red;
                    }
                }
            }
        }