commit
3c88b5a245
2 changed files with 94 additions and 1 deletions
93
ZoFo/GameCore/GameManagers/SettingsManager.cs
Normal file
93
ZoFo/GameCore/GameManagers/SettingsManager.cs
Normal file
|
@ -0,0 +1,93 @@
|
|||
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;
|
||||
using Newtonsoft.Json.Serialization;
|
||||
using Microsoft.Xna.Framework.Graphics;
|
||||
|
||||
namespace ZoFo.GameCore.GameManagers
|
||||
{
|
||||
public class SettingsManager //нужно что-то менять с разрешением
|
||||
{
|
||||
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;
|
||||
//AppManager.Instance.resolution = resolution;
|
||||
}
|
||||
public void SetMainVolume(float volume)
|
||||
{
|
||||
settingsContainer.MainVolume = volume;
|
||||
//AppManager.Instance.SoundManager.Update();
|
||||
SaveSettings();
|
||||
}
|
||||
public void SetMusicVolume(float volume)
|
||||
{
|
||||
settingsContainer.MusicVolume = volume;
|
||||
SaveSettings();
|
||||
|
||||
}
|
||||
public void SetSoundEffectsVolume(float volume)
|
||||
{
|
||||
settingsContainer.SoundEffectsVolume = volume;
|
||||
SaveSettings();
|
||||
|
||||
}
|
||||
public void SetIsFullScreen(bool isFullScreen)
|
||||
{
|
||||
settingsContainer.IsFullScreen = isFullScreen;
|
||||
//AppManager.Instance.SetIsFullScreen(isFullScreen);
|
||||
SaveSettings();
|
||||
}
|
||||
public void LoadSettings()
|
||||
{
|
||||
if (!File.Exists("GameSettings.txt"))
|
||||
{
|
||||
SaveSettings();
|
||||
return;
|
||||
}
|
||||
|
||||
settingsContainer = JsonConvert.DeserializeObject<SettingsContainer>(File.ReadAllText("GameSettings.txt"));
|
||||
SetIsFullScreen(settingsContainer.IsFullScreen);
|
||||
SetMainVolume(settingsContainer.MainVolume);
|
||||
SetMusicVolume(settingsContainer.MusicVolume);
|
||||
SetResolution(settingsContainer.Resolution);
|
||||
SetSoundEffectsVolume(settingsContainer.SoundEffectsVolume);
|
||||
|
||||
|
||||
}
|
||||
public void SaveSettings()
|
||||
{
|
||||
using (StreamWriter streamWriter = new StreamWriter("GameSettings.txt"))
|
||||
{
|
||||
string _str = JsonConvert.SerializeObject(settingsContainer);
|
||||
streamWriter.Write(_str);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
[Serializable]
|
||||
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(GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height);
|
||||
}
|
||||
}
|
|
@ -114,7 +114,7 @@ namespace ZoFo.GameCore.GameManagers
|
|||
SoundEffect = soundEffect;
|
||||
Position = position;
|
||||
}
|
||||
/*/ public void UpdateVolume(Vector2 playerPos)
|
||||
/*/public void UpdateVolume(Vector2 playerPos)
|
||||
{
|
||||
if (isAmbient)
|
||||
SoundEffect.Volume = baseVolume * AppManager.Instance.SettingsManager.MusicVolume * AppManager.Instance.SettingsManager.MainVolume;
|
||||
|
|
Loading…
Add table
Reference in a new issue