Editor.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. #include "Editor.h"
  2. #include "ActionThread.h"
  3. #include "Interface\Dialogs\Frage.h"
  4. #include "Interface\Dialogs\Nachricht.h"
  5. #include <iostream>
  6. // Inhalt der Editor Klasse aus Editor.h
  7. // Konstruktor
  8. Editor::Editor()
  9. {
  10. schrift = 0;
  11. klient = 0;
  12. laden = 0;
  13. i = 0;
  14. alpha = 0;
  15. status = START;
  16. dialogs = new Array< Dialog* >();
  17. rend = 1;
  18. ref = 1;
  19. }
  20. // Destruktor
  21. Editor::~Editor()
  22. {
  23. if( schrift )
  24. schrift->release();
  25. if( klient )
  26. klient->release();
  27. if( laden )
  28. laden->release();
  29. if( i )
  30. i->release();
  31. }
  32. // nicht constant
  33. void Editor::addDialog( Dialog *d )
  34. {
  35. c.lock();
  36. dialogs->add( d );
  37. c.unlock();
  38. }
  39. // nicht constant
  40. void Editor::setSchrift( Schrift *schrift )
  41. {
  42. if( this->schrift )
  43. this->schrift->release();
  44. this->schrift = schrift;
  45. if( !i )
  46. i = new Interface( schrift );
  47. }
  48. void Editor::setKlient( EditorKlientV *ekv )
  49. {
  50. if( klient )
  51. klient->release();
  52. klient = new EditorKlient( ekv );
  53. }
  54. void Editor::setLadeAnimation( Animation2D *la )
  55. {
  56. if( laden )
  57. laden->release();
  58. laden = la;
  59. }
  60. void Editor::setSichtbar()
  61. {
  62. status = START;
  63. EditorKlient *k = klient->getThis();
  64. Schrift *zS = schrift->getThis();
  65. Punkt mS = windowSize;
  66. new ActionThread( [ this, k, zS, mS ] (void) -> void
  67. {
  68. int ret = k->init();
  69. if( ret == 2 )
  70. {
  71. std::function< void() > wiederherstellen = [ k ]
  72. {
  73. // TODO Karte herunterladen und anzeigen
  74. };
  75. std::function< void() > verwerfen = [ this, k, zS, mS ]
  76. {
  77. if( !k->sitzungVerwerfen() )
  78. {
  79. Text t = "Fehler beim verwerfen der Sitzung: ";
  80. t += k->getLastError();
  81. this->addDialog( new Nachricht( zS, t, mS ) );
  82. }
  83. // TODO Karte herunterladen und anzeigen
  84. };
  85. this->addDialog( new Frage( zS, "Es wurde eine alte ungespeicherte Sitzung gefunden. möchtest du sie Wiederherstellen?", "Ja", "Nein", wiederherstellen, verwerfen, verwerfen, mS ) );
  86. zS->release();
  87. k->release();
  88. }
  89. } );
  90. rend = 1;
  91. }
  92. void Editor::doMausEreignis( MausEreignis &me )
  93. {
  94. c.lock();
  95. for( auto i = dialogs->getArray(); i.set && i.var; i++ )
  96. i.var->doMausEreignis( me );
  97. bool dialogActive = dialogs->hat( 0 );
  98. c.unlock();
  99. i->doMausEreignis( me );
  100. if( i->hatVerlassen() && status == INITIALIZED && !dialogActive )
  101. {
  102. status = EXIT;
  103. }
  104. }
  105. void Editor::doTastaturEreignis( TastaturEreignis &te )
  106. {
  107. c.lock();
  108. for( auto i = dialogs->getArray(); i.set && i.var; i++ )
  109. i.var->doTastaturEreignis( te );
  110. c.unlock();
  111. i->doTastaturEreignis( te );
  112. }
  113. bool Editor::tick( double z )
  114. {
  115. rend |= i->tick( z );
  116. c.lock();
  117. for( auto i = dialogs->getArray(); i.set && i.var; i++ )
  118. rend |= i.var->tick( z );
  119. c.unlock();
  120. bool tmp = rend;
  121. rend = 0;
  122. return tmp;
  123. }
  124. void Editor::render( Bild &zRObj )
  125. {
  126. i->render( zRObj );
  127. c.lock();
  128. for( int i = dialogs->getEintragAnzahl() - 1; i >= 0; i-- )
  129. {
  130. dialogs->get( i )->render( zRObj );
  131. if( dialogs->get( i )->hatVerlassen() )
  132. {
  133. delete dialogs->get( i );
  134. dialogs->remove( i );
  135. }
  136. }
  137. c.unlock();
  138. }
  139. // constant
  140. bool Editor::hatVerlassen( bool jetzt ) const
  141. {
  142. return status == EXIT;
  143. }
  144. // Reference Counting
  145. EditorV *Editor::getThis()
  146. {
  147. ref++;
  148. return this;
  149. }
  150. EditorV *Editor::release()
  151. {
  152. ref--;
  153. if( !ref )
  154. delete this;
  155. return 0;
  156. }