Esempio n. 1
0
        /// <summary>
        /// 显示编辑窗体
        /// </summary>
        /// <param name="selObj">当前对象</param>
        /// <param name="list">对象链表</param>
        /// <returns>当前选中对象</returns>
        public static T ShowSelect(T selObj, List <T> list)
        {
            T selectedObject;

            switch (list.Count)
            {
            case 0:
            {
                selectedObject = default(T);
                break;
            }

            case 1:
            {
                selectedObject = list[0];
                break;
            }

            default:
            {
                LineForm <T> lineForm = new LineForm <T>(selObj, list);

                if (lineForm.ShowDialog() == DialogResult.OK)
                {
                    selectedObject = lineForm.m_ResultObj;
                }
                else
                {
                    selectedObject = selObj;
                }

                break;
            }
            }

            return(selectedObject);
        }
Esempio n. 2
0
        /// <summary>
        /// 编辑连接线
        /// </summary>
        /// <param name="selectionList">选项链表</param>
        /// <param name="neightborInfo">同级连接线信息</param>
        private void EditLine(List <string> selectionList, Hashtable neightborInfo)
        {
            bool singleSelection = true;

            if (selectionList.Count > 1)
            {
                singleSelection = false;
            }

            foreach (DataElement dataElement in neightborInfo.Values) // 剔除已经选择过了的分支
            {
                string selection = dataElement.Data as string;

                if (selection != null)
                {
                    selectionList.Remove(selection);
                }
            }

            this.data = LineForm <string> .ShowSelect(this.data as string, selectionList);

            if (this.data == null || singleSelection)
            {
                this.text = "";
            }
            else
            {
                string displayText = this.data as string;
                int    index       = displayText.IndexOf(":");

                if (index != -1)
                {
                    this.text = displayText.Substring(index + 1);
                }
            }
        }
Esempio n. 3
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);
        }