Merge branch 'SongLoader' into develop

This commit is contained in:
Flamefire committed 2013-10-14 22:02:18 +02:00
commit 91afb830b5
37 files changed
+1550 -903

No files matched your search

+55 -108
View File
@@ -23,15 +23,6 @@ using VocaluxeLib.Songs;
namespace VocaluxeLib.Menu
{
struct SNote
{
public string Text;
public int StartBeat;
public int EndBeat;
public int Duration;
public ENoteType Type;
}
struct SThemeLyrics
{
public string Name;
@@ -46,7 +37,10 @@ namespace VocaluxeLib.Menu
private SThemeLyrics _Theme;
private bool _ThemeLoaded;
private readonly List<SNote> _Notes;
/// <summary>
/// Holds a reference to Songline. DO NOT MODIFY
/// </summary>
private CSongLine _Line;
private CText _Text;
private float _X;
@@ -109,7 +103,7 @@ namespace VocaluxeLib.Menu
_MaxW = 1f;
_H = 1f;
_Width = 1f;
_Notes = new List<SNote>();
_Line = new CSongLine();
_Text = new CText(_PartyModeID);
LyricStyle = ELyricStyle.Fill;
@@ -201,28 +195,27 @@ namespace VocaluxeLib.Menu
public void SetLine(CSongLine line)
{
_Notes.Clear();
_Line = line;
_Width = 0f;
foreach (CSongNote note in line.Notes)
{
var n = new SNote {Text = note.Text, StartBeat = note.StartBeat, EndBeat = note.EndBeat, Duration = note.Duration, Type = note.NoteType};
_Text.Text = note.Text;
_Text.Style = EStyle.Bold;
if (n.Type == ENoteType.Freestyle)
_Text.Style = EStyle.BoldItalic;
RectangleF rect = CBase.Fonts.GetTextBounds(_Text);
_Width += rect.Width;
_Notes.Add(n);
_SetText(note);
_Width += _Text.Rect.W;
}
}
private void _SetText(CSongNote note)
{
_Text.Text = note.Text;
_Text.Style = EStyle.Bold;
if (note.Type == ENoteType.Freestyle)
_Text.Style = EStyle.BoldItalic;
}
public void Clear()
{
_Notes.Clear();
_Line = new CSongLine();
}
public float GetCurrentLyricPosX()
@@ -260,15 +253,10 @@ namespace VocaluxeLib.Menu
{
float x = _X - _Width / 2;
foreach (SNote note in _Notes)
foreach (CSongNote note in _Line.Notes)
{
_Text.X = x;
_Text.Style = EStyle.Bold;
_Text.Text = note.Text;
RectangleF rect = CBase.Fonts.GetTextBounds(_Text);
if (note.Type == ENoteType.Freestyle)
_Text.Style = EStyle.BoldItalic;
_SetText(note);
if (currentBeat >= note.StartBeat)
{
@@ -276,9 +264,8 @@ namespace VocaluxeLib.Menu
{
_Text.Color = _ColorProcessed;
float diff = note.EndBeat - note.StartBeat;
if (Math.Abs(diff) < float.Epsilon)
int diff = note.EndBeat - note.StartBeat;
if (diff <= 0)
_Text.Draw(0f, 1f);
else
{
@@ -299,7 +286,7 @@ namespace VocaluxeLib.Menu
_Text.Draw();
}
x += rect.Width;
x += _Text.Rect.W;
}
}
@@ -308,37 +295,27 @@ namespace VocaluxeLib.Menu
float x = _X - _Width / 2; // most left position
//find last active note
int lastNote = -1;
for (int i = 0; i < _Notes.Count; i++)
{
if (currentBeat >= _Notes[i].StartBeat)
lastNote = i;
}
int lastNote = _Line.FindPreviousNote((int)currentBeat);
int zoomNote = -1;
int endBeat = -1;
float zoomx = 0f;
for (int note = 0; note < _Notes.Count; note++)
for (int note = 0; note < _Line.Notes.Length; note++)
{
_Text.X = x;
_Text.Style = EStyle.Bold;
_Text.Text = _Notes[note].Text;
RectangleF rect = CBase.Fonts.GetTextBounds(_Text);
_SetText(_Line.Notes[note]);
if (_Notes[note].Type == ENoteType.Freestyle)
_Text.Style = EStyle.BoldItalic;
if (currentBeat >= _Notes[note].StartBeat)
if (currentBeat >= _Line.Notes[note].StartBeat)
{
int endbeat = _Notes[note].EndBeat;
if (note < _Notes.Count - 1)
endbeat = _Notes[note + 1].StartBeat - 1;
int curEndBeat = _Line.Notes[note].EndBeat;
if (note < _Line.Notes.Length - 1)
curEndBeat = _Line.Notes[note + 1].StartBeat - 1;
if (currentBeat <= endbeat)
if (currentBeat <= curEndBeat)
{
zoomNote = note;
endBeat = endbeat;
endBeat = curEndBeat;
zoomx = _Text.X;
}
else
@@ -356,49 +333,37 @@ namespace VocaluxeLib.Menu
_Text.Draw();
}
x += rect.Width;
x += _Text.Rect.W;
}
if (zoomNote > -1)
{
if (_Notes[zoomNote].Duration == 0)
return;
_Text.X = zoomx;
_Text.Text = _Notes[zoomNote].Text;
_Text.Color = _ColorProcessed;
_Text.Style = EStyle.Bold;
_SetText(_Line.Notes[zoomNote]);
if (_Notes[zoomNote].Type == ENoteType.Freestyle)
_Text.Style = EStyle.BoldItalic;
RectangleF rect = CBase.Fonts.GetTextBounds(_Text);
float diff = endBeat - _Notes[zoomNote].StartBeat;
float diff = endBeat - _Line.Notes[zoomNote].StartBeat;
if (diff <= 0f)
diff = 1f;
float p = (currentBeat - _Notes[zoomNote].StartBeat) / diff;
float p = (currentBeat - _Line.Notes[zoomNote].StartBeat) / diff;
if (p > 1f)
p = 1f;
p = 1f - p;
float ty = _Text.Y;
float tx = _Text.X;
float th = _Text.Height;
float tz = _Text.Z;
SRectF normalRect = _Text.Rect;
_Text.Height += _Text.Height * p * 0.4f;
RectangleF rectz = CBase.Fonts.GetTextBounds(_Text);
_Text.X -= (rectz.Width - rect.Width) / 2f;
_Text.Y -= (rectz.Height - rect.Height) / 2f;
_Text.X -= (_Text.Rect.W - normalRect.W) / 2f;
_Text.Y -= (_Text.Rect.W - normalRect.H) / 2f;
_Text.Z -= 0.1f;
_Text.Draw();
_Text.Y = ty;
_Text.X = tx;
_Text.Height = th;
_Text.Z = tz;
}
@@ -408,15 +373,10 @@ namespace VocaluxeLib.Menu
{
float x = _X - _Width / 2; // most left position
foreach (SNote note in _Notes)
foreach (CSongNote note in _Line.Notes)
{
_Text.X = x;
_Text.Style = EStyle.Bold;
_Text.Text = note.Text;
RectangleF rect = CBase.Fonts.GetTextBounds(_Text);
if (note.Type == ENoteType.Freestyle)
_Text.Style = EStyle.BoldItalic;
_SetText(note);
if (currentBeat >= note.StartBeat)
{
@@ -430,7 +390,7 @@ namespace VocaluxeLib.Menu
_Text.Draw();
}
x += rect.Width;
x += _Text.Rect.W;
}
}
@@ -439,29 +399,23 @@ namespace VocaluxeLib.Menu
float x = _X - _Width / 2; // most left position
//find last active note
int lastNote = -1;
for (int i = 0; i < _Notes.Count; i++)
{
if (currentBeat >= _Notes[i].StartBeat)
lastNote = i;
}
int lastNote = _Line.FindPreviousNote((int)currentBeat);
int jumpNote = -1;
float jumpx = 0f;
for (int note = 0; note < _Notes.Count; note++)
for (int note = 0; note < _Line.Notes.Length; note++)
{
_Text.X = x;
_Text.Style = EStyle.Bold;
_Text.Text = _Notes[note].Text;
RectangleF rect = CBase.Fonts.GetTextBounds(_Text);
_SetText(_Line.Notes[note]);
if (_Notes[note].Type == ENoteType.Freestyle)
_Text.Style = EStyle.BoldItalic;
if (currentBeat >= _Notes[note].StartBeat)
if (currentBeat >= _Line.Notes[note].StartBeat)
{
if (currentBeat <= _Notes[note].EndBeat)
int curEndBeat = _Line.Notes[note].EndBeat;
if (note < _Line.Notes.Length - 1)
curEndBeat = _Line.Notes[note + 1].StartBeat - 1;
if (currentBeat <= curEndBeat)
{
jumpNote = note;
jumpx = _Text.X;
@@ -481,27 +435,20 @@ namespace VocaluxeLib.Menu
_Text.Draw();
}
x += rect.Width;
x += _Text.Rect.W;
}
if (jumpNote < 0)
return;
if (_Notes[jumpNote].Duration == 0)
return;
_Text.X = jumpx;
_Text.Text = _Notes[jumpNote].Text;
_Text.Color = _ColorProcessed;
_Text.Style = EStyle.Bold;
_SetText(_Line.Notes[jumpNote]);
if (_Notes[jumpNote].Type == ENoteType.Freestyle)
_Text.Style = EStyle.BoldItalic;
int diff = _Notes[jumpNote].EndBeat - _Notes[jumpNote].StartBeat;
int diff = _Line.Notes[jumpNote].EndBeat - _Line.Notes[jumpNote].StartBeat;
if (diff <= 0)
diff = 1;
float p = 1f - (currentBeat - _Notes[jumpNote].StartBeat) / diff;
float p = 1f - (currentBeat - _Line.Notes[jumpNote].StartBeat) / diff;
if (Math.Abs(p) < float.Epsilon)
_Text.Draw();
+3 -3
View File
@@ -84,7 +84,7 @@ namespace VocaluxeLib.Menu
{
private class CPlaylistElementContent
{
public EGameMode[] Modes;
public IList<EGameMode> Modes;
public int SongID;
public EGameMode Mode;
}
@@ -971,11 +971,11 @@ namespace VocaluxeLib.Menu
if (!mouseEvent.LBH && DragAndDropSongID != -1)
{
var gm = EGameMode.TR_GAMEMODE_NORMAL;
CSong song = CBase.Songs.GetSongByID(DragAndDropSongID);
if (song != null)
{
var gm = EGameMode.TR_GAMEMODE_NORMAL;
if (song.IsDuet)
gm = EGameMode.TR_GAMEMODE_DUET;
@@ -1220,7 +1220,7 @@ namespace VocaluxeLib.Menu
string t1 = CBase.Language.Translate(_Theme.Text1.Text).Replace("%a", song.Artist).Replace("%t", song.Title);
_PlaylistElements[i].Text1.Text = /*(Offset + i + 1) + ") " + */ t1; //TODO: Add text field for the number
_PlaylistElements[i].SelectSlide.Clear();
for (int g = 0; g < pec.Modes.Length; g++)
for (int g = 0; g < pec.Modes.Count; g++)
{
_PlaylistElements[i].SelectSlide.AddValue(Enum.GetName(typeof(EGameMode), pec.Modes[g]));
if (pec.Modes[g] == pec.Mode)
+1 -1
View File
@@ -561,7 +561,7 @@ namespace VocaluxeLib.Menu
float y = Y;
RectangleF bounds = CBase.Fonts.GetTextBounds(this);
if (bounds.Width > MaxWidth && MaxWidth > 0f && bounds.Width > 0f)
if (MaxWidth > 0f && bounds.Width > MaxWidth && bounds.Width > 0f)
{
float factor = MaxWidth / bounds.Width;
float step = h * (1 - factor);
+3 -3
View File
@@ -319,7 +319,7 @@ namespace VocaluxeLib.Menu.SingNotes
int nr = 1;
foreach (CSongNote note in line.Notes)
{
if (note.NoteType != ENoteType.Freestyle)
if (note.Type != ENoteType.Freestyle)
{
float width = note.Duration / beats * w;
@@ -334,7 +334,7 @@ namespace VocaluxeLib.Menu.SingNotes
_DrawNoteBG(rect, color, 1f, _PlayerNotes[n].Timer);
_DrawNote(rect, new SColorF(5f, 5f, 5f, 0.7f * _PlayerNotes[n].Alpha), 0.7f);
if (note.NoteType == ENoteType.Golden)
if (note.Type == ENoteType.Golden)
{
_AddGoldenNote(rect, n, nr);
nr++;
@@ -386,7 +386,7 @@ namespace VocaluxeLib.Menu.SingNotes
_DrawNote(rect, color, f);
if (note.EndBeat >= CBase.Game.GetRecordedBeat() && note.Hit && note.HitNote.NoteType == ENoteType.Golden)
if (note.EndBeat >= CBase.Game.GetRecordedBeat() && note.Hit && note.HitNote.Type == ENoteType.Golden)
{
var re = new SRectF(rect) {W = (CBase.Game.GetMidRecordedBeat() - note.StartBeat) / beats * w};
_AddFlare(re, n);
+16 -14
View File
@@ -22,6 +22,7 @@ using System.IO;
using System.Xml;
using VocaluxeLib.Draw;
using VocaluxeLib.PartyModes;
using VocaluxeLib.Songs;
namespace VocaluxeLib.Menu.SongMenu
{
@@ -101,7 +102,7 @@ namespace VocaluxeLib.Menu.SongMenu
private readonly Stopwatch _Timer = new Stopwatch();
private readonly Stopwatch _VideoFadeTimer = new Stopwatch();
private readonly List<int> _Streams = new List<int>();
private int _Actsong = -1;
private int _ActSongId = -1;
private int _Actsongstream = -1;
protected CTexture _Vidtex;
@@ -186,7 +187,7 @@ namespace VocaluxeLib.Menu.SongMenu
protected int _ActSong
{
get { return _Actsong; }
get { return _ActSongId; }
}
public SRectF Rect
@@ -206,7 +207,7 @@ namespace VocaluxeLib.Menu.SongMenu
public virtual int GetActualSelection()
{
return _Actsong;
return _ActSongId;
}
private bool _Selected;
@@ -434,7 +435,7 @@ namespace VocaluxeLib.Menu.SongMenu
if (!_Initialized)
return;
if (_Actsong != _PreviewSelected)
if (_ActSongId != _PreviewSelected)
_SelectSong(_PreviewSelected);
if (_Streams.Count <= 0 || _Video == -1)
@@ -607,7 +608,7 @@ namespace VocaluxeLib.Menu.SongMenu
protected void _SelectSong(int nr)
{
if (CBase.Songs.IsInCategory() && (CBase.Songs.GetNumSongsVisible() > 0) && (nr >= 0) && ((_Actsong != nr) || (_Streams.Count == 0)))
if (CBase.Songs.IsInCategory() && (CBase.Songs.GetNumSongsVisible() > 0) && (nr >= 0) && ((_ActSongId != nr) || (_Streams.Count == 0)))
{
_Streams.ForEach(soundStream => CBase.Sound.FadeAndStop(soundStream, 0f, 1f));
_Streams.Clear();
@@ -617,18 +618,19 @@ namespace VocaluxeLib.Menu.SongMenu
CBase.Drawing.RemoveTexture(ref _Vidtex);
_Actsong = nr;
if (_Actsong >= CBase.Songs.GetNumSongsVisible())
_Actsong = 0;
_ActSongId = nr;
if (_ActSongId >= CBase.Songs.GetNumSongsVisible())
_ActSongId = 0;
int stream = CBase.Sound.Load(Path.Combine(CBase.Songs.GetVisibleSong(_Actsong).Folder, CBase.Songs.GetVisibleSong(_Actsong).MP3FileName), true);
CSong actSong = CBase.Songs.GetVisibleSong(_ActSongId);
int stream = CBase.Sound.Load(Path.Combine(actSong.Folder, actSong.MP3FileName), true);
CBase.Sound.SetStreamVolumeMax(stream, _MaxVolume);
CBase.Sound.SetStreamVolume(stream, 0f);
float startposition = CBase.Songs.GetVisibleSong(_Actsong).PreviewStart;
float startposition = actSong.Preview.StartTime;
if (Math.Abs(startposition) < 0.001)
if (actSong.Preview.Source == EDataSource.None)
startposition = CBase.Sound.GetLength(stream) / 4f;
if (startposition >= 0.5f)
@@ -640,12 +642,12 @@ namespace VocaluxeLib.Menu.SongMenu
_Streams.Add(stream);
_Actsongstream = stream;
if (CBase.Songs.GetVisibleSong(_Actsong).VideoFileName != "" && CBase.Config.GetVideoPreview() == EOffOn.TR_CONFIG_ON)
if (actSong.VideoFileName != "" && CBase.Config.GetVideoPreview() == EOffOn.TR_CONFIG_ON)
{
_Video = CBase.Video.Load(Path.Combine(CBase.Songs.GetVisibleSong(_Actsong).Folder, CBase.Songs.GetVisibleSong(_Actsong).VideoFileName));
_Video = CBase.Video.Load(Path.Combine(actSong.Folder, actSong.VideoFileName));
if (_Video == -1)
return;
CBase.Video.Skip(_Video, startposition, CBase.Songs.GetVisibleSong(_Actsong).VideoGap);
CBase.Video.Skip(_Video, startposition, actSong.VideoGap);
_VideoFadeTimer.Stop();
_VideoFadeTimer.Reset();
_VideoFadeTimer.Start();
@@ -413,8 +413,8 @@ namespace VocaluxeLib.Menu.SongMenu
_Title.Text = song.Title;
_DuetIcon.Visible = song.IsDuet;
_VideoIcon.Visible = song.VideoFileName != "";
_MedleyCalcIcon.Visible = song.Medley.Source == EMedleySource.Calculated;
_MedleyTagIcon.Visible = song.Medley.Source == EMedleySource.Tag;
_MedleyCalcIcon.Visible = song.Medley.Source == EDataSource.Calculated;
_MedleyTagIcon.Visible = song.Medley.Source == EDataSource.Tag;
float time = CBase.Sound.GetLength(_SongStream);
if (Math.Abs(song.Finish) > 0.001)