diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..bc1c6b9 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "submodules/myra"] + path = submodules/myra + url = https://github.com/rds1983/Myra diff --git a/Blocktest.sln b/Blocktest.sln index c492999..46eea1e 100644 --- a/Blocktest.sln +++ b/Blocktest.sln @@ -6,6 +6,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DedicatedServer", "Dedicate EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared", "Shared\Shared.csproj", "{391CA9CC-64C8-45C5-8902-4C7C718AB113}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Myra.MonoGame", "submodules\myra\src\Myra\Myra.MonoGame.csproj", "{48B9EA4E-5DFF-4206-87D3-C0776DA88F32}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -24,5 +26,9 @@ Global {391CA9CC-64C8-45C5-8902-4C7C718AB113}.Debug|Any CPU.Build.0 = Debug|Any CPU {391CA9CC-64C8-45C5-8902-4C7C718AB113}.Release|Any CPU.ActiveCfg = Release|Any CPU {391CA9CC-64C8-45C5-8902-4C7C718AB113}.Release|Any CPU.Build.0 = Release|Any CPU + {48B9EA4E-5DFF-4206-87D3-C0776DA88F32}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {48B9EA4E-5DFF-4206-87D3-C0776DA88F32}.Debug|Any CPU.Build.0 = Debug|Any CPU + {48B9EA4E-5DFF-4206-87D3-C0776DA88F32}.Release|Any CPU.ActiveCfg = Release|Any CPU + {48B9EA4E-5DFF-4206-87D3-C0776DA88F32}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/Blocktest/Blocktest.csproj b/Blocktest/Blocktest.csproj index 7add7a2..de01b55 100644 --- a/Blocktest/Blocktest.csproj +++ b/Blocktest/Blocktest.csproj @@ -29,6 +29,7 @@ + diff --git a/Blocktest/BlocktestGame.cs b/Blocktest/BlocktestGame.cs index 1fa26bd..e37455a 100644 --- a/Blocktest/BlocktestGame.cs +++ b/Blocktest/BlocktestGame.cs @@ -1,5 +1,6 @@ using Blocktest.Block_System; using Blocktest.Scenes; +using Myra; using Shared.Code.Block_System; namespace Blocktest; @@ -11,26 +12,23 @@ public sealed class BlocktestGame : Game { private GraphicsDeviceManager _graphics; /// - public BlocktestGame() { - _connect = false; - _graphics = new GraphicsDeviceManager(this); - Content.RootDirectory = "Content"; - IsMouseVisible = true; - TargetElapsedTime = TimeSpan.FromMilliseconds(16); - Window.AllowUserResizing = true; - } - - public BlocktestGame(string newIp) { - _connect = true; + public BlocktestGame(string? newIp = null) { + _connect = newIp != null; _ip = newIp; _graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; IsMouseVisible = true; Window.AllowUserResizing = true; TargetElapsedTime = TimeSpan.FromMilliseconds(16); + MyraEnvironment.Game = this; } public static ContentManager? ContentManager { get; private set; } + + public void SetScene(IScene newScene) { + _currentScene?.EndScene(); + _currentScene = newScene; + } /// protected override void Initialize() { @@ -42,7 +40,17 @@ protected override void Initialize() { protected override void LoadContent() { ContentManager = Content; BlockSpritesManager.LoadBlockSprites(); - _currentScene = new GameScene(this, _connect, _ip); + + if(_ip != null) { + SetScene(new GameScene(this, true, _ip)); + return; + } + +#if DEBUG + SetScene(new GameScene(this, _connect, _ip)); +#else + SetScene(new MainMenuScene(this)); +#endif } /// diff --git a/Blocktest/Code/Scenes/GameScene.cs b/Blocktest/Code/Scenes/GameScene.cs index 462ce33..215cbf2 100644 --- a/Blocktest/Code/Scenes/GameScene.cs +++ b/Blocktest/Code/Scenes/GameScene.cs @@ -152,7 +152,7 @@ public void Draw(GameTime gameTime, GraphicsDevice graphicsDevice) { Rectangle destinationRectangle = pixelPerfect ? GetPixelPerfectRect() : GetFitRect(); _camera.RenderLocation = destinationRectangle; - graphicsDevice.Clear(Color.DarkGray); + graphicsDevice.Clear(Color.Black); _spriteBatch.Begin(samplerState: pixelPerfect ? SamplerState.PointClamp : null); _spriteBatch.Draw(_camera.RenderTarget, destinationRectangle, Color.White); diff --git a/Blocktest/Code/Scenes/MainMenuScene.cs b/Blocktest/Code/Scenes/MainMenuScene.cs new file mode 100644 index 0000000..a4ac5ed --- /dev/null +++ b/Blocktest/Code/Scenes/MainMenuScene.cs @@ -0,0 +1,73 @@ +using Blocktest.UI; +using Myra; +using Myra.Graphics2D; +using Myra.Graphics2D.Brushes; +using Myra.Graphics2D.UI; + +namespace Blocktest.Scenes; + + +public class MainMenuScene : IScene { + private Desktop _desktop; + private VerticalStackPanel _mainMenu; + + public MainMenuScene(BlocktestGame game) { + _mainMenu = new VerticalStackPanel { + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + BorderThickness = new Thickness(1), + Background = new SolidBrush("#404040FF"), + Border = new SolidBrush("#1BA1E2FF") + }; + + var titleLabel = new Label { + Text = "Blocktest", + HorizontalAlignment = HorizontalAlignment.Center, + VerticalAlignment = VerticalAlignment.Center, + Padding = new Thickness(8) + }; + _mainMenu.Widgets.Add(titleLabel); + + var newGameButton = new TextButton { + Text = "New Game", + HorizontalAlignment = HorizontalAlignment.Stretch, + Padding = new Thickness(5) + }; + newGameButton.Click += (_, _) => { + game.SetScene(new GameScene(game, false, null)); + }; + _mainMenu.Widgets.Add(newGameButton); + + var connectButton = new TextButton { + Text = "Connect", + HorizontalAlignment = HorizontalAlignment.Stretch, + Padding = new Thickness(5) + }; + connectButton.Click += (_, _) => { + new ConnectionWindow(game).ShowModal(_desktop); + }; + _mainMenu.Widgets.Add(connectButton); + + var exitButton = new TextButton { + Text = "Exit", + HorizontalAlignment = HorizontalAlignment.Stretch, + Padding = new Thickness(5) + }; + exitButton.Click += (_, _) => { + game.Exit(); + }; + _mainMenu.Widgets.Add(exitButton); + + _desktop = new Desktop { Root = _mainMenu }; + } + + public void Update(GameTime gameTime) { } + + public void Draw(GameTime gameTime, GraphicsDevice graphicsDevice) { + graphicsDevice.Clear(Color.CadetBlue); + + _desktop.Render(); + } + + public void EndScene() { } +} \ No newline at end of file diff --git a/Blocktest/Code/UI/ConnectionWindow.cs b/Blocktest/Code/UI/ConnectionWindow.cs new file mode 100644 index 0000000..d096e9e --- /dev/null +++ b/Blocktest/Code/UI/ConnectionWindow.cs @@ -0,0 +1,47 @@ +using Blocktest.Scenes; +using Myra.Graphics2D; +using Myra.Graphics2D.UI; +#pragma warning disable CS0618 // Type or member is obsolete, I don't care about this warning since it works fine + +namespace Blocktest.UI; + +public class ConnectionWindow : Window { + public ConnectionWindow(BlocktestGame game) { + var windowGrid = new Grid { + RowSpacing = 8, + ColumnSpacing = 8 + }; + + var label1 = new Label { + Text = "Enter IP:", + Padding = new Thickness(5), + GridColumn = 0, + GridRow = 0 + }; + windowGrid.Widgets.Add(label1); + + var textBox = new TextBox { + Text = "127.0.0.1", + Padding = new Thickness(5), + GridColumn = 1, + GridRow = 0 + }; + windowGrid.Widgets.Add(textBox); + + var button = new TextButton { + Text = "Connect", + Padding = new Thickness(5), + GridColumn = 0, + GridRow = 1, + GridColumnSpan = 2, + HorizontalAlignment = HorizontalAlignment.Stretch + }; + + button.Click += (_, _) => { + game.SetScene(new GameScene(game, true, textBox.Text)); + }; + windowGrid.Widgets.Add(button); + + Content = windowGrid; + } +} \ No newline at end of file diff --git a/Blocktest/Code/UI/DialogWindow.cs b/Blocktest/Code/UI/DialogWindow.cs new file mode 100644 index 0000000..8a1081b --- /dev/null +++ b/Blocktest/Code/UI/DialogWindow.cs @@ -0,0 +1,15 @@ +using Myra.Graphics2D.UI; + +namespace Blocktest.UI; + +public sealed class DialogueWindow : Window { + public DialogueWindow(string title, string text) { + var label1 = new Label { + Text = text + }; + + + Title = title; + Content = label1; + } +} \ No newline at end of file diff --git a/Blocktest/packages.lock.json b/Blocktest/packages.lock.json index 259290e..f5f604f 100644 --- a/Blocktest/packages.lock.json +++ b/Blocktest/packages.lock.json @@ -26,11 +26,85 @@ "resolved": "2.2.0", "contentHash": "u06nYzGcXCBcnF7cRe8Xa0KxBxGx8grhujZmb3PUiMVbds8d/I6qJ+waGn0IeC7Tdwmt0P6l3v7MqdYog5rJQg==" }, + "AssetManagementBase": { + "type": "Transitive", + "resolved": "0.6.6", + "contentHash": "iIMu6/5Zcxr07hS58j2jK8RhyY6cZyqTl3ouaFc1YjnQRKaoGSPZdaO3ysok8JDO18FjS6d+/2pyuNsScn4l7A==" + }, + "Cyotek.Drawing.BitmapFont": { + "type": "Transitive", + "resolved": "2.0.4", + "contentHash": "iA6WehGVdMUuNbfsQQDq/Bt+mMd/OqHjiMUtKFLIQd/0pyYh4ehT7FEjTxN9/4OXNKQZsp9bAJgltP2nnswUJg==" + }, + "DdsKtxXna.MonoGame": { + "type": "Transitive", + "resolved": "0.4.2", + "contentHash": "e350xVdu1c4Ix6h5q8EqmDqUfol9lPpkw5geq1yuxfjf96eXQOE90ejxE/dtqbrMf7smDZ2hVPfUsAQVkadMuw==" + }, + "FontStashSharp.Base": { + "type": "Transitive", + "resolved": "1.1.8", + "contentHash": "4EthXSV0SR1fhL+Bab3qc5b7vZy090FI8zJbb2p1vOjXKwCTAgaX2F9HPKD6ywEou0VdNWl1Wy3d8X+jEEcLBg==" + }, + "FontStashSharp.MonoGame": { + "type": "Transitive", + "resolved": "1.3.0", + "contentHash": "8hB/cYyHmeEXL6sn5KIb0PDdTKdiDTM9euvBp5E4b4MlnheHxBSSRp9qog//5kQKUlwVHFkjf6V3iACP2KvZyg==", + "dependencies": { + "Cyotek.Drawing.BitmapFont": "2.0.4", + "FontStashSharp.Base": "1.1.8", + "FontStashSharp.Rasterizers.StbTrueTypeSharp": "1.1.8", + "StbImageSharp": "2.27.13" + } + }, + "FontStashSharp.Rasterizers.StbTrueTypeSharp": { + "type": "Transitive", + "resolved": "1.1.8", + "contentHash": "QtO7CQ41xa2zbbBagNVtUdNz2rankAFDDH1g9rkDqSkvqb6/2/rJG950nHmSY+j6rFWxcbOYzkZtB9OEwyHhAw==", + "dependencies": { + "FontStashSharp.Base": "1.1.8", + "StbTrueTypeSharp": "1.26.11" + } + }, + "info.lundin.math.dll": { + "type": "Transitive", + "resolved": "1.2.6", + "contentHash": "rCSUXUISKOmFkpEPd9wZJP9bHsyozEwvid3zO4gByG1QQX9IMAUZ8R9OZmpKp20JWrBMGBMTgoXAuLCSoK6VAQ==" + }, + "StbImageSharp": { + "type": "Transitive", + "resolved": "2.27.13", + "contentHash": "tHnP2RHgFzWbOS96UqvRO/LYU1WmpMT1bKiig45we+rpaXacBr11Fq2IBF+MqlgyLyNXxRz18E66qr4R9YlSbg==" + }, + "StbTrueTypeSharp": { + "type": "Transitive", + "resolved": "1.26.11", + "contentHash": "3AFGjLBGUnUGMEMNMiFrHdsG7bLk/PIJqMgxUN57Wbv0OPTYQqHHG8O0W1bOArcc+/xDsCMHiK5CRCzw8F/2kg==" + }, + "XNAssets.MonoGame": { + "type": "Transitive", + "resolved": "0.6.7", + "contentHash": "bRO+Obkw5w1OL4UkarTokvtlCAwSZGyfz0FjJtwhbnvspz4dhLQZcBMlSnORm4dsvyM2zKdqa8hVdptQ1qf/CQ==", + "dependencies": { + "AssetManagementBase": "0.6.6", + "Cyotek.Drawing.BitmapFont": "2.0.4", + "DdsKtxXna.MonoGame": "0.4.2", + "StbImageSharp": "2.27.13" + } + }, "YamlDotNet": { "type": "Transitive", "resolved": "13.7.0", "contentHash": "RKkoQSCyk/94N20SL3U15hWAqBVXHu+59upcPi8R2uhrcAalyVa4Y/vYdXQ7MXQ71Lut//DH0tLcYByAkGmXhA==" }, + "Myra": { + "type": "Project", + "dependencies": { + "FontStashSharp.MonoGame": "[1.3.0, )", + "XNAssets.MonoGame": "[0.6.7, )", + "info.lundin.math.dll": "[1.2.6, )" + } + }, "shared": { "type": "Project", "dependencies": { diff --git a/submodules/myra b/submodules/myra new file mode 160000 index 0000000..3fea1a4 --- /dev/null +++ b/submodules/myra @@ -0,0 +1 @@ +Subproject commit 3fea1a44b9bed2f594b610fddce7fa5c65d4491b