diff --git a/DangerousD/GameCore/GUI/DeathGUI.cs b/DangerousD/GameCore/GUI/DeathGUI.cs index 5754efa..c19f9b5 100644 --- a/DangerousD/GameCore/GUI/DeathGUI.cs +++ b/DangerousD/GameCore/GUI/DeathGUI.cs @@ -13,6 +13,7 @@ internal class DeathGUI : AbstractGui { int wigth = AppManager.Instance.inGameResolution.X; int height = AppManager.Instance.inGameResolution.Y; + float scaler = AppManager.Instance.resolution.Y / (float)AppManager.Instance.inGameHUDHelperResolution.Y; var menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, wigth, height), textureName = "deathBackground" }; Elements.Add(menuBackground); menuBackground.LoadTexture(AppManager.Instance.Content); @@ -24,6 +25,17 @@ internal class DeathGUI : AbstractGui { AppManager.Instance.ChangeGameState(GameState.Menu); }; + foreach (var item in Elements) + { + item.rectangle.X = (int)(scaler * item.rectangle.X); + item.rectangle.Y = (int)(scaler * item.rectangle.Y); + item.rectangle.Width = (int)(scaler * item.rectangle.Width); + item.rectangle.Height = (int)(scaler * item.rectangle.Height); + if (item is DrawableTextedUiElement) + { + (item as DrawableTextedUiElement).scale *= scaler; + } + } } public override void Update(GameTime gameTime) diff --git a/DangerousD/GameCore/GUI/LobbyGUI.cs b/DangerousD/GameCore/GUI/LobbyGUI.cs index 9136760..3b8b9ab 100644 --- a/DangerousD/GameCore/GUI/LobbyGUI.cs +++ b/DangerousD/GameCore/GUI/LobbyGUI.cs @@ -25,6 +25,7 @@ namespace DangerousD.GameCore.GUI { int screenWidth = AppManager.Instance.inGameResolution.X; int screenHeight = AppManager.Instance.inGameResolution.Y; + float scaler = AppManager.Instance.resolution.Y / (float)AppManager.Instance.inGameHUDHelperResolution.Y; var lobbyBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, screenWidth, screenHeight), textureName = "menuFon3" }; Elements.Add(lobbyBackground); @@ -51,6 +52,7 @@ namespace DangerousD.GameCore.GUI textureName = "textboxbackground6-1" }; + Elements.Add(searchBarTextBox); searchBarTextBox.TextChanged += input => { if (searchBarTextBox.fontColor == Color.Gray) { @@ -73,6 +75,7 @@ namespace DangerousD.GameCore.GUI fontName = "font2", textureName = "textboxbackground1-1" }; + Elements.Add(backButton); backButton.LeftButtonPressed += () => { AppManager.Instance.ChangeGameState(GameState.Menu); }; @@ -86,6 +89,7 @@ namespace DangerousD.GameCore.GUI fontName = "buttonFont", textureName = "textboxbackground2-1" }; + Elements.Add(hostButton); hostButton.LeftButtonPressed += () => { AppManager.Instance.ChangeGameState(GameState.Game); AppManager.Instance.NetworkManager.HostInit(AppManager.Instance.IpAddress); @@ -101,6 +105,7 @@ namespace DangerousD.GameCore.GUI fontName = "buttonFont", textureName = "textboxbackground2-1" }; + Elements.Add(refreshButton); refreshButton.LeftButtonPressed += () => { }; @@ -114,6 +119,7 @@ namespace DangerousD.GameCore.GUI fontName = "buttonFont", textureName = "textboxbackground2-1" }; + Elements.Add(joinSelectedButton); joinSelectedButton.LeftButtonPressed += () => { AppManager.Instance.ChangeGameState(GameState.Game); AppManager.Instance.NetworkManager.ClientInit(AppManager.Instance.IpAddress); @@ -127,10 +133,25 @@ namespace DangerousD.GameCore.GUI fontName = "buttonFont", textureName = "textboxbackground2-1" }; + Elements.Add(joinByIpButton); joinByIpButton.LeftButtonPressed += () => { AppManager.Instance.NetworkManager.ClientInit(searchBarTextBox.text); }; } + + + + foreach (var item in Elements) + { + item.rectangle.X = (int)(scaler * item.rectangle.X); + item.rectangle.Y = (int)(scaler * item.rectangle.Y); + item.rectangle.Width = (int)(scaler * item.rectangle.Width); + item.rectangle.Height = (int)(scaler * item.rectangle.Height); + if (item is DrawableTextedUiElement) + { + (item as DrawableTextedUiElement).scale *= scaler; + } + } } } } diff --git a/DangerousD/GameCore/GUI/LoginGUI.cs b/DangerousD/GameCore/GUI/LoginGUI.cs index 37a62eb..de0a68c 100644 --- a/DangerousD/GameCore/GUI/LoginGUI.cs +++ b/DangerousD/GameCore/GUI/LoginGUI.cs @@ -26,6 +26,7 @@ namespace DangerousD.GameCore.GUI { int screenWidth = AppManager.Instance.inGameResolution.X; int screenHeight = AppManager.Instance.inGameResolution.Y; + float scaler = AppManager.Instance.resolution.Y / (float)AppManager.Instance.inGameHUDHelperResolution.Y; var loginBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, screenWidth, screenHeight), textureName = "menuFon2" }; Elements.Add(loginBackground); @@ -53,6 +54,7 @@ namespace DangerousD.GameCore.GUI textureName = "textboxbackground6-1" }; + Elements.Add(loginTextBox); loginTextBox.LoadTexture(AppManager.Instance.Content); loginTextBox.TextChanged += input => { if (loginTextBox.fontColor == Color.Gray) @@ -78,6 +80,7 @@ namespace DangerousD.GameCore.GUI textAligment = TextAligment.Left, textureName = "textboxbackground6-1" }; + Elements.Add(passwordTextBox); passwordTextBox.LoadTexture(AppManager.Instance.Content); passwordTextBox.TextChanged += input => { if (passwordTextBox.fontColor == Color.Gray) @@ -104,6 +107,7 @@ namespace DangerousD.GameCore.GUI fontName = "ButtonFont", textureName = "textboxbackground2-1" }; + Elements.Add(logButton); logButton.LeftButtonPressed += () => { if (CheckUser()) { @@ -120,6 +124,7 @@ namespace DangerousD.GameCore.GUI fontName = "ButtonFont", textureName = "textboxbackground2-1" }; + Elements.Add(regButton); regButton.LeftButtonPressed += GoToRegWebServer; Button backButton = new Button(Manager) @@ -131,10 +136,22 @@ namespace DangerousD.GameCore.GUI fontName = "font2", textureName = "textboxbackground1-1" }; + Elements.Add(backButton); backButton.LeftButtonPressed += () => { AppManager.Instance.ChangeGameState(GameState.Menu); }; } + foreach (var item in Elements) + { + item.rectangle.X = (int)(scaler * item.rectangle.X); + item.rectangle.Y = (int)(scaler * item.rectangle.Y); + item.rectangle.Width = (int)(scaler * item.rectangle.Width); + item.rectangle.Height = (int)(scaler * item.rectangle.Height); + if (item is DrawableTextedUiElement) + { + (item as DrawableTextedUiElement).scale *= scaler; + } + } } private void GoToRegWebServer() diff --git a/DangerousD/GameCore/GUI/MenuGUI.cs b/DangerousD/GameCore/GUI/MenuGUI.cs index 82170b1..d6e376e 100644 --- a/DangerousD/GameCore/GUI/MenuGUI.cs +++ b/DangerousD/GameCore/GUI/MenuGUI.cs @@ -13,9 +13,10 @@ internal class MenuGUI : AbstractGui int selected = 0; protected override void CreateUI() { - int wigth = AppManager.Instance.inGameResolution.X; - int height = AppManager.Instance.inGameResolution.Y; - + int wigth = AppManager.Instance.inGameHUDHelperResolution.X; + int height = AppManager.Instance.inGameHUDHelperResolution.Y; + float scaler = AppManager.Instance.resolution.Y / (float)AppManager.Instance.inGameHUDHelperResolution.Y; + var menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, wigth, height), textureName = "menuFon" }; Elements.Add(menuBackground); menuBackground.LoadTexture(AppManager.Instance.Content); @@ -59,6 +60,18 @@ internal class MenuGUI : AbstractGui { AppManager.Instance.Exit(); }; + + foreach ( var item in Elements) + { + item.rectangle.X = (int)(scaler * item.rectangle.X); + item.rectangle.Y = (int)(scaler * item.rectangle.Y); + item.rectangle.Width = (int)(scaler * item.rectangle.Width); + item.rectangle.Height = (int)(scaler * item.rectangle.Height); + if (item is DrawableTextedUiElement) + { + (item as DrawableTextedUiElement).scale *= scaler; + } + } } public override void Update(GameTime gameTime) diff --git a/DangerousD/GameCore/GUI/OptionsGUI.cs b/DangerousD/GameCore/GUI/OptionsGUI.cs index 6fc95c7..c879731 100644 --- a/DangerousD/GameCore/GUI/OptionsGUI.cs +++ b/DangerousD/GameCore/GUI/OptionsGUI.cs @@ -13,8 +13,9 @@ namespace DangerousD.GameCore.GUI int selectedGUI = 0; protected override void CreateUI() { - int wigth = AppManager.Instance.inGameResolution.X; - int height = AppManager.Instance.inGameResolution.Y; + int wigth = AppManager.Instance.inGameHUDHelperResolution.X; + int height = AppManager.Instance.inGameHUDHelperResolution.Y; + float scaler = AppManager.Instance.resolution.Y / (float)AppManager.Instance.inGameHUDHelperResolution.Y; var menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, wigth, height), textureName = "optionsBackground" }; Elements.Add(menuBackground); menuBackground.LoadTexture(AppManager.Instance.Content); @@ -27,6 +28,8 @@ namespace DangerousD.GameCore.GUI indentation = 5, textureName = "sliderBackground" }; + Elements.Add(slider); + //AppManager.Instance.SettingsManager.SetMainVolume(slider.GetSliderValue); var cB = new CheckBox(Manager); cB.rectangle = new Rectangle(wigth / 2 + 440, 405, (int)(40 * 2.4), (int)(40 * 2.4)); @@ -35,26 +38,28 @@ namespace DangerousD.GameCore.GUI SettingsManager sM = new SettingsManager(); }; cB.LoadTexture(AppManager.Instance.Content); + Elements.Add(cB); var checkBox = new CheckBox(Manager); checkBox.rectangle = new Rectangle(wigth / 2 + 360, 540, (int)(40 * 2.4), (int)(40 * 2.4)); checkBox.Checked += (newCheckState) => { - SettingsManager sM = new SettingsManager(); + AppManager.Instance.SettingsManager.SetIsFullScreen(newCheckState); }; checkBox.LoadTexture(AppManager.Instance.Content); + Elements.Add(checkBox); Label lblOptions = new Label(Manager) { fontName = "buttonFont", scale = 1.2f, text = "Options", fontColor = Color.White, rectangle = new Rectangle((wigth - 50) / 2, 40, 50, 50), mainColor = Color.Transparent }; Elements.Add(lblOptions); Label lblValue = new Label(Manager) - { fontName = "buttonFont", scale = 1f, text = "Volume", fontColor = Color.White, rectangle = new Rectangle((wigth - 50) / 2, 250, 50, 50), mainColor = Color.Transparent }; + { fontName = "buttonFont", scale = 1f , text = "Volume", fontColor = Color.White, rectangle = new Rectangle((wigth - 50) / 2, 250, 50, 50), mainColor = Color.Transparent }; Elements.Add(lblValue); Label lblIsFullScreen = new Label(Manager) - { fontName = "buttonFont", scale = 1f, text = "Full Screen", fontColor = Color.White, rectangle = new Rectangle((wigth - 50) / 2, 580, 50, 50), mainColor = Color.Transparent }; - Elements.Add(lblOptions); + { fontName = "buttonFont", scale = 1f , text = "Full Screen", fontColor = Color.White, rectangle = new Rectangle((wigth - 50) / 2, 580, 50, 50), mainColor = Color.Transparent }; + Elements.Add(lblIsFullScreen); Label lblSwitchMode = new Label(Manager) { fontName = "buttonFont", scale = 1f, text = "Left/Right Mode", fontColor = Color.White, rectangle = new Rectangle((wigth - 50) / 2, 415, 50, 50), mainColor = Color.Transparent }; @@ -67,6 +72,18 @@ namespace DangerousD.GameCore.GUI { AppManager.Instance.ChangeGameState(GameState.Menu); }; + + foreach (var item in Elements) + { + item.rectangle.X = (int)(scaler * item.rectangle.X); + item.rectangle.Y = (int)(scaler * item.rectangle.Y); + item.rectangle.Width = (int)(scaler * item.rectangle.Width); + item.rectangle.Height = (int)(scaler * item.rectangle.Height); + if (item is DrawableTextedUiElement) + { + (item as DrawableTextedUiElement).scale *= scaler; + } + } } public override void Update(GameTime gameTime) { diff --git a/DangerousD/GameCore/Managers/AppManager.cs b/DangerousD/GameCore/Managers/AppManager.cs index 84d6b07..b4b3872 100644 --- a/DangerousD/GameCore/Managers/AppManager.cs +++ b/DangerousD/GameCore/Managers/AppManager.cs @@ -27,8 +27,9 @@ namespace DangerousD.GameCore private SpriteBatch _spriteBatch; public GameState gameState { get; private set; } public MultiPlayerStatus multiPlayerStatus { get; private set; } = MultiPlayerStatus.SinglePlayer; - public Point resolution = new Point(1920, 1080); + public Point resolution; public Point inGameResolution = new Point(1920, 1080); + public Point inGameHUDHelperResolution = new Point(1920, 1080); IDrawableObject MenuGUI; IDrawableObject OptionsGUI; IDrawableObject LoginGUI; @@ -60,9 +61,7 @@ namespace DangerousD.GameCore NetworkManager.GetReceivingMessages += NetworkSync; resolution = SettingsManager.Resolution; - _graphics.PreferredBackBufferWidth = resolution.X; - _graphics.PreferredBackBufferHeight = resolution.Y; - _graphics.IsFullScreen = false; + gameState = GameState.Menu; MenuGUI = new MenuGUI(); LoginGUI = new LoginGUI(); @@ -71,8 +70,8 @@ namespace DangerousD.GameCore DeathGUI = new DeathGUI(); HUD = new HUD(); DebugHUD = new DebugHUD(); - UIManager.resolution = resolution; - UIManager.resolutionInGame = inGameResolution; + UIManager.resolution = new Point(_graphics.PreferredBackBufferWidth, _graphics.PreferredBackBufferHeight); + UIManager.resolutionInGame = resolution; } protected override void Initialize() @@ -103,7 +102,7 @@ namespace DangerousD.GameCore GameObject.debugTexture.SetData(new Color[] { new Color(1, 0,0,0.25f) }); SoundManager.LoadSounds(); SoundManager.StartAmbientSound("DoomTestSong"); - renderTarget = new RenderTarget2D(GraphicsDevice, inGameResolution.X, inGameResolution.Y); + renderTarget = new RenderTarget2D(GraphicsDevice, resolution.X, resolution.Y); } protected override void Update(GameTime gameTime) @@ -253,5 +252,24 @@ namespace DangerousD.GameCore { this.multiPlayerStatus = multiPlayerStatus; } + public void SetIsFullScreen(bool fullscrin) + { + DebugHUD?.Set("resX:", SettingsManager.Resolution.X.ToString()); + DebugHUD?.Set("resY:", SettingsManager.Resolution.Y.ToString()); + DebugHUD?.Set("FullScreen:", _graphics.IsFullScreen.ToString()); + if (fullscrin) + { + _graphics.PreferredBackBufferWidth = 1920; + _graphics.PreferredBackBufferHeight = 1080; + } + else + { + _graphics.PreferredBackBufferWidth = SettingsManager.Resolution.X; + _graphics.PreferredBackBufferHeight = SettingsManager.Resolution.Y; + } + UIManager.resolution = new Point(_graphics.PreferredBackBufferWidth, _graphics.PreferredBackBufferHeight); + _graphics.IsFullScreen = fullscrin; + _graphics.ApplyChanges(); + } } } diff --git a/DangerousD/GameCore/Managers/SettingsManager.cs b/DangerousD/GameCore/Managers/SettingsManager.cs index 7a55447..b781ef1 100644 --- a/DangerousD/GameCore/Managers/SettingsManager.cs +++ b/DangerousD/GameCore/Managers/SettingsManager.cs @@ -27,22 +27,26 @@ namespace DangerousD.GameCore.Managers public void SetMainVolume(float volume) { settingsContainer.MainVolume = MainVolume; - ///AppManager.Instance.SoundManager. + //AppManager.Instance.SoundManager. } public void SetMusicVolume(float volume) { settingsContainer.MusicVolume = MainVolume; + SaveSettings(); } public void SetSoundEffectsVolume(float volume) { settingsContainer.SoundEffectsVolume = MainVolume; + SaveSettings(); } public void SetIsFullScreen(bool isFullScreen) { settingsContainer.IsFullScreen = isFullScreen; + AppManager.Instance.SetIsFullScreen(isFullScreen); + SaveSettings(); } public void LoadSettings() {