Skip to content

Commit

Permalink
[HaRepacker] Simulator: Field VR (left and right) border
Browse files Browse the repository at this point in the history
Fixes for EOS tower, & Orbis tower
  • Loading branch information
lastbattle committed Jan 11, 2021
1 parent 266210b commit 34199ac
Showing 1 changed file with 87 additions and 2 deletions.
89 changes: 87 additions & 2 deletions HaCreator/MapSimulator/MapSimulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public class MapSimulator : Microsoft.Xna.Framework.Game

// Boundary, borders
private Rectangle vr_fieldBoundary;
private const int VR_BORDER_WIDTHHEIGHT = 600; // the height or width of the VR border
private Texture2D texture_vrBoundaryRectLeft, texture_vrBoundaryRectRight, texture_vrBoundaryRectTop, texture_vrBoundaryRectBottom;

// Minimap
private MinimapItem miniMap;
Expand Down Expand Up @@ -131,7 +133,7 @@ public MapSimulator(Board mapBoard, string titleName)
SupportedOrientations = DisplayOrientation.Default,
PreferredBackBufferWidth = Math.Max(RenderWidth, 1),
PreferredBackBufferHeight = Math.Max(RenderHeight, 1),
PreferredBackBufferFormat = SurfaceFormat.Color,
PreferredBackBufferFormat = SurfaceFormat.Color | SurfaceFormat.Bgr32 | SurfaceFormat.Dxt1| SurfaceFormat.Dxt5,
PreferredDepthStencilFormat = DepthFormat.Depth24Stencil8,
};
_DxDeviceManager.DeviceCreated += graphics_DeviceCreated;
Expand Down Expand Up @@ -248,9 +250,13 @@ protected override void LoadContent()
}
}
if (mapBoard.VRRectangle == null)
{
vr_fieldBoundary = new Rectangle(0, 0, mapBoard.MapSize.X, mapBoard.MapSize.Y);
}
else
{
vr_fieldBoundary = new Rectangle(mapBoard.VRRectangle.X + mapBoard.CenterPoint.X, mapBoard.VRRectangle.Y + mapBoard.CenterPoint.Y, mapBoard.VRRectangle.Width, mapBoard.VRRectangle.Height);
}
//SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true);

// test benchmark
Expand Down Expand Up @@ -409,6 +415,13 @@ protected override void LoadContent()
SetCameraMoveX(true, true, 0);
SetCameraMoveY(true, true, 0);

///////////// Border
// Left
texture_vrBoundaryRectLeft = CreateVRBorder(VR_BORDER_WIDTHHEIGHT, vr_fieldBoundary.Height, _DxDeviceManager.GraphicsDevice);
texture_vrBoundaryRectRight = CreateVRBorder(VR_BORDER_WIDTHHEIGHT, vr_fieldBoundary.Height, _DxDeviceManager.GraphicsDevice);
texture_vrBoundaryRectTop = CreateVRBorder(vr_fieldBoundary.Width * 2, VR_BORDER_WIDTHHEIGHT, _DxDeviceManager.GraphicsDevice);
texture_vrBoundaryRectBottom = CreateVRBorder(vr_fieldBoundary.Width * 2, VR_BORDER_WIDTHHEIGHT, _DxDeviceManager.GraphicsDevice);

// Debug items
System.Drawing.Bitmap bitmap_debug = new System.Drawing.Bitmap(1, 1);
bitmap_debug.SetPixel(0, 0, System.Drawing.Color.White);
Expand All @@ -425,6 +438,26 @@ protected override void LoadContent()

}

/// <summary>
/// Creates the black VR Border Texture2D object
/// </summary>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="graphicsDevice"></param>
/// <returns></returns>
private static Texture2D CreateVRBorder(int width, int height, GraphicsDevice graphicsDevice)
{
System.Drawing.Color brBorderColor = System.Drawing.Color.Black;
System.Drawing.Bitmap bitmap_vrBorder = new System.Drawing.Bitmap(width, height);

for (int x = 0; x < bitmap_vrBorder.Width; x++)
for (int y = 0; y < bitmap_vrBorder.Height; y++)
bitmap_vrBorder.SetPixel(x, y, brBorderColor); // is there a better way of doing this than looping?

Texture2D texture_vrBoundaryRect = bitmap_vrBorder.ToTexture2D(graphicsDevice);
return texture_vrBoundaryRect;
}

protected override void UnloadContent()
{
if (audio != null)
Expand Down Expand Up @@ -638,6 +671,8 @@ protected override void Draw(GameTime gameTime)
//Rectangle titleSafeRectangle = GraphicsDevice.Viewport.TitleSafeArea;
//DrawBorder(spriteBatch, titleSafeRectangle, 1, Color.Black);

DrawVRFieldBorder(spriteBatch);

//////////////////// UI related here ////////////////////
// Tooltips
if (mapObjects_tooltips.Count > 0)
Expand Down Expand Up @@ -715,14 +750,64 @@ protected override void Draw(GameTime gameTime)
base.Draw(gameTime);
}

/// <summary>
/// Draws the VR border
/// </summary>
/// <param name="sprite"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void DrawVRFieldBorder(SpriteBatch sprite)
{
if (vr_fieldBoundary.X == 0 && vr_fieldBoundary.Y == 0)
return;

Color borderColor = Color.Black;


// Draw top line
/* sprite.Draw(texture_vrBoundaryRectTop,
new Rectangle(
vr_fieldBoundary.Left - (VR_BORDER_WIDTHHEIGHT + mapShiftX),
vr_fieldBoundary.Top - (VR_BORDER_WIDTHHEIGHT + mapShiftY),
vr_fieldBoundary.Width * 2,
VR_BORDER_WIDTHHEIGHT),
borderColor);
// Draw bottom line
sprite.Draw(texture_vrBoundaryRectBottom,
new Rectangle(
vr_fieldBoundary.Left - (VR_BORDER_WIDTHHEIGHT + mapShiftX),
vr_fieldBoundary.Bottom - (mapShiftY),
vr_fieldBoundary.Width * 2,
VR_BORDER_WIDTHHEIGHT),
borderColor);*/

// Draw left line
sprite.Draw(texture_vrBoundaryRectLeft,
new Rectangle(
vr_fieldBoundary.Left - (VR_BORDER_WIDTHHEIGHT + mapShiftX),
vr_fieldBoundary.Top - (mapShiftY),
VR_BORDER_WIDTHHEIGHT,
vr_fieldBoundary.Height),
borderColor);

// Draw right line
sprite.Draw(texture_vrBoundaryRectRight,
new Rectangle(
vr_fieldBoundary.Right - mapShiftX,
vr_fieldBoundary.Top - (mapShiftY),
VR_BORDER_WIDTHHEIGHT,
vr_fieldBoundary.Height),
borderColor);
}

/// <summary>
/// Draws a border
/// </summary>
/// <param name="sprite"></param>
/// <param name="rectangleToDraw"></param>
/// <param name="thicknessOfBorder"></param>
/// <param name="borderColor"></param>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void DrawBorder(SpriteBatch sprite, Rectangle rectangleToDraw, int thicknessOfBorder, Color borderColor)
{
// Draw top line
Expand Down

1 comment on commit 34199ac

@lastbattle
Copy link
Owner Author

@lastbattle lastbattle commented on 34199ac Jan 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

image

Please sign in to comment.