unix.cpp 9.1 KB

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