Skip to content

Commit

Permalink
Added left handed display mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeoliphant committed May 24, 2024
1 parent 4a66d7f commit a2363ac
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 9 deletions.
72 changes: 64 additions & 8 deletions ChartPlayerShared/FretPlayerScene3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
using Microsoft.Xna.Framework;
using UILayout;
using SongFormat;
using System.Windows.Forms;

namespace ChartPlayer
{
public class FretCamera : Camera3D
{
public float CameraDistance { get; private set; } = 70;
public float FocusDist { get; set; } = 600;
public bool MirrorLeftRight { get; set; } = false;

float targetCameraDistance = 64;
float positionFret = 3;
Expand All @@ -27,7 +29,10 @@ public FretCamera()

public override Matrix GetViewMatrix()
{
return base.GetViewMatrix(); // * Matrix.CreateScale(-1, 1, 1);
if (MirrorLeftRight)
return base.GetViewMatrix() * Matrix.CreateScale(-1, 1, 1);

return base.GetViewMatrix();
}

public void Update(float minFret, float maxFret, float targetFocusFret, float focusY)
Expand Down Expand Up @@ -73,6 +78,15 @@ public class FretPlayerScene3D : Scene3D
static string[] stringColorNames = { "Red", "Yellow", "Cyan", "Orange", "Green", "Purple" };

public bool DisplayNotes { get; set; } = true;
public bool LeftyMode
{
get => lefyMode;
set
{
lefyMode = value;
fretCamera.MirrorLeftRight = lefyMode;
}
}
public float NoteDisplaySeconds { get; set; } = 3;
public int NumNotesDetected { get; private set; } = 0;
public int NumNotesTotal { get; private set; } = 0;
Expand All @@ -91,6 +105,7 @@ public class FretPlayerScene3D : Scene3D
SongNote? firstNote;
int numStrings;
bool isDetected = false;
bool lefyMode = false;

FretCamera fretCamera;

Expand Down Expand Up @@ -1204,7 +1219,18 @@ void DrawFlatText(string text, float fretCenter, float timeCenter, float heightO

Rectangle drawRect = Rectangle.Empty;

for (int i = 0; i < text.Length; i++)
int start = 0;
int end = text.Length;
int inc = 1;

if (LeftyMode)
{
start = text.Length - 1;
end = -1;
inc = -1;
}

for (int i = start; i != end; i += inc)
{
float z = timeCenter - (textHeight / 2);

Expand All @@ -1217,9 +1243,19 @@ void DrawFlatText(string text, float fretCenter, float timeCenter, float heightO
drawRect.Width = glyph.Width;
drawRect.Height = glyph.Height;

DrawQuad(font.SpriteFont.FontImage, drawRect, new Vector3(x, heightOffset, z), color, new Vector3(x, heightOffset, z + ((float)glyph.Height * imageScale)), color,
new Vector3(x + ((float)glyph.Width * imageScale), heightOffset, z + ((float)glyph.Height * imageScale)), color,
new Vector3(x + ((float)glyph.Width * imageScale), heightOffset, z), color);
if (LeftyMode)
{
DrawQuad(font.SpriteFont.FontImage, drawRect, new Vector3(x + ((float)glyph.Width * imageScale), heightOffset, z), color, new Vector3(x + ((float)glyph.Width * imageScale), heightOffset, z + ((float)glyph.Height * imageScale)), color,
new Vector3(x, heightOffset, z + ((float)glyph.Height * imageScale)), color,
new Vector3(x, heightOffset, z), color);
}
else
{
DrawQuad(font.SpriteFont.FontImage, drawRect, new Vector3(x, heightOffset, z), color, new Vector3(x, heightOffset, z + ((float)glyph.Height * imageScale)), color,
new Vector3(x + ((float)glyph.Width * imageScale), heightOffset, z + ((float)glyph.Height * imageScale)), color,
new Vector3(x + ((float)glyph.Width * imageScale), heightOffset, z), color);

}

x += (glyph.Width + font.SpriteFont.Spacing) * imageScale;
}
Expand Down Expand Up @@ -1255,7 +1291,18 @@ void DrawVerticalText(string text, float fretCenter, float verticalCenter, float

Rectangle drawRect = Rectangle.Empty;

for (int i = 0; i < text.Length; i++)
int start = 0;
int end = text.Length;
int inc = 1;

if (LeftyMode)
{
start = text.Length - 1;
end = -1;
inc = -1;
}

for (int i = start; i != end; i += inc)
{
float y = verticalCenter - (textHeight / 2);

Expand All @@ -1268,8 +1315,17 @@ void DrawVerticalText(string text, float fretCenter, float verticalCenter, float
drawRect.Width = glyph.Width;
drawRect.Height = glyph.Height;

DrawQuad(font.SpriteFont.FontImage, drawRect, new Vector3(x, y, timeCenter), color, new Vector3(x, y + ((float)glyph.Height * imageScale), timeCenter), color,
new Vector3(x + ((float)glyph.Width * imageScale), y + ((float)glyph.Height * imageScale), timeCenter), color, new Vector3(x + ((float)glyph.Width * imageScale), y, timeCenter), color);
if (LeftyMode)
{
DrawQuad(font.SpriteFont.FontImage, drawRect, new Vector3(x + ((float)glyph.Width * imageScale), y, timeCenter), color, new Vector3(x + ((float)glyph.Width * imageScale), y + ((float)glyph.Height * imageScale), timeCenter), color,
new Vector3(x, y + ((float)glyph.Height * imageScale), timeCenter), color, new Vector3(x, y, timeCenter), color);
}
else
{
DrawQuad(font.SpriteFont.FontImage, drawRect, new Vector3(x, y, timeCenter), color, new Vector3(x, y + ((float)glyph.Height * imageScale), timeCenter), color,
new Vector3(x + ((float)glyph.Width * imageScale), y + ((float)glyph.Height * imageScale), timeCenter), color, new Vector3(x + ((float)glyph.Width * imageScale), y, timeCenter), color);
}


x += (glyph.Width + font.SpriteFont.Spacing) * imageScale;
}
Expand Down
7 changes: 6 additions & 1 deletion ChartPlayerShared/SongPlayerInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,11 @@ public void SetSong(SongIndexEntry song, ESongInstrumentType instrumentType, str
(ChartPlayerGame.Instance.Scene3D as FretPlayerScene3D).Stop();
}

ChartPlayerGame.Instance.Scene3D = new FretPlayerScene3D(songPlayer) { NoteDisplaySeconds = ChartPlayerGame.Instance.Plugin.ChartPlayerSaveState.SongPlayerSettings.NoteDisplaySeconds };
ChartPlayerGame.Instance.Scene3D = new FretPlayerScene3D(songPlayer)
{
LeftyMode = ChartPlayerGame.Instance.Plugin.ChartPlayerSaveState.SongPlayerSettings.LeftyMode,
NoteDisplaySeconds = ChartPlayerGame.Instance.Plugin.ChartPlayerSaveState.SongPlayerSettings.NoteDisplaySeconds
};

(ChartPlayerGame.Instance.Scene3D as FretPlayerScene3D).DisplayNotes = !hideNotesButton.IsPressed;
}
Expand Down Expand Up @@ -457,6 +461,7 @@ void ApplySettings(SongPlayerSettings settings)

if ((ChartPlayerGame.Instance.Scene3D as FretPlayerScene3D) != null)
{
(ChartPlayerGame.Instance.Scene3D as FretPlayerScene3D).LeftyMode = ChartPlayerGame.Instance.Plugin.ChartPlayerSaveState.SongPlayerSettings.LeftyMode;
(ChartPlayerGame.Instance.Scene3D as FretPlayerScene3D).NoteDisplaySeconds = settings.NoteDisplaySeconds;
}

Expand Down
2 changes: 2 additions & 0 deletions ChartPlayerShared/SongPlayerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class SongPlayerSettings
{
public string SongPath { get; set; } = null;
public bool InvertStrings { get; set; } = false;
public bool LeftyMode { get; set; } = false;
public bool RetuneToEStandard { get; set; } = true;
public float NoteDisplaySeconds { get; set; } = 3;
public ESongInstrumentType CurrentInstrument { get; set; } = ESongInstrumentType.LeadGuitar;
Expand Down Expand Up @@ -70,6 +71,7 @@ void UpdateDisplay()
});

vStack.Children.Add(CreateTextToggleOption("InvertStrings", newSettings, "String Orientation:", "Low On Top", "Low On Bottom"));
vStack.Children.Add(CreateTextToggleOption("LeftyMode", newSettings, "Guitar Orientation:", "Left Handed", "Right Handed"));
vStack.Children.Add(CreateTextToggleOption("RetuneToEStandard", newSettings, "Re-tune to E Standard:", "Yes", "No"));
vStack.Children.Add(CreateFloatOption("NoteDisplaySeconds", newSettings, "Note Display Length (secs):", 1, 5, 1));
}
Expand Down

0 comments on commit a2363ac

Please sign in to comment.