KEBeschreibung.cpp 12 KB

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