MainPage.xaml.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. //
  2. // MainPage.xaml.cpp
  3. // MainPage 类的实现。
  4. //
  5. #include "pch.h"
  6. #include "MainPage.xaml.h"
  7. #include "../SDLPal.Common/StringHelper.h"
  8. #include "../SDLPal.Common/AsyncHelper.h"
  9. #include "../../global.h"
  10. using namespace SDLPal;
  11. using namespace Platform;
  12. using namespace Windows::Foundation;
  13. using namespace Windows::Foundation::Collections;
  14. using namespace Windows::UI::Xaml;
  15. using namespace Windows::UI::Xaml::Controls;
  16. using namespace Windows::UI::Xaml::Controls::Primitives;
  17. using namespace Windows::UI::Xaml::Data;
  18. using namespace Windows::UI::Xaml::Input;
  19. using namespace Windows::UI::Xaml::Media;
  20. using namespace Windows::UI::Xaml::Navigation;
  21. MainPage::MainPage()
  22. {
  23. InitializeComponent();
  24. static_cast<App^>(Application::Current)->SetMainPage(this);
  25. LoadControlContents();
  26. }
  27. void SDLPal::MainPage::SetPath(Windows::Storage::StorageFolder^ folder)
  28. {
  29. Windows::Storage::AccessCache::StorageApplicationPermissions::MostRecentlyUsedList->Add(folder, folder->Path);
  30. tbGamePath->Text = folder->Path;
  31. }
  32. void SDLPal::MainPage::LoadControlContents()
  33. {
  34. if (gConfig.pszGamePath) tbGamePath->Text = ConvertString(gConfig.pszGamePath);
  35. if (gConfig.pszMsgFile) tbMsgFile->Text = ConvertString(gConfig.pszMsgFile);
  36. tsLanguage->IsOn = (gConfig.uCodePage == CP_GBK);
  37. tsIsDOS->IsOn = (gConfig.fIsWIN95 == FALSE);
  38. tsUseEmbedFont->IsOn = (gConfig.fUseEmbeddedFonts == TRUE);
  39. tsKeepAspect->IsOn = (gConfig.fKeepAspectRatio == TRUE);
  40. tsStereo->IsOn = (gConfig.iAudioChannels == 2);
  41. tsSurroundOPL->IsOn = (gConfig.fUseSurroundOPL == TRUE);
  42. tsTouchOverlay->IsOn = (gConfig.fUseTouchOverlay == TRUE);
  43. slVolume->Value = gConfig.iVolume;
  44. slQuality->Value = gConfig.iResampleQuality;
  45. cbCD->SelectedIndex = (gConfig.eCDType == MUSIC_MP3) ? 0 : 1;
  46. if (gConfig.eMusicType == MUSIC_OGG)
  47. cbBGM->SelectedIndex = 2;
  48. else if (gConfig.eMusicType == MUSIC_MP3)
  49. cbBGM->SelectedIndex = 1;
  50. else
  51. cbBGM->SelectedIndex = 0;
  52. cbOPL->SelectedIndex = (int)gConfig.eOPLType;
  53. if (gConfig.iSampleRate <= 11025)
  54. cbSampleRate->SelectedIndex = 0;
  55. else if (gConfig.iSampleRate <= 22050)
  56. cbSampleRate->SelectedIndex = 1;
  57. else
  58. cbSampleRate->SelectedIndex = 2;
  59. if (gConfig.wAudioBufferSize <= 512)
  60. cbAudioBuffer->SelectedIndex = 0;
  61. else if (gConfig.wAudioBufferSize == 1024)
  62. cbAudioBuffer->SelectedIndex = 1;
  63. else if (gConfig.wAudioBufferSize == 2048)
  64. cbAudioBuffer->SelectedIndex = 2;
  65. else
  66. cbAudioBuffer->SelectedIndex = 3;
  67. if (gConfig.iOPLSampleRate <= 12429)
  68. cbOPLSR->SelectedIndex = 0;
  69. else if (gConfig.iSampleRate <= 24858)
  70. cbOPLSR->SelectedIndex = 1;
  71. else
  72. cbOPLSR->SelectedIndex = 2;
  73. tsUseEmbedFont->Visibility = tsIsDOS->IsOn ? Windows::UI::Xaml::Visibility::Visible : Windows::UI::Xaml::Visibility::Collapsed;
  74. }
  75. void SDLPal::MainPage::SaveControlContents()
  76. {
  77. std::wstring path;
  78. if (gConfig.pszGamePath) free(gConfig.pszGamePath);
  79. path.assign(tbGamePath->Text->Data());
  80. if (path.back() != '\\') path.append(L"\\");
  81. gConfig.pszGamePath = strdup(ConvertString(path).c_str());
  82. if (gConfig.pszMsgFile) { free(gConfig.pszMsgFile); gConfig.pszMsgFile = NULL; }
  83. gConfig.pszMsgFile = (tbMsgFile->Text->Length() > 0) ? strdup(ConvertString(tbMsgFile->Text).c_str()) : nullptr;
  84. gConfig.fIsWIN95 = tsIsDOS->IsOn ? FALSE : TRUE;
  85. gConfig.fUseEmbeddedFonts = tsUseEmbedFont->IsOn ? TRUE : FALSE;
  86. gConfig.fKeepAspectRatio = tsKeepAspect->IsOn ? TRUE : FALSE;
  87. gConfig.iAudioChannels = tsStereo->IsOn ? 2 : 1;
  88. gConfig.fUseSurroundOPL = tsSurroundOPL->IsOn ? TRUE : FALSE;
  89. gConfig.fUseTouchOverlay = tsTouchOverlay->IsOn ? TRUE : FALSE;
  90. gConfig.iVolume = (int)slVolume->Value;
  91. gConfig.iResampleQuality = (int)slQuality->Value;
  92. gConfig.uCodePage = tsLanguage->IsOn ? CP_GBK : CP_BIG5;
  93. gConfig.eCDType = (MUSICTYPE)(MUSIC_MP3 + cbCD->SelectedIndex);
  94. gConfig.eMusicType = (cbBGM->SelectedIndex >= 1) ? (MUSICTYPE)(MUSIC_MP3 + cbBGM->SelectedIndex) : MUSIC_RIX;
  95. gConfig.eOPLType = (OPLTYPE)cbOPL->SelectedIndex;
  96. gConfig.iSampleRate = wcstoul(static_cast<Platform::String^>(static_cast<ComboBoxItem^>(cbSampleRate->SelectedItem)->Content)->Data(), nullptr, 10);
  97. gConfig.iOPLSampleRate = wcstoul(static_cast<Platform::String^>(static_cast<ComboBoxItem^>(cbOPLSR->SelectedItem)->Content)->Data(), nullptr, 10);
  98. gConfig.wAudioBufferSize = wcstoul(static_cast<Platform::String^>(static_cast<ComboBoxItem^>(cbAudioBuffer->SelectedItem)->Content)->Data(), nullptr, 10);
  99. }
  100. void SDLPal::MainPage::btnBrowse_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
  101. {
  102. auto picker = ref new Windows::Storage::Pickers::FolderPicker();
  103. picker->PickFolderAndContinue();
  104. }
  105. void SDLPal::MainPage::tsIsDOS_Toggled(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
  106. {
  107. if (tsIsDOS->IsOn)
  108. {
  109. tsLanguage->IsOn = false;
  110. tsLanguage->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
  111. tsUseEmbedFont->Visibility = Windows::UI::Xaml::Visibility::Visible;
  112. }
  113. else
  114. {
  115. tsLanguage->IsOn = (gConfig.uCodePage == CP_GBK);
  116. tsLanguage->Visibility = Windows::UI::Xaml::Visibility::Visible;
  117. tsUseEmbedFont->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
  118. }
  119. }
  120. void SDLPal::MainPage::cbBGM_SelectionChanged(Platform::Object^ sender, Windows::UI::Xaml::Controls::SelectionChangedEventArgs^ e)
  121. {
  122. auto visibility = (cbBGM->SelectedIndex == 0) ? Windows::UI::Xaml::Visibility::Visible : Windows::UI::Xaml::Visibility::Collapsed;
  123. cbOPL->Visibility = visibility;
  124. cbOPLSR->Visibility = visibility;
  125. tsSurroundOPL->Visibility = visibility;
  126. }
  127. void SDLPal::MainPage::btnReset_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
  128. {
  129. PAL_LoadConfig(FALSE);
  130. LoadControlContents();
  131. }
  132. void SDLPal::MainPage::btnFinish_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
  133. {
  134. auto loader = ref new Windows::ApplicationModel::Resources::ResourceLoader();
  135. if (tbGamePath->Text->Length() > 0)
  136. {
  137. SaveControlContents();
  138. auto handler = ref new Windows::UI::Popups::UICommandInvokedHandler(this, &MainPage::CloseUICommandHandler);
  139. auto dlg = ref new Windows::UI::Popups::MessageDialog(loader->GetString("MBExitContent"));
  140. dlg->Commands->Append(ref new Windows::UI::Popups::UICommand(loader->GetString("MBYes"), handler, safe_cast<Platform::Object^>(0)));
  141. dlg->Commands->Append(ref new Windows::UI::Popups::UICommand(loader->GetString("MBNo"), handler, safe_cast<Platform::Object^>(1)));
  142. dlg->ShowAsync();
  143. }
  144. else
  145. {
  146. (ref new Windows::UI::Popups::MessageDialog(loader->GetString("MBEmptyContent")))->ShowAsync();
  147. }
  148. }
  149. void SDLPal::MainPage::CloseUICommandHandler(Windows::UI::Popups::IUICommand^ command)
  150. {
  151. gConfig.fLaunchSetting = ((int)command->Id == 0);
  152. PAL_SaveConfig();
  153. Application::Current->Exit();
  154. }