public void OnLabelEdit(string text)
        {
            Tokenizer tokenizer = Tokenizer.Tokenize(text);

            if (tokenizer.HasError())
            {
                popup.Set("err", defaultValue.gameObject, tokenizer.GetErrorString()); return;
            }
            Token token = Token.None;

            switch (tokenizer.tokens.Count)
            {
            case 0: break;

            case 1: token = tokenizer.tokens[0]; break;

            default: token = new Token(text); break;
            }
            cHeader.columnSetting.data.label = token;
            object result = token.Resolve(tokenizer, uds.data);

            if (tokenizer.HasError())
            {
                popup.Set("err", defaultValue.gameObject, tokenizer.GetErrorString()); return;
            }
            string resultText = result?.ToString() ?? "";

            UiText.SetText(cHeader.gameObject, resultText);
            popup.Hide();
        }
Exemplo n.º 2
0
        public void RefreshDebug()
        {
            if (!debugVisibleObject)
            {
                return;
            }
            Vector3 p = astar.maze.GetGroundPosition(coord), u = Vector3.up * .125f;

            debugVisibleObject.transform.position = p + u;
            bool   isVisible = visMap[coord];
            string text      = (_f < 0 && _g < 0)
                                ? coord.ToString()
                                : $"{coord}\nf:{_f}\ng:{_g}\n{_edge}";

            UiText.SetText(debugVisibleObject, text);
            UiText.SetColor(debugVisibleObject, isVisible ? Color.white : Color.black);
        }
Exemplo n.º 3
0
 public void RefreshColumnText(int column, ITokenErrLog errLog)
 {
     for (int row = 0; row < contentRectangle.childCount; ++row)
     {
         GameObject fieldUi = contentRectangle.GetChild(row).GetChild(column).gameObject;
         object     value   = data.RefreshValue(row, column, errLog);
         if (errLog.HasError())
         {
             return;
         }
         if (value != null)
         {
             UiText.SetText(fieldUi, value.ToString());
             //sb.Append(value.ToString() + ", ");
         }
         else
         {
             UiText.SetText(fieldUi, "");
         }
     }
 }
Exemplo n.º 4
0
        public GameObject UpdateRowData(DataSheetRow rObj, RowData rowData, float yPosition = float.NaN)
        {
            object[]      columns   = rowData.columns;
            Vector2       rowCursor = Vector2.zero;
            RectTransform rect;
            // remove all columns from the row (probably temporarily)
            List <GameObject> unusedColumns = new List <GameObject>();

            for (int i = 0; i < rObj.transform.childCount; ++i)
            {
                GameObject fieldUi = rObj.transform.GetChild(i).gameObject;
                if (fieldUi == null)
                {
                    throw new Exception("a null child in the row? wat");
                }
                unusedColumns.Add(fieldUi);
            }
            while (rObj.transform.childCount > 0)
            {
                rObj.transform.GetChild(rObj.transform.childCount - 1).SetParent(null, false);
            }
            TokenErrorLog errLog = new TokenErrorLog();

            for (int c = 0; c < data.columnSettings.Count; ++c)
            {
                Udash.ColumnSetting colS    = data.columnSettings[c];
                GameObject          fieldUi = null;
                string columnUiName         = colS.data.columnUi.ResolveString(errLog, rowData.obj);
                if (columnUiName == null)
                {
                    string errorMessage = "could not resolve column UI name from " + colS.data.columnUi + "\n" + errLog.GetErrorString();
                    Show.Log(errorMessage);
                    columnUiName = colS.data.columnUi.ResolveString(errLog, rowData.obj);
                    throw new Exception(errorMessage);
                }
                // check if there's a version of it from earlier
                for (int i = 0; i < unusedColumns.Count; ++i)
                {
                    if (unusedColumns[i].name.StartsWith(columnUiName))
                    {
                        fieldUi = unusedColumns[i];
                        unusedColumns.RemoveAt(i);
                        break;
                    }
                }
                // otherwise create it
                if (fieldUi == null)
                {
                    GameObject prefab = uiPrototypes.GetElement(columnUiName);
                    if (prefab == null)
                    {
                        columnUiName = colS.data.columnUi.ResolveString(errLog, rowData.obj);
                        throw new Exception("no such prefab \"" + columnUiName + "\" in data sheet initialization script. valid values: [" +
                                            uiPrototypes.transform.JoinToString() + "]\n---\n" + colS.data.columnUi + "\n---\n" + columnSetup);
                    }
                    fieldUi = Instantiate(prefab);
                }

                if (colS.data.onClick.IsSyntax)
                {
                    ClickableScriptedCell clickable = fieldUi.GetComponent <ClickableScriptedCell>();
                    UiClick.ClearOnClick(fieldUi);
                    if (fieldUi != null)
                    {
                        Destroy(clickable);
                    }
                    clickable = fieldUi.AddComponent <ClickableScriptedCell>();
                    clickable.Set(rowData.obj, colS.data.onClick);
                    clickable.debugMetaData = colS.data.onClick.StringifySmall();
                    if (!UiClick.AddOnButtonClickIfNotAlready(fieldUi, clickable, clickable.OnClick))
                    {
                        UiClick.AddOnPanelClickIfNotAlready(fieldUi, clickable, clickable.OnClick);
                    }
                }

                fieldUi.SetActive(true);
                fieldUi.transform.SetParent(rObj.transform, false);
                fieldUi.transform.SetSiblingIndex(c);
                object value = columns[c];
                if (value != null)
                {
                    UiText.SetText(fieldUi, value.ToString());
                }
                else
                {
                    UiText.SetText(fieldUi, "");
                }
                rect = fieldUi.GetComponent <RectTransform>();
                rect.anchoredPosition = rowCursor;
                float w = rect.sizeDelta.x;
                if (colS.data.widthOfColumn > 0)
                {
                    w = colS.data.widthOfColumn;
                    rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, w);
                }
                rowCursor.x += w * rt.localScale.x;
            }
            for (int i = 0; i < unusedColumns.Count; ++i)
            {
                Destroy(unusedColumns[i]);
            }
            unusedColumns.Clear();
            rect = rObj.GetComponent <RectTransform>();
            rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, rowCursor.x);
            rect.transform.SetParent(contentRectangle, false);
            if (!float.IsNaN(yPosition))
            {
                //rect.anchoredPosition = new Vector2(0, -yPosition);
                //rect.localPosition = new Vector2(0, -yPosition);
                rObj.LocalPosition = new Vector2(0, -yPosition);
            }
            return(rObj.gameObject);
        }
Exemplo n.º 5
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();
        }
Exemplo n.º 6
0
    void Update()
    {
        if (visionParticle != null)
        {
            if (characterMover.JumpButtonTimed > 0 && !visionParticle.isPlaying)
            {
                visionParticle.Play();
            }
            else if (characterMover.JumpButtonTimed == 0 && visionParticle.isPlaying)
            {
                visionParticle.Stop();
            }
        }
        Coord mapSize = maze.Map.GetSize();

        if (mapAstar == null)
        {
            mapAstar = new Map2dAStar(() => canJump, maze, discovery.vision, _t, prefab_debug_astar);
        }
        mapAstar.UpdateMapSize();
        Vector3 p    = _t.position;
        Coord   here = maze.GetCoord(p);

        if (follower.waypoints.Count > 0)
        {
            Coord there = maze.GetCoord(follower.waypoints[0].positon);
            if (here == there)
            {
                follower.NotifyWayPointReached();
            }
        }
        List <Coord> moves = mapAstar.Moves(here, canJump);

        if (textOutput != null)
        {
            UiText.SetText(textOutput, here.ToString() + ":" + (p - maze.transform.position) + " " + moves.JoinToString(", "));
        }
        if (useVisionParticle && visionParticle)
        {
            timer -= Time.deltaTime;
            if (timer <= 0)
            {
                mapSize.ForEach(co => {
                    if (discovery.vision[co])
                    {
                        Vector3 po = maze.GetPosition(co);
                        po.y       = _t.position.y;
                        visionParticle.transform.position = po;
                        visionParticle.Emit(1);
                    }
                });
                timer = .5f;
            }
        }
        switch (aiBehavior)
        {
        case AiBehavior.RandomLocalEdges:
            if (!characterMover.IsAutoMoving())
            {
                Coord c = moves[Random.Next(moves.Count)];
                characterMover.SetAutoMovePosition(MoveablePosition(c, p));
            }
            break;

        case AiBehavior.RandomInVision:
            if (mapAstar.goal == here)
            {
                if (mapAstar.RandomVisibleNode(out Coord there, here))
                {
                    //Debug.Log("startover #");
                    //Debug.Log("goal " + there+ " "+astar.IsFinished());
                }
                else
                {
                    mapAstar.RandomNeighborNode(out there, here);
                }
                mapAstar.Start(here, there);
            }
            else
            {
                // iterate astar algorithm
                if (!mapAstar.IsFinished())
                {
                    mapAstar.Update();
                }
                else if (mapAstar.BestPath == null)
                {
                    //Debug.Log("f" + astar.IsFinished() + " " + astar.BestPath);
                    mapAstar.Start(here, here);
                    //Debug.Log("startover could not find path");
                }
                if (mapAstar.BestPath != null)
                {
                    if (mapAstar.BestPath != currentBestPath)
                    {
                        currentBestPath = mapAstar.BestPath;
                        List <Coord> nodes = new List <Coord>();
                        Coord        c     = mapAstar.start;
                        nodes.Add(c);
                        for (int i = currentBestPath.Count - 1; i >= 0; --i)
                        {
                            c = mapAstar.NextNode(c, currentBestPath[i]);
                            nodes.Add(c);
                        }
                        //Debug.Log(currentBestPath.JoinToString(", "));
                        indexOnBestPath = nodes.IndexOf(here);
                        if (indexOnBestPath < 0)
                        {
                            mapAstar.Start(here, mapAstar.goal);
                            //Debug.Log("startover new better path");
                        }
                        Vector3 pos = p;
                        follower.ClearWaypoints();
                        for (int i = 0; i < currentBestPath.Count; ++i)
                        {
                            pos = MoveablePosition(nodes[i + 1], pos);
                            //pos.y += follower.CharacterHeight;
                            //Show.Log(i + " " + nodes.Count + " " + currentBestPath.Count + " " + (currentBestPath.Count - i - 1));
                            MazeAStar.EdgeMoveType moveType = MazeAStar.GetEdgeMoveType(currentBestPath[currentBestPath.Count - i - 1]);
                            switch (moveType)
                            {
                            case MazeAStar.EdgeMoveType.Walk: follower.AddWaypoint(pos, false); break;

                            case MazeAStar.EdgeMoveType.Fall: follower.AddWaypoint(pos, false, 0, true); break;

                            case MazeAStar.EdgeMoveType.Jump: follower.AddWaypoint(pos, false, characterMover.jump.fullPressDuration); break;
                            }
                        }
                        follower.SetCurrentTarget(pos);
                        follower.UpdateLine();
                        follower.doPrediction = true;
                    }
                    else
                    {
                        if (!characterMover.IsAutoMoving() && follower.waypoints.Count == 0)
                        {
                            mapAstar.Start(here, here);
                            //Debug.Log("startover new level?");
                        }
                    }
                }
            }
            break;
        }
    }