unix.cpp 9.5 KB

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