diff --git a/src/Murder/Core/Graphics/AnimationInfo.cs b/src/Murder/Core/Graphics/AnimationInfo.cs
index bd246f4b..99776c6e 100644
--- a/src/Murder/Core/Graphics/AnimationInfo.cs
+++ b/src/Murder/Core/Graphics/AnimationInfo.cs
@@ -10,6 +10,10 @@ public readonly struct AnimationInfo
public float Start { get; init; } = 0f;
public float Duration { get; init; } = -1f;
+
+ ///
+ /// User Game.Now instead of Game.NowUnscaled. False by default
+ ///
public bool UseScaledTime { get; init; } = false;
public bool Loop { get; init; } = true;
public string Name { get; init; } = string.Empty;
diff --git a/src/Murder/Core/Graphics/Mask2D.cs b/src/Murder/Core/Graphics/Mask2D.cs
index 5914263d..fefc956e 100644
--- a/src/Murder/Core/Graphics/Mask2D.cs
+++ b/src/Murder/Core/Graphics/Mask2D.cs
@@ -12,6 +12,7 @@ public class Mask2D : IDisposable
public readonly Vector2 Size;
private readonly RenderTarget2D _renderTarget;
+ private RenderTarget2D? _previousRenderTarget;
public RenderTarget2D RenderTarget => _renderTarget;
private readonly Batch2D _batch;
@@ -53,6 +54,11 @@ public Batch2D Begin(bool debug = false)
private void SetRenderTarget()
{
+ if (Game.GraphicsDevice.GetRenderTargets().Length>0)
+ {
+ _previousRenderTarget = (RenderTarget2D)Game.GraphicsDevice.GetRenderTargets()[0].RenderTarget;
+ }
+
Game.GraphicsDevice.SetRenderTarget(_renderTarget);
Game.GraphicsDevice.Clear(_color);
}
@@ -79,6 +85,11 @@ public void End(Batch2D targetBatch, Vector2 position, DrawInfo drawInfo)
drawInfo.Color,
drawInfo.Origin.ToXnaVector2(),
drawInfo.GetBlendMode());
+
+ if (_previousRenderTarget is not null)
+ {
+ Game.GraphicsDevice.SetRenderTarget(_previousRenderTarget);
+ }
}
///
diff --git a/src/Murder/Core/Input/PlayerInput.cs b/src/Murder/Core/Input/PlayerInput.cs
index efd161a7..357047de 100644
--- a/src/Murder/Core/Input/PlayerInput.cs
+++ b/src/Murder/Core/Input/PlayerInput.cs
@@ -399,6 +399,15 @@ internal bool Released(int button, bool raw = false)
throw new Exception($"Couldn't find button of type {button}");
}
+
+ [Flags]
+ public enum SimpleMenuFlags
+ {
+ None,
+ Clamp
+ }
+
+
public bool HorizontalMenu(ref int selectedOption, int length)
{
int move = 0;
@@ -420,12 +429,16 @@ public bool HorizontalMenu(ref MenuInfo currentInfo)
return false;
}
+ currentInfo.JustMoved = false;
VirtualAxis axis = GetAxis(MurderInputAxis.Ui);
- return HorizontalOrVerticalMenu(ref currentInfo, input: axis.TickX ? Math.Sign(axis.Value.X) : null,
- overflow: axis.TickY ? axis.IntValue.Y : 0);
+
+ // Check for vertical overflow
+ currentInfo.OverflowY = axis.TickY ? axis.IntValue.Y : 0;
+
+ return HorizontalOrVerticalMenu(ref currentInfo, input: axis.TickX ? Math.Sign(axis.Value.X) : null);
}
- public bool VerticalMenu(ref MenuInfo currentInfo)
+ public bool VerticalMenu(ref MenuInfo currentInfo, SimpleMenuFlags flags = SimpleMenuFlags.None)
{
if (currentInfo.Disabled)
{
@@ -433,13 +446,15 @@ public bool VerticalMenu(ref MenuInfo currentInfo)
}
currentInfo.JustMoved = false;
-
VirtualAxis axis = GetAxis(MurderInputAxis.Ui);
- return HorizontalOrVerticalMenu(ref currentInfo, axis.TickY ? Math.Sign(axis.Value.Y) : null,
- axis.TickX ? axis.IntValue.X : 0);
+
+ // Check for horizontal overflow
+ currentInfo.OverflowX = axis.TickX ? axis.IntValue.X : 0;
+
+ return HorizontalOrVerticalMenu(ref currentInfo, axis.TickY ? Math.Sign(axis.Value.Y) : null, flags);
}
- private bool HorizontalOrVerticalMenu(ref MenuInfo currentInfo, float? input, int overflow)
+ private bool HorizontalOrVerticalMenu(ref MenuInfo currentInfo, float? input, SimpleMenuFlags flags = SimpleMenuFlags.None)
{
bool pressed = false;
if (Pressed(MurderInputButtons.Submit))
@@ -458,8 +473,6 @@ private bool HorizontalOrVerticalMenu(ref MenuInfo currentInfo, float? input, in
currentInfo.Canceled = false;
}
- currentInfo.Overflow = overflow;
-
if (currentInfo.Disabled || currentInfo.Options == null || currentInfo.Length == 0)
return false;
@@ -472,6 +485,20 @@ private bool HorizontalOrVerticalMenu(ref MenuInfo currentInfo, float? input, in
if (input is not null)
{
+ // Fist check if we are clamping the menu
+ if (flags.HasFlag(SimpleMenuFlags.Clamp))
+ {
+ if (input.Value < 0 && currentInfo.Selection == 0)
+ {
+ return pressed;
+ }
+
+ if (input.Value > 0 && currentInfo.Selection == currentInfo.Length - 1)
+ {
+ return pressed;
+ }
+ }
+
// Pick the next option. However, we need to take into account options that can't be selected,
// so this gets slightly trickier.
int sign = Math.Sign(input.Value);
@@ -516,7 +543,7 @@ private bool HorizontalOrVerticalMenu(ref GenericMenuInfo currentInfo, flo
}
currentInfo.Canceled = canceled;
- currentInfo.Overflow = overflow;
+ currentInfo.OverflowX = overflow;
if (currentInfo.Disabled || currentInfo.Options == null || currentInfo.Length == 0)
return false;
@@ -586,7 +613,8 @@ public bool GridMenu(ref MenuInfo currentInfo, int width, int _, int size, GridM
int selectedOptionX = currentInfo.Selection % width;
int selectedOptionY = Calculator.FloorToInt(currentInfo.Selection / width);
- int overflow = 0;
+ int overflowX = 0;
+ int overflowY = 0;
if (axis.PressedX)
{
selectedOptionX += Math.Sign(axis.Value.X);
@@ -595,7 +623,7 @@ public bool GridMenu(ref MenuInfo currentInfo, int width, int _, int size, GridM
if (selectedOptionX >= currentWidth) // Is on last row and it has less than width.
{
- overflow = 1;
+ overflowX = 1;
if (gridMenuFlags.HasFlag(GridMenuFlags.ClampRight))
{
selectedOptionX = currentWidth - 1;
@@ -603,7 +631,7 @@ public bool GridMenu(ref MenuInfo currentInfo, int width, int _, int size, GridM
}
else if (selectedOptionX < 0)
{
- overflow = -1;
+ overflowX = -1;
if (gridMenuFlags.HasFlag(GridMenuFlags.ClampLeft))
{
selectedOptionX = 0;
@@ -622,10 +650,12 @@ public bool GridMenu(ref MenuInfo currentInfo, int width, int _, int size, GridM
if (selectedOptionY >= currentHeight && gridMenuFlags.HasFlag(GridMenuFlags.ClampBottom))
{
+ overflowY = 1;
selectedOptionY = currentHeight - 1;
}
- else if (selectedOptionY < 0)
+ else if (selectedOptionY < 0 && gridMenuFlags.HasFlag(GridMenuFlags.ClampTop))
{
+ overflowY = -1;
selectedOptionY = 0;
}
@@ -659,7 +689,7 @@ public bool GridMenu(ref MenuInfo currentInfo, int width, int _, int size, GridM
else if (isDisabled)
{
int sign = Math.Sign(axis.Value.X) < 0 ? -1 : 1;
- int newOption = currentInfo.NextAvailableOption(currentInfo.Selection, sign);
+ int newOption = currentInfo.NextAvailableOption(currentInfo.Selection, sign); // Ignore the overflow when skipping disabled options.
if (newOption == selectedOptionIndex)
{
@@ -672,7 +702,8 @@ public bool GridMenu(ref MenuInfo currentInfo, int width, int _, int size, GridM
}
currentInfo.Canceled = canceled;
- currentInfo.Overflow = overflow;
+ currentInfo.OverflowX = overflowX;
+ currentInfo.OverflowY = overflowY;
return pressed;
}
@@ -692,7 +723,8 @@ public bool GridMenu(ref GenericMenuInfo currentInfo, int width, int size,
int selectedOptionX = currentInfo.Selection % width;
int selectedOptionY = Calculator.FloorToInt(currentInfo.Selection / width);
- int overflow = 0;
+ int overflowX = 0;
+ int overflowY = 0;
if (axis.PressedX)
{
selectedOptionX += Math.Sign(axis.Value.X);
@@ -701,13 +733,13 @@ public bool GridMenu(ref GenericMenuInfo currentInfo, int width, int size,
if (selectedOptionX >= currentWidth) // Is on last row and it has less than width.
{
- overflow = 1;
+ overflowX = 1;
if (gridMenuFlags.HasFlag(GridMenuFlags.ClampRight))
selectedOptionX = currentWidth - 1;
}
else if (selectedOptionX < 0)
{
- overflow = -1;
+ overflowX = -1;
if (gridMenuFlags.HasFlag(GridMenuFlags.ClampLeft))
selectedOptionX = 0;
}
@@ -726,9 +758,11 @@ public bool GridMenu(ref GenericMenuInfo currentInfo, int width, int size,
if (selectedOptionY >= currentHeight && gridMenuFlags.HasFlag(GridMenuFlags.ClampBottom))
{
selectedOptionY = currentHeight - 1;
+ overflowY = 1;
}
- else if (selectedOptionY < 0)
+ else if (selectedOptionY < 0 && gridMenuFlags.HasFlag(GridMenuFlags.ClampTop))
{
+ overflowY = -1;
selectedOptionY = 0;
}
@@ -754,7 +788,8 @@ public bool GridMenu(ref GenericMenuInfo currentInfo, int width, int size,
currentInfo.Select(selectedOptionIndex, lastMoved);
currentInfo.Canceled = canceled;
- currentInfo.Overflow = overflow;
+ currentInfo.OverflowX = overflowX;
+ currentInfo.OverflowY = overflowY;
return pressed;
}
diff --git a/src/Murder/Services/Info/MenuInfo.cs b/src/Murder/Services/Info/MenuInfo.cs
index 4ca1d0c1..1082925a 100644
--- a/src/Murder/Services/Info/MenuInfo.cs
+++ b/src/Murder/Services/Info/MenuInfo.cs
@@ -1,6 +1,7 @@
using Murder.Core.Sounds;
using Murder.Services;
using Murder.Utilities;
+using static Murder.Core.Input.PlayerInput;
namespace Murder.Core.Input
{
@@ -17,7 +18,8 @@ public struct GenericMenuInfo
public float LastPressed = 0;
public float LastMoved;
- public int Overflow = 0;
+ public int OverflowX = 0;
+ public int OverflowY = 0;
public int PreviousSelection;
///
@@ -96,7 +98,8 @@ public struct MenuInfo
public float LastPressed;
public bool Canceled;
public bool Disabled = false;
- public int Overflow = 0;
+ public int OverflowX = 0;
+ public int OverflowY = 0;
public bool JustMoved = false;
public int Scroll = 0;