private SelectionState selectionState; // State of selected units by the user #endregion Fields #region Constructors /// <summary> /// Constructor /// </summary> /// <param name="game"></param> /// <param name="selectionState"></param> public SelectionView(Game game, SelectionState selectionState) : base(game) { this.selectionState = selectionState; selectionState.SelectionStateChanged += onSelectionChanged; mainBgPanel = new PictureBox(game, new Rectangle(GameConfig.MAINPANEL_START_X, GameConfig.MAINPANEL_START_Y, 730, 200)); mainBgPanel.DrawBox = new Rectangle(0, 0, 730, 200); AddChild(mainBgPanel); }
/// <summary> /// Constructor /// </summary> /// <param name="mapView">View object</param> /// <param name="buildingType">Type of the building</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; }
/// <summary> /// create a picture representation for each type /// </summary> /// <param name="type"></param> /// <param name="subtype"></param> /// <returns>PictureBox corresponding to type and subtype</returns> public PictureBox BuildPictureBox(string type, string subtype) { PictureBox pictureBox = null; // TODO: Add in logic to parse from XML that returns the appropriate rectangle from the type and subtype. if (type.Equals("button")) { if (subtype.Equals("move")) { return new PictureBox(game, new Rectangle(GameConfig.BUTTON_MOVE*GameConfig.BUTTON_DIM, GameConfig.BUTTON_START_Y, GameConfig.BUTTON_DIM, GameConfig.BUTTON_DIM)); } else if (subtype.Equals("attack")) { return new PictureBox(game, new Rectangle(GameConfig.BUTTON_ATTACK*GameConfig.BUTTON_DIM, GameConfig.BUTTON_START_Y, GameConfig.BUTTON_DIM, GameConfig.BUTTON_DIM)); } else if (subtype.Equals("build")) { return new PictureBox(game, new Rectangle(GameConfig.BUTTON_BUILD*GameConfig.BUTTON_DIM, GameConfig.BUTTON_START_Y_SECOND, GameConfig.BUTTON_DIM, GameConfig.BUTTON_DIM)); } else if (subtype.Equals("stop")) { return new PictureBox(game, new Rectangle(GameConfig.BUTTON_STOP * GameConfig.BUTTON_DIM, GameConfig.BUTTON_START_Y, GameConfig.BUTTON_DIM, GameConfig.BUTTON_DIM)); } else if (subtype.Equals("harvest")) { return new PictureBox(game, new Rectangle(GameConfig.BUTTON_HARVEST * GameConfig.BUTTON_DIM, GameConfig.BUTTON_START_Y_SECOND, GameConfig.BUTTON_DIM, GameConfig.BUTTON_DIM)); } } // Building Icon if (type.Equals("building")) { if (subtype.Equals("house")) { return new PictureBox(game, new Rectangle(1141 + GameConfig.BUTTON_DIM, 1038 + GameConfig.BUTTON_DIM, GameConfig.BUTTON_DIM, GameConfig.BUTTON_DIM)); } else if (subtype.Equals("barracks")) { return new PictureBox(game, new Rectangle(1141, 1038 + GameConfig.BUTTON_DIM, GameConfig.BUTTON_DIM, GameConfig.BUTTON_DIM)); } else if (subtype.Equals("hospital")) { return new PictureBox(game, new Rectangle(1141 + GameConfig.BUTTON_DIM*2, 1038 + GameConfig.BUTTON_DIM, GameConfig.BUTTON_DIM, GameConfig.BUTTON_DIM)); } } // UnitIcon if (type.Equals("unitBuild")) { if (subtype.Equals("soldier")) { return new PictureBox(game, new Rectangle(1141, 1038, GameConfig.BUTTON_DIM, GameConfig.BUTTON_DIM )); } else if (subtype.Equals("worker")) { return new PictureBox(game, new Rectangle(1141 + GameConfig.BUTTON_DIM, 1038, GameConfig.BUTTON_DIM, GameConfig.BUTTON_DIM)); } } // Selection Avator if (type.Equals("selectionAvatar")) { if (subtype.Equals("soldier")) { return new PictureBox(game, new Rectangle(0, GameConfig.SELECT_AVATAR_START_Y, GameConfig.BUTTON_UNIT_DIM, GameConfig.BUTTON_UNIT_DIM)); } else if (subtype.Equals("worker")) { return new PictureBox(game, new Rectangle(77, GameConfig.SELECT_AVATAR_START_Y, GameConfig.BUTTON_UNIT_DIM, GameConfig.BUTTON_UNIT_DIM)); } } // Big Avator if (type.Equals("bigAvatar")) { if (subtype.Equals("soldier")) { return new PictureBox(game, new Rectangle(0, GameConfig.BIG_AVATAR_START_Y, 140, 152)); } else if (subtype.Equals("worker")) { return new PictureBox(game, new Rectangle(140, GameConfig.BIG_AVATAR_START_Y, 140, 152)); } } else pictureBox = new PictureBox(game, new Rectangle(0, 0, 1, 1)); return pictureBox; }
/// <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); }