Inheritance: MonoBehaviour
    /*
     * Show dragging UI when trying to build an AreaBuilding
     * @param mouse_down is mouse position when mouse pressed
     * @param mouse_up is mouse position when mouse released
     */
    public void ShowDragging(Vector3 mouse_down, Vector3 mouse_up)
    {
        // flip order of mouseUp and mouseDown if necessary so that lowest x and y are in mouseDown
        Vector3 temp;
        if (mouse_down.x > mouse_up.x) { temp.x = mouse_down.x; mouse_down.x = mouse_up.x; mouse_up.x = temp.x; }
        if (mouse_down.z > mouse_up.z) { temp.z = mouse_down.z; mouse_down.z = mouse_up.z; mouse_up.z = temp.z; }

        // get gridCell, size, and center for calcuation
        minGridCell = GridHelper.GetGridCell (mouse_down);
        maxGridCell = GridHelper.GetGridCell (mouse_up);
        size = new Vector2 (maxGridCell.gridPosition.x - minGridCell.gridPosition.x + 1,
                                    maxGridCell.gridPosition.y - minGridCell.gridPosition.y + 1);

        if (size != area_building_factory.GetSize ())
        {
            area_building_factory.SetupPositionAndSize (minGridCell.gridPosition, size);
            this.transform.position = area_building_factory.UpdateSelectionObject (minGridCell, maxGridCell, size);

            DraggingUpdateLabels (minGridCell, size);

            if (!this.gameObject.activeSelf)
                NGUITools.SetActive (this.gameObject, true);

        }
    }
Ejemplo n.º 2
0
        /// <summary>
        /// Finds an sets a vaild location for the word to be placed
        /// </summary>
        /// <param name="xRange"></param>
        /// <param name="yRange"></param>
        /// <param name="word"></param>
        /// <param name="grid"></param>
        /// <returns></returns>
        protected PlacedWord FindWordLocation(IEnumerable<int> xRange, IEnumerable<int> yRange, string word, WordSearch grid)
        {
            xRange = xRange.Shuffle();
            yRange = yRange.Shuffle();

            var placeFound=false;
            GridCell startPos = new GridCell();

            //Find a Valid location
            foreach (var currentX in xRange) {
                foreach (var currentY in yRange)
                {
                    placeFound = this.TryPlaceWordLetters(word, new GridCell(currentX, currentY), grid);
                    if (placeFound)
                    {
                        startPos = new GridCell(currentX,currentY);
                        break;
                    }
                }
                if(placeFound) break;
            }

            //Set Word
            if(placeFound)
            {
                for (var i = 0; i < word.Length; i++)
                {
                    this.SetCellValue(startPos, i, grid, word[i]);
                }
                return new PlacedWord(word, this.GetDisplayDirection(), startPos);
            }else{
                return null;
            }
        }
    public Vector2 GetStraightOneDirection(Vector3 mouse_down, Vector3 mouse_up)
    {
        Vector2 returnVector = Vector2.zero;
         		GridCell mouseDownCell = GridHelper.GetGridCell(mouse_down);
        GridCell mouseUpCell = GridHelper.GetGridCell(mouse_up);

        Vector3 temp;
        if (mouse_down.x > mouse_up.x) { temp.x = mouse_down.x; mouse_down.x = mouse_up.x; mouse_up.x = temp.x; }
        if (mouse_down.z > mouse_up.z) { temp.z = mouse_down.z; mouse_down.z = mouse_up.z; mouse_up.z = temp.z; }

        minGridCell = GridHelper.GetGridCell (mouse_down);
        maxGridCell = GridHelper.GetGridCell (mouse_up);

        if (maxGridCell.gridPosition.x - minGridCell.gridPosition.x >= maxGridCell.gridPosition.y - minGridCell.gridPosition.y) {
            // horizontal
            if (mouseDownCell.gridPosition.x < mouseUpCell.gridPosition.x)
                returnVector = new Vector2(1,0);
            else
                returnVector = new Vector2(-1,0);
        } else {
            // vertical
            if (mouseDownCell.gridPosition.y < mouseUpCell.gridPosition.y)
                returnVector = new Vector2(0,1);
            else
                returnVector = new Vector2(0,-1);
        }

        //print ("direction vector = " + returnVector);
         		return returnVector;
    }
Ejemplo n.º 4
0
        public GVDKarla(ObstacleGrid grid)
        {
            this.grid = grid;

            open = new IntervalHeap<GridCellValue>();
            ties = new LinkedList<GridCell>();
            dist = new float[grid.NumColumns, grid.NumRows];
            distNew = new float[grid.NumColumns, grid.NumRows];
            parent = new GridCell[grid.NumColumns, grid.NumRows];
            tie = new GridCell[grid.NumColumns, grid.NumRows];
            obst = new int[grid.NumColumns, grid.NumRows];
            valid = new HashSet<int>();
            voro = new bool[grid.NumColumns, grid.NumRows];

            for (int c = grid.NumColumns - 1; c >= 0; c--)
                for (int r = grid.NumRows - 1; r >= 0; r--)
                {
                    dist[c, r] = float.PositiveInfinity;
                    distNew[c, r] = float.PositiveInfinity;
                    parent[c, r] = GridCell.Unknown;
                    tie[c, r] = GridCell.Unknown;
                    obst[c, r] = -1;
                    voro[c, r] = false;
                }
        }
Ejemplo n.º 5
0
        public void AsDynamicXml_WhenGivenValidGridCell_ShouldReturnDynamicXml()
        {
            var c = new GridCell() { Alias = "test", DataType = -88, Name = "Test", Value = "1234" };
            var x = c.AsDynamicXml();

            Assert.IsInstanceOfType(x, typeof(DynamicXml));
        }
Ejemplo n.º 6
0
 public Dictionary<float, List<GridCell>> GetAffections(GridCell center, int range)
 {
     var aff = new Dictionary<float, List<GridCell>> ();
     aff.Add (1f, new List<GridCell>(new GridCell[]{center}));
     if (range <= 1)
         return aff;
     for (int r = 1; r < range; r++) {
         var p = 1f - ((float)r / range);
         var clist = new List<GridCell>();
         var cu = GetCell(center.Position + new Vector2(0, r));
         var cur = GetCell(center.Position + new Vector2(r, r));
         var cr = GetCell(center.Position + new Vector2(r, 0));
         var cdr = GetCell(center.Position + new Vector2(r, -r));
         var cd = GetCell(center.Position + new Vector2(0, -r));
         var cld = GetCell(center.Position + new Vector2(-r, -r));
         var cl = GetCell(center.Position + new Vector2(-r, 0));
         var clu = GetCell(center.Position + new Vector2(-r, r));
         if(cu) clist.Add(cu);
         if(cur) clist.Add(cur);
         if(cr) clist.Add(cr);
         if(cdr) clist.Add(cdr);
         if(cd) clist.Add(cd);
         if(cld) clist.Add(cld);
         if(cl) clist.Add(cl);
         if(clu) clist.Add(clu);
         aff.Add (p, clist);
     }
     return aff;
 }
Ejemplo n.º 7
0
        public void ToString_WhenGivenValidGridCell_ShouldReturnValue()
        {
            var c = new GridCell() { Value = "1234" };
            var x = c.ToString();

            Assert.AreEqual(x, c.Value);
        }
Ejemplo n.º 8
0
 void Update()
 {
     if (mMaxSecurity == -1)
         mMaxSecurity = MapGrid.MaximumSecurity ();
     var pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
     pos.z = Camera.main.transform.position.z;
     var dir = new Vector3 (0, 0, 1);
     var hit = Physics2D.Raycast (pos, dir, 100f, CellLayer);
     if (hit) {
         var cell = hit.transform.GetComponent<GridCell>();
         if(cell && mHighlightedCell != cell) {
             transform.position = Camera.main.WorldToScreenPoint(cell.transform.position);
             var pMin = Camera.main.WorldToScreenPoint(cell.GetComponent<BoxCollider2D>().bounds.min);
             var pMax = Camera.main.WorldToScreenPoint(cell.GetComponent<BoxCollider2D>().bounds.max);
             var sizeW = pMax.x - pMin.x;
             var sizeH = pMax.y - pMin.y;
             ColorTarget.sizeDelta = new Vector2(sizeW, sizeH);
             ColorTarget.GetComponent<Image>().color = Color.Lerp(LowRiskColor, HighRiskColor, (float)cell.Security / mMaxSecurity);
             Population.text = FormatPopulation(cell.Population);
             Security.text = cell.Security.ToString();
             mHighlightedCell = cell;
         }
         else if(!cell) {
             mHighlightedCell = null;
         }
     }
 }
    public GridCell[] GetNeighbours()
    {
        GridCell[] returnList = new GridCell[8];
        int index = 0;

        for (int x = (int)gridCell.gridPosition.x - 1; x <= gridCell.gridPosition.x + 1; x++)
        {
            for (int y = (int)gridCell.gridPosition.y - 1; y <= gridCell.gridPosition.y + 1; y++)
            {
                if (x == gridCell.gridPosition.x && y == gridCell.gridPosition.y) { } // this cell, SKIP
                else if (IsWalkable())
                {
                    returnList[index] = GridHelper.GetGridCell(x, y);

                    /*
                    if (returnList[index] == null) // if it's null, leave index the same
                        index--;

                    index++;*/

                    if (returnList[index] != null) // if it's null, leave index the same
                        index++;

                }
                else
                {
                    //Debug.Log("not adding anything here!!!");
                }
            }
        }

        return returnList;
    }
Ejemplo n.º 10
0
	public Bomb GetBombInCell(GridCell cell) {
		foreach (var bomb in GetBombs()) {
			if(bomb.Target == cell && (bomb.CurrentStatus == Bomb.Status.Deployed || bomb.CurrentStatus == Bomb.Status.Ready))
				return bomb;
		}
		return null;
	}
Ejemplo n.º 11
0
 void ExlposionApplied(GridCell cell, Bomb bomb, float fatality)
 {
     int f = (int)fatality;
     Text.text = "-" + f;
     transform.position = Camera.main.WorldToScreenPoint(cell.transform.position);
     mAnimator.SetTrigger ("Indicate");
 }
Ejemplo n.º 12
0
 public AgentSprite(CatAndMouseGame game, Texture2D texture, Vector2 position, UserSprite target, GridCell[,] gridCell, Graph graph)
     : base(game, texture, position)
 {
     this.target = target;
     this.gridCell = gridCell;
     this.graph = graph;
 }
Ejemplo n.º 13
0
        public UniformGridBroadphase(int width, int height, int cellSize) : this()
        {
            Width = width;
            Height = height;
            CellSize = cellSize;
            CellsHigh = Height / cellSize;
            CellsWide = Width / cellSize;
            TotalCells = CellsHigh * CellsWide;
            Offset = new Point(width / 2, height / 2);

            _invCellSize = 1f / (float)cellSize;
            _pairs = new OverlappingPairCache();
            _cells = new GridCell[TotalCells];

            for (int i = 0; i < _cells.Length; i++)
                _cells[i] = new GridCell();

            neighbourOffset = new int[] 
            {
                -CellsWide - 1, // top-left
                -CellsWide,     // top
                -CellsWide + 1, // top-right
                -1,             // left
                0,
                1,              // right
                CellsWide - 1,  // bottom-left
                CellsWide,      // bottom
                CellsWide + 1,  // bottom-right
            };
        }
Ejemplo n.º 14
0
        public Graph(CatAndMouseGame game, GridCell[,] grid)
        {
            this.game = game;
            this.grid = grid;
            rows = grid.GetLength(0);
            columns = grid.GetLength(1);
            adjacencyList = new Node[rows * columns];

            for (int i = 0; i < rows; ++i)
            {
                for (int j = 0; j < columns; ++j)
                {
                    grid[i, j] = new GridCell(game, new Vector2(i * 32, j * 32));

                    List<Node> adjacentNodes = new List<Node>();
                    // Check NSEW
                    if (j - 1 >= 0) adjacentNodes.Add(new Node(i, j - 1));
                    if (j + 1 < columns) adjacentNodes.Add(new Node(i, j + 1));
                    if (i - 1 >= 0) adjacentNodes.Add(new Node(i - 1, j));
                    if (i + 1 < rows) adjacentNodes.Add(new Node(i + 1, j));

                    List<Node> cornerNodes = new List<Node>();
                    // Check all
                    if (i - 1 >= 0 && j - 1 >= 0) cornerNodes.Add(new Node(i - 1, j - 1));
                    if (i - 1 >= 0 && j + 1 < columns) cornerNodes.Add(new Node(i - 1, j + 1));
                    if (i + 1 < rows && j - 1 >= 0) cornerNodes.Add(new Node(i + 1, j - 1));
                    if (i + 1 < rows && j + 1 < columns) cornerNodes.Add(new Node(i + 1, j + 1));

                    adjacencyList[columns * i + j] = new Node(i, j);
                    allNodes.Add(adjacencyList[columns * i + j]);
                    adjacencyList[columns * i + j].AdjacentNodes = adjacentNodes;
                    adjacencyList[columns * i + j].CornerNodes = cornerNodes;
                }
            }
        }
Ejemplo n.º 15
0
        public void GetPropertyValue_WhenGivenValidGridCell_ShouldReturnPropertyValue()
        {
            var c = new GridCell() { Alias = "test", DataType = -41, Name = "Test", Value = "01/04/2013 00:00:00" };
            var x = c.GetPropertyValue();

            Assert.IsInstanceOfType(x, typeof(DateTime));
        }
Ejemplo n.º 16
0
        public void AsDynamicXml_WhenGivenUnescapedValue_ShouldReturnEscapedXml()
        {
            var v = "<XPathAutoComplete Type=\"c66ba18e-eaf3-4cff-8a22-41b16d66a972\"><Item Text=\"ABC\" Value=\"1\" /><Item Text=\"XYZ\" Value=\"9\" /></XPathAutoComplete>";
            var c = new GridCell() { Alias = "test", DataType = -88, Name = "Test", Value = v };

            var xml = c.AsDynamicXml();

            Assert.AreEqual(xml.InnerText, c.Value);
        }
Ejemplo n.º 17
0
	public void Deploy(GridCell target) {
		if (CurrentStatus != Status.Stored)
			return;
		mDeployStartTime = Time.time;
		mDeployDuration = GetDeployDuration(target);
		mTarget = target;
		mRenderer.enabled = true;
		CurrentStatus = Status.Deployed;
	}
Ejemplo n.º 18
0
        public void SetObstacle(GridCell cell, int obstacleId)
        {
            distNew[cell.C, cell.R] = 0f;
            obst[cell.C, cell.R] = obstacleId;
            parent[cell.C, cell.R] = cell;
            valid.Add(obstacleId);

            open.Add(new GridCellValue(cell, 0f));
        }
Ejemplo n.º 19
0
        private Type GetEditType(GridCell cell)
        {
            if (cell.EditorType != null)
                return (cell.EditorType);

            if (cell.GridColumn != null)
                return (cell.GridColumn.EditorType);

            return (null);
        }
Ejemplo n.º 20
0
	    private EEval(GridCell cell, string source, List<GridCell> usedCells)
        {
            _Cell = cell;
            _UsedCells = usedCells;

            if (_Cell != null)
                _GridPanel = cell.GridPanel;

            Source = source;
        }
Ejemplo n.º 21
0
 /// <summary>
 /// Tests if a word can be placed at a givern location
 /// </summary>
 /// <param name="wordLetters"></param>
 /// <param name="startX"></param>
 /// <param name="startY"></param>
 /// <param name="grid"></param>
 /// <returns></returns>
 protected bool TryPlaceWordLetters(string wordLetters, GridCell start, WordSearch grid)
 {
     for (var i = 0; i < wordLetters.Length; i++)
     {
         var cell = this.GetCellValue(start, i, grid);
         if (cell != NullChar && cell != wordLetters[i])
             return false;
     }
     return true;
 }
Ejemplo n.º 22
0
 public void BuildMap()
 {
     _mapGO = new GameObject("Map");
     foreach (var node in _grid.Nodes)
     {
         var cell = new GridCell(node);
         Cells.Add(cell);
         cell.GO.transform.SetParent(_mapGO.transform);
         cell.State = GridCell.EnumCellState.Blocked;
     }
 }
Ejemplo n.º 23
0
	// Use this for initialization
	public void InitialiseBoard()
	{
		boardConfig = BoardConfig.Instance;
		Grid = new GridCell[boardConfig.Width * boardConfig.Height];
		for (int index = 0; index < boardConfig.Width * boardConfig.Height; index++)
		{
			var pos = new Vector3(boardConfig.GetPosXFromIndex(index), boardConfig.GetPosYFromIndex(index), 0f);
			var cell = new GridCell(boardConfig.GetGridXFromIndex(index), boardConfig.GetGridYFromIndex(index), index, pos);
			Grid[index] = cell;
		}
	}
Ejemplo n.º 24
0
        public Grid(int width, int height)
        {
            grid = new GridCell[width, height];

            for (int w = 0; w < grid.GetLength(0); w++)
            {
                for (int h = 0; h < grid.GetLength(1); h++)
                {
                    grid[w, h] = new GridCell(w, h);
                }
            }
        }
Ejemplo n.º 25
0
        public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
        {
            if (context != null)
            {
                _Cell = context.Instance as GridCell;

                if (_Cell != null)
                    _HasBoolDropDown = CellHasBoolDropDown(_Cell);
            }

            return (UITypeEditorEditStyle.DropDown);
        }
Ejemplo n.º 26
0
 public GridCell(Vector3 position)
 {
     var go = Skin.GetPrefab(Skin.GamePrefabs.Cell);
     GO = Instantiate(go, position, go.transform.rotation) as GameObject;
     State = EnumCellState.Walkable;
     OriginalColor = GO.GetComponent<SpriteRenderer>().color;
     _script = GO.AddComponent<GridCell>();
     _script.GO = GO;
     _script.OriginalColor = OriginalColor;
     _script.State = State;
     OriginalState = State;
 }
Ejemplo n.º 27
0
    public CellGrid(GridCell[,] grid, Transform transform, float mazeRes)
    {
        this.grid = grid;

        offset = transform.position;

        scale = new Vector3(transform.lossyScale.x,
                            transform.lossyScale.z, 1);

        invScale = new Vector3(1.0f / scale.x,
                                       1.0f / scale.y, 1);
    }
Ejemplo n.º 28
0
    public void findPath(GridCell startCell, GridCell goalCell, GridCell[,,] grid)
    {
        this.grid = grid;
        gridWidth = grid.GetLength(0);
        gridHeight = grid.GetLength(1);
        gridDepth = grid.GetLength(2);

        start = new Node(startCell.getCell()[0], startCell.getCell()[1], startCell.getCell()[2], 0, 0, 0, null, startCell);
        end = new Node(goalCell.getCell()[0], goalCell.getCell()[1], goalCell.getCell()[2], 0, 0, 0, null, goalCell);

        openList.Add(start);
        bool keepSearching = true;
        bool pathExists = true;

        while (keepSearching && pathExists) {
            Node curNode = getBestFromOpenList();
            if (curNode == null) {
                pathExists = false;
                break;
            }
            closeList.Add(curNode);

            if (nodeIsGoal(curNode)) {
                keepSearching = false;
            } else {
                findValidNeighbors(curNode);

                foreach (Node n in neighbors) {
                    if (findInCloseList(n) != null) {
                        continue;
                    }
                    Node inOpenList = findInOpenList(n);
                    if (inOpenList == null) {
                        openList.Add(n);
                    } else {
                        if (n.G < inOpenList.G) {
                            inOpenList.G = n.G;
                            inOpenList.F = inOpenList.G + inOpenList.H;
                            inOpenList.parent = curNode;
                        }
                    }
                }
            }
        }
        if (pathExists) {
            Node n = findInCloseList(end);
            while (n != null) {
                finalPath.Add(n);
                n = n.parent;
            }
        }
    }
Ejemplo n.º 29
0
        private bool CellHasBoolDropDown(GridCell cell)
        {
            Type editType = GetEditType(cell);

            if (editType == typeof(GridCheckBoxEditControl) ||
                editType == typeof(GridCheckBoxXEditControl) ||
                editType == typeof(GridSwitchButtonEditControl))
            {
                return (true);
            }

            return (false);
        }
Ejemplo n.º 30
0
 private void CellSelected(GridCell oldCell, GridCell newCell)
 {
     if (!newCell) {
         Close ();
         return;
     }
     Name.text = newCell.ToString ();
     Population.text = newCell.Population.ToString ();
     Security.text = newCell.Security.ToString ();
     Value.text = newCell.GetValuePerPerson ().ToString ();
     transform.position = Camera.main.WorldToScreenPoint (newCell.transform.position);
     mCanvasGroup.alpha = 1f;
     mCanvasGroup.interactable = true;
     mCanvasGroup.blocksRaycasts = true;
 }
Ejemplo n.º 31
0
        private void superGridPanel_CellValueChanged(object sender, GridCellValueChangedEventArgs e)
        {
            GridCell cell = e.GridCell;

            if (cell.GridColumn.Name.Equals("製程序") == true && !IS_PROGRAM)
            {
                IS_PROGRAM = true;

                GridRow row = cell.GridRow;

                for (int i = 0; i < panel.Rows.Count; i++)
                {
                    if (i == row.Index)
                    {
                        continue;
                    }
                    bool check = (bool)panel.GridPanel.GetCell(i, 0).Value;
                    if (check)
                    {
                        panel.GridPanel.GetCell(i, 0).Value = (bool)false;
                    }
                }

                bool cur_check = (bool)panel.GridPanel.GetCell(row.Index, 0).Value;
                if (!cur_check)
                {
                    panel.GridPanel.GetCell(row.Index, 0).Value = (bool)false;
                }
                else
                {
                    panel.GridPanel.GetCell(row.Index, 0).Value = (bool)true;
                }
                //CaxLog.ShowListingWindow(row.Index.ToString());

                IS_PROGRAM = false;
            }

            //清空所有checkBox&labelBox
            ClearAllCheck();

            //判斷選取到的製程序對應開啟的groupBox
            bool check_sel = (bool)panel.GridPanel.GetCell(cell.GridRow.Index, 0).Value;

            if (check_sel)
            {
                SelePartName = panel.GridPanel.GetCell(cell.GridRow.Index, 1).Value.ToString();
                string[] SplitSelePartName       = SelePartName.Split(new string[] { "OP" }, StringSplitOptions.RemoveEmptyEntries);
                string   DoubleSplitSelePartName = (SplitSelePartName[1].Split(new string[] { "_CAM" }, StringSplitOptions.RemoveEmptyEntries))[0];
                if (DoubleSplitSelePartName == "001")
                {
                    groupBox001.Enabled = true;
                    groupBox900.Enabled = false;
                    groupBoxW.Enabled   = false;
                }
                else if (DoubleSplitSelePartName == "900")
                {
                    groupBox900.Enabled = true;
                    groupBox001.Enabled = false;
                    groupBoxW.Enabled   = false;
                }
                else
                {
                    groupBoxW.Enabled   = true;
                    groupBox001.Enabled = false;
                    groupBox900.Enabled = false;
                }
                SeleOperValue = DoubleSplitSelePartName;
            }
        }
Ejemplo n.º 32
0
 void removeBallFromGrid(GridCell cell)
 {
     _gridManager.RemoveBallFromGridCell(cell);
 }
Ejemplo n.º 33
0
        public void ValidateInnerHtmlIs_When_GetCell()
        {
            GridCell cell = _testGrid.GetCell(0, 1);

            cell.ValidateInnerHtmlIs("<b>John</b>");
        }
Ejemplo n.º 34
0
        public void should_get_empty_neighbors()
        {
            var gridCell = new GridCell(2, 3);

            Assert.Empty(gridCell.Neighbors);
        }
Ejemplo n.º 35
0
    public GridCell FindNearestGridCell(GridCell cellClue, Vector3 position)
    {
        List <GridCell> listNeighbors = GetNeighborCells(cellClue.X, cellClue.Y);

        return(findNearestGridCellInList(listNeighbors, position));
    }
Ejemplo n.º 36
0
    public void RotateRight()
    {
        BoatComponent[] boats = m_lastActiveObject.GetComponentsInChildren <BoatComponent>();

        if (boats[0].m_bOnGrid)
        {
            if (m_lastActiveCells.Count == 0)
            {
                //Loop through the boats
                foreach (BoatComponent b in boats)
                {
                    //Get every cell the boat is touching
                    GridCell bCell = GridCellManager.instance.GetGridCellByPosition(b.transform.position);
                    //Add it to the last active cell list
                    m_lastActiveCells.Add(bCell);
                    bCell.m_bIsFree     = false;
                    bCell.m_blockingObj = b.transform.parent.gameObject;
                }
            }

            m_lastActiveObject.transform.Rotate(Vector3.up, -90);

            //Get all the boat components within the active object

            GridCell cell = GridCellManager.instance.GetGridCellByPosition(m_lastActiveObject.transform.position);

            bool allCellsFree = CheckIfFree(boats);

            if (allCellsFree)
            {
                //Make sure they're set as now on the grid
                foreach (BoatComponent b in boats)
                {
                    b.m_bOnGrid = true;
                }

                //Set the old cells to be free
                foreach (GridCell c in m_lastActiveCells)
                {
                    c.m_bIsFree     = true;
                    c.m_blockingObj = null;
                }

                //Clear the last active cells list
                m_lastActiveCells.Clear();

                //Loop through the boats
                foreach (BoatComponent b in boats)
                {
                    //Get every cell the boat is touching
                    GridCell bCell = GridCellManager.instance.GetGridCellByPosition(b.transform.position);
                    bCell.m_bIsFree     = false;
                    bCell.m_blockingObj = b.transform.parent.gameObject;
                }
            }
            else
            {
                m_lastActiveObject.transform.Rotate(Vector3.up, 90);
            }
        }
    }
Ejemplo n.º 37
0
    public static void GridTokenClicked(GridToken token)
    {
        GridCell cell = GetCellFromToken[token];

        cell.OnMouseClicked();
    }
Ejemplo n.º 38
0
    void HandleTouchMoved(Touch touch)
    {
        if (m_activeDragObject != null)
        {
            //Get current cell finger is on
            GridCell cell = GetCellFromRay(touch, m_cellLayer);

            //Store the last position
            Vector3 lastPos;

            //If this is a valid cell
            if (cell != null)
            {
                //Store last position
                lastPos = m_activeDragObject.transform.position;

                //Move boat to new position
                m_activeDragObject.transform.position = cell.transform.position;

                BoatComponent[] boats = m_activeDragObject.GetComponentsInChildren <BoatComponent>();

                bool allCellsFree = CheckIfFree(boats);

                //If all the cells are free
                if (allCellsFree)
                {
                    //Set the new position of the object
                    m_activeDragObject.transform.position = cell.transform.position;

                    //Make sure they're set as now on the grid
                    foreach (BoatComponent b in boats)
                    {
                        b.m_bOnGrid = true;
                    }

                    if (m_lastActiveCells.Count > 0)
                    {
                        if (m_lastActiveCells[0] != null)
                        {
                            //If we have moved onto a new grid cell
                            if (cell.gameObject != m_lastActiveCells[0].gameObject)
                            {
                                //Set the old cells to be free
                                foreach (GridCell c in m_lastActiveCells)
                                {
                                    c.m_bIsFree     = true;
                                    c.m_blockingObj = null;
                                }
                            }
                        }
                    }

                    //Clear the last active cells list
                    m_lastActiveCells.Clear();
                    m_lastActiveCells.Capacity = 0;

                    //Loop through the boats
                    foreach (BoatComponent b in boats)
                    {
                        //Get every cell the boat is touching
                        GridCell bCell = GridCellManager.instance.GetGridCellByPosition(b.transform.position);
                        //Add it to the last active cell list
                        m_lastActiveCells.Add(bCell);
                        bCell.m_bIsFree     = false;
                        bCell.m_blockingObj = b.transform.parent.gameObject;
                    }
                }
                //If the cells aren't free then move back to original position
                else
                {
                    m_activeDragObject.transform.position = lastPos;
                }
            }

            //Move boat object when not attached to the grid
            else
            {
                foreach (GridCell lastCell in m_lastActiveCells)
                {
                    lastCell.m_bIsFree     = true;
                    lastCell.m_blockingObj = null;
                }

                //GridCellManager.instance.SetGridCell(m_lastActiveCell);

                Ray        ray = Camera.main.ScreenPointToRay(touch.position);
                RaycastHit hit;

                if (Physics.Raycast(ray, out hit, Mathf.Infinity))
                {
                    if (hit.transform.tag == "GroundingPlane")
                    {
                        BoatComponent[] boats = m_activeDragObject.GetComponentsInChildren <BoatComponent>();
                        foreach (BoatComponent b in boats)
                        {
                            b.m_bOnGrid = false;
                        }
                        m_activeDragObject.transform.position = hit.point;
                    }
                }
            }
        }
    }
Ejemplo n.º 39
0
    void HandleTouchEnded(Touch touch)
    {
        if (m_activeDragObject != null)
        {
            //Get current cell finger is on
            GridCell cell = GetCellFromRay(touch, m_cellLayer);

            //Store the last position
            Vector3 lastPos;

            BoatComponent[] boats = m_activeDragObject.GetComponentsInChildren <BoatComponent>();

            //If this is a valid cell
            if (cell != null)
            {
                //Store last position
                lastPos = m_activeDragObject.transform.position;

                //Move boat to new position
                m_activeDragObject.transform.position = cell.transform.position;

                bool allCellsFree = CheckIfFree(boats);

                //If all the cells are free
                if (allCellsFree)
                {
                    //Set the new position of the object
                    m_activeDragObject.transform.position = cell.transform.position;

                    //Make sure they're set as now on the grid
                    foreach (BoatComponent b in boats)
                    {
                        b.m_bOnGrid = true;
                    }

                    if (m_lastActiveCells.Count > 0)
                    {
                        if (m_lastActiveCells[0] != null)
                        {
                            //If we have moved onto a new grid cell
                            if (cell.gameObject != m_lastActiveCells[0].gameObject)
                            {
                                //Set the old cells to be free
                                foreach (GridCell c in m_lastActiveCells)
                                {
                                    c.m_bIsFree     = true;
                                    c.m_blockingObj = null;
                                }
                            }
                        }
                    }

                    //Clear the last active cells list
                    m_lastActiveCells.Clear();
                    m_lastActiveCells.Capacity = 0;

                    //Loop through the boats
                    foreach (BoatComponent b in boats)
                    {
                        //Get every cell the boat is touching
                        GridCell bCell = GridCellManager.instance.GetGridCellByPosition(b.transform.position);
                        //Add it to the last active cell list
                        m_lastActiveCells.Add(bCell);
                        bCell.m_bIsFree     = false;
                        bCell.m_blockingObj = b.transform.parent.gameObject;
                    }
                }
                //If the cells aren't free then move back to original position
                else
                {
                    m_activeDragObject.transform.position = lastPos;
                }
            }
            //If we haven't finished the touch on the grid
            else
            {
                Vector3 originalPos = m_activeDragObject.transform.GetChild(0).GetComponent <BoatComponent>().m_originalPosition;
                m_activeDragObject.transform.localPosition = originalPos;
                //Quaternion originalRot = m_activeDragObject.transform.GetChild(0).GetComponent<BoatComponent>().m_originalRotation;

                //m_activeDragObject.transform.rotation = originalRot;

                m_lastActiveObject.transform.Find("RotateButtonCanvas").gameObject.SetActive(false);
                m_lastActiveObject = null;
            }

            foreach (BoatComponent b in boats)
            {
                GridCell bCell = GridCellManager.instance.GetGridCellByPosition(b.transform.position);
                bCell.m_bIsFree     = false;
                bCell.m_blockingObj = b.transform.parent.gameObject;
            }

            m_lastActiveCells.Clear();

            //if (m_activeDragObject.GetComponentInChildren<BoatComponent>().m_bOnGrid == false)
            //{
            //    Destroy(m_activeDragObject);
            //}
        }

        m_activeDragObject = null;
    }
Ejemplo n.º 40
0
 /// <summary>
 /// 单元格点击事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="cell"></param>
 /// <param name="e"></param>
 private void floatDiv_CellClick(object sender, GridCell cell, MouseEventArgs e)
 {
     MessageBox.Show(cell.GetString());
 }
Ejemplo n.º 41
0
        //constructors are good!
        public ReversiGraph()
        {
            Cells = new Dictionary <string, GridCell>();
            dirty = true;

            //create a temporary array for the individual cells, for use only while constructing the graph
            GridCell[][] cellArr = new GridCell[8][];

            //loop through to create the 64 cells necessary (8x8).
            for (int i = 0; i < 8; ++i)
            {
                int row = i + 1;
                cellArr[i] = new GridCell[8];
                for (int j = 0; j < 8; ++j)
                {
                    char   letter = (char)(j + 65);
                    string name   = "_" + letter + row;
                    cellArr[i][j]            = new GridCell(name);
                    cellArr[i][j].SpawnPoint = new Vector3(-3.5f + (j * 1f), 1f, 3.5f - (i * 1f));
                    Cells.Add(name, cellArr[i][j]);
                }
            }

            //initialize states and models of starting positions
            cellArr[3][3].State = ReversiGraph.CellState.BLACK;
            cellArr[3][3].Model = GameObject.Find("Piece_D4");

            cellArr[4][4].State = ReversiGraph.CellState.BLACK;
            cellArr[4][4].Model = GameObject.Find("Piece_E5");

            cellArr[3][4].State = ReversiGraph.CellState.WHITE;
            cellArr[3][4].Model = GameObject.Find("Piece_E4");

            cellArr[4][3].State = ReversiGraph.CellState.WHITE;
            cellArr[4][3].Model = GameObject.Find("Piece_D5");

            /**
             * set up edges. Each GridCell actually uses a static map of Direction->string which will give us the ability to
             * quickly clone the board for recursive negamaxing without having to duplicate every edge. We simply shallow copy
             * the edge list, and use each graph's own string->GridCell map to look up the correct GridCell instance as we traverse.
             */
            for (int i = 0; i < 8; ++i)
            {
                for (int j = 0; j < 8; ++j)
                {
                    GridCell current = cellArr[i][j];

                    //NW, N, NE
                    if (i > 0)
                    {
                        //NW
                        if (j > 0)
                        {
                            current.Edges.Add(Direction.NW, cellArr[i - 1][j - 1].Name);
                        }

                        //N
                        current.Edges.Add(Direction.N, cellArr[i - 1][j].Name);

                        //NE
                        if (j < 7)
                        {
                            current.Edges.Add(Direction.NE, cellArr[i - 1][j + 1].Name);
                        }
                    }

                    //W
                    if (j > 0)
                    {
                        current.Edges.Add(Direction.W, cellArr[i][j - 1].Name);
                    }

                    //E
                    if (j < 7)
                    {
                        current.Edges.Add(Direction.E, cellArr[i][j + 1].Name);
                    }


                    //SW, S, SE
                    if (i < 7)
                    {
                        //SW
                        if (j > 0)
                        {
                            current.Edges.Add(Direction.SW, cellArr[i + 1][j - 1].Name);
                        }

                        //S
                        current.Edges.Add(Direction.S, cellArr[i + 1][j].Name);

                        //SE
                        if (j < 7)
                        {
                            current.Edges.Add(Direction.SE, cellArr[i + 1][j + 1].Name);
                        }
                    }
                }
            }
        }
Ejemplo n.º 42
0
        public void GridCellIsEmptyPropertyTest(char?constructorValue, bool expectedIsEmpty)
        {
            var cell = new GridCell(constructorValue);

            cell.IsEmpty.Should().Be(expectedIsEmpty);
        }
Ejemplo n.º 43
0
    private void ApplyRules()
    {
        int[,] NextGenGrid                  = new int[gridHeight, _gridWidth];
        Enviroments[,] nextCellColor        = new Enviroments[gridHeight, _gridWidth];
        Enviroments[,] nextEnviornmentColor = new Enviroments[gridHeight, _gridWidth];

        for (int i = 0; i < gridHeight; i++)
        {
            for (int j = 0; j < _gridWidth; j++)
            {
                int livingNeighbours = 0;

                GridCell        currentCell        = _gridCellsArray[i, j];
                Enviroments     auxCellEnviornment = currentCell.cellEnviornment;
                List <GridCell> cells = new List <GridCell>();

                if (currentCell.backgroundEnvionment == Enviroments.DeadZone)
                {
                    continue;
                }

                if (currentCell.isCellDevelopingSlowly)
                {
                    currentCell.SetIfCellDevelopingSlowly(true);
                    continue;
                }

                cells = CountLivingNeighbours(i, j);
                int livingNeighboursRed    = 0;
                int livingNeighboursGrey   = 0;
                int livingNeighboursYellow = 0;
                int livingNeighboursBlue   = 0;

                foreach (GridCell cell in cells)
                {
                    if (cell.isCellActive == 1)
                    {
                        switch (cell.cellEnviornment)
                        {
                        case Enviroments.TargarienRed:
                            livingNeighboursRed++;
                            break;

                        case Enviroments.StarkGrey:
                            livingNeighboursGrey++;
                            break;

                        case Enviroments.LannisterYellow:
                            livingNeighboursYellow++;
                            break;

                        case Enviroments.FreePeopleBlue:
                            livingNeighboursBlue++;
                            break;

                        case Enviroments.None:
                            break;
                        }
                    }
                }

                if (livingNeighboursRed > livingNeighboursGrey &&
                    livingNeighboursRed > livingNeighboursYellow &&
                    livingNeighboursRed > livingNeighboursBlue)
                {
                    livingNeighbours   = livingNeighboursRed;
                    auxCellEnviornment = Enviroments.TargarienRed;
                }
                else if (livingNeighboursGrey > livingNeighboursRed &&
                         livingNeighboursGrey > livingNeighboursYellow &&
                         livingNeighboursGrey > livingNeighboursBlue)
                {
                    livingNeighbours   = livingNeighboursGrey;
                    auxCellEnviornment = Enviroments.StarkGrey;
                }
                else if (livingNeighboursYellow > livingNeighboursRed &&
                         livingNeighboursYellow > livingNeighboursGrey &&
                         livingNeighboursYellow > livingNeighboursBlue)
                {
                    livingNeighbours   = livingNeighboursYellow;
                    auxCellEnviornment = Enviroments.LannisterYellow;
                }
                else if (livingNeighboursBlue > livingNeighboursRed &&
                         livingNeighboursBlue > livingNeighboursGrey &&
                         livingNeighboursBlue > livingNeighboursYellow)
                {
                    livingNeighbours   = livingNeighboursBlue;
                    auxCellEnviornment = Enviroments.FreePeopleBlue;
                }

                if (livingNeighbours == 4)
                {
                    nextEnviornmentColor[i, j] = auxCellEnviornment;
                }
                else
                {
                    nextEnviornmentColor[i, j] = currentCell.backgroundEnvionment;
                }

                if (livingNeighbours == 3)
                {
                    NextGenGrid[i, j]   = 1;
                    nextCellColor[i, j] = auxCellEnviornment;
                }
                else if (livingNeighbours == 2)
                {
                    NextGenGrid[i, j]   = 1;
                    nextCellColor[i, j] = Enviroments.None;
                }
                else if (livingNeighbours == 1)
                {
                    NextGenGrid[i, j]   = 0;
                    nextCellColor[i, j] = Enviroments.None;
                }
                else
                {
                    nextCellColor[i, j] = currentCell.cellEnviornment;
                }
            }
        }

        for (int i = 0; i < gridHeight; i++)
        {
            for (int j = 0; j < _gridWidth; j++)
            {
                GridCell cell = _gridCellsArray[i, j];
                if (cell.backgroundEnvionment == Enviroments.DeadZone)
                {
                    continue;
                }
                if (cell.GetIfCellEnviornmentEqualsWithBack())
                {
                    cell.SetIfCellDevelopingSlowly(false);
                    continue;
                }
                cell.SpawnCell(nextCellColor[i, j],
                               nextEnviornmentColor[i, j], NextGenGrid[i, j]);
            }
        }
    }
Ejemplo n.º 44
0
    void TryGetActiveObject(Touch touch)
    {
        Ray        ray = Camera.main.ScreenPointToRay(touch.position);
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, Mathf.Infinity))
        {
            //If the raycast has hit a boat
            if (hit.transform.tag == "Boat")
            {
                BoatComponent[] boats = hit.transform.parent.GetComponentsInChildren <BoatComponent>();
                //If the boat is already on the grid
                if (boats[0].m_bOnGrid)
                {
                    //Get the parent of the boat component
                    m_activeDragObject = hit.transform.parent.gameObject;

                    //Loop through each boat component
                    foreach (BoatComponent boat in boats)
                    {
                        //Get the grid cell the boat is on
                        GridCell bCell = GridCellManager.instance.GetGridCellByPosition(boat.transform.position);
                        //If this is a valid cell (i.e on the grid)
                        if (bCell != null)
                        {
                            //Add the cell to the last active cell list
                            m_lastActiveCells.Add(bCell);
                        }
                    }
                }
                //If the boat isn't already on the grid
                else
                {
                    //Instantiate a copy of the "boat spawner"
                    //m_activeDragObject = Instantiate(hit.transform.parent.gameObject, m_gridPlane.transform.parent);

                    m_activeDragObject = hit.transform.parent.gameObject;

                    //Set the last spawn prefab to this "boat spawner"
                    m_lastSpawnPrefab = hit.transform.parent.gameObject;
                    //Set the spawner to not be active
                    //m_lastSpawnPrefab.SetActive(false);
                }

                //If we don't have a last active object
                if (m_lastActiveObject == null)
                {
                    //Set the last active object to this new object
                    m_lastActiveObject = m_activeDragObject;
                    //Activate it's rotate canvas
                    m_lastActiveObject.transform.Find("RotateButtonCanvas").gameObject.SetActive(true);
                }
                else
                {
                    //Clicked on a different object
                    if (m_activeDragObject != m_lastActiveObject)
                    {
                        m_lastActiveObject.transform.Find("RotateButtonCanvas").gameObject.SetActive(false);
                        m_lastActiveObject = m_activeDragObject;
                        m_lastActiveObject.transform.Find("RotateButtonCanvas").gameObject.SetActive(true);
                    }
                }
            }
        }
    }
Ejemplo n.º 45
0
        /// <summary>
        /// 定时检查
        /// </summary>
        public void Check()
        {
            m_planService.OnTimer();
            Dictionary <int, GridColumn> columnsIndex = new Dictionary <int, GridColumn>();
            List <GridColumn>            columns      = m_gridPlan.GetColumns();
            int columnsSize = columns.Count;

            for (int i = 0; i < columnsSize; i++)
            {
                GridColumn column = columns[i];
                columnsIndex[CStr.ConvertStrToInt(column.Name.Substring(4))] = column;
            }
            Dictionary <String, String> pids = new Dictionary <String, String>();
            List <CPlan> plans = new List <CPlan>();

            DataCenter.PlanService.GetPlans(plans);
            int plansSize = plans.Count;

            for (int i = 0; i < plansSize; i++)
            {
                pids[plans[i].m_id] = "";
            }
            GridRow selectedRow = null;
            Dictionary <String, GridRow> rowsMap = new Dictionary <String, GridRow>();
            List <GridRow> rows     = m_gridPlan.GetRows();
            int            rowsSize = rows.Count;

            for (int i = 0; i < rowsSize; i++)
            {
                GridRow row = rows[i];
                String  id  = "";
                if (row.GetCell("colP1") != null)
                {
                    id = row.GetCell("colP1").GetString();
                }
                if (pids.ContainsKey(id))
                {
                    rowsMap[id] = row;
                }
                else
                {
                    m_gridPlan.RemoveRow(row);
                    row.Dispose();
                    rowsSize--;
                    i--;
                }
            }
            m_gridPlan.Update();
            m_gridPlan.BeginUpdate();
            for (int i = 0; i < plansSize; i++)
            {
                CPlan   plan    = plans[i];
                GridRow row     = null;
                bool    newData = false;
                if (rowsMap.ContainsKey(plan.m_id))
                {
                    row = rowsMap[plan.m_id];
                }
                else
                {
                    row         = new GridRow();
                    row.Height  = 50;
                    selectedRow = row;
                    m_gridPlan.AddRow(row);
                    newData = true;
                }
                foreach (int col in columnsIndex.Keys)
                {
                    GridCell   cell   = null;
                    GridColumn column = columnsIndex[col];
                    if (newData)
                    {
                        if (col == 5)
                        {
                            GridProgressCell progressCell = new GridProgressCell();
                            cell = progressCell;
                            row.AddCell(column.Index, cell);
                        }
                        else
                        {
                            cell = new GridStringCell();
                            if (col == 3)
                            {
                                cell.AllowEdit = true;
                            }
                            row.AddCell(column.Index, cell);
                        }
                    }
                    else
                    {
                        cell = row.GetCell(column.Index);
                    }
                    switch (col)
                    {
                    //ID
                    case 1:
                        cell.SetString(plan.m_id);
                        break;

                    //名称
                    case 2:
                        cell.SetString(plan.m_name);
                        break;

                    //进程
                    case 3:
                        cell.SetString(plan.m_command);
                        break;

                    //状态
                    case 4:
                        cell.SetString(plan.m_status);
                        GridCellStyle cellStyle = new GridCellStyle();
                        if (plan.m_status == "启动")
                        {
                            cellStyle.ForeColor = CDraw.GetPriceColor(1, 2);
                        }
                        else if (plan.m_status == "禁用")
                        {
                            cellStyle.ForeColor = CDraw.GetPriceColor(2, 1);
                        }
                        cell.Style = cellStyle;
                        break;

                    //下次执行时间
                    case 5:
                        GridProgressCell progressCell = cell as GridProgressCell;
                        if (plan.m_nextTime != 0)
                        {
                            DateTime nowDate = DateTime.Now;
                            long     span    = (long)plan.m_timeSpan * 1000 * 10000;
                            double   rate    = 100 - 100 * (plan.m_nextTime - nowDate.Ticks) / span;
                            if (rate < 0)
                            {
                                rate = 100 - 100 * (double)(plan.m_nextTime - nowDate.Ticks) / (plan.m_nextTime - plan.m_createTime);
                            }
                            progressCell.Rate = rate;
                        }
                        else
                        {
                            progressCell.Rate = 0;
                        }
                        cell.SetString(new DateTime(plan.m_nextTime).ToString());
                        break;

                    //上次执行时间
                    case 6:
                        cell.SetString(new DateTime(plan.m_lastTime).ToString());
                        break;

                    //上次结果
                    case 7:
                        cell.SetString(plan.m_lastResult);
                        break;

                    //间隔
                    case 8:
                        cell.SetString(plan.m_timeSpan.ToString());
                        break;

                    //创建时间
                    case 9:
                        cell.SetString(new DateTime(plan.m_createTime).ToString());
                        break;

                    //相关人员
                    case 10:
                        cell.SetString(plan.m_member);
                        break;
                    }
                }
            }
            //修正选中行
            if (selectedRow != null)
            {
                List <GridRow> selectedRows = new List <GridRow>();
                selectedRows.Add(selectedRow);
                m_gridPlan.SelectedRows = selectedRows;
            }
            m_gridPlan.EndUpdate();
            Native.Invalidate();
            columnsIndex.Clear();
            pids.Clear();
            plans.Clear();
        }
Ejemplo n.º 46
0
 public List <GridCell> getVerticalNeighbors(GridCell cell, int range = 1) => getNeighbors(cell, range, new Vector2Int(0, 1), new Vector2Int(0, -1));
Ejemplo n.º 47
0
        public void should_not_unlink_to_null_neighbors()
        {
            var gridCell = new GridCell(1, 1);

            Assert.Throws <ArgumentNullException>(() => gridCell.Unlink(null));
        }
Ejemplo n.º 48
0
 public List <GridCell> getHorizontalNeighbors(GridCell cell, int range = 1) => getNeighbors(cell, range, new Vector2Int(1, 0), new Vector2Int(-1, 0));
Ejemplo n.º 49
0
 public void RemoveBallFromGridCell(GridCell cell)
 {
     generatedGridWithBalls[cell.X, cell.Y].Ball = null;
 }
Ejemplo n.º 50
0
 public List <GridCell> getHVNeighbors(GridCell cell, int range = 1) => getVerticalNeighbors(cell, range).Concat(getHorizontalNeighbors(cell, range)).ToList();
Ejemplo n.º 51
0
        public void ValidateInnerHtmlContains_When_GetCell()
        {
            GridCell cell = _testGrid.GetCell(0, 1);

            cell.ValidateInnerHtmlContains("</b>");
        }
Ejemplo n.º 52
0
        /// <summary>
        /// find edge crossings and generate triangles for this cell
        /// </summary>
        bool polygonize_cell(GridCell cell, Vector3d[] vertList)
        {
            // construct bits of index into edge table, where bit for each
            // corner is 1 if that value is < isovalue.
            // This tell us which edges have sign-crossings, and the int value
            // of the bitmap is an index into the edge and triangle tables
            int cubeindex = 0, shift = 1;

            for (int i = 0; i < 8; ++i)
            {
                if (cell.f[i] < IsoValue)
                {
                    cubeindex |= shift;
                }
                shift <<= 1;
            }

            // no crossings!
            if (edgeTable[cubeindex] == 0)
            {
                return(false);
            }

            // check each bit of value in edge table. If it is 1, we
            // have a crossing on that edge. Look up the indices of this
            // edge and find the intersection point along it
            shift = 1;
            for (int i = 0; i <= 11; i++)
            {
                if ((edgeTable[cubeindex] & shift) != 0)
                {
                    int a = edge_indices[i, 0], b = edge_indices[i, 1];
                    find_iso(ref cell.p[a], ref cell.p[b], cell.f[a], cell.f[b], ref vertList[i]);
                }
                shift <<= 1;
            }

            // now iterate through the set of triangles in triTable for this cube,
            // and emit triangles using the vertices we found.
            int tri_count = 0;

            for (int i = 0; triTable[cubeindex, i] != -1; i += 3)
            {
                int ta = triTable[cubeindex, i];
                int a  = find_or_append_vertex(ref vertList[ta]);

                int tb = triTable[cubeindex, i + 1];
                int b  = find_or_append_vertex(ref vertList[tb]);

                int tc = triTable[cubeindex, i + 2];
                int c  = find_or_append_vertex(ref vertList[tc]);

                // if a corner is within tolerance of isovalue, then some triangles
                // will be degenerate, and we can skip them w/o resulting in cracks (right?)
                if (a == b || a == c || b == c)
                {
                    continue;
                }

                /*int tid = */ append_triangle(a, b, c);
                tri_count++;
            }

            return(tri_count > 0);
        }
Ejemplo n.º 53
0
        public void ValidateInnerTextContains_When_GetCell()
        {
            GridCell cell = _testGrid.GetCell(0, 1);

            cell.ValidateInnerTextContains("Jo");
        }
Ejemplo n.º 54
0
 public void SetNeighbor(GridDirection direction, GridCell cell)
 {
     neighbors[( int )direction] = cell;
     cell.neighbors[( int )direction.Opposite()] = this;
 }
Ejemplo n.º 55
0
        public void ValidateInnerText_When_GetCell()
        {
            GridCell cell = _testGrid.GetCell(0, 1);

            cell.ValidateInnerTextIs("John");
        }
Ejemplo n.º 56
0
 public void setPreviousSelectedCell(GridCell cell) => previousSelectedCell = cell;
Ejemplo n.º 57
0
        public static void RefreshHighlights()
        {
            try
            {
                if (bSkipHighlighting)
                {
                    return;
                }
                if (variablesToolWindowControl == null)
                {
                    return;
                }

#if DENALI || SQL2014
                packageDesigner = (ComponentDesigner)variablesToolWindowControl.GetType().GetProperty("PackageDesigner", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.Instance).GetValue(variablesToolWindowControl, null);
#else
                packageDesigner = (ComponentDesigner)variablesToolWindowControl.GetType().InvokeMember("PackageDesigner", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.GetProperty | System.Reflection.BindingFlags.FlattenHierarchy | System.Reflection.BindingFlags.Instance, null, variablesToolWindowControl, null);
#endif
                if (packageDesigner == null)
                {
                    return;
                }

                Package package = packageDesigner.Component as Package;
                if (package == null)
                {
                    return;
                }

                List <string> listConfigPaths;
                lock (HighlightingToDo.cacheConfigPaths)
                {
                    if (HighlightingToDo.cacheConfigPaths.ContainsKey(package))
                    {
                        listConfigPaths = HighlightingToDo.cacheConfigPaths[package];
                    }
                    else
                    {
                        listConfigPaths = new List <string>();
                    }
                }

                for (int iRow = 0; iRow < grid.RowsNumber; iRow++)
                {
                    GridCell cell = grid.GetCellInfo(iRow, 0);
                    if (cell.CellData != null)
                    {
                        System.Diagnostics.Debug.WriteLine(cell.CellData.GetType().FullName);
                        Variable variable = GetVariableForRow(iRow);

#if DENALI || SQL2014
                        // Denali doesn't need variable highlighting, it is built in. This is a quick fix to disable the highlighting
                        // for Denali only. The other code stays the same for backward compatability when compiled as 2005 or 2008 projects.
                        // We will retain the configuration highlighting though.
                        bool bHasExpression = false;
#else
                        bool bHasExpression = variable.EvaluateAsExpression && !string.IsNullOrEmpty(variable.Expression);
#endif
                        bool   bHasConfiguration = false;
                        string sVariablePath     = variable.GetPackagePath();
                        foreach (string configPath in listConfigPaths)
                        {
                            if (configPath.StartsWith(sVariablePath))
                            {
                                bHasConfiguration = true;
                                break;
                            }
                        }

                        System.Drawing.Bitmap icon = (System.Drawing.Bitmap)cell.CellData;
                        if (!bHasExpression && !bHasConfiguration && icon.Tag != null)
                        {
                            // Reset the icon because this one doesn't have an expression anymore
                            cell.CellData = icon.Tag;
                            icon.Tag      = null;

                            try
                            {
                                bSkipHighlighting = true;
                                grid.Invalidate(true);
                            }
                            finally
                            {
                                bSkipHighlighting = false;
                            }

                            System.Diagnostics.Debug.WriteLine("un-highlighted variable");
                        }
                        else if ((bHasExpression || bHasConfiguration))
                        {
                            //save what the icon looked like originally so we can go back if they remove the expression
                            if (icon.Tag == null)
                            {
                                icon.Tag = icon.Clone();
                            }

                            //now update the icon to note this one has an expression
                            if (bHasExpression && !bHasConfiguration)
                            {
                                HighlightingToDo.ModifyIcon(icon, HighlightingToDo.expressionColor);
                            }
                            else if (bHasConfiguration && !bHasExpression)
                            {
                                HighlightingToDo.ModifyIcon(icon, HighlightingToDo.configurationColor);
                            }
                            else
                            {
                                HighlightingToDo.ModifyIcon(icon, HighlightingToDo.expressionColor, HighlightingToDo.configurationColor);
                            }
                            cell.CellData = icon;

                            try
                            {
                                bSkipHighlighting = true;
                                grid.Invalidate(true);
                            }
                            finally
                            {
                                bSkipHighlighting = false;
                            }

                            System.Diagnostics.Debug.WriteLine("highlighted variable");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.Message + "\r\n\r\n" + ex.StackTrace);
            }
        }
 private void EnsureCellVisible(GridCell cell)
 {
     view.MakeRowVisible(cell.RowHandle);
     view.MakeColumnVisible(cell.Column);
 }
Ejemplo n.º 59
0
 /// <summary>
 /// 单元格双击事件
 /// </summary>
 /// <param name="sender">调用者</param>
 /// <param name="cell">单元格</param>
 /// <param name="mp">坐标</param>
 /// <param name="button">按钮</param>
 /// <param name="clicks">点击次数</param>
 /// <param name="delta">滚轮值</param>
 private void GridCellClick(object sender, GridCell cell, POINT mp, MouseButtonsA button, int clicks, int delta)
 {
     if (cell.Grid == m_tvIndicatorBrowser)
     {
         TreeNodeA tn = cell as TreeNodeA;
         if (tn.m_nodes.Count == 0)
         {
             NodeData nodeData = tn.Tag as NodeData;
             if (nodeData.IsCatalog)
             {
                 IndicatorLeafDataPacket leafPacket = new IndicatorLeafDataPacket(nodeData.Id);
                 ConnectManager.CreateInstance().Request(leafPacket);
                 int tick = 0;
                 while (leafPacket.ReserveFlag == 0 && tick < 50)
                 {
                     Thread.Sleep(100);
                     tick++;
                 }
                 if (leafPacket.LeafNodeList.Count > 0)
                 {
                     List <NodeData> nodes = leafPacket.LeafNodeList;
                     Dictionary <String, TreeNodeA> nodesMap = new Dictionary <String, TreeNodeA>();
                     int nodesSzie = nodes.Count;
                     for (int i = 0; i < nodesSzie; i++)
                     {
                         NodeData  node  = nodes[i];
                         TreeNodeA subTn = new TreeNodeA();
                         subTn.Text            = node.Name;
                         subTn.Style           = new GridCellStyle();
                         subTn.Style.ForeColor = COLOR.ARGB(255, 255, 80);
                         subTn.Style.Font      = new FONT("微软雅黑", 14, true, false, false);
                         subTn.Name            = node.Id;
                         subTn.Tag             = node;
                         if (nodesMap.ContainsKey(node.ParentId))
                         {
                             nodesMap[node.ParentId].AppendNode(subTn);
                             nodesMap[node.Id] = subTn;
                         }
                         else
                         {
                             tn.AppendNode(subTn);
                             nodesMap[node.Id] = subTn;
                         }
                         IndicatorEntityDataPacket entity = new IndicatorEntityDataPacket(node.Id);
                         ConnectManager.CreateInstance().Request(entity);
                     }
                     tn.ExpendAll();
                     m_tvIndicatorBrowser.Update();
                     m_tvIndicatorBrowser.Invalidate();
                 }
             }
             else
             {
                 StringBuilder     sb         = new StringBuilder();
                 CList <GSecurity> securities = SecurityService.FilterCode(m_txtIndicatorCode.Text);
                 int codesSize = securities.size();
                 for (int i = 0; i < codesSize; i++)
                 {
                     sb.Append(securities.get(i).m_code);
                     if (i != codesSize - 1)
                     {
                         sb.Append(",");
                     }
                 }
                 m_gridIndicatorBrowser.ClearRows();
                 IndicatorRootData data = GetIndicatorData(nodeData.Id, "Stock", sb.ToString());
                 m_gridIndicatorBrowser.GetColumn("colN3").Text = data.categoryName;
                 foreach (IndicatorItemData indicatorItem in data.items)
                 {
                     GridRow row = new GridRow();
                     m_gridIndicatorBrowser.AddRow(row);
                     GridStringCell codeCell = new GridStringCell(indicatorItem.code);
                     row.AddCell("colN1", codeCell);
                     GSecurity security = new GSecurity();
                     SecurityService.GetSecurityByCode(indicatorItem.code, ref security);
                     row.AddCell("colN2", new GridStringCell(security.m_name));
                     if (indicatorItem.type == 0)
                     {
                         GridStringCell valueCell = new GridStringCell(indicatorItem.text);
                         row.AddCell("colN3", valueCell);
                     }
                     else if (indicatorItem.type == 1)
                     {
                         GridDoubleCell valueCell = new GridDoubleCell(indicatorItem.num);
                         row.AddCell("colN3", valueCell);
                     }
                     row.GetCell("colN1").Style           = new GridCellStyle();
                     row.GetCell("colN1").Style.ForeColor = COLOR.ARGB(255, 255, 80);
                     row.GetCell("colN1").Style.Font      = new FONT("微软雅黑", 14, true, false, false);
                     row.GetCell("colN1").Style.Font      = new FONT("微软雅黑", 14, true, false, false);
                     row.GetCell("colN2").Style           = new GridCellStyle();
                     row.GetCell("colN2").Style.ForeColor = COLOR.ARGB(255, 80, 80);
                     row.GetCell("colN2").Style.Font      = new FONT("微软雅黑", 14, true, false, false);
                     row.GetCell("colN3").Style           = new GridCellStyle();
                     row.GetCell("colN3").Style.ForeColor = COLOR.ARGB(80, 255, 255);
                     row.GetCell("colN3").Style.Font      = new FONT("微软雅黑", 14, true, false, false);
                 }
                 m_gridIndicatorBrowser.Update();
                 m_gridIndicatorBrowser.Invalidate();
             }
         }
     }
     else if (cell.Grid == m_gridIndicatorBrowser)
     {
         if (clicks == 2)
         {
             m_mainFrame.SearchSecurity(cell.Row.GetCell("colN1").GetString());
         }
     }
 }
Ejemplo n.º 60
0
 public override void OnMouseClicked()
 {
     GridCell.GridTokenClicked(this);
 }