Skip to content

Commit

Permalink
Merge pull request #244 from UltraStar-Deluxe/anst/fixes
Browse files Browse the repository at this point in the history
Anst/fixes
  • Loading branch information
achimmihca committed May 3, 2021
2 parents f0a7e07 + c80fd92 commit 8291345
Show file tree
Hide file tree
Showing 28 changed files with 278 additions and 83 deletions.
17 changes: 17 additions & 0 deletions UltraStar Play/Assets/Common/I18N/I18NManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,21 @@ private static string GetPropertiesFilePath(string propertiesFileNameWithCountry
path = ApplicationUtils.GetStreamingAssetsPath(path);
return path;
}

public List<SystemLanguage> GetTranslatedLanguages()
{
HashSet<SystemLanguage> translatedLanguages = new HashSet<SystemLanguage> { SystemLanguage.English };
foreach (SystemLanguage systemLanguage in EnumUtils.GetValuesAsList<SystemLanguage>())
{
string suffix = GetCountryCodeSuffixForPropertiesFile(systemLanguage);
string propertiesFilePath = GetPropertiesFilePath(PropertiesFileName + suffix);
if (File.Exists(propertiesFilePath))
{
translatedLanguages.Add(systemLanguage);
}
}
return translatedLanguages
.OrderBy(it => it.ToString())
.ToList();
}
}
6 changes: 4 additions & 2 deletions UltraStar Play/Assets/Common/I18N/LanguageHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public static string Get2LetterIsoCodeFromSystemLanguage(SystemLanguage lang)
case SystemLanguage.Belarusian: return "BY";
case SystemLanguage.Bulgarian: return "BG";
case SystemLanguage.Catalan: return "CA";
case SystemLanguage.Chinese: return "ZH";
case SystemLanguage.Chinese:
case SystemLanguage.ChineseSimplified:
case SystemLanguage.ChineseTraditional: return "ZH";
case SystemLanguage.Czech: return "CS";
case SystemLanguage.Danish: return "DA";
case SystemLanguage.Dutch: return "NL";
Expand Down Expand Up @@ -63,4 +65,4 @@ public static string Get2LetterIsoCodeFromSystemLanguage(SystemLanguage lang)
return "EN";
}
}
}
}
5 changes: 3 additions & 2 deletions UltraStar Play/Assets/Common/Model/Song/SongMetaUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ public static Sentence FindExistingSentenceForNote(IReadOnlyCollection<Sentence>
public static Voice GetOrCreateVoice(SongMeta songMeta, string voiceName)
{
Voice matchingVoice = songMeta.GetVoices()
.Where(it => it.Name == voiceName || (voiceName.IsNullOrEmpty() && it.Name == Voice.soloVoiceName))
.FirstOrDefault();
.FirstOrDefault(voice => voice.Name == voiceName
|| (voiceName.IsNullOrEmpty() && voice.Name == Voice.firstVoiceName)
|| (voiceName == Voice.firstVoiceName && voice.Name.IsNullOrEmpty()));
if (matchingVoice != null)
{
return matchingVoice;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public void SetAction(Action action)
{
actionSubscriptionDisposable = button.OnClickAsObservable().Subscribe(_ =>
{
Debug.Log("ContextMenuItem triggered");
action();
ContextMenu.CloseContextMenu();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,28 @@ public class AvatarImage : MonoBehaviour, INeedInjection, IExcludeFromSceneInjec
[Inject(optional = true)]
private MicProfile micProfile;

public void SetPlayerProfile(PlayerProfile playerProfile)
{
AvatarImageReference imageRef = FindObjectsOfType<AvatarImageReference>().Where(it => it.avatar == playerProfile.Avatar).FirstOrDefault();
if (imageRef != null)
{
image.sprite = imageRef.Sprite;
}
else
{
Debug.LogWarning("Did not find an image for the avatar: " + playerProfile.Avatar);
}
}

[Inject(optional = true)]
private PlayerProfile playerProfile;

public void OnInjectionFinished()
{
if (micProfile != null)
{
image.color = micProfile.Color;
}

if (playerProfile != null)
{
AvatarImageReference imageRef = FindObjectsOfType<AvatarImageReference>()
.FirstOrDefault(it => it.avatar == playerProfile.Avatar);
if (imageRef != null)
{
image.sprite = imageRef.Sprite;
}
else
{
Debug.LogWarning("Did not find an image for the avatar: " + playerProfile.Avatar);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@

public class LanguageItemSlider : TextItemSlider<SystemLanguage>, INeedInjection
{
[Inject]
private I18NManager i18nManager;

protected override void Start()
{
base.Start();
Items = EnumUtils.GetValuesAsList<SystemLanguage>();
Items = i18nManager.GetTranslatedLanguages();
SystemLanguage currentLanguage = SettingsManager.Instance.Settings.GameSettings.language;
Selection.Value = currentLanguage;
Selection.Value = Items.Contains(currentLanguage) ? currentLanguage : SystemLanguage.English;
Selection.Subscribe(newValue =>
{
SettingsManager.Instance.Settings.GameSettings.language = newValue;
I18NManager.Instance.UpdateCurrentLanguageAndTranslations();
i18nManager.UpdateCurrentLanguageAndTranslations();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ void Update()
void OnDestroy()
{
DestroyStars();
DestroyLyrics();
}

public void SetColorOfMicProfile(MicProfile micProfile)
Expand Down Expand Up @@ -100,6 +101,20 @@ private void DestroyStars()
stars.Clear();
}

private void DestroyLyrics()
{
if (lyricsUiText != null
&& lyricsUiText.gameObject != null)
{
Destroy(lyricsUiText.gameObject);
}
if (lyricsUiTextRectTransform != null
&& lyricsUiTextRectTransform.gameObject != null)
{
Destroy(lyricsUiTextRectTransform.gameObject);
}
}

private void CreateGoldenNoteEffect()
{
// Create several particles. Longer notes require more particles because they have more space to fill.
Expand Down
2 changes: 1 addition & 1 deletion UltraStar Play/Assets/Scenes/Sing/SingSceneController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ private string GetVoiceName(PlayerProfile playerProfile)
return Voice.soloVoiceName;
}

List<string> voiceNames = new List<string>(SongMeta.VoiceNames.Values);
List<string> voiceNames = new List<string>(SongMeta.VoiceNames.Keys);
int voiceNameCount = voiceNames.Count;
if (voiceNameCount > 1)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ private void PositionUiNoteLyrics(UiNote uiNote)
lyricsRectTransform.anchorMax = new Vector2(lyricsRectTransform.anchorMax.x, 1);
lyricsRectTransform.sizeDelta = new Vector2(lyricsRectTransform.sizeDelta.x, 0);
lyricsRectTransform.localPosition = new Vector2(lyricsRectTransform.localPosition.x, 0);
uiNote.lyricsUiText.transform.SetParent(uiNote.RectTransform, true);
uiNote.lyricsUiText.transform.SetParent(lyricsBar, true);
}

private double GetNoteStartBeatOfFollowingNote(Note note)
Expand Down Expand Up @@ -152,7 +152,10 @@ private void UpdateUiNotePositions()
{
foreach (UiNote uiNote in noteToUiNoteMap.Values)
{
Vector3 lastPosition = uiNote.RectTransform.position;
PositionUiNote(uiNote.RectTransform, uiNote.Note.MidiNote, uiNote.Note.StartBeat, uiNote.Note.EndBeat);
Vector3 positionDelta = uiNote.RectTransform.position - lastPosition;
uiNote.lyricsUiTextRectTransform.Translate(positionDelta);
}

foreach (UiRecordedNote uiRecordedNote in uiRecordedNotes)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using UniInject;

// Disable warning about fields that are never assigned, their values are injected.
Expand All @@ -15,19 +16,32 @@ public class DeleteNotesAction : INeedInjection
[Inject]
private SongMetaChangeEventStream songMetaChangeEventStream;

[Inject]
private DeleteSentencesAction deleteSentencesAction;

public void Execute(IReadOnlyCollection<Note> selectedNotes)
{
HashSet<Sentence> affectedSentences = new HashSet<Sentence>();
foreach (Note note in selectedNotes)
{
if (note.Sentence != null)
{
affectedSentences.Add(note.Sentence);
}
note.SetSentence(null);
songEditorLayerManager.RemoveNoteFromAllLayers(note);
editorNoteDisplayer.DeleteNote(note);
}

List<Sentence> affectedSentencesWithoutNotes = affectedSentences
.Where(sentence => sentence.Notes.Count == 0)
.ToList();
deleteSentencesAction.Execute(affectedSentencesWithoutNotes);
}

public void ExecuteAndNotify(IReadOnlyCollection<Note> selectedNotes)
{
Execute(selectedNotes);
songMetaChangeEventStream.OnNext(new NotesDeletedEvent());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Collections.Generic;
using System.Linq;
using UniInject;

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

public class MoveNoteToOwnSentenceAction : INeedInjection
{
[Inject]
private SongMetaChangeEventStream songMetaChangeEventStream;

[Inject]
private DeleteSentencesAction deleteSentencesAction;

public bool CanMoveToOwnSentence(List<Note> notes)
{
if (notes.IsNullOrEmpty())
{
return false;
}
return notes.AnyMatch(note => note.Sentence?.Voice != null);
}

public void MoveToOwnSentence(List<Note> notes)
{
List<Sentence> affectedSentences = notes.Select(note => note.Sentence).ToList();

Sentence newSentence = new Sentence();
Voice voice = notes
.Select(note => note.Sentence?.Voice)
.FirstOrDefault();
newSentence.SetVoice(voice);

notes.ForEach(note => note.SetSentence(newSentence));
newSentence.FitToNotes();

// Remove old sentence if not more notes left
List<Sentence> sentencesWithoutNotes = affectedSentences.Where(it => it.Notes.IsNullOrEmpty()).ToList();
deleteSentencesAction.Execute(sentencesWithoutNotes);

// Fit sentences to notes
List<Sentence> sentencesWithNotes = affectedSentences.Where(it => !it.Notes.IsNullOrEmpty()).ToList();
sentencesWithNotes.ForEach(it => it.FitToNotes());
}

public void MoveToOwnSentenceAndNotify(List<Note> notes)
{
MoveToOwnSentence(notes);
songMetaChangeEventStream.OnNext(new SentencesChangedEvent());
}
}

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 @@ -21,6 +21,7 @@ public bool CanMoveNotesToVoice(List<Note> selectedNotes, params string[] voiceN
public void MoveNotesToVoice(SongMeta songMeta, List<Note> selectedNotes, string voiceName)
{
Voice voice = SongMetaUtils.GetOrCreateVoice(songMeta, voiceName);
Sentence createdSentence = null;
List<Sentence> changedSentences = new List<Sentence>();
foreach (Note note in selectedNotes)
{
Expand All @@ -35,9 +36,14 @@ public void MoveNotesToVoice(SongMeta songMeta, List<Note> selectedNotes, string
{
sentenceForNote = new Sentence(note.Sentence.MinBeat, note.Sentence.MaxBeat);
}
else if (createdSentence != null)
{
sentenceForNote = createdSentence;
}
else
{
sentenceForNote = new Sentence();
createdSentence = new Sentence();
sentenceForNote = createdSentence;
}
sentenceForNote.SetVoice(voice);
}
Expand Down Expand Up @@ -76,4 +82,4 @@ private static bool HasVoice(Note note, string[] voiceNames)
return note.Sentence != null && voiceNames.Contains(note.Sentence.Voice.Name);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public List<IBinding> GetBindings()
bb.BindTypeToNewInstances(typeof(AddNoteAction));
bb.BindTypeToNewInstances(typeof(MoveNoteToAjacentSentenceAction));
bb.BindTypeToNewInstances(typeof(MoveNotesToOtherVoiceAction));
bb.BindTypeToNewInstances(typeof(MoveNoteToOwnSentenceAction));
bb.BindTypeToNewInstances(typeof(MoveNotesAction));
bb.BindTypeToNewInstances(typeof(ExtendNotesAction));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public class EditorNoteContextMenuHandler : AbstractContextMenuHandler
[Inject]
private MoveNotesToOtherVoiceAction moveNotesToOtherVoiceAction;

[Inject]
private MoveNoteToOwnSentenceAction moveNoteToOwnSentenceAction;

[Inject]
private SpaceBetweenNotesAction spaceBetweenNotesAction;

Expand Down Expand Up @@ -183,6 +186,11 @@ private void FillContextMenuToMoveToOtherVoice(ContextMenu contextMenu, List<Not
contextMenu.AddItem("Move to player 2",
() => moveNotesToOtherVoiceAction.MoveNotesToVoiceAndNotify(songMeta, selectedNotes, Voice.secondVoiceName));
}

if (moveNoteToOwnSentenceAction.CanMoveToOwnSentence(selectedNotes))
{
contextMenu.AddItem("Move to own sentence", () => moveNoteToOwnSentenceAction.MoveToOwnSentenceAndNotify(selectedNotes));
}
}

private void FillContextMenuToMoveToOtherSentence(ContextMenu contextMenu, List<Note> selectedNotes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ void Start()
.Subscribe(_ => UpdateNotes());
}

settings.SongEditorSettings.ObserveEveryValueChanged(it => it.HideVoices.Count).Subscribe(_ => OnHideVoicesChanged());
settings.SongEditorSettings
.ObserveEveryValueChanged(it => it.HideVoices.Count)
.Subscribe(_ => OnHideVoicesChanged())
.AddTo(this);
}

private void OnHideVoicesChanged()
Expand Down Expand Up @@ -182,7 +185,8 @@ private void DrawSentencesInVoice(Voice voice)

public void UpdateNotes()
{
if (!gameObject.activeInHierarchy)
if (gameObject == null
|| !gameObject.activeInHierarchy)
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public void SyncWithNote()
Color color = songEditorSceneController.GetColorForVoice(Note.Sentence.Voice);
SetColor(color);
}
UpdateFontSize();
}

void Start()
Expand Down
Loading

0 comments on commit 8291345

Please sign in to comment.