/// <summary>
        /// Update and refresh holder every time multiple new units are selected
        /// </summary>
        /// <param name="holder"></param>
        /// <param name="e"></param>
        private void updateHolder(SameSizeChildrenFlowLayout holder, SelectionStateChangedArgs e)
        {
            int count = e.SelectedEntities.Count;

            if (holder != null)
            {
                holder.Clear();
                if (count > 1)
                {
                    holder.Visible = true;
                    foreach (ModelComponent component in e.SelectedEntities)
                    {
                        BuildSelectedEntityUIVisitor visitor = new BuildSelectedEntityUIVisitor();
                        if (component is UnitComponent)
                        {
                            UnitComponent temp = (UnitComponent)component;

                            component.Accept(visitor);
                            if (visitor.UI != null)
                            {
                                holder.AddChild(visitor.UI);
                            }
                        }
                    } //for
                }     //if
            }         //if
        }
        /// <summary>
        /// Update and refresh holder every time multiple new units are selected
        /// </summary>
        /// <param name="holder"></param>
        /// <param name="e"></param>
        private void updateHolder(SameSizeChildrenFlowLayout holder, SelectionStateChangedArgs e)
        {
            int count = e.SelectedEntities.Count;
            if (holder != null)
            {
                holder.Clear();
                if (count > 1)
                {
                    holder.Visible = true;
                    foreach (ModelComponent component in e.SelectedEntities)
                    {
                        BuildSelectedEntityUIVisitor visitor = new BuildSelectedEntityUIVisitor();
                        if (component is UnitComponent)
                        {
                            UnitComponent temp = (UnitComponent)component;

                            component.Accept(visitor);
                            if (visitor.UI != null)
                            {
                                holder.AddChild(visitor.UI);
                            }

                        }
                    }//for
                }//if
            }//if
        }
Esempio n. 3
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);
        }
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="game">game object</param>
        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.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);
        }