Skip to content

Commit

Permalink
Enhanced quick edit sequence menu
Browse files Browse the repository at this point in the history
  • Loading branch information
pnwparksfan committed Apr 7, 2020
1 parent b312fad commit f8faa00
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 6 deletions.
8 changes: 4 additions & 4 deletions LiveLights/Menu/EmergencyLightingMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ public EmergencyLightingMenu(EmergencyLighting els)
Menu.AddItem(TaillightsMenuItem, 4);
Menu.BindMenuAndCopyProperties(TaillightsMenu, TaillightsMenuItem);

LeftTaillightMultiplesItem = new UIMenuListItemSelector<byte>("Front Left Multiples", "Left Taillight multiples per flash", ELS.LeftTailLightMultiples, CommonSelectionItems.MultiplesBytes);
LeftTaillightMultiplesItem = new UIMenuListItemSelector<byte>("Left Rear Multiples", "Left Taillight multiples per flash", ELS.LeftTailLightMultiples, CommonSelectionItems.MultiplesBytes);
TaillightsMenu.AddMenuDataBinding(LeftTaillightMultiplesItem, (x) => ELS.LeftTailLightMultiples = x, () => ELS.LeftTailLightMultiples);

LeftTaillightSequenceItem = new UIMenuSequenceItemSelector("Front Left Sequence", ELS.LeftTailLightSequence, "Left Taillight flash pattern sequence");
LeftTaillightSequenceItem = new UIMenuSequenceItemSelector("Left Rear Sequence", ELS.LeftTailLightSequence, "Left Taillight flash pattern sequence");
TaillightsMenu.AddMenuDataBinding(LeftTaillightSequenceItem, (x) => ELS.LeftTailLightSequence = x, () => ELS.LeftTailLightSequence);

RightTaillightMultiplesItem = new UIMenuListItemSelector<byte>("Front Right Multiples", "Right Taillight multiples per flash", ELS.RightTailLightMultiples, CommonSelectionItems.MultiplesBytes);
RightTaillightMultiplesItem = new UIMenuListItemSelector<byte>("Right Rear Multiples", "Right Taillight multiples per flash", ELS.RightTailLightMultiples, CommonSelectionItems.MultiplesBytes);
TaillightsMenu.AddMenuDataBinding(RightTaillightMultiplesItem, (x) => ELS.RightTailLightMultiples = x, () => ELS.RightTailLightMultiples);

RightTaillightSequenceItem = new UIMenuSequenceItemSelector("Front Right Sequence", ELS.RightTailLightSequence, "Right Taillight flash pattern sequence");
RightTaillightSequenceItem = new UIMenuSequenceItemSelector("Right Rear Sequence", ELS.RightTailLightSequence, "Right Taillight flash pattern sequence");
TaillightsMenu.AddMenuDataBinding(RightTaillightSequenceItem, (x) => ELS.RightTailLightSequence = x, () => ELS.RightTailLightSequence);

// Sirens
Expand Down
1 change: 1 addition & 0 deletions LiveLights/Menu/MenuController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ internal static void Process()
}

VehicleMenu.SirenConfigMenu?.ShowSirenPositions(VehicleMenu.Vehicle, true);
VehicleMenu.SirenConfigMenu?.SequenceQuickEdit?.Process();


Pool.ProcessMenus();
Expand Down
104 changes: 104 additions & 0 deletions LiveLights/Menu/SequenceQuickEditMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Drawing;

namespace LiveLights.Menu
{
Expand Down Expand Up @@ -35,6 +37,19 @@ public SequenceQuickEditMenu(EmergencyLighting els, EmergencyLightingMenu parent
Menu.AddItem(Parent.LeftTaillightSequenceItem);
Menu.AddItem(Parent.RightTaillightSequenceItem);

buttons.Add(new InstructionalButton("V", "Paste sequence"));
buttons.Add(new InstructionalButton("C", "Copy sequence"));
buttons.Add(new InstructionalButton("dn", "Move siren down"));
buttons.Add(new InstructionalButton("up", "Move siren up"));
buttons.Add(new InstructionalButton(GameControl.FrontendRight, "Shift sequence"));
buttons.Add(new InstructionalButton(GameControl.FrontendLeft, "Shift sequence"));
buttons.Add(new InstructionalButton(GameControl.Duck, "Shift x4"));

foreach (InstructionalButton button in buttons)
{
Menu.AddInstructionalButton(button);
}

Menu.OnMenuClose += OnMenuClose;
}

Expand All @@ -45,12 +60,101 @@ private void OnMenuClose(UIMenu sender)
Parent.Menu.RefreshData();
}

internal void Process()
{
if(Menu.Visible)
{

if(Game.IsKeyDown(Keys.C))
{
copiedSequence = getSelectedSequence()?.ItemValue;
Common.PlaySound(Menu.AUDIO_SELECT, Menu.AUDIO_LIBRARY);
} else if(Game.IsKeyDown(Keys.V) && copiedSequence != null)
{
var s = getSelectedSequence();
if (s != null)
{
s.ItemValue = copiedSequence;
Common.PlaySound(Menu.AUDIO_SELECT, Menu.AUDIO_LIBRARY);
}
} else if(Game.IsControlJustPressed(13, GameControl.FrontendLeft))
{
shiftSelectedSequence(-1);
} else if(Game.IsControlJustPressed(13, GameControl.FrontendRight))
{
shiftSelectedSequence(1);
} else if(Game.IsKeyDown(Keys.PageDown))
{
shiftSelectedItem(1);
} else if(Game.IsKeyDown(Keys.PageUp))
{
shiftSelectedItem(-1);
}

if(!string.IsNullOrEmpty(copiedSequence))
{
string seqDisp = "Copied sequence " + UIMenuSequenceItemSelector.FormatSequence(copiedSequence);
Point p = new Point(Menu.WidthOffset + 500, 30);
ResText.Draw(seqDisp, p, 0.4f, Color.White, Common.EFont.Monospace, false);
int rectW = (int)ResText.MeasureStringWidth(seqDisp, Common.EFont.Monospace, 0.4f);
ResRectangle.Draw(new Point(p.X - 10, p.Y - 1), new Size(rectW + 20, 31), Color.FromArgb(180, Color.Black));
}
}
}

private string copiedSequence = "";

private void shiftSelectedItem(int shift)
{
var item = getSelectedSequence()?.MenuItem;
if(item != null)
{
int currentIndex = Menu.MenuItems.IndexOf(item);
int newIndex = (currentIndex + shift);
// if(newIndex > currentIndex) newIndex--;

Menu.MenuItems.RemoveAt(currentIndex);
Menu.MenuItems.Insert(newIndex, item);
Menu.RefreshIndex();
Menu.CurrentSelection = newIndex;
Common.PlaySound(Menu.AUDIO_LEFTRIGHT, Menu.AUDIO_LIBRARY);
}
}

private void shiftSelectedSequence(int shift)
{
shift *= -1;
if(NativeFunction.Natives.IS_DISABLED_CONTROL_PRESSED<bool>(0, (int)GameControl.Duck))
{
shift *= 4;
}
var s = getSelectedSequence();
if(s != null)
{
string seq = s.ItemValue;
if (shift < 0)
{
shift = seq.Length + shift;
}
s.ItemValue = seq.Substring(shift) + seq.Substring(0, shift);
Common.PlaySound(Menu.AUDIO_LEFTRIGHT, Menu.AUDIO_LIBRARY);
}
}

private UIMenuSequenceItemSelector getSelectedSequence()
{
UIMenuItem selectedItem = Menu.MenuItems[Menu.CurrentSelection];
return SirenSequenceItems.FirstOrDefault(x => x.MenuItem == selectedItem);
}

public EmergencyLightingMenu Parent { get; }
public EmergencyLighting ELS { get; }
public UIMenuRefreshable Menu { get; }

private List<UIMenuSequenceItemSelector> sirenSequenceItems = new List<UIMenuSequenceItemSelector>();

public UIMenuSequenceItemSelector[] SirenSequenceItems => sirenSequenceItems.ToArray();

private List<InstructionalButton> buttons = new List<InstructionalButton>();
}
}
4 changes: 3 additions & 1 deletion LiveLights/Menu/UIMenuSequenceItemSelector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ public UIMenuSequenceItemSelector(string text, string value, string description)
{
}


public static string FormatSequence(string sequence) => sequence.Replace("0", "~c~0~w~").Replace("1", "~r~1~w~");
protected override int MaxInputLength => 32;
protected override string DisplayMenu => base.DisplayMenu.Replace("0", "~c~0~w~").Replace("1", "~r~1~w~");
protected override string DisplayMenu => FormatSequence(base.DisplayMenu);
}
}
2 changes: 1 addition & 1 deletion LiveLights/Utils/MenuItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ public bool RightLabelMonospace
if(value)
{
base._labelText.FontEnum = Common.EFont.Monospace;
base._labelText.Scale = 0.45f;
} else
{
base._labelText.FontEnum = origLabelResText.FontEnum;
Expand All @@ -314,7 +315,6 @@ public bool MainTextMonospace
if (value)
{
base._text.FontEnum = Common.EFont.Monospace;
base._text.Scale = 0.45f;
}
else
{
Expand Down

0 comments on commit f8faa00

Please sign in to comment.