Exemplo n.º 1
0
 public ListItem( ListItemOwner owner, string task )
 {
     this.owner = owner;
     this.task = task;
     this.isComplete = false;
 }
Exemplo n.º 2
0
 public void AddTask( ListItemOwner owner, string task)
 {
     ListItem item = new ListItem( owner, task );
     items.Add(item);
 }
Exemplo n.º 3
0
 public ListItem(ListItemOwner owner, string task)
 {
     this.owner      = owner;
     this.task       = task;
     this.isComplete = false;
 }
Exemplo n.º 4
0
    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 (GUIUtility.hotControl != 0)
        {
            saveable = true;
        }
        if (GUIUtility.hotControl == 0 && saveable)
        {
            saveable = false;
            //Debug.Log("Save Data: " + _listData.items.Count);
            EditorUtility.SetDirty(_listData);
            EditorApplication.SaveAssets();
            AssetDatabase.SaveAssets();
        }
    }
Exemplo n.º 5
0
    public void AddTask(ListItemOwner owner, string task)
    {
        ListItem item = new ListItem(owner, task);

        items.Add(item);
    }