Exemplo n.º 1
0
        public void Sort(string text)
        {
            UnityDataSheet uds = GetComponentInParent <UnityDataSheet>();

            if (uds != null)
            {
                uds.Sort();
            }
        }
Exemplo n.º 2
0
        public void SetSortMode(int sortModeIndex)
        {
            if (sortModeIndex < 0 || sortModeIndex >= (int)SortState.Count)
            {
                return;
            }
            UnityDataSheet uds = UDS();
            int            col = transform.GetSiblingIndex();

            uds.SetSortState(col, (SortState)sortModeIndex);
        }
Exemplo n.º 3
0
        private void Init()
        {
            UnityDataSheet uds = UDS();

            if (uds == null)
            {
                return;
            }
            Button b = GetComponent <Button>();

            EventBind.On(b.onClick, uds, uds.RefreshData);
        }
Exemplo n.º 4
0
        public void AssignFromText(string text)
        {
            //TMPro.TMP_InputField input = GetComponent<TMPro.TMP_InputField>();
            //Show.Log("assign "+text+" instead of "+input.text);
            UnityDataSheet uds = GetComponentInParent <UnityDataSheet>();

            if (uds == null)
            {
                // this happens the first instant that the input field is created, before it is connected to the UI properly
                //Show.Log("missing "+nameof(UnityDataSheet)+" for "+transform.HierarchyPath());
                return;
            }
            int col = transform.GetSiblingIndex();
            int row = uds.GetRowIndex(transform.parent.gameObject);

            Udash.ColumnSetting column = uds.GetColumn(col);
            if (column.canEdit)
            {
                object value           = text;
                bool   validAssignment = true;
                if (column.type != null)
                {
                    if (!CodeConvert.Convert(ref value, column.type))
                    {
                        errorMessage = "could not assign \"" + text + "\" to " + column.type;
                        uds.errLog.AddError(-1, errorMessage);
                        validAssignment = false;
                        uds.popup.Set("err", gameObject, errorMessage);
                    }
                }
                if (validAssignment)
                {
                    ITokenErrLog errLog = new TokenErrorLog();
                    validAssignment = column.SetValue(uds.GetItem(row), value, errLog);
                    if (errLog.HasError())
                    {
                        errorMessage    = errLog.GetErrorString();
                        validAssignment = false;
                        uds.popup.Set("err", gameObject, errorMessage);
                    }
                }

                if (validAssignment)
                {
                    uds.data.Set(row, col, value);
                    if (errorMessage == uds.popup.Message)
                    {
                        uds.popup.Hide();
                    }
                }
            }
        }
Exemplo n.º 5
0
 private void MoveRowLogic(PointerEventData ped)
 {
     StateOfDrag(ped, out int oldIndex, out int newIndex, out bool inFrame);
     //Show.Log($"old{oldIndex}  new{newIndex}  in{inFrame}");
     if (inFrame)
     {
         UnityDataSheet uds = GetComponentInParent <UnityDataSheet>();
         if (newIndex != drag.toIndex && newIndex >= 0 && newIndex < uds.Count)
         {
             drag.toIndex = newIndex;
             uds.MoveRow(oldIndex, newIndex);
         }
     }
 }
Exemplo n.º 6
0
 public DragAction(Transform transform)
 {
     fromIndex = toIndex = transform.parent.GetSiblingIndex();
     rowRect   = transform.parent.GetComponent <RectTransform>();
     if (!ChangeIndexDuringDrag)
     {
         UnityDataSheet uds  = transform.GetComponentInParent <UnityDataSheet>();
         GameObject     rObj = Instantiate(uds.uiPrototypes.dataSheetRow.gameObject);
         rObj.SetActive(true);
         rObj.transform.SetParent(transform, false);
         predictionRect = rObj.GetComponent <RectTransform>();
         //Show.Log(pRect.sizeDelta.x);
         predictionRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, rowRect.sizeDelta.x);
         predictionRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, rowRect.sizeDelta.y);
         //predictionRect.localPosition = Vector2.zero;
     }
     startElement = transform.GetComponent <RectTransform>();
     startingLocalPositionForStartElement = startElement.localPosition;
     sr       = transform.GetComponentInParent <ScrollRect>();
     viewport = sr.viewport.GetComponent <RectTransform>();
 }
Exemplo n.º 7
0
        public void AddColumn()
        {
            UnityDataSheet uds = GetComponentInParent <UnityDataSheet>();

            uds.AddColumn();
        }
        public void SetColumnHeader(ColumnHeader columnHeader, UnityDataSheet uds, int column)
        {
            // unregister listeners before values change, since values are about to change.
            ClearInputTextBoxListeners();

            this.uds    = uds;
            this.column = column;
            cHeader     = columnHeader;
            TokenErrorLog errLog = new TokenErrorLog();
            // setup script value
            Token t = cHeader.columnSetting.fieldToken;
            //string textA = t.GetAsSmallText();
            //string textB = t.Stringify();
            //string textC = t.StringifySmall();
            //string textD = t.ToString();
            string text = t.GetAsBasicToken();

            //Show.Log("A: "+textA+"\nB:" + textB + "\nC:" + textC + "\nD:" + textD + "\nE:" + text);
            scriptValue.text = text;
            EventBind.On(scriptValue.onValueChanged, this, OnScriptValueEdit);
            // implicitly setup value types dropdown
            OnScriptValueEdit(text);
            // setup column label
            object labelText = cHeader.columnSetting.data.label.Resolve(errLog, uds.data);

            if (errLog.HasError())
            {
                popup.Set("err", defaultValue.gameObject, errLog.GetErrorString() + Proc.Now); return;
            }
            columnLabel.text = labelText.StringifySmall();
            EventBind.On(columnLabel.onValueChanged, this, OnLabelEdit);
            // setup column width
            columnWidth.text = cHeader.columnSetting.data.widthOfColumn.ToString();
            EventBind.On(columnWidth.onValueChanged, this, OnColumnWidthEdit);
            // setup column index
            columnIndex.text = column.ToString();
            EventBind.On(columnIndex.onValueChanged, this, OnIndexEdit);
            // setup column type
            List <ModalConfirmation.Entry> entries = columnTypes.ConvertAll(c => {
                string dropdownLabel;
                if (c.uiField != null && !string.IsNullOrEmpty(c.name))
                {
                    dropdownLabel = "/*" + c.name + "*/ " + c.uiField.name;
                }
                else
                {
                    dropdownLabel = c.name;
                }
                return(new ModalConfirmation.Entry(dropdownLabel, null));
            });

            t = cHeader.columnSetting.data.columnUi;
            string fieldTypeText = t.ToString();            //cHeader.columnSetting.data.columnUi.GetAsBasicToken();//ResolveString(errLog, null);
            int    currentIndex  = columnTypes.FindIndex(c => fieldTypeText.StartsWith(c.uiField.name)) + 1;

            //Show.Log(currentIndex+" field  " + fieldTypeText);
            DropDownEvent.PopulateDropdown(fieldType, entries, this, SetFieldType, currentIndex, true);
            if (currentIndex == 0)
            {
                DropDownEvent.SetCustomValue(fieldType.gameObject, fieldTypeText);
            }
            TMP_InputField elementUiInputField = fieldType.GetComponentInChildren <TMP_InputField>();

            if (elementUiInputField != null)
            {
                elementUiInputField.onValueChanged.RemoveAllListeners();
                //Show.Log("bind to "+elementUiInputField.name);
                EventBind.On(elementUiInputField.onValueChanged, this, OnSetFieldTypeText);
            }
            // setup default value
            object defVal = cHeader.columnSetting.defaultValue;

            if (defVal != null)
            {
                defaultValue.text = defVal.ToString();
            }
            else
            {
                defaultValue.text = "";
            }
            EventBind.On(defaultValue.onValueChanged, this, OnSetDefaultValue);
            // setup column destroy option
            EventBind.On(trashColumn.onClick, this, ColumnRemove);
            popup.Hide();
        }