Skip to content

Commit

Permalink
Basic main menu
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkSuckerberg committed Oct 24, 2023
1 parent ec5df93 commit 8a2a31d
Show file tree
Hide file tree
Showing 10 changed files with 241 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "submodules/myra"]
path = submodules/myra
url = https://github.com/rds1983/Myra
6 changes: 6 additions & 0 deletions Blocktest.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
1 change: 1 addition & 0 deletions Blocktest/Blocktest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj"/>
<ProjectReference Include="..\submodules\myra\src\Myra\Myra.MonoGame.csproj"/>
</ItemGroup>
<ItemGroup>
<Folder Include="Content\Fonts\"/>
Expand Down
32 changes: 20 additions & 12 deletions Blocktest/BlocktestGame.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Blocktest.Block_System;
using Blocktest.Scenes;
using Myra;
using Shared.Code.Block_System;
namespace Blocktest;

Expand All @@ -11,26 +12,23 @@ public sealed class BlocktestGame : Game {
private GraphicsDeviceManager _graphics;

/// <inheritdoc />
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;
}

/// <inheritdoc />
protected override void Initialize() {
Expand All @@ -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
}

/// <inheritdoc />
Expand Down
2 changes: 1 addition & 1 deletion Blocktest/Code/Scenes/GameScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
73 changes: 73 additions & 0 deletions Blocktest/Code/Scenes/MainMenuScene.cs
Original file line number Diff line number Diff line change
@@ -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() { }
}
47 changes: 47 additions & 0 deletions Blocktest/Code/UI/ConnectionWindow.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
15 changes: 15 additions & 0 deletions Blocktest/Code/UI/DialogWindow.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
74 changes: 74 additions & 0 deletions Blocktest/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions submodules/myra
Submodule myra added at 3fea1a

0 comments on commit 8a2a31d

Please sign in to comment.