diff --git a/MonogameLibrary/UI/Base/UIManager.cs b/MonogameLibrary/UI/Base/UIManager.cs index 826a0a1..125df25 100644 --- a/MonogameLibrary/UI/Base/UIManager.cs +++ b/MonogameLibrary/UI/Base/UIManager.cs @@ -59,8 +59,8 @@ namespace MonogameLibrary.UI.Base { keyboardState = Keyboard.GetState(); mouseState = Mouse.GetState(); - mouseState = new MouseState((int)(mouseState.X*(float)resolutionInGame.X/resolution.X), - (int)(mouseState.Y * (float)resolutionInGame.Y / resolution.Y), mouseState.ScrollWheelValue, mouseState.LeftButton, mouseState.MiddleButton, mouseState.RightButton, mouseState.XButton1, mouseState.XButton2); + //mouseState = new MouseState((int)(mouseState.X*(float)resolutionInGame.X/resolution.X), + // (int)(mouseState.Y * (float)resolutionInGame.Y / resolution.Y), mouseState.ScrollWheelValue, mouseState.LeftButton, mouseState.MiddleButton, mouseState.RightButton, mouseState.XButton1, mouseState.XButton2); } catch { diff --git a/ZoFo/Content/Content.mgcb b/ZoFo/Content/Content.mgcb index 44c7f84..4390819 100644 --- a/ZoFo/Content/Content.mgcb +++ b/ZoFo/Content/Content.mgcb @@ -13,14 +13,21 @@ #---------------------------------- Content ---------------------------------# -#begin Font/Font.spritefont +#begin Fonts/Font.spritefont /importer:FontDescriptionImporter /processor:FontDescriptionProcessor /processorParam:PremultiplyAlpha=True /processorParam:TextureFormat=Compressed -/build:Font/Font.spritefont +/build:Fonts/Font.spritefont -#begin Texture/GUI/MenuBackground.jpg +#begin Fonts/Font2.spritefont +/importer:FontDescriptionImporter +/processor:FontDescriptionProcessor +/processorParam:PremultiplyAlpha=True +/processorParam:TextureFormat=Compressed +/build:Fonts/Font2.spritefont + +#begin Textures/GUI/MenuBackground.jpg /importer:TextureImporter /processor:TextureProcessor /processorParam:ColorKeyColor=255,0,255,255 @@ -30,5 +37,5 @@ /processorParam:ResizeToPowerOfTwo=False /processorParam:MakeSquare=False /processorParam:TextureFormat=Color -/build:Texture/GUI/MenuBackground.jpg +/build:Textures/GUI/MenuBackground.jpg diff --git a/ZoFo/Content/Fonts/CarltineRegular-K7z5l.ttf b/ZoFo/Content/Fonts/CarltineRegular-K7z5l.ttf new file mode 100644 index 0000000..1496983 Binary files /dev/null and b/ZoFo/Content/Fonts/CarltineRegular-K7z5l.ttf differ diff --git a/ZoFo/Content/Font/Debrosee-ALPnL.ttf b/ZoFo/Content/Fonts/Debrosee-ALPnL.ttf similarity index 100% rename from ZoFo/Content/Font/Debrosee-ALPnL.ttf rename to ZoFo/Content/Fonts/Debrosee-ALPnL.ttf diff --git a/ZoFo/Content/Font/Font.spritefont b/ZoFo/Content/Fonts/Font.spritefont similarity index 98% rename from ZoFo/Content/Font/Font.spritefont rename to ZoFo/Content/Fonts/Font.spritefont index e6b9115..754d1ee 100644 --- a/ZoFo/Content/Font/Font.spritefont +++ b/ZoFo/Content/Fonts/Font.spritefont @@ -17,7 +17,7 @@ with. Size is a float value, measured in points. Modify this value to change the size of the font. --> - 12 + 100 + + + + + CarltineRegular-K7z5l.ttf + + + 15 + + + 0 + + + true + + + + + + + + + + + + ~ + + + + diff --git a/ZoFo/Content/Texture/GUI/MenuBackground.jpg b/ZoFo/Content/Textures/GUI/MenuBackground.jpg similarity index 100% rename from ZoFo/Content/Texture/GUI/MenuBackground.jpg rename to ZoFo/Content/Textures/GUI/MenuBackground.jpg diff --git a/ZoFo/Game1.cs b/ZoFo/Game1.cs deleted file mode 100644 index b9272db..0000000 --- a/ZoFo/Game1.cs +++ /dev/null @@ -1,52 +0,0 @@ -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using Microsoft.Xna.Framework.Input; - -namespace ZoFo; - -public class Game1 : Game -{ - private GraphicsDeviceManager _graphics; - private SpriteBatch _spriteBatch; - - public Game1() - { - _graphics = new GraphicsDeviceManager(this); - Content.RootDirectory = "Content"; - IsMouseVisible = true; - } - - protected override void Initialize() - { - // TODO: Add your initialization logic here - - base.Initialize(); - } - - protected override void LoadContent() - { - _spriteBatch = new SpriteBatch(GraphicsDevice); - - // TODO: use this.Content to load your game content here - } - - protected override void Update(GameTime gameTime) - { - if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || - Keyboard.GetState().IsKeyDown(Keys.Escape)) - Exit(); - - // TODO: Add your update logic here - - base.Update(gameTime); - } - - protected override void Draw(GameTime gameTime) - { - GraphicsDevice.Clear(Color.CornflowerBlue); - - // TODO: Add your drawing code here - - base.Draw(gameTime); - } -} \ No newline at end of file diff --git a/ZoFo/GameCore/GUI/AbstractGUI.cs b/ZoFo/GameCore/GUI/AbstractGUI.cs index 95ec020..2c2d7f6 100644 --- a/ZoFo/GameCore/GUI/AbstractGUI.cs +++ b/ZoFo/GameCore/GUI/AbstractGUI.cs @@ -41,7 +41,7 @@ public abstract class AbstractGUI public virtual void Update(GameTime gameTime) { - + Manager.Update(gameTime); } public virtual void Draw(SpriteBatch spriteBatch) diff --git a/ZoFo/GameCore/GUI/DebugHUD.cs b/ZoFo/GameCore/GUI/DebugHUD.cs index f735f7e..de4a587 100644 --- a/ZoFo/GameCore/GUI/DebugHUD.cs +++ b/ZoFo/GameCore/GUI/DebugHUD.cs @@ -1,6 +1,72 @@ -namespace ZoFo.GameCore.GUI; +using System.Collections.Generic; +using System.Linq; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using MonogameLibrary.UI.Elements; +using static System.String; +using ZoFo.GameCore.GameManagers; + +namespace ZoFo.GameCore.GUI; public class DebugHUD { - + private SpriteFont _spriteFont; + private Dictionary _text = new(); + private List _log = new(); + + public void Initialize() + { + } + + public void LoadContent() + { + _spriteFont = AppManager.Instance.Content.Load("Fonts\\Font2"); + } + + public void Update(GameTime gameTime) + { + } + + public void Draw(SpriteBatch spriteBatch) + { + var keysString = Join("\n", _text.Select(el => el.Key + ": " + el.Value).ToList()); + spriteBatch.Begin(); + spriteBatch.DrawString( + _spriteFont, + keysString, + new Vector2(10, 10), + Color.Cyan, + 0, + Vector2.Zero, + 1, + SpriteEffects.None, + 0 + ); + spriteBatch.DrawString( + _spriteFont, + Join("\n", _log), + new Vector2(10, 10 + _spriteFont.MeasureString(keysString).Y), + Color.Green, + 0, + Vector2.Zero, + 1, + SpriteEffects.None, + 0 + ); + spriteBatch.End(); + } + + public void Set(string key, string value) + { + _text[key] = value; + } + + public void Log(string value) + { + _log.Add(value); + if (_log.Count > 30) + { + _log.RemoveAt(0); + } + } } \ No newline at end of file diff --git a/ZoFo/GameCore/GUI/MainMenuGUI.cs b/ZoFo/GameCore/GUI/MainMenuGUI.cs index 98b0640..cb259c7 100644 --- a/ZoFo/GameCore/GUI/MainMenuGUI.cs +++ b/ZoFo/GameCore/GUI/MainMenuGUI.cs @@ -15,19 +15,68 @@ namespace ZoFo.GameCore.GUI; public class MainMenuGUI : AbstractGUI { - DrawableUIElement menuBackground; + private DrawableUIElement menuBackground; + Color mainBackgroundColor = Color.White; protected override void CreateUI() { int width = AppManager.Instance.CurentScreenResolution.X; int height = AppManager.Instance.CurentScreenResolution.Y; - menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, width, height), textureName = "Texture\\GUI\\MenuBackground" }; + menuBackground = new DrawableUIElement(Manager) { rectangle = new Rectangle(0, 0, width, height), mainColor = mainBackgroundColor, textureName = "Textures\\GUI\\MenuBackground" }; Elements.Add(menuBackground); menuBackground.LoadTexture(AppManager.Instance.Content); + + Elements.Add(new Label(Manager) { rectangle = new Rectangle(width / 2 - (int)(width / 8), height / 5, (int)(width / 4), (int)(height / 20)), text = "ZoFo", fontColor = Color.White, mainColor = Color.Transparent, scale = 0.9f, fontName = "Fonts\\Font"}); + + + Button playButton = new Button(Manager) + { + rectangle = new Rectangle(width / 2 - (int)(width / 10), height / 3 + height / 20 + height / 40, (int)(width / 5), (int)(height / 20)), + text = "Play", + scale = 0.2f, + fontColor = Color.White, + mainColor = Color.Gray, + fontName = "Fonts\\Font" + }; + playButton.LeftButtonPressed += () => + { + + }; + Elements.Add(playButton); + Button optionButton = 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 = "Options", + scale = 0.2f, + fontColor = Color.White, + mainColor = Color.Gray, + fontName = "Fonts\\Font" + }; + optionButton.LeftButtonPressed += () => + { + + }; + 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)), + text = "Exit", + scale = 0.2f, + fontColor = Color.White, + mainColor = Color.Gray, + fontName = "Fonts\\Font" + }; + exitButton.LeftButtonPressed += () => + { + AppManager.Instance.Exit(); + }; + 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 a6184d8..2cb6d1d 100644 --- a/ZoFo/GameCore/GameManagers/AppManager.cs +++ b/ZoFo/GameCore/GameManagers/AppManager.cs @@ -11,6 +11,7 @@ using Microsoft.Xna.Framework.Input; using ZoFo.GameCore.GameManagers.ItemManager; using ZoFo.GameCore.GUI; using static System.Collections.Specialized.BitVector32; +using MonogameLibrary.UI.Base; namespace ZoFo.GameCore.GameManagers { @@ -19,11 +20,13 @@ namespace ZoFo.GameCore.GameManagers { private GraphicsDeviceManager _graphics; private SpriteBatch _spriteBatch; - + + public static AppManager Instance { get; private set; } public GameState gamestate; public AbstractGUI currentGUI; + public DebugHUD debugHud; public Point CurentScreenResolution = new Point(1920, 1080); public Client client; public Server server; @@ -41,19 +44,27 @@ namespace ZoFo.GameCore.GameManagers public AppManager() { _graphics = new GraphicsDeviceManager(this); + SetResolution(CurentScreenResolution.X, CurentScreenResolution.Y); + FulscrreenSwitch(); + + Content.RootDirectory = "Content"; IsMouseVisible = true; Instance = this; InputManager = new InputManager(); + + currentGUI = new MainMenuGUI(); + debugHud = new DebugHUD(); } protected override void Initialize() { currentGUI.Initialize(); + debugHud.Initialize(); @@ -63,7 +74,8 @@ namespace ZoFo.GameCore.GameManagers protected override void LoadContent() { _spriteBatch = new SpriteBatch(GraphicsDevice); - + debugHud.LoadContent(); + currentGUI.LoadContent(); @@ -74,7 +86,9 @@ namespace ZoFo.GameCore.GameManagers if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) Exit(); - + + debugHud.Set("key", "value"); + InputManager.Update(); currentGUI.Update(gameTime); switch (gamestate) @@ -99,7 +113,9 @@ namespace ZoFo.GameCore.GameManagers { GraphicsDevice.Clear(Color.CornflowerBlue); + + debugHud.Draw(_spriteBatch); currentGUI.Draw(_spriteBatch); switch (gamestate) { @@ -127,5 +143,16 @@ namespace ZoFo.GameCore.GameManagers { //TODO } + + public void SetResolution(int x, int y) + { + _graphics.PreferredBackBufferWidth = x; + _graphics.PreferredBackBufferHeight = y; + } + + public void FulscrreenSwitch() + { + _graphics.IsFullScreen = !_graphics.IsFullScreen; + } } } diff --git a/ZoFo/GameCore/GameManagers/ItemManager/EquippableItemInfo.cs b/ZoFo/GameCore/GameManagers/ItemManager/EquippableItemInfo.cs new file mode 100644 index 0000000..5bffce5 --- /dev/null +++ b/ZoFo/GameCore/GameManagers/ItemManager/EquippableItemInfo.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ZoFo.GameCore.GameManagers.ItemManager +{ + class EquippableItemInfo : ItemInfo + { + bool IsEquiped; //экипирован ли предмет + public EquippableItemInfo(string tag) : base(tag) + { + + } + } +} diff --git a/ZoFo/GameCore/GameManagers/ItemManager/WeaponItemInfo.cs b/ZoFo/GameCore/GameManagers/ItemManager/WeaponItemInfo.cs index 9c464ca..3917575 100644 --- a/ZoFo/GameCore/GameManagers/ItemManager/WeaponItemInfo.cs +++ b/ZoFo/GameCore/GameManagers/ItemManager/WeaponItemInfo.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace ZoFo.GameCore.GameManagers.ItemManager { - class WeaponItemInfo:ItemInfo + class WeaponItemInfo: EquippableItemInfo { //поля float damage; diff --git a/ZoFo/ZoFo.csproj b/ZoFo/ZoFo.csproj index 70c8cbc..be7977b 100644 --- a/ZoFo/ZoFo.csproj +++ b/ZoFo/ZoFo.csproj @@ -27,7 +27,7 @@ - +