app.d 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. import dlangui;
  2. import config;
  3. import variables;
  4. import std.conv;
  5. import std.stdio;
  6. import std.array;
  7. mixin APP_ENTRY_POINT;
  8. /// entry point for dlangui based application
  9. extern (C) int UIAppMain(string[] args) {
  10. // create window
  11. systemSettings = loadSettingsFromConfigFile("conf/settings.conf");
  12. oldSettings = systemSettings;
  13. Window window = Platform.instance.createWindow((systemSettings.windowTitle~" Launcher").to!dstring, null);
  14. window.backgroundColor = 0xFFFFFF;
  15. string redResolution = systemSettings.screenWidth.to!string~"x"~systemSettings.screenHeight.to!string;
  16. writeln(redResolution);
  17. auto vlayout = new VerticalLayout();
  18. // put some widgets into background
  19. static immutable resolutionsAvailable = [
  20. "1920x1080",
  21. "1600x900",
  22. "1366x768",
  23. "1280x720",
  24. "1024x576",
  25. ];
  26. auto makeHandler(int idx) {
  27. return (Widget rb, bool isChecked) {
  28. if (isChecked) {
  29. writeln("selected resolution: ", idx);
  30. }
  31. return true;
  32. };
  33. }
  34. int defaultIndex = -1;
  35. foreach (i, res; resolutionsAvailable) {
  36. if (res == redResolution) {
  37. defaultIndex = cast(int)i;
  38. break;
  39. }
  40. }
  41. for (int i = 0; i < resolutionsAvailable.length; i++) {
  42. radioButtons[i] = new RadioButton(
  43. "resolution" ~ i.to!string,
  44. resolutionsAvailable[i].to!dstring
  45. );
  46. vlayout.addChild(radioButtons[i]);
  47. radioButtons[i].checkChange = makeHandler(i);
  48. if (i == defaultIndex) {
  49. radioButtons[i].checked = true;
  50. }
  51. }
  52. CheckBox fullscreen = new CheckBox();
  53. fullscreen.text = "Fullscreen".to!dstring;
  54. fullscreen.checked = systemSettings.defaultFullscreen;
  55. CheckBox audioState = new CheckBox();
  56. CheckBox gamepadState = new CheckBox();
  57. gamepadState.text = "Gamepad".to!dstring;
  58. gamepadState.checked = systemSettings.gamepadState;
  59. audioState.text = "Audio".to!dstring;
  60. audioState.checked = systemSettings.audioState;
  61. fullscreen.checkChange = (Widget sender, bool isChecked) {
  62. systemSettings.defaultFullscreen = isChecked;
  63. writeln("Fullscreen: ", isChecked ? "on" : "off");
  64. return true;
  65. };
  66. gamepadState.checkChange = (Widget sender, bool isChecked) {
  67. systemSettings.gamepadState = isChecked;
  68. writeln("gamepad state: ", isChecked ? "on" : "off");
  69. return true;
  70. };
  71. audioState.checkChange = (Widget sender, bool isChecked) {
  72. systemSettings.audioState = isChecked;
  73. writeln("Audio state: ", isChecked ? "on" : "off");
  74. return true;
  75. };
  76. Button launchButton = new Button();
  77. launchButton.text = "Launch!".to!dstring;
  78. launchButton.click = (Widget sender) {
  79. string selectedResolution;
  80. for (int i = 0; i < radioButtons.length; i++) {
  81. if (radioButtons[i].checked) {
  82. selectedResolution = resolutionsAvailable[i];
  83. break;
  84. }
  85. }
  86. if (selectedResolution != "") {
  87. auto parts = selectedResolution.split('x');
  88. if (parts.length == 2) {
  89. int newWidth = parts[0].to!int;
  90. int newHeight = parts[1].to!int;
  91. systemSettings.screenWidth = newWidth;
  92. systemSettings.screenHeight = newHeight;
  93. saveSettingsToConfigFile("conf/settings.conf");
  94. writeln("resolution:: ", selectedResolution);
  95. import std.process;
  96. import std.file;
  97. std.process.spawnProcess(std.file.getcwd()~"/himmel-engine");
  98. Platform.instance.closeWindow(window);
  99. }
  100. } else {
  101. writeln("please, select resolution!");
  102. }
  103. return true;
  104. };
  105. vlayout.addChild(fullscreen);
  106. vlayout.addChild(audioState);
  107. vlayout.addChild(gamepadState);
  108. vlayout.addChild(launchButton);
  109. // show window
  110. window.mainWidget = vlayout;
  111. window.show();
  112. // run message loop
  113. return Platform.instance.enterMessageLoop();
  114. }