unix.cpp 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "../../global.h"
  5. #include "../../util.h"
  6. #include "../../palcfg.h"
  7. #ifndef PAL_NO_LAUNCH_UI
  8. #include <FL/Fl.H>
  9. #include <FL/Fl_Window.H>
  10. #include <FL/Fl_Box.H>
  11. #include <FL/Fl_Button.H>
  12. #include <FL/Fl_Check_Button.H>
  13. #include <FL/Fl_Radio_Round_Button.H>
  14. #include <FL/Fl_Hor_Value_Slider.H>
  15. #include <FL/Fl_Input.H>
  16. #include <FL/Fl_Int_Input.H>
  17. #include <FL/Fl_Choice.H>
  18. #ifdef PAL_HAS_NATIVEMIDI
  19. #define MUSIC_MIN MUSIC_MIDI
  20. #else
  21. #define MUSIC_MIN MUSIC_RIX
  22. #endif
  23. struct {
  24. Fl_Input* gamepath;
  25. Fl_Radio_Round_Button* cht;
  26. Fl_Radio_Round_Button* chs;
  27. Fl_Input* msgfile;
  28. Fl_Check_Button* font;
  29. Fl_Check_Button* touch;
  30. Fl_Check_Button* aspect;
  31. Fl_Check_Button* fullscreen;
  32. Fl_Choice* cd;
  33. Fl_Choice* bgm;
  34. Fl_Choice* opl;
  35. Fl_Int_Input* samplerate;
  36. Fl_Check_Button* stereo;
  37. Fl_Int_Input* oplrate;
  38. Fl_Check_Button* surround;
  39. Fl_Int_Input* buffer;
  40. Fl_Hor_Value_Slider* quality;
  41. Fl_Hor_Value_Slider* music;
  42. Fl_Hor_Value_Slider* sound;
  43. } gWidgets;
  44. struct {
  45. const char* title;
  46. const char* language;
  47. const char* display;
  48. const char* audio;
  49. const char* gamepath;
  50. const char* cht;
  51. const char* chs;
  52. const char* msgfile;
  53. const char* font;
  54. const char* touch;
  55. const char* aspect;
  56. const char* fullscreen;
  57. const char* cd;
  58. const char* bgm;
  59. const char* opl;
  60. const char* samplerate;
  61. const char* stereo;
  62. const char* oplrate;
  63. const char* surround;
  64. const char* buffer;
  65. const char* quality;
  66. const char* musvol;
  67. const char* sndvol;
  68. const char* exit;
  69. const char* launch;
  70. const char* def;
  71. } gLabels[3] = {
  72. { "SDLPAL Launcher", "Game language", "Display", "Audio", "Game resource path:",
  73. "&Traditional Chinese", "&Simplified Chinese", "Message file:", "Use &embedded font",
  74. "Use touc&h overlay", "&Keep aspect ratio", "&Full screen", "&CD type:", "&BGM type:",
  75. "&OPL type:", "Sample rate:", "Ste&reo", "OPL rate:", "Surround O&PL", "Buffer:",
  76. "Quality:", "Music volume:", "Sound volume:", "E&xit", "&Launch game", "&Default" },
  77. { "SDLPAL 启动器", "游戏语言设置", "显示设置", "音频设置", "游戏资源目录:",
  78. "繁体中文(&T)", "简体中文(&S)", "语言文件:", "使用游戏资源内嵌字体(&E)",
  79. "启用触屏辅助(&H)", "保持纵横比(&K)", "全屏模式(&F)", "&CD 音源:", "&BGM 音源:",
  80. "&OPL 类型:", "采样率:", "立体声(&R)", "OPL 采样率:", "环绕声 O&PL", "缓冲区:",
  81. "质量:", "音乐音量:", "音效音量:", "退出(&X)", "启动游戏(&L)", "默认设置(&D)" },
  82. { "SDLPAL 啟動器", "遊戲語言設置", "顯示設定", "音訊設定", "遊戲資源目錄:",
  83. "繁體中文(&T)", "簡體中文(&S)", "語言檔:", "使用遊戲資源內嵌字體(&E)",
  84. "啟用觸屏輔助(&H)", "保持縱橫比(&K)", "全屏模式(&F)", "&CD 音源:", "&BGM 音源:",
  85. "&OPL 類型:", "取樣速率:", "立體聲(&R)", "OPL 取樣速率:", "環繞聲 O&PL", "緩衝區:",
  86. "品質:", "音樂音量:", "音效音量:", "退出(&X)", "啟動遊戲(&L)", "默認設定(&D)" },
  87. };
  88. void InitControls()
  89. {
  90. char buffer[64];
  91. gWidgets.gamepath->value(gConfig.pszGamePath);
  92. gWidgets.cht->value(gConfig.uCodePage == CP_BIG5 ? 1 : 0);
  93. gWidgets.chs->value(gConfig.uCodePage == CP_GBK ? 1 : 0);
  94. gWidgets.msgfile->value(gConfig.pszMsgFile);
  95. gWidgets.font->value(gConfig.fUseEmbeddedFonts ? 1 : 0);
  96. gWidgets.touch->value(gConfig.fUseTouchOverlay ? 1 : 0);
  97. #if SDL_VERSION_ATLEAST(2,0,0)
  98. gWidgets.aspect->value(gConfig.fKeepAspectRatio ? 1 : 0);
  99. #endif
  100. gWidgets.fullscreen->value(gConfig.fFullScreen ? 1 : 0);
  101. gWidgets.cd->value(gConfig.eCDType - MUSIC_MP3);
  102. gWidgets.bgm->value(gConfig.eMusicType - MUSIC_MIN);
  103. gWidgets.stereo->value(gConfig.iAudioChannels == 2 ? 1 : 0);
  104. sprintf(buffer, "%d", gConfig.iSampleRate); gWidgets.samplerate->value(buffer);
  105. gWidgets.opl->value(gConfig.eOPLType);
  106. sprintf(buffer, "%d", gConfig.iOPLSampleRate); gWidgets.oplrate->value(buffer);
  107. gWidgets.surround->value(gConfig.fUseSurroundOPL ? 1 : 0);
  108. sprintf(buffer, "%d", gConfig.wAudioBufferSize); gWidgets.buffer->value(buffer);
  109. gWidgets.quality->value(gConfig.iResampleQuality);
  110. gWidgets.music->value(gConfig.iMusicVolume);
  111. gWidgets.sound->value(gConfig.iSoundVolume);
  112. }
  113. void SaveControls()
  114. {
  115. free(gConfig.pszGamePath);
  116. gConfig.pszGamePath = strlen(gWidgets.gamepath->value()) ? strdup(gWidgets.gamepath->value()) : nullptr;
  117. free(gConfig.pszMsgFile);
  118. gConfig.pszMsgFile = strlen(gWidgets.msgfile->value()) ? strdup(gWidgets.msgfile->value()) : nullptr;
  119. gConfig.uCodePage = (gWidgets.cht->value() ? CP_BIG5 : CP_GBK);
  120. gConfig.fUseEmbeddedFonts = gWidgets.font->value();
  121. gConfig.fUseTouchOverlay = gWidgets.touch->value();
  122. #if SDL_VERSION_ATLEAST(2,0,0)
  123. gConfig.fKeepAspectRatio = gWidgets.aspect->value();
  124. #endif
  125. gConfig.fFullScreen = gWidgets.fullscreen->value();
  126. gConfig.eCDType = (MUSICTYPE)(gWidgets.cd->value() + MUSIC_MP3);
  127. gConfig.eMusicType = (MUSICTYPE)(gWidgets.bgm->value() + MUSIC_MIN);
  128. gConfig.iAudioChannels = gWidgets.stereo->value() ? 2 : 1;
  129. gConfig.iSampleRate = atoi(gWidgets.samplerate->value());
  130. gConfig.eOPLType = (OPLTYPE)gWidgets.opl->value();
  131. gConfig.iOPLSampleRate = atoi(gWidgets.oplrate->value());
  132. gConfig.fUseSurroundOPL = gWidgets.surround->value();
  133. gConfig.wAudioBufferSize = atoi(gWidgets.buffer->value());
  134. gConfig.iResampleQuality = (int)gWidgets.quality->value();
  135. gConfig.iMusicVolume = (int)gWidgets.music->value();
  136. gConfig.iSoundVolume = (int)gWidgets.sound->value();
  137. gConfig.fLaunchSetting = FALSE;
  138. }
  139. int GetLanguage()
  140. {
  141. auto lang = getenv("LANG");
  142. if (!lang) return 0;
  143. if (strncasecmp(lang, "zh_", 3) == 0)
  144. {
  145. if (strncasecmp(lang + 3, "hans", 4) == 0 || strncasecmp(lang + 3, "CN", 2) == 0 || strncasecmp(lang + 3, "SG", 2) == 0)
  146. return 1;
  147. else
  148. return 2;
  149. }
  150. else
  151. return 0;
  152. }
  153. Fl_Window* InitWindow()
  154. {
  155. int lang = GetLanguage();
  156. Fl_Window* window = new Fl_Window(640, 400, gLabels[lang].title);
  157. (gWidgets.gamepath = new Fl_Input(160, 9, 475, 22, gLabels[lang].gamepath))->value(gConfig.pszGamePath);
  158. (new Fl_Box(FL_BORDER_BOX, 5, 70, 310, 100, gLabels[lang].language))->align(FL_ALIGN_TOP);
  159. gWidgets.cht = new Fl_Radio_Round_Button(10, 80, 160, 20, gLabels[lang].cht);
  160. gWidgets.chs = new Fl_Radio_Round_Button(10, 110, 160, 20, gLabels[lang].chs);
  161. (gWidgets.msgfile = new Fl_Input(109, 139, 196, 22, gLabels[lang].msgfile))->value(gConfig.pszMsgFile);
  162. (new Fl_Box(FL_BORDER_BOX, 325, 70, 310, 100, gLabels[lang].display))->align(FL_ALIGN_TOP);
  163. gWidgets.font = new Fl_Check_Button(330, 80, 160, 20, gLabels[lang].font);
  164. gWidgets.touch = new Fl_Check_Button(330, 110, 160, 20, gLabels[lang].touch);
  165. gWidgets.aspect = new Fl_Check_Button(330, 140, 160, 20, gLabels[lang].aspect);
  166. gWidgets.fullscreen = new Fl_Check_Button(520, 140, 120, 20, gLabels[lang].fullscreen);
  167. (new Fl_Box(FL_BORDER_BOX, 5, 210, 630, 130, gLabels[lang].audio))->align(FL_ALIGN_TOP);
  168. (gWidgets.cd = new Fl_Choice(84, 219, lang ? 100 : 120, 22, gLabels[lang].cd))->add("MP3|OGG");
  169. (gWidgets.bgm = new Fl_Choice(285, 219, 60, 22, gLabels[lang].bgm))->add( va("%s%s",(PAL_HAS_NATIVEMIDI ? "MIDI|" : ""), "RIX|MP3|OGG") );
  170. gWidgets.stereo = new Fl_Check_Button(365, 220, 60, 20, gLabels[lang].stereo);
  171. gWidgets.samplerate = new Fl_Int_Input(570, 219, 60, 22, gLabels[lang].samplerate);
  172. (gWidgets.opl = new Fl_Choice(84, 249, lang ? 100 : 120, 22, gLabels[lang].opl))->add("DOSBOX|MAME|DOSBOXNEW");
  173. gWidgets.oplrate = new Fl_Int_Input(285, 249, 60, 22, gLabels[lang].oplrate);
  174. gWidgets.surround = new Fl_Check_Button(365, 250, 60, 20, gLabels[lang].surround);
  175. gWidgets.buffer = new Fl_Int_Input(570, 249, 60, 22, gLabels[lang].buffer);
  176. gWidgets.quality = new Fl_Hor_Value_Slider(72, 279, 180, 22, gLabels[lang].quality);
  177. gWidgets.quality->align(FL_ALIGN_LEFT);
  178. gWidgets.quality->bounds(0, 4);
  179. gWidgets.quality->precision(0);
  180. gWidgets.music = new Fl_Hor_Value_Slider(380, 279, 250, 22, gLabels[lang].musvol);
  181. gWidgets.music->align(FL_ALIGN_LEFT);
  182. gWidgets.music->bounds(0, 100);
  183. gWidgets.music->precision(0);
  184. gWidgets.sound = new Fl_Hor_Value_Slider(380, 309, 250, 22, gLabels[lang].sndvol);
  185. gWidgets.sound->align(FL_ALIGN_LEFT);
  186. gWidgets.sound->bounds(0, 100);
  187. gWidgets.sound->precision(0);
  188. (new Fl_Button(5, 370, 120, 24, gLabels[lang].exit))->callback([](Fl_Widget* ctrl, void* window) {
  189. if (ctrl->when() == FL_WHEN_RELEASE)
  190. static_cast<Fl_Window*>(window)->hide();
  191. }, window);
  192. (new Fl_Button(260, 370, 120, 24, gLabels[lang].launch))->callback([](Fl_Widget* ctrl, void* window) {
  193. if (ctrl->when() == FL_WHEN_RELEASE) {
  194. SaveControls();
  195. PAL_SaveConfig();
  196. static_cast<Fl_Window*>(window)->hide();
  197. }
  198. }, window);
  199. (new Fl_Button(515, 370, 120, 24, gLabels[lang].def))->callback([](Fl_Widget*) { PAL_LoadConfig(FALSE); InitControls(); });
  200. window->end();
  201. InitControls();
  202. return window;
  203. }
  204. #endif
  205. BOOL
  206. UTIL_GetScreenSize(
  207. DWORD *pdwScreenWidth,
  208. DWORD *pdwScreenHeight
  209. )
  210. {
  211. return pdwScreenWidth && pdwScreenHeight && *pdwScreenWidth && *pdwScreenHeight;
  212. }
  213. BOOL
  214. UTIL_IsAbsolutePath(
  215. LPCSTR lpszFileName
  216. )
  217. {
  218. return lpszFileName && *lpszFileName == '/';
  219. }
  220. INT
  221. UTIL_Platform_Init(
  222. int argc,
  223. char* argv[]
  224. )
  225. {
  226. #if !defined(UNIT_TEST) && !defined(PAL_NO_LAUNCH_UI)
  227. if (gConfig.fLaunchSetting)
  228. {
  229. Fl_Window *window = InitWindow();
  230. window->show(argc, argv);
  231. Fl::run();
  232. Fl::flush();
  233. delete window;
  234. }
  235. #else
  236. gConfig.fLaunchSetting = FALSE;
  237. #endif
  238. return 0;
  239. }
  240. VOID
  241. UTIL_Platform_Quit(
  242. VOID
  243. )
  244. {
  245. }