Einstellungen.cpp 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. #include "Einstellungen.h"
  2. #include <GraphicsApi.h>
  3. #include <InitDatei.h>
  4. #include <MausEreignis.h>
  5. #include "../../Global/Initialisierung.h"
  6. #include "../../Global/Variablen.h"
  7. // Inhalt der Einstellungen Klasse aus Einstellungen.h
  8. // Konstruktor
  9. Einstellungen::Einstellungen(Fenster* zF)
  10. : ReferenceCounter()
  11. {
  12. f = initFenster(zF->getBreite() / 2 - 250,
  13. zF->getHeight() / 2 - 250,
  14. 500,
  15. 500,
  16. Fenster::Style::normal | Fenster::Style::BodyHAlpha
  17. | Fenster::Style::BodyHintergrund | Fenster::Style::TitelHintergrund
  18. | Fenster::Style::TitelHAlpha,
  19. "Einstellungen");
  20. f->removeStyle(Fenster::Style::Sichtbar);
  21. f->setKBgFarbe(0xe0000000);
  22. f->setTBgFarbe(0xe0000000);
  23. f->setSBgFarbe(0xF0000000);
  24. f->setClosingMeParam(this);
  25. f->setClosingMe(einstellungenSchließenME);
  26. TextFeld* gat = initTextFeld(5,
  27. 5,
  28. 300,
  29. 20,
  30. TextFeld::Style::Text,
  31. "Grafik Engine (Neustart erforderlich)");
  32. f->addMember(gat);
  33. AuswahlBox* graphicAPI = initAuswahlBox(5,
  34. 25,
  35. 100,
  36. 20,
  37. AuswahlBox::Style::Normal | AuswahlBox::Style::Hintergrund,
  38. {"Aktuellste", "DirectX 9"});
  39. if (DirectX11::isAvailable()) graphicAPI->addEintrag("DirectX 11");
  40. if (DirectX12::isAvailable()) graphicAPI->addEintrag("DirectX 12");
  41. graphicAPI->setAuswahl(0);
  42. if (userOptions->wertExistiert("GraphicAPI")
  43. && userOptions->zWert("GraphicAPI")->istGleich("DX9"))
  44. graphicAPI->setAuswahl(1);
  45. if (userOptions->wertExistiert("GraphicAPI")
  46. && userOptions->zWert("GraphicAPI")->istGleich("DX11"))
  47. graphicAPI->setAuswahl(2);
  48. if (userOptions->wertExistiert("GraphicAPI")
  49. && userOptions->zWert("GraphicAPI")->istGleich("DX12"))
  50. graphicAPI->setAuswahl(3);
  51. graphicAPI->setEventAktion(
  52. [this](void* p, AuswahlBox* b, int unused, int auswahl) {
  53. userOptions->addWert("GraphicAPI", "BEST");
  54. switch (auswahl)
  55. {
  56. case 1:
  57. userOptions->setWert("GraphicAPI", "DX9");
  58. break;
  59. case 2:
  60. userOptions->setWert("GraphicAPI", "DX11");
  61. break;
  62. case 3:
  63. userOptions->setWert("GraphicAPI", "DX12");
  64. break;
  65. default:
  66. userOptions->setWert("GraphicAPI", "BEST");
  67. break;
  68. }
  69. });
  70. TextFeld* mft
  71. = initTextFeld(5, 50, 200, 20, TextFeld::Style::Text, "Maximale FPS");
  72. f->addMember(mft);
  73. maxFPS = initTextFeld(5,
  74. 70,
  75. 50,
  76. 20,
  77. TextFeld::Style::TextFeld,
  78. userOptions->wertExistiert("MaxFPS")
  79. ? userOptions->zWert("MaxFPS")->getText()
  80. : "30");
  81. maxFPS->setTastaturEreignis(_nurNummernTE);
  82. f->addMember(dynamic_cast<Zeichnung*>(maxFPS->getThis()));
  83. TextFeld* gst = initTextFeld(
  84. 5, 95, 200, 20, TextFeld::Style::Text, "GUI Lautstärke (0 bis 100)");
  85. f->addMember(gst);
  86. guiSound = initTextFeld(5,
  87. 115,
  88. 50,
  89. 20,
  90. TextFeld::Style::TextFeld,
  91. userOptions->wertExistiert("GUISound")
  92. ? userOptions->zWert("GUISound")->getText()
  93. : "100");
  94. guiSound->setTastaturEreignis(_nurNummernTE);
  95. f->addMember(dynamic_cast<Zeichnung*>(guiSound->getThis()));
  96. TextFeld* mt = initTextFeld(255,
  97. 5,
  98. 200,
  99. 20,
  100. TextFeld::Style::Text,
  101. "Monitor (Neustart erforderlich)");
  102. f->addMember(mt);
  103. AuswahlBox* monitorAuswahl = initAuswahlBox(255,
  104. 25,
  105. 200,
  106. 20,
  107. AuswahlBox::Style::Normal | AuswahlBox::Style::Hintergrund,
  108. {});
  109. Monitor m = getMonitor(0);
  110. int index = 0;
  111. do
  112. {
  113. monitorAuswahl->addEintrag(Text("Monitor ") + ++index + " (" + m.breite
  114. + "x" + m.height + ")");
  115. m = getMonitor(index);
  116. } while (m.existiert);
  117. if (userOptions->wertExistiert("Monitor"))
  118. monitorAuswahl->setAuswahl((int)*userOptions->zWert("Monitor"));
  119. monitorAuswahl->setEventAktion(
  120. [this](void* p, AuswahlBox* b, int unused, int auswahl) {
  121. if (!userOptions->wertExistiert("Monitor"))
  122. userOptions->addWert("Monitor", Text(auswahl));
  123. else
  124. userOptions->setWert("Monitor", Text(auswahl));
  125. Monitor m = getMonitor(auswahl);
  126. if (!userOptions->wertExistiert("ScreenWidth"))
  127. userOptions->addWert("ScreenWidth", Text(m.breite));
  128. else
  129. userOptions->setWert("ScreenWidth", Text(m.breite));
  130. if (!userOptions->wertExistiert("ScreenWidth"))
  131. userOptions->addWert("ScreenHeight", Text(m.height));
  132. else
  133. userOptions->setWert("ScreenHeight", Text(m.height));
  134. breite->setText(Text(m.breite));
  135. height->setText(Text(m.height));
  136. });
  137. TextFeld* at = initTextFeld(255,
  138. 50,
  139. 200,
  140. 20,
  141. TextFeld::Style::Text,
  142. "Auflösung (Neustart erforderlich)");
  143. f->addMember(at);
  144. breite = initTextFeld(255,
  145. 70,
  146. 50,
  147. 20,
  148. TextFeld::Style::TextFeld,
  149. userOptions->wertExistiert("ScreenWidth")
  150. ? *userOptions->zWert("ScreenWidth")
  151. : Text(getMonitor(userOptions->wertExistiert("Monitor")
  152. ? (int)*userOptions->zWert("Monitor")
  153. : 0)
  154. .breite));
  155. height = initTextFeld(312,
  156. 70,
  157. 50,
  158. 20,
  159. TextFeld::Style::TextFeld,
  160. userOptions->wertExistiert("ScreenHeight")
  161. ? *userOptions->zWert("ScreenHeight")
  162. : Text(getMonitor(userOptions->wertExistiert("Monitor")
  163. ? (int)*userOptions->zWert("Monitor")
  164. : 0)
  165. .height));
  166. breite->setTastaturEreignis(_nurNummernTE);
  167. height->setTastaturEreignis(_nurNummernTE);
  168. f->addMember(dynamic_cast<Zeichnung*>(breite->getThis()));
  169. f->addMember(initTextFeld(305, 70, 5, 20, TextFeld::Style::Text, "x"));
  170. f->addMember(dynamic_cast<Zeichnung*>(height->getThis()));
  171. ok = initKnopf(390, 450, 100, 20, Knopf::Style::Sichtbar, "Ok");
  172. ok->setMausEreignisParameter(this);
  173. ok->setMausEreignis(einstellungenOkME);
  174. f->addMember(dynamic_cast<Zeichnung*>(ok->getThis()));
  175. // add AuswahlBoxen
  176. f->addMember(graphicAPI);
  177. f->addMember(monitorAuswahl);
  178. zF->addMember(dynamic_cast<Zeichnung*>(f->getThis()));
  179. }
  180. // Destruktor
  181. Einstellungen::~Einstellungen()
  182. {
  183. maxFPS->release();
  184. guiSound->release();
  185. breite->release();
  186. height->release();
  187. f->release();
  188. ok->release();
  189. }
  190. // nicht constant
  191. void Einstellungen::setSichtbar()
  192. {
  193. f->setStyle(
  194. Fenster::Style::Sichtbar, f->hatStyleNicht(Fenster::Style::Sichtbar));
  195. }
  196. bool Einstellungen::closeME(MausEreignis& me)
  197. {
  198. if (me.id == ME_RLinks) f->removeStyle(Fenster::Style::Sichtbar);
  199. return 1;
  200. }
  201. bool Einstellungen::okME(MausEreignis& me)
  202. {
  203. if (me.id == ME_RLinks)
  204. {
  205. int fps = (int)*maxFPS->zText();
  206. int sound = (int)*guiSound->zText();
  207. int wi = (int)*breite->zText();
  208. int hi = (int)*height->zText();
  209. if (fps > 0 && sound >= 0 && sound <= 100 && wi > 0 && hi > 0)
  210. {
  211. f->removeStyle(Fenster::Style::Sichtbar);
  212. uiFactory.initParam.bildschirm->lock();
  213. if (!userOptions->wertExistiert("MaxFPS"))
  214. userOptions->addWert("MaxFPS", maxFPS->zText()->getText());
  215. else
  216. userOptions->setWert("MaxFPS", maxFPS->zText()->getText());
  217. if (!userOptions->wertExistiert("GUISound"))
  218. userOptions->addWert("GUISound", guiSound->zText()->getText());
  219. else
  220. userOptions->setWert("GUISound", guiSound->zText()->getText());
  221. if (!userOptions->wertExistiert("ScreenWidth"))
  222. userOptions->addWert("ScreenWidth", Text(wi));
  223. else
  224. userOptions->setWert("ScreenWidth", Text(wi));
  225. if (!userOptions->wertExistiert("ScreenHeight"))
  226. userOptions->addWert("ScreenHeight", Text(hi));
  227. else
  228. userOptions->setWert("ScreenHeight", Text(hi));
  229. uiFactory.initParam.bildschirm->unlock();
  230. userOptions->speichern();
  231. }
  232. }
  233. return 1;
  234. }
  235. // Ereignisse
  236. bool einstellungenSchließenME(void* p, void* obj, MausEreignis me)
  237. {
  238. if (!p) return 1;
  239. return ((Einstellungen*)p)->closeME(me);
  240. }
  241. bool einstellungenOkME(void* p, void* obj, MausEreignis me)
  242. {
  243. if (!p) return 1;
  244. return ((Einstellungen*)p)->okME(me);
  245. }