TeamAuswahl.cpp 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135
  1. #include "TeamAuswahl.h"
  2. #include "..\..\..\Global\Initialisierung.h"
  3. #include "..\..\..\Global\Variablen.h"
  4. #include <DateiSystem.h>
  5. #include <Rahmen.h>
  6. #include <AlphaFeld.h>
  7. #include <AuswahlBox.h>
  8. // Inhalt der TeamAuswahlListeSpieler Klasse aus TeamAuswahl.h
  9. // Konstruktor
  10. TeamAuswahlListeSpieler::TeamAuswahlListeSpieler( SpielerTeamStruktur *sts, Schrift *zSchrift, int accountId, int karteId )
  11. {
  12. this->accountId = accountId;
  13. Text *n = infoClient->getSpielerName( accountId );
  14. name = initTextFeld( 1, 1, 99, 20, zSchrift, TextFeld::Style::Text | TextFeld::Style::Center, n->getText() );
  15. n->release();
  16. if( accountId == loginClient->getAccountId() )
  17. {
  18. teamAuswahl = new AuswahlBox();
  19. teamAuswahl->setStyle( AuswahlBox::Style::Sichtbar | AuswahlBox::Style::Erlaubt | AuswahlBox::Style::Rahmen | AuswahlBox::Style::MultiStyled | AuswahlBox::Style::MaxHeight | AuswahlBox::Style::VScroll | AuswahlBox::Style::Hintergrund );
  20. teamAuswahl->setRahmenFarbe( 0xFFFFFFFF );
  21. teamAuswahl->setRahmenBreite( 1 );
  22. teamAuswahl->setPosition( 100, 1 );
  23. teamAuswahl->setSize( 150, 20 );
  24. teamAuswahl->setMaxAuskappHeight( 100 );
  25. teamAuswahl->setSchriftZ( zSchrift->getThis() );
  26. teamAuswahl->setHintergrundFarbe( 0xFF000000 );
  27. teamAuswahl->setMausEreignis( _ret1ME );
  28. teamAuswahl->setEventParam( this );
  29. teamAuswahl->setEventAktion( TeamAuswahlListeSpielerTeamAuswahlE );
  30. }
  31. else
  32. team = initTextFeld( 100, 1, 150, 20, zSchrift, TextFeld::Style::Text | TextFeld::Style::Center, "" );
  33. Array< int > *statistik = new Array< int >();
  34. infoClient->getSpielStatistik( accountId, infoClient->getSpielId( karteId ), statistik );
  35. punkte = initTextFeld( 250, 1, 80, 20, zSchrift, TextFeld::Style::Text | TextFeld::Style::Center, "Punkte: " );
  36. punkte->zText()->append( statistik->hat( 3 ) ? statistik->get( 3 ) : 0 );
  37. spiele = initTextFeld( 330, 1, 80, 20, zSchrift, TextFeld::Style::Text | TextFeld::Style::Center, "Spiele: " );
  38. spiele->zText()->append( statistik->hat( 0 ) ? statistik->get( 0 ) : 0 );
  39. gewonnen = initTextFeld( 410, 1, 90, 20, zSchrift, TextFeld::Style::Text | TextFeld::Style::Center, "Gewonnen: " );
  40. gewonnen->zText()->append( statistik->hat( 1 ) ? statistik->get( 1 ) : 0 );
  41. statistik->release();
  42. farbe = initTextFeld( 500, 1, 50, 20, zSchrift, TextFeld::Style::Text | TextFeld::Style::Center, "Farbe:" );
  43. spielerFarbe = 0;
  44. rahmen = new LRahmen();
  45. rahmen->setSize( 581, 22 );
  46. rahmen->setFarbe( 0xFFFFFFFF );
  47. rahmen->setRamenBreite( 1 );
  48. teamName = new Text( "" );
  49. this->sts = sts;
  50. rend = 0;
  51. ref = 1;
  52. }
  53. // Destruktor
  54. TeamAuswahlListeSpieler::~TeamAuswahlListeSpieler()
  55. {
  56. name->release();
  57. if( accountId == loginClient->getAccountId() )
  58. teamAuswahl->release();
  59. else
  60. team->release();
  61. punkte->release();
  62. spiele->release();
  63. gewonnen->release();
  64. farbe->release();
  65. rahmen->release();
  66. teamName->release();
  67. sts->release();
  68. }
  69. // nicht constant
  70. void TeamAuswahlListeSpieler::disable()
  71. {
  72. if( accountId == loginClient->getAccountId() )
  73. teamAuswahl->removeStyle( AuswahlBox::Style::Erlaubt );
  74. }
  75. void TeamAuswahlListeSpieler::spielerTeamAuswahlE( AuswahlBox *obj, int p1, int p2 )
  76. {
  77. Text *tmpTeamName = obj->zEintragText( p2 );
  78. if( !tmpTeamName->istGleich( teamName->getText() ) )
  79. {
  80. if( tmpTeamName->istGleich( "Zufällig" ) )
  81. {
  82. if( !spielClient->spielErstelltTeamWechseln( 0 ) )
  83. obj->setAuswahl( obj->getEintragPos( teamName->getText() ) );
  84. }
  85. else
  86. {
  87. int neuTeam = 0;
  88. for( int i = 0; i < sts->teamAnzahl; i++ )
  89. {
  90. if( sts->teamName->z( i )->istGleich( tmpTeamName->getText() ) )
  91. {
  92. neuTeam = i + 1;
  93. break;
  94. }
  95. }
  96. if( !spielClient->spielErstelltTeamWechseln( neuTeam ) )
  97. obj->setAuswahl( obj->getEintragPos( teamName->getText() ) );
  98. }
  99. obj->einklappen();
  100. }
  101. }
  102. void TeamAuswahlListeSpieler::setFarbe( int farbe )
  103. {
  104. this->spielerFarbe = farbe;
  105. if( farbe )
  106. rahmen->setFarbe( farbe );
  107. else
  108. rahmen->setFarbe( 0xFFFFFFFF );
  109. rend = 1;
  110. }
  111. void TeamAuswahlListeSpieler::setTeam( Text *zName )
  112. {
  113. teamName->setText( zName->getText() );
  114. rend = 1;
  115. }
  116. void TeamAuswahlListeSpieler::setTeamErlaubt( Text *zName, bool erlaubt, int teamFarbe )
  117. {
  118. if( accountId != loginClient->getAccountId() )
  119. return;
  120. if( erlaubt )
  121. {
  122. if( teamAuswahl->getEintragPos( zName->getText() ) < 0 )
  123. {
  124. int p = teamAuswahl->getEintragAnzahl();
  125. teamAuswahl->addEintrag( zName->getText() );
  126. teamAuswahl->setMsStyle( p, AuswahlBox::Style::FeldRahmen | AuswahlBox::Style::MausBuffer | AuswahlBox::Style::AuswahlBuffer | AuswahlBox::Style::FeldBuffer );
  127. if( teamFarbe )
  128. teamAuswahl->zEintrag( p )->setRahmenFarbe( teamFarbe );
  129. teamAuswahl->setMsAuswAlphaFeldFarbe( p, 0x50000000 | ( teamFarbe & 0x00FFFFFF ) );
  130. teamAuswahl->setMsAuswAlphaFeldStrength( p, -15 );
  131. teamAuswahl->setMsMausAlphaFeldFarbe( p, 0x10000000 | ( teamFarbe & 0x00FFFFFF ) );
  132. teamAuswahl->setMsMausAlphaFeldStrength( p, -15 );
  133. }
  134. }
  135. else
  136. {
  137. if( zName->istGleich( teamName->getText() ) )
  138. return;
  139. if( teamAuswahl->getEintragPos( zName->getText() ) >= 0 )
  140. teamAuswahl->removeEintrag( teamAuswahl->getEintragPos( zName->getText() ) );
  141. }
  142. }
  143. bool TeamAuswahlListeSpieler::tick( double tickVal )
  144. {
  145. if( accountId == loginClient->getAccountId() )
  146. rend |= teamAuswahl->tick( tickVal );
  147. else if( !team->zText()->istGleich( teamName->getText() ) )
  148. {
  149. team->setText( "" );
  150. team->zText()->append( teamName->getText() );
  151. }
  152. bool ret = rend;
  153. rend = 0;
  154. return ret;
  155. }
  156. void TeamAuswahlListeSpieler::doMausEreignis( MausEreignis &me )
  157. {
  158. if( accountId == loginClient->getAccountId() )
  159. teamAuswahl->doMausEreignis( me );
  160. }
  161. void TeamAuswahlListeSpieler::render( int yOff, Bild &zRObj )
  162. {
  163. if( !zRObj.setDrawOptions( 0, yOff, 581, 22 ) )
  164. return;
  165. rahmen->render( zRObj );
  166. name->render( zRObj );
  167. if( loginClient->getAccountId() == accountId )
  168. teamAuswahl->render( zRObj );
  169. else
  170. team->render( zRObj );
  171. punkte->render( zRObj );
  172. spiele->render( zRObj );
  173. gewonnen->render( zRObj );
  174. farbe->render( zRObj );
  175. zRObj.alphaRegion( 550, 2, 18, 18, spielerFarbe );
  176. zRObj.releaseDrawOptions();
  177. }
  178. // constant
  179. int TeamAuswahlListeSpieler::getAccountId() const
  180. {
  181. return accountId;
  182. }
  183. // Reference Counting
  184. TeamAuswahlListeSpieler *TeamAuswahlListeSpieler::getThis()
  185. {
  186. ref++;
  187. return this;
  188. }
  189. TeamAuswahlListeSpieler *TeamAuswahlListeSpieler::release()
  190. {
  191. ref--;
  192. if( !ref )
  193. delete this;
  194. return 0;
  195. }
  196. // Inhalt der TeamAuswahlListeTeam Klasse aus TeamAuswahl.h
  197. // Konstruktor
  198. TeamAuswahlListeTeam::TeamAuswahlListeTeam( Schrift *zSchrift )
  199. {
  200. maxSpieler = 0;
  201. jetztSpieler = 0;
  202. team = 0;
  203. name = initTextFeld( 0, 0, 300, 20, zSchrift, TextFeld::Style::Text | TextFeld::Style::Center, "Team: " );
  204. mjSpieler = initTextFeld( 300, 0, 150, 20, zSchrift, TextFeld::Style::Text | TextFeld::Style::Center, "Spieler: 0/0" );
  205. farbe = initTextFeld( 450, 0, 100, 20, zSchrift, TextFeld::Style::Text | TextFeld::Style::Center, "Team Farbe:" );
  206. teamFarbe = 0;
  207. spieler = new RCArray< TeamAuswahlListeSpieler >();
  208. rahmen = new LRahmen();
  209. rahmen->setSize( 583, 22 );
  210. rahmen->setFarbe( 0xFFFFFFFF );
  211. rahmen->setRamenBreite( 1 );
  212. titelAf = new AlphaFeld();
  213. titelAf->setPosition( 1, 1 );
  214. titelAf->setSize( 581, 20 );
  215. titelAf->setFarbe( 0x1000FF00 );
  216. titelAf->setStrength( -15 );
  217. teamName = new Text( "" );
  218. tickVal = 0;
  219. höhe = 22;
  220. rend = 0;
  221. ref = 1;
  222. }
  223. // Destruktor
  224. TeamAuswahlListeTeam::~TeamAuswahlListeTeam()
  225. {
  226. name->release();
  227. mjSpieler->release();
  228. farbe->release();
  229. spieler->release();
  230. rahmen->release();
  231. titelAf->release();
  232. teamName->release();
  233. }
  234. // nicht constant
  235. void TeamAuswahlListeTeam::disable()
  236. {
  237. for( int i = 0; i < jetztSpieler; i++ )
  238. spieler->z( i )->disable();
  239. }
  240. void TeamAuswahlListeTeam::setMaxSpieler( int maxSpieler )
  241. {
  242. this->maxSpieler = maxSpieler;
  243. rend = 1;
  244. }
  245. void TeamAuswahlListeTeam::setName( Text *name )
  246. {
  247. teamName->setText( name->getText() );
  248. name->release();
  249. rend = 1;
  250. }
  251. void TeamAuswahlListeTeam::setFarbe( int farbe )
  252. {
  253. teamFarbe = farbe;
  254. rahmen->setFarbe( teamFarbe );
  255. rend = 1;
  256. }
  257. void TeamAuswahlListeTeam::setTeam( int team )
  258. {
  259. this->team = team;
  260. rend = 1;
  261. }
  262. void TeamAuswahlListeTeam::addSpieler( TeamAuswahlListeSpieler *spieler )
  263. {
  264. if( !jetztSpieler )
  265. höhe++;
  266. spieler->setTeam( teamName );
  267. höhe += 22;
  268. this->spieler->set( spieler, jetztSpieler );
  269. jetztSpieler++;
  270. rend = 1;
  271. }
  272. void TeamAuswahlListeTeam::removeSpieler( int accountId )
  273. {
  274. höhe -= 22;
  275. for( int i = 0; i < jetztSpieler; i++ )
  276. {
  277. if( spieler->z( i )->getAccountId() == accountId )
  278. {
  279. jetztSpieler--;
  280. spieler->remove( i );
  281. rend = 1;
  282. break;
  283. }
  284. }
  285. if( !jetztSpieler )
  286. höhe = 22;
  287. }
  288. void TeamAuswahlListeTeam::setTeamErlaubt( Text *zName, bool erlaubt, int teamFarbe )
  289. {
  290. for( int i = 0; i < jetztSpieler; i++ )
  291. spieler->z( i )->setTeamErlaubt( zName, erlaubt, teamFarbe );
  292. }
  293. bool TeamAuswahlListeTeam::tick( double tickVal )
  294. {
  295. this->tickVal += tickVal * 50;
  296. int val = ( int )this->tickVal;
  297. if( val > 2 )
  298. val = 2;
  299. this->tickVal -= val;
  300. if( val )
  301. {
  302. if( rahmen->getHeight() > höhe )
  303. {
  304. rahmen->setSize( rahmen->getBreite(), rahmen->getHeight() - val );
  305. if( rahmen->getHeight() < höhe )
  306. rahmen->setSize( rahmen->getBreite(), höhe );
  307. rend = 1;
  308. }
  309. if( rahmen->getHeight() < höhe )
  310. {
  311. rahmen->setSize( rahmen->getBreite(), rahmen->getHeight() + val );
  312. if( rahmen->getHeight() > höhe )
  313. rahmen->setSize( rahmen->getBreite(), höhe );
  314. rend = 1;
  315. }
  316. }
  317. name->setText( "Team: " );
  318. name->zText()->append( teamName->getText() );
  319. mjSpieler->setText( "Spieler: " );
  320. mjSpieler->zText()->append( jetztSpieler );
  321. mjSpieler->zText()->append( "/" );
  322. mjSpieler->zText()->append( maxSpieler );
  323. for( int i = 0; i < jetztSpieler; i++ )
  324. rend |= spieler->z( i )->tick( tickVal );
  325. bool ret = rend;
  326. rend = 0;
  327. return ret;
  328. }
  329. void TeamAuswahlListeTeam::doMausEreignis( MausEreignis &me )
  330. {
  331. int tmpX = me.mx;
  332. int tmpY = me.my;
  333. me.mx--;
  334. me.my -= 22;
  335. for( int i = 0; i < jetztSpieler; i++ )
  336. {
  337. spieler->z( i )->doMausEreignis( me );
  338. me.my -= 22;
  339. }
  340. me.mx = tmpX;
  341. me.my = tmpY;
  342. }
  343. void TeamAuswahlListeTeam::render( int yOff, Bild &zRObj )
  344. {
  345. if( !zRObj.setDrawOptions( 50, yOff, 583, rahmen->getHeight() + 1 ) )
  346. return;
  347. rahmen->render( zRObj );
  348. titelAf->setPosition( 1, 1 );
  349. titelAf->render( zRObj );
  350. name->render( zRObj );
  351. mjSpieler->render( zRObj );
  352. farbe->render( zRObj );
  353. zRObj.alphaRegion( 550, 2, 18, 18, teamFarbe );
  354. zRObj.drawLinieH( 1, 21, 581, rahmen->getFarbe() );
  355. if( !zRObj.setDrawOptions( 1, 22, 582, rahmen->getHeight() ) )
  356. {
  357. zRObj.releaseDrawOptions();
  358. return;
  359. }
  360. int y = 22 * ( jetztSpieler - 1 );
  361. for( int i = jetztSpieler - 1; i >= 0; i-- )
  362. {
  363. spieler->z( i )->render( y, zRObj );
  364. y -= 22;
  365. }
  366. zRObj.releaseDrawOptions();
  367. zRObj.releaseDrawOptions();
  368. }
  369. // constant
  370. int TeamAuswahlListeTeam::getTeamNummer() const
  371. {
  372. return team;
  373. }
  374. int TeamAuswahlListeTeam::getHeight() const
  375. {
  376. return rahmen->getHeight() + 1;
  377. }
  378. bool TeamAuswahlListeTeam::istPlatzFrei() const
  379. {
  380. return jetztSpieler < maxSpieler;
  381. }
  382. int TeamAuswahlListeTeam::getMaxSpieler() const
  383. {
  384. return maxSpieler;
  385. }
  386. Text *TeamAuswahlListeTeam::zName() const
  387. {
  388. return teamName;
  389. }
  390. TeamAuswahlListeSpieler *TeamAuswahlListeTeam::getSpielerDaten( int accountId ) const
  391. {
  392. for( int i = 0; i < jetztSpieler; i++ )
  393. {
  394. if( spieler->z( i )->getAccountId() == accountId )
  395. return spieler->get( i );
  396. }
  397. return 0;
  398. }
  399. TeamAuswahlListeSpieler *TeamAuswahlListeTeam::zSpielerDaten( int accountId ) const
  400. {
  401. for( int i = 0; i < jetztSpieler; i++ )
  402. {
  403. if( spieler->z( i )->getAccountId() == accountId )
  404. return spieler->z( i );
  405. }
  406. return 0;
  407. }
  408. // Reference Counting
  409. TeamAuswahlListeTeam *TeamAuswahlListeTeam::getThis()
  410. {
  411. ref++;
  412. return this;
  413. }
  414. TeamAuswahlListeTeam *TeamAuswahlListeTeam::release()
  415. {
  416. ref--;
  417. if( !ref )
  418. delete this;
  419. return 0;
  420. }
  421. // Inhalt der TeamAuswahlListe Klasse aus TeamAuswahl.h
  422. // Konstruktor
  423. TeamAuswahlListe::TeamAuswahlListe( Schrift *zSchrift, SpielerTeamStruktur *sts, int karteId )
  424. {
  425. rahmen = new LRahmen();
  426. rahmen->setSize( 698, 398 );
  427. rahmen->setFarbe( 0xFFFFFFFF );
  428. rahmen->setRamenBreite( 1 );
  429. scroll = new VScrollBar();
  430. scroll->update( 0, 396 );
  431. scroll->setKlickScroll( 7 );
  432. teams = new RCArray< TeamAuswahlListeTeam >();
  433. TeamAuswahlListeTeam *zufall = new TeamAuswahlListeTeam( zSchrift );
  434. zufall->setTeam( 0 );
  435. zufall->setName( new Text( "Zufällig" ) );
  436. zufall->setMaxSpieler( sts->spielerAnzahl );
  437. teams->set( zufall, 0 );
  438. for( int i = 0; i < sts->teamAnzahl; i++ )
  439. {
  440. TeamAuswahlListeTeam *tmp = new TeamAuswahlListeTeam( zSchrift );
  441. tmp->setTeam( i );
  442. tmp->setName( sts->teamName->get( i ) );
  443. tmp->setFarbe( sts->teamFarbe->hat( i ) ? sts->teamFarbe->get( i ) : 0 );
  444. tmp->setMaxSpieler( sts->teamSize->hat( i ) ? sts->teamSize->get( i ) : 0 );
  445. teams->set( tmp, i + 1 );
  446. }
  447. teamAnzahl = 1 + sts->teamAnzahl;
  448. schrift = zSchrift->getThis();
  449. this->karteId = karteId;
  450. this->sts = sts;
  451. rend = 0;
  452. ref = 1;
  453. }
  454. // Destruktor
  455. TeamAuswahlListe::~TeamAuswahlListe()
  456. {
  457. rahmen->release();
  458. scroll->release();
  459. teams->release();
  460. schrift->release();
  461. sts->release();
  462. }
  463. // nicht constant
  464. void TeamAuswahlListe::disable()
  465. {
  466. for( int i = 0; i < teamAnzahl; i++ )
  467. teams->z( i )->disable();
  468. }
  469. void TeamAuswahlListe::setTeamVonSpieler( int accountId, int spielerNummer )
  470. {
  471. if( spielerNummer == 0 )
  472. {
  473. int neuTeam = 0;
  474. int altTeam = 0;
  475. for( int j = 0; j < teamAnzahl; j++ )
  476. {
  477. if( teams->z( j )->zSpielerDaten( accountId ) )
  478. {
  479. altTeam = j;
  480. break;
  481. }
  482. }
  483. TeamAuswahlListeSpieler *tmp = teams->z( altTeam )->getSpielerDaten( accountId );
  484. teams->z( altTeam )->removeSpieler( accountId );
  485. tmp->setFarbe( 0 );
  486. teams->z( neuTeam )->addSpieler( tmp );
  487. }
  488. else
  489. {
  490. int team = 0;
  491. int max = 0;
  492. int min = 0;
  493. for( int i = 0; i < sts->teamAnzahl; i++ )
  494. {
  495. min = max;
  496. max += sts->teamSize->get( i );
  497. if( spielerNummer - 1 >= min && spielerNummer - 1 < max )
  498. {
  499. int neuTeam = i + 1;
  500. int altTeam = 0;
  501. for( int j = 0; j < teamAnzahl; j++ )
  502. {
  503. if( teams->z( j )->zSpielerDaten( accountId ) )
  504. {
  505. altTeam = j;
  506. break;
  507. }
  508. }
  509. TeamAuswahlListeSpieler *tmp = teams->z( altTeam )->getSpielerDaten( accountId );
  510. teams->z( altTeam )->removeSpieler( accountId );
  511. tmp->setFarbe( sts->spielerFarbe->hat( spielerNummer - 1 ) ? sts->spielerFarbe->get( spielerNummer - 1 ) : 0 );
  512. teams->z( neuTeam )->addSpieler( tmp );
  513. break;
  514. }
  515. }
  516. }
  517. for( int i = 0; i < teamAnzahl; i++ )
  518. {
  519. for( int j = 0; j < teamAnzahl; j++ )
  520. {
  521. if( i == 0 )
  522. teams->z( j )->setTeamErlaubt( teams->z( i )->zName(), teams->z( i )->istPlatzFrei(), 0 );
  523. else
  524. teams->z( j )->setTeamErlaubt( teams->z( i )->zName(), teams->z( i )->istPlatzFrei(), sts->teamFarbe->hat( i - 1 ) ? sts->teamFarbe->get( i - 1 ) : 0 );
  525. }
  526. }
  527. rend = 1;
  528. }
  529. void TeamAuswahlListe::addSpieler( int accountId )
  530. {
  531. TeamAuswahlListeSpieler *tmp = new TeamAuswahlListeSpieler( sts->getThis(), schrift, accountId, karteId );
  532. for( int i = 0; i < teamAnzahl; i++ )
  533. {
  534. if( teams->z( i )->istPlatzFrei() )
  535. {
  536. if( i == 0 )
  537. tmp->setTeamErlaubt( teams->z( i )->zName(), 1, 0 );
  538. else
  539. tmp->setTeamErlaubt( teams->z( i )->zName(), 1, sts->teamFarbe->hat( i - 1 ) ? sts->teamFarbe->get( i - 1 ) : 0 );
  540. }
  541. }
  542. teams->z( 0 )->addSpieler( tmp );
  543. for( int i = 0; i < teamAnzahl; i++ )
  544. teams->z( i )->setTeamErlaubt( teams->z( 0 )->zName(), teams->z( 0 )->istPlatzFrei(), 0 );
  545. rend = 1;
  546. }
  547. void TeamAuswahlListe::removeSpieler( int accountId )
  548. {
  549. for( int i = 0; i < teamAnzahl; i++ )
  550. {
  551. if( teams->z( i )->zSpielerDaten( accountId ) )
  552. teams->z( i )->removeSpieler( accountId );
  553. }
  554. for( int i = 0; i < teamAnzahl; i++ )
  555. {
  556. for( int j = 0; j < teamAnzahl; j++ )
  557. {
  558. if( i == 0 )
  559. teams->z( j )->setTeamErlaubt( teams->z( i )->zName(), teams->z( i )->istPlatzFrei(), 0 );
  560. else
  561. teams->z( j )->setTeamErlaubt( teams->z( i )->zName(), teams->z( i )->istPlatzFrei(), sts->teamFarbe->hat( i - 1 ) ? sts->teamFarbe->get( i - 1 ) : 0 );
  562. }
  563. }
  564. rend = 1;
  565. }
  566. bool TeamAuswahlListe::tick( double tickVal )
  567. {
  568. for( int i = 0; i < teamAnzahl; i++ )
  569. rend |= teams->z( i )->tick( tickVal );
  570. rend |= scroll->getRend();
  571. bool ret = rend;
  572. rend = 0;
  573. return ret;
  574. }
  575. void TeamAuswahlListe::doMausEreignis( MausEreignis &me )
  576. {
  577. int tmpX = me.mx;
  578. int tmpY = me.my;
  579. me.mx -= 50;
  580. me.my -= 50 - scroll->getScroll();
  581. for( int i = 0; i < teamAnzahl; i++ )
  582. {
  583. teams->z( i )->doMausEreignis( me );
  584. me.my -= 20 + teams->z( i )->getHeight();
  585. }
  586. me.mx = tmpX;
  587. me.my = tmpY;
  588. if( me.mx > 1 && me.mx < 698 && me.my > 1 && me.my < 397 )
  589. {
  590. scroll->doMausMessage( 683, 1, 15, 396, me );
  591. me.verarbeitet = 1;
  592. }
  593. }
  594. void TeamAuswahlListe::render( Bild &zRObj )
  595. {
  596. if( !zRObj.setDrawOptions( 0, 0, 698, 398 ) )
  597. return;
  598. rahmen->render( zRObj );
  599. int maxHöhe = 50;
  600. for( int i = 0; i < teamAnzahl; i++ )
  601. maxHöhe += 20 + teams->z( i )->getHeight();
  602. maxHöhe += 30;
  603. scroll->update( maxHöhe, 396 );
  604. scroll->render( 683, 1, 15, 396, zRObj );
  605. if( !zRObj.setDrawOptions( 1, 1, 682, 395 ) )
  606. {
  607. zRObj.releaseDrawOptions();
  608. return;
  609. }
  610. int y = 50 - scroll->getScroll();
  611. for( int i = 0; i < teamAnzahl - 1; i++ )
  612. y += 20 + teams->z( i )->getHeight();
  613. for( int i = teamAnzahl - 1; i >= 0; i-- )
  614. {
  615. teams->z( i )->render( y, zRObj );
  616. if( i > 0 )
  617. y -= 20 + teams->z( i - 1 )->getHeight();
  618. }
  619. zRObj.releaseDrawOptions();
  620. zRObj.releaseDrawOptions();
  621. }
  622. // constant
  623. // Reference Counting
  624. TeamAuswahlListe *TeamAuswahlListe::getThis()
  625. {
  626. ref++;
  627. return this;
  628. }
  629. TeamAuswahlListe *TeamAuswahlListe::release()
  630. {
  631. ref--;
  632. if( !ref )
  633. delete this;
  634. return 0;
  635. }
  636. // Inhalt der TeamAuswahlTimer Klasse aus TeamAuswahl.h
  637. // Konstruktor
  638. TeamAuswahlTimer::TeamAuswahlTimer( Schrift *zSchrift )
  639. {
  640. zeit = initTextFeld( 0, 0, 200, 200, zSchrift, TextFeld::Style::Text | TextFeld::Style::Center, "" );
  641. bestätigen = initKnopf( 65, 170, 70, 20, zSchrift, Knopf::Style::Sichtbar, "Fertig" );
  642. time = 0;
  643. maxTime = 0;
  644. grad = 0;
  645. rend = 0;
  646. ref = 1;
  647. }
  648. // Destruktor
  649. TeamAuswahlTimer::~TeamAuswahlTimer()
  650. {
  651. zeit->release();
  652. bestätigen->release();
  653. }
  654. // nicht constant
  655. void TeamAuswahlTimer::setVerbleibendeZeit( int sekunden )
  656. {
  657. if( !maxTime )
  658. maxTime = sekunden;
  659. if( time != sekunden )
  660. rend = 1;
  661. time = sekunden;
  662. }
  663. bool TeamAuswahlTimer::doMausEreignis( MausEreignis &me )
  664. {
  665. bool vera = me.verarbeitet;
  666. bestätigen->doMausEreignis( me );
  667. if( !vera && me.verarbeitet && me.id == ME_RLinks )
  668. {
  669. if( spielClient->spielErstelltTeamFertig() )
  670. {
  671. bestätigen->removeStyle( Knopf::Style::Erlaubt );
  672. return 1;
  673. }
  674. }
  675. return 0;
  676. }
  677. bool TeamAuswahlTimer::tick( double tickVal )
  678. {
  679. zeit->setText( "" );
  680. zeit->zText()->append( time );
  681. grad += ( tickVal * 2 );
  682. rend = 1;
  683. if( grad > 360 )
  684. grad -= 360;
  685. bool ret = rend;
  686. rend = 0;
  687. return ret;
  688. }
  689. void TeamAuswahlTimer::render( Bild &zRObj )
  690. {
  691. if( !zRObj.setDrawOptions( 498, 398, 200, 200 ) )
  692. return;
  693. zeit->render( zRObj );
  694. int r = ( maxTime && time ) ? 90 - (int)( 75.0 / ( (double)maxTime / ( maxTime - time ) ) + 0.5 ) : 15;
  695. zRObj.drawKreis( 100, 100, 15, 0xFFFF0000 );
  696. zRObj.drawKreis( 100, 100, r, 0xFF00FF00 );
  697. int x1 = 100 + (int)( sin( grad ) * 15 );
  698. int y1 = 100 + (int)( cos( grad ) * 15 );
  699. int x2 = 100 + (int)( sin( grad ) * r );
  700. int y2 = 100 + (int)( cos( grad ) * r );
  701. zRObj.drawLinie( Punkt( x1, y1 ), Punkt( x2, y2 ), 0xFFFFFF00 );
  702. bestätigen->render( zRObj );
  703. zRObj.releaseDrawOptions();
  704. }
  705. // constant
  706. int TeamAuswahlTimer::getZeit() const
  707. {
  708. return time;
  709. }
  710. // Reference Counting
  711. TeamAuswahlTimer *TeamAuswahlTimer::getThis()
  712. {
  713. ref++;
  714. return this;
  715. }
  716. TeamAuswahlTimer *TeamAuswahlTimer::release()
  717. {
  718. ref--;
  719. if( !ref )
  720. delete this;
  721. return 0;
  722. }
  723. // Inhalt der TeamAuswahlChat Klasse aus TeamAuswahl.h
  724. // Konstruktor
  725. TeamAuswahlChat::TeamAuswahlChat( Schrift *zSchrift )
  726. {
  727. nachricht = initTextFeld( 2, 178, 472, 20, zSchrift, TextFeld::Style::TextFeld, "" );
  728. Bild *sendenBild = bilder->get( "chat.ltdb/senden.png" );
  729. if( !sendenBild )
  730. {
  731. LTDBDatei *datei = new LTDBDatei();
  732. datei->setDatei( new Text( "data/client/bilder/chat.ltdb" ) );
  733. datei->leseDaten( 0 );
  734. sendenBild = datei->laden( 0, new Text( "senden.png" ) );
  735. datei->release();
  736. bilder->add( "chat.ltdb/senden.png", sendenBild->getThis() );
  737. }
  738. senden = initKnopf( 476, 178, 20, 20, 0, 0, "" );
  739. senden->setStyle( Knopf::Style::Sichtbar | Knopf::Style::Erlaubt | Knopf::Style::Hintergrund | Knopf::Style::HAlpha | Knopf::Style::HBild | Knopf::Style::KlickBuffer );
  740. senden->setHintergrundBildZ( sendenBild );
  741. verlauf = initTextFeld( 2, 2, 494, 174, zSchrift, TextFeld::Style::TextGebiet & ~TextFeld::Style::Erlaubt, "" );
  742. verlauf->updateVScroll();
  743. verlauf->setVertikalKlickScroll( 5 );
  744. rahmen = new LRahmen();
  745. rahmen->setSize( 498, 200 );
  746. rahmen->setFarbe( 0xFFFFFFFF );
  747. rahmen->setRamenBreite( 1 );
  748. rend = 0;
  749. ref = 1;
  750. }
  751. // Destruktor
  752. TeamAuswahlChat::~TeamAuswahlChat()
  753. {
  754. nachricht->release();
  755. senden->release();
  756. verlauf->release();
  757. rahmen->release();
  758. }
  759. // nicht constant
  760. void TeamAuswahlChat::addNachricht( char *nachricht )
  761. {
  762. verlauf->addZeile( nachricht );
  763. verlauf->updateVScroll();
  764. rend = 1;
  765. }
  766. bool TeamAuswahlChat::tick( double tickVal )
  767. {
  768. rend |= verlauf->tick( tickVal );
  769. rend |= nachricht->tick( tickVal );
  770. rend |= senden->tick( tickVal );
  771. bool ret = rend;
  772. rend = 0;
  773. return ret;
  774. }
  775. void TeamAuswahlChat::doMausEreignis( MausEreignis &me )
  776. {
  777. verlauf->doMausEreignis( me );
  778. nachricht->doMausEreignis( me );
  779. bool ver = !me.verarbeitet;
  780. senden->doMausEreignis( me );
  781. int aktion = ( ver && me.verarbeitet && me.id == ME_RLinks ) ? 1 : 0;
  782. if( aktion == 1 )
  783. { // Nachricht senden
  784. if( spielClient->spielErstelltChatNachricht( nachricht->zText()->getText() ) )
  785. {
  786. nachricht->setText( "" );
  787. nachricht->setAuswahl( 0, 0 );
  788. rend = 1;
  789. }
  790. else
  791. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ), new Text( spielClient->getLetzterFehler() ), new Text( "Ok" ), 0 );
  792. }
  793. }
  794. void TeamAuswahlChat::doTastaturEreignis( TastaturEreignis &te )
  795. {
  796. bool ver = !te.verarbeitet;
  797. nachricht->doTastaturEreignis( te );
  798. int aktion = ( ver && te.verarbeitet && te.id == TE_Release && te.taste == T_Enter ) ? 1 : 0;
  799. if( aktion == 1 )
  800. { // Nachricht senden
  801. if( spielClient->spielErstelltChatNachricht( nachricht->zText()->getText() ) )
  802. {
  803. nachricht->setText( "" );
  804. nachricht->setAuswahl( 0, 0 );
  805. rend = 1;
  806. }
  807. else
  808. nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ), new Text( spielClient->getLetzterFehler() ), new Text( "Ok" ), 0 );
  809. }
  810. }
  811. void TeamAuswahlChat::render( Bild &zRObj )
  812. {
  813. if( !zRObj.setDrawOptions( 0, 398, 498, 200 ) )
  814. return;
  815. rahmen->render( zRObj );
  816. verlauf->render( zRObj );
  817. nachricht->render( zRObj );
  818. senden->render( zRObj );
  819. zRObj.releaseDrawOptions();
  820. }
  821. // constant
  822. // Reference Counting
  823. TeamAuswahlChat *TeamAuswahlChat::getThis()
  824. {
  825. ref++;
  826. return this;
  827. }
  828. TeamAuswahlChat *TeamAuswahlChat::release()
  829. {
  830. ref--;
  831. if( !ref )
  832. delete this;
  833. return 0;
  834. }
  835. // Inhalt der TeamAuswahl Klasse aus TeamAuswahl.h
  836. // Konstruktor
  837. TeamAuswahl::TeamAuswahl( Schrift *zSchrift )
  838. {
  839. tickVal = 0;
  840. animation = 0;
  841. sichtbar = 0;
  842. alpha = 0;
  843. karteId = 0;
  844. sts = 0;
  845. chat = 0;
  846. timer = 0;
  847. liste = 0;
  848. schrift = zSchrift->getThis();
  849. rend = 0;
  850. ref = 1;
  851. }
  852. // Destruktor
  853. TeamAuswahl::~TeamAuswahl()
  854. {
  855. if( sichtbar )
  856. setSichtbar( 0 );
  857. if( chat )
  858. chat->release();
  859. if( timer )
  860. timer->release();
  861. if( liste )
  862. liste->release();
  863. if( sts )
  864. sts->release();
  865. if( schrift )
  866. schrift->release();
  867. }
  868. // nicht constant
  869. void TeamAuswahl::setKarteId( int karteId )
  870. {
  871. this->karteId = karteId;
  872. }
  873. void TeamAuswahl::setSichtbar( bool sichtbar, bool sofort )
  874. {
  875. this->sichtbar = sichtbar;
  876. if( sichtbar )
  877. animation |= 0x1;
  878. else
  879. {
  880. if( sofort )
  881. alpha = 0;
  882. else
  883. animation &= ~0x1;
  884. }
  885. rend = 1;
  886. }
  887. void TeamAuswahl::initSTS( SpielerTeamStruktur *sts )
  888. {
  889. hauptScreen->lock();
  890. if( this->sts )
  891. this->sts->release();
  892. this->sts = sts;
  893. if( chat )
  894. chat = chat->release();
  895. if( timer )
  896. timer = timer->release();
  897. if( liste )
  898. liste = liste->release();
  899. chat = new TeamAuswahlChat( schrift );
  900. timer = new TeamAuswahlTimer( schrift );
  901. liste = new TeamAuswahlListe( schrift, sts->getThis(), karteId );
  902. hauptScreen->unlock();
  903. rend = 1;
  904. }
  905. void TeamAuswahl::addSpieler( int accountId )
  906. {
  907. if( liste )
  908. liste->addSpieler( accountId );
  909. }
  910. void TeamAuswahl::setSpielerNummer( int accountId, int sNummer )
  911. {
  912. if( liste )
  913. liste->setTeamVonSpieler( accountId, sNummer );
  914. }
  915. void TeamAuswahl::removeSpieler( int accountId )
  916. {
  917. if( liste )
  918. liste->removeSpieler( accountId );
  919. }
  920. void TeamAuswahl::verbleibendeZeit( int sekunden )
  921. {
  922. if( timer )
  923. timer->setVerbleibendeZeit( sekunden );
  924. }
  925. void TeamAuswahl::addNachricht( char *nachricht )
  926. {
  927. if( chat )
  928. chat->addNachricht( nachricht );
  929. }
  930. bool TeamAuswahl::tick( double tickVal )
  931. {
  932. if( !sichtbar && !alpha )
  933. return 0;
  934. if( chat )
  935. rend |= chat->tick( tickVal );
  936. if( timer )
  937. rend |= timer->tick( tickVal );
  938. if( liste )
  939. rend |= liste->tick( tickVal );
  940. this->tickVal += tickVal * 150;
  941. int val = ( int )this->tickVal;
  942. if( !val )
  943. {
  944. bool ret = rend;
  945. rend = 0;
  946. return ret;
  947. }
  948. if( val > 5 )
  949. val = 5;
  950. this->tickVal -= val;
  951. if( ( animation | 0x1 ) == animation ) // sichtbar werden
  952. {
  953. if( alpha != 255 )
  954. {
  955. if( alpha + val < 255 )
  956. alpha += val;
  957. else
  958. alpha = 255;
  959. rend = 1;
  960. }
  961. }
  962. else // unsichtbar werden
  963. {
  964. if( alpha != 0 )
  965. {
  966. if( alpha - val >= 0 )
  967. alpha -= val;
  968. else
  969. alpha = 0;
  970. rend = 1;
  971. }
  972. }
  973. bool ret = rend;
  974. rend = 0;
  975. return ret;
  976. }
  977. void TeamAuswahl::doMausEreignis( MausEreignis &me )
  978. {
  979. if( !alpha )
  980. return;
  981. if( liste )
  982. liste->doMausEreignis( me );
  983. if( chat )
  984. {
  985. me.my -= 398;
  986. chat->doMausEreignis( me );
  987. me.mx -= 498;
  988. if( timer->doMausEreignis( me ) )
  989. liste->disable();
  990. me.my += 398;
  991. me.mx += 498;
  992. }
  993. }
  994. void TeamAuswahl::doTastaturEreignis( TastaturEreignis &te )
  995. {
  996. if( !alpha )
  997. return;
  998. if( chat )
  999. chat->doTastaturEreignis( te );
  1000. }
  1001. void TeamAuswahl::render( Bild &zRObj )
  1002. {
  1003. if( !alpha )
  1004. return;
  1005. if( !zRObj.setDrawOptions( 0, 0, 700, 600 ) )
  1006. return;
  1007. zRObj.setAlpha( alpha );
  1008. if( timer )
  1009. timer->render( zRObj );
  1010. if( chat )
  1011. chat->render( zRObj );
  1012. if( liste )
  1013. liste->render( zRObj );
  1014. zRObj.releaseAlpha();
  1015. zRObj.releaseDrawOptions();
  1016. }
  1017. // constant
  1018. bool TeamAuswahl::istSichtbar() const
  1019. {
  1020. return sichtbar;
  1021. }
  1022. int TeamAuswahl::getKarteId() const
  1023. {
  1024. return karteId;
  1025. }
  1026. SpielerTeamStruktur *TeamAuswahl::getSTS() const
  1027. {
  1028. return sts->getThis();
  1029. }
  1030. // Reference Counting
  1031. TeamAuswahl *TeamAuswahl::getThis()
  1032. {
  1033. ref++;
  1034. return this;
  1035. }
  1036. TeamAuswahl *TeamAuswahl::release()
  1037. {
  1038. ref--;
  1039. if( !ref )
  1040. delete this;
  1041. return 0;
  1042. }
  1043. // Event Aktionen
  1044. void TeamAuswahlListeSpielerTeamAuswahlE( void *p, AuswahlBox *obj, int p1, int p2 )
  1045. {
  1046. if( !p )
  1047. return;
  1048. ( (TeamAuswahlListeSpieler*)p )->spielerTeamAuswahlE( obj, p1, p2 );
  1049. }