Merge pull request #59 from progtime-net/GUI

G UI
This commit is contained in:
SergoDobro 2024-08-18 14:05:04 +03:00 committed by GitHub
commit 429b24689e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 438 additions and 184 deletions

View file

@ -0,0 +1,79 @@
using Microsoft.Xna.Framework.Graphics;
using MonogameLibrary.UI.Base;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MonogameLibrary.UI.Enums;
using System;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using Microsoft.Xna.Framework.Content;
namespace MonogameLibrary.UI.Elements;
public class ItemDisplayLabel : DrawableUIElement
{
public int count;
public string itemTextureName;
private Texture2D itemTexture;
public Color fontColor1;
protected UIManager Manager;
public string fontName1;
public string text1;
public float scale1;
private DrawableUIElement icon;
public ItemDisplayLabel(UIManager manager) : base(manager)
{
Manager = manager;
}
public void Initialize()
{
icon = new DrawableUIElement(Manager)
{
rectangle = new Rectangle(rectangle.X + rectangle.Height / 3 / 2, rectangle.Y + rectangle.Height / 3 / 2, rectangle.Height / 3 * 2, rectangle.Height / 3 * 2),
mainColor = Color.White, textureName = itemTextureName
};
Label itemName = new Label(Manager)
{
rectangle = new Rectangle(rectangle.X + rectangle.Height / 3 / 2 + rectangle.Height / 3 * 2, rectangle.Y + rectangle.Height / 3 / 2, rectangle.Width / 3, rectangle.Height / 3 * 2),
fontColor = fontColor1, text = text1, scale = scale1, fontName = fontName1, mainColor = Color.Transparent
};
Label itemCount = new Label(Manager)
{
rectangle = new Rectangle(rectangle.X + rectangle.Width - (int)(rectangle.Height / 3 * 2.5), rectangle.Y + rectangle.Height / 3 / 2, rectangle.Height / 3 * 2, rectangle.Height / 3 * 2),
fontColor = fontColor1, text = count.ToString(), scale = scale1, fontName = fontName1, mainColor = Color.Transparent
};
}
public override void LoadTexture(ContentManager content)
{
icon.LoadTexture(content);
base.LoadTexture(content);
if (itemTextureName == "")
{
itemTexture = new Texture2D(Manager.GraphicsDevice, 1, 1);
itemTexture.SetData<Color>(new Color[] { mainColor });
}
else
{
try
{
itemTexture = content.Load<Texture2D>(itemTextureName);
}
catch
{
itemTexture = new Texture2D(Manager.GraphicsDevice, 1, 1);
itemTexture.SetData<Color>(new Color[] { mainColor });
}
}
}
public override void Draw(SpriteBatch _spriteBatch)
{
base.Draw(_spriteBatch);
}
}

View file

@ -0,0 +1,79 @@
using Microsoft.Xna.Framework.Graphics;
using MonogameLibrary.UI.Base;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using MonogameLibrary.UI.Enums;
using System;
using System.Collections.Generic;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using Microsoft.Xna.Framework.Content;
namespace MonogameLibrary.UI.Elements;
public class ItemDisplayButton : DrawableUIElement
{
public int count;
public string itemTextureName;
private Texture2D itemTexture;
public Color fontColor1;
protected UIManager Manager;
public string fontName1;
public string text1;
public float scale1;
private DrawableUIElement icon;
public ItemDisplayButton(UIManager manager) : base(manager)
{
Manager = manager;
}
public void Initialize()
{
icon = new DrawableUIElement(Manager)
{
rectangle = new Rectangle(rectangle.X + rectangle.Height / 3 / 2, rectangle.Y + rectangle.Height / 3 / 2, rectangle.Height / 3 * 2, rectangle.Height / 3 * 2),
mainColor = Color.White, textureName = itemTextureName
};
Label itemName = new Label(Manager)
{
rectangle = new Rectangle(rectangle.X + rectangle.Height / 3 / 2 + rectangle.Height / 3 * 2, rectangle.Y + rectangle.Height / 3 / 2, rectangle.Width / 3, rectangle.Height / 3 * 2),
fontColor = fontColor1, text = text1, scale = scale1, fontName = fontName1, mainColor = Color.Transparent
};
Label itemCount = new Label(Manager)
{
rectangle = new Rectangle(rectangle.X + rectangle.Width - (int)(rectangle.Height / 3 * 2.5), rectangle.Y + rectangle.Height / 3 / 2, rectangle.Height / 3 * 2, rectangle.Height / 3 * 2),
fontColor = fontColor1, text = count.ToString(), scale = scale1, fontName = fontName1, mainColor = Color.Transparent
};
}
public override void LoadTexture(ContentManager content)
{
icon.LoadTexture(content);
base.LoadTexture(content);
if (itemTextureName == "")
{
itemTexture = new Texture2D(Manager.GraphicsDevice, 1, 1);
itemTexture.SetData<Color>(new Color[] { mainColor });
}
else
{
try
{
itemTexture = content.Load<Texture2D>(itemTextureName);
}
catch
{
itemTexture = new Texture2D(Manager.GraphicsDevice, 1, 1);
itemTexture.SetData<Color>(new Color[] { mainColor });
}
}
}
public override void Draw(SpriteBatch _spriteBatch)
{
base.Draw(_spriteBatch);
}
}

View file

@ -352,7 +352,7 @@
/processorParam:TextureFormat=Color /processorParam:TextureFormat=Color
/build:Textures/GUI/switch.png /build:Textures/GUI/switch.png
#begin Textures/icons/12.png #begin Textures/Test/pickaxe.webp
/importer:TextureImporter /importer:TextureImporter
/processor:TextureProcessor /processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255 /processorParam:ColorKeyColor=255,0,255,255
@ -362,9 +362,10 @@
/processorParam:ResizeToPowerOfTwo=False /processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False /processorParam:MakeSquare=False
/processorParam:TextureFormat=Color /processorParam:TextureFormat=Color
/build:Textures/icons/12.png
#begin Textures/icons/13.png /build:Textures/Test/pickaxe.webp
#begin Textures/Test/rock.jpg
/importer:TextureImporter /importer:TextureImporter
/processor:TextureProcessor /processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255 /processorParam:ColorKeyColor=255,0,255,255
@ -374,9 +375,11 @@
/processorParam:ResizeToPowerOfTwo=False /processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False /processorParam:MakeSquare=False
/processorParam:TextureFormat=Color /processorParam:TextureFormat=Color
/build:Textures/icons/13.png
#begin Textures/icons/14.png /build:Textures/Test/rock.jpg
#begin Textures/Test/steel.png
/importer:TextureImporter /importer:TextureImporter
/processor:TextureProcessor /processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255 /processorParam:ColorKeyColor=255,0,255,255
@ -386,9 +389,11 @@
/processorParam:ResizeToPowerOfTwo=False /processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False /processorParam:MakeSquare=False
/processorParam:TextureFormat=Color /processorParam:TextureFormat=Color
/build:Textures/icons/14.png
#begin Textures/icons/21.png /build:Textures/Test/steel.png
#begin Textures/Test/wood.jpg
/importer:TextureImporter /importer:TextureImporter
/processor:TextureProcessor /processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255 /processorParam:ColorKeyColor=255,0,255,255
@ -398,9 +403,11 @@
/processorParam:ResizeToPowerOfTwo=False /processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False /processorParam:MakeSquare=False
/processorParam:TextureFormat=Color /processorParam:TextureFormat=Color
/build:Textures/icons/21.png
#begin Textures/icons/22.png /build:Textures/Test/wood.jpg
#begin Textures/TileSets/TilesetFloor.png
/importer:TextureImporter /importer:TextureImporter
/processor:TextureProcessor /processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255 /processorParam:ColorKeyColor=255,0,255,255
@ -410,125 +417,7 @@
/processorParam:ResizeToPowerOfTwo=False /processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False /processorParam:MakeSquare=False
/processorParam:TextureFormat=Color /processorParam:TextureFormat=Color
/build:Textures/icons/22.png
#begin Textures/icons/5.png /build:Textures/TileSets/TilesetFloor.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/icons/5.png
#begin Textures/icons/6.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/icons/6.png
#begin Textures/icons/7.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/icons/7.png
#begin Textures/icons/8.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/icons/8.png
#begin Textures/icons/9.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/icons/9.png
#begin Textures/TileSetImages/Tilelist1.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/TileSetImages/Tilelist1.png
#begin Textures/TileSetImages/Tilelist2.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/TileSetImages/Tilelist2.png
#begin Textures/TileSetImages/Tilelist3.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/TileSetImages/Tilelist3.png
#begin Textures/TileSetImages/Tilelist4.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/TileSetImages/Tilelist4.png
#begin Textures/TileSetImages/TilesetFloor.png
/importer:TextureImporter
/processor:TextureProcessor
/processorParam:ColorKeyColor=255,0,255,255
/processorParam:ColorKeyEnabled=True
/processorParam:GenerateMipmaps=False
/processorParam:PremultiplyAlpha=True
/processorParam:ResizeToPowerOfTwo=False
/processorParam:MakeSquare=False
/processorParam:TextureFormat=Color
/build:Textures/TileSetImages/TilesetFloor.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 648 KiB

After

Width:  |  Height:  |  Size: 9.2 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.6 MiB

After

Width:  |  Height:  |  Size: 5.7 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 508 KiB

After

Width:  |  Height:  |  Size: 7.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

View file

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading;
using System.Xml; using System.Xml;
using Microsoft.Xna.Framework; using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Content;
@ -9,20 +10,118 @@ using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
using MonogameLibrary.UI.Base; using MonogameLibrary.UI.Base;
using MonogameLibrary.UI.Elements; using MonogameLibrary.UI.Elements;
using ZoFo.GameCore.GameManagers;
using ZoFo.GameCore.GameManagers.ItemManager;
namespace ZoFo.GameCore.GUI; namespace ZoFo.GameCore.GUI;
public class BaseGUI : AbstractGUI public class BaseGUI : AbstractGUI
{ {
private DrawableUIElement menuBackground;
private List<ItemDisplayLabel> ItemDisplayButtonsList;
private int buttonIndex = 0;
private string textureName;
protected override void CreateUI() protected override void CreateUI()
{ {
// int width = AppManager.Instance.inGameHUDHelperResolution.X; ItemDisplayButtonsList = new List<ItemDisplayLabel>();
// int height = AppManager.Instance.inGameHUDHelperResolution.Y; int width = AppManager.Instance.CurentScreenResolution.X;
int height = AppManager.Instance.CurentScreenResolution.Y;
Dictionary<string, int> playerItems = AppManager.Instance.playerData.items;
Dictionary<string, ItemInfo> items = AppManager.Instance.ItemManager.tagItemPairs;
menuBackground = new DrawableUIElement(Manager)
{
rectangle = new Rectangle(0, 0, width, height), mainColor = Color.White,
textureName = "Textures\\GUI\\background\\base"
};
Elements.Add(menuBackground);
menuBackground.LoadTexture(AppManager.Instance.Content);
Elements.Add(new Label(Manager)
{
rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 15, (int)(width / 4), (int)(height / 20)),
text = "Base", fontColor = Color.Black, mainColor = Color.Transparent, scale = 0.9f,
fontName = "Fonts\\Font"
});
DrawableUIElement baseHudBack = new DrawableUIElement(Manager)
{
rectangle = new Rectangle(width / 2 - (int)(width / 1.5) / 2, height / 2 - (int)(height / 1.5) / 2,
(int)(width / 1.5), (int)(height / 1.5)),
mainColor = Color.LightGray
};
Elements.Add(baseHudBack);
//player itams
foreach (var item in playerItems)
{
textureName = AppManager.Instance.ItemManager.GetItemInfo(item.Key).textureName;
var temp = new ItemDisplayLabel(Manager)
{
rectangle = new Rectangle(width / 2 - (int)(width / 1.5) / 2 + height / 80,
height / 2 - (int)(height / 1.5) / 2 + height / 80 + (height / 20 + height / 80) * (buttonIndex),
(int)(width / 5), (int)(height / 20)),
text1 = item.Key,
scale1 = 0.4f,
count = item.Value,
itemTextureName = textureName,
fontColor1 = Color.White,
mainColor = Color.Gray,
fontName1 = "Fonts\\Font3"
};
Elements.Add(temp);
temp.Initialize();
temp.LoadTexture(AppManager.Instance.Content);
ItemDisplayButtonsList.Add(temp);
buttonIndex++;
}
// craftable items
buttonIndex = 0;
foreach (var item in items)
{
ItemInfo itemInfo = AppManager.Instance.ItemManager.GetItemInfo(item.Key);
if (itemInfo.isCraftable)
{
var temp = new ItemDisplayLabel(Manager)
{
rectangle = new Rectangle(width / 2 - (int)(width / 1.5) / 2 + height / 40 + width / 5,
height / 2 - (int)(height / 1.5) / 2 + height / 80 +
(height / 20 + height / 80) * (buttonIndex),
(int)(width / 5), (int)(height / 20)),
text1 = item.Key,
scale1 = 0.4f,
count = 0,
itemTextureName = itemInfo.textureName,
fontColor1 = Color.White,
mainColor = Color.Gray,
fontName1 = "Fonts\\Font3"
};
Elements.Add(temp);
temp.Initialize();
temp.LoadTexture(AppManager.Instance.Content);
ItemDisplayButtonsList.Add(temp);
buttonIndex++;
}
}
Button bTExit = new Button(Manager)
{
fontName = "Fonts\\Font3", scale = 0.4f, text = "<-", fontColor = Color.Black,
mainColor = Color.Transparent, rectangle = new Rectangle(width / 30, height / 30, width / 40, width / 40),
textureName = "Textures\\GUI\\checkboxs_off"
};
Elements.Add(bTExit);
bTExit.LeftButtonPressed += () => { AppManager.Instance.SetGUI(new MainMenuGUI()); };
} }
public override void Update(GameTime gameTime) public override void Update(GameTime gameTime)
{ {
base.Update(gameTime);
} }
} }

View file

@ -9,34 +9,27 @@ using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Input;
using MonogameLibrary.UI.Base; using MonogameLibrary.UI.Base;
using MonogameLibrary.UI.Elements; using MonogameLibrary.UI.Elements;
using ZoFo.GameCore.GameManagers;
namespace ZoFo.GameCore.GUI; namespace ZoFo.GameCore.GUI;
public class HUD : AbstractGUI public class HUD : AbstractGUI
{ {
private GraphicsDevice graphicsDevice;
public virtual void Initialize()
{
}
public virtual void LoadContent()
{
}
public virtual void Update(GameTime gameTime)
{
}
public virtual void Draw(SpriteBatch spriteBatch)
{
//Manager.Draw(spriteBatch);
}
protected override void CreateUI() protected override void CreateUI()
{ {
int width = AppManager.Instance.CurentScreenResolution.X;
int height = AppManager.Instance.CurentScreenResolution.Y;
Button pauseButton = new Button(Manager)
{ fontName = "Fonts\\Font3", scale = 0.4f, text = "| |", fontColor = Color.Black, mainColor = Color.Transparent, rectangle = new Rectangle(width / 30, height / 30, width / 40, width / 40), textureName = "Textures\\GUI\\checkboxs_off"};
Elements.Add(pauseButton);
pauseButton.LeftButtonPressed += () =>
{
AppManager.Instance.SetGUI(new PauseGUI());
};
}
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
} }
} }

View file

@ -44,9 +44,23 @@ public class MainMenuGUI : AbstractGUI
AppManager.Instance.SetGUI(new SelectModeMenu()); AppManager.Instance.SetGUI(new SelectModeMenu());
}; };
Elements.Add(playButton); Elements.Add(playButton);
Button optionButton = new Button(Manager) Button baseButton = new Button(Manager)
{ {
rectangle = new Rectangle(width / 2 - (int)(width / 10), height / 3 + (height / 20 + height / 40) * 2, (int)(width / 5), (int)(height / 20)), rectangle = new Rectangle(width / 2 - (int)(width / 10), height / 3 + (height / 20 + height / 40) * 2, (int)(width / 5), (int)(height / 20)),
text = "Base",
scale = 0.2f,
fontColor = Color.White,
mainColor = Color.Gray,
fontName = "Fonts\\Font"
};
baseButton.LeftButtonPressed += () =>
{
AppManager.Instance.SetGUI(new BaseGUI());
};
Elements.Add(baseButton);
Button optionButton = new Button(Manager)
{
rectangle = new Rectangle(width / 2 - (int)(width / 10), height / 3 + (height / 20 + height / 40) * 3, (int)(width / 5), (int)(height / 20)),
text = "Options", text = "Options",
scale = 0.2f, scale = 0.2f,
fontColor = Color.White, fontColor = Color.White,
@ -61,7 +75,7 @@ public class MainMenuGUI : AbstractGUI
Elements.Add(optionButton); Elements.Add(optionButton);
Button exitButton = new Button(Manager) Button exitButton = new Button(Manager)
{ {
rectangle = new Rectangle(width / 2 - (int)(width / 10), height / 3 + (height / 20 + height / 40) * 3, (int)(width / 5), (int)(height / 20)), rectangle = new Rectangle(width / 2 - (int)(width / 10), height / 3 + (height / 20 + height / 40) * 4, (int)(width / 5), (int)(height / 20)),
text = "Exit", text = "Exit",
scale = 0.2f, scale = 0.2f,
fontColor = Color.White, fontColor = Color.White,

View file

@ -40,6 +40,7 @@ public class OptionsGUI : AbstractGUI
var slider_OverallVolume = new Slider(Manager) var slider_OverallVolume = new Slider(Manager)
{ rectangle = new Rectangle(width / 2, height / 3, width / 10, height / 20), indentation = 7, textureName = "Textures/GUI/Switch_backgrownd", MinValue = 0, MaxValue = 1 }; { rectangle = new Rectangle(width / 2, height / 3, width / 10, height / 20), indentation = 7, textureName = "Textures/GUI/Switch_backgrownd", MinValue = 0, MaxValue = 1 };
slider_OverallVolume.SetValue(AppManager.Instance.SettingsManager.MainVolume); slider_OverallVolume.SetValue(AppManager.Instance.SettingsManager.MainVolume);
label_OverallVolume_Percent.text = Math.Round(slider_OverallVolume.GetSliderValue * 100) + "%";
slider_OverallVolume.SliderChanged += (newVal) => slider_OverallVolume.SliderChanged += (newVal) =>
{ {
label_OverallVolume_Percent.text = Math.Round(slider_OverallVolume.GetSliderValue * 100) + "%"; label_OverallVolume_Percent.text = Math.Round(slider_OverallVolume.GetSliderValue * 100) + "%";
@ -60,6 +61,7 @@ public class OptionsGUI : AbstractGUI
var slider_MusicVolume = new Slider(Manager) var slider_MusicVolume = new Slider(Manager)
{ rectangle = new Rectangle(width / 2, height / 3 + (height / 20 + height / 40) * 1, width / 10, height / 20), indentation = 7, textureName = "Textures/GUI/Switch_backgrownd", MinValue = 0, MaxValue = 1 }; { rectangle = new Rectangle(width / 2, height / 3 + (height / 20 + height / 40) * 1, width / 10, height / 20), indentation = 7, textureName = "Textures/GUI/Switch_backgrownd", MinValue = 0, MaxValue = 1 };
slider_MusicVolume.SetValue(AppManager.Instance.SettingsManager.MusicVolume); slider_MusicVolume.SetValue(AppManager.Instance.SettingsManager.MusicVolume);
label_MusicVolume_Percent.text = Math.Round(slider_MusicVolume.GetSliderValue * 100) + "%";
slider_MusicVolume.SliderChanged += (newVal) => slider_MusicVolume.SliderChanged += (newVal) =>
{ {
label_MusicVolume_Percent.text = Math.Round(slider_MusicVolume.GetSliderValue * 100) + "%"; label_MusicVolume_Percent.text = Math.Round(slider_MusicVolume.GetSliderValue * 100) + "%";
@ -80,6 +82,7 @@ public class OptionsGUI : AbstractGUI
var slider_EffectsVolume = new Slider(Manager) var slider_EffectsVolume = new Slider(Manager)
{ rectangle = new Rectangle(width / 2, height / 3 + (height / 20 + height / 40) * 2, width / 10, height / 20), indentation = 7, textureName = "Textures/GUI/Switch_backgrownd", MinValue = 0, MaxValue = 1 }; { rectangle = new Rectangle(width / 2, height / 3 + (height / 20 + height / 40) * 2, width / 10, height / 20), indentation = 7, textureName = "Textures/GUI/Switch_backgrownd", MinValue = 0, MaxValue = 1 };
slider_EffectsVolume.SetValue(AppManager.Instance.SettingsManager.SoundEffectsVolume); slider_EffectsVolume.SetValue(AppManager.Instance.SettingsManager.SoundEffectsVolume);
label_EffectsVolume_Percent.text = Math.Round(slider_EffectsVolume.GetSliderValue * 100) + "%";
slider_EffectsVolume.SliderChanged += (newVal) => slider_EffectsVolume.SliderChanged += (newVal) =>
{ {
label_EffectsVolume_Percent.text = Math.Round(slider_EffectsVolume.GetSliderValue * 100) + "%"; label_EffectsVolume_Percent.text = Math.Round(slider_EffectsVolume.GetSliderValue * 100) + "%";

View file

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Xml;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MonogameLibrary.UI.Base;
using MonogameLibrary.UI.Elements;
using ZoFo.GameCore.GameManagers;
namespace ZoFo.GameCore.GUI;
public class PauseGUI : AbstractGUI
{
protected override void CreateUI()
{
int width = AppManager.Instance.CurentScreenResolution.X;
int height = AppManager.Instance.CurentScreenResolution.Y;
Button continueButton = new Button(Manager)
{
rectangle = new Rectangle(width / 2 - (int)(width / 10), height / 3 + height / 20 + height / 40, (int)(width / 5), (int)(height / 20)),
text = "Continue",
scale = 0.2f,
fontColor = Color.White,
mainColor = Color.Gray,
fontName = "Fonts\\Font"
};
continueButton.LeftButtonPressed += () =>
{
AppManager.Instance.SetGUI(new HUD());
};
Elements.Add(continueButton);
Button exitButton = new Button(Manager)
{
rectangle = new Rectangle(width / 2 - (int)(width / 10), height / 3 + (height / 20 + height / 40) * 2, (int)(width / 5), (int)(height / 20)),
text = "Exit",
scale = 0.2f,
fontColor = Color.White,
mainColor = Color.Gray,
fontName = "Fonts\\Font"
};
exitButton.LeftButtonPressed += () =>
{
AppManager.Instance.SetGUI(new MainMenuGUI());
};
Elements.Add(exitButton);
}
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
}
}

View file

@ -28,9 +28,10 @@ namespace ZoFo.GameCore.GameManagers
public GameState gamestate; public GameState gamestate;
public AbstractGUI currentGUI; public AbstractGUI currentGUI;
public DebugHUD debugHud; public DebugHUD debugHud;
public Point CurentScreenResolution = new Point(1920, 1080); public Point CurentScreenResolution;
public Client client; public Client client;
public Server server; public Server server;
public PlayerData playerData;
#region Managers #region Managers
@ -47,6 +48,7 @@ namespace ZoFo.GameCore.GameManagers
public AppManager() public AppManager()
{ {
_graphics = new GraphicsDeviceManager(this); _graphics = new GraphicsDeviceManager(this);
CurentScreenResolution = new Point(GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Width, GraphicsAdapter.DefaultAdapter.CurrentDisplayMode.Height);
SetResolution(CurentScreenResolution.X, CurentScreenResolution.Y); SetResolution(CurentScreenResolution.X, CurentScreenResolution.Y);
//FulscrreenSwitch(); //FulscrreenSwitch();
@ -54,6 +56,8 @@ namespace ZoFo.GameCore.GameManagers
Content.RootDirectory = "Content"; Content.RootDirectory = "Content";
IsMouseVisible = true; IsMouseVisible = true;
playerData = new PlayerData();
ItemManager = new ItemManager.ItemManager();
Instance = this; Instance = this;
InputManager = new InputManager(); InputManager = new InputManager();
SettingsManager = new SettingsManager(); SettingsManager = new SettingsManager();
@ -71,7 +75,9 @@ namespace ZoFo.GameCore.GameManagers
protected override void Initialize() protected override void Initialize()
{ {
currentGUI.Initialize(); currentGUI.Initialize();
debugHud.Initialize(); debugHud.Initialize();
ItemManager.Initialize();
base.Initialize(); base.Initialize();
@ -82,6 +88,10 @@ namespace ZoFo.GameCore.GameManagers
_spriteBatch = new SpriteBatch(GraphicsDevice); _spriteBatch = new SpriteBatch(GraphicsDevice);
debugHud.LoadContent(); debugHud.LoadContent();
currentGUI.LoadContent(); currentGUI.LoadContent();
ItemManager.LoadItemTextures();
animationBuilder = new AnimationBuilder(); animationBuilder = new AnimationBuilder();
animationBuilder.LoadAnimations(); animationBuilder.LoadAnimations();
GameObject.debugTexture = new Texture2D(GraphicsDevice, 1, 1); GameObject.debugTexture = new Texture2D(GraphicsDevice, 1, 1);
@ -121,7 +131,6 @@ namespace ZoFo.GameCore.GameManagers
GraphicsDevice.Clear(Color.CornflowerBlue); GraphicsDevice.Clear(Color.CornflowerBlue);
// Pointwrap // Pointwrap
_spriteBatch.Begin(samplerState: SamplerState.PointWrap); _spriteBatch.Begin(samplerState: SamplerState.PointWrap);
switch (gamestate) switch (gamestate)

View file

@ -11,10 +11,10 @@ namespace ZoFo.GameCore.GameManagers.ItemManager
{ {
//поля //поля
string tag; string tag;
string textureName; public string textureName;
Texture2D itemTexture; Texture2D itemTexture;
bool isCraftable; public bool isCraftable;
Dictionary<string, int> resourcesNeededToCraft; public Dictionary<string, int> resourcesNeededToCraft;
public ItemInfo (string tag) public ItemInfo (string tag)
{ {
this.tag = tag; this.tag = tag;

View file

@ -9,24 +9,30 @@ namespace ZoFo.GameCore.GameManagers.ItemManager
public class ItemManager public class ItemManager
{ {
//поля //поля
Dictionary<string, ItemInfo> tagItemPairs; public Dictionary<string, ItemInfo> tagItemPairs;
//методы //методы
ItemInfo GetItemInfo(string tag) public ItemInfo GetItemInfo(string tag)
{ {
return tagItemPairs.GetValueOrDefault(tag); return tagItemPairs[tag];
} }
void LoadItemTextures() public void LoadItemTextures()
{ {
foreach (var item in tagItemPairs) foreach (var item in tagItemPairs)
{ {
item.Value.LoadTexture(); item.Value.LoadTexture();
} }
} }
void Initialize() public void Initialize()
{ {
tagItemPairs.Add("Wood", new ItemInfo("Wood","Wood",false,null)); tagItemPairs = new Dictionary<string, ItemInfo>();
tagItemPairs.Add("Peeble", new ItemInfo("Peeble", "Peeble", false, null)); tagItemPairs.Add("wood", new ItemInfo("wood","Textures\\Test\\wood",false,null));
tagItemPairs.Add("Steel", new ItemInfo("Steel", "Steel", false, null)); tagItemPairs.Add("rock", new ItemInfo("rock", "Textures\\Test\\rock", false, null));
tagItemPairs.Add("steel", new ItemInfo("steel", "Textures\\Test\\steel", false, null));
tagItemPairs.Add("pickaxe", new ItemInfo("steel", "Textures\\Test\\pickaxe", true, new Dictionary<string, int>()
{
{"wood", 2},
{"Steel", 3}
}));
} }
} }

View file

@ -9,16 +9,42 @@ namespace ZoFo.GameCore.GameManagers.ItemManager
/// <summary> /// <summary>
/// Класс хранит информацю о количестве ресурсов у игрока /// Класс хранит информацю о количестве ресурсов у игрока
/// </summary> /// </summary>
internal class PlayerData public class PlayerData
{ {
Dictionary<string, int> items; public PlayerData()
{
LoadPlayerData();
}
public Dictionary<string, int> items;
/// <summary> /// <summary>
/// Принимает тэг и крафтит этот объект /// Принимает тэг и крафтит этот объект
/// </summary> /// </summary>
/// <param name="itemTag"></param> /// <param name="itemTag"></param>
public void CraftItem(string itemTag) public bool CraftItem(string itemTag)
{
Dictionary<string, int> needToCraft = AppManager.Instance.ItemManager.GetItemInfo(itemTag).resourcesNeededToCraft;
foreach (var item in needToCraft)
{
if (items[item.Key] < item.Value)
{
return false;
}
}
foreach (var item in needToCraft)
{
items[item.Key] -= item.Value;
}
return true;
}
public void LoadPlayerData()
{ {
//TODO //TODO
items = new Dictionary<string, int>();
items.Add("wood", 2);
items.Add("steel", 110);
items.Add("rock", 6);
} }
} }
} }