Skip to content

Commit

Permalink
Merge pull request #282 from UltraStar-Deluxe/anst/improvements
Browse files Browse the repository at this point in the history
Anst/improvements
  • Loading branch information
basisbit committed Mar 28, 2022
2 parents 1451f0a + 2b86c6d commit acf5e81
Show file tree
Hide file tree
Showing 15 changed files with 226 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,12 @@ public static SongMeta ParseFile(string path, Encoding enc = null)
{
if (otherFields.ContainsKey(tag))
{
throw new SongMetaBuilderException("Cannot set '" + tag + "' twice in file " + path);
Debug.LogWarning($"Cannot set '{tag}' twice in file {path}");
}
else
{
otherFields[tag] = val;
}
otherFields.Add(tag, val);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
using System;
using System.IO;
using UniRx;

public class PathInputDialogControl : TextInputDialogControl
{
public override void OnInjectionFinished()
{
if (backslashReplacingTextFieldControl == null)
{
backslashReplacingTextFieldControl = new PathTextFieldControl(textField);
backslashReplacingTextFieldControl.ValueChangedEventStream
.Subscribe(newValue => ValidateValue(newValue, true));
}

base.OnInjectionFinished();

ValidateValueCallback = newValue =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class TextInputDialogControl : AbstractDialogControl, IInjectionFinishedL
[Inject(UxmlName = R.UxmlNames.cancelButton)]
protected Button cancelButton;

private BackslashReplacingTextFieldControl backslashReplacingTextFieldControl;
protected BackslashReplacingTextFieldControl backslashReplacingTextFieldControl;

private readonly Subject<string> submitValueEventStream = new Subject<string>();
public IObservable<string> SubmitValueEventStream => submitValueEventStream;
Expand Down Expand Up @@ -123,7 +123,7 @@ private void TrySubmitValue(string textValue)
}
}

private void ValidateValue(string textValue, bool showMessageIfInvalid)
protected void ValidateValue(string textValue, bool showMessageIfInvalid)
{
if (ValidateValueCallback == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@
*/
public class BackslashReplacingTextFieldControl
{
private const string BackslashReplacement = "";
private const string DefaultBackslashReplacement = "";

private TextField textField;

private readonly Subject<string> valueChangedEventStream = new Subject<string>();
public IObservable<string> ValueChangedEventStream => valueChangedEventStream;

public BackslashReplacingTextFieldControl(TextField textField)
private readonly string backslashReplacement;

public BackslashReplacingTextFieldControl(TextField textField, string backslashReplacement = DefaultBackslashReplacement)
{
this.backslashReplacement = backslashReplacement;
textField.RegisterValueChangedCallback(evt =>
{
string newValueEscaped = EscapeBackslashes(evt.newValue);
Expand All @@ -34,16 +37,16 @@ public BackslashReplacingTextFieldControl(TextField textField)
valueChangedEventStream.OnNext(newValueUnescaped);
});

textField.value = textField.value.Replace("\\", BackslashReplacement);
textField.value = textField.value.Replace("\\", backslashReplacement);
}

public static string EscapeBackslashes(string text)
public string EscapeBackslashes(string text)
{
return text.Replace("\\", BackslashReplacement);
return text.Replace("\\", backslashReplacement);
}

public static string UnescapeBackslashes(string text)
public string UnescapeBackslashes(string text)
{
return text.Replace(BackslashReplacement, "\\");
return text.Replace(backslashReplacement, "\\");
}
}
14 changes: 14 additions & 0 deletions UltraStar Play/Assets/Common/UIToolkit/Drag/AbstractDragControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public abstract class AbstractDragControl<EVENT> : INeedInjection, IInjectionFin

private readonly List<IDisposable> disposables = new List<IDisposable>();

public IReadOnlyCollection<int> ButtonFilter { get; set; } = new List<int> { 0, 1, 2 };

public virtual void OnInjectionFinished()
{
this.panelHelper = new PanelHelper(uiDocument);
Expand Down Expand Up @@ -70,6 +72,12 @@ public void RemoveListener(IDragListener<EVENT> listener)

protected virtual void OnPointerDown(IPointerEvent evt)
{
if (!ButtonFilter.IsNullOrEmpty()
&& !ButtonFilter.Contains(evt.button))
{
return;
}

dragControlPointerDownEvent = new DragControlPointerEvent(evt);
DragState.Value = EDragState.WaitingForDistanceThreshold;
}
Expand All @@ -92,6 +100,12 @@ protected virtual void OnPointerMove(IPointerEvent evt)

protected virtual void OnPointerUp(IPointerEvent evt)
{
if (!ButtonFilter.IsNullOrEmpty()
&& !ButtonFilter.Contains(evt.button))
{
return;
}

if (DragState.Value == EDragState.Dragging)
{
OnEndDrag(new DragControlPointerEvent(evt));
Expand Down
21 changes: 21 additions & 0 deletions UltraStar Play/Assets/Common/UIToolkit/PathTextFieldControl.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UIElements;
using UniInject;
using UniRx;

// Disable warning about fields that are never assigned, their values are injected.
#pragma warning disable CS0649

public class PathTextFieldControl : BackslashReplacingTextFieldControl
{
private const string BackslashReplacement = "/";

public PathTextFieldControl(TextField textField)
: base(textField, BackslashReplacement)
{
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ options_sampleRate_auto=Auto

# Content Download
contentDownloadScene_title=Content Download
contentDownloadScene_archiveUrlLabel=Archive URL (tar file)
contentDownloadScene_archiveUrlLabel=Archive URL
contentDownloadScene_startDownloadButton=Start Download
contentDownloadScene_cancelDownloadButton=Cancel Download
contentDownloadScene_status_finished=Finished
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ options_sampleRate_auto=Auto

# Content Download
contentDownloadScene_title=Downloads
contentDownloadScene_archiveUrlLabel=Archiv-URL (.tar-Datei)
contentDownloadScene_archiveUrlLabel=Archiv-URL
contentDownloadScene_startDownloadButton=Download Starten
contentDownloadScene_cancelDownloadButton=Download Abbrechen
contentDownloadScene_status_finished=Fertig
Expand Down
Loading

0 comments on commit acf5e81

Please sign in to comment.