#include "AccountSpieleUndKarten.h" #include "../../../Global/Initialisierung.h" #include "../../../Global/Variablen.h" #include #include #include #include #include // Inhalt der AccountSUKListeKarte Klasse aus AccountSpieleUndKarten.h // Konstruktor AccountSUKListeKarte::AccountSUKListeKarte(int id, int account) : ReferenceCounter(), ram(new LRahmen()), name(initTextFeld(5, 0, 150, 20, TextFeld::Style::Text | TextFeld::Style::Center, "Karte: ")), spiele(initTextFeld(165, 0, 150, 20, TextFeld::Style::Text | TextFeld::Style::Center, "Spiele: ")), gewonnen(initTextFeld(325, 0, 150, 20, TextFeld::Style::Text | TextFeld::Style::Center, "Gewonnen: ")), status(initTextFeld(485, 0, 150, 20, TextFeld::Style::Text | TextFeld::Style::Center, "Status: ")), st(new Text()), karteId(id), rend(0) { na = infoClient->getKarteName(id); if (na) name->zText()->append(na->getText()); sp = infoClient->getAccountKarteSpiele(account, id); spiele->zText()->append(sp); gw = infoClient->getAccountKarteSpieleGewonnen(account, id); gewonnen->zText()->append(gw); if (infoClient->hatAccountKarte(account, id)) st->setText("Im Besitz"); else st->setText("Nicht im Besitz"); status->zText()->append(st->getText()); ram->setFarbe(0xFFFFFFFF); ram->setSize(715, 20); ram->setRamenBreite(1); } // Destruktor AccountSUKListeKarte::~AccountSUKListeKarte() { ram->release(); name->release(); spiele->release(); gewonnen->release(); status->release(); if (na) na->release(); st->release(); } // nicht constant void AccountSUKListeKarte::render(int yOff, Bild& zRObj) { if (!zRObj.setDrawOptions(5, yOff, ram->getBreite(), ram->getHeight())) return; name->render(zRObj); spiele->render(zRObj); gewonnen->render(zRObj); status->render(zRObj); ram->render(zRObj); zRObj.releaseDrawOptions(); } // constant Text* AccountSUKListeKarte::zName() const { return na; } int AccountSUKListeKarte::getSpiele() const { return sp; } int AccountSUKListeKarte::getGewonnen() const { return gw; } Text* AccountSUKListeKarte::zStatus() const { return st; } // Inhalt der AccountSUKListeSpiel Klasse aus AccountSpieleUndKarten.h // Konstruktor AccountSUKListeSpiel::AccountSUKListeSpiel(int id, int account) : ReferenceCounter(), ram(new LRahmen()), nameTF(initTextFeld(5, 0, 150, 20, TextFeld::Style::Text | TextFeld::Style::Center, "Name: ")), spieleTF(initTextFeld(165, 0, 150, 20, TextFeld::Style::Text | TextFeld::Style::Center, "Spiele: ")), gewonnenTF(initTextFeld(325, 0, 100, 20, TextFeld::Style::Text | TextFeld::Style::Center, "Gewonnen: ")), punkteTF(initTextFeld(435, 0, 100, 20, TextFeld::Style::Text | TextFeld::Style::Center, "Punkte: ")), statusTF(initTextFeld(545, 0, 150, 20, TextFeld::Style::Text | TextFeld::Style::Center, "Status: ")), details(initKnopf(705, 0, 20, 20, 0, "")), karten(new RCArray< AccountSUKListeKarte >()), einklappen(bilder->get("data/client/bilder/account.ltdb/einklappen.png")), ausklappen(bilder->get("data/client/bilder/account.ltdb/ausklappen.png")), status(new Text()), statusFilter(new Text("Alle")), sortSpalte(new Text("Name")), sortAbsteigend(0), spielId(id), tickVal(0), rend(0) { ram->setFarbe(0xFFFFFFFF); ram->setRamenBreite(1); ram->setSize(725, 20); details->setStyle(Knopf::Style::Sichtbar | Knopf::Style::Erlaubt | Knopf::Style::Hintergrund | Knopf::Style::HAlpha | Knopf::Style::HBild | Knopf::Style::KlickBuffer); details->setHintergrundBildZ(dynamic_cast(ausklappen->getThis())); initToolTip(details, "Karten anzeigen."); name = infoClient->getSpielName(id); if (name) nameTF->zText()->append(name->getText()); Array< int >* stat = new Array< int >(); if (infoClient->getSpielStatistik(account, id, stat)) { spiele = stat->get(0); gewonnen = stat->get(1); punkte = stat->get(3); } stat->release(); spieleTF->zText()->append(spiele); gewonnenTF->zText()->append(gewonnen); punkteTF->zText()->append(punkte); if (infoClient->hatAccountSpiel(account, id)) status->setText("Im Besitz"); else status->setText("Nicht im Besitz"); statusTF->zText()->append(status->getText()); Array< int >* maps = infoClient->getAccountKarteGespieltListe(account, id); if (maps) { int anz = maps->getEintragAnzahl(); for (int i = 0; i < anz; i++) karten->set(new AccountSUKListeKarte(maps->get(i), account), i); maps->release(); } } // Destruktor AccountSUKListeSpiel::~AccountSUKListeSpiel() { ram->release(); nameTF->release(); spieleTF->release(); gewonnenTF->release(); punkteTF->release(); statusTF->release(); details->release(); karten->release(); einklappen->release(); ausklappen->release(); if (name) name->release(); status->release(); statusFilter->release(); sortSpalte->release(); } // privat int AccountSUKListeSpiel::getReihenfolge(int* arr) { int anz = karten->getEintragAnzahl(); if (!anz) return 0; int ret = 0; bool* fertig = new bool[anz]; ZeroMemory(fertig, anz); for (int i = 0; i < anz; i++) { int index = -1; int minMax = 0; Text minMaxT; for (int j = 0; j < anz; j++) { AccountSUKListeKarte* tmp = karten->z(j); if (!statusFilter->istGleich("Alle") && !tmp->zStatus()->istGleich(statusFilter->getText())) continue; if (sortSpalte->istGleich("Name") && !fertig[j] && (index < 0 || (sortAbsteigend && *tmp->zName() > minMaxT) || (!sortAbsteigend && *tmp->zName() < minMaxT))) { minMaxT = tmp->zName()->getText(); index = j; } else if (sortSpalte->istGleich("Spiele") && !fertig[j] && (index < 0 || (sortAbsteigend && tmp->getSpiele() > minMax) || (!sortAbsteigend && tmp->getSpiele() < minMax))) { minMax = tmp->getSpiele(); index = j; } else if (sortSpalte->istGleich("Gewonnen") && !fertig[j] && (index < 0 || (sortAbsteigend && tmp->getGewonnen() > minMax) || (!sortAbsteigend && tmp->getGewonnen() < minMax))) { minMax = tmp->getGewonnen(); index = j; } else if (sortSpalte->istGleich("Status") && !fertig[j] && (index < 0 || (sortAbsteigend && *tmp->zStatus() > minMaxT) || (!sortAbsteigend && *tmp->zStatus() < minMaxT))) { minMaxT = tmp->zStatus()->getText(); index = j; } else if (sortSpalte->istGleich("Punkte") && !fertig[j]) { index = j; break; } } if (index < 0) break; fertig[index] = 1; arr[ret] = index; ret++; } delete[] fertig; return ret; } // nicht constant void AccountSUKListeSpiel::setStatusAusw(const char* status) { statusFilter->setText(status); rend = 1; } void AccountSUKListeSpiel::setSortSpalte(const char* spalte) { sortSpalte->setText(spalte); rend = 1; } void AccountSUKListeSpiel::setSortRichtung(bool absteigend) { sortAbsteigend = absteigend; rend = 1; } bool AccountSUKListeSpiel::tick(double tickVal) { rend |= details->tick(tickVal); this->tickVal += tickVal * 150; int val = (int)this->tickVal; this->tickVal -= val; if (val) { if (details->zHintergrundBild() == ausklappen && ram->getHeight() != 20) { if (ram->getHeight() - val < 20) ram->setSize(ram->getBreite(), 20); else ram->setSize(ram->getBreite(), ram->getHeight() - val); rend = 1; } if (details->zHintergrundBild() == einklappen) { int maxHö = 20; int anz = karten->getEintragAnzahl(); for (int i = 0; i < anz; i++) { AccountSUKListeKarte* tmp = karten->z(i); if (!statusFilter->istGleich("Alle") && !tmp->zStatus()->istGleich(statusFilter->getText())) continue; maxHö += 25; } if (maxHö > 20) maxHö += 5; if (ram->getHeight() > maxHö) { if (ram->getHeight() - val < maxHö) ram->setSize(ram->getBreite(), maxHö); else ram->setSize(ram->getBreite(), ram->getHeight() - val); rend = 1; } if (ram->getHeight() < maxHö) { if (ram->getHeight() + val > maxHö) ram->setSize(ram->getBreite(), maxHö); else ram->setSize(ram->getBreite(), ram->getHeight() + val); rend = 1; } } } bool ret = rend; rend = 0; return ret; } void AccountSUKListeSpiel::doPublicMausEreignis(MausEreignis& me) { bool vera = me.verarbeitet; details->doPublicMausEreignis(me); if (!vera && me.verarbeitet && me.id == ME_RLinks) { if (details->zHintergrundBild() == ausklappen) { details->setHintergrundBildZ(dynamic_cast(einklappen->getThis())); // TODO: details->zToolTip()->setText( "Karten verbergen." ); } else { details->setHintergrundBildZ(dynamic_cast(ausklappen->getThis())); // TODO: details->zToolTip()->setText( "Karten anzeigen." ); } } } void AccountSUKListeSpiel::render(int yOff, Bild& zRObj) { if (!zRObj.setDrawOptions(10, yOff, ram->getBreite(), ram->getHeight())) return; nameTF->render(zRObj); spieleTF->render(zRObj); gewonnenTF->render(zRObj); punkteTF->render(zRObj); statusTF->render(zRObj); details->render(zRObj); ram->render(zRObj); if (ram->getHeight() > 20) { zRObj.drawLinieH(0, 20, ram->getBreite(), ram->getFarbe()); if (!zRObj.setDrawOptions(1, 25, ram->getBreite() - 2, ram->getHeight() - 2)) { zRObj.releaseDrawOptions(); return; } int anz = karten->getEintragAnzahl(); int* arr = new int[anz]; anz = getReihenfolge(arr); yOff = 0; for (int i = 0; i < anz; i++) { karten->z(arr[i])->render(yOff, zRObj); yOff += 25; } delete[]arr; zRObj.releaseDrawOptions(); } zRObj.releaseDrawOptions(); } // constant int AccountSUKListeSpiel::getHeight() const { return ram->getHeight(); } Text* AccountSUKListeSpiel::zName() const { return name; } int AccountSUKListeSpiel::getSpiele() const { return spiele; } int AccountSUKListeSpiel::getGewonnen() const { return gewonnen; } int AccountSUKListeSpiel::getPunkte() const { return punkte; } Text* AccountSUKListeSpiel::zStatus() const { return status; } // Inhalt der AccountSUKListe Klasse aus AccountSpieleUndKarten.h // Konstruktor AccountSUKListe::AccountSUKListe() : Zeichnung(), ram(new LRahmen()), scroll(new VScrollBar()), spiele(new RCArray< AccountSUKListeSpiel >()), status(new Text()), statusFilter(new Text("Alle")), sortSpalte(new Text("Name")), sortAbsteigend(0), rend(0) { pos = Punkt(10, 40); ram->setSize(760, 380); ram->setFarbe(0xFFFFFFFF); ram->setRamenBreite(1); } // Destruktor AccountSUKListe::~AccountSUKListe() { ram->release(); scroll->release(); spiele->release(); status->release(); statusFilter->release(); sortSpalte->release(); } // privat int AccountSUKListe::getReihenfolge(int* arr) { int anz = spiele->getEintragAnzahl(); if (!anz) return 0; int ret = 0; bool* fertig = new bool[anz]; ZeroMemory(fertig, anz); for (int i = 0; i < anz; i++) { int index = -1; int minMax = 0; Text minMaxT; for (int j = 0; j < anz; j++) { AccountSUKListeSpiel* tmp = spiele->z(j); if (!statusFilter->istGleich("Alle") && !tmp->zStatus()->istGleich(statusFilter->getText())) continue; if (sortSpalte->istGleich("Name") && !fertig[j] && (index < 0 || (sortAbsteigend && *tmp->zName() > minMaxT) || (!sortAbsteigend && *tmp->zName() < minMaxT))) { minMaxT = tmp->zName()->getText(); index = j; } else if (sortSpalte->istGleich("Spiele") && !fertig[j] && (index < 0 || (sortAbsteigend && tmp->getSpiele() > minMax) || (!sortAbsteigend && tmp->getSpiele() < minMax))) { minMax = tmp->getSpiele(); index = j; } else if (sortSpalte->istGleich("Gewonnen") && !fertig[j] && (index < 0 || (sortAbsteigend && tmp->getGewonnen() > minMax) || (!sortAbsteigend && tmp->getGewonnen() < minMax))) { minMax = tmp->getGewonnen(); index = j; } else if (sortSpalte->istGleich("Punkte") && !fertig[j] && (index < 0 || (sortAbsteigend && tmp->getPunkte() > minMax) || (!sortAbsteigend && tmp->getPunkte() < minMax))) { minMax = tmp->getPunkte(); index = j; } else if (sortSpalte->istGleich("Status") && !fertig[j] && (index < 0 || (sortAbsteigend && *tmp->zStatus() > minMaxT) || (!sortAbsteigend && *tmp->zStatus() < minMaxT))) { minMaxT = tmp->zStatus()->getText(); index = j; } } if (index < 0) break; fertig[index] = 1; arr[ret] = index; ret++; } delete[] fertig; return ret; } // nicht constant void AccountSUKListe::reset() { lockZeichnung(); spiele->leeren(); unlockZeichnung(); } void AccountSUKListe::addSpiel(AccountSUKListeSpiel* spiel) { lockZeichnung(); spiel->setSortRichtung(sortAbsteigend); spiel->setSortSpalte(sortSpalte->getText()); spiel->setStatusAusw(statusFilter->getText()); spiele->add(spiel); unlockZeichnung(); } void AccountSUKListe::setStatusAusw(const char* status) { lockZeichnung(); this->statusFilter->setText(status); int anz = spiele->getEintragAnzahl(); for (int i = 0; i < anz; i++) spiele->z(i)->setStatusAusw(status); unlockZeichnung(); rend = 1; } void AccountSUKListe::setSortSpalte(const char* spalte) { lockZeichnung(); this->sortSpalte->setText(spalte); int anz = spiele->getEintragAnzahl(); for (int i = 0; i < anz; i++) spiele->z(i)->setSortSpalte(spalte); unlockZeichnung(); rend = 1; } void AccountSUKListe::setSortRichtung(bool absteigend) { lockZeichnung(); sortAbsteigend = absteigend; int anz = spiele->getEintragAnzahl(); for (int i = 0; i < anz; i++) spiele->z(i)->setSortRichtung(absteigend); unlockZeichnung(); rend = 1; } bool AccountSUKListe::tick(double tickVal) { lockZeichnung(); int anz = spiele->getEintragAnzahl(); if (anz > 0) { int* rf = new int[anz]; int rfAnz = getReihenfolge(rf); for (int i = 0; i < rfAnz; i++) rend |= spiele->z(rf[i])->tick(tickVal); delete[] rf; } unlockZeichnung(); rend |= scroll->getRend(); bool ret = rend; rend = 0; return ret; } void AccountSUKListe::doPublicMausEreignis(MausEreignis& me) { bool vera = 0; if (me.mx - pos.x <= 0 || me.mx - pos.x >= ram->getBreite() || me.my - pos.y <= 0 || me.my - pos.y >= ram->getHeight()) { vera = 1; me.verarbeitet = 1; } int mx = me.mx, my = me.my; me.mx -= pos.x; me.my -= pos.y; scroll->doMausMessage(ram->getBreite() - 16, 1, 15, ram->getHeight() - 2, me); me.mx -= 10; me.my -= 10 - scroll->getScroll(); lockZeichnung(); int anz = spiele->getEintragAnzahl(); int* rf = new int[anz]; int rfAnz = getReihenfolge(rf); for (int i = 0; i < rfAnz; i++) { spiele->z(rf[i])->doPublicMausEreignis(me); me.my -= spiele->z(rf[i])->getHeight() + 10; } delete[] rf; unlockZeichnung(); me.mx = mx, me.my = my; if (vera) me.verarbeitet = 0; } void AccountSUKListe::render(Bild& zRObj) { if (!zRObj.setDrawOptions(pos.x, pos.y, ram->getBreite(), ram->getBreite())) return; ram->render(zRObj); scroll->render(ram->getBreite() - 16, 1, 15, ram->getHeight() - 2, zRObj); if (!zRObj.setDrawOptions(1, 1, ram->getBreite() - 15, ram->getHeight() - 2)) { zRObj.releaseDrawOptions(); return; } int y = -scroll->getScroll(); int anzHö = 10; lockZeichnung(); int anz = spiele->getEintragAnzahl(); int* rf = new int[anz]; int rfAnz = getReihenfolge(rf); for (int i = 0; i < rfAnz; i++) { spiele->z(rf[i])->render(anzHö, zRObj); anzHö += spiele->z(rf[i])->getHeight() + 10; } delete[] rf; unlockZeichnung(); scroll->update(anzHö, ram->getHeight() - 2); zRObj.releaseDrawOptions(); zRObj.releaseDrawOptions(); } #define ABSTYLE AuswahlBox::Style::Sichtbar | AuswahlBox::Style::Erlaubt | AuswahlBox::Style::Rahmen | AuswahlBox::Style::AuswahlBuffer | AuswahlBox::Style::MausBuffer | AuswahlBox::Style::MaxHeight | AuswahlBox::Style::Hintergrund | AuswahlBox::Style::VScroll // Inhalt der AccountSpieleUndKarten Klasse aus AccountSpieleUndKarten.h // Konstruktor AccountSpieleUndKarten::AccountSpieleUndKarten() : Thread(), spieleUndKartenF(initFenster(810, 40, 780, 450, Fenster::Style::Sichtbar | Fenster::Style::Titel | Fenster::Style::TitelBuffered | Fenster::Style::Rahmen | Fenster::Style::Erlaubt, "Spiele und Karten von ")), statusAusw(initAuswahlBox(10, 10, 150, 20, ABSTYLE, { "Alle", "Im Besitz", "Nicht im Besitz" })), sortSpalte(initAuswahlBox(170, 10, 150, 20, ABSTYLE, { "Name", "Spiele", "Gewonnen", "Punkte", "Status" })), sortRichtung(initAuswahlBox(330, 10, 150, 20, ABSTYLE, { "Aufwärts", "Abwärts" })), liste(new AccountSUKListe()), status(0), accId(0), animation(0), alpha(255), tickVal(0), rend(0) { initToolTip(statusAusw, "Wähle den Status der anzuzeigenden Spiele und Karten aus."); initToolTip(sortSpalte, "Wähle aus, nach welcher Spalte die\nTabelle sortiert werden soll."); initToolTip(sortRichtung, "Wähle aus, Ob Aufwärts oder Abwärts sortiert werden soll."); spieleUndKartenF->addMember(dynamic_cast(liste->getThis())); spieleUndKartenF->addMember(dynamic_cast(statusAusw->getThis())); spieleUndKartenF->addMember(dynamic_cast(sortSpalte->getThis())); spieleUndKartenF->addMember(dynamic_cast(sortRichtung->getThis())); spieleUndKartenF->setMausEreignis(_ret1ME); } // Destruktor AccountSpieleUndKarten::~AccountSpieleUndKarten() { spieleUndKartenF->release(); statusAusw->release(); sortSpalte->release(); sortRichtung->release(); liste->release(); } // nicht constant void AccountSpieleUndKarten::reset() { liste->reset(); } void AccountSpieleUndKarten::ladeStatistik(int accId) { if (this->accId == accId) return; this->status = 0; if (run) { warteAufThread(1000); ende(); } if ((animation | 0x1) == animation) { animation |= 0x4; this->accId = accId; this->status = 1; return; } if (this->accId) reset(); this->accId = accId; start(); this->status = 1; } void AccountSpieleUndKarten::thread() { Text* name = infoClient->getSpielerName(accId); if (name) { name->insert(0, "Spiele und Karten von "); spieleUndKartenF->setTitel(*name); name->release(); } Array< int >* spiele = infoClient->getAccountSpielGespieltListe(accId); if (spiele) { int anz = spiele->getEintragAnzahl(); for (int i = 0; i < anz; i++) { AccountSUKListeSpiel* s = new AccountSUKListeSpiel(spiele->get(i), accId); liste->addSpiel(s); } spiele->release(); } else nachLogin->zNachrichtenListe()->addNachricht(new Text("Fehler"), new Text("Fehler beim laden der Daten."), new Text("Ok")); animation &= ~0x4; status = 2; run = 0; } void AccountSpieleUndKarten::setSichtbar(bool sichtbar, bool nachRechts) { if (sichtbar) { if ((animation | 0x1) != animation || ((nachRechts && (animation | 0x2) != animation) || !nachRechts && (animation | 0x2) == animation)) { if (nachRechts) spieleUndKartenF->setPosition(-810, 40); else spieleUndKartenF->setPosition(810, 40); } animation |= 0x1; } else animation &= ~0x1; if (nachRechts) animation |= 0x2; else animation &= ~0x2; } bool AccountSpieleUndKarten::tick(double zeit) { rend |= spieleUndKartenF->tick(zeit); tickVal += zeit; int valA = (int)(tickVal * 150); int valB = (int)(tickVal * 500); tickVal -= valA / 150.0; if (valA) { if ((animation | 0x4) == animation && alpha) { if (alpha - valA <= 0) alpha = 0; else alpha -= valA; rend = 1; if (!alpha) { reset(); start(); } } if ((animation | 0x4) != animation && alpha != 255) { if (alpha + valA >= 255) alpha = 255; else alpha += valA; rend = 1; } } if (valB) { if ((animation | 0x1) == animation) { // Sichtbar if ((animation | 0x2) == animation) { // Nach Rechts if (spieleUndKartenF->getX() != 10) { if (spieleUndKartenF->getX() + valB > 10) spieleUndKartenF->setPosition(10, spieleUndKartenF->getY()); else spieleUndKartenF->setPosition(spieleUndKartenF->getX() + valB, spieleUndKartenF->getY()); rend = 1; } } else { // Nach Links if (spieleUndKartenF->getX() != 10) { if (spieleUndKartenF->getX() - valB < 10) spieleUndKartenF->setPosition(10, spieleUndKartenF->getY()); else spieleUndKartenF->setPosition(spieleUndKartenF->getX() - valB, spieleUndKartenF->getY()); rend = 1; } } } else { // Unsichtbar if ((animation | 0x2) == animation) { // Nach Rechts if (spieleUndKartenF->getX() != 810) { if (spieleUndKartenF->getX() + valB > 810) spieleUndKartenF->setPosition(810, spieleUndKartenF->getY()); else spieleUndKartenF->setPosition(spieleUndKartenF->getX() + valB, spieleUndKartenF->getY()); rend = 1; } } else { // Nach Links if (spieleUndKartenF->getX() != -810) { if (spieleUndKartenF->getX() - valB < -810) spieleUndKartenF->setPosition(-810, spieleUndKartenF->getY()); else spieleUndKartenF->setPosition(spieleUndKartenF->getX() - valB, spieleUndKartenF->getY()); rend = 1; } } } } bool ret = rend; rend = 0; return ret; } void AccountSpieleUndKarten::doPublicMausEreignis(MausEreignis& me) { int statusAuswS = statusAusw->getAuswahl(); int sortSpalteS = sortSpalte->getAuswahl(); int sortRichtungS = sortRichtung->getAuswahl(); spieleUndKartenF->doPublicMausEreignis(me); if (statusAusw->getAuswahl() != statusAuswS) { liste->setStatusAusw(statusAusw->zEintrag(statusAusw->getAuswahl())->zText()->getText()); statusAusw->einklappen(); } if (sortSpalte->getAuswahl() != sortSpalteS) { liste->setSortSpalte(sortSpalte->zEintrag(sortSpalte->getAuswahl())->zText()->getText()); sortSpalte->einklappen(); } if (sortRichtung->getAuswahl() != sortRichtungS) { liste->setSortRichtung(sortRichtung->getAuswahl() != 0); sortRichtung->einklappen(); } } void AccountSpieleUndKarten::render(Bild& zRObj) { zRObj.setAlpha(alpha); spieleUndKartenF->render(zRObj); zRObj.releaseAlpha(); } // constant int AccountSpieleUndKarten::getStatus() const { return status; }