StatistikChat.cpp 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. #include "StatistikChat.h"
  2. #include <Punkt.h>
  3. #include <DateiSystem.h>
  4. #include <MausEreignis.h>
  5. #include <AlphaFeld.h>
  6. #include <Scroll.h>
  7. #include <Rahmen.h>
  8. #include <TastaturEreignis.h>
  9. #include <Schrift.h>
  10. // Inhalt der ChatListeSpieler Klasse aus StatistikChat.h
  11. // Konstruktor
  12. ChatListeSpieler::ChatListeSpieler( int accountId, int eigeneId, UIInit &uiFactory, BilderV *bilder, KSGClient::InformationServerClient *zInfoc,
  13. bool istFreund, void( *addChatF )( void *, int ), void( *addFreundF )( void *, int ),
  14. void( *accountAnsehenF )( void *, int ), void *param )
  15. : ReferenceCounter(),
  16. addChatF( addChatF ),
  17. addFreundF( addFreundF ),
  18. accountAnsehenF( accountAnsehenF ),
  19. nachrichtParam( param ),
  20. accountId( accountId ),
  21. bg( new AlphaFeld() ),
  22. name( uiFactory.createTextFeld( uiFactory.initParam ) ),
  23. accountAnsehen( uiFactory.createKnopf( uiFactory.initParam ) ),
  24. nachrichtSenden( uiFactory.createKnopf( uiFactory.initParam ) ),
  25. freundesanfrageSenden( uiFactory.createKnopf( uiFactory.initParam ) ),
  26. pos( 0, 0 ),
  27. gr( 133, 20 ),
  28. online( 1 ),
  29. minKnopfX( 113 - ( ( ( accountId != eigeneId ) + !istFreund ) * 20 ) ),
  30. knopfX( 133 ),
  31. mausIn( 0 ),
  32. tickVal( 0 ),
  33. rend( 0 )
  34. {
  35. name->setPosition( 0, 0 );
  36. name->setSize( 133, 20 );
  37. name->setStyle( TextFeld::Style::Text | TextFeld::Style::Rahmen | TextFeld::Style::VCenter );
  38. name->setText( "" );
  39. accountAnsehen->setPosition( 133, 0 );
  40. accountAnsehen->setSize( 20, 20 );
  41. accountAnsehen->setText( "" );
  42. nachrichtSenden->setPosition( 153, 0 );
  43. nachrichtSenden->setSize( 20, 20 );
  44. nachrichtSenden->setText( "" );
  45. freundesanfrageSenden->setPosition( 173, 0 );
  46. freundesanfrageSenden->setSize( 20, 20 );
  47. freundesanfrageSenden->setText( "" );
  48. Bild *ansehenBild = bilder->get( "data/client/bilder/chat.ltdb/ansehen.png" );
  49. Bild *nachrichtBild = bilder->get( "data/client/bilder/chat.ltdb/nachricht.png" );
  50. Bild *einladungBild = bilder->get( "data/client/bilder/chat.ltdb/neuerfreund.png" );
  51. bg->setSize( gr );
  52. bg->setFarbe( 0x0000FF00 );
  53. bg->setStrength( -4 );
  54. name->setText( zInfoc->getSpielerName( accountId ) );
  55. accountAnsehen->setStyle( Knopf::Style::Sichtbar | Knopf::Style::Erlaubt | Knopf::Style::Hintergrund | Knopf::Style::HAlpha | Knopf::Style::HBild | Knopf::Style::KlickBuffer );
  56. accountAnsehen->setHintergrundBildZ( ansehenBild );
  57. nachrichtSenden->setStyle( Knopf::Style::Sichtbar | Knopf::Style::Erlaubt | Knopf::Style::Hintergrund | Knopf::Style::HAlpha | Knopf::Style::HBild | Knopf::Style::KlickBuffer );
  58. nachrichtSenden->setHintergrundBildZ( nachrichtBild );
  59. freundesanfrageSenden->setStyle( Knopf::Style::Sichtbar | Knopf::Style::Erlaubt | Knopf::Style::Hintergrund | Knopf::Style::HAlpha | Knopf::Style::HBild | Knopf::Style::KlickBuffer );
  60. freundesanfrageSenden->setHintergrundBildZ( einladungBild );
  61. }
  62. // Destruktor
  63. ChatListeSpieler::~ChatListeSpieler()
  64. {
  65. bg->release();
  66. name->release();
  67. accountAnsehen->release();
  68. nachrichtSenden->release();
  69. freundesanfrageSenden->release();
  70. }
  71. // nicht constant
  72. void ChatListeSpieler::setOffline()
  73. {
  74. online = 0;
  75. }
  76. void ChatListeSpieler::setPosition( int y )
  77. {
  78. if( pos.y != y )
  79. rend = 1;
  80. pos.y = y;
  81. }
  82. void ChatListeSpieler::doPublicMausEreignis( MausEreignis &me )
  83. {
  84. int mx = me.mx;
  85. int my = me.my;
  86. me.mx -= pos.x;
  87. me.my -= pos.y;
  88. if( me.mx > 0 && me.mx < gr.x && me.my > 0 && me.my < gr.y )
  89. mausIn = 1;
  90. else
  91. mausIn = 0;
  92. me.mx += 133 - knopfX;
  93. bool vera = me.verarbeitet;
  94. accountAnsehen->doPublicMausEreignis( me );
  95. int aktion = ( me.verarbeitet && !vera ) ? 1 : 0;
  96. nachrichtSenden->doPublicMausEreignis( me );
  97. aktion = ( me.verarbeitet && !vera && !aktion ) ? 2 : aktion;
  98. freundesanfrageSenden->doPublicMausEreignis( me );
  99. aktion = ( me.verarbeitet && !vera && !aktion ) ? 3 : aktion;
  100. me.mx -= 133 - knopfX;
  101. if( me.id == ME_RLinks && mausIn )
  102. {
  103. switch( aktion )
  104. {
  105. case 1:
  106. accountAnsehenF( nachrichtParam, accountId );
  107. break;
  108. case 2:
  109. addChatF( nachrichtParam, accountId );
  110. break;
  111. case 3:
  112. addFreundF( nachrichtParam, accountId );
  113. break;
  114. }
  115. }
  116. me.mx = mx;
  117. me.my = my;
  118. }
  119. bool ChatListeSpieler::tick( double tickVal )
  120. {
  121. rend |= name->tick( tickVal );
  122. rend |= accountAnsehen->tick( tickVal );
  123. rend |= nachrichtSenden->tick( tickVal );
  124. rend |= freundesanfrageSenden->tick( tickVal );
  125. this->tickVal += tickVal * 60;
  126. int val = (int)this->tickVal;
  127. if( val )
  128. {
  129. this->tickVal -= val;
  130. if( mausIn && knopfX != minKnopfX )
  131. {
  132. if( knopfX - val < minKnopfX )
  133. knopfX = minKnopfX;
  134. else
  135. knopfX -= val;
  136. rend = 1;
  137. }
  138. if( !mausIn && knopfX != gr.x )
  139. {
  140. if( knopfX + val > gr.x )
  141. knopfX = gr.x;
  142. else
  143. knopfX += val;
  144. rend = 1;
  145. }
  146. if( !online && bg->getFarbe() != 0x00FF0000 )
  147. {
  148. int g = ( bg->getFarbe() >> 8 ) & 0xFF;
  149. if( g - val < 0 )
  150. bg->setFarbe( 0x00FF0000 );
  151. else
  152. {
  153. bg->setFarbe( ( ( ( g - val ) << 8 ) & 0xFF00 ) | ( bg->getFarbe() & 0xFFFF00FF ) );
  154. bg->setFarbe( ( ( ( 255 - ( g - val ) ) << 16 ) & 0xFF0000 ) | ( bg->getFarbe() & 0xFF00FFFF ) );
  155. }
  156. rend = 1;
  157. }
  158. }
  159. bool ret = rend;
  160. rend = 0;
  161. return ret;
  162. }
  163. void ChatListeSpieler::render( Bild &zRObj )
  164. {
  165. if( !zRObj.setDrawOptions( pos, gr ) )
  166. return;
  167. bg->render( zRObj );
  168. name->render( zRObj );
  169. zRObj.addScrollOffset( 133 - knopfX, 0 );
  170. accountAnsehen->render( zRObj );
  171. nachrichtSenden->render( zRObj );
  172. freundesanfrageSenden->render( zRObj );
  173. zRObj.releaseDrawOptions();
  174. }
  175. // constant
  176. int ChatListeSpieler::getAccountId() const
  177. {
  178. return accountId;
  179. }
  180. // Inhalt der ChatListe Klasse aus StatistikChat.h
  181. // Konstruktor
  182. ChatListe::ChatListe( int eigeneId, KSGClient::InformationServerClient *infoc, UIInit &uiFactory, BilderV *bilder,
  183. void( *addChat )( void *, int ), void( *addFreund )( void *, int ),
  184. void( *accountAnsehen )( void *, int ), void *param )
  185. : ReferenceCounter(),
  186. addChat( addChat ),
  187. addFreund( addFreund ),
  188. accountAnsehen( accountAnsehen ),
  189. nachrichtParam( nachrichtParam ),
  190. eigeneId( eigeneId ),
  191. spieler( new RCArray< ChatListeSpieler >() ),
  192. vScroll( new VScrollBar() ),
  193. pos( 420, 295 ),
  194. gr( 150, 150 ),
  195. infoc( infoc ),
  196. uiFactory( uiFactory ),
  197. bilder( bilder ),
  198. ram( new LRahmen() ),
  199. rend( 0 )
  200. {
  201. vScroll->setKlickScroll( 10 );
  202. vScroll->update( 0, 148 );
  203. ram->setFarbe( 0xFFFFFFFF );
  204. ram->setSize( 150, 150 );
  205. }
  206. // Destruktor
  207. ChatListe::~ChatListe()
  208. {
  209. spieler->release();
  210. vScroll->release();
  211. infoc->release();
  212. ram->release();
  213. }
  214. // nicht constant
  215. void ChatListe::addSpieler( int accountId, bool istFreund )
  216. {
  217. int anz = spieler->getEintragAnzahl();
  218. for( int i = 0; i < anz; i++ )
  219. {
  220. if( spieler->z( i ) && spieler->z( i )->getAccountId() == accountId )
  221. return;
  222. }
  223. ChatListeSpieler *s = new ChatListeSpieler( accountId, eigeneId, uiFactory, bilder, infoc, istFreund, addChat, addFreund, accountAnsehen, nachrichtParam );
  224. s->setPosition( anz * 20 );
  225. spieler->add( s );
  226. rend = 1;
  227. }
  228. void ChatListe::setOffline( int accountId )
  229. {
  230. int anz = spieler->getEintragAnzahl();
  231. for( int i = 0; i < anz; i++ )
  232. {
  233. if( spieler->z( i ) && spieler->z( i )->getAccountId() == accountId )
  234. {
  235. spieler->z( i )->setOffline();
  236. return;
  237. }
  238. }
  239. }
  240. void ChatListe::doPublicMausEreignis( MausEreignis &me )
  241. {
  242. int mx = me.mx;
  243. int my = me.my;
  244. me.mx -= pos.x;
  245. me.my -= pos.y - vScroll->getScroll();
  246. vScroll->doMausMessage( 134, 1, 15, 148, me );
  247. int anz = spieler->getEintragAnzahl();
  248. for( int i = 0; i < anz; i++ )
  249. {
  250. if( spieler->z( i ) )
  251. spieler->z( i )->doPublicMausEreignis( me );
  252. }
  253. me.mx = mx;
  254. me.my = my;
  255. }
  256. bool ChatListe::tick( double tickVal )
  257. {
  258. rend |= vScroll->getRend();
  259. int anz = spieler->getEintragAnzahl();
  260. for( int i = 0; i < anz; i++ )
  261. {
  262. if( spieler->z( i ) )
  263. rend |= spieler->z( i )->tick( tickVal );
  264. }
  265. bool ret = rend;
  266. rend = 0;
  267. return ret;
  268. }
  269. void ChatListe::render( Bild &zRObj )
  270. {
  271. if( !zRObj.setDrawOptions( pos, gr ) )
  272. return;
  273. int anz = spieler->getEintragAnzahl();
  274. zRObj.addScrollOffset( 0, vScroll->getScroll() );
  275. for( int i = 0; i < anz; i++ )
  276. {
  277. if( spieler->z( i ) )
  278. spieler->z( i )->render( zRObj );
  279. }
  280. zRObj.addScrollOffset( 0, -vScroll->getScroll() );
  281. vScroll->render( 134, 1, 15, 148, zRObj );
  282. ram->render( zRObj );
  283. zRObj.releaseDrawOptions();
  284. }
  285. // Inhalt der StatistikChat Klasse aus StatistikChat.h
  286. // Konstruktor
  287. StatistikChat::StatistikChat( int eigeneId, KSGClient::SpielServerClient *spielc, KSGClient::InformationServerClient *infoc, UIInit &uiFactory, BilderV *bilder,
  288. void( *addNachricht )( void *, Text *, Text *, Text *, Text * ),
  289. void( *addChat )( void *, int ), void( *addFreund )( void *, int ),
  290. void( *accountAnsehen )( void *, int ), void *param )
  291. : ReferenceCounter(),
  292. addNachricht( addNachricht ),
  293. nachrichtParam( nachrichtParam ),
  294. spielc( spielc ),
  295. infoc( infoc ),
  296. verlauf( uiFactory.createTextFeld( uiFactory.initParam ) ),
  297. nachricht( uiFactory.createTextFeld( uiFactory.initParam ) ),
  298. senden( uiFactory.createKnopf( uiFactory.initParam ) ),
  299. verlassen( uiFactory.createKnopf( uiFactory.initParam ) ),
  300. spielerListe( new ChatListe( eigeneId, infoc->getThis(), uiFactory, bilder, addChat, addFreund, accountAnsehen, nachrichtParam ) ),
  301. beenden( 0 )
  302. {
  303. verlauf->setPosition( 10, 295 );
  304. verlauf->setSize( 400, 150 );
  305. verlauf->setStyle( TextFeld::Style::Sichtbar | TextFeld::Style::Rahmen | TextFeld::Style::VScroll | TextFeld::Style::Mehrzeilig );
  306. verlauf->setText( "" );
  307. nachricht->setPosition( 10, 450 );
  308. nachricht->setSize( 375, 20 );
  309. nachricht->setStyle( TextFeld::Style::TextFeld );
  310. nachricht->setText( "" );
  311. senden->setPosition( 390, 450 );
  312. senden->setSize( 20, 20 );
  313. senden->setText( "" );
  314. verlassen->setPosition( 430, 450 );
  315. verlassen->setSize( 130, 20 );
  316. verlassen->setText( "Verlassen" );
  317. Bild *sendenBild = bilder->get( "data/client/bilder/chat.ltdb/senden.png" );
  318. senden->setStyle( Knopf::Style::Sichtbar | Knopf::Style::Erlaubt | Knopf::Style::Hintergrund | Knopf::Style::HAlpha | Knopf::Style::HBild | Knopf::Style::KlickBuffer );
  319. senden->setHintergrundBildZ( sendenBild );
  320. }
  321. // Destruktor
  322. StatistikChat::~StatistikChat()
  323. {
  324. spielc->release();
  325. infoc->release();
  326. verlauf->release();
  327. nachricht->release();
  328. senden->release();
  329. verlassen->release();
  330. spielerListe->release();
  331. }
  332. // nicht constant
  333. void StatistikChat::addSpieler( int accountId, bool istFreund )
  334. {
  335. spielerListe->addSpieler( accountId, istFreund );
  336. }
  337. void StatistikChat::spielerOffline( int accountId )
  338. {
  339. spielerListe->setOffline( accountId );
  340. }
  341. void StatistikChat::addChatNachricht( int vonAccount, char *nachricht )
  342. {
  343. Text *txt = vonAccount ? infoc->getSpielerName( vonAccount ) : 0;
  344. if( !txt )
  345. txt = new Text();
  346. else
  347. *txt += ": ";
  348. *txt += nachricht;
  349. *txt += "\n";
  350. verlauf->zTextRenderer()->textFormatieren( txt, verlauf->getBreite() - 15 );
  351. verlauf->zText()->append( txt );
  352. verlauf->updateVScroll();
  353. }
  354. void StatistikChat::doPublicMausEreignis( MausEreignis &me )
  355. {
  356. verlauf->doPublicMausEreignis( me );
  357. nachricht->doPublicMausEreignis( me );
  358. spielerListe->doPublicMausEreignis( me );
  359. bool vera = me.verarbeitet;
  360. senden->doPublicMausEreignis( me );
  361. int aktion = ( me.verarbeitet && !vera ) ? 1 : 0;
  362. verlassen->doPublicMausEreignis( me );
  363. aktion = ( me.verarbeitet && !vera && !aktion ) ? 2 : aktion;
  364. if( me.id == ME_RLinks )
  365. {
  366. if( aktion == 1 )
  367. {
  368. if( nachricht->zText()->getLength() )
  369. {
  370. short län = 1 + nachricht->zText()->getLength();
  371. char *bytes = new char[ län ];
  372. bytes[ 0 ] = 2;
  373. for( int i = 0; i < län - 1; i++ )
  374. bytes[ i + 1 ] = nachricht->zText()->getText()[ i ];
  375. if( !spielc->statistikNachricht( län, bytes ) )
  376. addNachricht( nachrichtParam, new Text( "Fehler" ), new Text( "Die Nachricht konnte nicht gesendet werden." ), new Text( "Ok" ), 0 );
  377. else
  378. {
  379. nachricht->setAuswahl( 0, 0 );
  380. nachricht->setText( "" );
  381. }
  382. delete[] bytes;
  383. }
  384. }
  385. if( aktion == 2 )
  386. beenden = 1;
  387. }
  388. }
  389. void StatistikChat::doTastaturEreignis( TastaturEreignis &te )
  390. {
  391. bool vera = te.verarbeitet;
  392. nachricht->doTastaturEreignis( te );
  393. if( !vera && te.verarbeitet && te.id == TE_Release && te.taste == T_Enter )
  394. {
  395. if( nachricht->zText()->getLength() )
  396. {
  397. short län = 1 + nachricht->zText()->getLength();
  398. char *bytes = new char[ län ];
  399. bytes[ 0 ] = 2;
  400. for( int i = 0; i < län - 1; i++ )
  401. bytes[ i + 1 ] = nachricht->zText()->getText()[ i ];
  402. if( !spielc->statistikNachricht( län, bytes ) )
  403. addNachricht( nachrichtParam, new Text( "Fehler" ), new Text( "Die Nachricht konnte nicht gesendet werden." ), new Text( "Ok" ), 0 );
  404. else
  405. {
  406. nachricht->setAuswahl( 0, 0 );
  407. nachricht->setText( "" );
  408. }
  409. delete[] bytes;
  410. }
  411. }
  412. }
  413. bool StatistikChat::tick( double tickVal )
  414. {
  415. bool rend = verlauf->tick( tickVal );
  416. rend |= nachricht->tick( tickVal );
  417. rend |= senden->tick( tickVal );
  418. rend |= verlassen->tick( tickVal );
  419. rend |= spielerListe->tick( tickVal );
  420. return rend;
  421. }
  422. void StatistikChat::render( Bild &zRObj )
  423. {
  424. verlauf->render( zRObj );
  425. nachricht->render( zRObj );
  426. senden->render( zRObj );
  427. verlassen->render( zRObj );
  428. spielerListe->render( zRObj );
  429. }
  430. // constant
  431. bool StatistikChat::hatVerlassen() const
  432. {
  433. return beenden;
  434. }