public void LoadButtons(GraphicsDevice graphicsDevice_, GameContent content_) { Buttons[0] = new Button(content_.GetUiTexture(7), content_.GetFont(1)) { Position = new Vector2(Rectangle.X + 8, Rectangle.Y + 8) }; Buttons[0].Click += delegate { if (SelectionIndex.X > 0) { SelectionIndex -= new Vector2(1, 1); } }; Buttons[1] = new Button(content_.GetUiTexture(7), content_.GetFont(1)) { Position = new Vector2((Rectangle.X + 40) + (32 * 7) + (8 * 8), Rectangle.Y + 8), IsFlipped = true }; Buttons[1].Click += delegate { if (SelectionIndex.Y < Items.Count) { SelectionIndex += new Vector2(1, 1); } }; }
public GamePad(GraphicsDevice graphicsDevice_, GameContent content_) { _graphicsDevice = graphicsDevice_; _content = content_; _texture = _content.GetUiTexture(41); _textureRotated = _content.GetUiTexture(43); _gamepadDisplayOrigin = new Vector2(0, (int)((_graphicsDevice.Viewport.Height / 2) - (_textureDisplayDimension * 1.25))); }
public SpeechBubble(GameContent content_, int iconIndex_, Vector2 position_) { Content = content_; BubbleSprite = Content.GetUiTexture(2); IconIndex = iconIndex_; Position = position_; }
public EditMapsListState(GameInstance game, GraphicsDevice graphicsDevice, ContentManager content) : base(game, graphicsDevice, content) { _gameContent = new GameContent(content); // load maps LoadMaps(); int x = 50; int y = 50; int i = 0; // loop through each loaded map foreach (List <TileData> map in _maps) { var button = new Button(_gameContent.GetUiTexture(1), _gameContent.GetFont(1)) { Position = new Vector2(x, y + (100 * i)), Text = "Map " + (i + 1).ToString(), HoverColor = Color.Red }; button.Click += delegate { Console.WriteLine($"Map {i + 1} clicked"); Map_Click(map); }; _components.Add(button); i++; } }
public DebugMenu(GraphicsDevice graphicsDevice_, GameContent content_) { int height_ = 48; int width_ = 780; Position = new Vector2(10, 10); _displaySize = new Vector2(width_, height_); Console.WriteLine($"Debug Menu Created:>"); Console.WriteLine($"Size: {_displaySize}"); Console.WriteLine($"Position: {Position}"); SetColorData(graphicsDevice_); _content = content_; _font = _content.GetFont(1); LoadItemsMenu(graphicsDevice_); Button btn = new Button(_content.GetUiTexture(1), _content.GetFont(1)) { Position = new Vector2(SelectMenu.Position.X + SelectMenu.Rectangle.Width + 56, Position.Y + 8), Text = "SAVE MAP" }; btn.Click += delegate { Console.WriteLine("Saving Map..."); GameState.SaveMap(); }; Components.Add(btn); }
public void LoadContent(GameContent Content) { selectCursor.PlayAnimation(new Animation(Content.GetUiTexture(5), 0.1f, true)); /*** * technically you could have the sprite loaded based on custom input, if you have more than 1 character made * and you could load the sprites dynamically like this * int sprite_index = 1; * string spriteSouthWest = "0" + sprite_index + "_SouthWest"; * southWestBodyAnimation = new Animation(Content.Load<Texture2D>("Sprites/Characters/Body/"+spriteSouthWest), 0.13f, true); ***/ // Load the spritesheet for each direction southWestBodyAnimation = new Animation(Content.GetBodyTexture(1), 0.15f, true); southEastBodyAnimation = new Animation(Content.GetBodyTexture(2), 0.15f, true); northWestBodyAnimation = new Animation(Content.GetBodyTexture(3), 0.15f, true); northEastBodyAnimation = new Animation(Content.GetBodyTexture(4), 0.15f, true); // load the head spritesheet headAnimation = new Animation(Content.GetHeadTexture(2), 0.1f, false); // set the animation to be still for the head, so we can load each frame in it individually headAnimation.IsStill = true; footstep = Content.GetSoundEffect(1); // Calculate bounds within texture size. int width = (int)(southWestBodyAnimation.FrameWidth * 0.4); int left = (southWestBodyAnimation.FrameWidth - width) / 2; int height = (int)(southWestBodyAnimation.FrameWidth * 0.8); int top = southWestBodyAnimation.FrameHeight - height; localBounds = new Rectangle(left, top, width, height); }
public DialogWindow(string text_, Vector2 pos_, GraphicsDevice gd_, SpriteFont font_, GameContent content_, Texture2D txt_ = null) { // get required arguments from constructor Text = text_; _graphicsDevice = gd_; _font = font_; _gameContent = content_; // calculate texture of dialog window shadow _shadowTexture = new Texture2D(_graphicsDevice, (int)Dimensions.X, (int)Dimensions.Y); var u = new Color[(int)Dimensions.X * (int)Dimensions.Y]; for (int i = 0; i < u.Length; i++) { u[i] = Color.Black; } _shadowTexture.SetData(u); // check if custom texture supplied if (txt_ != null) { _texture = txt_; } else { // calculate default texture for dialog window _texture = new Texture2D(_graphicsDevice, (int)Dimensions.X, (int)Dimensions.Y); var o = new Color[(int)Dimensions.X * (int)Dimensions.Y]; for (int i = 0; i < o.Length; i++) { o[i] = Color.DarkKhaki; } _texture.SetData(o); } // Calculate position Position = new Vector2( (_graphicsDevice.Viewport.Width / 2) - (Rectangle.Width / 2), (_graphicsDevice.Viewport.Height / 2) - (Rectangle.Height / 2) ); // get close button texture _closeButtonTexture = _gameContent.GetUiTexture(38); CloseButton = new Button(_closeButtonTexture, _font) { Position = CloseButtonPosition, HoverColor = Color.Red }; CloseButton.CustomRect = new Rectangle( (int)CloseButton.Position.X, (int)CloseButton.Position.Y, _closeButtonTexture.Width * 5, _closeButtonTexture.Height * 5); CloseButton.Click += CloseButton_Click; }
public HUD(GraphicsDevice graphicsDevice_, GameContent content_) { _graphicsDevice = graphicsDevice_; int height = (int)(graphicsDevice_.Viewport.Height * 0.25f); int width = (int)(graphicsDevice_.Viewport.Width); _position = new Vector2(0, graphicsDevice_.Viewport.Height - height); _displaySize = new Vector2(width, height); _buttonSize = new Vector2(30, height * 0.8f); Console.WriteLine("HUD created."); Console.WriteLine($"HUD Size: {_displaySize}"); Console.WriteLine($"HUD Pos: {_position}"); _content = content_; _font = _content.GetFont(1); HUDIconIDs = new int[] { 5, 6, 7, 8, 12, 9, 10, 11 }; SetColorData(graphicsDevice_); DisplayInfo_Texture = content_.GetUiTexture(37); for (int i = (int)SelectionCells_BuildingIndexes.X; i < SelectionCells_BuildingIndexes.Y; i++) { SelectionCells_BuildingTextures.Add(content_.GetUiTexture(i)); } SelectionCells_BuildingTextures.Add(content_.GetUiTexture(24)); SelectionCells_BuildingTextures.Add(content_.GetUiTexture(25)); if (SelectionCells_BuildingTextures.Count < (SelectionCell_GridDimensions.X * SelectionCell_GridDimensions.Y)) { var dif = (SelectionCell_GridDimensions.X * SelectionCell_GridDimensions.Y) - SelectionCells_BuildingTextures.Count; for (int i = 0; i < dif + 1; i++) { SelectionCells_BuildingTextures.Add(SelectionCells_BuildingTextures[0]); } } SelectionCell_BlankTexture = content_.GetUiTexture(13); foreach (var e in SelectionCells_BldgHouses_Indexes) { SelectionCells_BldgHouses_Textures.Add(content_.GetUiTexture(e)); } foreach (var e in SelectionCells_BldgReso_Indexes) { SelectionCells_BldgReso_Textures.Add(content_.GetUiTexture(e)); } foreach (var e in SelectionCells_BldgDeco_Indexes) { SelectionCells_BldgDeco_Textures.Add(content_.GetUiTexture(e)); } foreach (var e in SelectionCells_AllBldgs_Textures) { if (e.Count < (SelectionCell_GridDimensions.X * SelectionCell_GridDimensions.Y)) { var dif = (SelectionCell_GridDimensions.X * SelectionCell_GridDimensions.Y) - e.Count; for (int i = 0; i < dif + 1; i++) { e.Add(SelectionCell_BlankTexture); } } } SetSelectionCellButtons(); // get textures for buttons that swap between building selections Btn_SelectHouses_Texture = content_.GetUiTexture(26); Btn_SelectReso_Texture = content_.GetUiTexture(27); Btn_SelectDeco_Texture = content_.GetUiTexture(28); var init_btn_bldg_pos = new Vector2(); init_btn_bldg_pos.X = (ResourceBar_Rectangle.X + ResourceBar_Rectangle.Width) - (Btn_SelectHouses_Texture.Width); init_btn_bldg_pos.Y = (ResourceBar_Rectangle.Y - (Btn_SelectHouses_Texture.Height * 3.5f)); var btn_bldgs_house = new Button(Btn_SelectHouses_Texture, _font) { Position = init_btn_bldg_pos, ID = 800 }; btn_bldgs_house.Click += ViewBldgsBtn_OnClick; var btn_bldgs_reso = new Button(Btn_SelectReso_Texture, _font) { Position = init_btn_bldg_pos + new Vector2(0, Btn_SelectHouses_Texture.Height * 1.18f), ID = 801 }; btn_bldgs_reso.Click += ViewBldgsBtn_OnClick; var btn_bldgs_deco = new Button(Btn_SelectDeco_Texture, _font) { Position = init_btn_bldg_pos + new Vector2(0, ((Btn_SelectHouses_Texture.Height * 1.18f) * 2f)), ID = 802 }; btn_bldgs_deco.Click += ViewBldgsBtn_OnClick; _components.Add(btn_bldgs_house); _components.Add(btn_bldgs_reso); _components.Add(btn_bldgs_deco); BtnList_SelectBldgsView.Add(btn_bldgs_house); BtnList_SelectBldgsView.Add(btn_bldgs_reso); BtnList_SelectBldgsView.Add(btn_bldgs_deco); DeleteBuildingBtn_Texture = content_.GetUiTexture(23); DeleteBuildingBtn_Pos = new Vector2( (int)(DisplayInfo_Rectangle.X + DisplayInfo_Rectangle.Width - DeleteBuildingBtn_Texture.Width - ((DisplayInfo_Rectangle.Width * 0.05f) / 2)), (int)(DisplayInfo_Rectangle.Y + (DisplayInfo_Rectangle.Height * 0.05f))); DeleteBuildingBtn = new Button(content_.GetUiTexture(23), _font) { Position = DeleteBuildingBtn_Pos, HoverColor = Color.Red }; DeleteBuildingBtn.Click += DeleteBuildingBtnOnClick; }
public TopBar(GraphicsDevice graphicsDevice_, GameContent content_) { // get required arguments _gameContent = content_; _graphicsDevice = graphicsDevice_; // set display dimensions _displayDimensions = new Vector2(_graphicsDevice.Viewport.Width, _graphicsDevice.Viewport.Height * 0.09f); // calculate texture data(s) _displayTexture = new Texture2D(_graphicsDevice, (int)_displayDimensions.X, (int)_displayDimensions.Y); var o = new Color[(int)_displayDimensions.X * (int)_displayDimensions.Y]; for (var i = 0; i < o.Length; i++) { o[i] = _displayColor; } _displayTexture.SetData(o); _borderTexture = new Texture2D(_graphicsDevice, (int)_borderDimensions.X, (int)_borderDimensions.Y); var e = new Color[(int)_borderDimensions.X * (int)_borderDimensions.Y]; for (var i = 0; i < e.Length; i++) { e[i] = _borderColor; } _borderTexture.SetData(e); _resourceAreaTexture = _gameContent.GetUiTexture(29); _font = _gameContent.GetFont(1); // calculate icon rects var icon_start = new Vector2(_resourceIconsAreaRectangle.X, 0); for (var i = 0; i < _resourceIconIDs.Length; i++) { var icon_id = _resourceIconIDs[i]; var icon_txt = _gameContent.GetUiTexture(icon_id); var icon_pos = icon_start + new Vector2(_resourceIconDisplayDimension.X * i, 0); var icon_rect = new Rectangle((int)icon_pos.X, (int)icon_pos.Y, (int)_resourceIconDisplayDimension.X, (int)_resourceIconDisplayDimension.Y); var icon_print_rect = new Rectangle( (int)(icon_rect.X + ((icon_rect.Width / 2) - (icon_rect.Width / 8))), (int)(icon_rect.Y + (icon_rect.Height / 7)), (int)(icon_rect.Width / 4), (int)((icon_rect.Width / 4) * icon_txt.Height / icon_txt.Width) ); var text_origin = new Vector2( icon_rect.X + (icon_rect.Width / 2), icon_rect.Y + (icon_rect.Height)); _resourceTopBarIcons.Add(new TopBarIcon() { Texture = icon_txt, Rect = icon_print_rect, Index = i, TextOrigin = text_origin }); } }
public HUD(GraphicsDevice graphicsDevice_, GameContent content_) { _graphicsDevice = graphicsDevice_; int height = (int)(graphicsDevice_.Viewport.Height * 0.25f); int width = (int)(graphicsDevice_.Viewport.Width); _position = new Vector2(0, graphicsDevice_.Viewport.Height - height); _startPosition = new Vector2(0, graphicsDevice_.Viewport.Height - height); _displaySize = new Vector2(width, height); _buttonSize = new Vector2(30, height * 0.8f); Log.Info("CitySim", "HUD created."); Log.Info("CitySim", $"HUD Size: {_displaySize}"); Log.Info("CitySim", $"HUD Pos: {_position}"); _content = content_; _font = _content.GetFont(1); HUDIconIDs = new int[] { 5, 6, 7, 8, 12, 9, 10, 11 }; SetColorData(graphicsDevice_); DisplayInfo_Texture = content_.GetUiTexture(37); for (int i = (int)SelectionCells_BuildingIndexes.X; i < SelectionCells_BuildingIndexes.Y; i++) { SelectionCells_BuildingTextures.Add(content_.GetUiTexture(i)); } SelectionCells_BuildingTextures.Add(content_.GetUiTexture(24)); SelectionCells_BuildingTextures.Add(content_.GetUiTexture(25)); if (SelectionCells_BuildingTextures.Count < (SelectionCell_GridDimensions.X * SelectionCell_GridDimensions.Y)) { var dif = (SelectionCell_GridDimensions.X * SelectionCell_GridDimensions.Y) - SelectionCells_BuildingTextures.Count; for (int i = 0; i < dif + 1; i++) { SelectionCells_BuildingTextures.Add(SelectionCells_BuildingTextures[0]); } } SelectionCell_BlankTexture = content_.GetUiTexture(13); foreach (var e in SelectionCells_BldgHouses_Indexes) { SelectionCells_BldgHouses_Textures.Add(content_.GetUiTexture(e)); } foreach (var e in SelectionCells_BldgReso_Indexes) { SelectionCells_BldgReso_Textures.Add(content_.GetUiTexture(e)); } foreach (var e in SelectionCells_BldgDeco_Indexes) { SelectionCells_BldgDeco_Textures.Add(content_.GetUiTexture(e)); } foreach (var e in SelectionCells_AllBldgs_Textures) { if (e.Count < (SelectionCell_GridDimensions.X * SelectionCell_GridDimensions.Y)) { var dif = (SelectionCell_GridDimensions.X * SelectionCell_GridDimensions.Y) - e.Count; for (int i = 0; i < dif + 1; i++) { e.Add(SelectionCell_BlankTexture); } } } SetSelectionCellButtons(); // get textures for buttons that swap between building selections Btn_SelectHouses_Texture = content_.GetUiTexture(26); Btn_SelectReso_Texture = content_.GetUiTexture(27); Btn_SelectDeco_Texture = content_.GetUiTexture(28); Btn_HideHUD_Texture = content_.GetUiTexture(40); var init_btn_bldg_pos = new Vector2(); init_btn_bldg_pos.X = _displaySize.X - ((Btn_SelectHouses_Texture.Width * 5) * 4) - 10; init_btn_bldg_pos.Y = DisplayRect.Y - (Btn_SelectHouses_Texture.Height * 5) - 10; Btn_SelectHouses = new Button(Btn_SelectHouses_Texture, _font) { Position = init_btn_bldg_pos, ID = 800, }; Btn_SelectHouses.CustomRect = new Rectangle( (int)Btn_SelectHouses.Position.X, (int)Btn_SelectHouses.Position.Y, Btn_SelectHouses_Texture.Width * 5, Btn_SelectHouses_Texture.Height * 5 ); Btn_SelectHouses.Click += ViewBldgsBtn_OnClick; Btn_SelectReso = new Button(Btn_SelectReso_Texture, _font) { Position = init_btn_bldg_pos + new Vector2(Btn_SelectHouses_Texture.Width * 5f, 0), ID = 801, }; Btn_SelectReso.CustomRect = new Rectangle( (int)Btn_SelectReso.Position.X, (int)Btn_SelectReso.Position.Y, Btn_SelectHouses_Texture.Width * 5, Btn_SelectHouses_Texture.Height * 5 ); Btn_SelectReso.Click += ViewBldgsBtn_OnClick; Btn_SelectDeco = new Button(Btn_SelectDeco_Texture, _font) { Position = init_btn_bldg_pos + new Vector2(((Btn_SelectHouses_Texture.Width * 5f) * 2f), 0), ID = 802, }; Btn_SelectDeco.CustomRect = new Rectangle( (int)Btn_SelectDeco.Position.X, (int)Btn_SelectDeco.Position.Y, Btn_SelectHouses_Texture.Width * 5, Btn_SelectHouses_Texture.Height * 5 ); Btn_SelectDeco.Click += ViewBldgsBtn_OnClick; _closeMenuButton = new Button(Btn_HideHUD_Texture, _font) { Position = init_btn_bldg_pos + new Vector2(((Btn_SelectHouses_Texture.Width * 5f) * 3f), 0), ID = 803, IsFlippedVert = true }; _closeMenuButton.CustomRect = new Rectangle( (int)_closeMenuButton.Position.X, (int)_closeMenuButton.Position.Y, Btn_SelectHouses_Texture.Width * 5, Btn_SelectHouses_Texture.Height * 5 ); _closeMenuButton.Click += Btn_hide_hud_Click; BtnList_SelectBldgsView.Add(Btn_SelectHouses); BtnList_SelectBldgsView.Add(Btn_SelectReso); BtnList_SelectBldgsView.Add(Btn_SelectDeco); DeleteBuildingBtn_Texture = content_.GetUiTexture(23); DeleteBuildingBtn_Pos = new Vector2( (int)(DisplayInfo_Rectangle.X + DisplayInfo_Rectangle.Width - DeleteBuildingBtn_Texture.Width - ((DisplayInfo_Rectangle.Width * 0.05f) / 2)), (int)(DisplayInfo_Rectangle.Y + (DisplayInfo_Rectangle.Height * 0.05f))); DeleteBuildingBtn = new Button(content_.GetUiTexture(23), _font) { Position = DeleteBuildingBtn_Pos, HoverColor = Color.Red }; DeleteBuildingBtn.Click += DeleteBuildingBtnOnClick; }