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); }; }
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: // }; }
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(); }