ViewModel.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #if UNITY_5_3_OR_NEWER
  2. #define NOESIS
  3. using Noesis;
  4. using System.Collections.ObjectModel;
  5. #else
  6. using System;
  7. using System.Windows;
  8. using System.Collections.ObjectModel;
  9. #endif
  10. namespace Localization
  11. {
  12. public class Language
  13. {
  14. public string Name { get; set; }
  15. public ResourceDictionary Resources { get; set; }
  16. }
  17. public class ViewModel : NotifyPropertyChangedBase
  18. {
  19. public ViewModel()
  20. {
  21. Languages = new ObservableCollection<Language>()
  22. {
  23. new Language
  24. {
  25. Name = "English",
  26. Resources = (ResourceDictionary)GUI.LoadXaml("Language-en.xaml")
  27. },
  28. new Language
  29. {
  30. Name = "Français",
  31. Resources = (ResourceDictionary)GUI.LoadXaml("Language-fr.xaml")
  32. },
  33. new Language
  34. {
  35. Name = "日本語",
  36. Resources = (ResourceDictionary)GUI.LoadXaml("Language-jp.xaml")
  37. }
  38. };
  39. SelectedLanguage = Languages[0];
  40. SoundLevel = 100.0f;
  41. MusicLevel = 80.0f;
  42. }
  43. public ObservableCollection<Language> Languages { get; private set; }
  44. private Language _selectedLanguage;
  45. public Language SelectedLanguage
  46. {
  47. get { return _selectedLanguage; }
  48. set
  49. {
  50. if (_selectedLanguage != value)
  51. {
  52. _selectedLanguage = value;
  53. OnPropertyChanged("SelectedLanguage");
  54. }
  55. }
  56. }
  57. private float _soundLevel;
  58. public float SoundLevel
  59. {
  60. get { return _soundLevel; }
  61. set
  62. {
  63. if (_soundLevel != value)
  64. {
  65. _soundLevel = value;
  66. OnPropertyChanged("SoundLevel");
  67. }
  68. }
  69. }
  70. private float _musicLevel;
  71. public float MusicLevel
  72. {
  73. get { return _musicLevel; }
  74. set
  75. {
  76. if (_musicLevel != value)
  77. {
  78. _musicLevel = value;
  79. OnPropertyChanged("MusicLevel");
  80. }
  81. }
  82. }
  83. #if !NOESIS
  84. private static class GUI
  85. {
  86. public static object LoadXaml(string filename)
  87. {
  88. return Application.LoadComponent(new Uri("/Localization;component/./" + filename, UriKind.RelativeOrAbsolute));
  89. }
  90. }
  91. #endif
  92. }
  93. }