Beispiel #1
0
        ////////////////////////////////////////////////////////////////////////

        #region Remove

        /// <summary>
        /// Removes a row at index and return the row
        /// </summary>
        public ITableRowValue Remove(int _index)
        {
            ITableRowValue _row = rows[_index];

            rows.RemoveAt(_index);
            return(_row);
        }
Beispiel #2
0
 /// <summary>
 /// Get a column by name and find a single row with value
 /// </summary>
 public void GetColumnAndASingleRowValue()
 {
     string         _name   = "Name";
     string         _value  = "Character With A Name";
     ITableColumn   _column = _tableSO.Table.GetColumn(_name);
     ITableRowValue _row    = _column.GetRowByValue(_value);
 }
Beispiel #3
0
        /// <summary>
        /// Create a row at index
        /// </summary>
        /// <returns>The row.</returns>
        /// <param name="_index">Index.</param>
        public TableRow InsertRow(int _index)
        {
            // No columns existing
            if (ColumnCount == 0)
            {
                #if UNITY_EDITOR
                string _msg = string.Format("Attempted to insert a row when no columns exist!");
                Debug.LogError(_msg);
                OnLogUpdate?.Invoke(null, new LogArgs(_msg, false));
                #endif

                return(null);
            }

            if (_index >= rowCount)
            {
                #if UNITY_EDITOR
                string _msg = string.Format("Cannot insert a row! Index: {0} exceeds row count: {1}", _index, rowCount);
                Debug.LogError(_msg);
                OnLogUpdate?.Invoke(null, new LogArgs(_msg, false));
                #endif

                return(null);
            }

            if (_index < 0)
            {
                #if UNITY_EDITOR
                string _msg = string.Format("Cannot insert a row! Negative index: {0}", _index);
                Debug.LogError(_msg);
                OnLogUpdate?.Invoke(null, new LogArgs(_msg, false));
                #endif

                return(null);
            }

            List <ITableRowValue> _columns = new List <ITableRowValue>();

            int _count = ColumnCount;
            for (int _i = 0; _i < _count; _i++)
            {
                ITableRowValue rowValue = columns[_i].CreateTableRow(string.Empty, _index);
                _columns.Add(rowValue);
            }

            // Increment row count
            rowCount++;

            TableRow _row = new TableRow(_columns);
            OnRowInserted?.Invoke(null, new TableArgs(_row));

            #if UNITY_EDITOR
            string _message = string.Format("Row inserted. Index: {0}", _index);
            OnLogUpdate?.Invoke(null, new LogArgs(_message, true));
            #endif

            return(_row);
        }
Beispiel #4
0
        /// <summary>
        /// Get a row and update a column value for that row
        /// </summary>
        public void GetRowAndUpdateValue()
        {
            // Get a row at index
            int      _index = -1;
            TableRow _row   = _tableSO.Table.GetRowByIndex(_index);

            if (_row != null)
            {
                // Get a column in the row you wish to update by its name
                ITableRowValue _column = _row.GetColumn("Name");
                // update with a value
                // if an object subscribed to updates, it will be notified
                _column?.Update("New Value");
            }
        }
        private void DrawTableRow()
        {
            if (currentRowIndex < 0)
            {
                return;
            }

            TableRow _currentRow = tableSO.Table.GetRowByIndex(currentRowIndex);

            int _columnCount = tableSO.Table.ColumnCount;

            for (int _i = 0; _i < _columnCount; _i++)
            {
                if (_i != 0)
                {
                    EditorGUILayout.Space();
                }

                EditorGUILayout.BeginHorizontal();

                // Display row index
                EditorStatics.CreateLabelField(_i.ToString(), EditorStatics.Width_50);

                ITableRowValue _column = _currentRow.RowColumns[_i];

                EditorStatics.CreateLabelField(
                    _column.ColumnName,
                    EditorStatics.Width_210
                    );

                _column.Value = EditorGUILayout.TextArea(
                    _column.Value,
                    GUILayout.MinHeight(100),
                    GUILayout.MaxWidth(460)
                    );

                ///Calls update method which will invoke OnRowUpdated event
                if (GUILayout.Button("Update", EditorStatics.Width_80))
                {
                    _column.Update(_column.Value);
                }

                EditorGUILayout.EndHorizontal();
            }
        }
Beispiel #6
0
        ////////////////////////////////////////////////////////////////////////

        #region Get

        /// <summary>
        /// Find a row by index.
        /// </summary>
        /// <param name="_index"></param>
        /// <returns>Null if row not found.</returns>
        public TableRow GetRowByIndex(int _index)
        {
            if (_index >= rowCount)
            {
                return(null);
            }

            List <ITableRowValue> _columns = new List <ITableRowValue>();

            int _count = ColumnCount;

            for (int _i = 0; _i < _count; _i++)
            {
                ITableRowValue _rowValue = columns[_i].GetRowValue(_index);
                _columns.Add(_rowValue);
            }

            TableRow _row = new TableRow(_columns);

            return(_row);
        }
        private void DrawRows()
        {
            int             _startIndex = currentPage * currentPerPageValue;
            List <TableRow> _rows       = tableSO.Table.GetRows(_startIndex, _startIndex + currentPerPageValue, true);

            if (_rows == null)
            {
                return;
            }

            int _count = _rows.Count;

            for (int _i = 0; _i < _count; _i++)
            {
                TableRow _row      = _rows[_i];
                int      _rowIndex = _startIndex + _i;

                GUIStyle _style = EditorStatics.GetBoxStyle(0, 0, 0, 0, 2, 2, 2, 2, 0, 30);
                EditorGUILayout.BeginVertical(_style);

                EditorGUILayout.BeginHorizontal();

                // Insert a row before this one
                if (GUILayout.Button(new GUIContent("Insert", "Insert a row before this one"), EditorStatics.Width_50))
                {
                    tableSO.Table.InsertRow(_rowIndex);
                    EditorGUILayout.EndHorizontal();
                    return;
                }

                // Insert a row before this one
                if (GUILayout.Button("Delete", EditorStatics.Width_50))
                {
                    tableSO.Table.RemoveRow(_rowIndex);
                    EditorGUILayout.EndHorizontal();
                    return;
                }

                if (GUILayout.Button("Edit", EditorStatics.Width_50))
                {
                    EditTableRow(_rowIndex);
                }

                // Shift row to previous index
                if (GUILayout.Button(EditorStatics.StringArrowUp, EditorStatics.Width_20))
                {
                    int _nextIndex = _rowIndex - 1;
                    if (tableSO.Table.ShiftRow(_rowIndex, _nextIndex))
                    {
                        Debug.Log(string.Format("Shifted row up. From Index: {0}, To Index: {1}", _rowIndex, _nextIndex));
                    }
                }

                // Shift row to next index
                if (GUILayout.Button(EditorStatics.StringArrowDown, EditorStatics.Width_20))
                {
                    int _nextIndex = _rowIndex + 1;
                    if (tableSO.Table.ShiftRow(_rowIndex, _nextIndex))
                    {
                        Debug.Log(string.Format("Shifted row down. From Index: {0}, To Index: {1}", _rowIndex, _nextIndex));
                    }
                }

                // Display row index
                EditorStatics.CreateLabelField(_rowIndex.ToString(), EditorStatics.Width_50);

                GUIStyle _styleC = EditorStatics.GetBoxStyle(0, 0, 0, 0, 0, 0, 2, 2, 0, 26);
                _styleC.alignment = TextAnchor.MiddleCenter;
                style.wordWrap    = true;

                int _columnCount = tableSO.Table.ColumnCount;
                for (int _j = 0; _j < _columnCount; _j++)
                {
                    ITableRowValue _column = _row.RowColumns[_j];

                    EditorStatics.CreateLabelField(
                        _column.Value.ShorterText(10, true),
                        EditorStatics.Width_80,
                        _styleC
                        );

                    // Push the next one
                    EditorStatics.CreateLabelField("", EditorStatics.Width_5);
                }

                EditorGUILayout.EndHorizontal();

                EditorGUILayout.EndVertical();
            }
        }
Beispiel #8
0
        ////////////////////////////////////////////////////////////////////////

        #region Constructor

        public RowArgs(ITableRowValue _row)
        {
            Row = _row;
        }