diff --git a/DangerousD/GameCore/Managers/AppManager.cs b/DangerousD/GameCore/Managers/AppManager.cs index 5bbf0f4..dc44ba9 100644 --- a/DangerousD/GameCore/Managers/AppManager.cs +++ b/DangerousD/GameCore/Managers/AppManager.cs @@ -8,6 +8,8 @@ using DangerousD.GameCore.GUI; using Microsoft.Xna.Framework.Input; using DangerousD.GameCore.Graphics; using DangerousD.GameCore.Network; +using MonogameLibrary.UI.Base; +using DangerousD.GameCore.Managers; namespace DangerousD.GameCore { @@ -16,20 +18,22 @@ namespace DangerousD.GameCore { public static AppManager Instance { get; private set; } private GraphicsDeviceManager _graphics; - private SpriteBatch _spriteBatch; - public Point resolution; + private SpriteBatch _spriteBatch; GameState gameState; IDrawableObject MenuGUI; IDrawableObject OptionsGUI; IDrawableObject LoginGUI; IDrawableObject LobbyGUI; - public Point inGameResolution; + public Point resolution = new Point(1920, 1080); + public Point inGameResolution = new Point(800, 480); + private RenderTarget2D renderTarget; public GameManager GameManager { get; private set; } = new GameManager(); public AnimationBuilder AnimationBuilder { get; private set; } = new AnimationBuilder(); public NetworkManager NetworkManager { get; private set; } = new NetworkManager(); public InputManager InputManager { get; private set; } = new InputManager(); public SoundManager SoundManager { get; private set; } = new SoundManager(); + public SettingsManager SettingsManager { get; private set; } = new SettingsManager(); public AppManager() { Instance = this; @@ -38,11 +42,19 @@ namespace DangerousD.GameCore IsMouseVisible = true; TargetElapsedTime = TimeSpan.FromMilliseconds(1000 / 30); - resolution = new Point(_graphics.PreferredBackBufferWidth, _graphics.PreferredBackBufferHeight); + SettingsManager = new SettingsManager(); + SettingsManager.LoadSettings(); + + resolution = SettingsManager.Resolution; + _graphics.PreferredBackBufferWidth = resolution.X; + _graphics.PreferredBackBufferHeight = resolution.Y; + // _graphics.IsFullScreen = true; gameState = GameState.Menu; MenuGUI = new MenuGUI(); LoginGUI = new LoginGUI(); LobbyGUI = new LobbyGUI(); + UIManager.resolution = resolution; + UIManager.resolutionInGame = inGameResolution; } protected override void Initialize() @@ -63,7 +75,8 @@ namespace DangerousD.GameCore GameObject.debugTexture = new Texture2D(GraphicsDevice, 1, 1); GameObject.debugTexture.SetData(new Color[] { new Color(1, 0,0,0.25f) }); SoundManager.LoadSounds(); - SoundManager.StartAmbientSound("DoomTestSong"); + SoundManager.StartAmbientSound("DoomTestSong"); + renderTarget = new RenderTarget2D(GraphicsDevice, inGameResolution.X, inGameResolution.Y); } protected override void Update(GameTime gameTime) @@ -100,8 +113,8 @@ namespace DangerousD.GameCore protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); - - GraphicsDevice.SetRenderTarget(renderTarget); + + GraphicsDevice.SetRenderTarget(renderTarget); switch (gameState) { case GameState.Menu: @@ -117,13 +130,17 @@ namespace DangerousD.GameCore LobbyGUI.Draw(_spriteBatch); break; case GameState.Game: - _spriteBatch.Begin(SpriteSortMode.Deferred,null,SamplerState.PointClamp); + _spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp); GameManager.Draw(_spriteBatch); _spriteBatch.End(); break; default: break; } + GraphicsDevice.SetRenderTarget(null); + _spriteBatch.Begin(); + _spriteBatch.Draw(renderTarget, new Rectangle(0, 0, _graphics.PreferredBackBufferWidth, _graphics.PreferredBackBufferHeight), Color.White); + _spriteBatch.End(); base.Draw(gameTime); diff --git a/DangerousD/GameCore/Managers/SettingsManager.cs b/DangerousD/GameCore/Managers/SettingsManager.cs index e0c0650..b04f3e6 100644 --- a/DangerousD/GameCore/Managers/SettingsManager.cs +++ b/DangerousD/GameCore/Managers/SettingsManager.cs @@ -1,31 +1,77 @@ using Newtonsoft.Json; using System; using System.Collections.Generic; +using Microsoft.Xna; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; +using Microsoft.Xna.Framework; namespace DangerousD.GameCore.Managers { - internal class SettingsManager + public class SettingsManager { - public bool isFullScreen =false; - public void SetResolution() + private SettingsContainer settingsContainer= new SettingsContainer(); + public bool IsFullScreen { get => settingsContainer.IsFullScreen; } + public float MainVolume { get => settingsContainer.MainVolume; } + public float MusicVolume { get => settingsContainer.MusicVolume; } + public float SoundEffectsVolume { get => settingsContainer.SoundEffectsVolume; } + public Point Resolution { get => settingsContainer.Resolution; } + public void SetResolution(Point resolution) { + settingsContainer.Resolution = resolution; + } + public void SetMainVolume(float volume) + { + settingsContainer.MainVolume = MainVolume; } - public void SetMainVolume() + public void SetMusicVolume(float volume) { + settingsContainer.MusicVolume = MainVolume; } - public void SetMusicVolume() + public void SetSoundEffectsVolume(float volume) { + settingsContainer.SoundEffectsVolume = MainVolume; } public void SetIsFullScreen(bool isFullScreen) { - + settingsContainer.IsFullScreen = isFullScreen; } - + public void LoadSettings() + { + if (!File.Exists("GameSettings.txt")) + { + File.Create("GameSettings.txt"); + SaveSettings(); + return; + } + + var serializedObject = JsonConvert.DeserializeObject(File.ReadAllText("GameSettings.txt")); + + } + public void SaveSettings() + { + if (!File.Exists("GameSettings.txt")) + File.Create("GameSettings.txt"); + File.WriteAllText("GameSettings.txt", JsonConvert.SerializeObject(settingsContainer)); + } + + } + public class SettingsContainer + { + [JsonProperty("IsFullScreen")] + public bool IsFullScreen { get; set; } = false; + [JsonProperty("MainVolume")] + public float MainVolume { get; set; } = 1; + [JsonProperty("MusicVolume")] + public float MusicVolume { get; set; } = 1; + [JsonProperty("SoundEffectsVolume")] + public float SoundEffectsVolume { get; set; } = 1; + [JsonProperty("Resolution")] + public Point Resolution { get; set; } = new Point(1920,1080); } } diff --git a/DangerousD/GameCore/Managers/SoundManager.cs b/DangerousD/GameCore/Managers/SoundManager.cs index 7c0c3c1..9021fa8 100644 --- a/DangerousD/GameCore/Managers/SoundManager.cs +++ b/DangerousD/GameCore/Managers/SoundManager.cs @@ -31,7 +31,7 @@ namespace DangerousD.GameCore { var sound = new Sound(Sounds[soundName]); sound.SoundEffect.IsLooped = false; - // sound.SoundEffect.Play(); + sound.SoundEffect.Play(); PlayingSounds.Add(sound); } @@ -42,7 +42,7 @@ namespace DangerousD.GameCore sound.SoundEffect.Volume = (float)sound.GetDistance(playerPos) / MaxSoundDistance; sound.SoundEffect.Play(); PlayingSounds.Add(sound); - }//GameManager.SendSound + } public void StopAllSounds() // остановка всех звуков { foreach (var sound in PlayingSounds) @@ -58,12 +58,12 @@ namespace DangerousD.GameCore var player = AppManager.Instance.GameManager.GetPlayer1; if (player != null) { - foreach (var sound in PlayingSounds) - { - if (!sound.isAmbient) - sound.SoundEffect.Volume = (float)sound.GetDistance(player.Pos) / MaxSoundDistance; - if (sound.SoundEffect.State == SoundState.Stopped) - PlayingSounds.Remove(sound); + for (int i = 0; i < PlayingSounds.Count; i++) + { + if (!PlayingSounds[i].isAmbient) + PlayingSounds[i].SoundEffect.Volume = (float)PlayingSounds[i].GetDistance(player.Pos) / MaxSoundDistance; + if (PlayingSounds[i].SoundEffect.State == SoundState.Stopped) + PlayingSounds.Remove(PlayingSounds[i]); } } }