initial commit
This commit is contained in:
commit
613efe3be0
25 changed files with 1235 additions and 0 deletions
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
bin
|
||||||
|
obj
|
||||||
|
.vs
|
25
DangerousD.sln
Normal file
25
DangerousD.sln
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
|
||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 16
|
||||||
|
VisualStudioVersion = 16.0.30907.101
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DangerousD", "DangerousD\DangerousD.csproj", "{1FC12F81-0E55-4142-83BD-23496EF29DC6}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{1FC12F81-0E55-4142-83BD-23496EF29DC6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{1FC12F81-0E55-4142-83BD-23496EF29DC6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{1FC12F81-0E55-4142-83BD-23496EF29DC6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{1FC12F81-0E55-4142-83BD-23496EF29DC6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {54250E62-AA1F-4858-BA7A-76F41EB64904}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
15
DangerousD/Content/Content.mgcb
Normal file
15
DangerousD/Content/Content.mgcb
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
|
||||||
|
#----------------------------- Global Properties ----------------------------#
|
||||||
|
|
||||||
|
/outputDir:bin/$(Platform)
|
||||||
|
/intermediateDir:obj/$(Platform)
|
||||||
|
/platform:Windows
|
||||||
|
/config:
|
||||||
|
/profile:Reach
|
||||||
|
/compress:False
|
||||||
|
|
||||||
|
#-------------------------------- References --------------------------------#
|
||||||
|
|
||||||
|
|
||||||
|
#---------------------------------- Content ---------------------------------#
|
||||||
|
|
27
DangerousD/DangerousD.csproj
Normal file
27
DangerousD/DangerousD.csproj
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>WinExe</OutputType>
|
||||||
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
|
<PublishReadyToRun>false</PublishReadyToRun>
|
||||||
|
<TieredCompilation>false</TieredCompilation>
|
||||||
|
<UseWindowsForms>true</UseWindowsForms>
|
||||||
|
</PropertyGroup>
|
||||||
|
<PropertyGroup>
|
||||||
|
<ApplicationManifest>app.manifest</ApplicationManifest>
|
||||||
|
<ApplicationIcon>Icon.ico</ApplicationIcon>
|
||||||
|
</PropertyGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<TrimmerRootAssembly Include="Microsoft.Xna.Framework.Content.ContentTypeReader" Visible="false" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="MonoGame.Framework.WindowsDX" Version="3.8.0.1641" />
|
||||||
|
<PackageReference Include="MonoGame.Content.Builder.Task" Version="3.8.0.1641" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<MonoGameContentReference Include="Content\Content.mgcb" />
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="GameCore\GameObjects\" />
|
||||||
|
<Folder Include="GameCore\UI\" />
|
||||||
|
</ItemGroup>
|
||||||
|
</Project>
|
100
DangerousD/GameCore/AppManager.cs
Normal file
100
DangerousD/GameCore/AppManager.cs
Normal file
|
@ -0,0 +1,100 @@
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using Microsoft.Xna.Framework.Content;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
using DangerousD.GameCore.HUD;
|
||||||
|
|
||||||
|
namespace DangerousD.GameCore
|
||||||
|
{
|
||||||
|
enum GameState { Menu, Options, Lobby, Game }
|
||||||
|
public class AppManager : Game
|
||||||
|
{
|
||||||
|
private GraphicsDeviceManager _graphics;
|
||||||
|
private SpriteBatch _spriteBatch;
|
||||||
|
|
||||||
|
GameState gameState;
|
||||||
|
GameManager GameManager;
|
||||||
|
IHUD MenuGUI;
|
||||||
|
IHUD OptionsGUI;
|
||||||
|
IHUD LobbyGUI;
|
||||||
|
public AppManager()
|
||||||
|
{
|
||||||
|
_graphics = new GraphicsDeviceManager(this);
|
||||||
|
Content.RootDirectory = "Content";
|
||||||
|
IsMouseVisible = true;
|
||||||
|
|
||||||
|
|
||||||
|
gameState = GameState.Menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Initialize()
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
|
||||||
|
|
||||||
|
switch (gameState)
|
||||||
|
{
|
||||||
|
case GameState.Menu:
|
||||||
|
MenuGUI.Update();
|
||||||
|
break;
|
||||||
|
case GameState.Options:
|
||||||
|
OptionsGUI.Update();
|
||||||
|
break;
|
||||||
|
case GameState.Lobby:
|
||||||
|
LobbyGUI.Update();
|
||||||
|
break;
|
||||||
|
case GameState.Game:
|
||||||
|
GameManager.Update(gameTime);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
base.Update(gameTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Draw(GameTime gameTime)
|
||||||
|
{
|
||||||
|
GraphicsDevice.Clear(Color.CornflowerBlue);
|
||||||
|
|
||||||
|
switch (gameState)
|
||||||
|
{
|
||||||
|
case GameState.Menu:
|
||||||
|
MenuGUI.Draw(_spriteBatch);
|
||||||
|
break;
|
||||||
|
case GameState.Options:
|
||||||
|
OptionsGUI.Draw(_spriteBatch);
|
||||||
|
break;
|
||||||
|
case GameState.Lobby:
|
||||||
|
LobbyGUI.Draw(_spriteBatch);
|
||||||
|
break;
|
||||||
|
case GameState.Game:
|
||||||
|
GameManager.Draw(_spriteBatch);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
base.Draw(gameTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
20
DangerousD/GameCore/GameManager.cs
Normal file
20
DangerousD/GameCore/GameManager.cs
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace DangerousD.GameCore
|
||||||
|
{
|
||||||
|
class GameManager
|
||||||
|
{
|
||||||
|
public void Draw(SpriteBatch _spriteBatch)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
public void Update(GameTime gameTime)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
DangerousD/GameCore/GameObjects/GameObject.cs
Normal file
10
DangerousD/GameCore/GameObjects/GameObject.cs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace DangerousD.GameCore
|
||||||
|
{
|
||||||
|
class GameObject
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
10
DangerousD/GameCore/GraphicsComponent.cs
Normal file
10
DangerousD/GameCore/GraphicsComponent.cs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace DangerousD.GameCore
|
||||||
|
{
|
||||||
|
class GraphicsComponent
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
13
DangerousD/GameCore/HUD/IHUD.cs
Normal file
13
DangerousD/GameCore/HUD/IHUD.cs
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace DangerousD.GameCore.HUD
|
||||||
|
{
|
||||||
|
interface IHUD
|
||||||
|
{
|
||||||
|
void Update();
|
||||||
|
void Draw(SpriteBatch _spriteBatch);
|
||||||
|
}
|
||||||
|
}
|
10
DangerousD/GameCore/NetworkManager.cs
Normal file
10
DangerousD/GameCore/NetworkManager.cs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace DangerousD.GameCore
|
||||||
|
{
|
||||||
|
class NetworkManager
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
10
DangerousD/GameCore/SoundManager.cs
Normal file
10
DangerousD/GameCore/SoundManager.cs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace DangerousD.GameCore
|
||||||
|
{
|
||||||
|
class SoundManager
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
90
DangerousD/GameCore/UI/Base/MonoClassManagerUI.cs
Normal file
90
DangerousD/GameCore/UI/Base/MonoClassManagerUI.cs
Normal file
|
@ -0,0 +1,90 @@
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Content;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
using MonogameLibrary.UI.Elements;
|
||||||
|
using MonogameLibrary.UI.Interfaces;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Security.Cryptography.X509Certificates;
|
||||||
|
using static System.Net.Mime.MediaTypeNames;
|
||||||
|
|
||||||
|
namespace MonogameLibrary.UI.Base
|
||||||
|
{
|
||||||
|
public class MonoClassManagerUI
|
||||||
|
{
|
||||||
|
static Dictionary<int, List<MonoDrawableUI>> layerCollection;
|
||||||
|
public static GraphicsDevice MainGraphicsDevice { get { return _graphicsDevice; } }
|
||||||
|
public static ContentManager MainContent { get { return _content; } }
|
||||||
|
public static SpriteFont MainBaseFont { get { return _baseFont; } }
|
||||||
|
static GraphicsDevice _graphicsDevice;
|
||||||
|
static ContentManager _content;
|
||||||
|
static SpriteFont _baseFont;
|
||||||
|
public void InitManager(GraphicsDevice graphicsDevice, ContentManager content, string font)
|
||||||
|
{
|
||||||
|
_graphicsDevice = graphicsDevice;
|
||||||
|
_content = content;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_baseFont = _content.Load<SpriteFont>(font);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
layerCollection = new Dictionary<int, List<MonoDrawableUI>>();
|
||||||
|
for (int i = -10; i < 11; i++)
|
||||||
|
{
|
||||||
|
layerCollection.Add(i, new List<MonoDrawableUI>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public KeyboardState GetKeyboardState { get { return keyboardState; } }
|
||||||
|
static MouseState mouseState, prevmouseState;
|
||||||
|
static KeyboardState keyboardState;
|
||||||
|
public void Update(GameTime gameTime)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
keyboardState = Keyboard.GetState();
|
||||||
|
mouseState = Mouse.GetState();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
bool hasInteracted = false;
|
||||||
|
foreach (var collection in layerCollection)
|
||||||
|
{
|
||||||
|
foreach (var item in collection.Value)
|
||||||
|
{
|
||||||
|
if (item is IInteractable)
|
||||||
|
{
|
||||||
|
if (!hasInteracted)
|
||||||
|
{
|
||||||
|
hasInteracted = (item as IInteractable).InteractUpdate(mouseState, prevmouseState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
prevmouseState = mouseState;
|
||||||
|
}
|
||||||
|
public void Draw(SpriteBatch spriteBatch)
|
||||||
|
{
|
||||||
|
spriteBatch.Begin();
|
||||||
|
foreach (var collection in layerCollection)
|
||||||
|
{
|
||||||
|
foreach (var item in collection.Value)
|
||||||
|
{
|
||||||
|
item.Draw(spriteBatch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
spriteBatch.End();
|
||||||
|
}
|
||||||
|
public void Register(MonoDrawableUI monoDrawableUI, int layerIndex)
|
||||||
|
{
|
||||||
|
if (!layerCollection.ContainsKey(layerIndex))
|
||||||
|
layerCollection.Add(layerIndex, new List<MonoDrawableUI>());
|
||||||
|
|
||||||
|
layerCollection[layerIndex].Add(monoDrawableUI);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
109
DangerousD/GameCore/UI/Base/MonoDrawableTextedUI.cs
Normal file
109
DangerousD/GameCore/UI/Base/MonoDrawableTextedUI.cs
Normal file
|
@ -0,0 +1,109 @@
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using MonogameLibrary.UI.Enums;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace MonogameLibrary.UI.Base
|
||||||
|
{
|
||||||
|
public class MonoDrawableTextedUI : MonoDrawableUI
|
||||||
|
{
|
||||||
|
protected SpriteFont spriteFont;
|
||||||
|
public string text = "";
|
||||||
|
public float scale = 0.5f;
|
||||||
|
public Color fontColor = Color.Black;
|
||||||
|
public TextAligment textAligment = TextAligment.Center;
|
||||||
|
public MonoDrawableTextedUI(MonoClassManagerUI MyUIManager = null, int layerIndex = 0) : base(MyUIManager,layerIndex)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
public virtual void LoadTexture(string textureName = "", string font = "")
|
||||||
|
{
|
||||||
|
base.LoadTexture(textureName);
|
||||||
|
if (font != "")
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
spriteFont = MonoClassManagerUI.MainContent.Load<SpriteFont>(font);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public virtual void DrawText(SpriteBatch _spriteBatch)
|
||||||
|
{
|
||||||
|
if (text == "")
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (spriteFont != null)
|
||||||
|
{
|
||||||
|
var measured = spriteFont.MeasureString(text) * scale;
|
||||||
|
|
||||||
|
if (textAligment == TextAligment.Center)
|
||||||
|
{
|
||||||
|
Vector2 pos = rectangle.Location.ToVector2();
|
||||||
|
pos.Y += (int)((rectangle.Height - measured.Y) / 2);
|
||||||
|
pos.X += (int)((rectangle.Width - measured.X) / 2);
|
||||||
|
_spriteBatch.DrawString(spriteFont, text, pos, fontColor, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
|
||||||
|
}
|
||||||
|
else if (textAligment == TextAligment.Center)
|
||||||
|
{
|
||||||
|
Vector2 pos = rectangle.Location.ToVector2();
|
||||||
|
pos.Y += (int)((rectangle.Height - measured.Y) / 2);
|
||||||
|
pos.X += (int)(2 * scale);
|
||||||
|
_spriteBatch.DrawString(spriteFont, text, pos, fontColor, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Vector2 pos = rectangle.Location.ToVector2();
|
||||||
|
pos.Y += (int)((rectangle.Height - measured.Y) / 2);
|
||||||
|
pos.X += (int)(rectangle.Width - measured.X - 2 * scale);
|
||||||
|
_spriteBatch.DrawString(spriteFont, text, pos, fontColor, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var measured = MonoClassManagerUI.MainBaseFont.MeasureString(text) * scale;
|
||||||
|
measured.X -= measured.X % 10;
|
||||||
|
//measured.Y *= -1;
|
||||||
|
if (textAligment == TextAligment.Center)
|
||||||
|
{
|
||||||
|
Vector2 pos = rectangle.Location.ToVector2();
|
||||||
|
pos.Y += (int)((rectangle.Height - measured.Y) / 2);
|
||||||
|
pos.X += (int)((rectangle.Width - measured.X) / 2);
|
||||||
|
_spriteBatch.DrawString(MonoClassManagerUI.MainBaseFont, text, pos, fontColor, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
|
||||||
|
}
|
||||||
|
else if (textAligment == TextAligment.Left)
|
||||||
|
{
|
||||||
|
//var rct = new Rectangle(rectangle.Location, rectangle.Size);
|
||||||
|
//rct.Width = (int)measured.X;
|
||||||
|
//rct.Height = (int)measured.Y;
|
||||||
|
//rct.Y += (int)((rectangle.Height - measured.Y) / 2);
|
||||||
|
//rct.X += (int)((rectangle.Width - measured.X) / 2);
|
||||||
|
|
||||||
|
//_spriteBatch.Draw(texture, rct, new Color(255, 0, 0, 125));
|
||||||
|
//_spriteBatch.DrawString(MonoClassManagerUI.MainBaseFont, text, rct.Location.ToVector2(), fontColor, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Vector2 pos = rectangle.Location.ToVector2();
|
||||||
|
pos.Y += (int)((rectangle.Height - measured.Y) / 2);
|
||||||
|
pos.X += (int)(2 * scale);
|
||||||
|
_spriteBatch.DrawString(MonoClassManagerUI.MainBaseFont, text, pos, fontColor, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Vector2 pos = rectangle.Location.ToVector2();
|
||||||
|
pos.Y += (int)((rectangle.Height - measured.Y) / 2);
|
||||||
|
pos.X += (int)(rectangle.Width - measured.X - 2 * scale);
|
||||||
|
_spriteBatch.DrawString(MonoClassManagerUI.MainBaseFont, text, pos, fontColor, 0, Vector2.Zero, scale, SpriteEffects.None, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
47
DangerousD/GameCore/UI/Base/MonoDrawableUI.cs
Normal file
47
DangerousD/GameCore/UI/Base/MonoDrawableUI.cs
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
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;
|
||||||
|
|
||||||
|
namespace MonogameLibrary.UI.Base
|
||||||
|
{
|
||||||
|
public class MonoDrawableUI
|
||||||
|
{
|
||||||
|
protected Texture2D texture;
|
||||||
|
protected int layerIndex;
|
||||||
|
public Rectangle rectangle = new Rectangle(0, 0, 10, 10);
|
||||||
|
public Color mainColor = Color.White;
|
||||||
|
public MonoDrawableUI(MonoClassManagerUI MyUIManager = null, int layerIndex = 0)
|
||||||
|
{
|
||||||
|
MyUIManager.Register(this, layerIndex);
|
||||||
|
}
|
||||||
|
public void LoadTexture(string textureName)
|
||||||
|
{
|
||||||
|
if (textureName == "")
|
||||||
|
{
|
||||||
|
texture = new Texture2D(MonoClassManagerUI.MainGraphicsDevice, 1, 1);
|
||||||
|
texture.SetData<Color>(new Color[] { Color.White });
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
texture = MonoClassManagerUI.MainContent.Load<Texture2D>(textureName);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
texture = new Texture2D(MonoClassManagerUI.MainGraphicsDevice, 1, 1);
|
||||||
|
texture.SetData<Color>(new Color[] { Color.White });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public virtual void Draw(SpriteBatch _spriteBatch)
|
||||||
|
{
|
||||||
|
_spriteBatch.Draw(texture, rectangle, mainColor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
105
DangerousD/GameCore/UI/Compounds/BasicDrawableCompound.cs
Normal file
105
DangerousD/GameCore/UI/Compounds/BasicDrawableCompound.cs
Normal file
|
@ -0,0 +1,105 @@
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using MonogameLibrary.UI.Base;
|
||||||
|
using MonogameLibrary.UI.Elements;
|
||||||
|
using MonogameLibrary.UI.Enums;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Input;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace MonogameLibrary.UI.Compounds
|
||||||
|
{
|
||||||
|
public enum BasicDrawableCompound_Type { Vertical, Horizontal };
|
||||||
|
public class BasicDrawableCompound : MonoDrawableTextedUI
|
||||||
|
{
|
||||||
|
Dictionary<string, MonoDrawableTextedUI> drawables = new Dictionary<string, MonoDrawableTextedUI>();
|
||||||
|
public Vector2 lastPos;
|
||||||
|
Vector2 offset = new Vector2(10, 10);
|
||||||
|
public BasicDrawableCompound()
|
||||||
|
{
|
||||||
|
rectangle = new Rectangle(0, 0, 20, 20);
|
||||||
|
lastPos = new Vector2(0, offset.Y);
|
||||||
|
}
|
||||||
|
int mainWidth = 40;
|
||||||
|
public void Add(string name, MonoDrawableTextedUI element)
|
||||||
|
{
|
||||||
|
//var a = Assembly.GetExecutingAssembly().GetTypes();
|
||||||
|
//var b = a.Where(t => t.Get().Contains(type));
|
||||||
|
//var element = ((MonoDrawableTextedUI)Assembly.GetExecutingAssembly().GetTypes()
|
||||||
|
// .Where(t => t.GetInterfaces().Contains(type))
|
||||||
|
// .Select(x => Activator.CreateInstance(x) as ICommand).ToArray()[0]);
|
||||||
|
if (element is Slider)
|
||||||
|
{
|
||||||
|
element.rectangle = new Rectangle(0, 0, mainWidth * 3, 30);
|
||||||
|
}
|
||||||
|
if (element is Label)
|
||||||
|
{
|
||||||
|
element.rectangle = new Rectangle(0, 0, mainWidth * 2, 30);
|
||||||
|
}
|
||||||
|
if (element is TextBox)
|
||||||
|
{
|
||||||
|
element.rectangle = new Rectangle(0, 0, mainWidth * 2, 30);
|
||||||
|
}
|
||||||
|
if (element is Button)
|
||||||
|
{
|
||||||
|
element.rectangle = new Rectangle(0, 0, mainWidth, 30);
|
||||||
|
}
|
||||||
|
element.rectangle.Location = GetPositionOfElement(element).ToPoint();
|
||||||
|
if (drawables.ContainsKey(name))
|
||||||
|
{
|
||||||
|
int i = 1;
|
||||||
|
while (drawables.ContainsKey(name + $"({i})"))
|
||||||
|
{
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
name += $"({i})";
|
||||||
|
}
|
||||||
|
drawables.Add(name, element);
|
||||||
|
}
|
||||||
|
public Vector2 GetPositionOfElement(MonoDrawableTextedUI element)
|
||||||
|
{
|
||||||
|
Vector2 pos = lastPos + new Vector2(offset.X, 0);
|
||||||
|
lastPos = pos + new Vector2(element.rectangle.Width, 0);
|
||||||
|
if (lastPos.X>= rectangle.Width)
|
||||||
|
{
|
||||||
|
pos.X = offset.X;
|
||||||
|
pos.Y += offset.Y + element.rectangle.Height;
|
||||||
|
lastPos = pos + new Vector2(element.rectangle.Width, 0);
|
||||||
|
}
|
||||||
|
return rectangle.Location.ToVector2() + pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void LoadTexture(string textureName = "", string font = "")
|
||||||
|
{
|
||||||
|
base.LoadTexture(textureName);
|
||||||
|
if (font != "")
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
spriteFont = MonoClassManagerUI.MainContent.Load<SpriteFont>(font);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (var d in drawables)
|
||||||
|
{
|
||||||
|
d.Value.LoadTexture(font: font);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
public override void Draw(SpriteBatch _spriteBatch)
|
||||||
|
{
|
||||||
|
_spriteBatch.Draw(texture, rectangle, mainColor);
|
||||||
|
foreach (var d in drawables)
|
||||||
|
{
|
||||||
|
d.Value.Draw(_spriteBatch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
67
DangerousD/GameCore/UI/Elements/Button.cs
Normal file
67
DangerousD/GameCore/UI/Elements/Button.cs
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
using MonogameLibrary.UI.Base;
|
||||||
|
using MonogameLibrary.UI.Enums;
|
||||||
|
using MonogameLibrary.UI.Interfaces;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using static MonogameLibrary.UI.Elements.Button;
|
||||||
|
|
||||||
|
namespace MonogameLibrary.UI.Elements
|
||||||
|
{
|
||||||
|
public class Button : MonoDrawableTextedUI, IInteractable
|
||||||
|
{
|
||||||
|
public delegate void OnButtonPressed();
|
||||||
|
public event OnButtonPressed? RightButtonPressed;
|
||||||
|
public event OnButtonPressed? LeftButtonPressed;
|
||||||
|
protected HoverState hoverState = HoverState.None;
|
||||||
|
public bool InteractUpdate(MouseState mouseState, MouseState prevmouseState)
|
||||||
|
{
|
||||||
|
if (rectangle.Intersects(new Rectangle(mouseState.Position, Point.Zero)))
|
||||||
|
{
|
||||||
|
if (mouseState.LeftButton == ButtonState.Pressed || mouseState.RightButton == ButtonState.Pressed)
|
||||||
|
{
|
||||||
|
hoverState = HoverState.Pressing;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hoverState = HoverState.Hovering;
|
||||||
|
}
|
||||||
|
if (prevmouseState.LeftButton == ButtonState.Pressed)
|
||||||
|
{
|
||||||
|
if (mouseState.LeftButton != prevmouseState.LeftButton)
|
||||||
|
{
|
||||||
|
hoverState = HoverState.Pressing;
|
||||||
|
LeftButtonPressed?.Invoke();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(prevmouseState.RightButton == ButtonState.Pressed)
|
||||||
|
{
|
||||||
|
if (mouseState.RightButton != prevmouseState.RightButton)
|
||||||
|
{
|
||||||
|
RightButtonPressed?.Invoke();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hoverState = HoverState.None;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public override void Draw(SpriteBatch _spriteBatch)
|
||||||
|
{
|
||||||
|
if (hoverState == HoverState.None)
|
||||||
|
_spriteBatch.Draw(texture, rectangle, Color.White);
|
||||||
|
else if (hoverState == HoverState.Hovering)
|
||||||
|
_spriteBatch.Draw(texture, rectangle, new Color(211,211,211));
|
||||||
|
else
|
||||||
|
_spriteBatch.Draw(texture, rectangle, new Color(112, 128, 144));
|
||||||
|
DrawText(_spriteBatch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
66
DangerousD/GameCore/UI/Elements/CheckBox.cs
Normal file
66
DangerousD/GameCore/UI/Elements/CheckBox.cs
Normal file
|
@ -0,0 +1,66 @@
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
using MonogameLibrary.UI.Base;
|
||||||
|
using MonogameLibrary.UI.Enums;
|
||||||
|
using MonogameLibrary.UI.Interfaces;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace MonogameLibrary.UI.Elements
|
||||||
|
{
|
||||||
|
public class CheckBox : MonoDrawableTextedUI, IInteractable
|
||||||
|
{
|
||||||
|
public delegate void OnCheck(bool checkState);
|
||||||
|
public event OnCheck? Checked;
|
||||||
|
private bool isChecked;
|
||||||
|
HoverState hoverState = HoverState.None;
|
||||||
|
public bool GetChecked { get { return isChecked; } }
|
||||||
|
public bool InteractUpdate(MouseState mouseState, MouseState prevmouseState)
|
||||||
|
{
|
||||||
|
if (rectangle.Intersects(new Rectangle(mouseState.Position, Point.Zero)))
|
||||||
|
{
|
||||||
|
hoverState = HoverState.Hovering;
|
||||||
|
if (prevmouseState.LeftButton == ButtonState.Pressed)
|
||||||
|
{
|
||||||
|
hoverState = HoverState.Pressing;
|
||||||
|
if (mouseState.LeftButton != prevmouseState.LeftButton)
|
||||||
|
{
|
||||||
|
isChecked = !isChecked;
|
||||||
|
Checked?.Invoke(isChecked);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hoverState = HoverState.None;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public override void Draw(SpriteBatch _spriteBatch)
|
||||||
|
{
|
||||||
|
if (isChecked)
|
||||||
|
{
|
||||||
|
if (hoverState == HoverState.None)
|
||||||
|
_spriteBatch.Draw(texture, rectangle, new Color(124, 255, 0));
|
||||||
|
else if (hoverState == HoverState.Hovering)
|
||||||
|
_spriteBatch.Draw(texture, rectangle, new Color(124, 215, 0));
|
||||||
|
else
|
||||||
|
_spriteBatch.Draw(texture, rectangle, new Color(124, 175, 0));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (hoverState == HoverState.None)
|
||||||
|
_spriteBatch.Draw(texture, rectangle, new Color(255, 20, 0));
|
||||||
|
else if (hoverState == HoverState.Hovering)
|
||||||
|
_spriteBatch.Draw(texture, rectangle, new Color(215, 20, 0));
|
||||||
|
else
|
||||||
|
_spriteBatch.Draw(texture, rectangle, new Color(175, 20, 0));
|
||||||
|
}
|
||||||
|
DrawText(_spriteBatch);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
51
DangerousD/GameCore/UI/Elements/Label.cs
Normal file
51
DangerousD/GameCore/UI/Elements/Label.cs
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
using MonogameLibrary.UI.Base;
|
||||||
|
using MonogameLibrary.UI.Enums;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace MonogameLibrary.UI.Elements
|
||||||
|
{
|
||||||
|
public class Label : MonoDrawableTextedUI
|
||||||
|
{
|
||||||
|
|
||||||
|
protected HoverState hoverState = HoverState.None;
|
||||||
|
|
||||||
|
public virtual bool InteractUpdate(MouseState mouseState, MouseState prevmouseState)
|
||||||
|
{
|
||||||
|
if (rectangle.Intersects(new Rectangle(mouseState.Position, Point.Zero)))
|
||||||
|
{
|
||||||
|
if (mouseState.LeftButton == ButtonState.Pressed)
|
||||||
|
{
|
||||||
|
hoverState = HoverState.Pressing;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hoverState = HoverState.Hovering;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hoverState = HoverState.None;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public override void Draw(SpriteBatch _spriteBatch)
|
||||||
|
{
|
||||||
|
if (hoverState == HoverState.None)
|
||||||
|
{
|
||||||
|
_spriteBatch.Draw(texture, rectangle, new Color(235, 235, 235));
|
||||||
|
}
|
||||||
|
else if (hoverState == HoverState.Hovering)
|
||||||
|
_spriteBatch.Draw(texture, rectangle, new Color(211, 211, 211));
|
||||||
|
else
|
||||||
|
_spriteBatch.Draw(texture, rectangle, new Color(112, 128, 144));
|
||||||
|
DrawText(_spriteBatch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
71
DangerousD/GameCore/UI/Elements/Slider.cs
Normal file
71
DangerousD/GameCore/UI/Elements/Slider.cs
Normal file
|
@ -0,0 +1,71 @@
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
using MonogameLibrary.UI.Base;
|
||||||
|
using MonogameLibrary.UI.Enums;
|
||||||
|
using MonogameLibrary.UI.Interfaces;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace MonogameLibrary.UI.Elements
|
||||||
|
{
|
||||||
|
public class Slider : MonoDrawableTextedUI, IInteractable
|
||||||
|
{
|
||||||
|
public delegate void OnSliderChanges(float value);
|
||||||
|
public event OnSliderChanges? SliderChanged;
|
||||||
|
|
||||||
|
public Rectangle sliderRect = new Rectangle(0, 0, 30, 30);
|
||||||
|
private float sliderValue = 0;
|
||||||
|
private float minValue = 0, maxValue = 1;
|
||||||
|
SliderState sliderState = SliderState.None;
|
||||||
|
|
||||||
|
public float GetValue { get { return minValue + sliderValue * (maxValue - minValue); } }
|
||||||
|
public float GetSliderValue { get { return sliderValue; } }
|
||||||
|
public float MinValue { get { return minValue; } set { minValue = value; } }
|
||||||
|
public float MaxValue { get { return maxValue; } set { maxValue = value; } }
|
||||||
|
|
||||||
|
public bool InteractUpdate(MouseState mouseState, MouseState prevmouseState)
|
||||||
|
{
|
||||||
|
if (mouseState.LeftButton == ButtonState.Pressed)
|
||||||
|
{
|
||||||
|
if (sliderRect.Intersects(new Rectangle(mouseState.Position, Point.Zero)) ||
|
||||||
|
rectangle.Intersects(new Rectangle(mouseState.Position, Point.Zero)) ||
|
||||||
|
sliderState == SliderState.Moving)
|
||||||
|
{
|
||||||
|
sliderValue = Math.Clamp((mouseState.Position.X - rectangle.X - sliderRect.Width / 2f) / (rectangle.Width - sliderRect.Width), 0, 1);
|
||||||
|
sliderState = SliderState.Moving;
|
||||||
|
SliderChanged?.Invoke(GetValue);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (sliderRect.Intersects(new Rectangle(mouseState.Position, Point.Zero)))
|
||||||
|
{
|
||||||
|
sliderState = SliderState.HoveringOverSliderButton;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
sliderState = SliderState.None;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public void SetValue(float setvalue)
|
||||||
|
{
|
||||||
|
sliderValue = setvalue;
|
||||||
|
SliderChanged?.Invoke(GetValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Draw(SpriteBatch _spriteBatch)
|
||||||
|
{
|
||||||
|
base.Draw(_spriteBatch);
|
||||||
|
sliderRect.Location = rectangle.Location;
|
||||||
|
sliderRect.X += (int)(sliderValue * (rectangle.Width - sliderRect.Width));
|
||||||
|
sliderRect.Y -= sliderRect.Height / 2 - rectangle.Height / 2;
|
||||||
|
if (sliderState == SliderState.Moving)
|
||||||
|
_spriteBatch.Draw(texture, sliderRect, Color.DarkRed);
|
||||||
|
else if(sliderState == SliderState.HoveringOverSliderButton)
|
||||||
|
_spriteBatch.Draw(texture, sliderRect, new Color(200,0,0));
|
||||||
|
else
|
||||||
|
_spriteBatch.Draw(texture, sliderRect, Color.Red);
|
||||||
|
DrawText(_spriteBatch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
306
DangerousD/GameCore/UI/Elements/TextBox.cs
Normal file
306
DangerousD/GameCore/UI/Elements/TextBox.cs
Normal file
|
@ -0,0 +1,306 @@
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
using MonogameLibrary.UI.Base;
|
||||||
|
using MonogameLibrary.UI.Enums;
|
||||||
|
using MonogameLibrary.UI.Interfaces;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using static System.Net.Mime.MediaTypeNames;
|
||||||
|
|
||||||
|
namespace MonogameLibrary.UI.Elements
|
||||||
|
{
|
||||||
|
public class TextBox : MonoDrawableTextedUI, IInteractable
|
||||||
|
{
|
||||||
|
public delegate void OnTextChange(string text);
|
||||||
|
public event OnTextChange? TextChanged;
|
||||||
|
public event OnTextChange? StopChanging;
|
||||||
|
public event OnTextChange? OnEnter;
|
||||||
|
|
||||||
|
protected HoverState hoverState = HoverState.None;
|
||||||
|
protected IsSelected isSelected = IsSelected.NotSelected;
|
||||||
|
public bool shouldEndOnEnter;
|
||||||
|
|
||||||
|
public TextBox() : base()
|
||||||
|
{
|
||||||
|
OnEnter += (txt) => {
|
||||||
|
isSelected = IsSelected.NotSelected;
|
||||||
|
StopChanging?.Invoke(text);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public virtual bool InteractUpdate(MouseState mouseState, MouseState prevmouseState)
|
||||||
|
{
|
||||||
|
if (isSelected == IsSelected.Selected)
|
||||||
|
{
|
||||||
|
if (MonoClassManagerUI.GetKeyboardState.IsKeyDown(Keys.Enter))
|
||||||
|
{
|
||||||
|
OnEnter?.Invoke(text);
|
||||||
|
if (shouldEndOnEnter)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
InputManager.GetInput(ref text);
|
||||||
|
}
|
||||||
|
if (rectangle.Intersects(new Rectangle(mouseState.Position, Point.Zero)))
|
||||||
|
{
|
||||||
|
if (mouseState.LeftButton == ButtonState.Pressed)
|
||||||
|
{
|
||||||
|
hoverState = HoverState.Pressing;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hoverState = HoverState.Hovering;
|
||||||
|
}
|
||||||
|
if (prevmouseState.LeftButton == ButtonState.Pressed)
|
||||||
|
{
|
||||||
|
if (mouseState.LeftButton != prevmouseState.LeftButton)
|
||||||
|
{
|
||||||
|
hoverState = HoverState.Pressing;
|
||||||
|
isSelected = IsSelected.Selected;
|
||||||
|
TextChanged?.Invoke(text);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
if (mouseState.LeftButton == ButtonState.Pressed)
|
||||||
|
{
|
||||||
|
isSelected = IsSelected.NotSelected;
|
||||||
|
StopChanging?.Invoke(text);
|
||||||
|
}
|
||||||
|
|
||||||
|
hoverState = HoverState.None;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
public override void Draw(SpriteBatch _spriteBatch)
|
||||||
|
{
|
||||||
|
if (hoverState == HoverState.None)
|
||||||
|
{
|
||||||
|
if (isSelected == IsSelected.Selected)
|
||||||
|
_spriteBatch.Draw(texture, rectangle, new Color(220, 220, 220));
|
||||||
|
else
|
||||||
|
_spriteBatch.Draw(texture, rectangle, new Color(245, 245, 245));
|
||||||
|
}
|
||||||
|
else if (hoverState == HoverState.Hovering)
|
||||||
|
_spriteBatch.Draw(texture, rectangle, new Color(211, 211, 211));
|
||||||
|
else
|
||||||
|
_spriteBatch.Draw(texture, rectangle, new Color(112, 128, 144));
|
||||||
|
DrawText(_spriteBatch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//TODO: add translation
|
||||||
|
public static class InputManager
|
||||||
|
{
|
||||||
|
static List<Keys> pressed = new List<Keys>();
|
||||||
|
static float del = 0;
|
||||||
|
static bool isShiftPressed = false;
|
||||||
|
static bool isCTRLPressed = false;
|
||||||
|
static bool isALTPressed = false;
|
||||||
|
static bool isCAPSLOCKOn = false;
|
||||||
|
|
||||||
|
public static void GetInput(ref string text)
|
||||||
|
{
|
||||||
|
var state = MonoClassManagerUI.GetKeyboardState;
|
||||||
|
var keys = state.GetPressedKeys();
|
||||||
|
isShiftPressed = state.IsKeyDown(Keys.LeftShift) || state.IsKeyDown(Keys.RightShift);
|
||||||
|
isCTRLPressed = state.IsKeyDown(Keys.LeftControl) || state.IsKeyDown(Keys.RightControl);
|
||||||
|
isALTPressed = state.IsKeyDown(Keys.LeftAlt) || state.IsKeyDown(Keys.RightAlt);
|
||||||
|
for (int i = 0; i < pressed.Count; i++)
|
||||||
|
{
|
||||||
|
if (!keys.Contains(pressed[i]))
|
||||||
|
{
|
||||||
|
pressed.RemoveAt(i);
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (var key in keys)
|
||||||
|
{
|
||||||
|
//System.Diagnostics.Debug.WriteLine(key.ToString());
|
||||||
|
if (!pressed.Contains(key))
|
||||||
|
{
|
||||||
|
pressed.Add(key);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
string getPressed = KeyDecode(key);
|
||||||
|
if (getPressed != null)
|
||||||
|
{
|
||||||
|
text += getPressed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (key == Keys.Back)
|
||||||
|
{
|
||||||
|
if (text.Length > 0)
|
||||||
|
{
|
||||||
|
text = text.Remove(text.Length - 1);
|
||||||
|
del = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (key == Keys.CapsLock)
|
||||||
|
{
|
||||||
|
isCAPSLOCKOn = !isCAPSLOCKOn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
if (IsKeySpecial(key))
|
||||||
|
{
|
||||||
|
del++;
|
||||||
|
if (key == Keys.Back)
|
||||||
|
{
|
||||||
|
if (del>15)
|
||||||
|
{
|
||||||
|
if (text.Length > 0)
|
||||||
|
text = text.Remove(text.Length - 1);
|
||||||
|
del = 13;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static string KeyDecode(Keys key)
|
||||||
|
{
|
||||||
|
string str = null;
|
||||||
|
if ((int)key >= 65 && (int)key <= 90)
|
||||||
|
{
|
||||||
|
str = key.ToString();
|
||||||
|
}
|
||||||
|
else if ((int)key >= 48 && (int)key <= 57)
|
||||||
|
{
|
||||||
|
if (!isShiftPressed)
|
||||||
|
{
|
||||||
|
str = key.ToString().Trim('D');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
case Keys.D1:
|
||||||
|
return str = "!";
|
||||||
|
case Keys.D2:
|
||||||
|
return str = "@";
|
||||||
|
case Keys.D3:
|
||||||
|
return str = "#";
|
||||||
|
case Keys.D4:
|
||||||
|
return str = "$";
|
||||||
|
case Keys.D5:
|
||||||
|
return str = "%";
|
||||||
|
case Keys.D6:
|
||||||
|
return str = "^";
|
||||||
|
case Keys.D7:
|
||||||
|
return str = "&";
|
||||||
|
case Keys.D8:
|
||||||
|
return str = "*";
|
||||||
|
case Keys.D9:
|
||||||
|
return str = "(";
|
||||||
|
case Keys.D0:
|
||||||
|
return str = ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ((int)key >= 96 && (int)key <= 105)
|
||||||
|
{
|
||||||
|
str = key.ToString().Remove(0, 6);
|
||||||
|
}
|
||||||
|
if (str != null)
|
||||||
|
{
|
||||||
|
if ((!isShiftPressed && !isCAPSLOCKOn) || (isShiftPressed && isCAPSLOCKOn))
|
||||||
|
return str.ToLower();
|
||||||
|
else
|
||||||
|
return str.ToUpper();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (!isShiftPressed)
|
||||||
|
{
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
case Keys.Space:
|
||||||
|
return " ";
|
||||||
|
case Keys.OemTilde:
|
||||||
|
return "`";
|
||||||
|
case Keys.Enter:
|
||||||
|
return "\n";
|
||||||
|
case Keys.OemPipe:
|
||||||
|
return "\\";
|
||||||
|
case Keys.OemPlus:
|
||||||
|
return "=";
|
||||||
|
case Keys.OemMinus:
|
||||||
|
return "-";
|
||||||
|
|
||||||
|
|
||||||
|
case Keys.OemComma:
|
||||||
|
return ",";
|
||||||
|
case Keys.OemQuestion:
|
||||||
|
return ".";
|
||||||
|
case Keys.OemPeriod:
|
||||||
|
return "/";
|
||||||
|
case Keys.OemSemicolon:
|
||||||
|
return ";";
|
||||||
|
case Keys.OemQuotes:
|
||||||
|
return "'";
|
||||||
|
case Keys.OemOpenBrackets:
|
||||||
|
return "[";
|
||||||
|
case Keys.OemCloseBrackets:
|
||||||
|
return "]";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
case Keys.Space:
|
||||||
|
return " ";
|
||||||
|
case Keys.OemTilde:
|
||||||
|
return "~";
|
||||||
|
case Keys.Enter:
|
||||||
|
return "\n";
|
||||||
|
case Keys.OemPipe:
|
||||||
|
return "|";
|
||||||
|
case Keys.OemPlus:
|
||||||
|
return "+";
|
||||||
|
case Keys.OemMinus:
|
||||||
|
return "_";
|
||||||
|
|
||||||
|
|
||||||
|
case Keys.OemComma:
|
||||||
|
return "<";
|
||||||
|
case Keys.OemQuestion:
|
||||||
|
return ">";
|
||||||
|
case Keys.OemPeriod:
|
||||||
|
return "?";
|
||||||
|
case Keys.OemSemicolon:
|
||||||
|
return ":";
|
||||||
|
case Keys.OemQuotes:
|
||||||
|
return "\"";
|
||||||
|
case Keys.OemOpenBrackets:
|
||||||
|
return "{";
|
||||||
|
case Keys.OemCloseBrackets:
|
||||||
|
return "}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//else if ((int)key >= 112 && (int)key <= 125)
|
||||||
|
//{
|
||||||
|
// return key.ToString().Trim('F');
|
||||||
|
//}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
public static bool IsKeySpecial(Keys key)
|
||||||
|
{
|
||||||
|
return (key == Keys.Back) || (key == Keys.Space);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
DangerousD/GameCore/UI/Enums/Enums.cs
Normal file
11
DangerousD/GameCore/UI/Enums/Enums.cs
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace MonogameLibrary.UI.Enums
|
||||||
|
{
|
||||||
|
public enum HoverState { None, Hovering, Pressing }
|
||||||
|
public enum SliderState { None, Moving, HoveringOverSliderButton }
|
||||||
|
public enum IsSelected { NotSelected, Selected }
|
||||||
|
public enum TextAligment { Center, Left, Right }
|
||||||
|
}
|
12
DangerousD/GameCore/UI/Interfaces/IInteractable.cs
Normal file
12
DangerousD/GameCore/UI/Interfaces/IInteractable.cs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace MonogameLibrary.UI.Interfaces
|
||||||
|
{
|
||||||
|
interface IInteractable
|
||||||
|
{
|
||||||
|
bool InteractUpdate(MouseState mouseState, MouseState prevmouseState);
|
||||||
|
}
|
||||||
|
}
|
BIN
DangerousD/Icon.ico
Normal file
BIN
DangerousD/Icon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 144 KiB |
14
DangerousD/Program.cs
Normal file
14
DangerousD/Program.cs
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace DangerousD
|
||||||
|
{
|
||||||
|
public static class Program
|
||||||
|
{
|
||||||
|
[STAThread]
|
||||||
|
static void Main()
|
||||||
|
{
|
||||||
|
using (var game = new AppManager())
|
||||||
|
game.Run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
43
DangerousD/app.manifest
Normal file
43
DangerousD/app.manifest
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
|
||||||
|
<assemblyIdentity version="1.0.0.0" name="DangerousD"/>
|
||||||
|
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
|
||||||
|
<security>
|
||||||
|
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||||
|
<requestedExecutionLevel level="asInvoker" uiAccess="false" />
|
||||||
|
</requestedPrivileges>
|
||||||
|
</security>
|
||||||
|
</trustInfo>
|
||||||
|
|
||||||
|
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
|
||||||
|
<application>
|
||||||
|
<!-- A list of the Windows versions that this application has been tested on and is
|
||||||
|
is designed to work with. Uncomment the appropriate elements and Windows will
|
||||||
|
automatically selected the most compatible environment. -->
|
||||||
|
|
||||||
|
<!-- Windows Vista -->
|
||||||
|
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />
|
||||||
|
|
||||||
|
<!-- Windows 7 -->
|
||||||
|
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />
|
||||||
|
|
||||||
|
<!-- Windows 8 -->
|
||||||
|
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />
|
||||||
|
|
||||||
|
<!-- Windows 8.1 -->
|
||||||
|
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />
|
||||||
|
|
||||||
|
<!-- Windows 10 -->
|
||||||
|
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
|
||||||
|
|
||||||
|
</application>
|
||||||
|
</compatibility>
|
||||||
|
|
||||||
|
<application xmlns="urn:schemas-microsoft-com:asm.v3">
|
||||||
|
<windowsSettings>
|
||||||
|
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/pm</dpiAware>
|
||||||
|
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">permonitorv2,permonitor</dpiAwareness>
|
||||||
|
</windowsSettings>
|
||||||
|
</application>
|
||||||
|
|
||||||
|
</assembly>
|
Loading…
Add table
Reference in a new issue