Exemplo n.º 1
0
        public static void DrawRandomBorder <T>(T border, DataGrid <T> grid, Vector2Int borderThickness, int z, MapEdge edges, bool overwrite = false)
        {
            if (edges.HasFlag(MapEdge.North))
            {
                int thickness = Random.Int(borderThickness);
                for (int x = grid.Bounds.xMin; x <= grid.Bounds.xMax; x++)
                {
                    for (int y = grid.Bounds.yMax - thickness; y <= grid.Bounds.yMax; y++)
                    {
                        grid.Add(new Vector3Int(x, y, z), border, overwrite);
                    }
                    thickness = ChangeThickness(thickness, borderThickness);
                }
            }

            if (edges.HasFlag(MapEdge.South))
            {
                int thickness = Random.Int(borderThickness);
                for (int x = grid.Bounds.xMin; x <= grid.Bounds.xMax; x++)
                {
                    for (int y = grid.Bounds.yMin + thickness; y >= grid.Bounds.yMin; y--)
                    {
                        grid.Add(new Vector3Int(x, y, 0), border, overwrite);
                    }
                    thickness = ChangeThickness(thickness, borderThickness);
                }
            }

            if (edges.HasFlag(MapEdge.East))
            {
                int thickness = Random.Int(borderThickness);
                for (int y = grid.Bounds.yMin; y <= grid.Bounds.yMax; y++)
                {
                    for (int x = grid.Bounds.xMax - thickness; x <= grid.Bounds.xMax; x++)
                    {
                        grid.Add(new Vector3Int(x, y, 0), border, overwrite);
                    }
                    thickness = ChangeThickness(thickness, borderThickness);
                }
            }

            if (edges.HasFlag(MapEdge.West))
            {
                int thickness = Random.Int(borderThickness);
                for (int y = grid.Bounds.yMin; y <= grid.Bounds.yMax; y++)
                {
                    for (int x = grid.Bounds.xMin + thickness; x >= grid.Bounds.xMin; x--)
                    {
                        grid.Add(new Vector3Int(x, y, 0), border, overwrite);
                    }
                    thickness = ChangeThickness(thickness, borderThickness);
                }
            }
        }
Exemplo n.º 2
0
        private void findClicked(object sender, RoutedEventArgs e)
        {
            string colName = comboInfo.Text; // Year / Model
            string toFind = textInfo.Text;

            ItemCollection rows = new DataGrid().Items;
            rows.Clear();
            myGrid.Items.Clear();
            foreach (Car car in carsList)
            {
                myGrid.Items.Add(new Row { Id = car.Id, Model = car.Model, Engine = car.Engine.ToString(), Year = car.Year, EngineType = car.Engine.Model == "TDI" ? "diesel" : "petrol" });
            }
            if (toFind == "" || colName == "none")
            {
                myGrid.Items.Refresh();
                return;
            }
            if (colName == "Model")
            {
                foreach (Row row in myGrid.Items)
                {
                    if (row.Model.Contains(toFind))
                    {
                        rows.Add(new Row { Id = row.Id, Model = row.Model, Engine = row.Engine.ToString(), Year = row.Year, EngineType = row.Model == "TDI" ? "diesel" : "petrol" });
                    }
                }
            }
            else
            {
                int x = 0;
                if (Int32.TryParse(toFind, out x))
                {
                    foreach (Row row in myGrid.Items)
                    {
                        if ((x == row.Year))
                        {
                            rows.Add(new Row { Id = row.Id, Model = row.Model, Engine = row.Engine.ToString(), Year = row.Year, EngineType = row.Model == "TDI" ? "diesel" : "petrol" });
                        }
                    }
                }
            }
            myGrid.Items.Clear();
            foreach (Row row in rows)
            {
                myGrid.Items.Add(row);
            }
            myGrid.Items.Refresh();
        }
Exemplo n.º 3
0
 private void ScannerDebug()
 {
     Log("BarcodeTiles... ");
     DataGrid.Add(new BarcodeTile()
     {
         OperatorName = "TestOpName", FixtureNumber = 1, Date = DateTime.Now, Time = DateTime.Now, SerialNumber = "TestSerialNumber123"
     });
     DataGrid.Add(new BarcodeTile()
     {
         OperatorName = "TestOpName2", FixtureNumber = 2, Date = DateTime.Now, Time = DateTime.Now, SerialNumber = "TestSerialNumber123"
     });
     DataGrid.Add(new BarcodeTile()
     {
         OperatorName = "TestOpName3", FixtureNumber = 3, Date = DateTime.Now, Time = DateTime.Now, SerialNumber = "TestSerialNumber123"
     });
     DataGrid.Add(new BarcodeTile()
     {
         OperatorName = "TestOpName4", FixtureNumber = 4, Date = DateTime.Now, Time = DateTime.Now, SerialNumber = "TestSerialNumber123"
     });
     DataGrid.Add(new BarcodeTile()
     {
         OperatorName = "TestOpName5", FixtureNumber = 5, Date = DateTime.Now, Time = DateTime.Now, SerialNumber = "TestSerialNumber123"
     });
     Log("Finished BarcodeTiles ");
     //DataGrid.Add(new Barcode("Serial#123456", DateTime.Now, "Operator", 1));
     //DataGrid.Add(new Barcode("Serial#123456", DateTime.Now, "Operator", 2));
     //DataGrid.Add(new Barcode("Serial#123456", DateTime.Now, "Operator", 3));
     //DataGrid = new ObservableCollection<Barcode>(DataGrid.Reverse());
     //DataGrid.Insert(0, new Barcode("Serial#123456", DateTime.Now, "Operator", 4));
     //DataGrid.RemoveAt(2);
     //DataGrid.Insert(0, new Barcode("Serial#123456", DateTime.Now, "Operator", 2));
 }
 private void LinkToDataGrid()
 {
     DataGrid.Clear();
     foreach (var equipment in Equipmentlist)
     {
         DataGrid.Add(equipment);
     }
 }
Exemplo n.º 5
0
 public static void DrawBox <T>(T item, DataGrid <T> grid, BoundsInt bounds, int z, bool fill = false, bool overwrite = false)
 {
     for (int y = bounds.yMin; y <= bounds.yMax; y++)
     {
         for (int x = bounds.xMin; x <= bounds.xMax; x++)
         {
             if (fill)
             {
                 grid.Add(new Vector3Int(x, y, z), item, overwrite);
             }
             else
             {
                 if (x == bounds.xMin || x == bounds.xMax || y == bounds.yMin || y == bounds.yMax)
                 {
                     grid.Add(new Vector3Int(x, y, z), item, overwrite);
                 }
             }
         }
     }
 }
Exemplo n.º 6
0
 public static void LayoutObjectsAtRandom <T>(T[] items, DataGrid <T> grid, BoundsInt bounds, int z, float chance, bool overwrite = false)
 {
     for (int y = bounds.yMin; y <= bounds.yMax; y++)
     {
         for (int x = bounds.xMin; x <= bounds.xMax; x++)
         {
             if (Random.Bool(chance))
             {
                 grid.Add(new Vector3Int(x, y, z), items[items.RandomArrayIndex()], overwrite);
             }
         }
     }
 }
Exemplo n.º 7
0
    protected override void OnInitialized()
    {
        base.OnInitialized();
        DataGrid?.Add(this);

        if (SortByExpression != null)
        {
            ((IDataSorter <TDataItem>)DataGrid !).Add(this);
        }

        if (SearchByPredicate != null)
        {
            ((IDataSearcher <TDataItem>)DataGrid !).Add(this);
        }
    }
        /// <summary>
        /// Handle the input
        /// </summary>
        public void HandleInput()
        {
            //_timeController.TargetSpeed = _inputManager.Mouse.IsButtonDown(MouseButton.Right) ? 2 : 1;

            if (_inputManager.Mouse.IsButtonReleased(MouseButton.Left) &&

                _toolBox != null && _inputManager.Mouse.IsOverObj(_toolBox.Position, _toolBox.Size))
            {
                _state.Type = _toolBox.Select(_inputManager.Mouse.Position - _toolBox.Position);
                return;
            }
            else if (_inputManager.Mouse.IsButtonDown(MouseButton.Left) &&
                     _grid != null && _gridData != null && _inputManager.Mouse.IsOverObj(_grid.Position, _grid.Size))
            {
                _gridData.Add(_grid.GridPosition(_inputManager.Mouse.Position - _grid.Position), _state.Type);
                return;
            }
        }
Exemplo n.º 9
0
        public void AddItem(ISelectable selectable, int rowIndex, int columnIndex)
        {
            if (Destroyed)
            {
                throw new InvalidOperationException("Cannot add a control to a destroyed group");
            }

            if (selectable == null)
            {
                throw new ArgumentNullException("selectable");
            }

            if (rowIndex < 0)
            {
                throw new ArgumentException("Cannot add an item to a row index less than 0");
            }

            if (columnIndex < 0)
            {
                throw new ArgumentException("Cannot add an item to a column index less than 0");
            }

            // Make sure this item doesn't already exist or an item doesn't exist in this row/column
            if (_items.Contains(selectable))
            {
                throw new InvalidOperationException("Selectable item already exists in the GridSelectableGroup");
            }

            // Make sure the row/column index is available
            if (_items[rowIndex, columnIndex] != null)
            {
                throw new InvalidOperationException(
                          string.Format("An item already exists at row {0} column {1} in the GridSelectableGroup", rowIndex, columnIndex));
            }

            // If we got here, the specified spot in the grid is free
            _items.Add(selectable, null, rowIndex, columnIndex);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Initializes screen
        /// </summary>
        public override void Initialize()
        {
            // Create the scene and add it
            _camera = new Camera2D(this.Game);
            _camera.Initialize();
            _fxcamera = new Camera2D(this.Game);
            _fxcamera.Initialize();

            _scene = new Scene(this.Game, _camera);
            _scene.TransitionPosition = 0;
            _scene.TransitionOnTime   = TimeSpan.FromSeconds(1);
            _scene.TransitionOffTime  = TimeSpan.FromSeconds(1);
            _scene.OffTransition();
            _fx           = new World(Vector2.UnitY * 10);
            _fxStaticBody = new Body(_fx)
            {
                Restitution = 0, Mass = 0, BodyType = BodyType.Static, Friction = 0.5f                            /*, Position =
                                                                                                                   * ConvertUnits.ToSimUnits(Vector2.UnitX * (_width - DataGrid.WidthInPixels) / 2f + Vector2.UnitY * 150)*/
            };

            // Create controllers
            _timeController        = new TimeController(this.Game);
            _pointsController      = new PointsController(this.Game);
            _dataGrid              = DataGrid.CreateDataGrid(this.Game, _fxStaticBody, _width / 70 - 1, _height / 49 - 4);
            _peaController         = new PeaController(this.Game);
            _inputController       = new InputController(this.Game);
            _achievementController = new AchievementController(this.Game);

            // Initialize controllers
            _timeController.Initialize();
            _pointsController.Initialize();
            _dataGrid.Initialize();
            _peaController.Initialize();
            _inputController.Initialize();
            _achievementController.Initialize();

            // Register controllers
            _dataGrid.Register(_peaController);

#if DEBUG && _
            DataBlock testBlock  = _dataGrid.Add(new Point(0, 0), BlockType.Normal);
            DataBlock testBlock2 = _dataGrid.Add(new Point(0, 1), BlockType.Gel);
            DataBlock testBlock3 = _dataGrid.Add(new Point(1, 1), BlockType.Normal);
            DataBlock testBlock4 = _dataGrid.Add(new Point(2, 1), BlockType.RightRamp);
            DataBlock testBlock5 = _dataGrid.Add(new Point(3, 2), BlockType.Normal);
            DataBlock testBlock6 = _dataGrid.Add(new Point(DataGrid.Width - 1, DataGrid.Height - 1), BlockType.Normal);
#endif
            // Create the peas
            DataPea pea1 = new DataPea(this.Game, _fx, _peaController);
            _pointsController.Register(pea1);
            _achievementController.Register(pea1);

            pea1.Initialize();

            this.Game.Components.Add(pea1);

            DataPea pea2 = new DataPea(this.Game, _fx, _peaController);
            DataPea pea3 = new DataPea(this.Game, _fx, _peaController);
            DataPea pea4 = new DataPea(this.Game, _fx, _peaController);
            DataPea pea5 = new DataPea(this.Game, _fx, _peaController);

            // This needs to be done BEFORE sprites of pea
            _pointsController.Register(pea2);
            _pointsController.Register(pea3);
            _pointsController.Register(pea4);
            _pointsController.Register(pea5);

            _achievementController.Register(pea2);
            _achievementController.Register(pea3);
            _achievementController.Register(pea4);
            _achievementController.Register(pea5);

            pea2.Initialize();
            pea3.Initialize();
            pea4.Initialize();
            pea5.Initialize();

            this.Game.Components.Add(pea2);
            this.Game.Components.Add(pea3);
            this.Game.Components.Add(pea4);
            this.Game.Components.Add(pea5);

            // Create layers
            _sceneryLayer = new SceneLayer(this.Game, _scene.Camera)
            {
                MoveSpeed = 0f, Distance = 0.9f
            };
            _levelLayer = new SceneLayer(this.Game, _scene.Camera)
            {
                MoveSpeed = 0f, Distance = 0.6f
            };
            _peasLayer = new SceneLayer(this.Game, _scene.Camera)
            {
                MoveSpeed = 0f, Distance = 0.3f
            };
            _hudLayer = new SceneLayer(this.Game, _scene.Camera)
            {
                MoveSpeed = 0f, Distance = 0.1f
            };

            // Create sprites
            _spriteGrid = new SpritesetGrid(_levelLayer)
            {
                Position = Vector2.UnitX * (_width - DataGrid.WidthInPixels) / 2f + Vector2.UnitY * 150
            };
            SpritePea.BaseOffset = _spriteGrid.Position;

            _peasLayer.Add(new SpritePea(_peasLayer, pea1, _pointsController));

#if !DEBUG || !TEST
            _peasLayer.Add(new SpritePea(_peasLayer, pea2, _pointsController));
            _peasLayer.Add(new SpritePea(_peasLayer, pea3, _pointsController));
            _peasLayer.Add(new SpritePea(_peasLayer, pea4, _pointsController));
            _peasLayer.Add(new SpritePea(_peasLayer, pea5, _pointsController));
#endif

#if DEBUG && TEST
            for (int i = 0; i < DataGrid.Width; i++)
            {
                if (new int[] { 3, 4, 5, 10, 12, 14 }.Contains(i) == false)
                {
                    DataBlock b = _dataGrid.Add(new Point(i, DataGrid.Height - 1), BlockType.Normal);
                    //_spriteGrid.Add(new SpriteBlock(_levelLayer, b));

                    if (new int[] { 0, 1, 2, 5, 8, 15 }.Contains(i))
                    {
                        b = _dataGrid.Add(new Point(i, DataGrid.Height - 2), BlockType.Normal);
                        //_spriteGrid.Add(new SpriteBlock(_levelLayer, b));
                    }

                    if (new int[] { 0, 15 }.Contains(i))
                    {
                        b = _dataGrid.Add(new Point(i, DataGrid.Height - 3), BlockType.Gel);
                        //_spriteGrid.Add(new SpriteBlock(_levelLayer, b));
                    }

                    if (new int[] { 0, 15 }.Contains(i))
                    {
                        b = _dataGrid.Add(new Point(i, DataGrid.Height - 4), BlockType.Gel);
                        //_spriteGrid.Add(new SpriteBlock(_levelLayer, b));
                    }
                }
            }


            DataBlock jump = _dataGrid.Add(new Point(3, 7), BlockType.Normal);
            //_spriteGrid.Add(new SpriteBlock(_levelLayer, jump));

            DataBlock ramp = _dataGrid.Add(new Point(1, 8), BlockType.RightRamp);
            //_spriteGrid.Add(new SpriteBlock(_levelLayer, ramp));

            //DataBlock gel = _dataGrid.Add(new Point(5, 10), BlockType.LeftRamp);
            //_spriteGrid.Add(new SpriteBlock(_levelLayer, gel));
#else
            // Some boundary blocks
            _dataGrid.Add(new Point(0, DataGrid.Height - 1), BlockType.Gel);
            _dataGrid.Add(new Point(DataGrid.Width - 1, DataGrid.Height - 1), BlockType.Gel);
            _dataGrid.Add(new Point(0, DataGrid.Height - 2), BlockType.Gel);
            _dataGrid.Add(new Point(DataGrid.Width - 1, DataGrid.Height - 2), BlockType.Gel);
#endif

            SpriteToolbox toolbox = new SpriteToolbox(_hudLayer)
            {
                Position = new Vector2(_width - (1280 - 1220),
                                       (Single)Math.Ceiling(150 * (_height / 720f)))
            };
            SpritesetHud hud = new SpritesetHud(_hudLayer, _pointsController, _inputController.State, _width, _height);


            // Register sprites at inputControllers
            _inputController.Register(_spriteGrid);
            _inputController.Register(toolbox);
            _inputController.Register(_camera, _width, _height);

            foreach (var blockRow in _dataGrid.Grid)
            {
                foreach (var block in blockRow)
                {
                    block.Place(block.BlockType, BlockState.Placed); // Direct placing;
                    _spriteGrid.Add(new SpriteBlock(_levelLayer, block));
                }
            }

            // Add the layers
            _scene.Add(_sceneryLayer);
            _scene.Add(_levelLayer);
            _scene.Add(_peasLayer);
            _scene.Add(_hudLayer);

            // Add the content
            Sprite background = new Sprite(_sceneryLayer, "Graphics/Background");
            background.Position = new Vector2(_width / 2f, _height / 2f);
            background.Origin   = new Vector2(1280f / 2f, 720f / 2f);
            background.Scale    = Math.Max(_width / 1280f, _height / 720f);

            Sprite splate = new Sprite(_sceneryLayer, "Graphics/Plate");
            splate.Position = new Vector2(_width / 2f, _height / 2f);
            splate.Origin   = new Vector2(1280f / 2f, 720f / 2f);
            splate.Scale    = Math.Max(_width / 1280f, _height / 720f);

            _sceneryLayer.Add(background);
            _sceneryLayer.Add(splate);
            _levelLayer.Add(_spriteGrid);
            _hudLayer.Add(toolbox);
            _hudLayer.Add(hud);

            // Bottom plate physics
            var plate = FixtureFactory.AttachRectangle(ConvertUnits.ToSimUnits(_width), ConvertUnits.ToSimUnits(20), 1f,
                                                       ConvertUnits.ToSimUnits(Vector2.UnitY * (49 * (DataGrid.Height - 3) + _spriteGrid.Position.Y + 5) + (_width / 2 - _spriteGrid.Position.X) * Vector2.UnitX), _fxStaticBody);
            plate.Restitution = 0;
            plate.Friction    = 0.5f;

            // Initializes scene and so on
            base.Initialize();

            _scene.Initialize();
            _camera.Position   = new Vector2(_width / 2f, _height / 2f);
            _fxcamera.Position = new Vector2(_width / 2f, _height / 2f) - _spriteGrid.Position; // + ConvertUnits.ToSimUnits(_spriteGrid.Position);
            _camera.Jump2Target();
            _fxcamera.Jump2Target();

            #if DEBUG && !SILVERLIGHT
            view = new DebugViewXNA(_fx);
            view.AppendFlags(FarseerPhysics.DebugViewFlags.CenterOfMass | FarseerPhysics.DebugViewFlags.DebugPanel | FarseerPhysics.DebugViewFlags.PerformanceGraph | FarseerPhysics.DebugViewFlags.PolygonPoints);
            #endif
            // Add components
            this.Game.Components.Add(_peaController);
            this.Game.Components.Add(_timeController);
            this.Game.Components.Add(_inputController);
            this.Game.Components.Add(_pointsController);
            this.Game.Components.Add(_achievementController);
            this.Game.Components.Add(_camera);
            this.Game.Components.Add(_fxcamera);
            this.Game.Components.Add(_dataGrid);
            this.Game.Components.Add(_scene);

            // Add popups
            _achievementController.OnCompletedAchievement += new AchievementCompletedHandler(_achievementController_OnCompletedAchievement);

            // Add overlay
            _overlay          = new PauseOverlay(_camera, _width, _height);
            _overlay.Exiting += new EventHandler(_overlay_Exiting);

            // Events
            this.Exited           += new EventHandler(PeaScreen_Exited);
            this.OnEnabledChanged += new BooleanDelegate(PeaScreen_OnEnabledChanged);
            this.OnVisibleChanged += new BooleanDelegate(PeaScreen_OnVisibleChanged);

            // Add end
            _pointsController.OnReachedGoal += new Action(_pointsController_OnReachedGoal);

            this.IsEnabled = false;
            this.IsVisible = false;
        }
Exemplo n.º 11
0
 // Use this for initialization
 void Start()
 {
     col = Map.Instance.Collision;
     col.Add(Map.Instance.Terrain.WorldToCell(transform.position), type);
 }