示例#1
0
        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;
        }
示例#2
0
        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;
        }