Einstellungen.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. #include "Einstellungen.h"
  2. #include <MausEreignis.h>
  3. #include <GraphicsApi.h>
  4. #include <InitDatei.h>
  5. #include "../../Global/Variablen.h"
  6. #include "../../Global/Initialisierung.h"
  7. // Inhalt der Einstellungen Klasse aus Einstellungen.h
  8. // Konstruktor
  9. Einstellungen::Einstellungen( Schrift *zSchrift, Fenster *zF )
  10. {
  11. f = initFenster( zF->getBreite() / 2 - 250, zF->getHeight() / 2 - 250, 500, 500, zSchrift,
  12. Fenster::Style::normal | Fenster::Style::BodyHAlpha | Fenster::Style::BodyHintergrund |
  13. Fenster::Style::TitelHintergrund | Fenster::Style::TitelHAlpha, "Einstellungen" );
  14. f->removeStyle( Fenster::Style::Sichtbar );
  15. f->setKBgFarbe( 0xe0000000 );
  16. f->setTBgFarbe( 0xe0000000 );
  17. f->setSBgFarbe( 0xF0000000 );
  18. f->setClosingMeParam( this );
  19. f->setClosingMe( einstellungenSchließenME );
  20. TextFeld *gat = initTextFeld( 5, 5, 300, 20, zSchrift, TextFeld::Style::Text, "Grafik Engine (Neustart erforderlich)" );
  21. f->addMember( gat );
  22. AuswahlBox *graphicAPI = initAuswahlBox( 5, 25, 100, 20, zSchrift, AuswahlBox::Style::Normal | AuswahlBox::Style::Hintergrund, { "Aktuellste", "DirectX 9" } );
  23. if( DirectX11::isAvailable() )
  24. graphicAPI->addEintrag( "DirectX 11" );
  25. if( DirectX12::isAvailable() )
  26. graphicAPI->addEintrag( "DirectX 12" );
  27. graphicAPI->setAuswahl( 0 );
  28. if( userOptions->wertExistiert( "GraphicAPI" ) && userOptions->zWert( "GraphicAPI" )->istGleich( "DX9" ) )
  29. graphicAPI->setAuswahl( 1 );
  30. if( userOptions->wertExistiert( "GraphicAPI" ) && userOptions->zWert( "GraphicAPI" )->istGleich( "DX11" ) )
  31. graphicAPI->setAuswahl( 2 );
  32. if( userOptions->wertExistiert( "GraphicAPI" ) && userOptions->zWert( "GraphicAPI" )->istGleich( "DX12" ) )
  33. graphicAPI->setAuswahl( 3 );
  34. graphicAPI->setEventAktion( [ this ]( void *p, AuswahlBox * b, int unused, int auswahl )
  35. {
  36. userOptions->addWert( "GraphicAPI", "BEST" );
  37. switch( auswahl )
  38. {
  39. case 1:
  40. userOptions->setWert( "GraphicAPI", "DX9" );
  41. break;
  42. case 2:
  43. userOptions->setWert( "GraphicAPI", "DX11" );
  44. break;
  45. case 3:
  46. userOptions->setWert( "GraphicAPI", "DX12" );
  47. break;
  48. default:
  49. userOptions->setWert( "GraphicAPI", "BEST" );
  50. break;
  51. }
  52. } );
  53. TextFeld *mft = initTextFeld( 5, 50, 200, 20, zSchrift, TextFeld::Style::Text, "Maximale FPS" );
  54. f->addMember( mft );
  55. maxFPS = initTextFeld( 5, 70, 50, 20, zSchrift, TextFeld::Style::TextFeld, userOptions->wertExistiert( "MaxFPS" ) ? userOptions->zWert( "MaxFPS" )->getText() : "30" );
  56. maxFPS->setTastaturEreignis( _nurNummernTE );
  57. f->addMember( maxFPS->getThis() );
  58. TextFeld * gst = initTextFeld( 5, 95, 200, 20, zSchrift, TextFeld::Style::Text, "GUI Lautstärke (0 bis 100)" );
  59. f->addMember( gst );
  60. guiSound = initTextFeld( 5, 115, 50, 20, zSchrift, TextFeld::Style::TextFeld, userOptions->wertExistiert( "GUISound" ) ? userOptions->zWert( "GUISound" )->getText() : "100" );
  61. guiSound->setTastaturEreignis( _nurNummernTE );
  62. f->addMember( guiSound->getThis() );
  63. TextFeld * mt = initTextFeld( 255, 5, 200, 20, zSchrift, TextFeld::Style::Text, "Monitor (Neustart erforderlich)" );
  64. f->addMember( mt );
  65. AuswahlBox * monitorAuswahl = initAuswahlBox( 255, 25, 200, 20, zSchrift, AuswahlBox::Style::Normal | AuswahlBox::Style::Hintergrund, {} );
  66. Monitor m = getMonitor( 0 );
  67. int index = 0;
  68. do
  69. {
  70. monitorAuswahl->addEintrag( Text( "Monitor " ) + ++index + " (" + m.breite + "x" + m.height + ")" );
  71. m = getMonitor( index );
  72. } while( m.existiert );
  73. if( userOptions->wertExistiert( "Monitor" ) )
  74. monitorAuswahl->setAuswahl( *userOptions->zWert( "Monitor" ) );
  75. monitorAuswahl->setEventAktion( [ this ]( void *p, AuswahlBox * b, int unused, int auswahl )
  76. {
  77. if( !userOptions->wertExistiert( "Monitor" ) )
  78. userOptions->addWert( "Monitor", Text( auswahl ) );
  79. else
  80. userOptions->setWert( "Monitor", Text( auswahl ) );
  81. } );
  82. ok = initKnopf( 390, 450, 100, 20, zSchrift, Knopf::Style::Sichtbar, "Ok" );
  83. ok->setMausEreignisParameter( this );
  84. ok->setMausEreignis( einstellungenOkME );
  85. f->addMember( ok->getThis() );
  86. // add AuswahlBoxen
  87. f->addMember( graphicAPI );
  88. f->addMember( monitorAuswahl );
  89. zF->addMember( f->getThis() );
  90. ref = 1;
  91. }
  92. // Destruktor
  93. Einstellungen::~Einstellungen()
  94. {
  95. maxFPS->release();
  96. guiSound->release();
  97. f->release();
  98. ok->release();
  99. }
  100. // nicht constant
  101. void Einstellungen::setSichtbar()
  102. {
  103. f->setStyle( Fenster::Style::Sichtbar, f->hatStyleNicht( Fenster::Style::Sichtbar ) );
  104. }
  105. bool Einstellungen::closeME( MausEreignis &me )
  106. {
  107. if( me.id == ME_RLinks )
  108. f->removeStyle( Fenster::Style::Sichtbar );
  109. return 1;
  110. }
  111. bool Einstellungen::okME( MausEreignis & me )
  112. {
  113. if( me.id == ME_RLinks )
  114. {
  115. int fps = *maxFPS->zText();
  116. int sound = *guiSound->zText();
  117. if( fps > 0 && sound >= 0 && sound <= 100 )
  118. {
  119. f->removeStyle( Fenster::Style::Sichtbar );
  120. hauptScreen->lock();
  121. if( !userOptions->wertExistiert( "MaxFPS" ) )
  122. userOptions->addWert( "MaxFPS", maxFPS->zText()->getText() );
  123. else
  124. userOptions->setWert( "MaxFPS", maxFPS->zText()->getText() );
  125. if( !userOptions->wertExistiert( "GUISound" ) )
  126. userOptions->addWert( "GUISound", guiSound->zText()->getText() );
  127. else
  128. userOptions->setWert( "GUISound", guiSound->zText()->getText() );
  129. hauptScreen->unlock();
  130. userOptions->speichern();
  131. }
  132. }
  133. return 1;
  134. }
  135. // Reference Counting
  136. Einstellungen *Einstellungen::getThis()
  137. {
  138. ref++;
  139. return this;
  140. }
  141. Einstellungen *Einstellungen::release()
  142. {
  143. ref--;
  144. if( !ref )
  145. delete this;
  146. return 0;
  147. }
  148. // Ereignisse
  149. bool einstellungenSchließenME( void *p, void *obj, MausEreignis me )
  150. {
  151. if( !p )
  152. return 1;
  153. return ( (Einstellungen *)p )->closeME( me );
  154. }
  155. bool einstellungenOkME( void *p, void *obj, MausEreignis me )
  156. {
  157. if( !p )
  158. return 1;
  159. return ( (Einstellungen *)p )->okME( me );
  160. }