Пример #1
0
        /// <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();
        }
Пример #2
0
        /// <summary>
        /// 初始化数据
        /// </summary>
        private void Init()
        {
            codeEditBox.ForWho = "GameLuaEditor";
            FlowChartInteractor it = Interactor.GetInteractor().CurrentFlowChartInteractor;

            codeEditBox.Text = it.CustomText;
        }
Пример #3
0
        /// <summary>
        /// 初始化数据
        /// </summary>
        /// <param name="canvas">绘图板实例</param>
        /// <param name="propertyGrid">属性面板实例</param>
        public void Init(Canvas canvas)
        {
            graphManager    = new GraphManager(this, canvas);
            dataManager     = new DataManager(this);
            dataBaseManager = DataBaseManager.GetDataBaseManager();
            int i = path.IndexOf('\\');

            mapName             = path.Substring(0, i);
            flowChartInteractor = new FlowChartInteractor();
        }
Пример #4
0
        /// <summary>
        /// 编辑流程图
        /// </summary>
        /// <param name="FlowID">流程图ID</param>
        /// <param name="data">元数据链表</param>
        /// <param name="manager">元数据管理器</param>
        /// <param name="flowVersion">绘图的版本号</param>
        /// <returns>是否编译成功</returns>
        public override bool GenerateCode(int FlowID, List <FlowChartMetaData> data, FlowChartMetaDataManager manager)
        {
            // 初始化数据
            string[] dataArray = scriptPath.Split(new char[] { '\\' });
            string   shortPath = dataArray[1];

            for (int i = 2; i < dataArray.Length; i++)
            {
                shortPath = shortPath + string.Format("\\{0}", dataArray[i]);
            }

            string fullPath = string.Format(@"{0}\scripts\Map\{1}\ai\{2}", rootDirectory.TrimEnd(new char[] { '\\' }), dataArray[0], shortPath);

            bool            success         = true;
            DataBaseManager dataBaseManager = DataBaseManager.GetDataBaseManager();

            customFunctionList.Clear();

            // 初始化参数
            StringBuilder            code             = new StringBuilder();
            string                   initialStateName = CodeProviderClass.GetStateString(manager.GetEventData(1)); // 初态的变量名
            List <FlowChartMetaData> metaDataList     = manager.GetAllNodes();
            List <FlowChartMetaData> stateList        = new List <FlowChartMetaData>();
            List <FlowChartMetaData> actionList       = new List <FlowChartMetaData>();
            Hashtable                registActions    = new Hashtable();

            string sqlString = "SELECT actionid, parms FROM AI_Action_Define";

            actionTable = dataBaseManager.GetDataTable(sqlString, dataBaseManager.Connection_Jx3web);

            foreach (FlowChartMetaData metaData in metaDataList)
            {
                switch (metaData.DataType)
                {
                case "AIStateNode":
                {
                    stateList.Add(metaData);
                    break;
                }

                case "AIActionNode":
                {
                    actionList.Add(metaData);
                    string[] information = CodeProviderClass.GetActionInformation(metaData.Data);
                    int      actionID    = int.Parse(information[2]);

                    if ((actionID == 0) || (actionID > 1000 && registActions[information[2]] == null))         // 注册自定义动作
                    {
                        registActions[information[2]] = metaData;
                    }

                    break;
                }
                }
            }

            // 添加注释
            code.AppendLine(string.Format("-- 编写者:{0}", Dns.GetHostName()));
            code.AppendLine(string.Format("-- 版本号:{0}", manager.Version));
            code.AppendLine();

            // 引用头文件
            code.AppendLine("Include('scripts/ai/customFuctions.lua')");
            code.AppendLine("Include('scripts/ai/AIParam.lua')");
            code.AppendLine("Include('scripts/ai/argumentStrings.ls')");
            code.AppendLine();
            code.AppendLine("g_AIDebugInfo = {}");
            code.AppendLine();

            // 声明变量
            code.AppendLine("-- 声明状态变量");
            foreach (FlowChartMetaData stateNode in stateList)
            {
                string stateName = stateNode.Code;
                code.AppendLine(string.Format("local {0} = {1} -- {2}", stateName, stateNode.ID, stateNode.DisplayText));
            }
            code.AppendLine();

            // 生成自定义附加脚本
            FlowChartInteractor it = Interactor.GetInteractor().CurrentFlowChartInteractor;
            string customCode      = it.CustomText;

            if (customCode != null && customCode != "")
            {
                code.AppendLine("-- 自定义附加脚本");
                code.AppendLine(string.Format("{0}", customCode));
                code.AppendLine();
            }

            // 写主方法
            code.AppendLine("function Setup(ai)");
            code.AppendLine("    local state");
            code.AppendLine("    local action");
            code.AppendLine("    local param = g_AIParam[ai.nAIType]");
            code.AppendLine();

            // 注册自定义动作
            code.AppendLine("    -- 注册自定义动作");
            foreach (object o in registActions.Values)
            {
                FlowChartMetaData actionNode  = o as FlowChartMetaData;
                string[]          information = CodeProviderClass.GetActionInformation(actionNode.Data);
                code.AppendLine(string.Format("    ai.RegisterUserAction({0}, '{1}')", information[2], information[0]));
            }
            code.AppendLine();

            List <FlowChartMetaData> list = new List <FlowChartMetaData>();

            GenerateCode(code, manager.GetEventNode(1), list);

            code.AppendLine(string.Format("    ai.SetInitState({0})", initialStateName));
            code.AppendLine("end");
            code.AppendLine();

            // 调试方法定义
            code.AppendLine("-- 调试方法");
            code.AppendLine("function DebugOnCallAction(action_id)");
            code.AppendLine("    Log('[AI] Call action: ' .. g_AIDebugInfo[action_id])");
            code.AppendLine("end");

            // 写本文件自定义脚本动作定义
            if (customFunctionList.Count > 0)
            {
                code.AppendLine();
                code.AppendLine("-- 本AI图内自定义脚本");

                foreach (string s in customFunctionList)
                {
                    code.AppendLine(string.Format("{0}", s));
                    code.AppendLine();
                }
            }

            // 提取转换中文字符串
            string scriptText = code.ToString();

            scriptText = ConvertScriptText(scriptText);

            // 输出文件
            string fileName = string.Format("{0}.lua", fullPath);

            saveFile(fileName, scriptText);

            string userActionScripts = dataBaseManager.GetUserActionContext();

            fileName = Path.Combine(rootDirectory, @"scripts\ai\customFuctions.lua");
            saveFile(fileName, userActionScripts);

            fileName = Path.Combine(rootDirectory, @"scripts\ai\argumentStrings.ls");
            string lsContent = ConstructLSFile();

            saveFile(fileName, lsContent);

            return(success);
        }
Пример #5
0
        /// <summary>
        /// 刷新数据
        /// </summary>
        public void Reload(AI_State state)
        {
            editSuccess = false;
            allEventTree.Nodes.Clear();
            registedEventTree.Nodes.Clear();

            this.m_state        = state;
            flowChartInteractor = Interactor.GetInteractor().CurrentFlowChartInteractor;

            // 初始化名称
            if (string.IsNullOrEmpty(state.Ename))
            {
                state.Ename = string.Format("State{0}", graphElementID.ToString());
            }

            txtName.Text = state.Name;

            // 初始化所有事件
            foreach (AI_Event ai_event in EventTable.EventItems)
            {
                // 取消已注册的事件
                if (!state.EventList.Contains(ai_event))
                {
                    Node node = new Node();
                    node.Text = ai_event.ToString();
                    node.Tag  = ai_event;
                    if (int.Parse(ai_event.eventid) < 1000) // 系统事件
                    {
                        node.Image = imageList1.Images[0];
                    }
                    else
                    {
                        node.Image = imageList1.Images[2];
                    }
                    allEventTree.Nodes.Add(node);
                }
            }

            // 初始化自定义事件
            List <AI_Event> customEventList = flowChartInteractor.CustomTable["CustomEventList"] as List <AI_Event>;

            if (customEventList != null)
            {
                foreach (AI_Event aiEvent in customEventList)
                {
                    // 去掉已注册的事件
                    if (!state.EventList.Contains(aiEvent))
                    {
                        Node node = new Node();
                        node.Text  = aiEvent.ToString();
                        node.Tag   = aiEvent;
                        node.Image = imageList1.Images[2];
                        allEventTree.Nodes.Add(node);
                    }
                }
            }

            // 初始化选中的事件
            foreach (AI_Event aiEvent in state.EventList)
            {
                Node node = new Node();
                node.Text = aiEvent.ToString();
                node.Tag  = aiEvent;

                if (int.Parse(aiEvent.eventid) < 1000) // 系统事件
                {
                    node.Image = imageList1.Images[0];
                }
                else
                {
                    node.Image = imageList1.Images[2];
                }

                registedEventTree.Nodes.Add(node);
            }

            // 切换焦点
            txtName.Focus();
        }