/// <summary>
 /// Initialize game
 /// </summary>
 /// <param name="game">game</param>
 public static void Initialize(Game game)
 {
     if (instance == null)
     {
         instance = new ZRTSCompositeViewUIFactory(game);
     }
 }
Example #2
0
 public static void Initialize(Game game)
 {
     if (instance == null)
     {
         instance = new ZRTSCompositeViewUIFactory(game);
     }
 }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="mapView">View of the map</param>
        /// <param name="buildingType">Building Type</param>
        public BuildBuildingMapViewLeftClickStrategy(MapView mapView, string buildingType)
        {
            this.mapView      = mapView;
            this.buildingType = buildingType;
            ZRTSCompositeViewUIFactory factory = ZRTSCompositeViewUIFactory.Instance;

            building = factory.BuildPictureBox(buildingType, "mapView");
            int width  = ZRTSModel.Factories.BuildingFactory.Instance.getStats(buildingType).width;
            int height = ZRTSModel.Factories.BuildingFactory.Instance.getStats(buildingType).height;

            // TODO: replace "2" with stats from the building factory.
            building.DrawBox  = new Microsoft.Xna.Framework.Rectangle(0, 0, width * GameConfig.TILE_DIM, height * GameConfig.TILE_DIM);
            building.OnClick += placeBuilding;
        }
Example #4
0
        public CommandView(Game game)
            : base(game)
        {
            this.DrawBox = new Rectangle(0, 0, 275, 275);


            // Background Panel
            backgroundPanel         = new PictureBox(game, new Rectangle(GameConfig.BUILDPANEL_START_X, GameConfig.BUILDING_START_Y, 275, 275));
            backgroundPanel.DrawBox = new Rectangle(0, 0, 275, 275);
            AddChild(backgroundPanel);

            // buildPanel
            buildPanel                = new SameSizeChildrenFlowLayout(game);
            buildPanel.Visible        = false;
            buildPanel.DrawBox        = new Rectangle(10, 10, 255, 255);
            buildPanel.SpacingBetween = 7;
            AddChild(buildPanel);

            // mainPanel
            mainPanel                = new SameSizeChildrenFlowLayout(game);
            mainPanel.DrawBox        = new Rectangle(10, 10, 255, 255);
            mainPanel.SpacingBetween = 7;
            AddChild(mainPanel);

            // WorkerPanel
            workerPanel                = new SameSizeChildrenFlowLayout(game);
            workerPanel.DrawBox        = new Rectangle(10, 10, 255, 255);
            workerPanel.SpacingBetween = 7;
            AddChild(workerPanel);


            // Barrack building commandPanel
            barracksPanel                = new SameSizeChildrenFlowLayout(game);
            barracksPanel.DrawBox        = new Rectangle(10, 10, 255, 255);
            barracksPanel.Visible        = false;
            barracksPanel.SpacingBetween = 7;
            AddChild(barracksPanel);

            // HouseBuilding commandPanel
            housePanel                = new SameSizeChildrenFlowLayout(game);
            housePanel.DrawBox        = new Rectangle(10, 10, 255, 255);
            housePanel.SpacingBetween = 7;
            housePanel.Visible        = false;
            AddChild(housePanel);



            ZRTSCompositeViewUIFactory factory = ZRTSCompositeViewUIFactory.Instance;

            moveButton               = factory.BuildPictureBox("button", "move");
            moveButton.DrawBox       = new Rectangle(0, 0, GameConfig.BUTTON_DIM, GameConfig.BUTTON_DIM);
            moveButton.OnClick      += handleMoveButtonClick;
            moveButton.OnMouseEnter += handleMoveButtonOver;
            moveButton.OnMouseLeave += handleMoveButtonAway;
            moveButton.OnMouseDown  += handleMoveButtonDown;
            moveButton.OnMouseUp    += handleMoveButtonUp;
            workerPanel.AddChild(moveButton);

            mainMoveButton               = factory.BuildPictureBox("button", "move");
            mainMoveButton.DrawBox       = new Rectangle(0, 0, GameConfig.BUTTON_DIM, GameConfig.BUTTON_DIM);
            mainMoveButton.OnClick      += handleMoveButtonClick;
            mainMoveButton.OnMouseEnter += handleMoveButtonOver;
            mainMoveButton.OnMouseLeave += handleMoveButtonAway;
            mainMoveButton.OnMouseDown  += handleMoveButtonDown;
            mainMoveButton.OnMouseUp    += handleMoveButtonUp;
            mainPanel.AddChild(mainMoveButton);

            stopButton               = factory.BuildPictureBox("button", "stop");
            stopButton.DrawBox       = new Rectangle(0, 0, GameConfig.BUTTON_DIM, GameConfig.BUTTON_DIM);
            stopButton.OnClick      += handleStopButtonClick;
            stopButton.OnMouseEnter += handleStopButtonOver;
            stopButton.OnMouseLeave += handleStopButtonAway;
            stopButton.OnMouseDown  += handleStopButtonDown;
            stopButton.OnMouseUp    += handleStopButtonUp;
            workerPanel.AddChild(stopButton);

            mainStopButton               = factory.BuildPictureBox("button", "stop");
            mainStopButton.DrawBox       = new Rectangle(0, 0, GameConfig.BUTTON_DIM, GameConfig.BUTTON_DIM);
            mainStopButton.OnClick      += handleStopButtonClick;
            mainStopButton.OnMouseEnter += handleStopButtonOver;
            mainStopButton.OnMouseLeave += handleStopButtonAway;
            mainStopButton.OnMouseDown  += handleStopButtonDown;
            mainStopButton.OnMouseUp    += handleStopButtonUp;
            mainPanel.AddChild(mainStopButton);

            buildButton               = factory.BuildPictureBox("button", "build");
            buildButton.DrawBox       = new Rectangle(GameConfig.BUTTON_BUILD * GameConfig.BUTTON_DIM, GameConfig.BUTTON_START_Y_SECOND, GameConfig.BUTTON_DIM, GameConfig.BUTTON_DIM);
            buildButton.OnClick      += handleBuildButtonClick;
            buildButton.OnMouseEnter += handleBuildButtonOver;
            buildButton.OnMouseLeave += handleBuildButtonAway;
            buildButton.OnMouseDown  += handleBuildButtonDown;
            buildButton.OnMouseUp    += handleBuildButtonUp;
            workerPanel.AddChild(buildButton);

            attackButton               = factory.BuildPictureBox("button", "attack");
            attackButton.DrawBox       = new Rectangle(GameConfig.BUTTON_ATTACK * GameConfig.BUTTON_DIM, GameConfig.BUTTON_START_Y, GameConfig.BUTTON_DIM, GameConfig.BUTTON_DIM);
            attackButton.OnClick      += handleAttackButtonClick;
            attackButton.OnMouseEnter += handleAttackButtonOver;
            attackButton.OnMouseLeave += handleAttackButtonAway;
            attackButton.OnMouseDown  += handleAttackButtonDown;
            attackButton.OnMouseUp    += handleAttackButtonUp;
            workerPanel.AddChild(attackButton);

            harvestButton               = factory.BuildPictureBox("button", "harvest");
            harvestButton.DrawBox       = new Rectangle(GameConfig.BUTTON_ATTACK * GameConfig.BUTTON_DIM, GameConfig.BUTTON_START_Y, GameConfig.BUTTON_DIM, GameConfig.BUTTON_DIM);
            harvestButton.OnClick      += handleHarvestButtonClick;
            harvestButton.OnMouseEnter += handleharvestButtonOver;
            harvestButton.OnMouseLeave += handleharvestButtonAway;
            harvestButton.OnMouseDown  += handleharvestButtonDown;
            harvestButton.OnMouseUp    += handleharvestButtonUp;
            workerPanel.AddChild(harvestButton);

            mainAttackButton               = factory.BuildPictureBox("button", "attack");
            mainAttackButton.DrawBox       = new Rectangle(GameConfig.BUTTON_ATTACK * GameConfig.BUTTON_DIM, GameConfig.BUTTON_START_Y, GameConfig.BUTTON_DIM, GameConfig.BUTTON_DIM);
            mainAttackButton.OnClick      += handleAttackButtonClick;
            mainAttackButton.OnMouseEnter += handleAttackButtonOver;
            mainAttackButton.OnMouseLeave += handleAttackButtonAway;
            mainAttackButton.OnMouseDown  += handleAttackButtonDown;
            mainAttackButton.OnMouseUp    += handleAttackButtonUp;
            mainPanel.AddChild(mainAttackButton);

            mainPanel.Visible   = false;
            workerPanel.Visible = false;

            // Individual building buttons in the build panel

            List <String> buildingKeys = BuildingFactory.Instance.getBuildingTypes();

            foreach (String key in buildingKeys)
            {
                PictureBox buildingButton = factory.BuildPictureBox("building", key);
                buildingButton.OnClick += handleBuildingButtonClick;
                buildingButton.DrawBox  = new Rectangle(0, 0, 85, 85);
                buildPanel.AddChild(buildingButton);
                uiToBuildingType.Add(buildingButton, key);
            }

            // Get unit's information
            List <String> unitKeys = UnitFactory.Instance.getPrefixes();

            foreach (String key in buildingKeys)
            {
                PictureBox unitButton = null;
                if (key.Equals("barracks"))
                {
                    unitButton          = factory.BuildPictureBox("unitBuild", "soldier");
                    unitButton.OnClick += handleUnitProduceButtonClick;
                    unitButton.DrawBox  = new Rectangle(0, 0, 85, 85);
                    barracksPanel.AddChild(unitButton);
                }
                else if (key.Equals("house"))
                {
                    unitButton          = factory.BuildPictureBox("unitBuild", "worker");
                    unitButton.OnClick += handleUnitProduceButtonClick;
                    unitButton.DrawBox  = new Rectangle(0, 0, 85, 85);
                    housePanel.AddChild(unitButton);
                }

                uiToBuildingType.Add(unitButton, key);
            }


            pixel = new Texture2D(game.GraphicsDevice, 1, 1, false, SurfaceFormat.Color);
            pixel.SetData(new[] { Color.White });
            color = new Color(100, 60, 88);
        }