UI_fullscreen

This commit is contained in:
gravity 2023-08-18 03:05:57 +03:00
parent 7e3bbd7143
commit b37fbaf4ea
7 changed files with 119 additions and 17 deletions

View file

@ -13,6 +13,7 @@ internal class DeathGUI : AbstractGui
{ {
int wigth = AppManager.Instance.inGameResolution.X; int wigth = AppManager.Instance.inGameResolution.X;
int height = AppManager.Instance.inGameResolution.Y; 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" }; var menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, wigth, height), textureName = "deathBackground" };
Elements.Add(menuBackground); Elements.Add(menuBackground);
menuBackground.LoadTexture(AppManager.Instance.Content); menuBackground.LoadTexture(AppManager.Instance.Content);
@ -24,6 +25,17 @@ internal class DeathGUI : AbstractGui
{ {
AppManager.Instance.ChangeGameState(GameState.Menu); 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) public override void Update(GameTime gameTime)

View file

@ -25,6 +25,7 @@ namespace DangerousD.GameCore.GUI
{ {
int screenWidth = AppManager.Instance.inGameResolution.X; int screenWidth = AppManager.Instance.inGameResolution.X;
int screenHeight = AppManager.Instance.inGameResolution.Y; 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" }; var lobbyBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, screenWidth, screenHeight), textureName = "menuFon3" };
Elements.Add(lobbyBackground); Elements.Add(lobbyBackground);
@ -51,6 +52,7 @@ namespace DangerousD.GameCore.GUI
textureName = "textboxbackground6-1" textureName = "textboxbackground6-1"
}; };
Elements.Add(searchBarTextBox);
searchBarTextBox.TextChanged += input => { searchBarTextBox.TextChanged += input => {
if (searchBarTextBox.fontColor == Color.Gray) if (searchBarTextBox.fontColor == Color.Gray)
{ {
@ -73,6 +75,7 @@ namespace DangerousD.GameCore.GUI
fontName = "font2", fontName = "font2",
textureName = "textboxbackground1-1" textureName = "textboxbackground1-1"
}; };
Elements.Add(backButton);
backButton.LeftButtonPressed += () => { backButton.LeftButtonPressed += () => {
AppManager.Instance.ChangeGameState(GameState.Menu); AppManager.Instance.ChangeGameState(GameState.Menu);
}; };
@ -86,6 +89,7 @@ namespace DangerousD.GameCore.GUI
fontName = "buttonFont", fontName = "buttonFont",
textureName = "textboxbackground2-1" textureName = "textboxbackground2-1"
}; };
Elements.Add(hostButton);
hostButton.LeftButtonPressed += () => { hostButton.LeftButtonPressed += () => {
AppManager.Instance.ChangeGameState(GameState.Game); AppManager.Instance.ChangeGameState(GameState.Game);
AppManager.Instance.NetworkManager.HostInit(AppManager.Instance.IpAddress); AppManager.Instance.NetworkManager.HostInit(AppManager.Instance.IpAddress);
@ -101,6 +105,7 @@ namespace DangerousD.GameCore.GUI
fontName = "buttonFont", fontName = "buttonFont",
textureName = "textboxbackground2-1" textureName = "textboxbackground2-1"
}; };
Elements.Add(refreshButton);
refreshButton.LeftButtonPressed += () => { refreshButton.LeftButtonPressed += () => {
}; };
@ -114,6 +119,7 @@ namespace DangerousD.GameCore.GUI
fontName = "buttonFont", fontName = "buttonFont",
textureName = "textboxbackground2-1" textureName = "textboxbackground2-1"
}; };
Elements.Add(joinSelectedButton);
joinSelectedButton.LeftButtonPressed += () => { joinSelectedButton.LeftButtonPressed += () => {
AppManager.Instance.ChangeGameState(GameState.Game); AppManager.Instance.ChangeGameState(GameState.Game);
AppManager.Instance.NetworkManager.ClientInit(AppManager.Instance.IpAddress); AppManager.Instance.NetworkManager.ClientInit(AppManager.Instance.IpAddress);
@ -127,10 +133,25 @@ namespace DangerousD.GameCore.GUI
fontName = "buttonFont", fontName = "buttonFont",
textureName = "textboxbackground2-1" textureName = "textboxbackground2-1"
}; };
Elements.Add(joinByIpButton);
joinByIpButton.LeftButtonPressed += () => { joinByIpButton.LeftButtonPressed += () => {
AppManager.Instance.NetworkManager.ClientInit(searchBarTextBox.text); 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;
}
}
} }
} }
} }

View file

@ -26,6 +26,7 @@ namespace DangerousD.GameCore.GUI
{ {
int screenWidth = AppManager.Instance.inGameResolution.X; int screenWidth = AppManager.Instance.inGameResolution.X;
int screenHeight = AppManager.Instance.inGameResolution.Y; 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" }; var loginBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, screenWidth, screenHeight), textureName = "menuFon2" };
Elements.Add(loginBackground); Elements.Add(loginBackground);
@ -53,6 +54,7 @@ namespace DangerousD.GameCore.GUI
textureName = "textboxbackground6-1" textureName = "textboxbackground6-1"
}; };
Elements.Add(loginTextBox);
loginTextBox.LoadTexture(AppManager.Instance.Content); loginTextBox.LoadTexture(AppManager.Instance.Content);
loginTextBox.TextChanged += input => { loginTextBox.TextChanged += input => {
if (loginTextBox.fontColor == Color.Gray) if (loginTextBox.fontColor == Color.Gray)
@ -78,6 +80,7 @@ namespace DangerousD.GameCore.GUI
textAligment = TextAligment.Left, textAligment = TextAligment.Left,
textureName = "textboxbackground6-1" textureName = "textboxbackground6-1"
}; };
Elements.Add(passwordTextBox);
passwordTextBox.LoadTexture(AppManager.Instance.Content); passwordTextBox.LoadTexture(AppManager.Instance.Content);
passwordTextBox.TextChanged += input => { passwordTextBox.TextChanged += input => {
if (passwordTextBox.fontColor == Color.Gray) if (passwordTextBox.fontColor == Color.Gray)
@ -104,6 +107,7 @@ namespace DangerousD.GameCore.GUI
fontName = "ButtonFont", fontName = "ButtonFont",
textureName = "textboxbackground2-1" textureName = "textboxbackground2-1"
}; };
Elements.Add(logButton);
logButton.LeftButtonPressed += () => { logButton.LeftButtonPressed += () => {
if (CheckUser()) if (CheckUser())
{ {
@ -120,6 +124,7 @@ namespace DangerousD.GameCore.GUI
fontName = "ButtonFont", fontName = "ButtonFont",
textureName = "textboxbackground2-1" textureName = "textboxbackground2-1"
}; };
Elements.Add(regButton);
regButton.LeftButtonPressed += GoToRegWebServer; regButton.LeftButtonPressed += GoToRegWebServer;
Button backButton = new Button(Manager) Button backButton = new Button(Manager)
@ -131,10 +136,22 @@ namespace DangerousD.GameCore.GUI
fontName = "font2", fontName = "font2",
textureName = "textboxbackground1-1" textureName = "textboxbackground1-1"
}; };
Elements.Add(backButton);
backButton.LeftButtonPressed += () => { backButton.LeftButtonPressed += () => {
AppManager.Instance.ChangeGameState(GameState.Menu); 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() private void GoToRegWebServer()

View file

@ -13,9 +13,10 @@ internal class MenuGUI : AbstractGui
int selected = 0; int selected = 0;
protected override void CreateUI() protected override void CreateUI()
{ {
int wigth = AppManager.Instance.inGameResolution.X; int wigth = AppManager.Instance.inGameHUDHelperResolution.X;
int height = AppManager.Instance.inGameResolution.Y; 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" }; var menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, wigth, height), textureName = "menuFon" };
Elements.Add(menuBackground); Elements.Add(menuBackground);
menuBackground.LoadTexture(AppManager.Instance.Content); menuBackground.LoadTexture(AppManager.Instance.Content);
@ -59,6 +60,18 @@ internal class MenuGUI : AbstractGui
{ {
AppManager.Instance.Exit(); 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) public override void Update(GameTime gameTime)

View file

@ -13,8 +13,9 @@ namespace DangerousD.GameCore.GUI
int selectedGUI = 0; int selectedGUI = 0;
protected override void CreateUI() protected override void CreateUI()
{ {
int wigth = AppManager.Instance.inGameResolution.X; int wigth = AppManager.Instance.inGameHUDHelperResolution.X;
int height = AppManager.Instance.inGameResolution.Y; 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" }; var menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, wigth, height), textureName = "optionsBackground" };
Elements.Add(menuBackground); Elements.Add(menuBackground);
menuBackground.LoadTexture(AppManager.Instance.Content); menuBackground.LoadTexture(AppManager.Instance.Content);
@ -27,6 +28,8 @@ namespace DangerousD.GameCore.GUI
indentation = 5, indentation = 5,
textureName = "sliderBackground" textureName = "sliderBackground"
}; };
Elements.Add(slider);
//AppManager.Instance.SettingsManager.SetMainVolume(slider.GetSliderValue);
var cB = new CheckBox(Manager); var cB = new CheckBox(Manager);
cB.rectangle = new Rectangle(wigth / 2 + 440, 405, (int)(40 * 2.4), (int)(40 * 2.4)); 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(); SettingsManager sM = new SettingsManager();
}; };
cB.LoadTexture(AppManager.Instance.Content); cB.LoadTexture(AppManager.Instance.Content);
Elements.Add(cB);
var checkBox = new CheckBox(Manager); var checkBox = new CheckBox(Manager);
checkBox.rectangle = new Rectangle(wigth / 2 + 360, 540, (int)(40 * 2.4), (int)(40 * 2.4)); checkBox.rectangle = new Rectangle(wigth / 2 + 360, 540, (int)(40 * 2.4), (int)(40 * 2.4));
checkBox.Checked += (newCheckState) => checkBox.Checked += (newCheckState) =>
{ {
SettingsManager sM = new SettingsManager(); AppManager.Instance.SettingsManager.SetIsFullScreen(newCheckState);
}; };
checkBox.LoadTexture(AppManager.Instance.Content); checkBox.LoadTexture(AppManager.Instance.Content);
Elements.Add(checkBox);
Label lblOptions = new Label(Manager) 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 }; { 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); Elements.Add(lblOptions);
Label lblValue = new Label(Manager) 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); Elements.Add(lblValue);
Label lblIsFullScreen = new Label(Manager) 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 }; { 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); Elements.Add(lblIsFullScreen);
Label lblSwitchMode = new Label(Manager) 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 }; { 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); 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) public override void Update(GameTime gameTime)
{ {

View file

@ -27,8 +27,9 @@ namespace DangerousD.GameCore
private SpriteBatch _spriteBatch; private SpriteBatch _spriteBatch;
public GameState gameState { get; private set; } public GameState gameState { get; private set; }
public MultiPlayerStatus multiPlayerStatus { get; private set; } = MultiPlayerStatus.SinglePlayer; 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 inGameResolution = new Point(1920, 1080);
public Point inGameHUDHelperResolution = new Point(1920, 1080);
IDrawableObject MenuGUI; IDrawableObject MenuGUI;
IDrawableObject OptionsGUI; IDrawableObject OptionsGUI;
IDrawableObject LoginGUI; IDrawableObject LoginGUI;
@ -60,9 +61,7 @@ namespace DangerousD.GameCore
NetworkManager.GetReceivingMessages += NetworkSync; NetworkManager.GetReceivingMessages += NetworkSync;
resolution = SettingsManager.Resolution; resolution = SettingsManager.Resolution;
_graphics.PreferredBackBufferWidth = resolution.X;
_graphics.PreferredBackBufferHeight = resolution.Y;
_graphics.IsFullScreen = false;
gameState = GameState.Menu; gameState = GameState.Menu;
MenuGUI = new MenuGUI(); MenuGUI = new MenuGUI();
LoginGUI = new LoginGUI(); LoginGUI = new LoginGUI();
@ -71,8 +70,8 @@ namespace DangerousD.GameCore
DeathGUI = new DeathGUI(); DeathGUI = new DeathGUI();
HUD = new HUD(); HUD = new HUD();
DebugHUD = new DebugHUD(); DebugHUD = new DebugHUD();
UIManager.resolution = resolution; UIManager.resolution = new Point(_graphics.PreferredBackBufferWidth, _graphics.PreferredBackBufferHeight);
UIManager.resolutionInGame = inGameResolution; UIManager.resolutionInGame = resolution;
} }
protected override void Initialize() protected override void Initialize()
@ -103,7 +102,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); renderTarget = new RenderTarget2D(GraphicsDevice, resolution.X, resolution.Y);
} }
protected override void Update(GameTime gameTime) protected override void Update(GameTime gameTime)
@ -253,5 +252,24 @@ namespace DangerousD.GameCore
{ {
this.multiPlayerStatus = multiPlayerStatus; 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();
}
} }
} }

View file

@ -27,22 +27,26 @@ namespace DangerousD.GameCore.Managers
public void SetMainVolume(float volume) public void SetMainVolume(float volume)
{ {
settingsContainer.MainVolume = MainVolume; settingsContainer.MainVolume = MainVolume;
///AppManager.Instance.SoundManager. //AppManager.Instance.SoundManager.
} }
public void SetMusicVolume(float volume) public void SetMusicVolume(float volume)
{ {
settingsContainer.MusicVolume = MainVolume; settingsContainer.MusicVolume = MainVolume;
SaveSettings();
} }
public void SetSoundEffectsVolume(float volume) public void SetSoundEffectsVolume(float volume)
{ {
settingsContainer.SoundEffectsVolume = MainVolume; settingsContainer.SoundEffectsVolume = MainVolume;
SaveSettings();
} }
public void SetIsFullScreen(bool isFullScreen) public void SetIsFullScreen(bool isFullScreen)
{ {
settingsContainer.IsFullScreen = isFullScreen; settingsContainer.IsFullScreen = isFullScreen;
AppManager.Instance.SetIsFullScreen(isFullScreen);
SaveSettings();
} }
public void LoadSettings() public void LoadSettings()
{ {