Ejemplo n.º 1
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();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// how to execute an onClick action
        /// </summary>
        /// <param name="scope"></param>
        public void OnClick()
        {
            //Show.Log(debugMetaData);
            //Show.Log("onClick " + scope + "." + script.Stringify());
            TokenErrorLog tok = new TokenErrorLog();

            if (script.meta != null)
            {
                object r = script.Resolve(tok, scope);
            }
            if (tok.HasError())
            {
                Show.Warning(tok.GetErrorString());
            }
        }
Ejemplo n.º 3
0
        public void RefreshHeaders()
        {
            if (headerRectangle == null)
            {
                return;
            }
            Vector2 cursor = Vector2.zero;
            // put old headers aside. they may be reused.
            List <GameObject> unusedHeaders = new List <GameObject>();

            for (int i = 0; i < headerRectangle.childCount; ++i)
            {
                GameObject header = headerRectangle.GetChild(i).gameObject;
                if (header != null)
                {
                    unusedHeaders.Add(header);
                }
            }
            while (headerRectangle.childCount > 0)
            {
                Transform t = headerRectangle.GetChild(headerRectangle.childCount - 1);
                t.SetParent(null, false);
            }
            errLog.ClearErrors();
            for (int i = 0; i < data.columnSettings.Count; ++i)
            {
                Udash.ColumnSetting colS   = data.columnSettings[i];
                GameObject          header = null;
                string headerObjName       = colS.data.headerUi.ResolveString(errLog, this);
                // check if the header we need is in the old header list
                object headerTextResult = colS.data.label.Resolve(errLog, data);
                if (errLog.HasError())
                {
                    popup.Set("err", null, errLog.GetErrorString()); return;
                }
                string headerTextString = headerTextResult?.ToString() ?? null;
                for (int h = 0; h < unusedHeaders.Count; ++h)
                {
                    GameObject hdr = unusedHeaders[h];
                    if (hdr.name.StartsWith(headerObjName) && UiText.GetText(hdr) == headerTextString)
                    {
                        header = hdr;
                        unusedHeaders.RemoveAt(h);
                        break;
                    }
                }
                if (header == null)
                {
                    GameObject headerObjectPrefab = uiPrototypes.GetElement(headerObjName);
                    header      = Instantiate(headerObjectPrefab);
                    header.name = header.name.SubstringBeforeFirst("(", headerObjName.Length) + "(" + colS.data.label + ")";
                    UiText.SetText(header, headerTextString);
                }
                ColumnHeader ch = header.GetComponent <ColumnHeader>();
                if (ch != null)
                {
                    ch.columnSetting = colS;
                }
                header.SetActive(true);
                header.transform.SetParent(headerRectangle, false);
                header.transform.SetSiblingIndex(i);
                RectTransform rect = header.GetComponent <RectTransform>();
                rect.anchoredPosition = cursor;
                float w = rect.sizeDelta.x;
                if (colS.data.widthOfColumn > 0)
                {
                    w = colS.data.widthOfColumn;
                    rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, w);
                }
                else
                {
                    colS.data.widthOfColumn = w;                     // if the width isn't set, use the default width of the column header
                }
                cursor.x += w * rt.localScale.x;
            }
            contentAreaSize.x = cursor.x;
            for (int i = 0; i < unusedHeaders.Count; ++i)
            {
                GameObject header = unusedHeaders[i];
                Destroy(header);
            }
            unusedHeaders.Clear();
            contentRectangle.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, cursor.x);
            popup.Hide();
        }
        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();
        }