KEBeschreibung.cpp 12 KB

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