KEBeschreibung.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. #include "KEBeschreibung.h"
  2. #include "../../../../Global/Initialisierung.h"
  3. #include "../../../../Global/Variablen.h"
  4. bool KEBKnopfPressME( void *p, void *obj, MausEreignis me )
  5. {
  6. if( p )
  7. ( (KEBeschreibung*)p )->knopfPress( (Knopf*)obj, &me );
  8. return 1;
  9. }
  10. // Inhalt der KEBeschreibung Klasse aus KEBeschreibung.h
  11. // Konstruktor
  12. KEBeschreibung::KEBeschreibung( int karte, Schrift *zSchrift )
  13. : Thread()
  14. {
  15. schrift = zSchrift->getThis();
  16. Text *kName = infoClient->getKarteName( karte );
  17. Text titel = kName ? kName->getText() : "<Karte>";
  18. titel += " - Beschreibung";
  19. if( kName )
  20. kName->release();
  21. fenster = initFenster( 10, 40, 880, 550, zSchrift, Fenster::Style::Sichtbar | Fenster::Style::Titel | Fenster::Style::TitelBuffered | Fenster::Style::Erlaubt | Fenster::Style::Rahmen, titel );
  22. editor = new KEBEditor( zSchrift, this );
  23. vorschau = new KEBVorschau( zSchrift );
  24. fenster->addMember( editor->getThis() );
  25. fenster->addMember( vorschau->getThis() );
  26. laden = (Animation2D*)ladeAnimation->dublizieren();
  27. laden->setPosition( 425, 275 );
  28. laden->setSichtbar( 0 );
  29. importDialog = 0;
  30. importPfad = 0;
  31. animation = 0;
  32. tickVal = 0;
  33. sichtbar = 0;
  34. rechts = 0;
  35. xStart = 0;
  36. breite = 0;
  37. aktion = 0;
  38. jetzt = 0;
  39. this->karte = karte;
  40. alpha = 255;
  41. }
  42. // Destruktor
  43. KEBeschreibung::~KEBeschreibung()
  44. {
  45. fenster->release();
  46. laden->release();
  47. schrift->release();
  48. editor->release();
  49. vorschau->release();
  50. if( importDialog )
  51. importDialog->release();
  52. if( importPfad )
  53. importPfad->release();
  54. }
  55. // nicht constant
  56. void KEBeschreibung::setSichtbar( bool s, bool vr )
  57. {
  58. animation = 1;
  59. sichtbar = s;
  60. rechts = vr;
  61. if( sichtbar )
  62. {
  63. if( vr )
  64. {
  65. xStart = 900;
  66. breite = 0;
  67. }
  68. else
  69. {
  70. xStart = 0;
  71. breite = 0;
  72. }
  73. if( !run )
  74. {
  75. aktion = 0;
  76. start();
  77. }
  78. }
  79. }
  80. void KEBeschreibung::thread()
  81. {
  82. laden->setSichtbar( 1 );
  83. if( aktion == 0 )
  84. {
  85. if( jetzt == 1 )
  86. { // beschreibung laden
  87. Text *t = editorClient->beschreibungLaden();
  88. t->ersetzen( "\r\n", "\n" );
  89. hauptScreen->lock();
  90. if( !t )
  91. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ), new Text( editorClient->getLetzterFehler() ), new Text( "Ok" ) );
  92. else
  93. editor->setText( t );
  94. hauptScreen->unlock();
  95. t->release();
  96. }
  97. if( jetzt == 2 )
  98. { // Titelbild laden
  99. Bild *b = editorClient->titelbildLaden();
  100. hauptScreen->lock();
  101. if( !b )
  102. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ), new Text( editorClient->getLetzterFehler() ), new Text( "Ok" ) );
  103. else
  104. editor->setBild( b );
  105. hauptScreen->unlock();
  106. b->release();
  107. }
  108. if( jetzt == 3 )
  109. { // Minimap Bild laden
  110. Bild *b = editorClient->minimapLaden();
  111. hauptScreen->lock();
  112. if( !b )
  113. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ), new Text( editorClient->getLetzterFehler() ), new Text( "Ok" ) );
  114. else
  115. editor->setBild( b );
  116. hauptScreen->unlock();
  117. b->release();
  118. }
  119. if( jetzt == 4 )
  120. { // Ladebild laden
  121. Bild *b = editorClient->ladebildLaden();
  122. hauptScreen->lock();
  123. if( !b )
  124. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ), new Text( editorClient->getLetzterFehler() ), new Text( "Ok" ) );
  125. else
  126. editor->setBild( b );
  127. hauptScreen->unlock();
  128. b->release();
  129. }
  130. editor->setSichtbar( 1 );
  131. }
  132. if( aktion == 1 )
  133. {
  134. if( jetzt == 1 )
  135. { // Beschreibung speichern
  136. if( !editorClient->beschreibungSpeichern( editor->zBeschreibung() ) )
  137. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ), new Text( editorClient->getLetzterFehler() ), new Text( "Ok" ) );
  138. }
  139. if( jetzt == 2 )
  140. { // Titelbild hochladen
  141. importPfad->ersetzen( "\\", "/" );
  142. Text *n = importPfad->getTeilText( importPfad->positionVon( "/", importPfad->anzahlVon( "/" ) - 1 ) + 1 );
  143. Text name = n->getText();
  144. n->release();
  145. Text *err = new Text();
  146. Bild *b = ladeBild( importPfad->getText(), err );
  147. if( !b )
  148. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ), err, new Text( "Ok" ) );
  149. else
  150. {
  151. err->release();
  152. if( !editorClient->titelbildSpeichern( b ) )
  153. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ), new Text( editorClient->getLetzterFehler() ), new Text( "Ok" ) );
  154. hauptScreen->lock();
  155. editor->setBild( b );
  156. hauptScreen->unlock();
  157. b->release();
  158. }
  159. }
  160. if( jetzt == 3 )
  161. { // Minimap hochladen
  162. importPfad->ersetzen( "\\", "/" );
  163. Text *n = importPfad->getTeilText( importPfad->positionVon( "/", importPfad->anzahlVon( "/" ) - 1 ) + 1 );
  164. Text name = n->getText();
  165. n->release();
  166. Text *err = new Text();
  167. Bild *b = ladeBild( importPfad->getText(), err );
  168. if( !b )
  169. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ), err, new Text( "Ok" ) );
  170. else
  171. {
  172. err->release();
  173. if( !editorClient->minimapSpeichern( b ) )
  174. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ), new Text( editorClient->getLetzterFehler() ), new Text( "Ok" ) );
  175. hauptScreen->lock();
  176. editor->setBild( b );
  177. hauptScreen->unlock();
  178. b->release();
  179. }
  180. }
  181. if( jetzt == 4 )
  182. { // Ladebild hochladen
  183. importPfad->ersetzen( "\\", "/" );
  184. Text *n = importPfad->getTeilText( importPfad->positionVon( "/", importPfad->anzahlVon( "/" ) - 1 ) + 1 );
  185. Text name = n->getText();
  186. n->release();
  187. Text *err = new Text();
  188. Bild *b = ladeBild( importPfad->getText(), err );
  189. if( !b )
  190. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ), err, new Text( "Ok" ) );
  191. else
  192. {
  193. err->release();
  194. if( !editorClient->ladebildSpeichern( b ) )
  195. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ), new Text( editorClient->getLetzterFehler() ), new Text( "Ok" ) );
  196. hauptScreen->lock();
  197. editor->setBild( b );
  198. hauptScreen->unlock();
  199. b->release();
  200. }
  201. }
  202. }
  203. if( aktion == 2 )
  204. { // Vorschau
  205. if( vorschau->ladeKarte() )
  206. {
  207. editor->setSichtbar( 0 );
  208. vorschau->setSichtbar( 1 );
  209. }
  210. }
  211. run = 0;
  212. laden->setSichtbar( 0 );
  213. return;
  214. }
  215. void KEBeschreibung::knopfPress( Knopf *k, MausEreignis *me )
  216. {
  217. if( run || me->id != ME_RLinks )
  218. return;
  219. if( editor->getKNum( k ) > 0 && jetzt != editor->getKNum( k ) )
  220. {
  221. jetzt = editor->getKNum( k );
  222. aktion = 0;
  223. start();
  224. }
  225. if( editor->getKNum( k ) == -1 )
  226. {
  227. aktion = 1;
  228. start();
  229. }
  230. if( editor->getKNum( k ) == -2 )
  231. {
  232. if( !importDialog )
  233. {
  234. importDialog = new DateiDialogTh();
  235. importDialog->setOpen( 1 );
  236. importDialog->setDateiTypAuswahl( 4 );
  237. importDialog->addDateiTyp( "JPEG-Bild", "*.jpg;*.jpeg;*.jpe" );
  238. importDialog->addDateiTyp( "GIF-Bild", "*.gif" );
  239. importDialog->addDateiTyp( "PNG-Bild", "*.png" );
  240. importDialog->addDateiTyp( "Alle Dateien", "*.*" );
  241. importDialog->start();
  242. }
  243. }
  244. if( editor->getKNum( k ) == -3 )
  245. {
  246. aktion = 2;
  247. start();
  248. }
  249. }
  250. void KEBeschreibung::doPublicMausEreignis( MausEreignis &me )
  251. {
  252. if( !run )
  253. fenster->doPublicMausEreignis( me );
  254. }
  255. void KEBeschreibung::doTastaturEreignis( TastaturEreignis &te )
  256. {
  257. if( !run )
  258. fenster->doTastaturEreignis( te );
  259. }
  260. bool KEBeschreibung::tick( double z )
  261. {
  262. if( importDialog )
  263. {
  264. if( !importDialog->isRunning() )
  265. {
  266. if( importPfad )
  267. importPfad->release();
  268. importPfad = importDialog->getPfad();
  269. importDialog = (DateiDialogTh*)importDialog->release();
  270. if( sichtbar && importPfad )
  271. {
  272. aktion = 1;
  273. start();
  274. }
  275. }
  276. }
  277. if( vorschau->istSichtbar() )
  278. {
  279. if( vorschau->getAktion() )
  280. {
  281. vorschau->setSichtbar( 0 );
  282. editor->setSichtbar( 1 );
  283. }
  284. }
  285. bool ret = laden->tick( z );
  286. tickVal += z * 150;
  287. int val = (int)tickVal;
  288. tickVal -= val;
  289. if( val )
  290. {
  291. if( run && alpha > 100 )
  292. {
  293. if( alpha - val < 100 )
  294. alpha = 100;
  295. else
  296. alpha -= val;
  297. ret = 1;
  298. }
  299. if( sichtbar && !run && alpha != 255 )
  300. {
  301. if( alpha + val > 255 )
  302. alpha = 255;
  303. else
  304. alpha += val;
  305. ret = 1;
  306. }
  307. val *= 3;
  308. if( sichtbar )
  309. {
  310. if( alpha < 100 )
  311. {
  312. if( alpha + val > 100 )
  313. alpha = 100;
  314. else
  315. alpha += val;
  316. ret = 1;
  317. }
  318. if( xStart != 0 || breite != 900 )
  319. {
  320. if( rechts )
  321. {
  322. if( xStart - val <= 0 )
  323. {
  324. xStart = 0;
  325. breite = 900;
  326. animation = 0;
  327. }
  328. else
  329. {
  330. xStart -= val;
  331. breite += val;
  332. }
  333. }
  334. else
  335. {
  336. if( breite + val >= 900 )
  337. {
  338. breite = 900;
  339. animation = 0;
  340. }
  341. else
  342. breite += val;
  343. }
  344. ret = 1;
  345. }
  346. }
  347. else
  348. {
  349. if( breite != 0 )
  350. {
  351. if( rechts )
  352. {
  353. if( breite - val <= 0 )
  354. {
  355. breite = 0;
  356. animation = 0;
  357. }
  358. else
  359. breite -= val;
  360. }
  361. else
  362. {
  363. if( breite - val <= 0 )
  364. {
  365. breite = 0;
  366. xStart = 900;
  367. animation = 0;
  368. }
  369. else
  370. {
  371. breite -= val;
  372. xStart += val;
  373. }
  374. }
  375. ret = 1;
  376. }
  377. }
  378. }
  379. return ret || fenster->tick( z );
  380. }
  381. void KEBeschreibung::render( Bild &zRObj )
  382. {
  383. if( !zRObj.setDrawOptions( xStart, 0, breite, 600 ) )
  384. return;
  385. zRObj.setAlpha( alpha );
  386. fenster->render( zRObj );
  387. zRObj.releaseAlpha();
  388. laden->render( zRObj );
  389. zRObj.releaseDrawOptions();
  390. }
  391. // constant
  392. bool KEBeschreibung::istSichtbar() const
  393. {
  394. return sichtbar || animation;
  395. }
  396. // löscht das objekt wenn es nicht mehr gebraucht wird und beendet den Thread
  397. Thread *KEBeschreibung::release()
  398. {
  399. if( ref == 2 && run )
  400. {
  401. warteAufThread( 5000 );
  402. if( run )
  403. ende();
  404. }
  405. return Thread::release();
  406. }