Exemplo n.º 1
0
        void ResetEnumMembersList()
        {
            JArray ja_member = SelectedJsonElement.jo ["Member"] as JArray;

            EnumMembersList = new ReorderableList(ja_member, typeof(JToken));
            EnumMembersList.drawHeaderCallback += (Rect rect) => {
                GUI.Label(rect, "Items in Enum");
            };
            float[] split = new float[] { 0f, .2f, .6f, 1f };

            EnumMembersList.drawElementCallback += (Rect rect, int index, bool isActive, bool isFocused) => {
                JObject jo_member = ja_member [index] as JObject;

                Rect r = new Rect(rect);
                r.y      += 2;
                r.height -= 4;
                int split_idx = 0;
                r.x     = (rect.width - 25f) * split [split_idx] + 25f;
                r.width = (rect.width - 25f) * (split [split_idx + 1] - split [split_idx]) - 2f;

                string default_title = string.Format("Item.{0}", index);
                string short_desc    = jo_member ["Desc"].Value <string> ().Split(new char[] { '#' }) [0];

                if (string.IsNullOrEmpty(short_desc))
                {
                    GUI.Label(r, default_title);
                }
                else
                {
                    GUI.Label(r, short_desc, GUIStyleTemplate.GreenDescStyle());
                }

                split_idx++;
                r.x     = (rect.width - 25f) * split [split_idx] + 25f;
                r.width = (rect.width - 25f) * (split [split_idx + 1] - split [split_idx]) - 2f;

                string new_member_name = GUI.TextField(r, jo_member ["Name"].Value <string> ());
                if (new_member_name != jo_member ["Name"].Value <string> ())
                {
                    jo_member ["Name"] = new_member_name;
                }
                split_idx++;
                r.x               = (rect.width - 25f) * split [split_idx] + 25f;
                r.width           = (rect.width - 25f) * (split [split_idx + 1] - split [split_idx]) - 2f;
                jo_member ["Int"] = EditorGUI.IntField(r, jo_member ["Int"].Value <int> ());

                if (ShowDesc)
                {
                    r.y                = rect.y + singleRowHeight - 6f;
                    r.x                = (rect.width - 25f) * split [1] + 25f;
                    r.width            = (rect.width - 25f) * (split [3] - split [1]) - 2f;
                    jo_member ["Desc"] = GUI.TextField(r, jo_member ["Desc"].Value <string> (), GUIStyleTemplate.GreenDescStyle());
                }
            };

            EnumMembersList.showDefaultBackground = false;

            EnumMembersList.drawElementBackgroundCallback += (Rect rect, int index, bool isActive, bool isFocused) => {
                if (Event.current.type == EventType.Repaint)
                {
                    Color color = GUI.backgroundColor;
                    if (ShowDesc)
                    {
                        if (isActive)
                        {
                            GUI.backgroundColor = Color.yellow;
                        }
                        if (isFocused)
                        {
                            GUI.backgroundColor = Color.cyan;
                        }
                        GUI.skin.box.Draw(new Rect(rect.x + 2f, rect.y, rect.width - 4f, CalcHeight_Enum(index) - 4f), false, isActive, isFocused, false);
                        GUI.backgroundColor = color;
                    }
                    else
                    {
                        if (isFocused)
                        {
                            GUI.backgroundColor = Color.cyan;
                            GUI.skin.box.Draw(new Rect(rect.x + 2f, rect.y, rect.width - 4f, CalcHeight_Enum(index) - 4f), false, isActive, isFocused, false);
                            GUI.backgroundColor = color;
                        }
                    }
                }
            };

            EnumMembersList.elementHeightCallback += (int index) => {
                return(CalcHeight_Enum(index));
            };

            EnumMembersList.onAddCallback += (ReorderableList list) => {
                GenericEnumMenuOnAddCallback();
            };
//		EnumMembersList.onRemoveCallback += (ReorderableList list) => {
//			// PR_TODO:
//		};
        }
Exemplo n.º 2
0
        void DesignList_Element_View()
        {
            if (SelectedJsonElement == null)
            {
                return;
            }

            JObject jo_common = SelectedJsonElement.jo ["Common"] as JObject;
            JArray  ja_member = SelectedJsonElement.jo ["Member"] as JArray;
            JArray  ja_views  = SelectedJsonElement.jo ["Views"] as JArray;

            ElementViewScrollPos = GUILayout.BeginScrollView(ElementViewScrollPos);
            for (int i = 0; i < ja_views.Count; i++)
            {
                JObject jo_view         = ja_views [i] as JObject;
                string  viewName        = jo_view ["Name"].Value <string> ();
                string  viewType        = jo_view ["Type"].Value <string> ();
                JObject jo_view_members = jo_view ["Members"] as JObject;

                #region VerticalBox

                Color color = GUI.backgroundColor;

                if (SelectedViewIdx == i)
                {
                    GUI.backgroundColor = Color.cyan;
                }

                EditorGUILayout.BeginVertical("box");
                GUI.backgroundColor = color;

                EditorGUILayout.BeginHorizontal();
                string fold_flag = SelectedViewIdx == i ? "-" : "+";

                if (SelectedViewIdx == i)
                {
                    if (GUILayout.Button(string.Format(" {0}", fold_flag), GUIStyleTemplate.LabelStyle(), GUILayout.MaxWidth(10)))
                    {
                        SelectedViewIdx = SelectedViewIdx != i ? i : -1;
                    }
                    viewName = GUILayout.TextField(viewName);
                    if (viewName != jo_view ["Name"].Value <string> ())
                    {
                        jo_view ["Name"] = viewName;
                    }
                    GUILayout.Label(" : ", GUIStyleTemplate.LabelStyle(), GUILayout.MaxWidth(10));
                    viewType = GUILayout.TextField(viewType);
                    if (viewType != jo_view ["Type"].Value <string> ())
                    {
                        jo_view ["Type"] = viewType;
                    }
                }
                else
                {
                    if (GUILayout.Button(string.Format(" {0} {1} : {2}", fold_flag, viewName, viewType), GUIStyleTemplate.LabelStyle()))
                    {
                        SelectedViewIdx = SelectedViewIdx != i ? i : -1;
                    }
                }

                if (GUILayout.Button("-", GUIStyleTemplate.BlackCommandLink(), GUILayout.MaxWidth(10)))
                {
                    ElementViewTools evtools = new ElementViewTools(SelectedJsonElement.jo);
                    evtools.DeleteView(i);
                }

                if (i != 0)
                {
                    if (GUILayout.Button("^", GUIStyleTemplate.BlackCommandLink(), GUILayout.MaxWidth(10)))
                    {
                        JObject jo0 = ja_views [i] as JObject;
                        JObject jo1 = ja_views [i - 1] as JObject;
                        ja_views [i]     = jo1;
                        ja_views [i - 1] = jo0;
                    }
                }
                EditorGUILayout.EndHorizontal();

                if (SelectedViewIdx == i)
                {
                    if (jo_view ["Desc"] == null)
                    {
                        jo_view ["Desc"] = "";
                    }
                    jo_view ["Desc"] = GUILayout.TextArea(jo_view ["Desc"].Value <string> (), GUIStyleTemplate.GreenDescStyle2());

                    for (int j = 0; j < ja_member.Count; j++)
                    {
                        JObject jo_member  = ja_member [j] as JObject;
                        string  memberName = jo_member ["Name"].Value <string> ();
                        string  rxType     = jo_member ["RxType"].Value <string> ();

                        GUILayout.Label(string.Format("{1} | {0}", rxType, memberName), EditorStyles.helpBox);
                        JObject jo_view_bind = jo_view_members [memberName] ["Bind"] as JObject;
                        DesignViewBind(jo_view_bind);
                    }
                }
                EditorGUILayout.EndVertical();

                #endregion
            }
            GUILayout.EndScrollView();

            if (GUILayout.Button("Create Default View"))
            {
                string element_name         = jo_common ["Name"].Value <string> ();
                string ori_target_view_name = string.Format("{0}View", element_name);
                string target_view_name     = ori_target_view_name;
                int    digital_suffix       = 0;
                while (ja_views.FirstOrDefault(_ => _ ["Name"].Value <string> () == target_view_name) != null)
                {
                    digital_suffix++;
                    target_view_name = string.Format("{0}{1}", ori_target_view_name, digital_suffix);
                }
                ElementViewTools evtools = new ElementViewTools(SelectedJsonElement.jo);
                evtools.CreateDefaultView(target_view_name);
            }
        }
Exemplo n.º 3
0
        void DesignList_Enum()
        {
            if (SelectedJsonElement == null || SelectedJsonElement.jo ["Common"] ["Desc"] == null)
            {
                return;
            }

            JObject jo_common = SelectedJsonElement.jo ["Common"] as JObject;

            if (GUILayout.Button("<<"))
            {
                SelectedJsonElement = null;
                EnumMembersList     = null;
                NeedRefresh         = true;

                AutoSelected.SelectedJsonFileName = string.Empty;
                AutoSelected.Save();

                return;
            }

            GUILayout.Label(string.Format("Workspace:{0}, Enum:{1}", SelectedJsonElement.Workspace, SelectedJsonElement.Name), EditorStyles.boldLabel);

            jo_common ["Desc"] = GUILayout.TextArea(jo_common ["Desc"].Value <string> (), GUIStyleTemplate.GreenDescStyle2());

            DesignList_Enum_Member();

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Reset"))
            {
                SelectedJsonElement.Load();
                ResetEnumMembersList();
            }
            if (GUILayout.Button("Save"))
            {
                SaveJson();
            }
            if (GUILayout.Button("Save&Generate"))
            {
                SaveJson();

                Generator.GenerateCode(SelectedJsonElement.jo);

                AssetDatabase.Refresh();

                NeedRefresh = true;

                this.Repaint();
            }
            GUILayout.EndHorizontal();
        }
Exemplo n.º 4
0
        void DesignList_Element()
        {
            if (SelectedJsonElement == null || SelectedJsonElement.jo ["Common"] ["Desc"] == null)
            {
                return;
            }

            JObject jo_common = SelectedJsonElement.jo ["Common"] as JObject;

            if (GUILayout.Button("<<"))
            {
                SelectedJsonElement = null;
                ElementMembersList  = null;
                NeedRefresh         = true;

                AutoSelected.SelectedJsonFileName = string.Empty;
                AutoSelected.Save();

                return;
            }

            GUILayout.Label(string.Format("Workspace:{0}, Element:{1}", SelectedJsonElement.Workspace, SelectedJsonElement.Name), EditorStyles.boldLabel);

            jo_common ["Desc"] = GUILayout.TextArea(jo_common ["Desc"].Value <string> (), GUIStyleTemplate.GreenDescStyle2());

            if (jo_common ["Type"] == null)
            {
                jo_common.Add("Type", "");
            }

            GUILayout.BeginHorizontal();
            jo_common ["Type"] = EditorGUILayout.TextField("Base", jo_common ["Type"].Value <string> ());
            GUILayout.EndHorizontal();

            toolbar_index = GUILayout.Toolbar(toolbar_index, ToolbarHeaders, new GUILayoutOption[] { GUILayout.Height(25f) });

            switch (toolbar_index)
            {
            case 0:
                DesignList_Element_Member();
                break;

            case 1:
                DesignList_Element_View();
                break;

            default:
                break;
            }

            GUILayout.BeginHorizontal();
            if (GUILayout.Button("Reset"))
            {
                SelectedJsonElement.Load();
                ResetElementMembersList();
            }
            if (GUILayout.Button("Save"))
            {
                SaveJson();
            }
            if (GUILayout.Button("Save&Generate"))
            {
                SaveJson();

                Generator.GenerateCode(SelectedJsonElement.jo);

                AssetDatabase.Refresh();

                NeedRefresh = true;

                this.Repaint();
            }
            GUILayout.EndHorizontal();
        }
Exemplo n.º 5
0
        void ResetElementMembersList()
        {
            ElementViewTools evtools = new ElementViewTools(SelectedJsonElement.jo);

            JArray ja_member = SelectedJsonElement.jo ["Member"] as JArray;

            ElementMembersList = new ReorderableList(ja_member, typeof(JToken));
            ElementMembersList.drawHeaderCallback += (Rect rect) => {
                GUI.Label(rect, "Members in Element");
            };
            float[] split   = new float[] { 0f, .2f, .6f, 1f, 1.2f };
            float[] split_c = new float[] { 0f, .3f, .6f, .9f, .95f, 1f };

            ElementMembersList.drawElementCallback += (Rect rect, int index, bool isActive, bool isFocused) => {
                JObject jo_member = ja_member [index] as JObject;

                Rect r = new Rect(rect);
                r.y      += 2;
                r.height -= 4;
                int split_idx = 0;
                r.x     = (rect.width - 25f) * split [split_idx] + 25f;
                r.width = (rect.width - 25f) * (split [split_idx + 1] - split [split_idx]) - 2f;

                if (!ShowDesc && jo_member ["Desc"].Value <string> ().Contains("#"))
                {
                    GUI.Label(r, jo_member ["Desc"].Value <string> ().Split(new char[] { '#' }) [0] + "(" + jo_member ["RxType"].Value <string> ().Substring(0, 3).ToUpper() + ")", GUIStyleTemplate.GreenDescStyle());
                }
                else
                {
                    GUI.Label(r, jo_member ["RxType"].Value <string> ());
                }

                split_idx++;
                r.x     = (rect.width - 25f) * split [split_idx] + 25f;
                r.width = (rect.width - 25f) * (split [split_idx + 1] - split [split_idx]) - 2f;

                string new_member_name = GUI.TextField(r, jo_member ["Name"].Value <string> ());
                if (new_member_name != jo_member ["Name"].Value <string> ())
                {
                    evtools.ChangeName(jo_member ["Name"].Value <string> (), new_member_name);
                    jo_member ["Name"] = new_member_name;
                }

                if (jo_member ["RxType"].Value <string> () != "Command")
                {
                    split_idx++;
                    r.x                = (rect.width - 25f) * split [split_idx] + 25f;
                    r.width            = (rect.width - 25f) * (split [split_idx + 1] - split [split_idx]) - 2f;
                    jo_member ["Type"] = GUI.TextField(r, jo_member ["Type"].Value <string> ());

                    string jo_member_type = jo_member ["Type"].Value <string> ();

                    if (jo_member ["RxType"].Value <string> () == "Dictionary")
                    {
                        string[] dic_type_split = jo_member_type.Split(new char[] { ',' });
                        if (dic_type_split.Length == 2)
                        {
                            jo_member_type = dic_type_split [1];
                        }
                    }

                    TypeType?tt = PGFrameTools.GetTypeTypeByType(jo_member_type);
                    if (tt.HasValue && pgf_typetype_short_icons != null && pgf_typetype_short_icons.ContainsKey(tt.Value))
                    {
                        split_idx++;
                        r.x     = (rect.width - 25f) * split [split_idx] + 25f;
                        r.width = (rect.width - 25f) * (split [split_idx + 1] - split [split_idx]) - 2f;
                        GUI.Label(r, this.pgf_typetype_short_icons [tt.Value]);
                    }
                    else
                    {
                        string[] ts          = jo_member ["Type"].Value <string> ().Split(new char[] { '.' });
                        string   workspace   = "";
                        string   single_name = "";
                        if (ts.Length == 1)
                        {
                            workspace   = PGFrameWindow.Current.SelectedWorkspace.Name;
                            single_name = ts [0];
                        }
                        else if (ts.Length == 2)
                        {
                            workspace   = ts [0];
                            single_name = ts [1];
                        }

                        DocType?dt = CommonManager.GetTheDocTypeByName(workspace, single_name);
                        if (dt.HasValue && pgf_doctype_short_icons != null && pgf_doctype_short_icons.ContainsKey(dt.Value))
                        {
                            split_idx++;
                            r.x     = (rect.width - 25f) * split [split_idx] + 25f;
                            r.width = (rect.width - 25f) * (split [split_idx + 1] - split [split_idx]) - 2f;
                            GUI.Label(r, this.pgf_doctype_short_icons [dt.Value]);
                        }
                    }

                    if (ShowDesc)
                    {
                        r.y                = rect.y + singleRowHeight - 6f;
                        r.x                = (rect.width - 25f) * split [1] + 25f;
                        r.width            = (rect.width - 25f) * (split [3] - split [1]) - 2f;
                        jo_member ["Desc"] = GUI.TextField(r, jo_member ["Desc"].Value <string> (), GUIStyleTemplate.GreenDescStyle());
                    }
                }
                else
                {
                    split_idx++;
                    r.x     = (rect.width - 25f) * split [split_idx] + 25f;
                    r.width = (rect.width - 25f) * (split [split_idx + 1] - split [split_idx]) - 2f;

                    JArray ja_command_params = jo_member ["Params"] as JArray;

                    if (GUI.Button(r, "+", GUIStyleTemplate.BlackCommandLink()))
                    {
                        if (ja_command_params == null)
                        {
                            jo_member.Add("Params", new JArray());
                            ja_command_params = jo_member ["Params"] as JArray;
                        }
                        JObject jo_command_param = new JObject();
                        jo_command_param.Add("Name", string.Format("Param{0}", ja_command_params.Count));
                        jo_command_param.Add("Type", "object");
                        jo_command_param.Add("Desc", "");
                        ja_command_params.Add(jo_command_param);
                    }

                    if (ShowDesc)
                    {
                        r.y                = rect.y + singleRowHeight - 6f;
                        r.x                = (rect.width - 25f) * split [1] + 25f;
                        r.width            = (rect.width - 25f) * (split [3] - split [1]) - 2f;
                        jo_member ["Desc"] = GUI.TextField(r, jo_member ["Desc"].Value <string> (), GUIStyleTemplate.GreenDescStyle());
                    }

                    float show_desc_height_amplify = 1f;
                    if (ShowDesc)
                    {
                        show_desc_height_amplify = 2f;
                    }

                    if (ja_command_params != null)
                    {
                        for (int i = 0; i < ja_command_params.Count; i++)
                        {
                            int split_c_idx = 0;
                            r.y = rect.y + (singleRowHeight_c * (float)(i + 1)) * show_desc_height_amplify;
                            JObject jo_command_param = ja_command_params [i] as JObject;

                            split_c_idx = 0;
                            r.x         = (rect.width - 25f) * split_c [split_c_idx] + 25f;
                            r.width     = (rect.width - 25f) * (split_c [split_c_idx + 1] - split_c [split_c_idx]) - 2f;

                            if (!ShowDesc && jo_command_param ["Desc"].Value <string> ().Contains("#"))
                            {
                                GUI.Label(r, "  - " + jo_command_param ["Desc"].Value <string> ().Split(new char[] { '#' }) [0] + "(P" + i + ")", GUIStyleTemplate.GreenDescStyle());
                            }
                            else
                            {
                                GUI.Label(r, "  - Command Params");
                            }

                            split_c_idx = 1;
                            r.x         = (rect.width - 25f) * split_c [split_c_idx] + 25f;
                            r.width     = (rect.width - 25f) * (split_c [split_c_idx + 1] - split_c [split_c_idx]) - 2f;
                            string new_name = GUI.TextField(r, jo_command_param ["Name"].Value <string> ());
                            if (new_name != jo_command_param ["Name"].Value <string> ())
                            {
                                jo_command_param ["Name"] = new_name;
                            }

                            split_c_idx = 2;
                            r.x         = (rect.width - 25f) * split_c [split_c_idx] + 25f;
                            r.width     = (rect.width - 25f) * (split_c [split_c_idx + 1] - split_c [split_c_idx]) - 2f;
                            jo_command_param ["Type"] = GUI.TextField(r, jo_command_param ["Type"].Value <string> ());

                            split_c_idx = 3;
                            r.x         = (rect.width - 25f) * split_c [split_c_idx] + 25f;
                            r.width     = (rect.width - 25f) * (split_c [split_c_idx + 1] - split_c [split_c_idx]) - 2f;
                            if (GUI.Button(r, "-", GUIStyleTemplate.BlackCommandLink()))
                            {
                                ja_command_params.RemoveAt(i);
                                return;
                            }

                            if (i != 0)
                            {
                                split_c_idx = 4;
                                r.x         = (rect.width - 25f) * split_c [split_c_idx] + 25f;
                                r.width     = (rect.width - 25f) * (split_c [split_c_idx + 1] - split_c [split_c_idx]) - 2f;
                                if (GUI.Button(r, "^", GUIStyleTemplate.BlackCommandLink()))
                                {
                                    JObject jo0 = ja_command_params [i] as JObject;
                                    JObject jo1 = ja_command_params [i - 1] as JObject;
                                    ja_command_params [i]     = jo1;
                                    ja_command_params [i - 1] = jo0;
                                }
                            }

                            if (ShowDesc)
                            {
                                r.y     = rect.y + (singleRowHeight_c * (float)(i + 1)) * show_desc_height_amplify + singleRowHeight_c - 2f;
                                r.x     = (rect.width - 25f) * split_c [1] + 25f;
                                r.width = (rect.width - 25f) * (split_c [3] - split_c [1]) - 2f;
                                jo_command_param ["Desc"] = GUI.TextField(r, jo_command_param ["Desc"].Value <string> (), GUIStyleTemplate.GreenDescStyle());
                            }
                        }
                    }
                }
            };
            ElementMembersList.elementHeightCallback += (int index) => {
                return(CalcHeight(index));
            };
            ElementMembersList.showDefaultBackground = false;

            ElementMembersList.drawElementBackgroundCallback += (Rect rect, int index, bool isActive, bool isFocused) => {
                if (Event.current.type == EventType.Repaint)
                {
                    Color color = GUI.backgroundColor;
                    if (ShowDesc)
                    {
                        if (isActive)
                        {
                            GUI.backgroundColor = Color.yellow;
                        }
                        if (isFocused)
                        {
                            GUI.backgroundColor = Color.cyan;
                        }
                        GUI.skin.box.Draw(new Rect(rect.x + 2f, rect.y, rect.width - 4f, CalcHeight(index) - 4f), false, isActive, isFocused, false);
                        GUI.backgroundColor = color;
                    }
                    else
                    {
                        if (isFocused)
                        {
                            GUI.backgroundColor = Color.cyan;
                            GUI.skin.box.Draw(new Rect(rect.x + 2f, rect.y, rect.width - 4f, CalcHeight(index) - 4f), false, isActive, isFocused, false);
                            GUI.backgroundColor = color;
                        }
                    }
                }
            };

            ElementMembersList.onAddCallback += (ReorderableList list) => {
                GenericMenu menu = new GenericMenu();
                foreach (RxType rt in Enum.GetValues(typeof(RxType)))
                {
                    menu.AddItem(new GUIContent(rt.ToString()), false, GenericElementMenuOnAddCallback, rt);
                }
                menu.ShowAsContext();
            };
            ElementMembersList.onRemoveCallback += (ReorderableList list) => {
                JObject jo_member = ja_member [list.index] as JObject;
//				string element_rxtype = jo_member ["RxType"].Value<string> ();
                string element_name = jo_member ["Name"].Value <string> ();
                ja_member.RemoveAt(list.index);
                evtools.DeleteMember(element_name);
            };
        }
Exemplo n.º 6
0
        private void OnGUI()
        {
            if (TransitionsList == null)
            {
                if (jElement == null)
                {
                    this.Close();
                    return;
                }
                ResetReorderableTransitionsList();
            }

            if (StatesList == null)
            {
                if (jElement == null)
                {
                    this.Close();
                    return;
                }
                ResetReorderableStatesList();
            }

            JObject jo_common = jElement.jo ["Common"] as JObject;


            GUILayout.BeginHorizontal();

            // tab
            GUILayout.BeginVertical(GUILayout.MaxWidth(tab_width));
            scrollStatesPosition = GUILayout.BeginScrollView(scrollStatesPosition);

            TransitionsList.DoLayoutList();
            EditorGUILayout.Space();
            StatesList.DoLayoutList();

            GUILayout.FlexibleSpace();

            GUILayout.EndScrollView();

            if (in_state_rename_jo_state != null)
            {
                GUILayout.BeginVertical("box");
                GUILayout.Label(string.Format("Rename State({0}) To:", in_state_rename_jo_state ["Name"].Value <string> ()));
                in_state_rename_target_name = GUILayout.TextField(in_state_rename_target_name);
                if (GUILayout.Button("Confirm Rename"))
                {
                    RenameState();
                    in_state_rename_jo_state    = null;
                    in_state_rename_target_name = "";
                }
                if (GUILayout.Button("Cancel Rename State"))
                {
                    in_state_rename_jo_state    = null;
                    in_state_rename_target_name = "";
                }
                GUILayout.EndVertical();
            }

            if (in_state_transition_target_selecting_jo_state_transition != null)
            {
                if (GUILayout.Button("Cancel Transition To"))
                {
                    in_state_transition_target_selecting_jo_state_transition = null;
                    in_state_transition_target_selecting_window_id           = -1;
                }
            }
            if (GUILayout.Button("Create New State"))
            {
                CreateNewState();
            }
            if (GUILayout.Button("JElement"))
            {
                PRDebug.TagLog(lt, lc, JsonConvert.SerializeObject(jElement, Formatting.Indented));
            }
            if (GUILayout.Button("Reset"))
            {
                TransitionsList = null;
                StatesList      = null;
                jElement.Load();
            }
            if (GUILayout.Button("Save"))
            {
                SaveJsonFile();
            }
            if (GUILayout.Button("Save & Generate"))
            {
                SaveJsonFile();
                PGFrameWindow.Current.Generator.GenerateCode(jElement.jo);
            }
            if (GUILayout.Button("Save & Close"))
            {
                SaveJsonFile();
                this.Close();
                return;
            }
            EditorGUILayout.Space();
            GUILayout.EndVertical();

            // title
            GUILayout.BeginVertical();
            GUILayout.Label(jo_common ["Name"].Value <string> (), GUIStyleTemplate.FSMTitleStyle());
            jo_common ["Desc"] = EditorGUILayout.TextArea(jo_common ["Desc"].Value <string> (), GUIStyleTemplate.GreenDescStyle());
            GUILayout.EndVertical();

            GUILayout.EndHorizontal();

            DrawTransitionLines();

            BeginWindows();
            if (jElement != null)
            {
                JArray ja_states = jElement.jo ["State"] as JArray;

                for (int i = 0; i < ja_states.Count; i++)
                {
                    JObject jo_state   = ja_states [i] as JObject;
                    string  state_name = jo_state ["Name"].Value <string> ();
                    float   x          = jo_state ["Rect"] ["x"].Value <float> ();
                    float   y          = jo_state ["Rect"] ["y"].Value <float> ();
                    float   w          = jo_state ["Rect"] ["w"].Value <float> ();
                    float   h          = jo_state ["Rect"] ["h"].Value <float> ();

                    Rect rect = GUI.Window(i, new Rect(x, y, w, h), WindowFunction, state_name);

                    rect.x = Math.Max((int)tab_width, (int)rect.x);
                    rect.y = Math.Max(50, (int)rect.y);
                    rect   = SnapRect(rect);
                    jo_state ["Rect"] ["x"] = (int)rect.x;
                    jo_state ["Rect"] ["y"] = (int)rect.y;
                    jo_state ["Rect"] ["w"] = (int)rect.width;
                    jo_state ["Rect"] ["h"] = (int)rect.height;
                }
            }
            EndWindows();
        }
Exemplo n.º 7
0
        void DesignList()
        {
            if (WorkspaceDirectoryInfos == null || CommonManager.CommonObjectDic == null)
            {
                NeedRefresh = true;
                return;
            }

//			string JsonRootFull = Path.Combine (Application.dataPath, JsonRoot);
            if (SelectedWorkspace == null)
            {
                GUILayout.Label("Root", EditorStyles.boldLabel);
                scrollViewPos = GUILayout.BeginScrollView(scrollViewPos);
                for (int i = 0; i < WorkspaceDirectoryInfos.Length; i++)
                {
                    DirectoryInfo wdi        = WorkspaceDirectoryInfos [i];
                    string        ws_name    = wdi.Name;
                    StringBuilder sb_content = new StringBuilder(wdi.Name);

                    if (CommonManager != null)
                    {
                        int file_count = CommonManager.CommonObjectDic [ws_name].ElementFiles.Count;
                        sb_content.AppendFormat(" ({0} file{1})", file_count, file_count > 1 ? "s" : "");
//					button_content += " (" + CommonManager.CommonObjectDic [ws_name].ElementFiles.Count + " file)";
                    }

                    GUIContent button_content = new GUIContent(sb_content.ToString(), pgf_workspace_icon);

                    if (GUILayout.Button(button_content, GUIStyleTemplate.ButtonStyleAlignmentLeft()))
                    {
                        AutoSelected.SelectedWorkspaceName = ws_name;
                        AutoSelected.Save();
                        SelectedWorkspace = wdi;
                        NeedRefresh       = true;
                    }
                }
                GUILayout.EndScrollView();
            }
            else
            {
                GUILayout.BeginHorizontal();
                if (GUILayout.Button("<<"))
                {
                    SelectedWorkspace       = null;
                    NeedRefresh             = true;
                    WSJsonFilesList         = null;
                    SelectedWorkspaceCommon = null;

                    AutoSelected.SelectedWorkspaceName = string.Empty;
                    AutoSelected.Save();

                    return;
                }
                if (GUILayout.Button("Save"))
                {
                    SaveCommonFile();
                }
                GUILayout.EndHorizontal();

                GUILayout.Label("Workspace:" + SelectedWorkspace.Name, EditorStyles.boldLabel);

                if (SelectedWorkspaceCommon != null)
                {
//				PRDebug.TagLog ("PGFrameWindow.Debug", Color.yellow, JsonConvert.SerializeObject (SelectedWorkspaceCommon));
                    if (WSJsonFilesList == null)
                    {
                        ResetReorderableList();
                    }

                    JsonFilesScrollPos = GUILayout.BeginScrollView(JsonFilesScrollPos);
                    WSJsonFilesList.DoLayoutList();

                    GUILayout.EndScrollView();

                    TryShowPopupWindowDoc();
                }
            }
        }
Exemplo n.º 8
0
        void ResetReorderableList()
        {
            JArray ja_elements = SelectedWorkspaceCommon.jo ["ElementFiles"] as JArray;

            WSJsonFilesList = new ReorderableList(ja_elements, typeof(JToken));
            WSJsonFilesList.drawHeaderCallback += (Rect rect) => {
                GUI.Label(rect, "ElementFiles");
            };
            float[] split = new float[] { 0f, 1f };
            WSJsonFilesList.drawElementCallback += (Rect rect, int index, bool isActive, bool isFocused) => {
                Rect r = new Rect(rect);
                r.y      -= 1;
                r.height -= 2;
                int split_idx = 0;
                r.x     = (rect.width - 25f) * split [split_idx] + 25f;
                r.width = (rect.width - 25f) * (split [split_idx + 1] - split [split_idx]);
                JObject jo_element = ja_elements [index] as JObject;

                string jo_element_filename = jo_element ["File"].Value <string> ();

                DocType   dt   = (DocType)Enum.Parse(typeof(DocType), jo_element ["DocType"].Value <string> ());
                Texture2D icon = null;
                switch (dt)
                {
                case DocType.Element:
                    icon = pgf_element_icon;
                    break;

                case DocType.SimpleClass:
                    icon = pgf_simple_class_icon;
                    break;

                case DocType.Enum:
                    icon = pgf_enum_icon;
                    break;

                case DocType.FSM:
                    icon = pgf_fsm_icon;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                GUIContent content = new GUIContent(jo_element_filename, icon);
                if (GUI.Button(r, content, GUIStyleTemplate.ButtonStyleAlignmentLeft()))
                {
                    if (Event.current.button == 1)
                    {
                        JSONElement jsonElement = jElements.Single(je => je.FileName == jo_element_filename);

                        PGFrameOpenFileTools.OpenContentMenu(jsonElement);
                    }
                    else
                    {
                        SelectedJsonElement = jElements.Single(je => je.FileName == jo_element_filename);

                        if (dt == DocType.FSM)
                        {
                            FSMWindow.Init();
                            FSMWindow.Current.jElement = SelectedJsonElement;
                        }

                        AutoSelected.SelectedJsonFileName = jo_element_filename;
                        AutoSelected.Save();
                    }
                }
            };

            WSJsonFilesList.onAddCallback += (ReorderableList list) => {
                GenericMenu menu = new GenericMenu();
                foreach (DocType dt in Enum.GetValues(typeof(DocType)))
                {
                    menu.AddItem(new GUIContent(dt.ToString()), false, (object userData) => {
                        NeedShowPopupWindowDocType = (DocType)userData;
                    }, dt);
                }
                menu.ShowAsContext();
            };

            WSJsonFilesList.onRemoveCallback += (ReorderableList list) => {
                JObject jo       = ja_elements [list.index] as JObject;
                string  jsonName = jo ["File"].Value <string> ();

                if (EditorUtility.DisplayDialog("警告!", string.Format("确定删除框架中的{0}文件?", jo ["File"].Value <string> ()), "Yes", "No"))
                {
                    ja_elements.RemoveAt(list.index);
                    SelectedWorkspaceCommon.jo ["ElementFiles"] = ja_elements;
                    SaveCommonFile();

                    DeleteElementJsonFile(jsonName, SelectedWorkspaceCommon.Workspace);
                    NeedRefresh = true;
                }
            };
        }