More duplicate Code removed
This commit is contained in:
Flamefire committed 2013-03-16 21:57:24 +01:00
1 parent c3cac56e1a
commit 1eef829479
7 files changed
+98 -184

No files matched your search

+9 -26
View File
@@ -664,7 +664,6 @@ namespace Vocaluxe.Base
//Check if there are inputs. //Check if there are inputs.
if (Devices[dev].Inputs.Count >= 1) if (Devices[dev].Inputs.Count >= 1)
{ {
bool micfound = false;
//Check if there is one or more channels //Check if there is one or more channels
if (Devices[dev].Inputs[0].Channels >= 1) if (Devices[dev].Inputs[0].Channels >= 1)
{ {
@@ -674,21 +673,16 @@ namespace Vocaluxe.Base
MicConfig[0].InputName = Devices[dev].Inputs[0].Name; MicConfig[0].InputName = Devices[dev].Inputs[0].Name;
MicConfig[0].Channel = 1; MicConfig[0].Channel = 1;
micfound = true; if (Devices[dev].Inputs[0].Channels >= 2)
} {
if (Devices[dev].Inputs[0].Channels >= 2) //Set this device to player 2
{ MicConfig[1].DeviceName = Devices[dev].Name;
//Set this device to player 2 MicConfig[1].DeviceDriver = Devices[dev].Driver;
MicConfig[1].DeviceName = Devices[dev].Name; MicConfig[1].InputName = Devices[dev].Inputs[0].Name;
MicConfig[1].DeviceDriver = Devices[dev].Driver; MicConfig[1].Channel = 2;
MicConfig[1].InputName = Devices[dev].Inputs[0].Name;
MicConfig[1].Channel = 2;
micfound = true; return true;
} }
if (micfound)
{
return true;
} }
} }
} }
@@ -820,17 +814,6 @@ namespace Vocaluxe.Base
switch (param) switch (param)
{ {
case "songfolder": case "songfolder":
//Check if SongFolders from config.xml are saved
if (SongFolderOld.Count == 0)
{
SongFolderOld.Clear();
SongFolderOld.AddRange(SongFolder);
SongFolder.Clear();
}
//Add parameter-value to SongFolder
SongFolder.Add(value);
break;
case "songpath": case "songpath":
//Check if SongFolders from config.xml are saved //Check if SongFolders from config.xml are saved
if (SongFolderOld.Count == 0) if (SongFolderOld.Count == 0)
+52 -52
View File
@@ -155,40 +155,18 @@ namespace Vocaluxe.Base
class CFont:IDisposable class CFont:IDisposable
{ {
private List<CGlyph> _Glyphs; private Dictionary<char, CGlyph> _Glyphs;
private Hashtable _htGlyphs;
private PrivateFontCollection fonts = null; private PrivateFontCollection fonts = null;
private FontFamily family; private FontFamily family;
private float SIZEh; private float SIZEh;
public string FilePath; public string FilePath;
public Font GetFont()
{
if (fonts == null)
{
fonts = new PrivateFontCollection();
try
{
fonts.AddFontFile(FilePath);
family = fonts.Families[0];
}
catch (Exception e)
{
CLog.LogError("Error opening font file " + FilePath + ": " + e.Message);
}
}
return new Font(family, CFonts.Height, CFonts.GetFontStyle(), GraphicsUnit.Pixel);
}
public CFont(string File) public CFont(string File)
{ {
FilePath = File; FilePath = File;
_Glyphs = new List<CGlyph>(); _Glyphs = new Dictionary<char, CGlyph>();
_htGlyphs = new Hashtable();
switch (CConfig.TextureQuality) switch (CConfig.TextureQuality)
{ {
@@ -213,74 +191,95 @@ namespace Vocaluxe.Base
} }
} }
public void DrawGlyph(char chr, float x, float y, float h, float z, SColorF color) public Font GetFont()
{ {
AddGlyph(chr); if (fonts == null)
{
fonts = new PrivateFontCollection();
try
{
fonts.AddFontFile(FilePath);
family = fonts.Families[0];
}
catch (Exception e)
{
CLog.LogError("Error opening font file " + FilePath + ": " + e.Message);
}
}
CFonts.Height = h; return new Font(family, CFonts.Height, CFonts.GetFontStyle(), GraphicsUnit.Pixel);
CGlyph glyph = _Glyphs[(int)_htGlyphs[chr]];
float factor = h / glyph.Texture.height;
float d = glyph.SIZEh / 5f * factor;
CDraw.DrawTexture(glyph.Texture, new SRectF(x - d, y, glyph.Texture.width * factor, h, z), color);
} }
public void DrawGlyphReflection(char chr, float x, float y, float h, float z, SColorF color, float rspace, float rheight) public void DrawGlyph(char chr, float x, float y, float h, float z, SColorF color)
{ {
AddGlyph(chr); STexture texture;
SRectF rect;
CFonts.Height = h; _GetGlyphTextureAndRect(chr, x, y, z, h, out texture, out rect);
CGlyph glyph = _Glyphs[(int)_htGlyphs[chr]]; CDraw.DrawTexture(texture, rect, color);
float factor = h / glyph.Texture.height;
float d = glyph.SIZEh / 5f * factor;
SRectF rect = new SRectF(x - d, y, glyph.Texture.width * factor, h, z);
CDraw.DrawTextureReflection(glyph.Texture, rect, color, rect, rspace, rheight);
} }
public void DrawGlyph(char chr, float x, float y, float h, float z, SColorF color, float begin, float end) public void DrawGlyph(char chr, float x, float y, float h, float z, SColorF color, float begin, float end)
{
STexture texture;
SRectF rect;
_GetGlyphTextureAndRect(chr, x, y, z, h, out texture, out rect);
CDraw.DrawTexture(texture, rect, color, begin, end);
}
public void DrawGlyphReflection(char chr, float x, float y, float h, float z, SColorF color, float rspace, float rheight)
{
STexture texture;
SRectF rect;
_GetGlyphTextureAndRect(chr, x, y, z, h, out texture, out rect);
CDraw.DrawTextureReflection(texture, rect, color, rect, rspace, rheight);
}
private void _GetGlyphTextureAndRect(char chr, float x, float y, float z, float h, out STexture texture, out SRectF rect)
{ {
AddGlyph(chr); AddGlyph(chr);
CFonts.Height = h; CFonts.Height = h;
CGlyph glyph = _Glyphs[(int)_htGlyphs[chr]]; CGlyph glyph = _Glyphs[chr];
float factor = h / glyph.Texture.height; texture = glyph.Texture;
float width = glyph.Texture.width * factor; float factor = h / texture.height;
float width = texture.width * factor;
float d = glyph.SIZEh / 5f * factor; float d = glyph.SIZEh / 5f * factor;
rect = new SRectF(x - d, y, width, h, z);
CDraw.DrawTexture(glyph.Texture, new SRectF(x - d, y, width, h, z), color, begin, end);
} }
public float GetWidth(char chr) public float GetWidth(char chr)
{ {
AddGlyph(chr); AddGlyph(chr);
CGlyph glyph = _Glyphs[(int)_htGlyphs[chr]]; CGlyph glyph = _Glyphs[chr];
float factor = CFonts.Height / glyph.Texture.height; float factor = CFonts.Height / glyph.Texture.height;
return glyph.width * factor; return glyph.width * factor;
} }
public float GetHeight(char chr) public float GetHeight(char chr)
{ {
return CFonts.Height;
/*WTF???
AddGlyph(chr); AddGlyph(chr);
CGlyph glyph = _Glyphs[(int)_htGlyphs[chr]]; CGlyph glyph = _Glyphs[chr];
float factor = CFonts.Height / glyph.Texture.height; float factor = CFonts.Height / glyph.Texture.height;
return glyph.Texture.height * factor; return glyph.Texture.height * factor;*/
} }
public void AddGlyph(char chr) public void AddGlyph(char chr)
{ {
if (_htGlyphs.ContainsKey(chr)) if (_Glyphs.ContainsKey(chr))
return; return;
float h = CFonts.Height; float h = CFonts.Height;
_Glyphs.Add(new CGlyph(chr, SIZEh)); _Glyphs.Add(chr, new CGlyph(chr, SIZEh));
_htGlyphs.Add(chr, _Glyphs.Count - 1);
CFonts.Height = h; CFonts.Height = h;
} }
public void UnloadAllGlyphs() public void UnloadAllGlyphs()
{ {
foreach (CGlyph glyph in _Glyphs) foreach (CGlyph glyph in _Glyphs.Values)
{ {
glyph.UnloadTexture(); glyph.UnloadTexture();
} }
@@ -293,6 +292,7 @@ namespace Vocaluxe.Base
{ {
fonts.Dispose(); fonts.Dispose();
fonts = null; fonts = null;
UnloadAllGlyphs();
} }
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
} }
+1 -2
View File
@@ -192,8 +192,7 @@ namespace Vocaluxe.Base
foreach (string folder in Folders) foreach (string folder in Folders)
{ {
string path = Path.Combine(Environment.CurrentDirectory, folder); string path = Path.Combine(Environment.CurrentDirectory, folder);
if (!Directory.Exists(path)) CreateFolder(path);
Directory.CreateDirectory(path);
} }
} }
+28 -51
View File
@@ -27,7 +27,7 @@ namespace Vocaluxe.Lib.Draw
private bool _Run; private bool _Run;
private Direct3D _D3D; private Direct3D _D3D;
private Device _Device; private Device _Device = null;
private PresentParameters _PresentParameters; private PresentParameters _PresentParameters;
private bool _fullscreen = false; private bool _fullscreen = false;
@@ -123,52 +123,37 @@ namespace Vocaluxe.Lib.Draw
//Apply antialiasing and check if antialiasing mode is supported //Apply antialiasing and check if antialiasing mode is supported
#region Antialiasing #region Antialiasing
int quality = 0; int quality = 1;
if (CConfig.AAMode == EAntiAliasingModes.x0) MultisampleType msType;
switch (CConfig.AAMode)
{ {
_PresentParameters.Multisample = MultisampleType.None; case EAntiAliasingModes.x2:
_PresentParameters.MultisampleQuality = quality; msType = MultisampleType.TwoSamples;
break;
case EAntiAliasingModes.x4:
msType = MultisampleType.FourSamples;
break;
case EAntiAliasingModes.x8:
msType = MultisampleType.EightSamples;
break;
case EAntiAliasingModes.x16:
case EAntiAliasingModes.x32://x32 is not supported, fallback to x16
msType = MultisampleType.SixteenSamples;
break;
default:
msType = MultisampleType.None;
break;
} }
else if (CConfig.AAMode == EAntiAliasingModes.x2)
if (!_D3D.CheckDeviceMultisampleType(_D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware, _D3D.Adapters.DefaultAdapter.CurrentDisplayMode.Format, false, msType, out quality))
{ {
if (_D3D.CheckDeviceMultisampleType(_D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware, _D3D.Adapters.DefaultAdapter.CurrentDisplayMode.Format, false, MultisampleType.TwoSamples, out quality)) CLog.LogError("[Direct3D] This AAMode is not supported by this device or driver, fallback to no AA");
{ msType = MultisampleType.None;
_PresentParameters.Multisample = MultisampleType.TwoSamples; quality = 1;
_PresentParameters.MultisampleQuality = quality - 1;
}
else
CLog.LogError("[Direct3D] This AAMode is not supported by this device or driver, fallback to no AA");
}
else if (CConfig.AAMode == EAntiAliasingModes.x4)
{
if (_D3D.CheckDeviceMultisampleType(_D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware, _D3D.Adapters.DefaultAdapter.CurrentDisplayMode.Format, false, MultisampleType.FourSamples, out quality))
{
_PresentParameters.Multisample = MultisampleType.FourSamples;
_PresentParameters.MultisampleQuality = quality - 1;
}
else
CLog.LogError("[Direct3D] This AAMode is not supported by this device or driver, fallback to no AA");
}
else if (CConfig.AAMode == EAntiAliasingModes.x8)
{
if (_D3D.CheckDeviceMultisampleType(_D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware, _D3D.Adapters.DefaultAdapter.CurrentDisplayMode.Format, false, MultisampleType.EightSamples, out quality))
{
_PresentParameters.Multisample = MultisampleType.EightSamples;
_PresentParameters.MultisampleQuality = quality - 1;
}
else
CLog.LogError("[Direct3D] This AAMode is not supported by this device or driver, fallback to no AA");
}
else if (CConfig.AAMode == EAntiAliasingModes.x16 || CConfig.AAMode == EAntiAliasingModes.x32) //x32 is not supported, fallback to x16
{
if (_D3D.CheckDeviceMultisampleType(_D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware, _D3D.Adapters.DefaultAdapter.CurrentDisplayMode.Format, false, MultisampleType.SixteenSamples, out quality))
{
_PresentParameters.Multisample = MultisampleType.SixteenSamples;
_PresentParameters.MultisampleQuality = quality - 1;
}
else
CLog.LogError("[Direct3D] This AAMode is not supported by this device or driver, fallback to no AA");
} }
_PresentParameters.Multisample = msType;
_PresentParameters.MultisampleQuality = quality - 1;
#endregion Antialiasing #endregion Antialiasing
//Apply the VSync configuration //Apply the VSync configuration
@@ -195,14 +180,6 @@ namespace Vocaluxe.Lib.Draw
{ {
_Device = new Device(_D3D, _D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware, Handle, flags, _PresentParameters); _Device = new Device(_D3D, _D3D.Adapters.DefaultAdapter.Adapter, DeviceType.Hardware, Handle, flags, _PresentParameters);
} }
catch (Exception e)
{
MessageBox.Show("Something went wrong during device creating, please check if your DirectX redistributables " +
"and graphic card drivers are up to date. You can download the DirectX runtimes at http://www.microsoft.com/download/en/details.aspx?id=8109",
CSettings.sProgramName, MessageBoxButtons.OK, MessageBoxIcon.Error);
CLog.LogError(e.Message + " - Something went wrong during device creating, please check if your DirectX redistributables and grafic card drivers are up to date. You can download the DirectX runtimes at http://www.microsoft.com/download/en/details.aspx?id=8109");
Environment.Exit(Environment.ExitCode);
}
finally finally
{ {
if (_Device == null || _Device.Disposed) if (_Device == null || _Device.Disposed)
+7 -44
View File
@@ -220,16 +220,16 @@ namespace Vocaluxe.Menu
{ {
if (Elements != null) if (Elements != null)
{ {
for (int i = 0; i < Elements.Length; i++) foreach (string elName in Elements)
{ {
T Element = (T)Activator.CreateInstance(typeof(T), _PartyModeID); T Element = (T)Activator.CreateInstance(typeof(T), _PartyModeID);
if (Element.LoadTheme("//root/" + _ThemeName, _ThemeBackgrounds[i], xmlReader, SkinIndex)) if (Element.LoadTheme("//root/" + _ThemeName, elName, xmlReader, SkinIndex))
{ {
MAddElement(Element, Elements[i]); MAddElement(Element, elName);
} }
else else
{ {
CBase.Log.LogError("Can't load " + typeof(T).Name.Substring(1) + " \"" + Elements[i] + "\" in screen " + _ThemeName); CBase.Log.LogError("Can't load " + typeof(T).Name.Substring(1) + " \"" + elName + "\" in screen " + _ThemeName);
} }
} }
} }
@@ -797,11 +797,7 @@ namespace Vocaluxe.Menu
public virtual bool HandleInputThemeEditor(KeyEvent KeyEvent) public virtual bool HandleInputThemeEditor(KeyEvent KeyEvent)
{ {
_UnsetHighlighted(_Selection); _UnsetHighlighted(_Selection);
if (KeyEvent.KeyPressed) if (!KeyEvent.KeyPressed)
{
}
else
{ {
switch (KeyEvent.Key) switch (KeyEvent.Key)
{ {
@@ -1311,40 +1307,7 @@ namespace Vocaluxe.Menu
private float _GetZValue(int interaction) private float _GetZValue(int interaction)
{ {
switch (_Interactions[interaction].Type) return _GetZValue(_Interactions[interaction]);
{
case EType.TButton:
return _Buttons[_Interactions[interaction].Num].Rect.Z;
case EType.TSelectSlide:
return _SelectSlides[_Interactions[interaction].Num].Rect.Z;
case EType.TStatic:
return _Statics[_Interactions[interaction].Num].Rect.Z;
case EType.TText:
return _Texts[_Interactions[interaction].Num].Z;
case EType.TSongMenu:
return _SongMenus[_Interactions[interaction].Num].Rect.Z;
case EType.TLyric:
return _Lyrics[_Interactions[interaction].Num].Rect.Z;
case EType.TNameSelection:
return _NameSelections[_Interactions[interaction].Num].Rect.Z;
case EType.TEqualizer:
return _Equalizers[_Interactions[interaction].Num].Rect.Z;
case EType.TPlaylist:
return _Playlists[_Interactions[interaction].Num].Rect.Z;
case EType.TParticleEffect:
return _ParticleEffects[_Interactions[interaction].Num].Rect.Z;
}
return CBase.Settings.GetZFar();
} }
private void _NextInteraction() private void _NextInteraction()
@@ -2146,7 +2109,7 @@ namespace Vocaluxe.Menu
// Statics // Statics
CStatic stat = new CStatic(_PartyModeID); CStatic stat = new CStatic(_PartyModeID);
i = 1; i = 1;
while (stat.LoadTheme("//root/" + _ThemeName, "Statics[" + i.ToString(), xmlReader, SkinIndex)) while (stat.LoadTheme("//root/" + _ThemeName, "Static" + i.ToString(), xmlReader, SkinIndex))
{ {
AddStatic(stat); AddStatic(stat);
stat = new CStatic(_PartyModeID); stat = new CStatic(_PartyModeID);
+1 -6
View File
@@ -642,17 +642,12 @@ namespace Vocaluxe.Menu
return false; return false;
} }
public void Draw()
{
Draw(false);
}
public void ForceDraw() public void ForceDraw()
{ {
Draw(true); Draw(true);
} }
public void Draw(bool ForceDraw) public void Draw(bool ForceDraw = false)
{ {
if (!ForceDraw && !Visible && CBase.Settings.GetGameState() != EGameState.EditTheme) if (!ForceDraw && !Visible && CBase.Settings.GetGameState() != EGameState.EditTheme)
return; return;
-3
View File
@@ -317,9 +317,6 @@ namespace Vocaluxe.Menu
CPlaylistSong GetPlaylistSong(int PlaylistID, int SongIndex); CPlaylistSong GetPlaylistSong(int PlaylistID, int SongIndex);
} }
public interface IPlaylists
{
}
[Flags] [Flags]
public enum EModifier public enum EModifier