Merge branch 'develop' of github.com:Vocaluxe/Vocaluxe into komadoc-develop

This commit is contained in:
Florian Küpper committed 2014-12-21 12:45:02 +01:00
commit a199d7fba3
63 files changed
+1587 -1411

No files matched your search

+75 -120
View File
@@ -188,14 +188,12 @@ namespace VocaluxeLib.Menu
case ELyricStyle.Fill:
_DrawFill();
break;
case ELyricStyle.Jump:
_DrawJump();
break;
case ELyricStyle.Slide:
_DrawSlide();
break;
case ELyricStyle.Zoom:
_DrawZoom();
case ELyricStyle.Jump:
_DrawZoomOrJump();
break;
default:
_DrawSlide();
@@ -219,14 +217,15 @@ namespace VocaluxeLib.Menu
{
_Text.Color = _ColorProcessed;
int diff = note.EndBeat - note.StartBeat;
int diff = note.Duration;
if (diff <= 0)
_Text.Draw(0f, 1f);
else
{
_Text.Draw(0f, (_CurrentBeat - note.StartBeat) / diff);
float p = (_CurrentBeat - note.StartBeat) / diff;
_Text.Draw(0f, p);
_Text.Color = _Color;
_Text.Draw((_CurrentBeat - note.StartBeat) / diff, 1f);
_Text.Draw(p, 1f);
}
}
else
@@ -245,87 +244,6 @@ namespace VocaluxeLib.Menu
}
}
private void _DrawZoom()
{
float x = X - _Width / 2; // most left position
//find last active note
int lastNote = _Line.FindPreviousNote((int)_CurrentBeat);
int zoomNote = -1;
int endBeat = -1;
float zoomx = 0f;
for (int note = 0; note < _Line.Notes.Length; note++)
{
_Text.X = x;
_SetText(_Line.Notes[note]);
if (_CurrentBeat >= _Line.Notes[note].StartBeat)
{
int curEndBeat = _Line.Notes[note].EndBeat;
if (note < _Line.Notes.Length - 1)
curEndBeat = _Line.Notes[note + 1].StartBeat - 1;
if (_CurrentBeat <= curEndBeat)
{
zoomNote = note;
endBeat = curEndBeat;
zoomx = _Text.X;
}
else
{
// already passed
_Text.Color = note == lastNote ? _ColorProcessed : _Color;
_Text.Draw();
}
}
else
{
// not passed
_Text.Color = _Color;
_Text.Draw();
}
x += _Text.Rect.W;
}
if (zoomNote > -1)
{
_Text.X = zoomx;
_SetText(_Line.Notes[zoomNote]);
float diff = endBeat - _Line.Notes[zoomNote].StartBeat;
if (diff <= 0f)
diff = 1f;
float p = (_CurrentBeat - _Line.Notes[zoomNote].StartBeat) / diff;
if (p > 1f)
p = 1f;
p = 1f - p;
float ty = _Text.Y;
float th = _Text.Font.Height;
float tz = _Text.Z;
SRectF normalRect = _Text.Rect;
_Text.Font.Height *= 1f + p * 0.4f;
_Text.X -= (_Text.Rect.W - normalRect.W) / 2f;
_Text.Y -= (_Text.Rect.H - normalRect.H) / 2f;
_Text.Z -= 0.1f;
_Text.Color = _ColorProcessed;
_Text.Draw();
_Text.Y = ty;
_Text.Font.Height = th;
_Text.Z = tz;
}
}
private void _DrawFill()
{
float x = X - _Width / 2; // most left position
@@ -351,37 +269,87 @@ namespace VocaluxeLib.Menu
}
}
private void _DrawJump()
private void _DrawZoomedNote(CBaseNote zoomNote, int endBeat)
{
float diff = endBeat - zoomNote.StartBeat;
if (diff <= 0f)
diff = 1f;
float p = 1f - (_CurrentBeat - zoomNote.StartBeat) / diff;
if (p < 0)
p = 0;
float ty = _Text.Y;
float th = _Text.Font.Height;
float tz = _Text.Z;
SRectF normalRect = _Text.Rect;
_Text.Font.Height *= 1f + p * 0.4f;
_Text.X -= (_Text.Rect.W - normalRect.W) / 2f;
_Text.Y -= (_Text.Rect.H - normalRect.H) / 2f;
_Text.Z -= 0.1f;
_Text.Color = _ColorProcessed;
_Text.Draw();
_Text.Y = ty;
_Text.Font.Height = th;
_Text.Z = tz;
}
private void _DrawJumpingNode(CBaseNote jumpNote)
{
_Text.Color = _ColorProcessed;
int diff = jumpNote.Duration;
if (diff <= 0)
diff = 1;
float p = 1f - (_CurrentBeat - jumpNote.StartBeat) / diff;
if (p < 0.001)
_Text.Draw();
else
{
float y = _Text.Y;
_Text.Y -= _Text.Font.Height * 0.1f * p;
_Text.Draw();
_Text.Y = y;
}
}
private void _DrawZoomOrJump()
{
float x = X - _Width / 2; // most left position
//find last active note
int lastNote = _Line.FindPreviousNote((int)_CurrentBeat);
int jumpNote = -1;
float jumpx = 0f;
CSongNote highlightNote = null;
int hEndBeat = 0;
float hX = 0;
for (int note = 0; note < _Line.Notes.Length; note++)
{
_Text.X = x;
_SetText(_Line.Notes[note]);
CSongNote curNote = _Line.Notes[note];
_SetText(curNote);
if (_CurrentBeat >= _Line.Notes[note].StartBeat)
if (_CurrentBeat >= curNote.StartBeat)
{
int curEndBeat = _Line.Notes[note].EndBeat;
int curEndBeat = curNote.EndBeat;
if (note < _Line.Notes.Length - 1)
curEndBeat = _Line.Notes[note + 1].StartBeat - 1;
if (_CurrentBeat <= curEndBeat)
{
jumpNote = note;
jumpx = _Text.X;
highlightNote = curNote;
hEndBeat = curEndBeat;
hX = x;
}
else
{
// already passed
_Text.Color = note == lastNote ? _ColorProcessed : _Color;
_Text.Color = lastNote == note ? _ColorProcessed : _Color;
_Text.Draw();
}
}
@@ -395,28 +363,15 @@ namespace VocaluxeLib.Menu
x += _Text.Rect.W;
}
if (jumpNote < 0)
// Draw the highlighted note after all others because we want it to be above those! (transparency won't work well otherwhise)
if (highlightNote == null)
return;
_Text.X = jumpx;
_Text.Color = _ColorProcessed;
_SetText(_Line.Notes[jumpNote]);
int diff = _Line.Notes[jumpNote].EndBeat - _Line.Notes[jumpNote].StartBeat;
if (diff <= 0)
diff = 1;
float p = 1f - (_CurrentBeat - _Line.Notes[jumpNote].StartBeat) / diff;
if (Math.Abs(p) < float.Epsilon)
_Text.Draw();
_SetText(highlightNote);
_Text.X = hX;
if (LyricStyle == ELyricStyle.Jump)
_DrawJumpingNode(highlightNote);
else
{
float y = _Text.Y;
_Text.Y -= _Text.Font.Height * 0.1f * p;
_Text.Draw();
_Text.Y = y;
}
_DrawZoomedNote(highlightNote, hEndBeat);
}
#endregion draw
+28 -24
View File
@@ -153,6 +153,26 @@ namespace VocaluxeLib.Menu
}
}
private class CLoadThemeErrorHandler : CXmlDeserializer.CXmlDefaultErrorHandler
{
private static readonly string[] _AllowedMissing = new string[]
{
"Backgrounds", "Statics", "Texts", "Buttons", "SongMenus", "Lyrics", "SelectSlides", "SingNotes",
"NameSelections", "Equalizers", "Playlists", "ParticleEffects", "ScreenSettings"
};
public override void HandleError(CXmlException e)
{
CXmlMissingElementException missingEx = e as CXmlMissingElementException;
if (missingEx != null)
{
if (_AllowedMissing.Contains(missingEx.Field.Name))
return;
}
base.HandleError(e);
}
}
public virtual void LoadTheme(string xmlPath)
{
if (CBase.Config.GetLoadOldThemeFiles())
@@ -165,26 +185,10 @@ namespace VocaluxeLib.Menu
string file = Path.Combine(xmlPath, ThemeName + ".xml");
Theme.Informations = new SScreenInformation();
Theme.Backgrounds = new List<SThemeBackground>();
Theme.Statics = new List<SThemeStatic>();
Theme.Texts = new List<SThemeText>();
Theme.Buttons = new List<SThemeButton>();
Theme.SongMenus = new List<SThemeSongMenu>();
Theme.Lyrics = new List<SThemeLyrics>();
Theme.SelectSlides = new List<SThemeSelectSlide>();
Theme.SingNotes = new List<SThemeSingBar>();
Theme.NameSelections = new List<SThemeNameSelection>();
Theme.Equalizers = new List<SThemeEqualizer>();
Theme.Playlists = new List<SThemePlaylist>();
Theme.ParticleEffects = new List<SThemeParticleEffect>();
Theme.ScreenSettings = new List<SThemeScreenSetting>();
try
{
TextReader textReader = new StreamReader(file);
XmlSerializer deserializer = new XmlSerializer(typeof(SThemeScreen));
Theme = (SThemeScreen)deserializer.Deserialize(textReader);
CXmlDeserializer deserializer = new CXmlDeserializer(new CLoadThemeErrorHandler());
Theme = deserializer.Deserialize<SThemeScreen>(file);
foreach (SThemeBackground bg in Theme.Backgrounds)
_AddBackground(new CBackground(bg, PartyModeID), bg.Name);
@@ -243,6 +247,10 @@ namespace VocaluxeLib.Menu
{
CBase.Log.LogError("Error while reading " + ThemeName + ".xml", true, true);
}
catch (CXmlException e)
{
CBase.Log.LogError("Error while reading " + ThemeName + ".xml: " + e, true, true);
}
catch (Exception e)
{
CBase.Log.LogError(e.Message + e.StackTrace, true, true);
@@ -324,12 +332,8 @@ namespace VocaluxeLib.Menu
try
{
TextWriter textWriter = new StreamWriter(Path.Combine(ThemePath, ThemeName + ".xml"));
XmlSerializer serializer = new XmlSerializer(typeof(SThemeScreen));
serializer.Serialize(textWriter, Theme);
textWriter.Close();
CXmlSerializer serializer = new CXmlSerializer();
serializer.Serialize(Path.Combine(ThemePath, ThemeName + ".xml"), Theme);
}
catch (Exception e)
{
+24 -22
View File
@@ -29,8 +29,10 @@ namespace VocaluxeLib.Menu
get
{
for (int team = 0; team < _NumTeams; team++)
{
if (_TeamList[team].Count < _NumPlayerTeams[team])
return false;
}
return true;
}
}
@@ -147,7 +149,7 @@ namespace VocaluxeLib.Menu
{
if (!_ChangePlayerNumDynamic && _TeamList[_CurrentTeam].Count == _NumPlayerTeams[_CurrentTeam])
resetSelection = true;
else if (_TeamList[_CurrentTeam].Count == _PartyMode.GetMaxPlayerPerTeam())
else if (_TeamList[_CurrentTeam].Count == _PartyMode.MaxPlayersPerTeam)
resetSelection = true;
}
else if (!_SelectingFast)
@@ -344,13 +346,13 @@ namespace VocaluxeLib.Menu
if (numPressed > 0)
{
if (_ChangeTeamNumDynamic && numPressed < _PartyMode.GetMaxTeams() && numPressed > _SelectSlides[_SelectSlideTeams].NumValues)
if (_ChangeTeamNumDynamic && numPressed < _PartyMode.MaxTeams && numPressed > _SelectSlides[_SelectSlideTeams].NumValues)
{
while (numPressed < _PartyMode.GetMaxTeams())
while (numPressed < _PartyMode.MaxTeams)
IncreaseTeamNum();
}
if (numPressed <= _SelectSlides[_SelectSlideTeams].NumValues)
_SelectSlides[_SelectSlideTeams].SetSelectionByValueIndex(numPressed - 1);
_SelectSlides[_SelectSlideTeams].SelectedTag = numPressed;
}
}
if (_SelectingFastPlayerNr > 0 && _SelectingFastPlayerNr <= _NumPlayerTeams[_CurrentTeam])
@@ -433,7 +435,7 @@ namespace VocaluxeLib.Menu
if (!_ChangePlayerNumDynamic && _TeamList[_CurrentTeam].Count == _NumPlayerTeams[_CurrentTeam])
stopSelectingFast = true;
else if (_TeamList[_CurrentTeam].Count == _PartyMode.GetMaxPlayerPerTeam())
else if (_TeamList[_CurrentTeam].Count == _PartyMode.MaxPlayersPerTeam)
stopSelectingFast = true;
}
else
@@ -488,7 +490,7 @@ namespace VocaluxeLib.Menu
else if (mouseEvent.RB)
{
bool exit = true;
if (_SelectSlides[_SelectSlidePlayer].Selected && _TeamList[_CurrentTeam].Count > 0)
if (_SelectSlides[_SelectSlidePlayer].Selected && _TeamList[_CurrentTeam].Count > _SelectSlides[_SelectSlidePlayer].Selection)
{
int currentSelection = _SelectSlides[_SelectSlidePlayer].Selection;
int id = _TeamList[_CurrentTeam][currentSelection];
@@ -505,7 +507,7 @@ namespace VocaluxeLib.Menu
{
if (!_ChangePlayerNumDynamic && _TeamList[_CurrentTeam].Count == _NumPlayerTeams[_CurrentTeam])
stopSelectingFast = true;
else if (_TeamList[_CurrentTeam].Count == _PartyMode.GetMaxPlayerPerTeam())
else if (_TeamList[_CurrentTeam].Count == _PartyMode.MaxPlayersPerTeam)
stopSelectingFast = true;
}
else if (mouseEvent.MB)
@@ -539,8 +541,8 @@ namespace VocaluxeLib.Menu
public override void LoadTheme(string xmlPath)
{
base.LoadTheme(xmlPath);
_SelectSlides[_SelectSlidePlayer].WithTextures = true;
_SelectSlides[_SelectSlidePlayer].SelectionByHover = true;
_SelectSlides[_SelectSlidePlayer].DrawTextures = true;
_SelectSlides[_SelectSlidePlayer].SelectByHovering = true;
_AddStatic(_ChooseAvatarStatic);
}
@@ -571,7 +573,7 @@ namespace VocaluxeLib.Menu
if (!_AllowChangeTeamNum)
return;
if (_NumTeams + 1 <= _PartyMode.GetMaxTeams())
if (_NumTeams + 1 <= _PartyMode.MaxTeams)
{
_NumTeams++;
int[] numPlayerTeams = _NumPlayerTeams;
@@ -600,7 +602,7 @@ namespace VocaluxeLib.Menu
if (!_AllowChangeTeamNum)
return;
if (_NumTeams - 1 >= _PartyMode.GetMinTeams())
if (_NumTeams - 1 >= _PartyMode.MinTeams)
_NumTeams--;
_UpdateButtonState();
}
@@ -611,7 +613,7 @@ namespace VocaluxeLib.Menu
return;
if (_NumPlayerTeams.Length > team)
{
if (_NumPlayerTeams[team] + 1 <= _PartyMode.GetMaxPlayerPerTeam())
if (_NumPlayerTeams[team] + 1 <= _PartyMode.MaxPlayersPerTeam)
_NumPlayerTeams[team]++;
_UpdatePlayerSlide();
}
@@ -624,7 +626,7 @@ namespace VocaluxeLib.Menu
return;
if (_NumPlayerTeams.Length > team)
{
if (_NumPlayerTeams[team] - 1 >= _PartyMode.GetMinPlayerPerTeam())
if (_NumPlayerTeams[team] - 1 >= _PartyMode.MinPlayersPerTeam)
_NumPlayerTeams[team]--;
if (_TeamList[team].Count > _NumPlayerTeams[team])
_RemovePlayerByIndex(team, _NumPlayerTeams[team] - 1);
@@ -684,7 +686,7 @@ namespace VocaluxeLib.Menu
_SelectSlides[_SelectSlidePlayer].AddValue("", _NameSelections[_NameSelection].TextureEmptyTile);
if (selection >= _TeamList[_CurrentTeam].Count)
selection = _TeamList[_CurrentTeam].Count - 1;
_SelectSlides[_SelectSlidePlayer].SetSelectionByValueIndex(selection);
_SelectSlides[_SelectSlidePlayer].Selection = selection;
}
private void _UpdateTeamSlide()
@@ -692,25 +694,25 @@ namespace VocaluxeLib.Menu
_SelectSlides[_SelectSlideTeams].Visible = _Teams;
_SelectSlides[_SelectSlideTeams].Clear();
for (int i = 1; i <= _NumTeams; i++)
_SelectSlides[_SelectSlideTeams].AddValue("Team " + i);
_SelectSlides[_SelectSlideTeams].AddValue("Team " + i, null, i);
}
private void _UpdateButtonVisibility()
{
_Buttons[_ButtonIncreaseTeams].Visible = _AllowChangePlayerNum && _Teams && _PartyMode.GetMinTeams() != _PartyMode.GetMaxTeams();
_Buttons[_ButtonDecreaseTeams].Visible = _AllowChangePlayerNum && _Teams && _PartyMode.GetMinTeams() != _PartyMode.GetMaxTeams();
_Buttons[_ButtonIncreaseTeams].Visible = _AllowChangePlayerNum && _Teams && _PartyMode.MinTeams != _PartyMode.MaxTeams;
_Buttons[_ButtonDecreaseTeams].Visible = _AllowChangePlayerNum && _Teams && _PartyMode.MinTeams != _PartyMode.MaxTeams;
_Buttons[_ButtonIncreasePlayer].Visible = _AllowChangePlayerNum;
_Buttons[_ButtonDecreasePlayer].Visible = _AllowChangePlayerNum;
}
private void _UpdateButtonState()
{
_Buttons[_ButtonIncreaseTeams].Selectable = _NumTeams < _PartyMode.GetMaxTeams();
_Buttons[_ButtonDecreaseTeams].Selectable = _NumTeams > _PartyMode.GetMinTeams();
_Buttons[_ButtonIncreaseTeams].Selectable = _NumTeams < _PartyMode.MaxTeams;
_Buttons[_ButtonDecreaseTeams].Selectable = _NumTeams > _PartyMode.MinTeams;
if (_NumPlayerTeams != null && _NumPlayerTeams.Length > _CurrentTeam)
{
_Buttons[_ButtonIncreasePlayer].Selectable = _NumPlayerTeams[_CurrentTeam] < _PartyMode.GetMaxPlayerPerTeam();
_Buttons[_ButtonDecreasePlayer].Selectable = _NumPlayerTeams[_CurrentTeam] > _PartyMode.GetMinPlayerPerTeam();
_Buttons[_ButtonIncreasePlayer].Selectable = _NumPlayerTeams[_CurrentTeam] < _PartyMode.MaxPlayersPerTeam;
_Buttons[_ButtonDecreasePlayer].Selectable = _NumPlayerTeams[_CurrentTeam] > _PartyMode.MinPlayersPerTeam;
}
else
{
@@ -723,7 +725,7 @@ namespace VocaluxeLib.Menu
{
if (_NumPlayerTeams[team] == _TeamList[team].Count && !_ChangePlayerNumDynamic)
return;
if (_NumPlayerTeams[team] == _PartyMode.GetMaxPlayerPerTeam())
if (_NumPlayerTeams[team] == _PartyMode.MaxPlayersPerTeam)
return;
_NameSelections[_NameSelection].UseProfile(profileID);
+6 -7
View File
@@ -1037,14 +1037,16 @@ namespace VocaluxeLib.Menu
Cover = new CStatic(_Theme.StaticCover, _PartyModeID)
};
en.Cover.LoadSkin();
en.Cover.Y += Rect.Y + (i * _Theme.EntryHeight);
en.Cover.X += Rect.X;
en.Cover.X += Rect.X;
en.Text1 = new CText(_Text1);
en.Text1.X += Rect.X;
en.Text1.Y += Rect.Y + (i * _Theme.EntryHeight);
en.SelectSlide = new CSelectSlide(_SelectSlideGameMode);
en.SelectSlide.LoadSkin();
en.SelectSlide.X += Rect.X;
en.SelectSlide.Y += Rect.Y + (i * _Theme.EntryHeight);
@@ -1145,12 +1147,9 @@ namespace VocaluxeLib.Menu
string t1 = CBase.Language.Translate(_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.Count; g++)
{
_PlaylistElements[i].SelectSlide.AddValue(Enum.GetName(typeof(EGameMode), pec.Modes[g]));
if (pec.Modes[g] == pec.Mode)
_PlaylistElements[i].SelectSlide.SetSelectionByValueIndex(g);
}
foreach (EGameMode gm in pec.Modes)
_PlaylistElements[i].SelectSlide.AddValue(Enum.GetName(typeof(EGameMode), gm), null, (int)gm);
_PlaylistElements[i].SelectSlide.SelectedTag = (int)pec.Mode;
}
else
{
+197 -191
View File
@@ -17,6 +17,8 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Xml.Serialization;
using VocaluxeLib.Draw;
@@ -51,8 +53,8 @@ namespace VocaluxeLib.Menu
public SThemeColor TextSelColor;
public float TextH;
public float TextRelativeX;
public float TextRelativeY;
[DefaultValue(0.0f)] public float TextRelativeX;
[DefaultValue(0.0f)] public float TextRelativeY;
public float TextMaxW;
public string TextFont;
@@ -61,8 +63,23 @@ namespace VocaluxeLib.Menu
public int NumVisible;
}
public sealed class CSelectSlide : CMenuElementBase, IMenuElement, ICloneable, IThemeable
public sealed class CSelectSlide : CMenuElementBase, IMenuElement, IThemeable
{
private struct SValue
{
public string Text;
public int TranslationId;
public int Tag;
public CTextureRef Texture;
}
private class CElement
{
public CText Text;
public CStatic Img;
public SRectF Bounds;
}
private readonly int _PartyModeID;
private SThemeSelectSlide _Theme;
@@ -138,52 +155,52 @@ namespace VocaluxeLib.Menu
}
}
}
public bool ValueSelected
public bool IsValueSelected
{
get { return Selected && !_ArrowLeftSelected && !_ArrowRightSelected; }
}
public bool SelectionByHover;
private bool _ArrowLeftSelected;
private bool _ArrowRightSelected;
private readonly List<string> _ValueNames;
private readonly List<int> _ValuePartyModeIDs;
private readonly List<CTextureRef> _Textures;
private readonly List<int> _ValueIndexes;
private readonly List<SRectF> _ValueBounds = new List<SRectF>();
public bool WithTextures;
public bool SelectByHovering;
public bool DrawTextures;
private int _Selection = -1;
public int Selection
{
get { return _Selection; }
set { _Selection = value.Clamp(0, _ValueNames.Count - 1, false); }
}
public string Value
{
get { return (_Selection >= 0 && _Selection < _ValueNames.Count) ? _ValueNames[_Selection] : null; }
}
public int ValueIndex
{
get
set
{
if (_Selection >= 0 && _ValueIndexes.Count > _Selection)
return _ValueIndexes[_Selection];
return -1;
value = value.Clamp(0, _Values.Count - 1, false);
if (value == _Selection)
return;
_Selection = value;
_Invalidate();
}
}
public string SelectedValue
{
get { return _Selection >= 0 ? _Values[_Selection].Text : null; }
set { Selection = _Values.FindIndex(val => val.Text == value); }
}
public int SelectedTag
{
get { return _Selection >= 0 ? _Values[_Selection].Tag : -1; }
set { Selection = _Values.FindIndex(val => val.Tag == value); }
}
public int NumValues
{
get { return _ValueNames.Count; }
get { return _Values.Count; }
}
private readonly List<SValue> _Values = new List<SValue>();
private readonly List<CElement> _VisibleElements = new List<CElement>();
private bool _NeedsRevalidate = true;
private int _NumVisible = -1;
private CTextureRef _Texture;
private CTextureRef _TextureArrowLeft;
@@ -197,10 +214,11 @@ namespace VocaluxeLib.Menu
get { return _NumVisible; }
set
{
if (value > 0)
_NumVisible = value;
if (value <= 0 || value == _NumVisible)
return;
_NumVisible = value;
_ValueBounds.Clear();
_Invalidate();
}
}
@@ -210,11 +228,6 @@ namespace VocaluxeLib.Menu
ThemeLoaded = false;
_TextH = 1f;
_MaxW = 0f;
_Textures = new List<CTextureRef>();
_ValueIndexes = new List<int>();
_ValueNames = new List<string>();
_ValuePartyModeIDs = new List<int>();
}
public CSelectSlide(CSelectSlide slide)
@@ -241,15 +254,11 @@ namespace VocaluxeLib.Menu
_TextRelativeY = slide._TextRelativeY;
_MaxW = slide._MaxW;
_Textures = new List<CTextureRef>(slide._Textures);
_ValueIndexes = new List<int>(slide._ValueIndexes);
_ValueNames = new List<string>(slide._ValueNames);
_ValueBounds = new List<SRectF>(slide._ValueBounds);
_ValuePartyModeIDs = new List<int>(slide._ValuePartyModeIDs);
_Values.AddRange(slide._Values);
_Selection = slide._Selection;
_NumVisible = slide._NumVisible;
WithTextures = slide.WithTextures;
DrawTextures = slide.DrawTextures;
Visible = slide.Visible;
}
@@ -258,11 +267,6 @@ namespace VocaluxeLib.Menu
_PartyModeID = partyModeID;
_Theme = theme;
_Textures = new List<CTextureRef>();
_ValueIndexes = new List<int>();
_ValueNames = new List<string>();
_ValuePartyModeIDs = new List<int>();
ThemeLoaded = true;
}
@@ -382,58 +386,73 @@ namespace VocaluxeLib.Menu
return ThemeLoaded;
}
public void AddValue(string value)
private void _Invalidate()
{
AddValue(value, _PartyModeID);
_NeedsRevalidate = true;
}
public void AddValue(string value, int partyModeID)
/// <summary>
/// Adds an integer to the slide setting its tag to the value and its text to the text representation of the tag
/// </summary>
/// <param name="tag">Value to add</param>
public void AddValue(int tag)
{
AddValue(value, null, _ValueIndexes.Count, partyModeID);
AddValue(tag.ToString(), null, tag);
}
public void AddValue(string value, CTextureRef texture)
/// <summary>
/// Adds an entry to the slide.
/// </summary>
/// <param name="text">Label to show</param>
/// <param name="texture">Texture to show</param>
/// <param name="tag">User value (e.g. id of entry)</param>
public void AddValue(string text, CTextureRef texture = null, int tag = 0)
{
AddValue(value, texture, _ValueIndexes.Count, _PartyModeID);
AddValue(text, _PartyModeID, texture, tag);
}
private void _AddValue(string value, CTextureRef texture, int valueIndex)
/// <summary>
/// Adds an entry to the slide.
/// </summary>
/// <param name="text">Label to show</param>
/// <param name="translationId">Translation id to use for the text</param>
/// <param name="texture">Texture to show</param>
/// <param name="tag">User value (e.g. id of entry)</param>
public void AddValue(string text, int translationId, CTextureRef texture = null, int tag = 0)
{
AddValue(value, texture, valueIndex, _PartyModeID);
}
SValue value = new SValue {Text = text, TranslationId = translationId, Tag = tag, Texture = texture};
public void AddValue(string value, CTextureRef texture, int valueIndex, int partyModeID)
{
_ValueNames.Add(value);
_Textures.Add(texture);
_ValueIndexes.Add(valueIndex);
_ValuePartyModeIDs.Add(partyModeID);
_Values.Add(value);
if (Selection == -1)
if (Selection < 0)
Selection = 0;
_ValueBounds.Clear();
_Invalidate();
}
public void AddValues(IEnumerable<string> values)
{
foreach (string value in values)
_AddValue(value, null, _PartyModeID);
_ValueBounds.Clear();
AddValue(value);
}
public void AddValues(string[] values, CTextureRef[] textures)
{
if (values.Length != textures.Length)
return;
Debug.Assert(values.Length == textures.Length);
for (int i = 0; i < values.Length; i++)
AddValue(values[i], textures[i]);
if (Selection == -1)
Selection = 0;
}
_ValueBounds.Clear();
public void RemoveValue(string text)
{
int idx = _Values.FindIndex(val => val.Text == text);
if (idx < 0)
return;
_Values.RemoveAt(idx);
if (Selection >= idx)
Selection--;
_Invalidate();
}
public void SetValues<T>(int selection)
@@ -447,31 +466,20 @@ namespace VocaluxeLib.Menu
RenameValue(Selection, newName);
}
public void RenameValue(int selection, string newName, CTextureRef newTexture = null)
public void RenameValue(int index, string newName, CTextureRef newTexture = null)
{
if (selection < 0 && selection >= _ValueNames.Count)
if (index < 0 && index >= _Values.Count)
return;
_ValueNames[selection] = newName;
_Textures[selection] = newTexture;
}
public bool SetSelectionByValueIndex(int valueIndex)
{
for (int i = 0; i < _ValueIndexes.Count; i++)
{
if (_ValueIndexes[i] == valueIndex)
{
Selection = i;
return true;
}
}
return false;
SValue value = _Values[index];
value.Text = newName;
value.Texture = newTexture;
_Values[index] = value;
}
public bool SelectNextValue()
{
if (Selection < _ValueNames.Count - 1)
if (Selection < _Values.Count - 1)
{
Selection++;
return true;
@@ -491,50 +499,46 @@ namespace VocaluxeLib.Menu
public void SelectFirstValue()
{
if (_ValueNames.Count > 0)
if (_Values.Count > 0)
Selection = 0;
}
public void SelectLastValue()
{
if (_ValueNames.Count > 0)
Selection = _ValueNames.Count - 1;
if (_Values.Count > 0)
Selection = _Values.Count - 1;
}
public void Clear()
{
_Values.Clear();
_Selection = -1;
_ValueNames.Clear();
_Textures.Clear();
_ValueBounds.Clear();
_ValueIndexes.Clear();
_Invalidate();
}
private int _GetCurOffset()
{
int offset = _Selection - _NumVisible / 2;
return offset.Clamp(0, _Values.Count - _NumVisible, true);
}
private void _SelectAtPos(int x, int y)
{
if (_NeedsRevalidate)
_Revalidate();
int index = _VisibleElements.FindIndex(el => CHelper.IsInBounds(el.Bounds, x, y));
if (index < 0)
return;
Selection = index + _GetCurOffset();
}
public void ProcessMouseMove(int x, int y)
{
_ArrowLeftSelected = CHelper.IsInBounds(RectArrowLeft, x, y) && _Selection > 0;
_ArrowRightSelected = CHelper.IsInBounds(RectArrowRight, x, y) && _Selection < _ValueNames.Count - 1;
_ArrowRightSelected = CHelper.IsInBounds(RectArrowRight, x, y) && _Selection < _Values.Count - 1;
if (SelectionByHover)
{
for (int i = 0; i < _ValueBounds.Count; i++)
{
if (CHelper.IsInBounds(_ValueBounds[i], x, y))
{
int offset = _Selection - _NumVisible / 2;
if (_ValueNames.Count - _NumVisible - offset < 0)
offset = _ValueNames.Count - _NumVisible;
if (offset < 0)
offset = 0;
Selection = i + offset;
_ValueBounds.Clear();
break;
}
}
}
if (SelectByHovering)
_SelectAtPos(x, y);
}
public void ProcessMouseLBClick(int x, int y)
@@ -547,21 +551,78 @@ namespace VocaluxeLib.Menu
if (_ArrowRightSelected)
SelectNextValue();
for (int i = 0; i < _ValueBounds.Count; i++)
_SelectAtPos(x, y);
}
private void _Revalidate()
{
if (!_NeedsRevalidate)
return;
_NeedsRevalidate = false;
int numvis = Math.Min(_NumVisible, _Values.Count);
if (numvis != _VisibleElements.Count)
{
if (CHelper.IsInBounds(_ValueBounds[i], x, y))
_VisibleElements.Clear();
for (int i = 0; i < numvis; i++)
{
int offset = _Selection - _NumVisible / 2;
var el = new CElement
{
Text = new CText(0, 0, 0, _TextH, _MaxW, EAlignment.Center, _Theme.TextStyle, _Theme.TextFont, _TextColor, "T", _PartyModeID),
Img = new CStatic(_PartyModeID)
};
_VisibleElements.Add(el);
}
}
if (numvis == 0)
return;
if (_ValueNames.Count - _NumVisible - offset < 0)
offset = _ValueNames.Count - _NumVisible;
float elWidth = (Rect.W - _TextRelativeX * 2) / numvis;
//Center point of the first entry
float xStart = Rect.X + _TextRelativeX + elWidth / 2f;
if (offset < 0)
offset = 0;
int offset = _GetCurOffset();
Selection = i + offset;
_ValueBounds.Clear();
break;
for (int i = 0; i < numvis; i++)
{
CText text = _VisibleElements[i].Text;
RectangleF textBounds;
float curX = xStart + elWidth * i;
if (String.IsNullOrEmpty(_Values[i + offset].Text))
{
text.Visible = false;
textBounds = new RectangleF();
}
else
{
text.Visible = true;
text.Text = _Values[i + offset].Text;
text.TranslationID = _Values[i + offset].TranslationId;
text.Color = (i + offset == Selection) ? _SelTextColor : _TextColor;
textBounds = CBase.Fonts.GetTextBounds(text);
text.X = curX;
text.Z = Rect.Z;
}
CStatic img = _VisibleElements[i].Img;
if (!DrawTextures || _Values[i + offset].Texture == null)
{
if (text.Visible)
text.Y = Rect.Y + (Rect.H - textBounds.Height) / 2 - _TextRelativeY;
img.Visible = false;
_VisibleElements[i].Bounds = new SRectF(text.X - textBounds.Width / 2f, text.Y, textBounds.Width, textBounds.Height, Rect.Z);
}
else
{
text.Y = (int)(Rect.Y + Rect.H - textBounds.Height - _TextRelativeY);
img.Texture = _Values[i + offset].Texture;
float alpha = (i + offset == _Selection) ? 1f : 0.35f;
img.Color = new SColorF(1f, 1f, 1f, alpha);
float size = Rect.H - textBounds.Height - 2 * _TextRelativeY;
if (size > elWidth)
size = elWidth;
var imgRect = new SRectF(curX - size / 2, Rect.Y + _TextRelativeY, size, size, Rect.Z);
img.MaxRect = imgRect;
_VisibleElements[i].Bounds = imgRect;
}
}
}
@@ -584,7 +645,7 @@ namespace VocaluxeLib.Menu
CBase.Drawing.DrawTexture(_TextureArrowLeft, RectArrowLeft, _ColorArrow);
}
if (_Selection < _ValueNames.Count - 1 || CBase.Settings.GetProgramState() == EProgramState.EditTheme)
if (_Selection < _Values.Count - 1 || CBase.Settings.GetProgramState() == EProgramState.EditTheme)
{
if (_ArrowRightSelected)
CBase.Drawing.DrawTexture(_SelTextureArrowRight, RectArrowRight, _SelColorArrow);
@@ -592,63 +653,12 @@ namespace VocaluxeLib.Menu
CBase.Drawing.DrawTexture(_TextureArrowRight, RectArrowRight, _ColorArrow);
}
if (_NumVisible < 1 || _ValueNames.Count == 0)
return;
float x = Rect.X + (Rect.W - _TextRelativeX) * 0.1f;
float dx = (Rect.W - _TextRelativeX) * 0.8f / _NumVisible;
//float y = Rect.Y + (Rect.H - TextH);
int offset = _Selection - _NumVisible / 2;
if (_ValueNames.Count - _NumVisible - offset < 0)
offset = _ValueNames.Count - _NumVisible;
if (offset < 0)
offset = 0;
int numvis = _NumVisible;
if (_ValueNames.Count < numvis)
numvis = _ValueNames.Count;
_ValueBounds.Clear();
for (int i = 0; i < numvis; i++)
if (_NeedsRevalidate)
_Revalidate();
foreach (CElement element in _VisibleElements)
{
var text = new CText(0, 0, 0, _TextH, _MaxW, EAlignment.Center, _Theme.TextStyle, _Theme.TextFont, _TextColor, "T",
_ValuePartyModeIDs[i + offset]);
if (_ValueNames[i + offset] != "")
text.Text = _ValueNames[i + offset];
else
text.Visible = false;
var alpha = new SColorF(1f, 1f, 1f, 0.35f);
if (i + offset == _Selection)
{
text.Color = _SelTextColor;
alpha = new SColorF(1f, 1f, 1f, 1f);
}
RectangleF bounds = CBase.Fonts.GetTextBounds(text);
text.X = (x + dx / 2f + dx * i) + _TextRelativeX;
if (!WithTextures)
text.Y = (int)((Rect.Y + (Rect.H - bounds.Height) / 2) + _TextRelativeY);
else
text.Y = (int)((Rect.Y + (Rect.H - bounds.Height)) + _TextRelativeY);
text.Z = Rect.Z;
text.Draw();
if (WithTextures)
{
float dh = text.Y - Rect.Y - Rect.H * 0.1f;
var rect = new SRectF(text.X - dh / 2, Rect.Y + Rect.H * 0.05f, dh, dh, Rect.Z);
CBase.Drawing.DrawTexture(_Textures[i + offset], rect, alpha, rect);
_ValueBounds.Add(rect);
}
else
_ValueBounds.Add(new SRectF(text.X - bounds.Width / 2f, text.Y, bounds.Width, bounds.Height, Rect.Z));
element.Text.Draw();
element.Img.Draw();
}
}
@@ -686,6 +696,7 @@ namespace VocaluxeLib.Menu
_SelTexture = CBase.Themes.GetSkinTexture(_Theme.SkinSelected, _PartyModeID);
_SelTextureArrowLeft = CBase.Themes.GetSkinTexture(_Theme.SkinArrowLeftSelected, _PartyModeID);
_SelTextureArrowRight = CBase.Themes.GetSkinTexture(_Theme.SkinArrowRightSelected, _PartyModeID);
_Invalidate();
}
public void ReloadSkin()
@@ -694,11 +705,6 @@ namespace VocaluxeLib.Menu
LoadSkin();
}
public object Clone()
{
return MemberwiseClone();
}
#region ThemeEdit
public void MoveElement(int stepX, int stepY)
{
+24
View File
@@ -17,6 +17,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Xml.Serialization;
using VocaluxeLib.Xml;
@@ -56,6 +58,12 @@ namespace VocaluxeLib.Menu.SingNotes
public readonly List<CNoteBars> PlayerNotes = new List<CNoteBars>();
private SRectF _Rect;
public override SRectF Rect
{
get { return _Rect; }
}
public bool Selectable
{
get { return false; }
@@ -143,6 +151,16 @@ namespace VocaluxeLib.Menu.SingNotes
PlayerNotes.Clear();
for (int p = 0; p < numPlayers; p++)
PlayerNotes.Add(new CNoteBars(_PartyModeID, p, _BarPos[p, numPlayers - 1], _Theme));
if (numPlayers == 0)
_Rect = new SRectF(0, 0, 0, 0, Rect.Z);
else
{
_Rect.X = PlayerNotes.Select(bp => bp.Rect.X).Min();
_Rect.Y = PlayerNotes.Select(bp => bp.Rect.X).Min();
_Rect.Right = PlayerNotes.Select(bp => bp.Rect.Right).Max();
_Rect.Bottom = PlayerNotes.Select(bp => bp.Rect.Bottom).Max();
_Rect.Z = PlayerNotes.Select(bp => bp.Rect.Z).Average();
}
}
public void Draw()
@@ -155,6 +173,12 @@ namespace VocaluxeLib.Menu.SingNotes
public void LoadSkin()
{
Debug.Assert(_Theme.BarPos.Length > 0);
X = _Theme.BarPos.Select(bp => bp.Rect.X).Min();
Y = _Theme.BarPos.Select(bp => bp.Rect.X).Min();
W = X - _Theme.BarPos.Select(bp => bp.Rect.Right).Max();
H = Y - _Theme.BarPos.Select(bp => bp.Rect.Bottom).Max();
Z = _Theme.BarPos.Select(bp => bp.Rect.Z).Average();
foreach (SBarPosition bp in _Theme.BarPos)
{
int n = Int32.Parse(bp.Name.Substring(3, 1)) - 1;