diff --git a/MonogameLibrary/UI/Elements/ItemDisplayLabel.cs b/MonogameLibrary/UI/Elements/ItemDisplayLabel.cs new file mode 100644 index 0000000..1e637fb --- /dev/null +++ b/MonogameLibrary/UI/Elements/ItemDisplayLabel.cs @@ -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(new Color[] { mainColor }); + } + else + { + try + { + itemTexture = content.Load(itemTextureName); + } + catch + { + itemTexture = new Texture2D(Manager.GraphicsDevice, 1, 1); + itemTexture.SetData(new Color[] { mainColor }); + } + } + } + + public override void Draw(SpriteBatch _spriteBatch) + { + base.Draw(_spriteBatch); + } +} \ No newline at end of file diff --git a/MonogameLibrary/UI/Elements/itemDisplayButton.cs b/MonogameLibrary/UI/Elements/itemDisplayButton.cs new file mode 100644 index 0000000..0a29c4f --- /dev/null +++ b/MonogameLibrary/UI/Elements/itemDisplayButton.cs @@ -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(new Color[] { mainColor }); + } + else + { + try + { + itemTexture = content.Load(itemTextureName); + } + catch + { + itemTexture = new Texture2D(Manager.GraphicsDevice, 1, 1); + itemTexture.SetData(new Color[] { mainColor }); + } + } + } + + public override void Draw(SpriteBatch _spriteBatch) + { + base.Draw(_spriteBatch); + } +} \ No newline at end of file diff --git a/ZoFo/Content/Content.mgcb b/ZoFo/Content/Content.mgcb index 8f1470a..3df811a 100644 --- a/ZoFo/Content/Content.mgcb +++ b/ZoFo/Content/Content.mgcb @@ -351,8 +351,8 @@ /processorParam:MakeSquare=False /processorParam:TextureFormat=Color /build:Textures/GUI/switch.png - -#begin Textures/icons/12.png + +#begin Textures/Test/pickaxe.webp /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -362,9 +362,10 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /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 /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -374,9 +375,11 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /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 /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -386,9 +389,11 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /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 /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -398,9 +403,11 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /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 /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -410,125 +417,7 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Textures/icons/22.png -#begin Textures/icons/5.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 +/build:Textures/TileSets/TilesetFloor.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 diff --git a/ZoFo/Content/Textures/GUI/background/base.png b/ZoFo/Content/Textures/GUI/background/base.png index 11cbac6..49a5fb7 100644 Binary files a/ZoFo/Content/Textures/GUI/background/base.png and b/ZoFo/Content/Textures/GUI/background/base.png differ diff --git a/ZoFo/Content/Textures/GUI/background/join.png b/ZoFo/Content/Textures/GUI/background/join.png index 6d45273..c0bb204 100644 Binary files a/ZoFo/Content/Textures/GUI/background/join.png and b/ZoFo/Content/Textures/GUI/background/join.png differ diff --git a/ZoFo/Content/Textures/GUI/background/mainMenu.png b/ZoFo/Content/Textures/GUI/background/mainMenu.png index a0778fb..7f7665c 100644 Binary files a/ZoFo/Content/Textures/GUI/background/mainMenu.png and b/ZoFo/Content/Textures/GUI/background/mainMenu.png differ diff --git a/ZoFo/Content/Textures/Test/pickaxe.webp b/ZoFo/Content/Textures/Test/pickaxe.webp new file mode 100644 index 0000000..549165d Binary files /dev/null and b/ZoFo/Content/Textures/Test/pickaxe.webp differ diff --git a/ZoFo/Content/Textures/Test/rock.jpg b/ZoFo/Content/Textures/Test/rock.jpg new file mode 100644 index 0000000..e4f78d7 Binary files /dev/null and b/ZoFo/Content/Textures/Test/rock.jpg differ diff --git a/ZoFo/Content/Textures/Test/steel.png b/ZoFo/Content/Textures/Test/steel.png new file mode 100644 index 0000000..ca6d643 Binary files /dev/null and b/ZoFo/Content/Textures/Test/steel.png differ diff --git a/ZoFo/Content/Textures/Test/wood.jpg b/ZoFo/Content/Textures/Test/wood.jpg new file mode 100644 index 0000000..983d6f5 Binary files /dev/null and b/ZoFo/Content/Textures/Test/wood.jpg differ diff --git a/ZoFo/GameCore/GUI/BaseGUI.cs b/ZoFo/GameCore/GUI/BaseGUI.cs index cb159db..0949412 100644 --- a/ZoFo/GameCore/GUI/BaseGUI.cs +++ b/ZoFo/GameCore/GUI/BaseGUI.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Threading; using System.Xml; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; @@ -9,20 +10,118 @@ using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using MonogameLibrary.UI.Base; using MonogameLibrary.UI.Elements; +using ZoFo.GameCore.GameManagers; +using ZoFo.GameCore.GameManagers.ItemManager; namespace ZoFo.GameCore.GUI; public class BaseGUI : AbstractGUI { + private DrawableUIElement menuBackground; + private List ItemDisplayButtonsList; + private int buttonIndex = 0; + private string textureName; + protected override void CreateUI() { - // int width = AppManager.Instance.inGameHUDHelperResolution.X; - // int height = AppManager.Instance.inGameHUDHelperResolution.Y; + ItemDisplayButtonsList = new List(); + int width = AppManager.Instance.CurentScreenResolution.X; + int height = AppManager.Instance.CurentScreenResolution.Y; + Dictionary playerItems = AppManager.Instance.playerData.items; + Dictionary 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) { - + base.Update(gameTime); } } \ No newline at end of file diff --git a/ZoFo/GameCore/GUI/HUD.cs b/ZoFo/GameCore/GUI/HUD.cs index a2b1892..745453a 100644 --- a/ZoFo/GameCore/GUI/HUD.cs +++ b/ZoFo/GameCore/GUI/HUD.cs @@ -9,34 +9,27 @@ 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 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); - } - +public class HUD : AbstractGUI +{ 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); } } \ No newline at end of file diff --git a/ZoFo/GameCore/GUI/MainMenuGUI.cs b/ZoFo/GameCore/GUI/MainMenuGUI.cs index 5d258eb..645faf8 100644 --- a/ZoFo/GameCore/GUI/MainMenuGUI.cs +++ b/ZoFo/GameCore/GUI/MainMenuGUI.cs @@ -44,9 +44,23 @@ public class MainMenuGUI : AbstractGUI AppManager.Instance.SetGUI(new SelectModeMenu()); }; 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)), + 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", scale = 0.2f, fontColor = Color.White, @@ -61,7 +75,7 @@ public class MainMenuGUI : AbstractGUI Elements.Add(optionButton); 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", scale = 0.2f, fontColor = Color.White, diff --git a/ZoFo/GameCore/GUI/OptionsGUI.cs b/ZoFo/GameCore/GUI/OptionsGUI.cs index 464da7d..39db371 100644 --- a/ZoFo/GameCore/GUI/OptionsGUI.cs +++ b/ZoFo/GameCore/GUI/OptionsGUI.cs @@ -40,6 +40,7 @@ public class OptionsGUI : AbstractGUI 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 }; slider_OverallVolume.SetValue(AppManager.Instance.SettingsManager.MainVolume); + label_OverallVolume_Percent.text = Math.Round(slider_OverallVolume.GetSliderValue * 100) + "%"; slider_OverallVolume.SliderChanged += (newVal) => { label_OverallVolume_Percent.text = Math.Round(slider_OverallVolume.GetSliderValue * 100) + "%"; @@ -60,6 +61,7 @@ public class OptionsGUI : AbstractGUI 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 }; slider_MusicVolume.SetValue(AppManager.Instance.SettingsManager.MusicVolume); + label_MusicVolume_Percent.text = Math.Round(slider_MusicVolume.GetSliderValue * 100) + "%"; slider_MusicVolume.SliderChanged += (newVal) => { label_MusicVolume_Percent.text = Math.Round(slider_MusicVolume.GetSliderValue * 100) + "%"; @@ -80,6 +82,7 @@ public class OptionsGUI : AbstractGUI 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 }; slider_EffectsVolume.SetValue(AppManager.Instance.SettingsManager.SoundEffectsVolume); + label_EffectsVolume_Percent.text = Math.Round(slider_EffectsVolume.GetSliderValue * 100) + "%"; slider_EffectsVolume.SliderChanged += (newVal) => { label_EffectsVolume_Percent.text = Math.Round(slider_EffectsVolume.GetSliderValue * 100) + "%"; diff --git a/ZoFo/GameCore/GUI/PauseGUI.cs b/ZoFo/GameCore/GUI/PauseGUI.cs new file mode 100644 index 0000000..d316fb7 --- /dev/null +++ b/ZoFo/GameCore/GUI/PauseGUI.cs @@ -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); + } +} \ No newline at end of file diff --git a/ZoFo/GameCore/GameManagers/AppManager.cs b/ZoFo/GameCore/GameManagers/AppManager.cs index b879078..b129359 100644 --- a/ZoFo/GameCore/GameManagers/AppManager.cs +++ b/ZoFo/GameCore/GameManagers/AppManager.cs @@ -28,9 +28,10 @@ namespace ZoFo.GameCore.GameManagers public GameState gamestate; public AbstractGUI currentGUI; public DebugHUD debugHud; - public Point CurentScreenResolution = new Point(1920, 1080); + public Point CurentScreenResolution; public Client client; public Server server; + public PlayerData playerData; #region Managers @@ -46,14 +47,17 @@ namespace ZoFo.GameCore.GameManagers 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); - // FulscrreenSwitch(); + //FulscrreenSwitch(); Content.RootDirectory = "Content"; IsMouseVisible = true; + playerData = new PlayerData(); + ItemManager = new ItemManager.ItemManager(); Instance = this; InputManager = new InputManager(); SettingsManager = new SettingsManager(); @@ -71,7 +75,9 @@ namespace ZoFo.GameCore.GameManagers protected override void Initialize() { currentGUI.Initialize(); - debugHud.Initialize(); + + debugHud.Initialize(); + ItemManager.Initialize(); base.Initialize(); @@ -81,11 +87,15 @@ namespace ZoFo.GameCore.GameManagers { _spriteBatch = new SpriteBatch(GraphicsDevice); debugHud.LoadContent(); - currentGUI.LoadContent(); + currentGUI.LoadContent(); + ItemManager.LoadItemTextures(); + + + animationBuilder = new AnimationBuilder(); animationBuilder.LoadAnimations(); GameObject.debugTexture = new Texture2D(GraphicsDevice, 1, 1); - GameObject.debugTexture.SetData(new Color[] { Color.White }); + GameObject.debugTexture.SetData(new Color[] { Color.White }); } protected override void Update(GameTime gameTime) @@ -119,11 +129,10 @@ namespace ZoFo.GameCore.GameManagers protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); - - + // Pointwrap - _spriteBatch.Begin(samplerState: SamplerState.PointWrap); + _spriteBatch.Begin(samplerState: SamplerState.PointWrap); switch (gamestate) { case GameState.ClientPlaying: @@ -135,7 +144,7 @@ namespace ZoFo.GameCore.GameManagers break; } - _spriteBatch.End(); + _spriteBatch.End(); currentGUI.Draw(_spriteBatch); debugHud.Draw(_spriteBatch); diff --git a/ZoFo/GameCore/GameManagers/ItemManager/ItemInfo.cs b/ZoFo/GameCore/GameManagers/ItemManager/ItemInfo.cs index cfd5a4f..6461dc6 100644 --- a/ZoFo/GameCore/GameManagers/ItemManager/ItemInfo.cs +++ b/ZoFo/GameCore/GameManagers/ItemManager/ItemInfo.cs @@ -11,10 +11,10 @@ namespace ZoFo.GameCore.GameManagers.ItemManager { //поля string tag; - string textureName; + public string textureName; Texture2D itemTexture; - bool isCraftable; - Dictionary resourcesNeededToCraft; + public bool isCraftable; + public Dictionary resourcesNeededToCraft; public ItemInfo (string tag) { this.tag = tag; diff --git a/ZoFo/GameCore/GameManagers/ItemManager/ItemManager.cs b/ZoFo/GameCore/GameManagers/ItemManager/ItemManager.cs index 9f7c724..3b982e6 100644 --- a/ZoFo/GameCore/GameManagers/ItemManager/ItemManager.cs +++ b/ZoFo/GameCore/GameManagers/ItemManager/ItemManager.cs @@ -9,24 +9,30 @@ namespace ZoFo.GameCore.GameManagers.ItemManager public class ItemManager { //поля - Dictionary tagItemPairs; + public Dictionary 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) { item.Value.LoadTexture(); } } - void Initialize() - { - tagItemPairs.Add("Wood", new ItemInfo("Wood","Wood",false,null)); - tagItemPairs.Add("Peeble", new ItemInfo("Peeble", "Peeble", false, null)); - tagItemPairs.Add("Steel", new ItemInfo("Steel", "Steel", false, null)); + public void Initialize() + { + tagItemPairs = new Dictionary(); + tagItemPairs.Add("wood", new ItemInfo("wood","Textures\\Test\\wood",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() + { + {"wood", 2}, + {"Steel", 3} + })); } } diff --git a/ZoFo/GameCore/GameManagers/ItemManager/PlayerData.cs b/ZoFo/GameCore/GameManagers/ItemManager/PlayerData.cs index 1dfc351..5a6c78e 100644 --- a/ZoFo/GameCore/GameManagers/ItemManager/PlayerData.cs +++ b/ZoFo/GameCore/GameManagers/ItemManager/PlayerData.cs @@ -9,16 +9,42 @@ namespace ZoFo.GameCore.GameManagers.ItemManager /// /// Класс хранит информацю о количестве ресурсов у игрока /// - internal class PlayerData + public class PlayerData { - Dictionary items; + public PlayerData() + { + LoadPlayerData(); + } + public Dictionary items; /// /// Принимает тэг и крафтит этот объект /// /// - public void CraftItem(string itemTag) + public bool CraftItem(string itemTag) + { + Dictionary 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 + items = new Dictionary(); + items.Add("wood", 2); + items.Add("steel", 110); + items.Add("rock", 6); } } }