public void OnGUI() { // Create our data if we have none. if (_listData == null) { //Debug.Log("no asset file found, need to reload"); _listData = AssetDatabase.LoadAssetAtPath(_listDataAssetPath, typeof(ListData)) as ListData; if (_listData == null) { //Debug.Log("no asset file found, could not reload"); _listData = ScriptableObject.CreateInstance(typeof(ListData)) as ListData; System.IO.Directory.CreateDirectory(Application.dataPath + _listDataDirectory); AssetDatabase.CreateAsset(_listData, _listDataAssetPath); GUI.changed = true; } } // display the filter fields string[] owners = new string[_listData.owners.Count + 1]; string[] ownersToSelect = new string[_listData.owners.Count]; owners[0] = "All Tasks"; for (int i = 0; i < _listData.owners.Count; i++) { owners[i + 1] = _listData.owners[i].name; ownersToSelect[i] = _listData.owners[i].name; } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Show tasks:", EditorStyles.boldLabel); _currentOwnerIndex = EditorGUILayout.Popup(_currentOwnerIndex, owners); EditorGUILayout.EndHorizontal(); // display the list GUIStyle itemStyle = new GUIStyle(EditorStyles.wordWrappedMiniLabel); itemStyle.alignment = TextAnchor.UpperLeft; _scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition); int displayCount = 0; for (int i = 0; i < _listData.items.Count; i++) { ListItem item = _listData.items[i]; ListItemOwner owner = item.owner; if (_currentOwnerIndex == 0) { itemStyle.normal.textColor = owner.color; if (item.isComplete == false) { displayCount++; EditorGUILayout.BeginHorizontal(); if (EditorGUILayout.Toggle(item.isComplete, GUILayout.Width(20)) == true) { _listData.items[i].isComplete = true; } _listData.items[i].task = EditorGUILayout.TextField(item.task, itemStyle); int newOwnerIndex = EditorGUILayout.Popup(owner.index, ownersToSelect, GUILayout.Width(60)); if (newOwnerIndex != owner.index) { item.owner = _listData.owners[newOwnerIndex]; _listData.items[i] = item; } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); } } else { int adjustedIndex = _currentOwnerIndex - 1; owner = _listData.owners[adjustedIndex]; if (owner.name == item.owner.name) { itemStyle.normal.textColor = owner.color; if (item.isComplete == false) { displayCount++; EditorGUILayout.BeginHorizontal(); if (EditorGUILayout.Toggle(item.isComplete, GUILayout.Width(20)) == true) { _listData.items[i].isComplete = true; } _listData.items[i].task = EditorGUILayout.TextField(item.task, itemStyle); int newOwnerIndex = EditorGUILayout.Popup(adjustedIndex, ownersToSelect, GUILayout.Width(60)); if (newOwnerIndex != adjustedIndex) { item.owner = _listData.owners[newOwnerIndex]; _listData.items[i] = item; } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); } } } } if (displayCount == 0) { EditorGUILayout.LabelField("No tasks currently", EditorStyles.largeLabel); } if ((showCompletedTasks) && (_currentOwnerIndex == 0)) { itemStyle.normal.textColor = Color.grey; for (int i = 0; i < _listData.items.Count; i++) { if (_listData.items[i].isComplete == true) { ListItem item = _listData.items[i]; EditorGUILayout.BeginHorizontal(); if (EditorGUILayout.Toggle(item.isComplete, GUILayout.Width(20)) == false) { _listData.items[i].isComplete = false; } EditorGUILayout.LabelField(item.task, itemStyle); if (GUILayout.Button("x", GUILayout.Width(23))) { _listData.items.RemoveAt(i); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); } } } EditorGUILayout.EndScrollView(); // display our task creation area EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Create Task:", EditorStyles.boldLabel); _newTaskOwnerIndex = EditorGUILayout.Popup(_newTaskOwnerIndex, ownersToSelect, GUILayout.Width(60)); EditorGUILayout.EndHorizontal(); _newTask = EditorGUILayout.TextField(_newTask, GUILayout.Height(40)); if ((GUILayout.Button("Create Task") && _newTask != "")) { // create new task ListItemOwner newOwner = _listData.owners[_newTaskOwnerIndex]; _listData.AddTask(newOwner, _newTask); //EditorUtility.DisplayDialog("Task created for " + newOwner.name, _newTask, "Sweet"); _newTask = ""; GUI.FocusControl(null); } if (GUI.changed) { //Debug.Log("Save Data: " + _listData.items.Count); EditorUtility.SetDirty(_listData); EditorApplication.SaveAssets(); AssetDatabase.SaveAssets(); } }
public void OnGUI() { // EditorGUILayout.BeginVertical (); GUIStyle titleGUIStyle = new GUIStyle(); titleGUIStyle.fontSize = 128; titleGUIStyle.fontStyle = FontStyle.BoldAndItalic; titleGUIStyle.normal.textColor = ColorWithAlpha(Color.black, 0.05f); EditorGUILayout.LabelField("TASKS", titleGUIStyle); // owners string[] categories = InsertIntoArray <string> (_listData.categoryStrings, 0, "All"); categories = AddToArray <string> (categories, "Archived"); // people string[] people = InsertIntoArray <string> (_listData.peopleStrings, 0, "All"); // categories string[] tags = InsertIntoArray <string> (_listData.tagStrings, 0, "All"); // status string[] statuses = new string[] { "All", "Active only", "Completed only" }; EditorGUILayout.BeginHorizontal(); { EditorGUILayout.BeginVertical(); EditorGUILayout.LabelField("CATEGORY", EditorStyles.boldLabel, GUILayout.Width(88)); _currentCategoryIndex = EditorGUILayout.Popup(_currentCategoryIndex, categories); EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(); EditorGUILayout.LabelField("STATUS", EditorStyles.boldLabel, GUILayout.Width(64)); _currentStatusIndex = EditorGUILayout.Popup(_currentStatusIndex, statuses); EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(); EditorGUILayout.LabelField("PERSON", EditorStyles.boldLabel, GUILayout.Width(64)); _currentPersonIndex = EditorGUILayout.Popup(_currentPersonIndex, people); EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(); EditorGUILayout.LabelField("TYPE", EditorStyles.boldLabel, GUILayout.Width(36)); _currentTagIndex = EditorGUILayout.Popup(_currentTagIndex, tags); EditorGUILayout.EndVertical(); } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.Space(); // LIST OF ITEMS GUIStyle itemStyle = new GUIStyle(EditorStyles.wordWrappedLabel); itemStyle.alignment = TextAnchor.UpperLeft; itemStyle.fontStyle = FontStyle.Bold; itemStyle.fontSize = 12; _scrollPosition = EditorGUILayout.BeginScrollView(_scrollPosition); { int displayCount = 0; bool showArchives = _currentCategoryIndex == categories.Length - 1; // First, draw all the active quests. if (showActiveTasks) { for (int i = 0; i < _listData.tasks.Count; i++) { ListItem item = _listData.tasks [i]; ListItemOwner cat = _listData.categories [item.categoryId]; var catIndex = _currentCategoryIndex - 1; // Show active only. if (item.isComplete == true) { continue; } // Only show the item if we're in the correct category, showing ALL, or showing ARCHIVES if (!showAll && catIndex != item.categoryId && !showArchives) { continue; } // Only show archived items if we're archived. if (item.isArchived != showArchives) { continue; } // Only show items if we have the correct person. if (_currentPersonIndex != 0 && _currentPersonIndex - 1 != item.personId) { continue; } // Only show items if we have the correct category. if (_currentTagIndex != 0 && _currentTagIndex - 1 != item.tagId) { continue; } // int adjustedIndex = _currentOwnerIndex - 1; // owner = _listData.owners [adjustedIndex]; // itemStyle.normal.textColor = owner.color; DrawItemRow(i, item, itemStyle); displayCount++; EditorGUILayout.Space(); EditorGUILayout.Space(); } } if (showCompletedTasks) { for (int i = 0; i < _listData.tasks.Count; i++) { ListItem item = _listData.tasks[i]; ListItemOwner cat = _listData.categories [item.categoryId]; var catIndex = _currentCategoryIndex - 1; // Show completed only. if (item.isComplete == false) { continue; } // Only show the item if we're in the correct category. if (!showAll && catIndex != item.categoryId && !showArchives) { continue; } // Only show archived items if we're archived. if (item.isArchived != showArchives) { continue; } // Only show items if we have the correct person. if (_currentPersonIndex != 0 && _currentPersonIndex - 1 != item.personId) { continue; } // Only show items if we have the correct category. if (_currentTagIndex != 0 && _currentTagIndex - 1 != item.tagId) { continue; } itemStyle.normal.textColor = Color.gray; itemStyle.fontStyle = FontStyle.Italic; DrawItemRow(i, item, itemStyle); displayCount++; EditorGUILayout.Space(); EditorGUILayout.Space(); } } // Then, draw all the completed quests. if (displayCount <= 0) { EditorGUILayout.LabelField("No tasks currently", itemStyle); } } EditorGUILayout.EndScrollView(); // CREATE NEW TASK var nts = EditorStyles.boldLabel; GUILayout.Label("NEW TASK", nts); // EditorGUILayout.LabelField ("NEW TASK", titleGUIStyle); EditorGUILayout.BeginHorizontal(); { // EditorGUILayout.LabelField("Create Task:", EditorStyles.boldLabel); _newCategoryIndex = EditorGUILayout.Popup(_newCategoryIndex, _listData.categoryStrings); //, GUILayout.Width(90)); _newPersonIndex = EditorGUILayout.Popup(_newPersonIndex, _listData.peopleStrings); //, GUILayout.Width(90)); _newTagIndex = EditorGUILayout.Popup(_newTagIndex, _listData.tagStrings); //, GUILayout.Width(90)); _newTimeEstimate = EditorGUILayout.Slider(_newTimeEstimate, 0f, 8f); } EditorGUILayout.EndHorizontal(); _newTask = EditorGUILayout.TextArea(_newTask, GUILayout.Height(40)); // BOTTOM BUTTONS GUILayout.BeginHorizontal(); { if ((GUILayout.Button("Create Task") && _newTask != "")) { // create new task // _listData.AddTask (_newTaskOwnerIndex, _newTask); _listData.AddTask(_newTask, _newTimeEstimate, _newCategoryIndex, _newPersonIndex, _newTagIndex); //EditorUtility.DisplayDialog("Task created for " + newOwner.name, _newTask, "Sweet"); _newTask = ""; GUI.FocusControl(null); } if ((GUILayout.Button("Create Multiple Tasks") && _newTask != "")) { var ss = _newTask.Split('\n'); foreach (var s in ss) { if (string.IsNullOrEmpty(s)) { continue; } string sss = s; if (sss.StartsWith("- ")) { sss = sss.Replace("- ", "\t"); } // create new task _listData.AddTask(sss, _newTimeEstimate, _newCategoryIndex, _newPersonIndex, _newTagIndex); } _newTask = ""; GUI.FocusControl(null); } } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { if (GUILayout.Button("Copy Current")) { string s = ""; foreach (var l in _listData.tasks) { if (!l.isComplete && (_currentCategoryIndex == 0 || l.categoryId == _currentCategoryIndex)) { s += l.task.Replace("\t", "- ") + "\n"; } } EditorGUIUtility.systemCopyBuffer = s; } // if (GUILayout.Button ("Copy Completed")) { // string s = ""; // // foreach (var l in _listData.items) { // if (l.isComplete) // s += l.task + "\n"; // } // // EditorGUIUtility.systemCopyBuffer = s; // } if (GUILayout.Button("Archive Completed")) { for (int i = 0; i < _listData.tasks.Count; i++) { var l = _listData.tasks [i]; if (l.isComplete && !l.isArchived) { _listData.ArchiveTask(i); } } } if (GUILayout.Button("Remove Archived")) { if (EditorUtility.DisplayDialog( "Careful", "You are about to remove all archived items. This cannot be undone.", "Remove all archived items!", "Cancel")) { RemoveAllArchivedItems(); } } } GUILayout.EndHorizontal(); // EditorGUILayout.EndVertical (); // if(GUI.changed) // { // //Debug.Log("Save Data: " + _listData.items.Count); // EditorUtility.SetDirty(_listData); // EditorApplication.SaveAssets(); // AssetDatabase.SaveAssets(); // } if (GUIUtility.hotControl != 0) { saveable = true; } if (GUIUtility.hotControl == 0 && saveable) { saveable = false; // Debug.Log("Save Data: " + _listData.items.Count); EditorUtility.SetDirty(_listData); AssetDatabase.SaveAssets(); } }