コード例 #1
0
        /// <summary>
        /// 拷贝副本
        /// </summary>
        /// <returns>副本</returns>
        public object Clone()
        {
            AI_State state = new AI_State();

            state.Name  = this.Name;
            state.Ename = this.Ename;

            foreach (AI_Event aiEvent in EventList)
            {
                state.EventList.Add(aiEvent.Clone() as AI_Event);
            }

            return(state);
        }
コード例 #2
0
        private static StateNodeForm stateForm = new StateNodeForm(); // 状态结点编辑窗体

        // [NonSerialized]
        // private static SingleActionForm singleActionForm = new SingleActionForm(); // 单动作结点编辑窗体

        /// <summary>
        /// 编辑数据
        /// </summary>
        /// <param name="table">数据哈希表</param>
        /// <returns>是否编辑成功</returns>
        public override bool EditData(System.Collections.Hashtable table)
        {
            switch (this.DataType)
            {
            case "AIStateNode":     // 状态结点
            {
                AI_State state = table["data"] as AI_State;

                if (state == null)
                {
                    state = new AI_State();
                }

                // 优化窗体显示
                stateForm.GraphElementID = id;
                stateForm.Reload(state);
                stateForm.ShowDialog();

                if (stateForm.EditSuccess)         // 编辑成功
                {
                    this.Data = state;

                    // 清空连接线
                    List <AI_Event> elist       = state.EventList;
                    Hashtable       outlineList = (table["next_data"] as Hashtable);
                    foreach (DataElement de in outlineList.Values)
                    {
                        if (!elist.Contains(de.Data as AI_Event))
                        {
                            de.Data        = null;
                            de.Text        = "";
                            de.TooltipText = "";
                        }
                    }
                    this.Text        = state.ToString();
                    this.TooltipText = state.ToFullText();
                }
                else
                {
                    return(false);
                }

                break;
            }

            case "AIActionNode":     // 动作结点
            {
                AI_SingleAction action = table["data"] as AI_SingleAction;

                if (action == null)
                {
                    action = new AI_SingleAction();
                }

                // 优化窗体显示
                SingleActionForm singleActionForm = new SingleActionForm();
                singleActionForm.GraphElementID = id;
                singleActionForm.InActionGroup  = false;
                singleActionForm.Reload(action);
                singleActionForm.ShowDialog();

                if (singleActionForm.EditSuccess)         // 编辑成功
                {
                    this.Data = action;

                    // 清空连接线
                    List <string> eventList   = action.Action.RetList;
                    Hashtable     outLineList = (table["next_data"] as Hashtable);

                    foreach (DataElement dataElement in outLineList.Values)
                    {
                        if (!eventList.Contains(dataElement.Data as string))
                        {
                            dataElement.Data        = null;
                            dataElement.Text        = "";
                            dataElement.TooltipText = "";
                        }
                    }

                    this.Text        = action.ToString();
                    this.TooltipText = action.ToFullText();
                }
                else
                {
                    return(false);
                }

                break;
            }

            case "AIActionsNode":     // 动作组结点
            {
                AI_MultiAction multiAction = table["data"] as AI_MultiAction;

                if (multiAction == null)
                {
                    multiAction = new AI_MultiAction();
                }

                MultiActionForm multiActionForm = new MultiActionForm(multiAction);
                multiActionForm.GraphElementID = id;

                if (multiActionForm.ShowDialog() == DialogResult.OK)
                {
                    this.Data = multiAction;

                    //清空连接线
                    Hashtable outlineList = (table["next_data"] as Hashtable);
                    if (multiAction.ActionList.Count == 0)
                    {
                        foreach (DataElement dataElement in outlineList.Values)
                        {
                            dataElement.Data        = null;
                            dataElement.Text        = "";
                            dataElement.TooltipText = "";
                        }
                    }
                    else
                    {
                        List <string> elist = multiAction.ActionList[multiAction.ActionList.Count - 1].Action.RetList;
                        foreach (DataElement dataElement in outlineList.Values)
                        {
                            if (!elist.Contains(dataElement.Data as string))
                            {
                                dataElement.Data        = null;
                                dataElement.Text        = "";
                                dataElement.TooltipText = "";
                            }
                        }
                    }
                    this.Text        = multiAction.ToString();
                    this.TooltipText = multiAction.ToFullText();
                }
                else
                {
                    return(false);
                }

                break;
            }

            case "AILine":     // 连接线
            {
                Hashtable ht_prev_data      = table["prev_data"] as Hashtable;
                Hashtable ht_neightbor_data = table["neighbor_data"] as Hashtable;

                if (ht_prev_data.Count == 0)
                {
                    return(false);
                }

                object      prev_data           = null;
                DataElement previousDataElement = null;

                foreach (object o in ht_prev_data.Values)
                {
                    DataElement dataElement = o as DataElement;

                    if (dataElement.Data != null)
                    {
                        previousDataElement = dataElement;
                        prev_data           = dataElement.Data;
                        break;
                    }
                }

                if (previousDataElement == null || prev_data == null)
                {
                    return(false);
                }

                switch (previousDataElement.DataType)
                {
                case "AIStateNode":             // 状态结点连出的线
                {
                    AI_State        state         = prev_data as AI_State;
                    List <AI_Event> selectionList = new List <AI_Event>(state.EventList);

                    foreach (DataElement de in ht_neightbor_data.Values)                 // 剔除已经选择过了的事件
                    {
                        if ((de.Data as AI_Event) != null)
                        {
                            selectionList.Remove(de.Data as AI_Event);
                        }
                    }

                    this.data = LineForm <AI_Event> .ShowSelect(table["data"] as AI_Event, selectionList);

                    if (this.data == null)
                    {
                        this.Text = "";
                    }
                    else
                    {
                        this.Text = this.Data.ToString();
                    }

                    break;
                }

                case "AIActionNode":
                {
                    AI_Action action = (prev_data as AI_SingleAction).Action;

                    if (action == null)
                    {
                        return(false);
                    }

                    List <string> selectionList = new List <string>(action.RetList);
                    EditLine(selectionList, ht_neightbor_data);

                    break;
                }

                case "AIActionsNode":
                {
                    List <AI_SingleAction> actionList = (prev_data as AI_MultiAction).ActionList;

                    if (actionList.Count == 0)
                    {
                        return(false);
                    }

                    AI_Action action = actionList[actionList.Count - 1].Action;

                    if (action == null)
                    {
                        return(false);
                    }

                    List <string> selectionList = new List <string>(action.RetList);
                    EditLine(selectionList, ht_neightbor_data);

                    break;
                }

                case "InnerChart":
                {
                    Hashtable infoTable   = prev_data as Hashtable;
                    Hashtable outSlotInfo = infoTable["outSlotInfo"] as Hashtable;

                    List <string> selectionList = new List <string>();

                    foreach (string id in outSlotInfo.Keys)
                    {
                        string interfaceName = outSlotInfo[id] as string;

                        if (interfaceName == null)
                        {
                            interfaceName = "未命名";
                        }

                        selectionList.Add(string.Format("{0}:{1}", id, interfaceName));
                    }

                    EditLine(selectionList, ht_neightbor_data);

                    break;
                }

                case "InterfaceNode":
                {
                    this.data = "1:下一步";
                    this.text = "";

                    break;
                }
                }

                break;
            }
            }

            return(true);
        }
コード例 #3
0
        /// <summary>
        /// 获取数据元信息
        /// </summary>
        /// <returns>数据元信息哈希表</returns>
        public override System.Collections.Hashtable GetOutputArgs()
        {
            Hashtable infoTable = new Hashtable();

            infoTable["DataType"] = this.dataType;

            switch (this.dataType)
            {
            case "AIStateNode":     // 状态结点
            {
                AI_State state = this.data as AI_State;

                if (state != null)
                {
                    infoTable["Name"]        = state.Name;
                    infoTable["EnglishName"] = state.Ename;
                }

                break;
            }

            case "AIActionNode":     // 动作结点
            {
                AI_SingleAction action = this.data as AI_SingleAction;

                if (action != null && action.Action != null)
                {
                    infoTable["Name"]        = action.Action.Name;
                    infoTable["EnglishName"] = action.Action.Ename;

                    if (int.Parse(action.Action.ActionID) > 2000)
                    {
                        infoTable["Script"] = action.Action.Info;
                    }
                }

                break;
            }

            case "AIActionsNode":     // 动作组结点
            {
                AI_MultiAction multiAction = this.data as AI_MultiAction;

                if (multiAction != null)
                {
                    List <string> scriptList = new List <string>();

                    foreach (AI_SingleAction singleAction in multiAction.ActionList)
                    {
                        if (singleAction.Action != null && int.Parse(singleAction.Action.ActionID) > 2000)
                        {
                            if (!string.IsNullOrEmpty(singleAction.Action.Info))
                            {
                                scriptList.Add(singleAction.Action.Info);
                            }
                        }
                    }

                    infoTable["ScriptList"] = scriptList;
                }

                break;
            }

            case "AILine":     // 连接线
            {
                // 无需求,暂时忽略

                break;
            }
            }

            return(infoTable);
        }
コード例 #4
0
ファイル: StateNodeForm.cs プロジェクト: weimingtom/pap2
        /// <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();
        }