Updated to MonoGame 3.6 + Directory refactor

- Barotrauma's projects are in the Barotrauma directory
- All libraries are in the Libraries directory
- MonoGame is now managed by NuGet, rather than referenced from the installed files (TODO: consider using PCL for easier cross-platform development?)
- NuGet libraries are not included in the repo, as getting the latest versions automatically should be preferred
- Removed Content/effects.mgfx as it didn't seem to be used anywhere
- Removed some references to Subsurface directory
- Renamed Launcher2 to Launcher
This commit is contained in:
juanjp600
2017-06-27 09:52:57 -03:00
parent 330b24bcf6
commit 4d225c65f2
1301 changed files with 169 additions and 77952 deletions
@@ -0,0 +1,234 @@
using System;
using Microsoft.Xna.Framework;
using System.Linq;
//TODO: this class still does things that the server doesn't need, cleanup
namespace Barotrauma
{
public class Camera
{
public static bool FollowSub = true;
const float DefaultZoom = 1.0f;
const float ZoomSmoothness = 8.0f;
const float MoveSmoothness = 8.0f;
private float zoom;
private float offsetAmount;
private Matrix transform, shaderTransform, viewMatrix;
private Vector2 position;
private float rotation;
private Vector2 prevPosition;
private float prevZoom;
public float Shake;
private Vector2 shakePosition;
private Vector2 shakeTargetPosition;
//the area of the world inside the camera view
private Rectangle worldView;
private Point resolution;
private Vector2 targetPos;
public float Zoom
{
get { return zoom; }
set
{
zoom = value;
Vector2 center = WorldViewCenter;
float newWidth = resolution.X / zoom;
float newHeight = resolution.Y / zoom;
worldView = new Rectangle(
(int)(center.X - newWidth / 2.0f),
(int)(center.Y + newHeight / 2.0f),
(int)newWidth,
(int)newHeight);
//UpdateTransform();
}
}
public float Rotation
{
get { return rotation; }
set { rotation = value; }
}
public float OffsetAmount
{
get { return offsetAmount; }
set { offsetAmount = value; }
}
public Point Resolution
{
get { return resolution; }
}
public Rectangle WorldView
{
get { return worldView; }
}
public Vector2 WorldViewCenter
{
get
{
return new Vector2(
worldView.X + worldView.Width / 2.0f,
worldView.Y - worldView.Height / 2.0f);
}
}
public Matrix Transform
{
get { return transform; }
}
public Matrix ShaderTransform
{
get { return shaderTransform; }
}
public Camera()
{
zoom = 1.0f;
rotation = 0.0f;
position = Vector2.Zero;
worldView = new Rectangle(0,0,
1,
1);
resolution = new Point(1,1);
viewMatrix =
Matrix.CreateTranslation(new Vector3(0.5f, 0.5f, 0));
UpdateTransform();
}
public Vector2 TargetPos
{
get { return targetPos; }
set { targetPos = value; }
}
// Auxiliary function to move the camera
public void Translate(Vector2 amount)
{
position += amount;
}
public void UpdateTransform(bool interpolate = true, bool clampPos = false)
{
Vector2 interpolatedPosition = interpolate ? Timing.Interpolate(prevPosition, position) : position;
float interpolatedZoom = interpolate ? Timing.Interpolate(prevZoom, zoom) : zoom;
worldView.X = (int)(interpolatedPosition.X - worldView.Width / 2.0);
worldView.Y = (int)(interpolatedPosition.Y + worldView.Height / 2.0);
if (Level.Loaded != null && clampPos)
{
position.Y -= Math.Max(worldView.Y - Level.Loaded.Size.Y, 0.0f);
interpolatedPosition.Y -= Math.Max(worldView.Y - Level.Loaded.Size.Y, 0.0f);
worldView.Y = Math.Min((int)Level.Loaded.Size.Y, worldView.Y);
}
transform = Matrix.CreateTranslation(
new Vector3(-interpolatedPosition.X, interpolatedPosition.Y, 0)) *
Matrix.CreateScale(new Vector3(interpolatedZoom, interpolatedZoom, 1)) *
viewMatrix;
shaderTransform = Matrix.CreateTranslation(
new Vector3(
-interpolatedPosition.X - resolution.X / interpolatedZoom / 2.0f,
-interpolatedPosition.Y - resolution.Y / interpolatedZoom / 2.0f, 0)) *
Matrix.CreateScale(new Vector3(interpolatedZoom, interpolatedZoom, 1)) *
viewMatrix;
if (!interpolate)
{
prevPosition = position;
prevZoom = zoom;
}
}
public void MoveCamera(float deltaTime, bool allowMove = true, bool allowZoom = true)
{
prevPosition = position;
prevZoom = zoom;
float moveSpeed = 20.0f/zoom;
Vector2 moveCam = Vector2.Zero;
if (targetPos == Vector2.Zero)
{
}
else
{
Vector2 mousePos = PlayerInput.MousePosition;
Vector2 offset = mousePos - new Vector2(resolution.X / 2.0f, resolution.Y / 2.0f);
offset.X = offset.X / (resolution.X * 0.4f);
offset.Y = -offset.Y / (resolution.Y * 0.3f);
if (offset.Length() > 1.0f) offset.Normalize();
offset = offset * offsetAmount;
float newZoom = Math.Min(DefaultZoom - Math.Min(offset.Length() / resolution.Y, 1.0f),1.0f);
Zoom += (newZoom - zoom) / ZoomSmoothness;
Vector2 diff = (targetPos + offset) - position;
moveCam = diff / MoveSmoothness;
}
shakeTargetPosition = Rand.Vector(Shake);
shakePosition = Vector2.Lerp(shakePosition, shakeTargetPosition, 0.5f);
Shake = MathHelper.Lerp(Shake, 0.0f, deltaTime * 2.0f);
Translate(moveCam + shakePosition);
}
public Vector2 Position
{
get { return position; }
set
{
if (!MathUtils.IsValid(value))
{
return;
}
position = value;
}
}
public Vector2 ScreenToWorld(Vector2 coords)
{
Vector2 worldCoords = Vector2.Transform(coords, Matrix.Invert(transform));
return new Vector2(worldCoords.X, -worldCoords.Y);
}
public Vector2 WorldToScreen(Vector2 coords)
{
coords.Y = -coords.Y;
//Vector2 screenCoords = Vector2.Transform(coords, transform);
return Vector2.Transform(coords, transform);
}
}
}
@@ -0,0 +1,32 @@
using FarseerPhysics;
using FarseerPhysics.Dynamics;
using FarseerPhysics.Dynamics.Joints;
using Barotrauma.Networking;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Microsoft.Xna.Framework;
namespace Barotrauma
{
partial class Character : Entity, IDamageable, IPropertyObject, IClientSerializable, IServerSerializable
{
//the Character that the player is currently controlling
private const Character controlled = null;
public static Character Controlled
{
get { return controlled; }
set
{
//do nothing
}
}
partial void InitProjSpecific(XDocument doc)
{
keys = null;
}
}
}
@@ -0,0 +1,149 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Barotrauma.Networking;
using Barotrauma.Items.Components;
using System.Text;
using FarseerPhysics;
namespace Barotrauma
{
static partial class DebugConsole
{
public static List<string> QueuedCommands = new List<string>();
public static void Update()
{
lock (QueuedCommands)
{
while (QueuedCommands.Count>0)
{
ExecuteCommand(QueuedCommands[0], GameMain.Instance);
QueuedCommands.RemoveAt(0);
}
}
}
private static bool ExecProjSpecific(string[] commands)
{
switch (commands[0].ToLower())
{
case "restart":
case "reset":
DebugConsole.NewMessage("*****************", Color.Lime);
DebugConsole.NewMessage("RESTARTING SERVER", Color.Lime);
DebugConsole.NewMessage("*****************", Color.Lime);
GameMain.Instance.CloseServer();
GameMain.Instance.StartServer();
break;
case "exit":
case "close":
case "quit":
GameMain.ShouldRun = false;
break;
case "say":
case "msg":
string text = string.Join(" ", commands.Skip(1));
if (commands[0].ToLower() == "say") text = "HOST: " + text;
GameMain.Server.SendChatMessage(text, ChatMessageType.Server);
break;
case "servername":
GameMain.Server.Name = string.Join(" ", commands.Skip(1));
GameMain.NetLobbyScreen.ChangeServerName(string.Join(" ", commands.Skip(1)));
break;
case "servermsg":
GameMain.NetLobbyScreen.ChangeServerMessage(string.Join(" ", commands.Skip(1)));
break;
case "seed":
GameMain.NetLobbyScreen.LevelSeed = string.Join(" ", commands.Skip(1));
break;
case "gamemode":
{
int index = -1;
if (int.TryParse(string.Join(" ", commands.Skip(1)), out index))
{
GameMain.NetLobbyScreen.SelectedModeIndex = index;
}
else
{
GameMain.NetLobbyScreen.SelectedModeName = string.Join(" ", commands.Skip(1));
}
DebugConsole.NewMessage("Set gamemode to " + GameMain.NetLobbyScreen.SelectedModeName, Color.Cyan);
}
break;
case "mission":
{
int index = -1;
if (int.TryParse(string.Join(" ", commands.Skip(1)), out index))
{
GameMain.NetLobbyScreen.MissionTypeIndex = index;
}
else
{
GameMain.NetLobbyScreen.MissionTypeName = string.Join(" ", commands.Skip(1));
}
DebugConsole.NewMessage("Set mission to " + GameMain.NetLobbyScreen.MissionTypeName, Color.Cyan);
}
break;
case "sub":
case "submarine":
{
Submarine sub = GameMain.NetLobbyScreen.GetSubList().Find(s => s.Name.ToLower() == string.Join(" ", commands.Skip(1)).ToLower());
if (sub != null)
{
GameMain.NetLobbyScreen.SelectedSub = sub;
}
sub = GameMain.NetLobbyScreen.SelectedSub;
DebugConsole.NewMessage("Selected sub: " + sub.Name + (sub.HasTag(SubmarineTag.Shuttle) ? " (shuttle)" : ""), Color.Cyan);
}
break;
case "shuttle":
{
Submarine shuttle = GameMain.NetLobbyScreen.GetSubList().Find(s => s.Name.ToLower() == string.Join(" ", commands.Skip(1)).ToLower());
if (shuttle != null)
{
GameMain.NetLobbyScreen.SelectedShuttle = shuttle;
}
shuttle = GameMain.NetLobbyScreen.SelectedShuttle;
DebugConsole.NewMessage("Selected shuttle: " + shuttle.Name + (shuttle.HasTag(SubmarineTag.Shuttle) ? "" : " (not shuttle)"), Color.Cyan);
}
break;
case "startgame":
case "startround":
case "start":
if (Screen.Selected == GameMain.GameScreen) break;
if (!GameMain.Server.StartGame()) NewMessage("Failed to start server",Color.Yellow);
break;
case "endgame":
case "endround":
case "end":
if (Screen.Selected == GameMain.NetLobbyScreen) break;
GameMain.Server.EndGame();
break;
case "entitydata":
Entity ent = Entity.FindEntityByID(Convert.ToUInt16(commands[1]));
if (ent != null)
{
NewMessage(ent.ToString(), Color.Lime);
}
break;
#if DEBUG
case "eventdata":
ServerEntityEvent ev = GameMain.Server.EntityEventManager.Events[Convert.ToUInt16(commands[1])];
if (ev != null)
{
NewMessage(ev.StackTrace, Color.Lime);
}
break;
#endif
default:
return false;
break;
}
return true; //command found
}
}
}
@@ -0,0 +1,158 @@
using System;
using System.Diagnostics;
using System.Reflection;
using FarseerPhysics;
using FarseerPhysics.Dynamics;
using Barotrauma.Networking;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using System.Threading;
namespace Barotrauma
{
class GameMain
{
public static readonly Version Version = Assembly.GetEntryAssembly().GetName().Version;
public static World World;
public static GameSettings Config;
public static GameServer Server;
public const GameClient Client = null;
public static NetworkMember NetworkMember
{
get { return Server as NetworkMember; }
}
public static GameSession GameSession;
public static GameMain Instance
{
get;
private set;
}
//only screens the server implements
public static GameScreen GameScreen;
public static NetLobbyScreen NetLobbyScreen;
//null screens because they are not implemented by the server,
//but they're checked for all over the place
//TODO: maybe clean up instead of having these constants
public static readonly Screen MainMenuScreen = UnimplementedScreen.Instance;
public static readonly Screen LobbyScreen = UnimplementedScreen.Instance;
public static readonly Screen ServerListScreen = UnimplementedScreen.Instance;
public static readonly Screen EditMapScreen = UnimplementedScreen.Instance;
public static readonly Screen EditCharacterScreen = UnimplementedScreen.Instance;
//
public static bool ShouldRun = true;
public static ContentPackage SelectedPackage
{
get { return Config.SelectedContentPackage; }
}
public GameMain()
{
Instance = this;
World = new World(new Vector2(0, -9.82f));
FarseerPhysics.Settings.AllowSleep = true;
FarseerPhysics.Settings.ContinuousPhysics = false;
FarseerPhysics.Settings.VelocityIterations = 1;
FarseerPhysics.Settings.PositionIterations = 1;
Config = new GameSettings("serverconfig.xml");
if (Config.WasGameUpdated)
{
UpdaterUtil.CleanOldFiles();
Config.WasGameUpdated = false;
Config.Save("serverconfig.xml");
}
GameScreen = new GameScreen();
}
public void Init()
{
Mission.Init();
MapEntityPrefab.Init();
LevelGenerationParams.LoadPresets();
JobPrefab.LoadAll(SelectedPackage.GetFilesOfType(ContentType.Jobs));
StructurePrefab.LoadAll(SelectedPackage.GetFilesOfType(ContentType.Structure));
ItemPrefab.LoadAll(SelectedPackage.GetFilesOfType(ContentType.Item));
GameModePreset.Init();
LocationType.Init();
Submarine.RefreshSavedSubs();
Screen.SelectNull();
NetLobbyScreen = new NetLobbyScreen();
}
public void StartServer()
{
Server = new GameServer("Dedicated Server Test", 14242, false, "asd", false, 10);
}
public void CloseServer()
{
Server.Disconnect();
Server = null;
}
public void Run()
{
Hyper.ComponentModel.HyperTypeDescriptionProvider.Add(typeof(Character));
Hyper.ComponentModel.HyperTypeDescriptionProvider.Add(typeof(Item));
Hyper.ComponentModel.HyperTypeDescriptionProvider.Add(typeof(Items.Components.ItemComponent));
Hyper.ComponentModel.HyperTypeDescriptionProvider.Add(typeof(Hull));
Init();
StartServer();
DateTime prevTime = DateTime.Now;
while (ShouldRun)
{
prevTime = DateTime.Now;
DebugConsole.Update();
if (Screen.Selected != null) Screen.Selected.Update((float)Timing.Step);
Server.Update((float)Timing.Step);
CoroutineManager.Update((float)Timing.Step, (float)Timing.Step);
int frameTime = DateTime.Now.Subtract(prevTime).Milliseconds;
Thread.Sleep(Math.Max((int)(Timing.Step * 1000.0) - frameTime,0));
}
CloseServer();
}
public void ProcessInput()
{
while (true)
{
string input = Console.ReadLine();
lock (DebugConsole.QueuedCommands)
{
DebugConsole.QueuedCommands.Add(input);
}
}
}
public CoroutineHandle ShowLoading(IEnumerable<object> loader, bool waitKeyHit = true)
{
return CoroutineManager.StartCoroutine(loader);
}
}
}
@@ -0,0 +1,12 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Xml.Linq;
namespace Barotrauma
{
partial class GameSession
{
public const Map Map = null;
}
}
@@ -0,0 +1,45 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
namespace Barotrauma
{
public enum WindowMode
{
Windowed, Fullscreen, BorderlessWindowed
}
public partial class GameSettings
{
public void Save(string filePath)
{
XDocument doc = new XDocument();
if (doc.Root == null)
{
doc.Add(new XElement("config"));
}
doc.Root.Add(
new XAttribute("masterserverurl", MasterServerUrl),
new XAttribute("autocheckupdates", AutoCheckUpdates),
new XAttribute("verboselogging", VerboseLogging));
if (WasGameUpdated)
{
doc.Root.Add(new XAttribute("wasgameupdated", true));
}
if (SelectedContentPackage != null)
{
doc.Root.Add(new XElement("contentpackage",
new XAttribute("path", SelectedContentPackage.Path)));
}
doc.Save(filePath);
}
}
}
@@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Xml.Linq;
using Lidgren.Network;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Barotrauma.Networking;
using System.IO;
namespace Barotrauma.Items.Components
{
partial class ItemComponent : IPropertyObject
{
private bool LoadElemProjSpecific(XElement subElement)
{
switch (subElement.Name.ToString().ToLowerInvariant())
{
case "guiframe":
break;
case "sound":
break;
default:
return false; //unknown element
}
return true; //element processed
}
}
}
@@ -0,0 +1,39 @@
using Microsoft.Xna.Framework;
using System.Xml.Linq;
namespace Barotrauma.Items.Components
{
partial class ItemLabel : ItemComponent, IDrawableComponent
{
[HasDefaultValue("", true), Editable(100)]
public string Text
{
get;
set;
}
[Editable, HasDefaultValue("0.0,0.0,0.0,1.0", true)]
public string TextColor
{
get;
set;
}
[Editable, HasDefaultValue(1.0f, true)]
public float TextScale
{
get;
set;
}
public override void Move(Vector2 amount)
{
//do nothing
}
public ItemLabel(Item item, XElement element)
: base(item, element)
{
}
}
}
@@ -0,0 +1,21 @@
using Barotrauma.Networking;
using FarseerPhysics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Voronoi2;
namespace Barotrauma.Items.Components
{
partial class Steering : Powered, IServerSerializable, IClientSerializable
{
public bool MaintainPos;
public bool LevelStartSelected;
public bool LevelEndSelected;
}
}
@@ -0,0 +1,16 @@
using FarseerPhysics.Dynamics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Lidgren.Network;
using Barotrauma.Networking;
namespace Barotrauma
{
partial class Hull : MapEntity, IPropertyObject, IServerSerializable
{
public override bool IsMouseOn(Vector2 position)
{
return false;
}
}
}
@@ -0,0 +1,19 @@
using System;
using Lidgren.Network;
using Microsoft.Xna.Framework;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.ComponentModel;
using System.Linq;
namespace Barotrauma.Networking
{
class GameClient : NetworkMember
{
public GameClient(string newName)
{
throw new Exception("Tried to create GameClient in dedicated server build");
}
}
}
@@ -0,0 +1,35 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using Lidgren.Network;
using Microsoft.Xna.Framework;
using RestSharp;
using Barotrauma.Items.Components;
namespace Barotrauma.Networking
{
partial class GameServer : NetworkMember
{
void InitProjSpecific()
{
//do nothing
}
void InitUPnP()
{
server.UPnP.ForwardPort(config.Port, "barotrauma");
}
bool DiscoveringUPnP()
{
return server.UPnP.Status == UPnPStatus.Discovering;
}
void FinishUPnP()
{
//do nothing
}
}
}
@@ -0,0 +1,32 @@
using System;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Collections.Generic;
using Lidgren.Network;
using Barotrauma.Items.Components;
namespace Barotrauma.Networking
{
abstract partial class NetworkMember
{
protected const CharacterInfo characterInfo = null;
protected const Character myCharacter = null;
public CharacterInfo CharacterInfo
{
get { return null; }
}
public Character Character
{
get { return null; }
}
private void InitProjSpecific()
{
//do nothing
}
}
}
@@ -0,0 +1,25 @@
using Barotrauma.Networking;
using Lidgren.Network;
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Barotrauma
{
partial class Voting
{
public bool AllowSubVoting
{
get { return allowSubVoting; }
set { allowSubVoting = value; }
}
public bool AllowModeVoting
{
get { return allowModeVoting; }
set { allowModeVoting = value; }
}
}
}
@@ -0,0 +1,134 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
namespace Barotrauma
{
public static class PlayerInput
{
public static Keys selectKey = Keys.E;
public static Vector2 MousePosition
{
get { return Vector2.Zero; }
}
public static Vector2 LatestMousePosition
{
get { return Vector2.Zero; }
}
//public static MouseState GetMouseState
//{
// get { return mouseState; }
//}
//public static MouseState GetOldMouseState
//{
// get { return oldMouseState; }
//}
public static bool MouseInsideWindow
{
get { return false; }
}
public static Vector2 MouseSpeed
{
get
{
return Vector2.Zero;
}
}
public static KeyboardState GetKeyboardState
{
get { return new KeyboardState(); }
}
public static KeyboardState GetOldKeyboardState
{
get { return new KeyboardState(); }
}
public static int ScrollWheelSpeed
{
get { return 0; }
}
public static bool LeftButtonHeld()
{
return false;
}
public static bool LeftButtonDown()
{
return false;
}
public static bool LeftButtonReleased()
{
return false;
}
public static bool LeftButtonClicked()
{
return false;
}
public static bool RightButtonHeld()
{
return false;
}
public static bool RightButtonClicked()
{
return false;
}
public static bool DoubleClicked()
{
return false;
}
public static bool KeyHit(InputType inputType)
{
return false;
}
public static bool KeyDown(InputType inputType)
{
return false;
}
public static bool KeyUp(InputType inputType)
{
return false;
}
public static bool KeyHit(Keys button)
{
return false;
}
public static bool KeyDown(Keys button)
{
return false;
}
public static bool KeyUp(Keys button)
{
return false;
}
public static void Update(double deltaTime)
{
}
public static void UpdateVariable()
{
}
}
}
@@ -0,0 +1,92 @@
#region Using Statements
using System;
using System.IO;
using System.Reflection;
using System.Text;
using System.Threading;
#if WINDOWS
using System.Management;
#endif
#endregion
namespace Barotrauma
{
#if WINDOWS || LINUX
/// <summary>
/// The main class.
/// </summary>
public static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
GameMain game = null;
Thread inputThread = null;
try
{
game = new GameMain();
inputThread = new Thread(new ThreadStart(game.ProcessInput));
inputThread.Start();
game.Run();
inputThread.Abort(); inputThread.Join();
}
catch (Exception e)
{
CrashDump(game, "servercrashreport.txt", e);
inputThread.Abort(); inputThread.Join();
}
}
static void CrashDump(GameMain game, string filePath, Exception exception)
{
StreamWriter sw = new StreamWriter(filePath);
StringBuilder sb = new StringBuilder();
sb.AppendLine("Barotrauma Dedicated Server crash report (generated on " + DateTime.Now + ")");
sb.AppendLine("\n");
sb.AppendLine("Barotrauma seems to have crashed. Sorry for the inconvenience! ");
sb.AppendLine("If you'd like to help fix the bug that caused the crash, please send this file to the developers on the Undertow Games forums.");
sb.AppendLine("\n");
sb.AppendLine("Game version " + GameMain.Version);
sb.AppendLine("Selected content package: " + GameMain.SelectedPackage.Name);
sb.AppendLine("Level seed: " + ((Level.Loaded == null) ? "no level loaded" : Level.Loaded.Seed));
sb.AppendLine("Loaded submarine: " + ((Submarine.MainSub == null) ? "None" : Submarine.MainSub.Name + " (" + Submarine.MainSub.MD5Hash + ")"));
sb.AppendLine("Selected screen: " + (Screen.Selected == null ? "None" : Screen.Selected.ToString()));
if (GameMain.Server != null)
{
sb.AppendLine("Server (" + (GameMain.Server.GameStarted ? "Round had started)" : "Round hadn't been started)"));
}
sb.AppendLine("\n");
sb.AppendLine("System info:");
sb.AppendLine(" Operating system: " + System.Environment.OSVersion + (System.Environment.Is64BitOperatingSystem ? " 64 bit" : " x86"));
sb.AppendLine("\n");
sb.AppendLine("Exception: "+exception.Message);
sb.AppendLine("Target site: " +exception.TargetSite.ToString());
sb.AppendLine("Stack trace: ");
sb.AppendLine(exception.StackTrace);
sb.AppendLine("\n");
sb.AppendLine("Last debug messages:");
for (int i = DebugConsole.Messages.Count - 1; i > 0 && i > DebugConsole.Messages.Count - 15; i-- )
{
sb.AppendLine(" "+DebugConsole.Messages[i].Time+" - "+DebugConsole.Messages[i].Text);
}
Console.ForegroundColor = ConsoleColor.Red;
Console.Write(sb.ToString());
sw.WriteLine(sb.ToString());
sw.Close();
}
}
#endif
}
@@ -0,0 +1,160 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Barotrauma.Networking;
using System.Linq;
using System.Collections.Generic;
using System.Reflection;
using System.ComponentModel;
namespace Barotrauma
{
partial class NetLobbyScreen : Screen
{
private Submarine selectedSub;
private Submarine selectedShuttle;
public Submarine SelectedSub
{
get { return selectedSub; }
set { selectedSub = value; lastUpdateID++; }
}
public Submarine SelectedShuttle
{
get { return selectedShuttle; }
set { selectedShuttle = value; lastUpdateID++; }
}
private GameModePreset[] GameModes;
private int selectedModeIndex;
public int SelectedModeIndex
{
get { return selectedModeIndex; }
set {
lastUpdateID++;
selectedModeIndex = Math.Max(0, Math.Min(GameModes.Count()-1, value));
}
}
public string SelectedModeName
{
get { return GameModes[SelectedModeIndex].Name; }
set
{
for (int i = 0; i < GameModes.Count(); i++)
{
if (GameModes[i].Name.ToLower() == value.ToLower())
{
SelectedModeIndex = i;
break;
}
}
}
}
public GameModePreset SelectedMode
{
get { return GameModes[SelectedModeIndex]; }
}
public string ServerMessageText;
private int missionTypeIndex;
public int MissionTypeIndex
{
get { return missionTypeIndex; }
set {
lastUpdateID++;
missionTypeIndex = Math.Max(0, Math.Min(Mission.MissionTypes.Count()-1, value));
}
}
public string MissionTypeName
{
get { return Mission.MissionTypes[MissionTypeIndex]; }
set
{
for (int i = 0; i < Mission.MissionTypes.Count(); i++)
{
if (Mission.MissionTypes[i].ToLower() == value.ToLower())
{
MissionTypeIndex = i;
break;
}
}
}
}
public void ChangeServerName(string n)
{
ServerName = n; lastUpdateID++;
}
public void ChangeServerMessage(string m)
{
ServerMessageText = m; lastUpdateID++;
}
public List<JobPrefab> JobPreferences
{
get
{
return null;
}
}
public NetLobbyScreen()
{
LevelSeed = ToolBox.RandomSeed(8);
subs = Submarine.SavedSubmarines.Where(s => !s.HasTag(SubmarineTag.HideInMenus)).ToList();
if (subs == null || subs.Count()==0)
{
throw new Exception("No submarines are available.");
}
selectedSub = subs.First(s => !s.HasTag(SubmarineTag.Shuttle));
selectedShuttle = subs.First(s => s.HasTag(SubmarineTag.Shuttle));
DebugConsole.NewMessage("Selected sub: " + SelectedSub.Name, Color.White);
DebugConsole.NewMessage("Selected shuttle: " + SelectedShuttle.Name, Color.White);
GameModes = GameModePreset.list.ToArray();
}
public override void Select()
{
base.Select();
}
private List<Submarine> subs;
public List<Submarine> GetSubList()
{
return subs;
}
public string LevelSeed
{
get
{
return levelSeed;
}
set
{
if (levelSeed == value) return;
lastUpdateID++;
levelSeed = value;
LocationType.Random(levelSeed); //call to sync up with clients
}
}
public bool StartButtonEnabled
{
get { return true; }
set { /* do nothing */ }
}
}
}
@@ -0,0 +1,21 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Barotrauma.Networking;
using System.Linq;
using System.Collections.Generic;
using System.Reflection;
using System.ComponentModel;
namespace Barotrauma
{
class UnimplementedScreen : Screen
{
public static readonly UnimplementedScreen Instance = new UnimplementedScreen();
public override void Select()
{
throw new Exception("Tried to select unimplemented screen");
}
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,28 @@
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
namespace Microsoft.Xna.Framework.Graphics
{
/// <summary>
/// Defines sprite visual options for mirroring.
/// </summary>
[Flags]
public enum SpriteEffects
{
/// <summary>
/// No options specified.
/// </summary>
None = 0,
/// <summary>
/// Render the sprite reversed along the X axis.
/// </summary>
FlipHorizontally = 1,
/// <summary>
/// Render the sprite reversed along the Y axis.
/// </summary>
FlipVertically = 2
}
}
@@ -0,0 +1,58 @@
#region License
// /*
// Microsoft Public License (Ms-PL)
// MonoGame - Copyright © 2009 The MonoGame Team
//
// All rights reserved.
//
// This license governs use of the accompanying software. If you use the software, you accept this license. If you do not
// accept the license, do not use the software.
//
// 1. Definitions
// The terms "reproduce, " "reproduction, " "derivative works, " and "distribution" have the same meaning here as under
// U.S. copyright law.
//
// A "contribution" is the original software, or any additions or changes to the software.
// A "contributor" is any person that distributes its contribution under this license.
// "Licensed patents" are a contributor's patent claims that read directly on its contribution.
//
// 2. Grant of Rights
// (A) Copyright Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
// each contributor grants you a non-exclusive, worldwide, royalty-free copyright license to reproduce its contribution, prepare derivative works of its contribution, and distribute its contribution or any derivative works that you create.
// (B) Patent Grant- Subject to the terms of this license, including the license conditions and limitations in section 3,
// each contributor grants you a non-exclusive, worldwide, royalty-free license under its licensed patents to make, have made, use, sell, offer for sale, import, and/or otherwise dispose of its contribution in the software or derivative works of the contribution in the software.
//
// 3. Conditions and Limitations
// (A) No Trademark License- This license does not grant you rights to use any contributors' name, logo, or trademarks.
// (B) If you bring a patent claim against any contributor over patents that you claim are infringed by the software,
// your patent license from such contributor to the software ends automatically.
// (C) If you distribute any portion of the software, you must retain all copyright, patent, trademark, and attribution
// notices that are present in the software.
// (D) If you distribute any portion of the software in source code form, you may do so only under this license by including
// a complete copy of this license with your distribution. If you distribute any portion of the software in compiled or object
// code form, you may only do so under a license that complies with this license.
// (E) The software is licensed "as-is." You bear the risk of using it. The contributors give no express warranties, guarantees
// or conditions. You may have additional consumer rights under your local laws which this license cannot change. To the extent
// permitted under your local laws, the contributors exclude the implied warranties of merchantability, fitness for a particular
// purpose and non-infringement.
// */
#endregion License
namespace Microsoft.Xna.Framework.Input
{
/// <summary>
/// Identifies the state of a keyboard key.
/// </summary>
public enum KeyState
{
/// <summary>
/// Key is released.
/// </summary>
Up,
/// <summary>
/// Key is pressed.
/// </summary>
Down,
}
}
@@ -0,0 +1,303 @@
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System.Collections.Generic;
namespace Microsoft.Xna.Framework.Input
{
/// <summary>
/// Holds the state of keystrokes by a keyboard.
/// </summary>
public struct KeyboardState
{
// Used for the common situation where GetPressedKeys will return an empty array
static Keys[] empty = new Keys[0];
#region Key Data
// Array of 256 bits:
uint keys0, keys1, keys2, keys3, keys4, keys5, keys6, keys7;
bool InternalGetKey(Keys key)
{
uint mask = (uint)1 << (((int)key) & 0x1f);
uint element;
switch (((int)key) >> 5)
{
case 0: element = keys0; break;
case 1: element = keys1; break;
case 2: element = keys2; break;
case 3: element = keys3; break;
case 4: element = keys4; break;
case 5: element = keys5; break;
case 6: element = keys6; break;
case 7: element = keys7; break;
default: element = 0; break;
}
return (element & mask) != 0;
}
void InternalSetKey(Keys key)
{
uint mask = (uint)1 << (((int)key) & 0x1f);
switch (((int)key) >> 5)
{
case 0: keys0 |= mask; break;
case 1: keys1 |= mask; break;
case 2: keys2 |= mask; break;
case 3: keys3 |= mask; break;
case 4: keys4 |= mask; break;
case 5: keys5 |= mask; break;
case 6: keys6 |= mask; break;
case 7: keys7 |= mask; break;
}
}
void InternalClearKey(Keys key)
{
uint mask = (uint)1 << (((int)key) & 0x1f);
switch (((int)key) >> 5)
{
case 0: keys0 &= ~mask; break;
case 1: keys1 &= ~mask; break;
case 2: keys2 &= ~mask; break;
case 3: keys3 &= ~mask; break;
case 4: keys4 &= ~mask; break;
case 5: keys5 &= ~mask; break;
case 6: keys6 &= ~mask; break;
case 7: keys7 &= ~mask; break;
}
}
void InternalClearAllKeys()
{
keys0 = 0;
keys1 = 0;
keys2 = 0;
keys3 = 0;
keys4 = 0;
keys5 = 0;
keys6 = 0;
keys7 = 0;
}
#endregion
#region XNA Interface
/// <summary>
/// Gets the current state of the Caps Lock key.
/// </summary>
public bool CapsLock { get; private set; }
/// <summary>
/// Gets the current state of the Num Lock key.
/// </summary>
public bool NumLock { get; private set; }
internal KeyboardState(List<Keys> keys, bool capsLock = false, bool numLock = false) : this()
{
CapsLock = capsLock;
NumLock = numLock;
keys0 = 0;
keys1 = 0;
keys2 = 0;
keys3 = 0;
keys4 = 0;
keys5 = 0;
keys6 = 0;
keys7 = 0;
if (keys != null)
foreach (Keys k in keys)
InternalSetKey(k);
}
/// <summary>
/// Initializes a new instance of the <see cref="KeyboardState"/> class.
/// </summary>
/// <param name="keys">List of keys to be flagged as pressed on initialization.</param>
/// <param name="capsLock">Caps Lock state.</param>
/// <param name="numLock">Num Lock state.</param>
public KeyboardState(Keys[] keys, bool capsLock = false, bool numLock = false) : this()
{
CapsLock = capsLock;
NumLock = numLock;
keys0 = 0;
keys1 = 0;
keys2 = 0;
keys3 = 0;
keys4 = 0;
keys5 = 0;
keys6 = 0;
keys7 = 0;
if (keys != null)
foreach (Keys k in keys)
InternalSetKey(k);
}
/// <summary>
/// Initializes a new instance of the <see cref="KeyboardState"/> class.
/// </summary>
/// <param name="keys">List of keys to be flagged as pressed on initialization.</param>
public KeyboardState(params Keys[] keys) : this()
{
CapsLock = false;
NumLock = false;
keys0 = 0;
keys1 = 0;
keys2 = 0;
keys3 = 0;
keys4 = 0;
keys5 = 0;
keys6 = 0;
keys7 = 0;
if (keys != null)
foreach (Keys k in keys)
InternalSetKey(k);
}
/// <summary>
/// Returns the state of a specified key.
/// </summary>
/// <param name="key">The key to query.</param>
/// <returns>The state of the key.</returns>
public KeyState this[Keys key]
{
get { return InternalGetKey(key) ? KeyState.Down : KeyState.Up; }
}
/// <summary>
/// Gets whether given key is currently being pressed.
/// </summary>
/// <param name="key">The key to query.</param>
/// <returns>true if the key is pressed; false otherwise.</returns>
public bool IsKeyDown(Keys key)
{
return InternalGetKey(key);
}
/// <summary>
/// Gets whether given key is currently being not pressed.
/// </summary>
/// <param name="key">The key to query.</param>
/// <returns>true if the key is not pressed; false otherwise.</returns>
public bool IsKeyUp(Keys key)
{
return !InternalGetKey(key);
}
#endregion
#region GetPressedKeys()
private static uint CountBits(uint v)
{
// http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
v = v - ((v >> 1) & 0x55555555); // reuse input as temporary
v = (v & 0x33333333) + ((v >> 2) & 0x33333333); // temp
return ((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24; // count
}
private static int AddKeysToArray(uint keys, int offset, Keys[] pressedKeys, int index)
{
for (int i = 0; i < 32; i++)
{
if ((keys & (1 << i)) != 0)
pressedKeys[index++] = (Keys)(offset + i);
}
return index;
}
/// <summary>
/// Returns an array of values holding keys that are currently being pressed.
/// </summary>
/// <returns>The keys that are currently being pressed.</returns>
public Keys[] GetPressedKeys()
{
uint count = CountBits(keys0) + CountBits(keys1) + CountBits(keys2) + CountBits(keys3)
+ CountBits(keys4) + CountBits(keys5) + CountBits(keys6) + CountBits(keys7);
if (count == 0)
return empty;
Keys[] keys = new Keys[count];
int index = 0;
if (keys0 != 0) index = AddKeysToArray(keys0, 0 * 32, keys, index);
if (keys1 != 0) index = AddKeysToArray(keys1, 1 * 32, keys, index);
if (keys2 != 0) index = AddKeysToArray(keys2, 2 * 32, keys, index);
if (keys3 != 0) index = AddKeysToArray(keys3, 3 * 32, keys, index);
if (keys4 != 0) index = AddKeysToArray(keys4, 4 * 32, keys, index);
if (keys5 != 0) index = AddKeysToArray(keys5, 5 * 32, keys, index);
if (keys6 != 0) index = AddKeysToArray(keys6, 6 * 32, keys, index);
if (keys7 != 0) index = AddKeysToArray(keys7, 7 * 32, keys, index);
return keys;
}
#endregion
#region Objet and Equality
/// <summary>
/// Gets the hash code for <see cref="KeyboardState"/> instance.
/// </summary>
/// <returns>Hash code of the object.</returns>
public override int GetHashCode()
{
return (int)(keys0 ^ keys1 ^ keys2 ^ keys3 ^ keys4 ^ keys5 ^ keys6 ^ keys7);
}
/// <summary>
/// Compares whether two <see cref="KeyboardState"/> instances are equal.
/// </summary>
/// <param name="a"><see cref="KeyboardState"/> instance to the left of the equality operator.</param>
/// <param name="b"><see cref="KeyboardState"/> instance to the right of the equality operator.</param>
/// <returns>true if the instances are equal; false otherwise.</returns>
public static bool operator ==(KeyboardState a, KeyboardState b)
{
return a.keys0 == b.keys0
&& a.keys1 == b.keys1
&& a.keys2 == b.keys2
&& a.keys3 == b.keys3
&& a.keys4 == b.keys4
&& a.keys5 == b.keys5
&& a.keys6 == b.keys6
&& a.keys7 == b.keys7;
}
/// <summary>
/// Compares whether two <see cref="KeyboardState"/> instances are not equal.
/// </summary>
/// <param name="a"><see cref="KeyboardState"/> instance to the left of the inequality operator.</param>
/// <param name="b"><see cref="KeyboardState"/> instance to the right of the inequality operator.</param>
/// <returns>true if the instances are different; false otherwise.</returns>
public static bool operator !=(KeyboardState a, KeyboardState b)
{
return !(a == b);
}
/// <summary>
/// Compares whether current instance is equal to specified object.
/// </summary>
/// <param name="obj">The <see cref="KeyboardState"/> to compare.</param>
/// <returns>true if the provided <see cref="KeyboardState"/> instance is same with current; false otherwise.</returns>
public override bool Equals(object obj)
{
return obj is KeyboardState && this == (KeyboardState)obj;
}
#endregion
}
}
@@ -0,0 +1,653 @@
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
namespace Microsoft.Xna.Framework.Input
{
/// <summary>
/// Defines the keys on a keyboard.
/// </summary>
public enum Keys
{
/// <summary>
/// Reserved.
/// </summary>
None = 0,
/// <summary>
/// BACKSPACE key.
/// </summary>
Back = 8,
/// <summary>
/// TAB key.
/// </summary>
Tab = 9,
/// <summary>
/// ENTER key.
/// </summary>
Enter = 13,
/// <summary>
/// CAPS LOCK key.
/// </summary>
CapsLock = 20,
/// <summary>
/// ESC key.
/// </summary>
Escape = 27,
/// <summary>
/// SPACEBAR key.
/// </summary>
Space = 32,
/// <summary>
/// PAGE UP key.
/// </summary>
PageUp = 33,
/// <summary>
/// PAGE DOWN key.
/// </summary>
PageDown = 34,
/// <summary>
/// END key.
/// </summary>
End = 35,
/// <summary>
/// HOME key.
/// </summary>
Home = 36,
/// <summary>
/// LEFT ARROW key.
/// </summary>
Left = 37,
/// <summary>
/// UP ARROW key.
/// </summary>
Up = 38,
/// <summary>
/// RIGHT ARROW key.
/// </summary>
Right = 39,
/// <summary>
/// DOWN ARROW key.
/// </summary>
Down = 40,
/// <summary>
/// SELECT key.
/// </summary>
Select = 41,
/// <summary>
/// PRINT key.
/// </summary>
Print = 42,
/// <summary>
/// EXECUTE key.
/// </summary>
Execute = 43,
/// <summary>
/// PRINT SCREEN key.
/// </summary>
PrintScreen = 44,
/// <summary>
/// INS key.
/// </summary>
Insert = 45,
/// <summary>
/// DEL key.
/// </summary>
Delete = 46,
/// <summary>
/// HELP key.
/// </summary>
Help = 47,
/// <summary>
/// Used for miscellaneous characters; it can vary by keyboard.
/// </summary>
D0 = 48,
/// <summary>
/// Used for miscellaneous characters; it can vary by keyboard.
/// </summary>
D1 = 49,
/// <summary>
/// Used for miscellaneous characters; it can vary by keyboard.
/// </summary>
D2 = 50,
/// <summary>
/// Used for miscellaneous characters; it can vary by keyboard.
/// </summary>
D3 = 51,
/// <summary>
/// Used for miscellaneous characters; it can vary by keyboard.
/// </summary>
D4 = 52,
/// <summary>
/// Used for miscellaneous characters; it can vary by keyboard.
/// </summary>
D5 = 53,
/// <summary>
/// Used for miscellaneous characters; it can vary by keyboard.
/// </summary>
D6 = 54,
/// <summary>
/// Used for miscellaneous characters; it can vary by keyboard.
/// </summary>
D7 = 55,
/// <summary>
/// Used for miscellaneous characters; it can vary by keyboard.
/// </summary>
D8 = 56,
/// <summary>
/// Used for miscellaneous characters; it can vary by keyboard.
/// </summary>
D9 = 57,
/// <summary>
/// A key.
/// </summary>
A = 65,
/// <summary>
/// B key.
/// </summary>
B = 66,
/// <summary>
/// C key.
/// </summary>
C = 67,
/// <summary>
/// D key.
/// </summary>
D = 68,
/// <summary>
/// E key.
/// </summary>
E = 69,
/// <summary>
/// F key.
/// </summary>
F = 70,
/// <summary>
/// G key.
/// </summary>
G = 71,
/// <summary>
/// H key.
/// </summary>
H = 72,
/// <summary>
/// I key.
/// </summary>
I = 73,
/// <summary>
/// J key.
/// </summary>
J = 74,
/// <summary>
/// K key.
/// </summary>
K = 75,
/// <summary>
/// L key.
/// </summary>
L = 76,
/// <summary>
/// M key.
/// </summary>
M = 77,
/// <summary>
/// N key.
/// </summary>
N = 78,
/// <summary>
/// O key.
/// </summary>
O = 79,
/// <summary>
/// P key.
/// </summary>
P = 80,
/// <summary>
/// Q key.
/// </summary>
Q = 81,
/// <summary>
/// R key.
/// </summary>
R = 82,
/// <summary>
/// S key.
/// </summary>
S = 83,
/// <summary>
/// T key.
/// </summary>
T = 84,
/// <summary>
/// U key.
/// </summary>
U = 85,
/// <summary>
/// V key.
/// </summary>
V = 86,
/// <summary>
/// W key.
/// </summary>
W = 87,
/// <summary>
/// X key.
/// </summary>
X = 88,
/// <summary>
/// Y key.
/// </summary>
Y = 89,
/// <summary>
/// Z key.
/// </summary>
Z = 90,
/// <summary>
/// Left Windows key.
/// </summary>
LeftWindows = 91,
/// <summary>
/// Right Windows key.
/// </summary>
RightWindows = 92,
/// <summary>
/// Applications key.
/// </summary>
Apps = 93,
/// <summary>
/// Computer Sleep key.
/// </summary>
Sleep = 95,
/// <summary>
/// Numeric keypad 0 key.
/// </summary>
NumPad0 = 96,
/// <summary>
/// Numeric keypad 1 key.
/// </summary>
NumPad1 = 97,
/// <summary>
/// Numeric keypad 2 key.
/// </summary>
NumPad2 = 98,
/// <summary>
/// Numeric keypad 3 key.
/// </summary>
NumPad3 = 99,
/// <summary>
/// Numeric keypad 4 key.
/// </summary>
NumPad4 = 100,
/// <summary>
/// Numeric keypad 5 key.
/// </summary>
NumPad5 = 101,
/// <summary>
/// Numeric keypad 6 key.
/// </summary>
NumPad6 = 102,
/// <summary>
/// Numeric keypad 7 key.
/// </summary>
NumPad7 = 103,
/// <summary>
/// Numeric keypad 8 key.
/// </summary>
NumPad8 = 104,
/// <summary>
/// Numeric keypad 9 key.
/// </summary>
NumPad9 = 105,
/// <summary>
/// Multiply key.
/// </summary>
Multiply = 106,
/// <summary>
/// Add key.
/// </summary>
Add = 107,
/// <summary>
/// Separator key.
/// </summary>
Separator = 108,
/// <summary>
/// Subtract key.
/// </summary>
Subtract = 109,
/// <summary>
/// Decimal key.
/// </summary>
Decimal = 110,
/// <summary>
/// Divide key.
/// </summary>
Divide = 111,
/// <summary>
/// F1 key.
/// </summary>
F1 = 112,
/// <summary>
/// F2 key.
/// </summary>
F2 = 113,
/// <summary>
/// F3 key.
/// </summary>
F3 = 114,
/// <summary>
/// F4 key.
/// </summary>
F4 = 115,
/// <summary>
/// F5 key.
/// </summary>
F5 = 116,
/// <summary>
/// F6 key.
/// </summary>
F6 = 117,
/// <summary>
/// F7 key.
/// </summary>
F7 = 118,
/// <summary>
/// F8 key.
/// </summary>
F8 = 119,
/// <summary>
/// F9 key.
/// </summary>
F9 = 120,
/// <summary>
/// F10 key.
/// </summary>
F10 = 121,
/// <summary>
/// F11 key.
/// </summary>
F11 = 122,
/// <summary>
/// F12 key.
/// </summary>
F12 = 123,
/// <summary>
/// F13 key.
/// </summary>
F13 = 124,
/// <summary>
/// F14 key.
/// </summary>
F14 = 125,
/// <summary>
/// F15 key.
/// </summary>
F15 = 126,
/// <summary>
/// F16 key.
/// </summary>
F16 = 127,
/// <summary>
/// F17 key.
/// </summary>
F17 = 128,
/// <summary>
/// F18 key.
/// </summary>
F18 = 129,
/// <summary>
/// F19 key.
/// </summary>
F19 = 130,
/// <summary>
/// F20 key.
/// </summary>
F20 = 131,
/// <summary>
/// F21 key.
/// </summary>
F21 = 132,
/// <summary>
/// F22 key.
/// </summary>
F22 = 133,
/// <summary>
/// F23 key.
/// </summary>
F23 = 134,
/// <summary>
/// F24 key.
/// </summary>
F24 = 135,
/// <summary>
/// NUM LOCK key.
/// </summary>
NumLock = 144,
/// <summary>
/// SCROLL LOCK key.
/// </summary>
Scroll = 145,
/// <summary>
/// Left SHIFT key.
/// </summary>
LeftShift = 160,
/// <summary>
/// Right SHIFT key.
/// </summary>
RightShift = 161,
/// <summary>
/// Left CONTROL key.
/// </summary>
LeftControl = 162,
/// <summary>
/// Right CONTROL key.
/// </summary>
RightControl = 163,
/// <summary>
/// Left ALT key.
/// </summary>
LeftAlt = 164,
/// <summary>
/// Right ALT key.
/// </summary>
RightAlt = 165,
/// <summary>
/// Browser Back key.
/// </summary>
BrowserBack = 166,
/// <summary>
/// Browser Forward key.
/// </summary>
BrowserForward = 167,
/// <summary>
/// Browser Refresh key.
/// </summary>
BrowserRefresh = 168,
/// <summary>
/// Browser Stop key.
/// </summary>
BrowserStop = 169,
/// <summary>
/// Browser Search key.
/// </summary>
BrowserSearch = 170,
/// <summary>
/// Browser Favorites key.
/// </summary>
BrowserFavorites = 171,
/// <summary>
/// Browser Start and Home key.
/// </summary>
BrowserHome = 172,
/// <summary>
/// Volume Mute key.
/// </summary>
VolumeMute = 173,
/// <summary>
/// Volume Down key.
/// </summary>
VolumeDown = 174,
/// <summary>
/// Volume Up key.
/// </summary>
VolumeUp = 175,
/// <summary>
/// Next Track key.
/// </summary>
MediaNextTrack = 176,
/// <summary>
/// Previous Track key.
/// </summary>
MediaPreviousTrack = 177,
/// <summary>
/// Stop Media key.
/// </summary>
MediaStop = 178,
/// <summary>
/// Play/Pause Media key.
/// </summary>
MediaPlayPause = 179,
/// <summary>
/// Start Mail key.
/// </summary>
LaunchMail = 180,
/// <summary>
/// Select Media key.
/// </summary>
SelectMedia = 181,
/// <summary>
/// Start Application 1 key.
/// </summary>
LaunchApplication1 = 182,
/// <summary>
/// Start Application 2 key.
/// </summary>
LaunchApplication2 = 183,
/// <summary>
/// The OEM Semicolon key on a US standard keyboard.
/// </summary>
OemSemicolon = 186,
/// <summary>
/// For any country/region, the '+' key.
/// </summary>
OemPlus = 187,
/// <summary>
/// For any country/region, the ',' key.
/// </summary>
OemComma = 188,
/// <summary>
/// For any country/region, the '-' key.
/// </summary>
OemMinus = 189,
/// <summary>
/// For any country/region, the '.' key.
/// </summary>
OemPeriod = 190,
/// <summary>
/// The OEM question mark key on a US standard keyboard.
/// </summary>
OemQuestion = 191,
/// <summary>
/// The OEM tilde key on a US standard keyboard.
/// </summary>
OemTilde = 192,
/// <summary>
/// The OEM open bracket key on a US standard keyboard.
/// </summary>
OemOpenBrackets = 219,
/// <summary>
/// The OEM pipe key on a US standard keyboard.
/// </summary>
OemPipe = 220,
/// <summary>
/// The OEM close bracket key on a US standard keyboard.
/// </summary>
OemCloseBrackets = 221,
/// <summary>
/// The OEM singled/double quote key on a US standard keyboard.
/// </summary>
OemQuotes = 222,
/// <summary>
/// Used for miscellaneous characters; it can vary by keyboard.
/// </summary>
Oem8 = 223,
/// <summary>
/// The OEM angle bracket or backslash key on the RT 102 key keyboard.
/// </summary>
OemBackslash = 226,
/// <summary>
/// IME PROCESS key.
/// </summary>
ProcessKey = 229,
/// <summary>
/// Attn key.
/// </summary>
Attn = 246,
/// <summary>
/// CrSel key.
/// </summary>
Crsel = 247,
/// <summary>
/// ExSel key.
/// </summary>
Exsel = 248,
/// <summary>
/// Erase EOF key.
/// </summary>
EraseEof = 249,
/// <summary>
/// Play key.
/// </summary>
Play = 250,
/// <summary>
/// Zoom key.
/// </summary>
Zoom = 251,
/// <summary>
/// PA1 key.
/// </summary>
Pa1 = 253,
/// <summary>
/// CLEAR key.
/// </summary>
OemClear = 254,
/// <summary>
/// Green ChatPad key.
/// </summary>
ChatPadGreen = 0xCA,
/// <summary>
/// Orange ChatPad key.
/// </summary>
ChatPadOrange = 0xCB,
/// <summary>
/// PAUSE key.
/// </summary>
Pause = 0x13,
/// <summary>
/// IME Convert key.
/// </summary>
ImeConvert = 0x1c,
/// <summary>
/// IME NoConvert key.
/// </summary>
ImeNoConvert = 0x1d,
/// <summary>
/// Kana key on Japanese keyboards.
/// </summary>
Kana = 0x15,
/// <summary>
/// Kanji key on Japanese keyboards.
/// </summary>
Kanji = 0x19,
/// <summary>
/// OEM Auto key.
/// </summary>
OemAuto = 0xf3,
/// <summary>
/// OEM Copy key.
/// </summary>
OemCopy = 0xf2,
/// <summary>
/// OEM Enlarge Window key.
/// </summary>
OemEnlW = 0xf4
}
}
@@ -0,0 +1,220 @@
// MIT License - Copyright (C) The Mono.Xna Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
using System.Diagnostics;
using System.Runtime.Serialization;
namespace Microsoft.Xna.Framework
{
/// <summary>
/// Describes a 2D-point.
/// </summary>
[DebuggerDisplay("{DebugDisplayString,nq}")]
public struct Point : IEquatable<Point>
{
#region Private Fields
private static readonly Point zeroPoint = new Point();
#endregion
#region Public Fields
/// <summary>
/// The x coordinate of this <see cref="Point"/>.
/// </summary>
public int X;
/// <summary>
/// The y coordinate of this <see cref="Point"/>.
/// </summary>
public int Y;
#endregion
#region Properties
/// <summary>
/// Returns a <see cref="Point"/> with coordinates 0, 0.
/// </summary>
public static Point Zero
{
get { return zeroPoint; }
}
#endregion
#region Internal Properties
internal string DebugDisplayString
{
get
{
return string.Concat(
this.X.ToString(), " ",
this.Y.ToString()
);
}
}
#endregion
#region Constructors
/// <summary>
/// Constructs a point with X and Y from two values.
/// </summary>
/// <param name="x">The x coordinate in 2d-space.</param>
/// <param name="y">The y coordinate in 2d-space.</param>
public Point(int x, int y)
{
this.X = x;
this.Y = y;
}
/// <summary>
/// Constructs a point with X and Y set to the same value.
/// </summary>
/// <param name="value">The x and y coordinates in 2d-space.</param>
public Point(int value)
{
this.X = value;
this.Y = value;
}
#endregion
#region Operators
/// <summary>
/// Adds two points.
/// </summary>
/// <param name="value1">Source <see cref="Point"/> on the left of the add sign.</param>
/// <param name="value2">Source <see cref="Point"/> on the right of the add sign.</param>
/// <returns>Sum of the points.</returns>
public static Point operator +(Point value1, Point value2)
{
return new Point(value1.X + value2.X, value1.Y + value2.Y);
}
/// <summary>
/// Subtracts a <see cref="Point"/> from a <see cref="Point"/>.
/// </summary>
/// <param name="value1">Source <see cref="Point"/> on the left of the sub sign.</param>
/// <param name="value2">Source <see cref="Point"/> on the right of the sub sign.</param>
/// <returns>Result of the subtraction.</returns>
public static Point operator -(Point value1, Point value2)
{
return new Point(value1.X - value2.X, value1.Y - value2.Y);
}
/// <summary>
/// Multiplies the components of two points by each other.
/// </summary>
/// <param name="value1">Source <see cref="Point"/> on the left of the mul sign.</param>
/// <param name="value2">Source <see cref="Point"/> on the right of the mul sign.</param>
/// <returns>Result of the multiplication.</returns>
public static Point operator *(Point value1, Point value2)
{
return new Point(value1.X * value2.X, value1.Y * value2.Y);
}
/// <summary>
/// Divides the components of a <see cref="Point"/> by the components of another <see cref="Point"/>.
/// </summary>
/// <param name="source">Source <see cref="Point"/> on the left of the div sign.</param>
/// <param name="divisor">Divisor <see cref="Point"/> on the right of the div sign.</param>
/// <returns>The result of dividing the points.</returns>
public static Point operator /(Point source, Point divisor)
{
return new Point(source.X / divisor.X, source.Y / divisor.Y);
}
/// <summary>
/// Compares whether two <see cref="Point"/> instances are equal.
/// </summary>
/// <param name="a"><see cref="Point"/> instance on the left of the equal sign.</param>
/// <param name="b"><see cref="Point"/> instance on the right of the equal sign.</param>
/// <returns><c>true</c> if the instances are equal; <c>false</c> otherwise.</returns>
public static bool operator ==(Point a, Point b)
{
return a.Equals(b);
}
/// <summary>
/// Compares whether two <see cref="Point"/> instances are not equal.
/// </summary>
/// <param name="a"><see cref="Point"/> instance on the left of the not equal sign.</param>
/// <param name="b"><see cref="Point"/> instance on the right of the not equal sign.</param>
/// <returns><c>true</c> if the instances are not equal; <c>false</c> otherwise.</returns>
public static bool operator !=(Point a, Point b)
{
return !a.Equals(b);
}
#endregion
#region Public methods
/// <summary>
/// Compares whether current instance is equal to specified <see cref="Object"/>.
/// </summary>
/// <param name="obj">The <see cref="Object"/> to compare.</param>
/// <returns><c>true</c> if the instances are equal; <c>false</c> otherwise.</returns>
public override bool Equals(object obj)
{
return (obj is Point) && Equals((Point)obj);
}
/// <summary>
/// Compares whether current instance is equal to specified <see cref="Point"/>.
/// </summary>
/// <param name="other">The <see cref="Point"/> to compare.</param>
/// <returns><c>true</c> if the instances are equal; <c>false</c> otherwise.</returns>
public bool Equals(Point other)
{
return ((X == other.X) && (Y == other.Y));
}
/// <summary>
/// Gets the hash code of this <see cref="Point"/>.
/// </summary>
/// <returns>Hash code of this <see cref="Point"/>.</returns>
public override int GetHashCode()
{
unchecked
{
var hash = 17;
hash = hash * 23 + X.GetHashCode();
hash = hash * 23 + Y.GetHashCode();
return hash;
}
}
/// <summary>
/// Returns a <see cref="String"/> representation of this <see cref="Point"/> in the format:
/// {X:[<see cref="X"/>] Y:[<see cref="Y"/>]}
/// </summary>
/// <returns><see cref="String"/> representation of this <see cref="Point"/>.</returns>
public override string ToString()
{
return "{X:" + X + " Y:" + Y + "}";
}
/// <summary>
/// Gets a <see cref="Vector2"/> representation for this object.
/// </summary>
/// <returns>A <see cref="Vector2"/> representation for this object.</returns>
public Vector2 ToVector2()
{
return new Vector2(X, Y);
}
#endregion
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,524 @@
// MIT License - Copyright (C) The Mono.Xna Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
using System.Runtime.Serialization;
using System.Diagnostics;
namespace Microsoft.Xna.Framework
{
/// <summary>
/// Describes a 2D-rectangle.
/// </summary>
[DebuggerDisplay("{DebugDisplayString,nq}")]
public struct Rectangle : IEquatable<Rectangle>
{
#region Private Fields
private static Rectangle emptyRectangle = new Rectangle();
#endregion
#region Public Fields
/// <summary>
/// The x coordinate of the top-left corner of this <see cref="Rectangle"/>.
/// </summary>
public int X;
/// <summary>
/// The y coordinate of the top-left corner of this <see cref="Rectangle"/>.
/// </summary>
public int Y;
/// <summary>
/// The width of this <see cref="Rectangle"/>.
/// </summary>
public int Width;
/// <summary>
/// The height of this <see cref="Rectangle"/>.
/// </summary>
public int Height;
#endregion
#region Public Properties
/// <summary>
/// Returns a <see cref="Rectangle"/> with X=0, Y=0, Width=0, Height=0.
/// </summary>
public static Rectangle Empty
{
get { return emptyRectangle; }
}
/// <summary>
/// Returns the x coordinate of the left edge of this <see cref="Rectangle"/>.
/// </summary>
public int Left
{
get { return this.X; }
}
/// <summary>
/// Returns the x coordinate of the right edge of this <see cref="Rectangle"/>.
/// </summary>
public int Right
{
get { return (this.X + this.Width); }
}
/// <summary>
/// Returns the y coordinate of the top edge of this <see cref="Rectangle"/>.
/// </summary>
public int Top
{
get { return this.Y; }
}
/// <summary>
/// Returns the y coordinate of the bottom edge of this <see cref="Rectangle"/>.
/// </summary>
public int Bottom
{
get { return (this.Y + this.Height); }
}
/// <summary>
/// Whether or not this <see cref="Rectangle"/> has a <see cref="Width"/> and
/// <see cref="Height"/> of 0, and a <see cref="Location"/> of (0, 0).
/// </summary>
public bool IsEmpty
{
get
{
return ((((this.Width == 0) && (this.Height == 0)) && (this.X == 0)) && (this.Y == 0));
}
}
/// <summary>
/// The top-left coordinates of this <see cref="Rectangle"/>.
/// </summary>
public Point Location
{
get
{
return new Point(this.X, this.Y);
}
set
{
X = value.X;
Y = value.Y;
}
}
/// <summary>
/// The width-height coordinates of this <see cref="Rectangle"/>.
/// </summary>
public Point Size
{
get
{
return new Point(this.Width,this.Height);
}
set
{
Width = value.X;
Height = value.Y;
}
}
/// <summary>
/// A <see cref="Point"/> located in the center of this <see cref="Rectangle"/>.
/// </summary>
/// <remarks>
/// If <see cref="Width"/> or <see cref="Height"/> is an odd number,
/// the center point will be rounded down.
/// </remarks>
public Point Center
{
get
{
return new Point(this.X + (this.Width / 2), this.Y + (this.Height / 2));
}
}
#endregion
#region Internal Properties
internal string DebugDisplayString
{
get
{
return string.Concat(
this.X, " ",
this.Y, " ",
this.Width, " ",
this.Height
);
}
}
#endregion
#region Constructors
/// <summary>
/// Creates a new instance of <see cref="Rectangle"/> struct, with the specified
/// position, width, and height.
/// </summary>
/// <param name="x">The x coordinate of the top-left corner of the created <see cref="Rectangle"/>.</param>
/// <param name="y">The y coordinate of the top-left corner of the created <see cref="Rectangle"/>.</param>
/// <param name="width">The width of the created <see cref="Rectangle"/>.</param>
/// <param name="height">The height of the created <see cref="Rectangle"/>.</param>
public Rectangle(int x, int y, int width, int height)
{
this.X = x;
this.Y = y;
this.Width = width;
this.Height = height;
}
/// <summary>
/// Creates a new instance of <see cref="Rectangle"/> struct, with the specified
/// location and size.
/// </summary>
/// <param name="location">The x and y coordinates of the top-left corner of the created <see cref="Rectangle"/>.</param>
/// <param name="size">The width and height of the created <see cref="Rectangle"/>.</param>
public Rectangle(Point location,Point size)
{
this.X = location.X;
this.Y = location.Y;
this.Width = size.X;
this.Height = size.Y;
}
#endregion
#region Operators
/// <summary>
/// Compares whether two <see cref="Rectangle"/> instances are equal.
/// </summary>
/// <param name="a"><see cref="Rectangle"/> instance on the left of the equal sign.</param>
/// <param name="b"><see cref="Rectangle"/> instance on the right of the equal sign.</param>
/// <returns><c>true</c> if the instances are equal; <c>false</c> otherwise.</returns>
public static bool operator ==(Rectangle a, Rectangle b)
{
return ((a.X == b.X) && (a.Y == b.Y) && (a.Width == b.Width) && (a.Height == b.Height));
}
/// <summary>
/// Compares whether two <see cref="Rectangle"/> instances are not equal.
/// </summary>
/// <param name="a"><see cref="Rectangle"/> instance on the left of the not equal sign.</param>
/// <param name="b"><see cref="Rectangle"/> instance on the right of the not equal sign.</param>
/// <returns><c>true</c> if the instances are not equal; <c>false</c> otherwise.</returns>
public static bool operator !=(Rectangle a, Rectangle b)
{
return !(a == b);
}
#endregion
#region Public Methods
/// <summary>
/// Gets whether or not the provided coordinates lie within the bounds of this <see cref="Rectangle"/>.
/// </summary>
/// <param name="x">The x coordinate of the point to check for containment.</param>
/// <param name="y">The y coordinate of the point to check for containment.</param>
/// <returns><c>true</c> if the provided coordinates lie inside this <see cref="Rectangle"/>; <c>false</c> otherwise.</returns>
public bool Contains(int x, int y)
{
return ((((this.X <= x) && (x < (this.X + this.Width))) && (this.Y <= y)) && (y < (this.Y + this.Height)));
}
/// <summary>
/// Gets whether or not the provided coordinates lie within the bounds of this <see cref="Rectangle"/>.
/// </summary>
/// <param name="x">The x coordinate of the point to check for containment.</param>
/// <param name="y">The y coordinate of the point to check for containment.</param>
/// <returns><c>true</c> if the provided coordinates lie inside this <see cref="Rectangle"/>; <c>false</c> otherwise.</returns>
public bool Contains(float x, float y)
{
return ((((this.X <= x) && (x < (this.X + this.Width))) && (this.Y <= y)) && (y < (this.Y + this.Height)));
}
/// <summary>
/// Gets whether or not the provided <see cref="Point"/> lies within the bounds of this <see cref="Rectangle"/>.
/// </summary>
/// <param name="value">The coordinates to check for inclusion in this <see cref="Rectangle"/>.</param>
/// <returns><c>true</c> if the provided <see cref="Point"/> lies inside this <see cref="Rectangle"/>; <c>false</c> otherwise.</returns>
public bool Contains(Point value)
{
return ((((this.X <= value.X) && (value.X < (this.X + this.Width))) && (this.Y <= value.Y)) && (value.Y < (this.Y + this.Height)));
}
/// <summary>
/// Gets whether or not the provided <see cref="Point"/> lies within the bounds of this <see cref="Rectangle"/>.
/// </summary>
/// <param name="value">The coordinates to check for inclusion in this <see cref="Rectangle"/>.</param>
/// <param name="result"><c>true</c> if the provided <see cref="Point"/> lies inside this <see cref="Rectangle"/>; <c>false</c> otherwise. As an output parameter.</param>
public void Contains(ref Point value, out bool result)
{
result = ((((this.X <= value.X) && (value.X < (this.X + this.Width))) && (this.Y <= value.Y)) && (value.Y < (this.Y + this.Height)));
}
/// <summary>
/// Gets whether or not the provided <see cref="Vector2"/> lies within the bounds of this <see cref="Rectangle"/>.
/// </summary>
/// <param name="value">The coordinates to check for inclusion in this <see cref="Rectangle"/>.</param>
/// <returns><c>true</c> if the provided <see cref="Vector2"/> lies inside this <see cref="Rectangle"/>; <c>false</c> otherwise.</returns>
public bool Contains(Vector2 value)
{
return ((((this.X <= value.X) && (value.X < (this.X + this.Width))) && (this.Y <= value.Y)) && (value.Y < (this.Y + this.Height)));
}
/// <summary>
/// Gets whether or not the provided <see cref="Vector2"/> lies within the bounds of this <see cref="Rectangle"/>.
/// </summary>
/// <param name="value">The coordinates to check for inclusion in this <see cref="Rectangle"/>.</param>
/// <param name="result"><c>true</c> if the provided <see cref="Vector2"/> lies inside this <see cref="Rectangle"/>; <c>false</c> otherwise. As an output parameter.</param>
public void Contains(ref Vector2 value, out bool result)
{
result = ((((this.X <= value.X) && (value.X < (this.X + this.Width))) && (this.Y <= value.Y)) && (value.Y < (this.Y + this.Height)));
}
/// <summary>
/// Gets whether or not the provided <see cref="Rectangle"/> lies within the bounds of this <see cref="Rectangle"/>.
/// </summary>
/// <param name="value">The <see cref="Rectangle"/> to check for inclusion in this <see cref="Rectangle"/>.</param>
/// <returns><c>true</c> if the provided <see cref="Rectangle"/>'s bounds lie entirely inside this <see cref="Rectangle"/>; <c>false</c> otherwise.</returns>
public bool Contains(Rectangle value)
{
return ((((this.X <= value.X) && ((value.X + value.Width) <= (this.X + this.Width))) && (this.Y <= value.Y)) && ((value.Y + value.Height) <= (this.Y + this.Height)));
}
/// <summary>
/// Gets whether or not the provided <see cref="Rectangle"/> lies within the bounds of this <see cref="Rectangle"/>.
/// </summary>
/// <param name="value">The <see cref="Rectangle"/> to check for inclusion in this <see cref="Rectangle"/>.</param>
/// <param name="result"><c>true</c> if the provided <see cref="Rectangle"/>'s bounds lie entirely inside this <see cref="Rectangle"/>; <c>false</c> otherwise. As an output parameter.</param>
public void Contains(ref Rectangle value,out bool result)
{
result = ((((this.X <= value.X) && ((value.X + value.Width) <= (this.X + this.Width))) && (this.Y <= value.Y)) && ((value.Y + value.Height) <= (this.Y + this.Height)));
}
/// <summary>
/// Compares whether current instance is equal to specified <see cref="Object"/>.
/// </summary>
/// <param name="obj">The <see cref="Object"/> to compare.</param>
/// <returns><c>true</c> if the instances are equal; <c>false</c> otherwise.</returns>
public override bool Equals(object obj)
{
return (obj is Rectangle) && this == ((Rectangle)obj);
}
/// <summary>
/// Compares whether current instance is equal to specified <see cref="Rectangle"/>.
/// </summary>
/// <param name="other">The <see cref="Rectangle"/> to compare.</param>
/// <returns><c>true</c> if the instances are equal; <c>false</c> otherwise.</returns>
public bool Equals(Rectangle other)
{
return this == other;
}
/// <summary>
/// Gets the hash code of this <see cref="Rectangle"/>.
/// </summary>
/// <returns>Hash code of this <see cref="Rectangle"/>.</returns>
public override int GetHashCode()
{
unchecked
{
var hash = 17;
hash = hash * 23 + X.GetHashCode();
hash = hash * 23 + Y.GetHashCode();
hash = hash * 23 + Width.GetHashCode();
hash = hash * 23 + Height.GetHashCode();
return hash;
}
}
/// <summary>
/// Adjusts the edges of this <see cref="Rectangle"/> by specified horizontal and vertical amounts.
/// </summary>
/// <param name="horizontalAmount">Value to adjust the left and right edges.</param>
/// <param name="verticalAmount">Value to adjust the top and bottom edges.</param>
public void Inflate(int horizontalAmount, int verticalAmount)
{
X -= horizontalAmount;
Y -= verticalAmount;
Width += horizontalAmount * 2;
Height += verticalAmount * 2;
}
/// <summary>
/// Adjusts the edges of this <see cref="Rectangle"/> by specified horizontal and vertical amounts.
/// </summary>
/// <param name="horizontalAmount">Value to adjust the left and right edges.</param>
/// <param name="verticalAmount">Value to adjust the top and bottom edges.</param>
public void Inflate(float horizontalAmount, float verticalAmount)
{
X -= (int)horizontalAmount;
Y -= (int)verticalAmount;
Width += (int)horizontalAmount * 2;
Height += (int)verticalAmount * 2;
}
/// <summary>
/// Gets whether or not the other <see cref="Rectangle"/> intersects with this rectangle.
/// </summary>
/// <param name="value">The other rectangle for testing.</param>
/// <returns><c>true</c> if other <see cref="Rectangle"/> intersects with this rectangle; <c>false</c> otherwise.</returns>
public bool Intersects(Rectangle value)
{
return value.Left < Right &&
Left < value.Right &&
value.Top < Bottom &&
Top < value.Bottom;
}
/// <summary>
/// Gets whether or not the other <see cref="Rectangle"/> intersects with this rectangle.
/// </summary>
/// <param name="value">The other rectangle for testing.</param>
/// <param name="result"><c>true</c> if other <see cref="Rectangle"/> intersects with this rectangle; <c>false</c> otherwise. As an output parameter.</param>
public void Intersects(ref Rectangle value, out bool result)
{
result = value.Left < Right &&
Left < value.Right &&
value.Top < Bottom &&
Top < value.Bottom;
}
/// <summary>
/// Creates a new <see cref="Rectangle"/> that contains overlapping region of two other rectangles.
/// </summary>
/// <param name="value1">The first <see cref="Rectangle"/>.</param>
/// <param name="value2">The second <see cref="Rectangle"/>.</param>
/// <returns>Overlapping region of the two rectangles.</returns>
public static Rectangle Intersect(Rectangle value1, Rectangle value2)
{
Rectangle rectangle;
Intersect(ref value1, ref value2, out rectangle);
return rectangle;
}
/// <summary>
/// Creates a new <see cref="Rectangle"/> that contains overlapping region of two other rectangles.
/// </summary>
/// <param name="value1">The first <see cref="Rectangle"/>.</param>
/// <param name="value2">The second <see cref="Rectangle"/>.</param>
/// <param name="result">Overlapping region of the two rectangles as an output parameter.</param>
public static void Intersect(ref Rectangle value1, ref Rectangle value2, out Rectangle result)
{
if (value1.Intersects(value2))
{
int right_side = Math.Min(value1.X + value1.Width, value2.X + value2.Width);
int left_side = Math.Max(value1.X, value2.X);
int top_side = Math.Max(value1.Y, value2.Y);
int bottom_side = Math.Min(value1.Y + value1.Height, value2.Y + value2.Height);
result = new Rectangle(left_side, top_side, right_side - left_side, bottom_side - top_side);
}
else
{
result = new Rectangle(0, 0, 0, 0);
}
}
/// <summary>
/// Changes the <see cref="Location"/> of this <see cref="Rectangle"/>.
/// </summary>
/// <param name="offsetX">The x coordinate to add to this <see cref="Rectangle"/>.</param>
/// <param name="offsetY">The y coordinate to add to this <see cref="Rectangle"/>.</param>
public void Offset(int offsetX, int offsetY)
{
X += offsetX;
Y += offsetY;
}
/// <summary>
/// Changes the <see cref="Location"/> of this <see cref="Rectangle"/>.
/// </summary>
/// <param name="offsetX">The x coordinate to add to this <see cref="Rectangle"/>.</param>
/// <param name="offsetY">The y coordinate to add to this <see cref="Rectangle"/>.</param>
public void Offset(float offsetX, float offsetY)
{
X += (int)offsetX;
Y += (int)offsetY;
}
/// <summary>
/// Changes the <see cref="Location"/> of this <see cref="Rectangle"/>.
/// </summary>
/// <param name="amount">The x and y components to add to this <see cref="Rectangle"/>.</param>
public void Offset(Point amount)
{
X += amount.X;
Y += amount.Y;
}
/// <summary>
/// Changes the <see cref="Location"/> of this <see cref="Rectangle"/>.
/// </summary>
/// <param name="amount">The x and y components to add to this <see cref="Rectangle"/>.</param>
public void Offset(Vector2 amount)
{
X += (int)amount.X;
Y += (int)amount.Y;
}
/// <summary>
/// Returns a <see cref="String"/> representation of this <see cref="Rectangle"/> in the format:
/// {X:[<see cref="X"/>] Y:[<see cref="Y"/>] Width:[<see cref="Width"/>] Height:[<see cref="Height"/>]}
/// </summary>
/// <returns><see cref="String"/> representation of this <see cref="Rectangle"/>.</returns>
public override string ToString()
{
return "{X:" + X + " Y:" + Y + " Width:" + Width + " Height:" + Height + "}";
}
/// <summary>
/// Creates a new <see cref="Rectangle"/> that completely contains two other rectangles.
/// </summary>
/// <param name="value1">The first <see cref="Rectangle"/>.</param>
/// <param name="value2">The second <see cref="Rectangle"/>.</param>
/// <returns>The union of the two rectangles.</returns>
public static Rectangle Union(Rectangle value1, Rectangle value2)
{
int x = Math.Min(value1.X, value2.X);
int y = Math.Min(value1.Y, value2.Y);
return new Rectangle(x, y,
Math.Max(value1.Right, value2.Right) - x,
Math.Max(value1.Bottom, value2.Bottom) - y);
}
/// <summary>
/// Creates a new <see cref="Rectangle"/> that completely contains two other rectangles.
/// </summary>
/// <param name="value1">The first <see cref="Rectangle"/>.</param>
/// <param name="value2">The second <see cref="Rectangle"/>.</param>
/// <param name="result">The union of the two rectangles as an output parameter.</param>
public static void Union(ref Rectangle value1, ref Rectangle value2, out Rectangle result)
{
result.X = Math.Min(value1.X, value2.X);
result.Y = Math.Min(value1.Y, value2.Y);
result.Width = Math.Max(value1.Right, value2.Right) - result.X;
result.Height = Math.Max(value1.Bottom, value2.Bottom) - result.Y;
}
#endregion
}
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,42 @@
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
namespace Barotrauma
{
public static class XnaToConsoleColor
{
static Dictionary<Color, ConsoleColor> dictionary;
public static ConsoleColor Convert(Color xnaCol)
{
if (dictionary == null)
{
dictionary = new Dictionary<Color, ConsoleColor>();
dictionary.Add(Color.White, ConsoleColor.White);
dictionary.Add(Color.Gray, ConsoleColor.Gray);
dictionary.Add(Color.LightGray, ConsoleColor.Gray);
dictionary.Add(Color.DarkGray, ConsoleColor.Gray);
dictionary.Add(Color.Red, ConsoleColor.Red);
dictionary.Add(Color.DarkRed, ConsoleColor.DarkRed);
dictionary.Add(Color.Yellow, ConsoleColor.Yellow);
dictionary.Add(Color.Orange, ConsoleColor.Yellow);
dictionary.Add(Color.Green, ConsoleColor.Green);
dictionary.Add(Color.Lime, ConsoleColor.Green);
dictionary.Add(Color.Blue, ConsoleColor.Blue);
dictionary.Add(Color.Cyan, ConsoleColor.Cyan);
dictionary.Add(Color.DarkBlue, ConsoleColor.DarkBlue);
dictionary.Add(Color.Pink, ConsoleColor.Magenta);
dictionary.Add(Color.Magenta, ConsoleColor.Magenta);
}
ConsoleColor val = ConsoleColor.White;
if (dictionary.TryGetValue(xnaCol, out val))
{
return val;
}
return ConsoleColor.White;
}
}
}