minoryrefectlring
This commit is contained in:
parent
dca6928daf
commit
634a986e70
3 changed files with 86 additions and 23 deletions
|
@ -8,6 +8,8 @@ using DangerousD.GameCore.GUI;
|
||||||
using Microsoft.Xna.Framework.Input;
|
using Microsoft.Xna.Framework.Input;
|
||||||
using DangerousD.GameCore.Graphics;
|
using DangerousD.GameCore.Graphics;
|
||||||
using DangerousD.GameCore.Network;
|
using DangerousD.GameCore.Network;
|
||||||
|
using MonogameLibrary.UI.Base;
|
||||||
|
using DangerousD.GameCore.Managers;
|
||||||
|
|
||||||
namespace DangerousD.GameCore
|
namespace DangerousD.GameCore
|
||||||
{
|
{
|
||||||
|
@ -17,19 +19,21 @@ namespace DangerousD.GameCore
|
||||||
public static AppManager Instance { get; private set; }
|
public static AppManager Instance { get; private set; }
|
||||||
private GraphicsDeviceManager _graphics;
|
private GraphicsDeviceManager _graphics;
|
||||||
private SpriteBatch _spriteBatch;
|
private SpriteBatch _spriteBatch;
|
||||||
public Point resolution;
|
|
||||||
GameState gameState;
|
GameState gameState;
|
||||||
IDrawableObject MenuGUI;
|
IDrawableObject MenuGUI;
|
||||||
IDrawableObject OptionsGUI;
|
IDrawableObject OptionsGUI;
|
||||||
IDrawableObject LoginGUI;
|
IDrawableObject LoginGUI;
|
||||||
IDrawableObject LobbyGUI;
|
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 GameManager GameManager { get; private set; } = new GameManager();
|
||||||
public AnimationBuilder AnimationBuilder { get; private set; } = new AnimationBuilder();
|
public AnimationBuilder AnimationBuilder { get; private set; } = new AnimationBuilder();
|
||||||
public NetworkManager NetworkManager { get; private set; } = new NetworkManager();
|
public NetworkManager NetworkManager { get; private set; } = new NetworkManager();
|
||||||
public InputManager InputManager { get; private set; } = new InputManager();
|
public InputManager InputManager { get; private set; } = new InputManager();
|
||||||
public SoundManager SoundManager { get; private set; } = new SoundManager();
|
public SoundManager SoundManager { get; private set; } = new SoundManager();
|
||||||
|
public SettingsManager SettingsManager { get; private set; } = new SettingsManager();
|
||||||
public AppManager()
|
public AppManager()
|
||||||
{
|
{
|
||||||
Instance = this;
|
Instance = this;
|
||||||
|
@ -38,11 +42,19 @@ namespace DangerousD.GameCore
|
||||||
IsMouseVisible = true;
|
IsMouseVisible = true;
|
||||||
TargetElapsedTime = TimeSpan.FromMilliseconds(1000 / 30);
|
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;
|
gameState = GameState.Menu;
|
||||||
MenuGUI = new MenuGUI();
|
MenuGUI = new MenuGUI();
|
||||||
LoginGUI = new LoginGUI();
|
LoginGUI = new LoginGUI();
|
||||||
LobbyGUI = new LobbyGUI();
|
LobbyGUI = new LobbyGUI();
|
||||||
|
UIManager.resolution = resolution;
|
||||||
|
UIManager.resolutionInGame = inGameResolution;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Initialize()
|
protected override void Initialize()
|
||||||
|
@ -64,6 +76,7 @@ namespace DangerousD.GameCore
|
||||||
GameObject.debugTexture.SetData<Color>(new Color[] { new Color(1, 0,0,0.25f) });
|
GameObject.debugTexture.SetData<Color>(new Color[] { new Color(1, 0,0,0.25f) });
|
||||||
SoundManager.LoadSounds();
|
SoundManager.LoadSounds();
|
||||||
SoundManager.StartAmbientSound("DoomTestSong");
|
SoundManager.StartAmbientSound("DoomTestSong");
|
||||||
|
renderTarget = new RenderTarget2D(GraphicsDevice, inGameResolution.X, inGameResolution.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Update(GameTime gameTime)
|
protected override void Update(GameTime gameTime)
|
||||||
|
@ -117,13 +130,17 @@ namespace DangerousD.GameCore
|
||||||
LobbyGUI.Draw(_spriteBatch);
|
LobbyGUI.Draw(_spriteBatch);
|
||||||
break;
|
break;
|
||||||
case GameState.Game:
|
case GameState.Game:
|
||||||
_spriteBatch.Begin(SpriteSortMode.Deferred,null,SamplerState.PointClamp);
|
_spriteBatch.Begin(SpriteSortMode.Deferred, null, SamplerState.PointClamp);
|
||||||
GameManager.Draw(_spriteBatch);
|
GameManager.Draw(_spriteBatch);
|
||||||
_spriteBatch.End();
|
_spriteBatch.End();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
GraphicsDevice.SetRenderTarget(null);
|
||||||
|
_spriteBatch.Begin();
|
||||||
|
_spriteBatch.Draw(renderTarget, new Rectangle(0, 0, _graphics.PreferredBackBufferWidth, _graphics.PreferredBackBufferHeight), Color.White);
|
||||||
|
_spriteBatch.End();
|
||||||
|
|
||||||
|
|
||||||
base.Draw(gameTime);
|
base.Draw(gameTime);
|
||||||
|
|
|
@ -1,31 +1,77 @@
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.Xna;
|
||||||
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
|
||||||
namespace DangerousD.GameCore.Managers
|
namespace DangerousD.GameCore.Managers
|
||||||
{
|
{
|
||||||
internal class SettingsManager
|
public class SettingsManager
|
||||||
{
|
{
|
||||||
public bool isFullScreen =false;
|
private SettingsContainer settingsContainer= new SettingsContainer();
|
||||||
public void SetResolution()
|
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)
|
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<SettingsContainer>(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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace DangerousD.GameCore
|
||||||
{
|
{
|
||||||
var sound = new Sound(Sounds[soundName]);
|
var sound = new Sound(Sounds[soundName]);
|
||||||
sound.SoundEffect.IsLooped = false;
|
sound.SoundEffect.IsLooped = false;
|
||||||
// sound.SoundEffect.Play();
|
sound.SoundEffect.Play();
|
||||||
PlayingSounds.Add(sound);
|
PlayingSounds.Add(sound);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,7 +42,7 @@ namespace DangerousD.GameCore
|
||||||
sound.SoundEffect.Volume = (float)sound.GetDistance(playerPos) / MaxSoundDistance;
|
sound.SoundEffect.Volume = (float)sound.GetDistance(playerPos) / MaxSoundDistance;
|
||||||
sound.SoundEffect.Play();
|
sound.SoundEffect.Play();
|
||||||
PlayingSounds.Add(sound);
|
PlayingSounds.Add(sound);
|
||||||
}//GameManager.SendSound
|
}
|
||||||
public void StopAllSounds() // остановка всех звуков
|
public void StopAllSounds() // остановка всех звуков
|
||||||
{
|
{
|
||||||
foreach (var sound in PlayingSounds)
|
foreach (var sound in PlayingSounds)
|
||||||
|
@ -58,12 +58,12 @@ namespace DangerousD.GameCore
|
||||||
var player = AppManager.Instance.GameManager.GetPlayer1;
|
var player = AppManager.Instance.GameManager.GetPlayer1;
|
||||||
if (player != null)
|
if (player != null)
|
||||||
{
|
{
|
||||||
foreach (var sound in PlayingSounds)
|
for (int i = 0; i < PlayingSounds.Count; i++)
|
||||||
{
|
{
|
||||||
if (!sound.isAmbient)
|
if (!PlayingSounds[i].isAmbient)
|
||||||
sound.SoundEffect.Volume = (float)sound.GetDistance(player.Pos) / MaxSoundDistance;
|
PlayingSounds[i].SoundEffect.Volume = (float)PlayingSounds[i].GetDistance(player.Pos) / MaxSoundDistance;
|
||||||
if (sound.SoundEffect.State == SoundState.Stopped)
|
if (PlayingSounds[i].SoundEffect.State == SoundState.Stopped)
|
||||||
PlayingSounds.Remove(sound);
|
PlayingSounds.Remove(PlayingSounds[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue