Initial version
|
@ -1,7 +1,9 @@
|
||||||
#----------------------------- Global Properties ----------------------------#
|
|
||||||
|
#----------------------------- Global Properties ----------------------------#
|
||||||
|
|
||||||
/outputDir:bin/$(Platform)
|
/outputDir:bin/$(Platform)
|
||||||
/intermediateDir:obj/$(Platform)
|
/intermediateDir:obj/$(Platform)
|
||||||
|
/platform:Windows
|
||||||
/config:
|
/config:
|
||||||
/profile:Reach
|
/profile:Reach
|
||||||
/compress:False
|
/compress:False
|
||||||
|
@ -10,3 +12,16 @@
|
||||||
|
|
||||||
|
|
||||||
#---------------------------------- Content ---------------------------------#
|
#---------------------------------- Content ---------------------------------#
|
||||||
|
|
||||||
|
#begin Fonts/Title.spritefont
|
||||||
|
/importer:FontDescriptionImporter
|
||||||
|
/processor:FontDescriptionProcessor
|
||||||
|
/processorParam:TextureFormat=Compressed
|
||||||
|
/build:Fonts/Title.spritefont
|
||||||
|
|
||||||
|
#begin Fonts/Normal.spritefont
|
||||||
|
/importer:FontDescriptionImporter
|
||||||
|
/processor:FontDescriptionProcessor
|
||||||
|
/processorParam:TextureFormat=Compressed
|
||||||
|
/build:Fonts/Normal.spritefont
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
This file contains an xml description of a font, and will be read by the XNA
|
||||||
|
Framework Content Pipeline. Follow the comments to customize the appearance
|
||||||
|
of the font in your game, and to change the characters which are available to draw
|
||||||
|
with.
|
||||||
|
-->
|
||||||
|
<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">
|
||||||
|
<Asset Type="Graphics:FontDescription">
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Modify this string to change the font that will be imported.
|
||||||
|
-->
|
||||||
|
<FontName>Cantarell</FontName>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Size is a float value, measured in points. Modify this value to change
|
||||||
|
the size of the font.
|
||||||
|
-->
|
||||||
|
<Size>12</Size>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Spacing is a float value, measured in pixels. Modify this value to change
|
||||||
|
the amount of spacing in between characters.
|
||||||
|
-->
|
||||||
|
<Spacing>0</Spacing>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
UseKerning controls the layout of the font. If this value is true, kerning information
|
||||||
|
will be used when placing characters.
|
||||||
|
-->
|
||||||
|
<UseKerning>true</UseKerning>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Style controls the style of the font. Valid entries are "Regular", "Bold", "Italic",
|
||||||
|
and "Bold, Italic", and are case sensitive.
|
||||||
|
-->
|
||||||
|
<Style>Regular</Style>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
If you uncomment this line, the default character will be substituted if you draw
|
||||||
|
or measure text that contains characters which were not included in the font.
|
||||||
|
-->
|
||||||
|
<!-- <DefaultCharacter>*</DefaultCharacter> -->
|
||||||
|
|
||||||
|
<!--
|
||||||
|
CharacterRegions control what letters are available in the font. Every
|
||||||
|
character from Start to End will be built and made available for drawing. The
|
||||||
|
default range is from 32, (ASCII space), to 126, ('~'), covering the basic Latin
|
||||||
|
character set. The characters are ordered according to the Unicode standard.
|
||||||
|
See the documentation for more information.
|
||||||
|
-->
|
||||||
|
<CharacterRegions>
|
||||||
|
<CharacterRegion>
|
||||||
|
<Start> </Start>
|
||||||
|
<End>~</End>
|
||||||
|
</CharacterRegion>
|
||||||
|
</CharacterRegions>
|
||||||
|
</Asset>
|
||||||
|
</XnaContent>
|
|
@ -0,0 +1,60 @@
|
||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
This file contains an xml description of a font, and will be read by the XNA
|
||||||
|
Framework Content Pipeline. Follow the comments to customize the appearance
|
||||||
|
of the font in your game, and to change the characters which are available to draw
|
||||||
|
with.
|
||||||
|
-->
|
||||||
|
<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">
|
||||||
|
<Asset Type="Graphics:FontDescription">
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Modify this string to change the font that will be imported.
|
||||||
|
-->
|
||||||
|
<FontName>Cantarell</FontName>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Size is a float value, measured in points. Modify this value to change
|
||||||
|
the size of the font.
|
||||||
|
-->
|
||||||
|
<Size>32</Size>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Spacing is a float value, measured in pixels. Modify this value to change
|
||||||
|
the amount of spacing in between characters.
|
||||||
|
-->
|
||||||
|
<Spacing>0</Spacing>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
UseKerning controls the layout of the font. If this value is true, kerning information
|
||||||
|
will be used when placing characters.
|
||||||
|
-->
|
||||||
|
<UseKerning>true</UseKerning>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Style controls the style of the font. Valid entries are "Regular", "Bold", "Italic",
|
||||||
|
and "Bold, Italic", and are case sensitive.
|
||||||
|
-->
|
||||||
|
<Style>Regular</Style>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
If you uncomment this line, the default character will be substituted if you draw
|
||||||
|
or measure text that contains characters which were not included in the font.
|
||||||
|
-->
|
||||||
|
<!-- <DefaultCharacter>*</DefaultCharacter> -->
|
||||||
|
|
||||||
|
<!--
|
||||||
|
CharacterRegions control what letters are available in the font. Every
|
||||||
|
character from Start to End will be built and made available for drawing. The
|
||||||
|
default range is from 32, (ASCII space), to 126, ('~'), covering the basic Latin
|
||||||
|
character set. The characters are ordered according to the Unicode standard.
|
||||||
|
See the documentation for more information.
|
||||||
|
-->
|
||||||
|
<CharacterRegions>
|
||||||
|
<CharacterRegion>
|
||||||
|
<Start> </Start>
|
||||||
|
<End>~</End>
|
||||||
|
</CharacterRegion>
|
||||||
|
</CharacterRegions>
|
||||||
|
</Asset>
|
||||||
|
</XnaContent>
|
Before Width: | Height: | Size: 86 KiB |
After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 167 B |
Before Width: | Height: | Size: 306 B |
Before Width: | Height: | Size: 297 B |
Before Width: | Height: | Size: 167 B |
Before Width: | Height: | Size: 168 B |
Before Width: | Height: | Size: 173 B |
Before Width: | Height: | Size: 166 B |
Before Width: | Height: | Size: 305 B |
Before Width: | Height: | Size: 300 B |
|
@ -37,12 +37,42 @@
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Game1.cs" />
|
<Compile Include="MainGame.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="Icon.png" />
|
<None Include="Icon.png" />
|
||||||
|
<None Include="Content\Textures\Boxes\Button\2_1.png">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Include="Content\Textures\Boxes\Button\2_0.png">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Include="Content\Textures\Boxes\Button\2_2.png">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Include="Content\Textures\Boxes\Button\1_1.png">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Include="Content\Textures\Boxes\Button\1_0.png">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Include="Content\Textures\Boxes\Button\1_2.png">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Include="Content\Textures\Boxes\Button\0_1.png">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Include="Content\Textures\Boxes\Button\0_0.png">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Include="Content\Textures\Boxes\Button\0_2.png">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
<None Include="Content\Textures\Background.png">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="Icon.ico" />
|
<EmbeddedResource Include="Icon.ico" />
|
||||||
|
@ -85,6 +115,16 @@
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\MyMonoGameAddin\MyMonoGameAddin.csproj">
|
||||||
|
<Project>{FF4B3F52-D94E-4F54-A829-C1492B875267}</Project>
|
||||||
|
<Name>MyMonoGameAddin</Name>
|
||||||
|
</ProjectReference>
|
||||||
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Content\Textures\" />
|
||||||
|
<Folder Include="Content\Textures\Boxes\" />
|
||||||
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Content.Builder.targets" />
|
<Import Project="$(MSBuildExtensionsPath)\MonoGame\v3.0\MonoGame.Content.Builder.targets" />
|
||||||
</Project>
|
</Project>
|
|
@ -1,107 +1,123 @@
|
||||||
using System;
|
using System;
|
||||||
using MyMonoGameAddin;
|
using MyMonoGameAddin;
|
||||||
using MyMonoGameAddin.UI;
|
|
||||||
using MyMonoGameAddin.Inputs;
|
|
||||||
using Microsoft.Xna.Framework;
|
using Microsoft.Xna.Framework;
|
||||||
using Microsoft.Xna.Framework.Graphics;
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
using Microsoft.Xna.Framework.Input;
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace Exemple
|
namespace Exemple
|
||||||
{
|
{
|
||||||
/// <summary>
|
public class MainGame : Game
|
||||||
/// This is the main type for your game.
|
|
||||||
/// </summary>
|
|
||||||
public class Game1 : Game
|
|
||||||
{
|
{
|
||||||
|
enum GameState { Menu, Credit }
|
||||||
|
|
||||||
GraphicsDeviceManager graphics;
|
GraphicsDeviceManager graphics;
|
||||||
SpriteBatch spriteBatch;
|
SpriteBatch spriteBatch;
|
||||||
ResourcesManager resources;
|
ResourcesManager resources;
|
||||||
InputsManager inputs = new InputsManager();
|
InputsManager inputs;
|
||||||
|
UIManager ui;
|
||||||
|
|
||||||
Layout canvas = new Layout();
|
GameState state = GameState.Menu;
|
||||||
Image pointer;
|
|
||||||
|
|
||||||
const int ScreenWidth = 800;
|
string Github;
|
||||||
const int ScreenHeight = 600;
|
|
||||||
|
|
||||||
public Game1()
|
public MainGame()
|
||||||
{
|
{
|
||||||
graphics = new GraphicsDeviceManager(this);
|
graphics = new GraphicsDeviceManager(this);
|
||||||
graphics.PreferredBackBufferWidth = ScreenWidth;
|
|
||||||
graphics.PreferredBackBufferHeight = ScreenHeight;
|
Window.AllowUserResizing = true;
|
||||||
|
Window.AllowUserResizing = true;
|
||||||
|
Window.ClientSizeChanged += delegate
|
||||||
|
{
|
||||||
|
graphics.PreferredBackBufferWidth = Window.ClientBounds.Width;
|
||||||
|
graphics.PreferredBackBufferHeight = Window.ClientBounds.Height;
|
||||||
graphics.ApplyChanges();
|
graphics.ApplyChanges();
|
||||||
|
};
|
||||||
|
|
||||||
Content.RootDirectory = "Content";
|
Content.RootDirectory = "Content";
|
||||||
|
|
||||||
|
inputs = new InputsManager();
|
||||||
resources = new ResourcesManager(Content, GraphicsDevice);
|
resources = new ResourcesManager(Content, GraphicsDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Allows the game to perform any initialization it needs to before starting to run.
|
|
||||||
/// This is where it can query for any required services and load any non-graphic
|
|
||||||
/// related content. Calling base.Initialize will enumerate through any components
|
|
||||||
/// and initialize them as well.
|
|
||||||
/// </summary>
|
|
||||||
protected override void Initialize()
|
protected override void Initialize()
|
||||||
{
|
{
|
||||||
|
graphics.PreferredBackBufferWidth = 800;
|
||||||
|
graphics.PreferredBackBufferHeight = 600;
|
||||||
|
graphics.IsFullScreen = false;
|
||||||
|
graphics.ApplyChanges();
|
||||||
|
|
||||||
|
IsMouseVisible = true;
|
||||||
|
|
||||||
base.Initialize();
|
base.Initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// LoadContent will be called once per game and is the place to load
|
|
||||||
/// all of your content.
|
|
||||||
/// </summary>
|
|
||||||
protected override void LoadContent()
|
protected override void LoadContent()
|
||||||
{
|
{
|
||||||
// Create a new SpriteBatch, which can be used to draw textures.
|
|
||||||
spriteBatch = new SpriteBatch(GraphicsDevice);
|
spriteBatch = new SpriteBatch(GraphicsDevice);
|
||||||
|
|
||||||
//resources.LoadFont("basic");
|
resources.LoadFont("Normal");
|
||||||
|
resources.LoadFont("Title");
|
||||||
//resources.LoadSound("bip");
|
//resources.LoadSound("bip");
|
||||||
resources.LoadTexture("Background");
|
resources.LoadTexture("Background");
|
||||||
resources.LoadBox("Button");
|
resources.LoadBox("Button");
|
||||||
|
ui = new UIManager(spriteBatch, inputs, new Skin(resources.Boxes["Button"], resources.Fonts["Normal"], new Colors(Color.White, Color.LightGray, Color.DarkGray), new Colors(Color.Black, Color.Black, Color.White)));
|
||||||
|
|
||||||
BuildCanvas();
|
|
||||||
//TODO: use this.Content to load your game content here
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Allows the game to run logic such as updating the world,
|
|
||||||
/// checking for collisions, gathering input, and playing audio.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
|
||||||
protected override void Update(GameTime gameTime)
|
protected override void Update(GameTime gameTime)
|
||||||
{
|
{
|
||||||
inputs.Update();
|
inputs.Update();
|
||||||
// TODO: Add your update logic here
|
ui.Update();
|
||||||
|
|
||||||
base.Update(gameTime);
|
base.Update(gameTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// This is called when the game should draw itself.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="gameTime">Provides a snapshot of timing values.</param>
|
|
||||||
protected override void Draw(GameTime gameTime)
|
protected override void Draw(GameTime gameTime)
|
||||||
{
|
{
|
||||||
pointer.Transform.Position = inputs.Mouse.Position;
|
graphics.GraphicsDevice.Clear(Color.DarkGray);
|
||||||
|
|
||||||
graphics.GraphicsDevice.Clear(Color.Black);
|
|
||||||
|
|
||||||
//TODO: Add your drawing code here
|
|
||||||
spriteBatch.Begin();
|
spriteBatch.Begin();
|
||||||
|
ui.Texture(new Rectangle(10, 10, 200, 150), resources.Textures["Background"]);
|
||||||
|
switch (state)
|
||||||
|
{
|
||||||
|
case GameState.Credit:
|
||||||
|
ui.Box(new Rectangle(200, 100, graphics.PreferredBackBufferWidth - 400, graphics.PreferredBackBufferWidth - 200), new Colors(Color.LightGray, Color.White));
|
||||||
|
ui.Label(new Vector(graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight / 4), "By Sheychen", new Colors(Color.Red, Color.OrangeRed), null, UIManager.textAlign.centerCenter);
|
||||||
|
if (ui.Button(new Rectangle(graphics.PreferredBackBufferWidth / 2 - 100, graphics.PreferredBackBufferHeight / 2 - 100, 200, 40), "My website"))
|
||||||
|
{
|
||||||
|
Process.Start("https://sheychen.shost.ca");
|
||||||
|
}
|
||||||
|
if (ui.Button(new Rectangle(graphics.PreferredBackBufferWidth / 2 - 100, graphics.PreferredBackBufferHeight / 2 - 50, 200, 40), "Show on GitHub"))
|
||||||
|
{
|
||||||
|
Process.Start("https://github.com/sheychen290/MyMonoGame");
|
||||||
|
}
|
||||||
|
if (ui.Button(new Rectangle(graphics.PreferredBackBufferWidth / 2 - 100, graphics.PreferredBackBufferHeight / 2, 200, 40), "Back"))
|
||||||
|
{
|
||||||
|
state = GameState.Menu;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
canvas.Draw(spriteBatch, new Transform());
|
case GameState.Menu:
|
||||||
|
ui.Label(new Vector(graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight / 4), "MyMonoGameAddin", new Colors(Color.Black, Color.Green), resources.Fonts["Title"], UIManager.textAlign.centerCenter);
|
||||||
|
if (ui.TextField(new Vector(graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight / 2), ref Github, new Colors(Color.White, Color.WhiteSmoke, Color.LightGray), null, UIManager.textAlign.centerCenter, "Search on Github"))
|
||||||
|
{
|
||||||
|
Process.Start("https://github.com/search?q=" + Github);
|
||||||
|
Github = null;
|
||||||
|
}
|
||||||
|
if (ui.Button(new Rectangle(graphics.PreferredBackBufferWidth / 2 - 100, graphics.PreferredBackBufferHeight * 3 / 4 + 50, 200, 40), "About", null, new Colors(Color.Black, Color.Green)))
|
||||||
|
{
|
||||||
|
state = GameState.Credit;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
spriteBatch.End();
|
spriteBatch.End();
|
||||||
|
|
||||||
base.Draw(gameTime);
|
base.Draw(gameTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void BuildCanvas()
|
protected override void OnExiting(object sender, EventArgs args)
|
||||||
{
|
{
|
||||||
canvas.Children.Add(new Box(resources.Boxes["Button"], new Vector(10, 10), new Vector(100, 20), Color.White));
|
Process.GetCurrentProcess().Kill();
|
||||||
pointer = new Image(resources.Textures["Background"], new Vector(0, 0), new Vector(10, 10), Color.White);
|
base.OnExiting(sender, args);
|
||||||
canvas.Children.Add(pointer);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,11 +20,11 @@ namespace Exemple
|
||||||
static class Program
|
static class Program
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
private static Game1 game;
|
private static MainGame game;
|
||||||
|
|
||||||
internal static void RunGame()
|
internal static void RunGame()
|
||||||
{
|
{
|
||||||
game = new Game1();
|
game = new MainGame();
|
||||||
game.Run();
|
game.Run();
|
||||||
#if !__IOS__ && !__TVOS__
|
#if !__IOS__ && !__TVOS__
|
||||||
game.Dispose();
|
game.Dispose();
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
Copyright (c) 2017, Clement Bois
|
||||||
|
|
||||||
|
Copyright © 2017 Clement Bois <contact@sheychen.shost.ca>
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>
|
|
@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio 2012
|
# Visual Studio 2012
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Exemple", "Exemple\Exemple.csproj", "{9C18BB68-EFE3-4E53-8761-B780F2BA5C52}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Exemple", "Exemple\Exemple.csproj", "{9C18BB68-EFE3-4E53-8761-B780F2BA5C52}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyMonoGameAddin", "MyMonoGameAddin\MyMonoGameAddin.csproj", "{FF4B3F52-D94E-4F54-A829-C1492B875267}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|x86 = Debug|x86
|
Debug|x86 = Debug|x86
|
||||||
|
@ -13,5 +15,9 @@ Global
|
||||||
{9C18BB68-EFE3-4E53-8761-B780F2BA5C52}.Debug|x86.Build.0 = Debug|x86
|
{9C18BB68-EFE3-4E53-8761-B780F2BA5C52}.Debug|x86.Build.0 = Debug|x86
|
||||||
{9C18BB68-EFE3-4E53-8761-B780F2BA5C52}.Release|x86.ActiveCfg = Release|x86
|
{9C18BB68-EFE3-4E53-8761-B780F2BA5C52}.Release|x86.ActiveCfg = Release|x86
|
||||||
{9C18BB68-EFE3-4E53-8761-B780F2BA5C52}.Release|x86.Build.0 = Release|x86
|
{9C18BB68-EFE3-4E53-8761-B780F2BA5C52}.Release|x86.Build.0 = Release|x86
|
||||||
|
{FF4B3F52-D94E-4F54-A829-C1492B875267}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{FF4B3F52-D94E-4F54-A829-C1492B875267}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{FF4B3F52-D94E-4F54-A829-C1492B875267}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{FF4B3F52-D94E-4F54-A829-C1492B875267}.Release|x86.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
EndGlobal
|
EndGlobal
|
||||||
|
|
|
@ -4,8 +4,124 @@ using Microsoft.Xna.Framework.Graphics;
|
||||||
|
|
||||||
namespace MyMonoGameAddin
|
namespace MyMonoGameAddin
|
||||||
{
|
{
|
||||||
public struct BoxSprite
|
public class BoxTexture
|
||||||
{
|
{
|
||||||
public
|
public Texture2D[,] Textures = new Texture2D[3, 3];
|
||||||
|
|
||||||
|
public Texture2D top_left
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Textures[0, 0];
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
Textures[0, 0] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public Texture2D top_middle
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Textures[0, 1];
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
Textures[0, 1] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public Texture2D top_right
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Textures[0, 2];
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
Textures[0, 2] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public Texture2D middle_left
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Textures[1, 0];
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
Textures[1, 0] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public Texture2D middle_middle
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Textures[1, 1];
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
Textures[1, 1] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public Texture2D middle_right
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Textures[1, 2];
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
Textures[1, 2] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public Texture2D bottom_left
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Textures[2, 0];
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
Textures[2, 0] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public Texture2D bottom_middle
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Textures[2, 1];
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
Textures[2, 1] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public Texture2D bottom_right
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return Textures[2, 2];
|
||||||
|
}
|
||||||
|
set
|
||||||
|
{
|
||||||
|
Textures[2, 2] = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsCorrect()
|
||||||
|
{
|
||||||
|
if (Textures.GetLength(0) != 3 || Textures.GetLength(1) != 3)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
for (int x = 0; x < 3; x++)
|
||||||
|
{
|
||||||
|
for (int y = 0; y < 3; y++)
|
||||||
|
{
|
||||||
|
if (Textures[x, y] == null)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,48 @@
|
||||||
using System;
|
using Microsoft.Xna.Framework;
|
||||||
|
|
||||||
namespace MyMonoGameAddin
|
namespace MyMonoGameAddin
|
||||||
{
|
{
|
||||||
public class Colors
|
public class Colors
|
||||||
{
|
{
|
||||||
public Colors()
|
public Color Normal;
|
||||||
|
public Color Hover;
|
||||||
|
public Color Focus;
|
||||||
|
|
||||||
|
public Colors(Color color)
|
||||||
{
|
{
|
||||||
|
Normal = color;
|
||||||
|
Hover = color;
|
||||||
|
Focus = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Colors(Color normal, Color hover)
|
||||||
|
{
|
||||||
|
Normal = normal;
|
||||||
|
Hover = hover;
|
||||||
|
Focus = hover;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Colors(Color normal, Color hover, Color focus)
|
||||||
|
{
|
||||||
|
Normal = normal;
|
||||||
|
Hover = hover;
|
||||||
|
Focus = focus;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal Color Get(UIManager.State status)
|
||||||
|
{
|
||||||
|
switch (status)
|
||||||
|
{
|
||||||
|
case UIManager.State.Hover:
|
||||||
|
return Hover;
|
||||||
|
|
||||||
|
case UIManager.State.Focus:
|
||||||
|
case UIManager.State.Active:
|
||||||
|
return Focus;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return Normal;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,10 +0,0 @@
|
||||||
using System;
|
|
||||||
namespace MyMonoGameAddin
|
|
||||||
{
|
|
||||||
public class GUIManager
|
|
||||||
{
|
|
||||||
public GUIManager()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,10 +1,185 @@
|
||||||
using System;
|
using System.Collections.Generic;
|
||||||
|
using Input = Microsoft.Xna.Framework.Input;
|
||||||
|
|
||||||
namespace MyMonoGameAddin
|
namespace MyMonoGameAddin
|
||||||
{
|
{
|
||||||
|
public enum ButtonState { Released, Pressing, Pressed, Releasing }
|
||||||
|
|
||||||
public class InputsManager
|
public class InputsManager
|
||||||
{
|
{
|
||||||
public InputsManager()
|
public MouseManager Mouse;
|
||||||
|
public KeyboardManager Keyboard;
|
||||||
|
|
||||||
|
public InputsManager(bool mouse = true, bool keyboard = true)
|
||||||
{
|
{
|
||||||
|
Mouse = new MouseManager(mouse);
|
||||||
|
Keyboard = new KeyboardManager(keyboard);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
Mouse.Update();
|
||||||
|
Keyboard.Update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class KeyboardManager
|
||||||
|
{
|
||||||
|
public enum SpecialKeys { Control, Alt, Shift, Windows }
|
||||||
|
|
||||||
|
public bool Enable;
|
||||||
|
|
||||||
|
public KeyboardManager(bool enable = true) { Enable = enable; }
|
||||||
|
|
||||||
|
public Input.KeyboardState State { get { return nowKeyboardState; } }
|
||||||
|
Input.KeyboardState oldKeyboardState;
|
||||||
|
Input.KeyboardState nowKeyboardState;
|
||||||
|
|
||||||
|
public Input.Keys FirstKey { get { return nowKeyboardState.GetPressedKeys().Length > 0 ? nowKeyboardState.GetPressedKeys()[0] : Input.Keys.None; } }
|
||||||
|
|
||||||
|
public List<Input.Keys> Keys { get { return nowKeys; } }
|
||||||
|
List<Input.Keys> nowKeys = new List<Input.Keys>();
|
||||||
|
List<Input.Keys> oldKeys = new List<Input.Keys>();
|
||||||
|
|
||||||
|
public List<Input.Keys> PressingKeys { get { return _PressingKeys; } }
|
||||||
|
List<Input.Keys> _PressingKeys = new List<Input.Keys>();
|
||||||
|
|
||||||
|
public List<Input.Keys> ReleassingKeys { get { return _ReleassingKeys; } }
|
||||||
|
List<Input.Keys> _ReleassingKeys = new List<Input.Keys>();
|
||||||
|
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
if (Enable)
|
||||||
|
{
|
||||||
|
oldKeyboardState = nowKeyboardState;
|
||||||
|
nowKeyboardState = Input.Keyboard.GetState();
|
||||||
|
|
||||||
|
oldKeys = nowKeys;
|
||||||
|
nowKeys = new List<Input.Keys>(nowKeyboardState.GetPressedKeys());
|
||||||
|
|
||||||
|
_PressingKeys.Clear();
|
||||||
|
foreach (Input.Keys newKey in nowKeys)
|
||||||
|
{
|
||||||
|
if (!oldKeys.Contains(newKey))
|
||||||
|
_PressingKeys.Add(newKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
_ReleassingKeys.Clear();
|
||||||
|
foreach (Input.Keys oldKey in oldKeys)
|
||||||
|
{
|
||||||
|
if (!nowKeys.Contains(oldKey))
|
||||||
|
_ReleassingKeys.Add(oldKey);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsPressed(Input.Keys key)
|
||||||
|
{
|
||||||
|
return nowKeyboardState.IsKeyDown(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsPressed(SpecialKeys key)
|
||||||
|
{
|
||||||
|
switch (key)
|
||||||
|
{
|
||||||
|
case SpecialKeys.Control:
|
||||||
|
return IsPressed(Input.Keys.LeftControl) || IsPressed(Input.Keys.RightControl);
|
||||||
|
|
||||||
|
case SpecialKeys.Alt:
|
||||||
|
return IsPressed(Input.Keys.LeftAlt) || IsPressed(Input.Keys.RightAlt);
|
||||||
|
|
||||||
|
case SpecialKeys.Shift:
|
||||||
|
return IsPressed(Input.Keys.LeftShift) || IsPressed(Input.Keys.RightShift);
|
||||||
|
|
||||||
|
case SpecialKeys.Windows:
|
||||||
|
return IsPressed(Input.Keys.LeftWindows) || IsPressed(Input.Keys.RightWindows);
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ButtonState GetKeyState(Input.Keys key)
|
||||||
|
{
|
||||||
|
if (nowKeyboardState.IsKeyDown(key))
|
||||||
|
{
|
||||||
|
if (oldKeyboardState.IsKeyUp(key))
|
||||||
|
return ButtonState.Pressing;
|
||||||
|
|
||||||
|
return ButtonState.Pressed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (oldKeyboardState.IsKeyDown(key))
|
||||||
|
return ButtonState.Releasing;
|
||||||
|
|
||||||
|
return ButtonState.Released;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MouseManager
|
||||||
|
{
|
||||||
|
public bool Enable;
|
||||||
|
|
||||||
|
public MouseManager(bool enable = true) { Enable = enable; }
|
||||||
|
|
||||||
|
public Input.MouseState State { get { return nowMouseState; } }
|
||||||
|
Input.MouseState oldMouseState;
|
||||||
|
Input.MouseState nowMouseState;
|
||||||
|
|
||||||
|
public Vector Position { get { return new Vector(nowMouseState.X, nowMouseState.Y); } }
|
||||||
|
public int X { get { return nowMouseState.X; } }
|
||||||
|
public int Y { get { return nowMouseState.Y; } }
|
||||||
|
|
||||||
|
public bool LeftPressed { get { return nowMouseState.LeftButton == Input.ButtonState.Pressed; } }
|
||||||
|
public ButtonState LeftState { get { return GetState(nowMouseState.LeftButton, oldMouseState.LeftButton); } }
|
||||||
|
|
||||||
|
public bool RightPressed { get { return nowMouseState.RightButton == Input.ButtonState.Pressed; } }
|
||||||
|
public ButtonState RightState { get { return GetState(nowMouseState.RightButton, oldMouseState.RightButton); } }
|
||||||
|
|
||||||
|
public bool MiddlePressed { get { return nowMouseState.MiddleButton == Input.ButtonState.Pressed; } }
|
||||||
|
public ButtonState MiddleState { get { return GetState(nowMouseState.MiddleButton, oldMouseState.MiddleButton); } }
|
||||||
|
|
||||||
|
public int RelativeScroolWheel { get { return nowMouseState.ScrollWheelValue - oldMouseState.ScrollWheelValue; } }
|
||||||
|
public int AbsoluteScroolWheel { get { return nowMouseState.ScrollWheelValue; } }
|
||||||
|
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
if (Enable)
|
||||||
|
{
|
||||||
|
oldMouseState = nowMouseState;
|
||||||
|
nowMouseState = Input.Mouse.GetState();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetPosition(Vector v)
|
||||||
|
{
|
||||||
|
SetPositon(v.X, v.Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetPositon(int x, int y)
|
||||||
|
{
|
||||||
|
Input.Mouse.SetPosition(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ButtonState GetState(Input.ButtonState now, Input.ButtonState old)
|
||||||
|
{
|
||||||
|
if (now == Input.ButtonState.Pressed)
|
||||||
|
{
|
||||||
|
if (old == Input.ButtonState.Released)
|
||||||
|
return ButtonState.Pressing;
|
||||||
|
|
||||||
|
return ButtonState.Pressed;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (old == Input.ButtonState.Pressed)
|
||||||
|
return ButtonState.Releasing;
|
||||||
|
|
||||||
|
return ButtonState.Released;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,212 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.Xna.Framework.Input;
|
||||||
|
|
||||||
|
namespace MyMonoGameAddin
|
||||||
|
{
|
||||||
|
public static class KeyChar
|
||||||
|
{
|
||||||
|
public enum Layout { QWERTY, AZERTY }
|
||||||
|
|
||||||
|
static readonly Dictionary<Keys, CharPair>[] Data = new Dictionary<Keys, CharPair>[2]
|
||||||
|
{
|
||||||
|
new Dictionary<Keys, CharPair>() //QWERTY
|
||||||
|
{
|
||||||
|
{Keys.OemTilde, new CharPair('`','~')},
|
||||||
|
{Keys.D1, new CharPair('1','!')},
|
||||||
|
{Keys.D2, new CharPair('2','@')},
|
||||||
|
{Keys.D3, new CharPair('3','#')},
|
||||||
|
{Keys.D4, new CharPair('4','$')},
|
||||||
|
{Keys.D5, new CharPair('5','%')},
|
||||||
|
{Keys.D6, new CharPair('6','^')},
|
||||||
|
{Keys.D7, new CharPair('7','&')},
|
||||||
|
{Keys.D8, new CharPair('8','*')},
|
||||||
|
{Keys.D9, new CharPair('9','(')},
|
||||||
|
{Keys.D0, new CharPair('0',')')},
|
||||||
|
{Keys.OemMinus, new CharPair('-','_')},
|
||||||
|
{Keys.OemPlus, new CharPair('=','+')},
|
||||||
|
|
||||||
|
{Keys.Q, new CharPair('q','Q')},
|
||||||
|
{Keys.W, new CharPair('w','W')},
|
||||||
|
{Keys.E, new CharPair('e','E')},
|
||||||
|
{Keys.R, new CharPair('r','R')},
|
||||||
|
{Keys.T, new CharPair('t','T')},
|
||||||
|
{Keys.Y, new CharPair('y','Y')},
|
||||||
|
{Keys.U, new CharPair('u','U')},
|
||||||
|
{Keys.I, new CharPair('i','i')},
|
||||||
|
{Keys.O, new CharPair('o','O')},
|
||||||
|
{Keys.P, new CharPair('p','P')},
|
||||||
|
{Keys.OemOpenBrackets, new CharPair('[','{')},
|
||||||
|
{Keys.OemCloseBrackets, new CharPair(']','}')},
|
||||||
|
{Keys.OemPipe, new CharPair('\\','|')},
|
||||||
|
|
||||||
|
{Keys.A, new CharPair('a','A')},
|
||||||
|
{Keys.S, new CharPair('s','S')},
|
||||||
|
{Keys.D, new CharPair('d','D')},
|
||||||
|
{Keys.F, new CharPair('f','F')},
|
||||||
|
{Keys.G, new CharPair('g','G')},
|
||||||
|
{Keys.H, new CharPair('h','H')},
|
||||||
|
{Keys.J, new CharPair('j','J')},
|
||||||
|
{Keys.K, new CharPair('k','K')},
|
||||||
|
{Keys.L, new CharPair('l','L')},
|
||||||
|
{Keys.OemSemicolon, new CharPair(';',':')},
|
||||||
|
{Keys.OemQuotes, new CharPair('\'','"')},
|
||||||
|
|
||||||
|
{Keys.Z, new CharPair('z','Z')},
|
||||||
|
{Keys.X, new CharPair('x','X')},
|
||||||
|
{Keys.C, new CharPair('c','C')},
|
||||||
|
{Keys.V, new CharPair('v','V')},
|
||||||
|
{Keys.B, new CharPair('b','B')},
|
||||||
|
{Keys.N, new CharPair('n','N')},
|
||||||
|
{Keys.M, new CharPair('m','M')},
|
||||||
|
{Keys.OemComma, new CharPair(',','<')},
|
||||||
|
{Keys.OemPeriod, new CharPair('.','>')},
|
||||||
|
{Keys.OemQuestion, new CharPair('/','?')},
|
||||||
|
|
||||||
|
{Keys.NumPad1, new CharPair('1')},
|
||||||
|
{Keys.NumPad2, new CharPair('2')},
|
||||||
|
{Keys.NumPad3, new CharPair('3')},
|
||||||
|
{Keys.NumPad4, new CharPair('4')},
|
||||||
|
{Keys.NumPad5, new CharPair('5')},
|
||||||
|
{Keys.NumPad6, new CharPair('6')},
|
||||||
|
{Keys.NumPad7, new CharPair('7')},
|
||||||
|
{Keys.NumPad8, new CharPair('8')},
|
||||||
|
{Keys.NumPad9, new CharPair('9')},
|
||||||
|
{Keys.NumPad0, new CharPair('0')},
|
||||||
|
{Keys.Add, new CharPair('+')},
|
||||||
|
{Keys.Divide, new CharPair('/')},
|
||||||
|
{Keys.Multiply, new CharPair('*')},
|
||||||
|
{Keys.Subtract, new CharPair('-')},
|
||||||
|
{Keys.Decimal, new CharPair('.')},
|
||||||
|
|
||||||
|
{Keys.Space, new CharPair(' ')}
|
||||||
|
},
|
||||||
|
|
||||||
|
new Dictionary<Keys, CharPair>() //AZERTY
|
||||||
|
{
|
||||||
|
{Keys.OemTilde, new CharPair('²')},
|
||||||
|
{Keys.D1, new CharPair('&','1')},
|
||||||
|
{Keys.D2, new CharPair('é','2','~')},
|
||||||
|
{Keys.D3, new CharPair('"','3','#')},
|
||||||
|
{Keys.D4, new CharPair('\'','4','\'')},
|
||||||
|
{Keys.D5, new CharPair('(','5','[')},
|
||||||
|
{Keys.D6, new CharPair('-','6','|')},
|
||||||
|
{Keys.D7, new CharPair('è','7','`')},
|
||||||
|
{Keys.D8, new CharPair('_','8','\\')},
|
||||||
|
{Keys.D9, new CharPair('ç','9','^')},
|
||||||
|
{Keys.D0, new CharPair('à','0','@')},
|
||||||
|
{Keys.OemMinus, new CharPair(')','°',']')},
|
||||||
|
{Keys.OemPlus, new CharPair('=','+','}')},
|
||||||
|
|
||||||
|
{Keys.Q, new CharPair('a','A')},
|
||||||
|
{Keys.W, new CharPair('z','Z')},
|
||||||
|
{Keys.E, new CharPair('e','E')},
|
||||||
|
{Keys.R, new CharPair('r','R')},
|
||||||
|
{Keys.T, new CharPair('t','T')},
|
||||||
|
{Keys.Y, new CharPair('y','Y')},
|
||||||
|
{Keys.U, new CharPair('u','U')},
|
||||||
|
{Keys.I, new CharPair('i','i')},
|
||||||
|
{Keys.O, new CharPair('o','O')},
|
||||||
|
{Keys.P, new CharPair('p','P')},
|
||||||
|
{Keys.OemOpenBrackets, new CharPair('^','"')},
|
||||||
|
{Keys.OemCloseBrackets, new CharPair('$','£','ø')},
|
||||||
|
|
||||||
|
{Keys.A, new CharPair('q','Q')},
|
||||||
|
{Keys.S, new CharPair('s','S')},
|
||||||
|
{Keys.D, new CharPair('d','D')},
|
||||||
|
{Keys.F, new CharPair('f','F')},
|
||||||
|
{Keys.G, new CharPair('g','G')},
|
||||||
|
{Keys.H, new CharPair('h','H')},
|
||||||
|
{Keys.J, new CharPair('j','J')},
|
||||||
|
{Keys.K, new CharPair('k','K')},
|
||||||
|
{Keys.L, new CharPair('l','L')},
|
||||||
|
{Keys.OemSemicolon, new CharPair('m','M')},
|
||||||
|
{Keys.OemQuotes, new CharPair('ù','%')},
|
||||||
|
{Keys.OemPipe, new CharPair('*','µ')},
|
||||||
|
|
||||||
|
{Keys.Z, new CharPair('w','W')},
|
||||||
|
{Keys.X, new CharPair('x','X')},
|
||||||
|
{Keys.C, new CharPair('c','C')},
|
||||||
|
{Keys.V, new CharPair('v','V')},
|
||||||
|
{Keys.B, new CharPair('b','B')},
|
||||||
|
{Keys.N, new CharPair('n','N')},
|
||||||
|
{Keys.M, new CharPair(',','?')},
|
||||||
|
{Keys.OemComma, new CharPair(';','.')},
|
||||||
|
{Keys.OemPeriod, new CharPair(':','/')},
|
||||||
|
{Keys.OemQuestion, new CharPair('!','§')},
|
||||||
|
|
||||||
|
{Keys.NumPad1, new CharPair('1')},
|
||||||
|
{Keys.NumPad2, new CharPair('2')},
|
||||||
|
{Keys.NumPad3, new CharPair('3')},
|
||||||
|
{Keys.NumPad4, new CharPair('4')},
|
||||||
|
{Keys.NumPad5, new CharPair('5')},
|
||||||
|
{Keys.NumPad6, new CharPair('6')},
|
||||||
|
{Keys.NumPad7, new CharPair('7')},
|
||||||
|
{Keys.NumPad8, new CharPair('8')},
|
||||||
|
{Keys.NumPad9, new CharPair('9')},
|
||||||
|
{Keys.NumPad0, new CharPair('0')},
|
||||||
|
{Keys.Add, new CharPair('+')},
|
||||||
|
{Keys.Divide, new CharPair('/')},
|
||||||
|
{Keys.Multiply, new CharPair('*')},
|
||||||
|
{Keys.Subtract, new CharPair('-')},
|
||||||
|
{Keys.Decimal, new CharPair('.')},
|
||||||
|
|
||||||
|
{Keys.Space, new CharPair(' ')}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class CharPair
|
||||||
|
{
|
||||||
|
public CharPair(char normalChar, Nullable<char> shiftChar = null, Nullable<char> altChar = null)
|
||||||
|
{
|
||||||
|
NormalChar = normalChar;
|
||||||
|
ShiftChar = shiftChar;
|
||||||
|
AltChar = altChar;
|
||||||
|
}
|
||||||
|
|
||||||
|
public char NormalChar;
|
||||||
|
public Nullable<char> ShiftChar;
|
||||||
|
public Nullable<char> AltChar;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool KeyToChar(Keys key, bool shitKeyPressed, out Nullable<char> character, Layout layout = Layout.QWERTY, bool altKeyPressed = false)
|
||||||
|
{
|
||||||
|
bool result = false;
|
||||||
|
character = null;
|
||||||
|
CharPair charPair;
|
||||||
|
|
||||||
|
if (Data[(int)layout].TryGetValue(key, out charPair))
|
||||||
|
{
|
||||||
|
if (shitKeyPressed)
|
||||||
|
{
|
||||||
|
if (!altKeyPressed)
|
||||||
|
{
|
||||||
|
if (charPair.ShiftChar.HasValue)
|
||||||
|
{
|
||||||
|
character = charPair.ShiftChar.Value;
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (altKeyPressed)
|
||||||
|
{
|
||||||
|
if (charPair.AltChar.HasValue)
|
||||||
|
{
|
||||||
|
character = charPair.AltChar.Value;
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
character = charPair.NormalChar;
|
||||||
|
result = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -28,10 +28,21 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
|
<Reference Include="MonoGame.Framework">
|
||||||
|
<HintPath>..\..\..\..\..\..\..\usr\lib\mono\xbuild\MonoGame\v3.0\Assemblies\DesktopGL\MonoGame.Framework.dll</HintPath>
|
||||||
|
</Reference>
|
||||||
|
<Reference Include="System.Core" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="MyClass.cs" />
|
<Compile Include="ResourcesManager.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
|
<Compile Include="Vector.cs" />
|
||||||
|
<Compile Include="InputsManager.cs" />
|
||||||
|
<Compile Include="BoxTexture.cs" />
|
||||||
|
<Compile Include="UIManager.cs" />
|
||||||
|
<Compile Include="KeyChar.cs" />
|
||||||
|
<Compile Include="Colors.cs" />
|
||||||
|
<Compile Include="Skin.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
|
@ -1,10 +1,169 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Microsoft.Xna.Framework.Content;
|
||||||
|
using Microsoft.Xna.Framework.Audio;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
|
||||||
namespace MyMonoGameAddin
|
namespace MyMonoGameAddin
|
||||||
{
|
{
|
||||||
public class MyClass
|
public class ResourcesManager
|
||||||
{
|
{
|
||||||
public MyClass()
|
public enum KeyMode { path, file }
|
||||||
|
|
||||||
|
public Dictionary<string, SpriteFont> Fonts = new Dictionary<string, SpriteFont>();
|
||||||
|
public Dictionary<string, Texture2D> Textures = new Dictionary<string, Texture2D>();
|
||||||
|
public Dictionary<string, SoundEffect> Sounds = new Dictionary<string, SoundEffect>();
|
||||||
|
public Dictionary<string, BoxTexture> Boxes = new Dictionary<string, BoxTexture>();
|
||||||
|
|
||||||
|
ContentManager Content;
|
||||||
|
GraphicsDevice Graphics;
|
||||||
|
|
||||||
|
public ResourcesManager(ContentManager content, GraphicsDevice graphics)
|
||||||
{
|
{
|
||||||
|
Content = content;
|
||||||
|
Graphics = graphics;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadFont(string assetname, KeyMode keymode = KeyMode.file, bool fullpath = false)
|
||||||
|
{
|
||||||
|
string keyname;
|
||||||
|
if (keymode == KeyMode.file)
|
||||||
|
{
|
||||||
|
string[] split = assetname.Split('/');
|
||||||
|
keyname = split[split.Length - 1];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
keyname = assetname;
|
||||||
|
}
|
||||||
|
LoadFont(keyname, assetname, fullpath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadFont(string keyname, string path, bool fullpath = false)
|
||||||
|
{
|
||||||
|
Fonts.Add(keyname, Content.Load<SpriteFont>((fullpath ? "" : "Fonts/") + path));
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TryLoadTextureFile(string keyname, string path)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (File.Exists(path))
|
||||||
|
{
|
||||||
|
using (FileStream fileStream = new FileStream(path, FileMode.Open))
|
||||||
|
{
|
||||||
|
Textures.Add(keyname, Texture2D.FromStream(Graphics, fileStream));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadTexture(string assetname, KeyMode keymode = KeyMode.file, bool fullpath = false)
|
||||||
|
{
|
||||||
|
string keyname;
|
||||||
|
if (keymode == KeyMode.file)
|
||||||
|
{
|
||||||
|
string[] split = assetname.Split('/');
|
||||||
|
keyname = split[split.Length - 1];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
keyname = assetname;
|
||||||
|
}
|
||||||
|
LoadTexture(keyname, assetname, fullpath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadTexture(string keyname, string path, bool fullpath = false)
|
||||||
|
{
|
||||||
|
Textures.Add(keyname, Content.Load<Texture2D>((fullpath ? "" : "Textures/") + path));
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TryLoadSoundFile(string keyname, string path)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (File.Exists(path))
|
||||||
|
{
|
||||||
|
using (FileStream fileStream = new FileStream(path, FileMode.Open))
|
||||||
|
{
|
||||||
|
Sounds.Add(keyname, SoundEffect.FromStream(fileStream));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadSound(string assetname, KeyMode keymode = KeyMode.file, bool fullpath = false)
|
||||||
|
{
|
||||||
|
string keyname;
|
||||||
|
if (keymode == KeyMode.file)
|
||||||
|
{
|
||||||
|
string[] split = assetname.Split('/');
|
||||||
|
keyname = split[split.Length - 1];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
keyname = assetname;
|
||||||
|
}
|
||||||
|
LoadSound(keyname, assetname, fullpath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadSound(string keyname, string path, bool fullpath = false)
|
||||||
|
{
|
||||||
|
Sounds.Add(keyname, Content.Load<SoundEffect>((fullpath ? "" : "Sounds/") + path));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadBox(string foldername, KeyMode keymode = KeyMode.file, bool textname = false, bool fullpath = false)
|
||||||
|
{
|
||||||
|
string keyname;
|
||||||
|
if (keymode == KeyMode.file)
|
||||||
|
{
|
||||||
|
string[] split = foldername.Split('/');
|
||||||
|
keyname = split[split.Length - 1];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
keyname = foldername;
|
||||||
|
}
|
||||||
|
LoadBox(keyname, foldername, textname, fullpath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LoadBox(string keyname, string path, bool textname = false, bool fullpath = false)
|
||||||
|
{
|
||||||
|
BoxTexture box = new BoxTexture();
|
||||||
|
string folderpath = (fullpath ? "" : "Textures/Boxes/") + path + "/";
|
||||||
|
if (textname)
|
||||||
|
{
|
||||||
|
box.top_left = Content.Load<Texture2D>(folderpath + "top_left");
|
||||||
|
box.top_middle = Content.Load<Texture2D>(folderpath + "top_middle");
|
||||||
|
box.top_right = Content.Load<Texture2D>(folderpath + "top_right");
|
||||||
|
box.middle_left = Content.Load<Texture2D>(folderpath + "middle_left");
|
||||||
|
box.middle_middle = Content.Load<Texture2D>(folderpath + "middle_middle");
|
||||||
|
box.middle_right = Content.Load<Texture2D>(folderpath + "middle_right");
|
||||||
|
box.bottom_left = Content.Load<Texture2D>(folderpath + "bottom_left");
|
||||||
|
box.bottom_middle = Content.Load<Texture2D>(folderpath + "bottom_middle");
|
||||||
|
box.bottom_right = Content.Load<Texture2D>(folderpath + "bottom_right");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int x = 0; x < 3; x++)
|
||||||
|
{
|
||||||
|
for (int y = 0; y < 3; y++)
|
||||||
|
{
|
||||||
|
box.Textures[x, y] = Content.Load<Texture2D>(folderpath + x + "_" + y); //0_0.png
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!box.IsCorrect())
|
||||||
|
throw new Exception("Incorrect Box");
|
||||||
|
Boxes.Add(keyname, box);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
using System;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
|
||||||
|
namespace MyMonoGameAddin
|
||||||
|
{
|
||||||
|
public struct Skin
|
||||||
|
{
|
||||||
|
public Colors backColors;
|
||||||
|
public Colors foreColors;
|
||||||
|
public BoxTexture texture;
|
||||||
|
public SpriteFont font;
|
||||||
|
|
||||||
|
public Skin(BoxTexture text, SpriteFont fon, Colors back, Colors fore)
|
||||||
|
{
|
||||||
|
texture = text;
|
||||||
|
font = fon;
|
||||||
|
backColors = back;
|
||||||
|
foreColors = fore;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,414 @@
|
||||||
|
using System;
|
||||||
|
using Microsoft.Xna.Framework;
|
||||||
|
using Microsoft.Xna.Framework.Graphics;
|
||||||
|
|
||||||
|
namespace MyMonoGameAddin
|
||||||
|
{
|
||||||
|
public class UIManager
|
||||||
|
{
|
||||||
|
public enum State { Normal, Hover, Focus, Active }
|
||||||
|
public enum textAlign { topLeft, topCenter, topRight, centerLeft, centerCenter, centerRight, bottomLeft, bottomCenter, bottomRight };
|
||||||
|
|
||||||
|
SpriteBatch spriteBatch;
|
||||||
|
InputsManager inputs;
|
||||||
|
public KeyChar.Layout layout = KeyChar.Layout.QWERTY;
|
||||||
|
bool moved = false;
|
||||||
|
|
||||||
|
public Vector focus;
|
||||||
|
|
||||||
|
public Skin skin;
|
||||||
|
|
||||||
|
public UIManager(SpriteBatch batch, InputsManager input, Skin defaultSkin)
|
||||||
|
{
|
||||||
|
spriteBatch = batch;
|
||||||
|
inputs = input;
|
||||||
|
skin = defaultSkin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetBatch(SpriteBatch batch)
|
||||||
|
{
|
||||||
|
spriteBatch = batch;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update()
|
||||||
|
{
|
||||||
|
moved = false;
|
||||||
|
|
||||||
|
if (inputs.Mouse.LeftState == ButtonState.Releasing)
|
||||||
|
{
|
||||||
|
focus = inputs.Mouse.Position;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void ResetFocus()
|
||||||
|
{
|
||||||
|
focus = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public State GetState(Rectangle rect)
|
||||||
|
{
|
||||||
|
bool contain = rect.Contains(inputs.Mouse.X, inputs.Mouse.Y);
|
||||||
|
|
||||||
|
if (inputs.Mouse.LeftPressed)
|
||||||
|
return contain ? State.Active : State.Normal;
|
||||||
|
|
||||||
|
if (focus != null)
|
||||||
|
if (rect.Contains(focus.X, focus.Y))
|
||||||
|
return State.Focus;
|
||||||
|
|
||||||
|
return contain ? State.Hover : State.Normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector GetLabelPos(Vector _pos, textAlign _align, SpriteFont _font, string _text)
|
||||||
|
{
|
||||||
|
switch (_align)
|
||||||
|
{
|
||||||
|
case textAlign.topLeft:
|
||||||
|
return new Vector(_pos.X - (int)_font.MeasureString(_text).X, _pos.Y - (int)_font.MeasureString(_text).Y);
|
||||||
|
|
||||||
|
case textAlign.topCenter:
|
||||||
|
return new Vector(_pos.X - (int)_font.MeasureString(_text).X / 2, _pos.Y - (int)_font.MeasureString(_text).Y);
|
||||||
|
|
||||||
|
case textAlign.topRight:
|
||||||
|
return new Vector(_pos.X, _pos.Y - (int)_font.MeasureString(_text).Y);
|
||||||
|
|
||||||
|
case textAlign.centerLeft:
|
||||||
|
return new Vector(_pos.X - (int)_font.MeasureString(_text).X, _pos.Y - (int)_font.MeasureString(_text).Y / 2);
|
||||||
|
|
||||||
|
case textAlign.centerCenter:
|
||||||
|
return new Vector(_pos.X - (int)_font.MeasureString(_text).X / 2, _pos.Y - (int)_font.MeasureString(_text).Y / 2);
|
||||||
|
|
||||||
|
case textAlign.centerRight:
|
||||||
|
return new Vector(_pos.X, _pos.Y - (int)_font.MeasureString(_text).Y / 2);
|
||||||
|
|
||||||
|
case textAlign.bottomLeft:
|
||||||
|
return new Vector(_pos.X - (int)_font.MeasureString(_text).X, _pos.Y);
|
||||||
|
|
||||||
|
case textAlign.bottomCenter:
|
||||||
|
return new Vector(_pos.X - (int)_font.MeasureString(_text).X / 2, _pos.Y);
|
||||||
|
|
||||||
|
case textAlign.bottomRight:
|
||||||
|
return new Vector(_pos.X, _pos.Y);
|
||||||
|
|
||||||
|
default:
|
||||||
|
return new Vector(_pos.X, _pos.Y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector GetLabelPos(Rectangle _pos, textAlign _align, SpriteFont _font, string _text)
|
||||||
|
{
|
||||||
|
switch (_align)
|
||||||
|
{
|
||||||
|
case textAlign.topLeft:
|
||||||
|
return new Vector(_pos.X, _pos.Y);
|
||||||
|
|
||||||
|
case textAlign.topCenter:
|
||||||
|
return new Vector(_pos.X + _pos.Width / 2 - (int)_font.MeasureString(_text).X / 2, _pos.Y);
|
||||||
|
|
||||||
|
case textAlign.topRight:
|
||||||
|
return new Vector(_pos.X + _pos.Width - (int)_font.MeasureString(_text).X, _pos.Y);
|
||||||
|
|
||||||
|
case textAlign.centerLeft:
|
||||||
|
return new Vector(_pos.X, _pos.Y + _pos.Height / 2 - (int)_font.MeasureString(_text).Y / 2);
|
||||||
|
|
||||||
|
case textAlign.centerCenter:
|
||||||
|
return new Vector(_pos.X + _pos.Width / 2 - (int)_font.MeasureString(_text).X / 2, _pos.Y + _pos.Height / 2 - (int)_font.MeasureString(_text).Y / 2);
|
||||||
|
|
||||||
|
case textAlign.centerRight:
|
||||||
|
return new Vector(_pos.X + _pos.Width - (int)_font.MeasureString(_text).X, _pos.Y + _pos.Height / 2 - (int)_font.MeasureString(_text).Y / 2);
|
||||||
|
|
||||||
|
case textAlign.bottomLeft:
|
||||||
|
return new Vector(_pos.X, _pos.Y + _pos.Height - (int)_font.MeasureString(_text).Y);
|
||||||
|
|
||||||
|
case textAlign.bottomCenter:
|
||||||
|
return new Vector(_pos.X + _pos.Width / 2 - (int)_font.MeasureString(_text).X / 2, _pos.Y + _pos.Height - (int)_font.MeasureString(_text).Y);
|
||||||
|
|
||||||
|
case textAlign.bottomRight:
|
||||||
|
return new Vector(_pos.X + _pos.Width - (int)_font.MeasureString(_text).X, _pos.Y + _pos.Height - (int)_font.MeasureString(_text).Y);
|
||||||
|
|
||||||
|
default:
|
||||||
|
return new Vector(_pos.X, _pos.Y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Next(Vector next, Rectangle pos)
|
||||||
|
{
|
||||||
|
if (next != null)
|
||||||
|
{
|
||||||
|
if (focus != null)
|
||||||
|
{
|
||||||
|
if (!moved)
|
||||||
|
{
|
||||||
|
if (inputs.Keyboard.GetKeyState(Microsoft.Xna.Framework.Input.Keys.Tab) == ButtonState.Pressing)
|
||||||
|
{
|
||||||
|
if (GetState(pos) == State.Focus)
|
||||||
|
{
|
||||||
|
moved = true;
|
||||||
|
focus = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Texture(Rectangle pos, Texture2D texture, Color color, Vector next = null)
|
||||||
|
{
|
||||||
|
Next(next, pos);
|
||||||
|
spriteBatch.Draw(texture, pos, color);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Texture(Rectangle pos, Texture2D texture, Colors color = null, Vector next = null)
|
||||||
|
{
|
||||||
|
if (color == null)
|
||||||
|
color = skin.backColors;
|
||||||
|
|
||||||
|
Texture(pos, texture, color.Get(GetState(pos)), next);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Box(Rectangle pos, Color backColor, BoxTexture backSprites = null, Vector next = null)
|
||||||
|
{
|
||||||
|
if (backSprites == null)
|
||||||
|
backSprites = skin.texture;
|
||||||
|
|
||||||
|
Next(next, pos);
|
||||||
|
int leftWidth = backSprites.top_left.Width;
|
||||||
|
int rightWidth = backSprites.top_right.Width;
|
||||||
|
int centerWidth = pos.Width - leftWidth - rightWidth;
|
||||||
|
|
||||||
|
int topHeight = backSprites.top_left.Height;
|
||||||
|
int bottomHeight = backSprites.bottom_left.Height;
|
||||||
|
int centerHeight = pos.Height - topHeight - bottomHeight;
|
||||||
|
|
||||||
|
spriteBatch.Draw(backSprites.top_left, new Rectangle(pos.X, pos.Y, leftWidth, topHeight), backColor);
|
||||||
|
spriteBatch.Draw(backSprites.top_middle, new Rectangle(pos.X + leftWidth, pos.Y, centerWidth, topHeight), backColor);
|
||||||
|
spriteBatch.Draw(backSprites.top_right, new Rectangle(pos.X + pos.Width - rightWidth, pos.Y, rightWidth, topHeight), backColor);
|
||||||
|
spriteBatch.Draw(backSprites.middle_left, new Rectangle(pos.X, pos.Y + topHeight, leftWidth, centerHeight), backColor);
|
||||||
|
spriteBatch.Draw(backSprites.middle_middle, new Rectangle(pos.X + leftWidth, pos.Y + topHeight, centerWidth, centerHeight), backColor);
|
||||||
|
spriteBatch.Draw(backSprites.middle_right, new Rectangle(pos.X + pos.Width - rightWidth, pos.Y + topHeight, rightWidth, centerHeight), backColor);
|
||||||
|
spriteBatch.Draw(backSprites.bottom_left, new Rectangle(pos.X, pos.Y + pos.Height - bottomHeight, leftWidth, bottomHeight), backColor);
|
||||||
|
spriteBatch.Draw(backSprites.bottom_middle, new Rectangle(pos.X + leftWidth, pos.Y + pos.Height - bottomHeight, centerWidth, bottomHeight), backColor);
|
||||||
|
spriteBatch.Draw(backSprites.bottom_right, new Rectangle(pos.X + pos.Width - rightWidth, pos.Y + pos.Height - bottomHeight, rightWidth, bottomHeight), backColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Box(Rectangle pos, Colors backColor = null, BoxTexture backSprites = null, Vector next = null)
|
||||||
|
{
|
||||||
|
if (backColor == null)
|
||||||
|
backColor = skin.backColors;
|
||||||
|
|
||||||
|
Box(pos, backColor.Get(GetState(pos)), backSprites, next);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Label(Rectangle pos, string text, Color color, SpriteFont font = null, textAlign align = textAlign.centerCenter, Vector next = null)
|
||||||
|
{
|
||||||
|
if (font == null)
|
||||||
|
font = skin.font;
|
||||||
|
|
||||||
|
Next(next, pos);
|
||||||
|
Vector v = GetLabelPos(pos, align, font, text);
|
||||||
|
spriteBatch.DrawString(font, text, new Vector2(v.X, v.Y), color);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Label(Rectangle pos, string text, Colors colors = null, SpriteFont font = null, textAlign align = textAlign.centerCenter, Vector next = null)
|
||||||
|
{
|
||||||
|
if (colors == null)
|
||||||
|
colors = skin.foreColors;
|
||||||
|
|
||||||
|
Label(pos, text, colors.Get(GetState(pos)), font, align, next);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Label(Vector vector, string text, Color color, SpriteFont font = null, textAlign align = textAlign.bottomRight, Vector next = null)
|
||||||
|
{
|
||||||
|
if (font == null)
|
||||||
|
font = skin.font;
|
||||||
|
|
||||||
|
Vector v = GetLabelPos(vector, align, font, text);
|
||||||
|
|
||||||
|
if (next != null)
|
||||||
|
Next(next, new Rectangle(v.X, v.Y, (int)font.MeasureString(text).X, (int)font.MeasureString(text).Y));
|
||||||
|
|
||||||
|
spriteBatch.DrawString(font, text, new Vector2(v.X, v.Y), color);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Label(Vector vector, string text, Colors colors = null, SpriteFont font = null, textAlign align = textAlign.bottomRight, Vector next = null)
|
||||||
|
{
|
||||||
|
if (colors == null)
|
||||||
|
colors = skin.foreColors;
|
||||||
|
|
||||||
|
if (font == null)
|
||||||
|
font = skin.font;
|
||||||
|
|
||||||
|
Vector v = GetLabelPos(vector, align, font, text);
|
||||||
|
|
||||||
|
if (next != null)
|
||||||
|
Next(next, new Rectangle(v.X, v.Y, (int)font.MeasureString(text).X, (int)font.MeasureString(text).Y));
|
||||||
|
|
||||||
|
spriteBatch.DrawString(font, text, new Vector2(v.X, v.Y), colors.Get(GetState(new Rectangle(v.X, v.Y, (int)font.MeasureString(text).X, (int)font.MeasureString(text).Y))));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Button(State state)
|
||||||
|
{
|
||||||
|
switch (state)
|
||||||
|
{
|
||||||
|
case State.Active:
|
||||||
|
return true;
|
||||||
|
|
||||||
|
case State.Focus:
|
||||||
|
return inputs.Keyboard.IsPressed(Microsoft.Xna.Framework.Input.Keys.Enter);
|
||||||
|
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Button(Rectangle pos, Texture2D texture, Color color, Vector next = null)
|
||||||
|
{
|
||||||
|
Texture(pos, texture, color, next);
|
||||||
|
return Button(GetState(pos));
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Button(Rectangle pos, Texture2D texture, Colors color = null, Vector next = null)
|
||||||
|
{
|
||||||
|
if (color == null)
|
||||||
|
color = skin.backColors;
|
||||||
|
|
||||||
|
return Button(pos, texture, color.Get(GetState(pos)), next);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Button(Rectangle pos, Color color, BoxTexture texture = null, Vector next = null)
|
||||||
|
{
|
||||||
|
if (texture == null)
|
||||||
|
texture = skin.texture;
|
||||||
|
|
||||||
|
Box(pos, color, texture, next);
|
||||||
|
return Button(GetState(pos));
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Button(Rectangle pos, Colors color = null, BoxTexture texture = null, Vector next = null)
|
||||||
|
{
|
||||||
|
if (color == null)
|
||||||
|
color = skin.backColors;
|
||||||
|
|
||||||
|
return Button(pos, color.Get(GetState(pos)), texture, next);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Button(Rectangle pos, string text, Color backcolor, Color forecolor, BoxTexture texture = null, SpriteFont font = null, textAlign align = textAlign.centerCenter, Vector next = null)
|
||||||
|
{
|
||||||
|
Box(pos, backcolor, texture, next);
|
||||||
|
Label(pos, text, forecolor, font, align);
|
||||||
|
return Button(GetState(pos));
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Button(Rectangle pos, String text, Colors backcolor = null, Colors forecolor = null, BoxTexture texture = null, SpriteFont font = null, textAlign align = textAlign.centerCenter, Vector next = null)
|
||||||
|
{
|
||||||
|
if (backcolor == null)
|
||||||
|
backcolor = skin.backColors;
|
||||||
|
|
||||||
|
if (forecolor == null)
|
||||||
|
forecolor = skin.foreColors;
|
||||||
|
|
||||||
|
State state = GetState(pos);
|
||||||
|
return Button(pos, text, backcolor.Get(state), forecolor.Get(state), texture, font, align, next);
|
||||||
|
}
|
||||||
|
|
||||||
|
string fieldText(string value, string placeHolder)
|
||||||
|
{
|
||||||
|
return (placeHolder != null && (value == null || value == "")) ? placeHolder : value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TextField(Rectangle pos, ref string value, Color color, SpriteFont font = null, textAlign align = textAlign.centerCenter, string placeHolder = null, Vector next = null)
|
||||||
|
{
|
||||||
|
string _text = fieldText(value, placeHolder);
|
||||||
|
if (inputs.Keyboard.PressingKeys.Count > 0)
|
||||||
|
{
|
||||||
|
if (GetState(pos) == State.Focus)
|
||||||
|
{
|
||||||
|
if (inputs.Keyboard.PressingKeys[0] == Microsoft.Xna.Framework.Input.Keys.Back)
|
||||||
|
{
|
||||||
|
if (value != null)
|
||||||
|
{
|
||||||
|
if (value.Length > 0)
|
||||||
|
{
|
||||||
|
value = value.Remove(value.Length - 1);
|
||||||
|
_text = fieldText(value, placeHolder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Nullable<char> ch;
|
||||||
|
if (KeyChar.KeyToChar(inputs.Keyboard.PressingKeys[0], inputs.Keyboard.IsPressed(KeyboardManager.SpecialKeys.Shift), out ch, layout, inputs.Keyboard.IsPressed(Microsoft.Xna.Framework.Input.Keys.RightAlt)))
|
||||||
|
{
|
||||||
|
if (ch.HasValue)
|
||||||
|
{
|
||||||
|
value += ch.Value;
|
||||||
|
_text = fieldText(value, placeHolder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Label(pos, _text, color, font, align, next);
|
||||||
|
return inputs.Keyboard.GetKeyState(Microsoft.Xna.Framework.Input.Keys.Enter) == ButtonState.Pressing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TextField(Rectangle pos, ref string value, Colors color = null, SpriteFont font = null, textAlign align = textAlign.centerCenter, string placeHolder = null, Vector next = null)
|
||||||
|
{
|
||||||
|
if (color == null)
|
||||||
|
color = skin.foreColors;
|
||||||
|
|
||||||
|
return TextField(pos, ref value, color.Get(GetState(pos)), font, align, placeHolder, next);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TextField(Vector vector, ref string value, Color color, SpriteFont font = null, textAlign align = textAlign.centerCenter, string placeHolder = null, Vector next = null)
|
||||||
|
{
|
||||||
|
if (font == null)
|
||||||
|
font = skin.font;
|
||||||
|
|
||||||
|
string _text = fieldText(value, placeHolder);
|
||||||
|
if (inputs.Keyboard.PressingKeys.Count > 0)
|
||||||
|
{
|
||||||
|
if (GetState(new Rectangle(vector.X, vector.Y, (int)font.MeasureString(_text).X, (int)font.MeasureString(_text).Y)) == State.Focus)
|
||||||
|
{
|
||||||
|
if (inputs.Keyboard.PressingKeys[0] == Microsoft.Xna.Framework.Input.Keys.Back)
|
||||||
|
{
|
||||||
|
if (value != null)
|
||||||
|
{
|
||||||
|
if (value.Length > 0)
|
||||||
|
{
|
||||||
|
value = value.Remove(value.Length - 1);
|
||||||
|
_text = fieldText(value, placeHolder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Nullable<char> ch;
|
||||||
|
if (KeyChar.KeyToChar(inputs.Keyboard.PressingKeys[0], inputs.Keyboard.IsPressed(KeyboardManager.SpecialKeys.Shift), out ch, layout, inputs.Keyboard.IsPressed(Microsoft.Xna.Framework.Input.Keys.RightAlt)))
|
||||||
|
{
|
||||||
|
if (ch.HasValue)
|
||||||
|
{
|
||||||
|
value += ch.Value;
|
||||||
|
_text = fieldText(value, placeHolder);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Label(vector, _text, color, font, align, next);
|
||||||
|
return inputs.Keyboard.GetKeyState(Microsoft.Xna.Framework.Input.Keys.Enter) == ButtonState.Pressing;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TextField(Vector vector, ref string value, Colors color = null, SpriteFont font = null, textAlign align = textAlign.centerCenter, string placeHolder = null, Vector next = null)
|
||||||
|
{
|
||||||
|
if (color == null)
|
||||||
|
color = skin.foreColors;
|
||||||
|
|
||||||
|
if (font == null)
|
||||||
|
font = skin.font;
|
||||||
|
|
||||||
|
string _text = fieldText(value, placeHolder);
|
||||||
|
return TextField(vector, ref value, color.Get(GetState(new Rectangle(vector.X, vector.Y, (int)font.MeasureString(_text).X, (int)font.MeasureString(_text).Y))), font, align, placeHolder, next);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,12 +11,18 @@
|
||||||
Y = y;
|
Y = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Vector Add(Vector v1, Vector v2)
|
||||||
|
{
|
||||||
|
return new Vector(v1.X + v2.X, v1.Y + v2.Y);
|
||||||
|
}
|
||||||
|
|
||||||
public void Add(Vector v)
|
public void Add(Vector v)
|
||||||
{
|
{
|
||||||
X += v.X;
|
X += v.X;
|
||||||
Y += v.Y;
|
Y += v.Y;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vector Zero { get { return new Vector(0, 0); } }
|
public static Vector Zero = new Vector(0, 0);
|
||||||
|
public static Vector One = new Vector(1, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
# My Monogame Addin
|
||||||
|
|
||||||
|
MyMonogameAddin is a simple library from [Monogame](https://github.com/MonoGame/MonoGame)
|
||||||
|
|
||||||
|
### Prerequisities
|
||||||
|
|
||||||
|
* .NET/[Mono](https://github.com/mono/mono) 4.5+
|
||||||
|
* [Monogame](https://github.com/MonoGame/MonoGame) 3.5+
|
||||||
|
|
||||||
|
### Installing
|
||||||
|
|
||||||
|
1. Download last version
|
||||||
|
|
||||||
|
2. Copy Exemple/MainGame.cs
|
||||||
|
|
||||||
|
3. Let's Go
|
||||||
|
|
||||||
|
## Test With
|
||||||
|
|
||||||
|
* Windows 10 x64
|
||||||
|
* Linux Manjaro 16.10.3 x64
|
||||||
|
|
||||||
|
## Contributing
|
||||||
|
|
||||||
|
Get [Monogame](https://github.com/MonoGame/MonoGame).
|
||||||
|
As you wish, I am opened to new ideas.
|
||||||
|
|
||||||
|
## Author
|
||||||
|
|
||||||
|
* **[Sheychen](https://sheychen.shost.ca)** - *Initial work*
|
||||||
|
|
||||||
|
See also the list of [contributors](https://github.com/sheychen290/Galactic_Colors_Control/contributors) who participated in this project.
|
||||||
|
|
||||||
|
### License
|
||||||
|
|
||||||
|
This software comes under the terms of the GPLv3+. See the [License.md](License.md) file for the complete text of the license.
|