Einstellungen.cpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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( Fenster *zF )
  10. : ReferenceCounter()
  11. {
  12. f = initFenster( zF->getBreite() / 2 - 250, zF->getHeight() / 2 - 250, 500, 500,
  13. Fenster::Style::normal | Fenster::Style::BodyHAlpha | Fenster::Style::BodyHintergrund |
  14. Fenster::Style::TitelHintergrund | Fenster::Style::TitelHAlpha, "Einstellungen" );
  15. f->removeStyle( Fenster::Style::Sichtbar );
  16. f->setKBgFarbe( 0xe0000000 );
  17. f->setTBgFarbe( 0xe0000000 );
  18. f->setSBgFarbe( 0xF0000000 );
  19. f->setClosingMeParam( this );
  20. f->setClosingMe( einstellungenSchließenME );
  21. TextFeld *gat = initTextFeld( 5, 5, 300, 20, TextFeld::Style::Text, "Grafik Engine (Neustart erforderlich)" );
  22. f->addMember( gat );
  23. AuswahlBox *graphicAPI = initAuswahlBox( 5, 25, 100, 20, AuswahlBox::Style::Normal | AuswahlBox::Style::Hintergrund, { "Aktuellste", "DirectX 9" } );
  24. if( DirectX11::isAvailable() )
  25. graphicAPI->addEintrag( "DirectX 11" );
  26. if( DirectX12::isAvailable() )
  27. graphicAPI->addEintrag( "DirectX 12" );
  28. graphicAPI->setAuswahl( 0 );
  29. if( userOptions->wertExistiert( "GraphicAPI" ) && userOptions->zWert( "GraphicAPI" )->istGleich( "DX9" ) )
  30. graphicAPI->setAuswahl( 1 );
  31. if( userOptions->wertExistiert( "GraphicAPI" ) && userOptions->zWert( "GraphicAPI" )->istGleich( "DX11" ) )
  32. graphicAPI->setAuswahl( 2 );
  33. if( userOptions->wertExistiert( "GraphicAPI" ) && userOptions->zWert( "GraphicAPI" )->istGleich( "DX12" ) )
  34. graphicAPI->setAuswahl( 3 );
  35. graphicAPI->setEventAktion( [this]( void *p, AuswahlBox *b, int unused, int auswahl )
  36. {
  37. userOptions->addWert( "GraphicAPI", "BEST" );
  38. switch( auswahl )
  39. {
  40. case 1:
  41. userOptions->setWert( "GraphicAPI", "DX9" );
  42. break;
  43. case 2:
  44. userOptions->setWert( "GraphicAPI", "DX11" );
  45. break;
  46. case 3:
  47. userOptions->setWert( "GraphicAPI", "DX12" );
  48. break;
  49. default:
  50. userOptions->setWert( "GraphicAPI", "BEST" );
  51. break;
  52. }
  53. } );
  54. TextFeld *mft = initTextFeld( 5, 50, 200, 20, TextFeld::Style::Text, "Maximale FPS" );
  55. f->addMember( mft );
  56. maxFPS = initTextFeld( 5, 70, 50, 20, TextFeld::Style::TextFeld, userOptions->wertExistiert( "MaxFPS" ) ? userOptions->zWert( "MaxFPS" )->getText() : "30" );
  57. maxFPS->setTastaturEreignis( _nurNummernTE );
  58. f->addMember( dynamic_cast<Zeichnung *>( maxFPS->getThis() ) );
  59. TextFeld *gst = initTextFeld( 5, 95, 200, 20, TextFeld::Style::Text, "GUI Lautstärke (0 bis 100)" );
  60. f->addMember( gst );
  61. guiSound = initTextFeld( 5, 115, 50, 20, TextFeld::Style::TextFeld, userOptions->wertExistiert( "GUISound" ) ? userOptions->zWert( "GUISound" )->getText() : "100" );
  62. guiSound->setTastaturEreignis( _nurNummernTE );
  63. f->addMember( dynamic_cast<Zeichnung *>( guiSound->getThis() ) );
  64. TextFeld *mt = initTextFeld( 255, 5, 200, 20, TextFeld::Style::Text, "Monitor (Neustart erforderlich)" );
  65. f->addMember( mt );
  66. AuswahlBox *monitorAuswahl = initAuswahlBox( 255, 25, 200, 20, AuswahlBox::Style::Normal | AuswahlBox::Style::Hintergrund, {} );
  67. Monitor m = getMonitor( 0 );
  68. int index = 0;
  69. do
  70. {
  71. monitorAuswahl->addEintrag( Text( "Monitor " ) + ++index + " (" + m.breite + "x" + m.height + ")" );
  72. m = getMonitor( index );
  73. } while( m.existiert );
  74. if( userOptions->wertExistiert( "Monitor" ) )
  75. monitorAuswahl->setAuswahl( *userOptions->zWert( "Monitor" ) );
  76. monitorAuswahl->setEventAktion( [this]( void *p, AuswahlBox *b, int unused, int auswahl )
  77. {
  78. if( !userOptions->wertExistiert( "Monitor" ) )
  79. userOptions->addWert( "Monitor", Text( auswahl ) );
  80. else
  81. userOptions->setWert( "Monitor", Text( auswahl ) );
  82. Monitor m = getMonitor( auswahl );
  83. if( !userOptions->wertExistiert( "ScreenWidth" ) )
  84. userOptions->addWert( "ScreenWidth", Text( m.breite ) );
  85. else
  86. userOptions->setWert( "ScreenWidth", Text( m.breite ) );
  87. if( !userOptions->wertExistiert( "ScreenWidth" ) )
  88. userOptions->addWert( "ScreenHeight", Text( m.height ) );
  89. else
  90. userOptions->setWert( "ScreenHeight", Text( m.height ) );
  91. breite->setText( Text( m.breite ) );
  92. height->setText( Text( m.height ) );
  93. } );
  94. TextFeld *at = initTextFeld( 255, 50, 200, 20, TextFeld::Style::Text, "Auflösung (Neustart erforderlich)" );
  95. f->addMember( at );
  96. breite = initTextFeld( 255, 70, 50, 20, TextFeld::Style::TextFeld, userOptions->wertExistiert( "ScreenWidth" ) ? userOptions->zWert( "ScreenWidth" )->getText() :
  97. Text( getMonitor( userOptions->wertExistiert( "Monitor" ) ? *userOptions->zWert( "Monitor" ) : 0 ).breite ) );
  98. height = initTextFeld( 312, 70, 50, 20, TextFeld::Style::TextFeld, userOptions->wertExistiert( "ScreenHeight" ) ? userOptions->zWert( "ScreenHeight" )->getText() :
  99. Text( getMonitor( userOptions->wertExistiert( "Monitor" ) ? *userOptions->zWert( "Monitor" ) : 0 ).height ) );
  100. breite->setTastaturEreignis( _nurNummernTE );
  101. height->setTastaturEreignis( _nurNummernTE );
  102. f->addMember( dynamic_cast<Zeichnung *>( breite->getThis() ) );
  103. f->addMember( initTextFeld( 305, 70, 5, 20, TextFeld::Style::Text, "x" ) );
  104. f->addMember( dynamic_cast<Zeichnung *>( height->getThis() ) );
  105. ok = initKnopf( 390, 450, 100, 20, Knopf::Style::Sichtbar, "Ok" );
  106. ok->setMausEreignisParameter( this );
  107. ok->setMausEreignis( einstellungenOkME );
  108. f->addMember( dynamic_cast<Zeichnung *>( ok->getThis() ) );
  109. // add AuswahlBoxen
  110. f->addMember( graphicAPI );
  111. f->addMember( monitorAuswahl );
  112. zF->addMember( dynamic_cast<Zeichnung *>( f->getThis() ) );
  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. uiFactory.initParam.bildschirm->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. uiFactory.initParam.bildschirm->unlock();
  164. userOptions->speichern();
  165. }
  166. }
  167. return 1;
  168. }
  169. // Ereignisse
  170. bool einstellungenSchließenME( void *p, void *obj, MausEreignis me )
  171. {
  172. if( !p )
  173. return 1;
  174. return ( (Einstellungen *)p )->closeME( me );
  175. }
  176. bool einstellungenOkME( void *p, void *obj, MausEreignis me )
  177. {
  178. if( !p )
  179. return 1;
  180. return ( (Einstellungen *)p )->okME( me );
  181. }