Esempio n. 1
0
    public static GridViewSettings CreateGridViewSettings(this WebViewPage view, GridType gridType)
    {
        GridViewSettings settings = new GridViewSettings();

        settings.Name = "GridView" + gridType.ToString();
        settings.CallbackRouteValues = new { Controller = "Home", Action = "GridViewPartial", gridType = gridType };
        settings.KeyFieldName        = "Id";

        if (gridType == GridType.Invoices)
        {
            settings.Columns.Add("Id");
            settings.Columns.Add("Price");
            settings.Columns.Add(column => {
                column.Caption = "Description";
                column.SetDataItemTemplateContent(container => {
                    view.Html.DevExpress().HyperLink(hyperlink => {
                        var keyValue    = container.KeyValue;
                        var description = DataBinder.Eval(container.DataItem, "Description");

                        hyperlink.Name            = "hl" + keyValue.ToString();
                        hyperlink.Properties.Text = description.ToString();
                        hyperlink.NavigateUrl     = view.Url.Action("Details", "Home", new { key = keyValue });
                    }).Render();
                });
            });
        }

        return(settings);
    }
        private static void RenderGridImageAsPngFile(GridType gridType)
        {
            var gridLines = GridCreator.CreateGrid(gridType, ImageWidth, ImageHeight, false);

            var outputPath = Path.Combine(Path.GetTempPath(), "ScreenGrid");

            if (!Directory.Exists(outputPath))
            {
                Directory.CreateDirectory(outputPath);
            }

            using (var image = new Bitmap(ImageWidth, ImageHeight))
            {
                using (var g = Graphics.FromImage(image))
                {
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                    g.Clear(Color.Transparent);
                    using (var pen = new Pen(Color.Black))
                    {
                        foreach (var line in gridLines)
                        {
                            g.DrawLine(
                                pen,
                                new Point((int)(line.p1.X * (ImageWidth - 1)), (int)(line.p1.Y * (ImageHeight - 1))),
                                new Point((int)(line.p2.X * (ImageWidth - 1)), (int)(line.p2.Y * (ImageHeight - 1))));
                        }
                    }
                }

                image.Save(Path.Combine(outputPath, gridType.ToString() + ".png"), System.Drawing.Imaging.ImageFormat.Png);
            }
        }
Esempio n. 3
0
    public void ClickZhongDian()
    {
        curType = GridType.End;
        var go = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject;

        curColor = go.GetComponent <Image>().color;
        Debug.Log(curType.ToString());
    }
        private MyDataGrid GetMyDataGrid(InternalLeagueCode internalLeagueCode, GridType gridType)
        {
            var dataGrid = new MyDataGrid
            {
                Name       = internalLeagueCode + gridType.ToString(),
                Visibility = Visibility.Visible,
            };

            if (_competitionResultSingletonInstance == null)
            {
                dataGrid.ItemsSource = _nullStandings;
            }
            else
            {
                DataGridLoaded(dataGrid, internalLeagueCode, gridType);
            }

            return(dataGrid);
        }
Esempio n. 5
0
        private void BuildMap()
        {
            foreach (Transform child in transform)
            {
                if (child.gameObject != m_Background && child.gameObject != m_GridPrefab)
                {
                    GameObject.Destroy(child.gameObject);
                }
            }

            float gridWidth  = m_Boundary.width / mMapData.Width;
            float gridHeight = m_Boundary.height / mMapData.Height;

            mGridLength = Mathf.Min(gridWidth, gridHeight);

            float mapWidth  = mGridLength * mMapData.Width;
            float mapHeight = mGridLength * mMapData.Height;

            m_Background.transform.localPosition = new Vector3(m_Boundary.center.x, m_Boundary.center.y, 1);
            m_Background.transform.localScale    = new Vector3(mapWidth + 0.2f, mapHeight + 0.2f, 1);

            //topleft
            Vector3 startPos = new Vector3(m_Boundary.center.x - 0.5f * mapWidth, m_Boundary.center.y + 0.5f * mapHeight);

            startPos.x += 0.5f * mGridLength;
            startPos.y -= 0.5f * mGridLength;

            Vector3 gridPos = startPos;

            mGrids = new MazeGrid[mMapData.Height, mMapData.Width];

            for (int i = 0; i < mMapData.Height; i++)
            {
                for (int j = 0; j < mMapData.Width; j++)
                {
                    int      index    = i * mMapData.Width + j;
                    GridType gridType = mMapData.Grids[index];

                    GameObject gridObj = GameObject.Instantiate(m_GridPrefab, transform, false);
                    gridObj.SetActive(true);
                    gridObj.name = "Grid" + gridType.ToString();
                    gridObj.GetComponent <SpriteRenderer>().sprite = Resources.Load <Sprite>(MazeDefine.GridTextures[gridType]);

                    gridObj.transform.localPosition = gridPos;
                    gridObj.transform.localScale    = new Vector3(mGridLength, mGridLength, 1);

                    if (j < mMapData.Width - 1)
                    {
                        gridPos.x += mGridLength;
                    }
                    else
                    {
                        gridPos.x = startPos.x;
                    }

                    MazeGrid grid = MazeGridFactory.Create(gridType, new Vector2 <int>(j, i));
                    grid.GridObject = gridObj;
                    mGrids[i, j]    = grid;

                    if (gridType == GridType.Start)
                    {
                        mStart = grid;
                    }
                    else if (gridType == GridType.Terminal)
                    {
                        mTerminal = grid;
                    }
                }
                gridPos.y -= mGridLength;
            }
        }
Esempio n. 6
0
        public override string ToString()
        {
            StringBuilder strRet = new StringBuilder();

            strRet.Append("_emptyField: ''");
            if (DataType != string.Empty)
            {
                strRet.AppendFormat(", datatype:'{0}'", DataType);
            }
            if (GridType != null)
            {
                strRet.AppendFormat(", GridType:'{0}'", GridType.ToString());
            }
            if (URL != string.Empty)
            {
                strRet.AppendFormat(", url:'{0}'", URL);
            }
            if (MType != string.Empty)
            {
                strRet.AppendFormat(", mtype:'{0}'", MType.Trim());
            }
            if (Height != null)
            {
                strRet.AppendFormat(", height:'{0}'", Height.ToString());
            }
            if (Sortable != string.Empty)
            {
                strRet.AppendFormat(", sortable:'{0}'", Sortable);
            }
            if (Width != null)
            {
                strRet.AppendFormat(", width:'{0}'", Width);
            }
            if (IsDynamic != null)
            {
                strRet.AppendFormat(", isdynamic:{0}", (bool)IsDynamic ? "true" : "false");
            }
            if (IsMultiSelect != null)
            {
                strRet.AppendFormat(", multiselect:{0}", (bool)IsMultiSelect ? "true" : "false");
            }
            if (Caption != string.Empty)
            {
                strRet.AppendFormat(", caption:'{0}'", Caption);
            }
            if (ForceFit != string.Empty)
            {
                strRet.AppendFormat(", forceFit:'{0}'", ForceFit);
            }
            if (RowNum != null)
            {
                strRet.AppendFormat(", rowNum:{0}", RowNum);
            }
            if (RowNumber != null)
            {
                strRet.AppendFormat(", rownumbers:{0}", (bool)RowNumber ? "true" : "false");
            }
            if (RowNumWidth != string.Empty)
            {
                strRet.AppendFormat(", rownumWidth:{0}", RowNumWidth);
            }
            if (SubGrid != null)
            {
                strRet.AppendFormat(", subGrid:{0}", (bool)RowNumber ? "true" : "false");
            }
            if (FooterSummary != null)
            {
                strRet.AppendFormat(", footerSummary:{0}", (bool)FooterSummary ? "true" : "false");
            }
            // column != 0 => fixed column
            if (FixedColumn != 0)
            {
                strRet.AppendFormat(", fixedcolumn:{0}", FixedColumn);
            }
            strRet.AppendFormat(", allowEdit:{0}", AllowEdit ? "true" : "false");
            strRet.AppendFormat(", allowDelete:{0}", AllowDelete ? "true" : "false");
            strRet.AppendFormat(", allowAddRow:{0}", AllowAddRow ? "true" : "false");
            strRet.AppendFormat(", numberEmptyRow:{0}", NumberEmptyRow);

            if (AdditionAttribute != string.Empty && AdditionAttribute != null)
            {
                string[] arr = AdditionAttribute.Split(',');
                if (arr.Length > 0)
                {
                    for (int i = 0; i < arr.Length; i++)
                    {
                        strRet.AppendFormat(", {0}: {1}", arr[i].Split(':')[0], arr[i].Split(':')[1]);
                    }
                }
            }
            return(strRet.ToString());
        }
Esempio n. 7
0
    public void Init()
    {
        //设置大小
        templateObjPar.SetActive(false);
        int mapIconSize = gridSize - 2 * iconEdgeSize;

        blockTemplate.width       = mapIconSize;
        blockTemplate.height      = mapIconSize;
        startPointTemplate.width  = mapIconSize;
        startPointTemplate.height = mapIconSize;
        endPointTemplate.width    = mapIconSize;
        endPointTemplate.height   = mapIconSize;
        lineTemplate.width        = mapIconSize;
        lineTemplate.height       = mapIconSize;
        pathTemplate.width        = mapIconSize;
        pathTemplate.height       = mapIconSize;

        //保存初始化输入框提示
        mInputInitValue = inputSaveName.value;

        //描画背景
        int bgWidth  = gridSize * (int)MapManager.Instant.MapWidth + edgeSize * 2;
        int bgHeight = gridSize * (int)MapManager.Instant.MapHeight + edgeSize * 2;

        sprBg.transform.localPosition = new Vector3(0f, 0f, 0f);
        sprBg.width  = bgWidth;
        sprBg.height = bgHeight;
        BoxCollider collider = sprBg.GetComponent <BoxCollider> ();

        collider.size   = new Vector3(MapManager.Instant.MapWidth * gridSize, MapManager.Instant.MapHeight * gridSize, 0f);
        collider.center = new Vector3(bgWidth / 2f, -bgHeight / 2f, 0f);
        UIEventListener.Get(collider.gameObject).onClick = OnBgClick;

        //描画格子
        float topPos    = -edgeSize;
        float leftPos   = edgeSize;
        float bottomPos = topPos - MapManager.Instant.MapHeight * gridSize;
        float rightPos  = leftPos + MapManager.Instant.MapWidth * gridSize;

        //竖线
        for (int i = 0; i <= MapManager.Instant.MapWidth; ++i)
        {
            float    posX    = i * gridSize + leftPos;
            UISprite sprLine = CreateLine();
            sprLine.width = (int)(topPos - bottomPos);
            sprLine.transform.localEulerAngles = new Vector3(0f, 0f, -90f);
            sprLine.transform.localPosition    = new Vector3(posX, topPos, 0f);
        }
        //横线
        for (int i = 0; i <= MapManager.Instant.MapHeight; ++i)
        {
            float    posY    = topPos - i * gridSize;
            UISprite sprLine = CreateLine();
            sprLine.width = (int)(rightPos - leftPos);
            sprLine.transform.localEulerAngles = new Vector3(0f, 0f, 0f);
            sprLine.transform.localPosition    = new Vector3(leftPos, posY, 0f);
        }

        //创建起始点
        mStartPoint = GameObject.Instantiate(startPointTemplate) as UISprite;
        mStartPoint.transform.parent     = transView;
        mStartPoint.transform.localScale = Vector3.one;
        HideStartPoint();

        //创建结束点
        mEndPoint = GameObject.Instantiate(endPointTemplate) as UISprite;
        mEndPoint.transform.parent     = transView;
        mEndPoint.transform.localScale = Vector3.one;
        HideEndPoint();

        //选择列表
        Array array = Enum.GetValues(typeof(GridType));

        for (int i = 0; i < array.Length; ++i)
        {
            GridType type = (GridType)array.GetValue(i);
            UIToggle tog  = GameObject.Instantiate(togTemplate) as UIToggle;
            tog.transform.parent        = togParent;
            tog.transform.localScale    = Vector3.one;
            tog.transform.localPosition = new Vector3(0f, -togHeight * i, 0f);
            tog.name = type.ToString();
            tog.GetComponentInChildren <UILabel> ().text = type.ToString();
            mTogList.Add(tog);
        }
        mTogList [0].value = true;

        UIEventListener.Get(btnFindPath.gameObject).onClick      = OnFindPathClicked;
        UIEventListener.Get(btnClearFindPath.gameObject).onClick = OnClearPathClicked;
        UIEventListener.Get(btnSaveData.gameObject).onClick      = OnSaveData;
        UIEventListener.Get(btnLoadData.gameObject).onClick      = OnLoadData;

        RefreshBlock();
    }
Esempio n. 8
0
        /// <summary>
        /// Creates list of lines, which forms the selected grid type
        /// X axis is directed from left to right
        /// Y axis is directed from top to bottom
        /// Coordinates are in normalized range [0..1]
        /// </summary>
        /// <param name="gridType">Selected type of grid</param>
        /// <param name="width">Width of output image</param>
        /// <param name="height">Height of output image</param>
        /// <param name="isRotated">Output grid is rotated (width swapped with height)</param>
        /// <returns>List of lines</returns>
        public static IList <Line> CreateGrid(GridType gridType, double width, double height, bool isRotated)
        {
            var actualAspectRatio = CalculateAspectRatio(width, height, isRotated);

            switch (gridType)
            {
            case GridType.None:
            {
                return(new List <Line>());
            }

            case GridType.Crosshair:
            {
                const double HorizontalTickLength = (3.0 / 100.0);
                const double VerticalTickLength   = (1.0 / 30.0);
                const double CentralTickLength    = (3.0 / 200.0);

                var aspect = (width / height);

                var points = new[]
                {
                    new Point(RatioConstants.Zero, RatioConstants.Half), new Point(RatioConstants.Zero + HorizontalTickLength, RatioConstants.Half),
                    new Point(RatioConstants.One, RatioConstants.Half), new Point(RatioConstants.One - HorizontalTickLength, RatioConstants.Half),
                    new Point(RatioConstants.Half, RatioConstants.One), new Point(RatioConstants.Half, RatioConstants.One - VerticalTickLength),
                    new Point(RatioConstants.Half, RatioConstants.Zero), new Point(RatioConstants.Half, RatioConstants.Zero + VerticalTickLength),
                    new Point(RatioConstants.Half - CentralTickLength, RatioConstants.Half), new Point(RatioConstants.Half + CentralTickLength, RatioConstants.Half),
                    new Point(RatioConstants.Half, RatioConstants.Half - CentralTickLength * aspect), new Point(RatioConstants.Half, RatioConstants.Half + CentralTickLength * aspect),
                };

                return(CreateLines(points));
            }

            case GridType.Thirds:
            {
                var points = new[]
                {
                    new Point(RatioConstants.Zero, RatioConstants.OneThird), new Point(RatioConstants.One, RatioConstants.OneThird),
                    new Point(RatioConstants.Zero, RatioConstants.TwoThirds), new Point(RatioConstants.One, RatioConstants.TwoThirds),
                    new Point(RatioConstants.OneThird, RatioConstants.Zero), new Point(RatioConstants.OneThird, RatioConstants.One),
                    new Point(RatioConstants.TwoThirds, RatioConstants.Zero), new Point(RatioConstants.TwoThirds, RatioConstants.One),
                };

                return(CreateLines(points));
            }

            case GridType.DiagonalOfThirds:
            {
                var points = new[]
                {
                    new Point(RatioConstants.Zero, RatioConstants.One), new Point(RatioConstants.One, RatioConstants.Zero),
                    new Point(RatioConstants.Zero, RatioConstants.One - (RatioConstants.OneSixth)), new Point(RatioConstants.One - (RatioConstants.OneSixth), RatioConstants.Zero),
                    new Point(RatioConstants.OneSixth, RatioConstants.One), new Point(RatioConstants.One, RatioConstants.OneSixth),
                };

                return(CreateLines(points));
            }

            case GridType.GoldenRatio:
            {
                var points = new[]
                {
                    new Point(RatioConstants.Zero, RatioConstants.Phi3D8), new Point(RatioConstants.One, RatioConstants.Phi3D8),
                    new Point(RatioConstants.Zero, RatioConstants.Phi5D8), new Point(RatioConstants.One, RatioConstants.Phi5D8),
                    new Point(RatioConstants.Phi3D8, RatioConstants.Zero), new Point(RatioConstants.Phi3D8, RatioConstants.One),
                    new Point(RatioConstants.Phi5D8, RatioConstants.Zero), new Point(RatioConstants.Phi5D8, RatioConstants.One),
                };

                return(CreateLines(points));
            }

            case GridType.GoldenTriangle:
            {
                var srcPoints = new List <Point>(6);
                srcPoints.Add(new Point(RatioConstants.Zero, RatioConstants.Zero));
                srcPoints.Add(new Point(RatioConstants.One, RatioConstants.One));

                // TODO: if ((this.rotation == Rotation.R0) || (this.rotation == Rotation.R180))
                {
                    var pt1 = new Point(0.0, height);
                    var pt2 = new Point(width, 0.0);

                    {
                        var pt4 = Models.Geometry.Utils.PerpendicularIntersection(pt1, pt2, Point.Zero);
                        pt4.Y = height - pt4.Y;

                        srcPoints.Add(new Point(pt1.X / width, pt1.Y / height));
                        srcPoints.Add(new Point(pt4.X / width, pt4.Y / height));
                    }

                    {
                        var pt4 = Models.Geometry.Utils.PerpendicularIntersection(pt1, pt2, new Point(width, height));
                        pt4.Y = height - pt4.Y;

                        srcPoints.Add(new Point(pt2.X / width, pt2.Y / height));
                        srcPoints.Add(new Point(pt4.X / width, pt4.Y / height));
                    }
                }

                return(CreateLines(srcPoints.ToArray()));
            }

            case GridType.GoldenDiagonal1:
            {
                var points = new[]
                {
                    new Point(RatioConstants.Zero, RatioConstants.One), new Point(RatioConstants.One, RatioConstants.Zero),
                    new Point(RatioConstants.Zero, RatioConstants.One), new Point(RatioConstants.Phi3D8, RatioConstants.Zero),
                    new Point(RatioConstants.Phi5D8, RatioConstants.One), new Point(RatioConstants.One, RatioConstants.Zero),
                };

                return(CreateLines(points));
            }

            case GridType.GoldenDiagonal2:
            {
                var points = new[]
                {
                    new Point(RatioConstants.Zero, RatioConstants.One), new Point(RatioConstants.One, RatioConstants.Zero),
                    new Point(RatioConstants.Zero, RatioConstants.Zero), new Point(RatioConstants.Phi3D8, RatioConstants.One),
                    new Point(RatioConstants.Phi5D8, RatioConstants.Zero), new Point(RatioConstants.One, RatioConstants.One),
                };

                return(CreateLines(points));
            }

            case GridType.FibonacciRectanglesZoomed:
            case GridType.FibonacciRectanglesStretched:
            {
                // https://en.wikipedia.org/wiki/Fibonacci_number
                // http://stackoverflow.com/a/18121331/1182448

                // Current Fibonacci numbers
                var current  = 1;
                var previous = 0;

                // Current bounding box
                var left   = 0;
                var right  = 1;
                var top    = 0;
                var bottom = 0;

                const int NumberOfRectangles = 10;

                var lines = new List <Line>();
                for (var i = 0; i < NumberOfRectangles; i++)
                {
                    switch (i % 4)
                    {
                    case 0:             // attach to bottom of current rectangle
                        lines.AddRange(CreateRectangleLines(left, right, bottom, bottom + current));
                        bottom += current;
                        break;

                    case 1:             // attach to right of current rectangle
                        lines.AddRange(CreateRectangleLines(right, right + current, top, bottom));
                        right += current;
                        break;

                    case 2:             // attach to top of current rectangle
                        lines.AddRange(CreateRectangleLines(left, right, top - current, top));
                        top -= current;
                        break;

                    case 3:             // attach to left of current rectangle
                        lines.AddRange(CreateRectangleLines(left - current, left, top, bottom));
                        left -= current;
                        break;
                    }

                    // TODO: create precalculated (Lazy) array of Fibonnacci numbers
                    // Update current fibonacci number
                    {
                        var temp = current;
                        current += previous;
                        previous = temp;
                    }
                }

                if (gridType == GridType.FibonacciRectanglesZoomed)
                {
                    var aspect = (isRotated) ? (height / width) : (width / height);
                    lines = StretchToRectangleWithAspectRatio(lines, aspect, left, right, top, bottom);
                }
                else if (gridType == GridType.FibonacciRectanglesStretched)
                {
                    lines = StretchToUniformRectangle(lines, left, top, right, bottom);
                }
                else
                {
                    throw new ArgumentOutOfRangeException(gridType.ToString());
                }

                return(lines);
            }

            case GridType.GoldenSpiralZoomed:
            case GridType.GoldenSpiralStretched:
            {
                // https://en.wikipedia.org/wiki/Golden_spiral
                // http://csharphelper.com/blog/2012/05/draw-a-phi-spiral-or-golden-spiral-in-c/

                // TODO: Simplify code (use some pre-calculations and common functions)
                var points = new List <Point>();

                const double CenterX = 0.5;
                const double CenterY = 0.5;
                var          minX    = CenterX;
                var          minY    = CenterY;
                var          maxX    = CenterX;
                var          maxY    = CenterY;

                const int    NumberOfTurns = 3;
                const double FullTurn      = 2.0 * Math.PI;
                const double MaxAngle      = ((double)NumberOfTurns) * FullTurn;

                for (var theta = 0.0; theta < MaxAngle;)
                {
                    var r = Math.Pow(RatioConstants.GoldenSpiralCInRadians, theta);

                    var x = CenterX + r * Math.Cos(theta);
                    var y = 1.0 - (CenterY + r * Math.Sin(theta));         // Flip Y axis

                    points.Add(new Point(x, y));

                    minX = Math.Min(minX, x);
                    minY = Math.Min(minY, y);
                    maxX = Math.Max(maxX, x);
                    maxY = Math.Max(maxY, y);

                    // variable step for optimization
                    var turnNumber = theta / FullTurn;
                    var step       = 0.005 * 5.0 * ((double)NumberOfTurns) / (turnNumber + 1.0) * FullTurn;
                    theta += step;
                }

                // Add some points after main turns to finish spiral (inscribe to rectangle)
                var lastY = minY;
                for (var theta = MaxAngle; ; theta += 0.001 * FullTurn)
                {
                    var r = Math.Pow(RatioConstants.GoldenSpiralCInRadians, theta);

                    var x = CenterX + r * Math.Cos(theta);
                    var y = 1.0 - (CenterY + r * Math.Sin(theta));         // Flip Y axis

                    points.Add(new Point(x, y));

                    minX = Math.Min(minX, x);
                    minY = Math.Min(minY, y);
                    maxX = Math.Max(maxX, x);
                    maxY = Math.Max(maxY, y);

                    if (y <= lastY)
                    {
                        // TODO: Correct last point (clip to bounds)
                        break;
                    }
                }

                var lines = new List <Line>();
                for (var i = 1; i < points.Count; i++)
                {
                    lines.Add(new Line(points[i - 1], points[i]));
                }

                if (gridType == GridType.GoldenSpiralZoomed)
                {
                    var aspect = (isRotated) ? (height / width) : (width / height);
                    lines = StretchToRectangleWithAspectRatio(lines, aspect, minX, maxX, minY, maxY);

                    // Adding extents lines
                    var extents = GetExtents(lines);
                    if (aspect < RatioConstants.Phi)
                    {
                        lines.Add(new Line(RatioConstants.Zero, extents.Top, RatioConstants.One, extents.Top));
                        lines.Add(new Line(RatioConstants.Zero, extents.Bottom, RatioConstants.One, extents.Bottom));
                    }
                    else
                    {
                        lines.Add(new Line(extents.Left, RatioConstants.Zero, extents.Left, RatioConstants.One));
                        lines.Add(new Line(extents.Right, RatioConstants.Zero, extents.Right, RatioConstants.One));
                    }
                }
                else if (gridType == GridType.GoldenSpiralStretched)
                {
                    lines = StretchToUniformRectangle(lines, minX, minY, maxX, maxY);
                }
                else
                {
                    throw new ArgumentOutOfRangeException(gridType.ToString());
                }

                return(lines);
            }

            case GridType.OneDotFiveRectangle:
            {
                var rectangle = CalculateDynamicRectangleExtents(RatioConstants.OneDotFive, actualAspectRatio);
                var lines     = CreateRectangleWithMainDiagonals(rectangle);

                var w = rectangle.Width / (RatioConstants.OneDotFive * RatioConstants.OneDotFive);
                var h = rectangle.Height / (RatioConstants.OneDotFive * RatioConstants.OneDotFive);
                lines.Add(new Line(rectangle.Left + w, rectangle.Top, rectangle.Left + w, rectangle.Bottom));
                lines.Add(new Line(rectangle.Right - w, rectangle.Top, rectangle.Right - w, rectangle.Bottom));
                lines.Add(new Line(rectangle.Left, rectangle.Top + h, rectangle.Right, rectangle.Top + h));
                lines.Add(new Line(rectangle.Left, rectangle.Bottom - h, rectangle.Right, rectangle.Bottom - h));

                // Left
                lines.Add(new Line(rectangle.Left, rectangle.Top, rectangle.Left + w, rectangle.Bottom));
                lines.Add(new Line(rectangle.Left, rectangle.Bottom, rectangle.Left + w, rectangle.Top));

                // Right
                lines.Add(new Line(rectangle.Right, rectangle.Top, rectangle.Right - w, rectangle.Bottom));
                lines.Add(new Line(rectangle.Right, rectangle.Bottom, rectangle.Right - w, rectangle.Top));

                return(lines);
            }

            case GridType.GoldenRectangle:
            {
                var rectangle = CalculateDynamicRectangleExtents(RatioConstants.Phi / RatioConstants.One, actualAspectRatio);
                var lines     = CreateRectangleWithMainDiagonals(rectangle);

                var w = rectangle.Width * RatioConstants.Phi3D8;
                var h = rectangle.Height * RatioConstants.Phi3D8;

                lines.Add(new Line(rectangle.Left, rectangle.Top + h, rectangle.Right, rectangle.Top + h));
                lines.Add(new Line(rectangle.Left, rectangle.Bottom - h, rectangle.Right, rectangle.Bottom - h));
                lines.Add(new Line(rectangle.Left + w, rectangle.Top, rectangle.Left + w, rectangle.Bottom));
                lines.Add(new Line(rectangle.Right - w, rectangle.Top, rectangle.Right - w, rectangle.Bottom));
                // Left
                lines.Add(new Line(rectangle.Left, rectangle.Top, rectangle.Left + w, rectangle.Bottom));
                lines.Add(new Line(rectangle.Left, rectangle.Bottom, rectangle.Left + w, rectangle.Top));
                // Right
                lines.Add(new Line(rectangle.Right, rectangle.Top, rectangle.Right - w, rectangle.Bottom));
                lines.Add(new Line(rectangle.Right, rectangle.Bottom, rectangle.Right - w, rectangle.Top));

                return(lines);
            }

            case GridType.GoldenCircles:
            {
                var lines = new List <Line>();

                var rectangle  = CalculateDynamicRectangleExtents(RatioConstants.Phi, actualAspectRatio);
                var centerLine = rectangle.Top + rectangle.Height / 2.0;

                // Major circles
                var majorRadius = (rectangle.Width * RatioConstants.Phi5D8) / 2.0;
                lines.AddRange(CreateCirclePoints(rectangle.Left + majorRadius, centerLine, majorRadius, actualAspectRatio));
                lines.AddRange(CreateCirclePoints(rectangle.Right - majorRadius, centerLine, majorRadius, actualAspectRatio));

                // Minor circles
                var minorRadius = (rectangle.Width * RatioConstants.Phi3D8) / 2.0;
                lines.AddRange(CreateCirclePoints(rectangle.Left + minorRadius, centerLine, minorRadius, actualAspectRatio));
                lines.AddRange(CreateCirclePoints(rectangle.Right - minorRadius, centerLine, minorRadius, actualAspectRatio));

                return(lines);
            }

            case GridType.RootPhiRectangle:
            {
                var rectangle = CalculateDynamicRectangleExtents(RatioConstants.RootPhi / RatioConstants.One, actualAspectRatio);
                var lines     = CreateRectangleWithMainDiagonals(rectangle);

                var w = rectangle.Width / (RatioConstants.RootPhi * RatioConstants.RootPhi);
                var h = rectangle.Height / (RatioConstants.RootPhi * RatioConstants.RootPhi);

                lines.Add(new Line(rectangle.Left + w, rectangle.Top, rectangle.Left + w, rectangle.Bottom));
                lines.Add(new Line(rectangle.Right - w, rectangle.Top, rectangle.Right - w, rectangle.Bottom));
                lines.Add(new Line(rectangle.Left, rectangle.Top + h, rectangle.Right, rectangle.Top + h));
                lines.Add(new Line(rectangle.Left, rectangle.Bottom - h, rectangle.Right, rectangle.Bottom - h));

                // Left
                lines.Add(new Line(rectangle.Left, rectangle.Top, rectangle.Left + w, rectangle.Bottom));
                lines.Add(new Line(rectangle.Left, rectangle.Bottom, rectangle.Left + w, rectangle.Top));

                // Right
                lines.Add(new Line(rectangle.Right, rectangle.Top, rectangle.Right - w, rectangle.Bottom));
                lines.Add(new Line(rectangle.Right, rectangle.Bottom, rectangle.Right - w, rectangle.Top));

                return(lines);
            }

            case GridType.Root2Rectangle:
            {
                var rectangle = CalculateDynamicRectangleExtents(RatioConstants.Root2 / RatioConstants.One, actualAspectRatio);
                var lines     = CreateRectangleWithMainDiagonals(rectangle);
                lines.Add(new Line(rectangle.Left, RatioConstants.Half, rectangle.Right, RatioConstants.Half));
                lines.Add(new Line(RatioConstants.Half, rectangle.Top, RatioConstants.Half, rectangle.Bottom));
                lines.Add(new Line(rectangle.Left, rectangle.Bottom, RatioConstants.Half, rectangle.Top));
                lines.Add(new Line(rectangle.Left, rectangle.Top, RatioConstants.Half, rectangle.Bottom));
                lines.Add(new Line(RatioConstants.Half, rectangle.Bottom, rectangle.Right, rectangle.Top));
                lines.Add(new Line(RatioConstants.Half, rectangle.Top, rectangle.Right, rectangle.Bottom));

                return(lines);
            }

            case GridType.Root3Rectangle:
            {
                var rectangle = CalculateDynamicRectangleExtents(RatioConstants.Root3 / RatioConstants.One, actualAspectRatio);
                var lines     = CreateRectangleWithMainDiagonals(rectangle);
                lines.AddRange(CreateRegularLines(rectangle, 2));
                var w = rectangle.Width / 3.0;
                // Left
                lines.Add(new Line(rectangle.Left, rectangle.Top, rectangle.Left + w, rectangle.Bottom));
                lines.Add(new Line(rectangle.Left, rectangle.Bottom, rectangle.Left + w, rectangle.Top));
                // Right
                lines.Add(new Line(rectangle.Right, rectangle.Top, rectangle.Right - w, rectangle.Bottom));
                lines.Add(new Line(rectangle.Right, rectangle.Bottom, rectangle.Right - w, rectangle.Top));
                // Two horizontals
                var h = rectangle.Height / 3.0;
                lines.Add(new Line(rectangle.Left, rectangle.Top + h, rectangle.Right, rectangle.Top + h));
                lines.Add(new Line(rectangle.Left, rectangle.Bottom - h, rectangle.Right, rectangle.Bottom - h));

                return(lines);
            }

            case GridType.Root4Rectangle:
            {
                var rectangle = CalculateDynamicRectangleExtents(RatioConstants.Root4 / RatioConstants.One, actualAspectRatio);
                var lines     = CreateRectangleWithMainDiagonals(rectangle);
                lines.AddRange(CreateRegularLines(rectangle, 3));
                var w = rectangle.Width / 4.0;
                // Left
                lines.Add(new Line(rectangle.Left, rectangle.Top, rectangle.Left + w, rectangle.Bottom));
                lines.Add(new Line(rectangle.Left, rectangle.Bottom, rectangle.Left + w, rectangle.Top));
                // Right
                lines.Add(new Line(rectangle.Right, rectangle.Top, rectangle.Right - w, rectangle.Bottom));
                lines.Add(new Line(rectangle.Right, rectangle.Bottom, rectangle.Right - w, rectangle.Top));

                lines.Add(new Line(rectangle.Left, rectangle.Bottom, rectangle.CenterX, rectangle.Top));
                lines.Add(new Line(rectangle.Right, rectangle.Bottom, rectangle.CenterX, rectangle.Top));
                lines.Add(new Line(rectangle.Left, rectangle.Top, rectangle.CenterX, rectangle.Bottom));
                lines.Add(new Line(rectangle.Right, rectangle.Top, rectangle.CenterX, rectangle.Bottom));
                // Two horizontals
                var h = rectangle.Height / 4.0;
                lines.Add(new Line(rectangle.Left, rectangle.Top + h, rectangle.Right, rectangle.Top + h));
                lines.Add(new Line(rectangle.Left, rectangle.Bottom - h, rectangle.Right, rectangle.Bottom - h));

                return(lines);
            }

            case GridType.Root5Rectangle:
            {
                var rectangle = CalculateDynamicRectangleExtents(RatioConstants.Root5 / RatioConstants.One, actualAspectRatio);
                var lines     = CreateRectangleWithMainDiagonals(rectangle);
                lines.AddRange(CreateRegularLines(rectangle, 4));
                var w = rectangle.Width / 5.0;
                // Left
                lines.Add(new Line(rectangle.Left, rectangle.Top, rectangle.Left + w, rectangle.Bottom));
                lines.Add(new Line(rectangle.Left, rectangle.Bottom, rectangle.Left + w, rectangle.Top));
                // Right
                lines.Add(new Line(rectangle.Right, rectangle.Top, rectangle.Right - w, rectangle.Bottom));
                lines.Add(new Line(rectangle.Right, rectangle.Bottom, rectangle.Right - w, rectangle.Top));

                var h = rectangle.Height / 5.0;
                lines.Add(new Line(rectangle.Left, rectangle.CenterY, rectangle.Right, rectangle.CenterY));
                lines.Add(new Line(rectangle.Left, rectangle.Top + h, rectangle.Right, rectangle.Top + h));
                lines.Add(new Line(rectangle.Left, rectangle.Bottom - h, rectangle.Right, rectangle.Bottom - h));

                return(lines);
            }

            case GridType.Armature14Line:
            {
                var points = new[]
                {
                    // Main diagonals
                    new Point(RatioConstants.Zero, RatioConstants.Zero), new Point(RatioConstants.One, RatioConstants.One),
                    new Point(RatioConstants.Zero, RatioConstants.One), new Point(RatioConstants.One, RatioConstants.Zero),

                    // Central rotated square
                    new Point(RatioConstants.Zero, RatioConstants.Half), new Point(RatioConstants.Half, RatioConstants.Zero),
                    new Point(RatioConstants.Zero, RatioConstants.Half), new Point(RatioConstants.Half, RatioConstants.One),
                    new Point(RatioConstants.One, RatioConstants.Half), new Point(RatioConstants.Half, RatioConstants.Zero),
                    new Point(RatioConstants.One, RatioConstants.Half), new Point(RatioConstants.Half, RatioConstants.One),

                    // From corners to sides
                    new Point(RatioConstants.Zero, RatioConstants.Zero), new Point(RatioConstants.One, RatioConstants.Half),
                    new Point(RatioConstants.Zero, RatioConstants.Zero), new Point(RatioConstants.Half, RatioConstants.One),
                    new Point(RatioConstants.Zero, RatioConstants.One), new Point(RatioConstants.Half, RatioConstants.Zero),
                    new Point(RatioConstants.Zero, RatioConstants.One), new Point(RatioConstants.One, RatioConstants.Half),
                    new Point(RatioConstants.One, RatioConstants.Zero), new Point(RatioConstants.Zero, RatioConstants.Half),
                    new Point(RatioConstants.One, RatioConstants.Zero), new Point(RatioConstants.Half, RatioConstants.One),
                    new Point(RatioConstants.One, RatioConstants.One), new Point(RatioConstants.Half, RatioConstants.Zero),
                    new Point(RatioConstants.One, RatioConstants.One), new Point(RatioConstants.Zero, RatioConstants.Half),
                };

                return(CreateLines(points));
            }

            default:
            {
                throw new ArgumentException(gridType.ToString());
            }
            }
        }
Esempio n. 9
0
    public static EnemyPiece Spawn(int _posX, int _posY, int _health, GridType _movementType, EnemyType _unitType)
    {
        EnemyPiece curPiece = null;

        for (int i = 0; i < enemyPool.Count; i++)
        {
            if (enemyPool[i].IsAlive == false)
            {
                curPiece                    = enemyPool[i];
                curPiece.mbIsAlive          = true;
                curPiece.mSpriteRen.enabled = true;

                curPiece.mnPosX   = _posX;
                curPiece.mnPosY   = _posY;
                curPiece.mnHealth = _health;
                curPiece.SetMovementType(_movementType);
                curPiece.SetUnitType(_unitType);
                int spriteIndex = Array.IndexOf(enemySpriteNames, _unitType.ToString() + "_" + _movementType.ToString());
                curPiece.mSpriteRen.sprite = enemySprites[spriteIndex];

                DungeonManager.Instance.PlaceEnemy(curPiece, _posX, _posY);
                curPiece.transform.position = DungeonManager.Instance.GridPosToWorldPos(_posX, _posY);

                break;
            }
        }

        if (curPiece == null)
        {
            GameObject newEnemyPiece = (GameObject)Instantiate(GameManager.Instance.EnemyPrefab);

            curPiece                    = newEnemyPiece.GetComponent <EnemyPiece>();
            curPiece.mbIsAlive          = true;
            curPiece.mSpriteRen.enabled = true;

            curPiece.mnPosX   = _posX;
            curPiece.mnPosY   = _posY;
            curPiece.mnHealth = _health;
            curPiece.SetMovementType(_movementType);
            curPiece.SetUnitType(_unitType);
            int spriteIndex = Array.IndexOf(enemySpriteNames, _unitType.ToString() + "_" + _movementType.ToString());
            curPiece.mSpriteRen.sprite = enemySprites[spriteIndex];

            DungeonManager.Instance.PlaceEnemy(curPiece, _posX, _posY);
            curPiece.transform.position = DungeonManager.Instance.GridPosToWorldPos(_posX, _posY);
        }

        GameManager.Instance.EnemyList.Add(curPiece);

        return(curPiece);
    }
Esempio n. 10
0
        /// <summary>
        /// Update the contents of a data grid based on its grid type and associated database
        /// connection string.
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="connectionString"></param>
        /// <param name="type"></param>
        private void updateTablesGrid(DataGridView grid, string connectionString, GridType type)
        {
            // read the excluded tables list from the App.config
            string excludedTablesConfig = ConfigurationSettings.AppSettings["ExcludedTables"];

            string[] excludedTables = null;

            if (!string.IsNullOrWhiteSpace(excludedTablesConfig))
            {
                excludedTables = excludedTablesConfig.ToLower().Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
            }

            lock (tablesLock)
            {
                // clear the grid first
                if (grid != null && grid.Rows != null)
                {
                    grid.Rows.Clear();
                }

                try
                {
                    // only operate on a valid connection string
                    if (!string.IsNullOrWhiteSpace(connectionString))
                    {
                        foreach (string[] table in transferUtils.EnumerateTables(connectionString))
                        {
                            // ignore tables specified to be excluded
                            if (excludedTables == null || !excludedTables.Contains(table[0].ToLower()))
                            {
                                if (type == GridType.Source)
                                {
                                    grid.Rows.Add(
                                        new DataGridViewCheckBoxCell()
                                    {
                                        TrueValue = true, FalseValue = false
                                    },
                                        table[0],
                                        table[1],
                                        getCustomColumnMappings(table[0]),
                                        getVirtualSelectQueryString(table[0]),
                                        ConfigurationSettings.AppSettings.AllKeys.Contains(table[0]) ?
                                        ConfigurationSettings.AppSettings[table[0]] :
                                        string.Empty
                                        );
                                }
                                else // we're operating on the destination grid
                                {
                                    // make sure the table does not already exist in the source grid
                                    if (!sourceGridContainsTable(table[0]))
                                    {
                                        string mapping = ConfigurationSettings.AppSettings["Table_Mapping_Distinct:" + table[0]] ??
                                                         ConfigurationSettings.AppSettings["Table_Mapping:" + table[0]];

                                        grid.Rows.Add(
                                            new DataGridViewCheckBoxCell()
                                        {
                                            TrueValue = true, FalseValue = false
                                        },
                                            table[0],
                                            mapping,
                                            new DataGridViewCheckBoxCell()
                                        {
                                            TrueValue = true, FalseValue = false
                                        },
                                            getVirtualSelectQueryString(table[0])
                                            );
                                    }
                                }
                            }
                        }

                        // initialize the checkboxes
                        for (int index = 0; index < grid.Rows.Count; ++index)
                        {
                            DataGridViewCheckBoxCell cell = grid.Rows[index].Cells[0] as DataGridViewCheckBoxCell;
                            if (cell != null)
                            {
                                cell.TrueValue  = true;
                                cell.FalseValue = false;
                                cell.Value      = cell.TrueValue;
                            }
                            cell = grid.Rows[index].Cells[3] as DataGridViewCheckBoxCell;
                            if (cell != null)
                            {
                                cell.TrueValue  = true;
                                cell.FalseValue = false;
                                cell.Value      = ConfigurationSettings.AppSettings.AllKeys.Contains("Table_Mapping_Distinct:" + (grid.Rows[index].Cells[1].Value as string)) ?
                                                  cell.TrueValue : cell.FalseValue;
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    // show a generic error message at first
                    DialogResult result = MessageBox.Show("Unable to connect to " + type.ToString().ToLower() + " database. Do you wish to see more information?",
                                                          "Connection Error", MessageBoxButtons.YesNo);

                    // show additional error information if the user requests it
                    if (result == System.Windows.Forms.DialogResult.Yes)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
            }
        }