TeamAuswahl.cpp 28 KB

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