private void MatItem_KeyPress(object sender, CellKeyPressEventArgs args)
        {
            if (GridNavigator.ColumnKeyPress(args, colItem.Index, MatItemChoose,
                                             MatItemEvaluate, MatItemEditPrev, MatItemEditNext))
            {
                return;
            }

            string gdkKey = KeyShortcuts.KeyToString(args.EventKey);
            string quickGoods;

            if (!BusinessDomain.QuickItems.TryGetValue(gdkKey, out quickGoods))
            {
                return;
            }

            if (!MatItemEvaluate(grdMaterials.EditedCell.Row, quickGoods))
            {
                return;
            }

            MatQtyEvaluate(grdMaterials.EditedCell.Row, 1);

            if (recipe.DetailsMat.Count <= grdMaterials.EditedCell.Row + 1)
            {
                recipe.AddNewDetail();
            }

            MatEditGridField(grdMaterials.EditedCell.Row + 1, colItem.Index);

            args.MarkAsHandled();
        }
Ejemplo n.º 2
0
        // We need local copy of GridNavigator for each call of recursive func
        private GridNavigator GetGridNavigator(int x, int y)
        {
            var result = new GridNavigator(_cells.GetLength(0), _cells.GetLength(1));

            result.SetCurrentPosition(x, y);
            return(result);
        }
Ejemplo n.º 3
0
        public Vector2 PosToUv(Vector3 diff)
        {
            var uv = new Vector2();

            switch (GridNavigator.Inst().gSide)
            {
            case Gridside.xy:
                uv.x = diff.x;
                uv.y = diff.y;
                break;

            case Gridside.xz:
                uv.x = diff.x;
                uv.y = diff.z;
                break;

            case Gridside.zy:
                uv.x = diff.z;
                uv.y = diff.y;
                break;
            }

            uv = (uv + offset);

            uv.Scale(tiling);

            return(uv);
        }
Ejemplo n.º 4
0
        public void NavigateNorth_Invalid_VerticalCoordinates_Fail()
        {
            GridNavigator sut = new GridNavigator();

            sut.InitializeCoordinates(new Point2D(-1, 100000));
            sut.NavigateTo(NavigationDirections.North);
        }
Ejemplo n.º 5
0
        public override bool Match(int x, int y, TileResultCollector <TRenderTile, TContext> resultCollector)
        {
            if (!Matcher(x, y))
            {
                return(false);
            }

            var context = ContextProvider(x, y);

            neighbourPositions = GridNavigator.NavigateNeighbours(new MapCoordinate(x, y), neighbourPositions);
            bool matchedOne = false;

            for (var i = 1; i < positions.Length; i++)
            {
                var mc = neighbourPositions[i - 1];
                if (Matcher(mc.X, mc.Y) && tileExists[i])
                {
                    resultCollector(SpritePosition.Whole, tiles[i], context);
                    matchedOne = true;
                }
            }

            if (!matchedOne)
            {
                // isolated tile ..
                if (tileExists[0])
                {
                    resultCollector(SpritePosition.Whole, tiles[0], context);
                }
            }

            return(true);
        }
Ejemplo n.º 6
0
        public Vector3 HalfVectorToB(LineData other)
        {
            var lineA = this;
            var lineB = other;

            if (other.points[1] == points[0])
            {
                lineA = other;
                lineB = this;
            }

            var a = lineA.points[0].LocalPos - lineA.points[1].LocalPos;
            var b = lineB.points[1].LocalPos - lineB.points[0].LocalPos;

            var fromVector2 = GridNavigator.Inst().InPlaneVector(a);
            var toVector2   = GridNavigator.Inst().InPlaneVector(b);

            var mid = (fromVector2.normalized + toVector2.normalized).normalized;

            var cross = Vector3.Cross(fromVector2, toVector2);

            if (cross.z > 0)
            {
                mid = -mid;
            }

            return(GridNavigator.Inst().PlaneToWorldVector(mid).normalized);
        }
Ejemplo n.º 7
0
        public void NavigateWest_Invalid_HorizontalCoordinates_Fail()
        {
            GridNavigator sut = new GridNavigator();

            sut.InitializeCoordinates(new Point2D(-100000, 2));
            sut.NavigateTo(NavigationDirections.West);
        }
Ejemplo n.º 8
0
        public Vector3 HalfVectorToB(LineData other)
        {
            LineData LineA = this;
            LineData LineB = other;

            if (other.pnts[1] == pnts[0])
            {
                LineA = other;
                LineB = this;
            }

            Vector3 a = LineA.pnts[0].Pos - LineA.pnts[1].Pos;
            Vector3 b = LineB.pnts[1].Pos - LineB.pnts[0].Pos;


            Vector2 fromVector2 = GridNavigator.Inst().InPlaneVector(a);
            Vector2 toVector2   = GridNavigator.Inst().InPlaneVector(b);


            Vector2 mid = (fromVector2.normalized + toVector2.normalized).normalized;

            Vector3 cross = Vector3.Cross(fromVector2, toVector2);

            if (cross.z > 0)
            {
                mid = -mid;
            }



            return(GridNavigator.Inst().PlaneToWorldVector(mid).normalized);
        }
Ejemplo n.º 9
0
        public void CanGetNextTrackPiece(string track, int x, int y, Direction startDirection, String desiredResult)
        {
            // Arrange
            var            grid        = new Grid(track);
            Coord          pos         = new Coord(x, y);
            var            direction   = startDirection;
            var            resultTrack = new StringBuilder();
            bool           moreTrack   = true;
            int            i           = 0;
            IGridNavigator nav         = new GridNavigator();

            // Act
            do
            {
                char piece = grid[pos];
                resultTrack.Append(piece);
                var res = TrackBuilder.GetNextTrackPiece(nav, grid, pos, direction);
                moreTrack = res.Found;
                pos       = res.NextPos;
                direction = res.NextDir;
                i++;
            } while (moreTrack && i < 20);

            // Assert
            resultTrack.ToString().Should().Be(desiredResult);
        }
Ejemplo n.º 10
0
        public void MoveVertexToGrid(MeshPoint vp)
        {
            UpdateLocalSpaceV3s();
            Vector3 diff = onGridLocal - vp.localPos;

            diff.Scale(GridNavigator.Inst().GetGridPerpendicularVector());
            vp.localPos += diff;
        }
Ejemplo n.º 11
0
        public void IsCellInBounds_returns_true_if_coordinates_is_inside_of_bounds()
        {
            GridNavigator navigator = new GridNavigator(10, 10);

            Assert.IsTrue(navigator.IsCellInBounds(1, 2));
            Assert.IsTrue(navigator.IsCellInBounds(9, 9));
            Assert.IsTrue(navigator.IsCellInBounds(0, 0));
        }
Ejemplo n.º 12
0
        public void SetCurrentPosition_sets_position()
        {
            GridNavigator navigator = new GridNavigator(10, 10);

            navigator.SetCurrentPosition(1, 2);

            Assert.AreEqual(new Cell(1, 2), navigator.CurrentPosition);
        }
Ejemplo n.º 13
0
        public void SetCurrentPosition_throws_exception_if_outside_bounds()
        {
            GridNavigator navigator = new GridNavigator(10, 10);

            Assert.Throws <ArgumentOutOfRangeException>(() => { navigator.SetCurrentPosition(-1, -1); });
            Assert.Throws <ArgumentOutOfRangeException>(() => navigator.SetCurrentPosition(11, 0));
            Assert.Throws <ArgumentOutOfRangeException>(() => navigator.SetCurrentPosition(0, 11));
        }
Ejemplo n.º 14
0
        public override bool Match(int x, int y, TileResultCollector <TRenderTile, TContext> resultCollector)
        {
            coordinates = GridNavigator.NavigateCardinalNeighbours(new MapCoordinate(x, y), coordinates);

            var  n      = Matches(coordinates[(int)Direction.Up]);
            var  e      = Matches(coordinates[(int)Direction.Right]);
            var  s      = Matches(coordinates[(int)Direction.Down]);
            var  w      = Matches(coordinates[(int)Direction.Left]);
            bool result = false;

            if (n)
            {
                if (e)
                {
                    if (tileExists[1])
                    {
                        resultCollector(SpritePosition.Whole, tiles[1], ContextProvider(x, y));
                    }

                    result = true;
                }

                if (w)
                {
                    if (tileExists[0])
                    {
                        resultCollector(SpritePosition.Whole, tiles[0], ContextProvider(x, y));
                    }

                    result = true;
                }
            }

            if (s)
            {
                if (e)
                {
                    if (tileExists[2])
                    {
                        resultCollector(SpritePosition.Whole, tiles[2], ContextProvider(x, y));
                    }

                    result = true;
                }

                if (w)
                {
                    if (tileExists[3])
                    {
                        resultCollector(SpritePosition.Whole, tiles[3], ContextProvider(x, y));
                    }

                    result = true;
                }
            }

            return(result);
        }
Ejemplo n.º 15
0
        private void InitializeGrid()
        {
            grid = new ListView();
            scwGrid.Add(grid);
            grid.Show();

            grid.WidthRequest  = 500;
            grid.HeightRequest = 200;

            ColumnController cc = new ColumnController();

            CellText ct = new CellText("ItemName")
            {
                IsEditable = true
            };

            colItem = new Column(Translator.GetString("Item"), ct, 1);
            colItem.ButtonPressEvent += ItemColumn_ButtonPressEvent;
            colItem.KeyPressEvent    += ItemColumn_KeyPress;
            cc.Add(colItem);

            CellTextQuantity ctq = new CellTextQuantity("Quantity")
            {
                IsEditable = true
            };

            colQtty = new Column(Translator.GetString("Qtty"), ctq, 0.1)
            {
                MinWidth = 70
            };
            colQtty.ButtonPressEvent += QttyColumn_ButtonPressEvent;
            colQtty.KeyPressEvent    += QtyColumn_KeyPress;
            cc.Add(colQtty);

            CellTextCurrency ctc = new CellTextCurrency("OriginalPriceOut")
            {
                IsEditable = true
            };

            colSalePrice = new Column(Translator.GetString("Price"), ctc, 0.1)
            {
                MinWidth = 70
            };
            colSalePrice.ButtonPressEvent += SalePriceColumn_ButtonPressEvent;
            colSalePrice.KeyPressEvent    += SalePriceColumn_KeyPress;
            cc.Add(colSalePrice);

            grid.ColumnController   = cc;
            grid.Model              = new BindingListModel(selectedDetails);
            grid.AllowSelect        = false;
            grid.CellsFucusable     = true;
            grid.ManualFucusChange  = true;
            grid.RulesHint          = true;
            grid.CellKeyPressEvent += Grid_CellKeyPressEvent;
            grid.Mapped            += (sender, e) => EditGridCell(0, 0);
            gridNavigator           = new GridNavigator(grid, EditGridCell, GridColumnEditOver, GridColumnEditBelow);
        }
Ejemplo n.º 16
0
        public void Neighbours_for_corner_cell_returns_only_available_neighbours()
        {
            GridNavigator navigator = new GridNavigator(10, 10);

            navigator.SetCurrentPosition(0, 0);

            Assert.AreEqual(2, navigator.Neighbours.Count);
            Assert.AreEqual(new Cell(1, 0), navigator.Neighbours[Direction.Right]);
            Assert.AreEqual(new Cell(0, 1), navigator.Neighbours[Direction.Down]);
        }
Ejemplo n.º 17
0
        public void IsCellInBounds_returns_false_if_coordinates_is_outside_of_bounds()
        {
            GridNavigator navigator = new GridNavigator(10, 10);

            Assert.IsFalse(navigator.IsCellInBounds(11, 0));
            Assert.IsFalse(navigator.IsCellInBounds(10, 10));
            Assert.IsFalse(navigator.IsCellInBounds(0, 11));
            Assert.IsFalse(navigator.IsCellInBounds(-1, 0));
            Assert.IsFalse(navigator.IsCellInBounds(0, -1));
        }
        private void MatQtyEditPrev(int row, Gdk.Key keyCode)
        {
            if (keyCode == Gdk.Key.ISO_Left_Tab)
            {
                MatCurrentColumnEvaluate();
                return;
            }

            GridNavigator.EditPrev(row, keyCode, colItem, MatItemEditPrev);
        }
Ejemplo n.º 19
0
        public static Coord GetStart(this IGrid grid)
        {
            var res = new GridNavigator().FindFirst(grid, c => TrackBuilder.IsTrackPiece(c));

            if (!res.IsInGrid)
            {
                throw new InvalidOperationException($"Grid Start could not be found.");
            }

            return(res.NewPosition);
        }
Ejemplo n.º 20
0
        public void Neighbours_returns_all_neighbour_cells()
        {
            GridNavigator navigator = new GridNavigator(10, 10);

            navigator.SetCurrentPosition(5, 5);

            Assert.AreEqual(new Cell(4, 5), navigator.Neighbours[Direction.Left]);
            Assert.AreEqual(new Cell(6, 5), navigator.Neighbours[Direction.Right]);
            Assert.AreEqual(new Cell(5, 6), navigator.Neighbours[Direction.Down]);
            Assert.AreEqual(new Cell(5, 4), navigator.Neighbours[Direction.Up]);
        }
        private void MatQtyEditNext(int row, Gdk.Key keyCode)
        {
            if (keyCode == Gdk.Key.Tab)
            {
                MatCurrentColumnEvaluate();
                ProdEditGridField(0, colItem.Index);
                return;
            }

            GridNavigator.EditNextOnLast(row, keyCode, colItem, MatItemEditNext, recipe.DetailsMat, recipe.AddNewDetail);
        }
Ejemplo n.º 22
0
        public override bool Match(int x, int y, TileResultCollector <TRenderTile, TContext> resultCollector)
        {
            // The current tile is not a land tile. If it is an ocean tile, we can test
            // whether one of the cardinal neighbours is a river that flows into the
            // ocean.
            if (!selfMatcher(x, y))
            {
                return(false);
            }

            coordinates = GridNavigator.NavigateCardinalNeighbours(new MapCoordinate(x, y), coordinates);
            if (Matches(coordinates[CardinalIndex.North.AsInt()]))
            {
                if (northTileExists)
                {
                    resultCollector(SpritePosition.Whole, northTile, ContextProvider(x, y));
                }

                return(true);
            }

            if (Matches(coordinates[CardinalIndex.East.AsInt()]))
            {
                if (eastTileExists)
                {
                    resultCollector(SpritePosition.Whole, eastTile, ContextProvider(x, y));
                }

                return(true);
            }

            if (Matches(coordinates[CardinalIndex.South.AsInt()]))
            {
                if (southTileExists)
                {
                    resultCollector(SpritePosition.Whole, southTile, ContextProvider(x, y));
                }

                return(true);
            }

            if (Matches(coordinates[CardinalIndex.West.AsInt()]))
            {
                if (westTileExists)
                {
                    resultCollector(SpritePosition.Whole, westTile, ContextProvider(x, y));
                }

                return(true);
            }

            return(false);
        }
Ejemplo n.º 23
0
        public override void ManageDragging()
        {
            var m = MeshMGMT;

            bool beforeCouldDrag = m.dragDelay <= 0;

            if (EditorInputManager.GetMouseButtonUp(0) || !EditorInputManager.GetMouseButton(0))
            {
                m.Dragging = false;

                if (beforeCouldDrag)
                {
                    EditedMesh.dirty_Position = true;
                }
                else
                if ((m.TrisVerts < 3) && (m.SelectedUV != null) && (!m.IsInTrisSet(m.SelectedUV.meshPoint)))
                {
                    m.AddToTrisSet(m.SelectedUV);
                }
            }
            else
            {
                m.dragDelay -= Time.deltaTime;

                bool canDrag = m.dragDelay <= 0;

                if (beforeCouldDrag != canDrag && EditorInputManager.getAltKey() && (m.SelectedUV.meshPoint.uvpoints.Count > 1))
                {
                    m.DisconnectDragged();
                }

                if (canDrag || !Application.isPlaying)
                {
                    if ((GridNavigator.Inst().AngGridToCamera(GridNavigator.onGridPos) < 82))
                    {
                        Vector3 delta = GridNavigator.onGridPos - originalPosition;

                        if (delta.magnitude > 0)
                        {
                            m.TrisVerts = 0;

                            foreach (var v in draggedVertices)
                            {
                                v.WorldPos += delta;
                            }

                            originalPosition = GridNavigator.onGridPos;
                        }
                    }
                }
            }
        }
Ejemplo n.º 24
0
 public void Invalid_VerticalCoordinates_Fail()
 {
     try
     {
         GridNavigator sut = new GridNavigator();
         sut.InitializeCoordinates(new Point2D(-100000, 100001));
     }
     catch (InvalidOperationException ex)
     {
         Debug.WriteLine(ex.Message);
         throw;
     }
 }
Ejemplo n.º 25
0
 public void DisconnectMesh()
 {
     if (target != null)
     {
         MeshTool.OnDeSelectTool();
         target.SavedEditableMesh = edMesh.Encode().ToString();
         target = null;
     }
     Grid.Deactivateverts();
     GridNavigator.Inst().SetEnabled(false, false);
     undoMoves.Clear();
     redoMoves.Clear();
 }
Ejemplo n.º 26
0
 public void DisconnectMesh()
 {
     if (target)
     {
         MeshTool.OnDeSelectTool();
         target.SavedEditableMesh = editedMesh.Encode().ToString();
         target          = null;
         targetTransform = null;
     }
     Grid.DeactivateVertices();
     GridNavigator.Inst().SetEnabled(false, false);
     UndoMoves.Clear();
     RedoMoves.Clear();
 }
Ejemplo n.º 27
0
        public override void ManageDragging()
        {
            var m = MeshMGMT;

            var beforeCouldDrag = m.DragDelay <= 0;

            if (EditorInputManager.GetMouseButtonUp(0) || !EditorInputManager.GetMouseButton(0))
            {
                m.Dragging = false;

                if (beforeCouldDrag)
                {
                    EditedMesh.dirtyPosition = true;
                }
                else
                {
                    OnClickDetected();
                }
            }
            else
            {
                var canDrag = m.DragDelay <= 0;

                if (beforeCouldDrag != canDrag && EditorInputManager.Alt && m.SelectedUv.meshPoint.vertices.Count > 1)
                {
                    m.DisconnectDragged();
                }

                if (!canDrag || !(GridNavigator.Inst().AngGridToCamera(GridNavigator.onGridPos) < 82))
                {
                    return;
                }

                var delta = GridNavigator.onGridPos - _originalPosition;

                if (delta.magnitude == 0)
                {
                    return;
                }

                m.TriVertices = 0;

                foreach (var v in _draggedVertices)
                {
                    v.WorldPos += delta;
                }

                _originalPosition = GridNavigator.onGridPos;
            }
        }
Ejemplo n.º 28
0
        public override void FeedEvents(Event e) {
            
            GridNavigator.Inst().FeedEvent(e);

            if (painter != null) {

                painter.FeedEvents(e);

                if (painter.meshEditing)
                MeshManager.Inst.UpdateInputEditorTime(e,  L_mouseUp, L_mouseDwn);

                
            }
        }
Ejemplo n.º 29
0
        public void CheckFindFirstMatch()
        {
            // Arrange
            var sit = new GridNavigator();

            // Act
            var result = sit.FindFirst(grid, c => c == 'X');

            var(x, y) = result.NewPosition;

            result.IsInGrid.Should().BeTrue();
            x.Should().Be(1);
            y.Should().Be(1);
            result.NewValue.Should().Be('X');
        }
        public static void FeedEvents(Event e)
        {
            GridNavigator.Inst().FeedEvent(e);

            if (!painter)
            {
                return;
            }

            painter.FeedEvents(e);

            if (painter.meshEditing)
            {
                MeshEditorManager.Inst.UpdateInputEditorTime(e, lMouseUp, lMouseDwn);
            }
        }