Einstellungen.cpp 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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. Monitor m = getMonitor( auswahl );
  82. if( !userOptions->wertExistiert( "ScreenWidth" ) )
  83. userOptions->addWert( "ScreenWidth", Text( m.breite ) );
  84. else
  85. userOptions->setWert( "ScreenWidth", Text( m.breite ) );
  86. if( !userOptions->wertExistiert( "ScreenWidth" ) )
  87. userOptions->addWert( "ScreenHeight", Text( m.height ) );
  88. else
  89. userOptions->setWert( "ScreenHeight", Text( m.height ) );
  90. breite->setText( Text( m.breite ) );
  91. height->setText( Text( m.height ) );
  92. } );
  93. TextFeld *at = initTextFeld( 255, 50, 200, 20, zSchrift, TextFeld::Style::Text, "Auflösung (Neustart erforderlich)" );
  94. f->addMember( at );
  95. breite = initTextFeld( 255, 70, 50, 20, zSchrift, TextFeld::Style::TextFeld, userOptions->wertExistiert( "ScreenWidth" ) ? userOptions->zWert( "ScreenWidth" )->getText() :
  96. Text( getMonitor( userOptions->wertExistiert( "Monitor" ) ? *userOptions->zWert( "Monitor" ) : 0 ).breite ) );
  97. height = initTextFeld( 312, 70, 50, 20, zSchrift, TextFeld::Style::TextFeld, userOptions->wertExistiert( "ScreenHeight" ) ? userOptions->zWert( "ScreenHeight" )->getText() :
  98. Text( getMonitor( userOptions->wertExistiert( "Monitor" ) ? *userOptions->zWert( "Monitor" ) : 0 ).height ) );
  99. breite->setTastaturEreignis( _nurNummernTE );
  100. height->setTastaturEreignis( _nurNummernTE );
  101. f->addMember( breite->getThis() );
  102. f->addMember( initTextFeld( 305, 70, 5, 20, zSchrift, TextFeld::Style::Text, "x" ) );
  103. f->addMember( height->getThis() );
  104. ok = initKnopf( 390, 450, 100, 20, zSchrift, Knopf::Style::Sichtbar, "Ok" );
  105. ok->setMausEreignisParameter( this );
  106. ok->setMausEreignis( einstellungenOkME );
  107. f->addMember( ok->getThis() );
  108. // add AuswahlBoxen
  109. f->addMember( graphicAPI );
  110. f->addMember( monitorAuswahl );
  111. zF->addMember( f->getThis() );
  112. ref = 1;
  113. }
  114. // Destruktor
  115. Einstellungen::~Einstellungen()
  116. {
  117. maxFPS->release();
  118. guiSound->release();
  119. breite->release();
  120. height->release();
  121. f->release();
  122. ok->release();
  123. }
  124. // nicht constant
  125. void Einstellungen::setSichtbar()
  126. {
  127. f->setStyle( Fenster::Style::Sichtbar, f->hatStyleNicht( Fenster::Style::Sichtbar ) );
  128. }
  129. bool Einstellungen::closeME( MausEreignis &me )
  130. {
  131. if( me.id == ME_RLinks )
  132. f->removeStyle( Fenster::Style::Sichtbar );
  133. return 1;
  134. }
  135. bool Einstellungen::okME( MausEreignis & me )
  136. {
  137. if( me.id == ME_RLinks )
  138. {
  139. int fps = *maxFPS->zText();
  140. int sound = *guiSound->zText();
  141. int wi = *breite->zText();
  142. int hi = *height->zText();
  143. if( fps > 0 && sound >= 0 && sound <= 100 && wi > 0 && hi > 0 )
  144. {
  145. f->removeStyle( Fenster::Style::Sichtbar );
  146. hauptScreen->lock();
  147. if( !userOptions->wertExistiert( "MaxFPS" ) )
  148. userOptions->addWert( "MaxFPS", maxFPS->zText()->getText() );
  149. else
  150. userOptions->setWert( "MaxFPS", maxFPS->zText()->getText() );
  151. if( !userOptions->wertExistiert( "GUISound" ) )
  152. userOptions->addWert( "GUISound", guiSound->zText()->getText() );
  153. else
  154. userOptions->setWert( "GUISound", guiSound->zText()->getText() );
  155. if( !userOptions->wertExistiert( "ScreenWidth" ) )
  156. userOptions->addWert( "ScreenWidth", Text( wi ) );
  157. else
  158. userOptions->setWert( "ScreenWidth", Text( wi ) );
  159. if( !userOptions->wertExistiert( "ScreenHeight" ) )
  160. userOptions->addWert( "ScreenHeight", Text( hi ) );
  161. else
  162. userOptions->setWert( "ScreenHeight", Text( hi ) );
  163. hauptScreen->unlock();
  164. userOptions->speichern();
  165. }
  166. }
  167. return 1;
  168. }
  169. // Reference Counting
  170. Einstellungen *Einstellungen::getThis()
  171. {
  172. ref++;
  173. return this;
  174. }
  175. Einstellungen *Einstellungen::release()
  176. {
  177. ref--;
  178. if( !ref )
  179. delete this;
  180. return 0;
  181. }
  182. // Ereignisse
  183. bool einstellungenSchließenME( void *p, void *obj, MausEreignis me )
  184. {
  185. if( !p )
  186. return 1;
  187. return ( (Einstellungen *)p )->closeME( me );
  188. }
  189. bool einstellungenOkME( void *p, void *obj, MausEreignis me )
  190. {
  191. if( !p )
  192. return 1;
  193. return ( (Einstellungen *)p )->okME( me );
  194. }