#include "AccountStatistik.h" #include "../../../Global/Initialisierung.h" #include "../../../Global/Variablen.h" #include // Inhalt der AccountStatistik Klasse aus AccountStatistik.h // Konstruktor AccountStatistik::AccountStatistik( Schrift *zSchrift ) : Thread(), schrift( zSchrift->getThis() ), statistikF( initFenster( 810, 40, 780, 450, zSchrift, Fenster::Style::Sichtbar | Fenster::Style::Titel | Fenster::Style::TitelBuffered | Fenster::Style::Rahmen | Fenster::Style::Erlaubt, "Statistik von " ) ), sortSpalte( initAuswahlBox( 10, 10, 150, 20, zSchrift, ABSTYLE, { "Name", "Spiele", "Gewonnen", "Verloren", "Punkte", "BW0", "BW1", "BW2", "BW3", "BW4", "BW5" } ) ), sortRichtung( initAuswahlBox( 170, 10, 150, 20, zSchrift, ABSTYLE, { "Aufwärts", "Abwärts" } ) ), zurück( initKnopf( 590, 10, 20, 20, 0, 0, "" ) ), vor( initKnopf( 750, 10, 20, 20, 0, 0, "" ) ), seiteTF( initTextFeld( 620, 10, 120, 20, zSchrift, TextFeld::Style::Text | TextFeld::Style::Center, "Seite 0 von 0" ) ), tabelle( initObjTabelle( 10, 40, 760, 400, zSchrift, OTSTYLE, { { "Name", 108, 0, 0 }, { "Spiele", 70, 0, 0 }, { "Gewonnen", 70, 0, 0 }, { "Verloren", 70, 0, 0 }, { "Punkte", 70, 0, 0 }, { "BW0", 60, 0, 0 }, { "BW1", 60, 0, 0 }, { "BW2", 60, 0, 0 }, { "BW3", 60, 0, 0 }, { "BW4", 60, 0, 0 }, { "BW5", 60, 0, 0 } }, 20 ) ), laden( (Animation2D*)ladeAnimation->dublizieren() ), seite( 0 ), maxSeite( 0 ), status( 0 ), accId( 0 ), animation( 0 ), alpha( 255 ), tickVal( 0 ), rend( 0 ), ref( 1 ) { initToolTip( sortSpalte, "Wähle aus, nach welcher Spalte die\nTabelle sortiert werden soll.", zSchrift->getThis(), hauptScreen ); initToolTip( sortRichtung, "Wähle aus, ob Aufwärts oder Abwärts\nsortiert werden soll.", zSchrift->getThis(), hauptScreen ); Bild *zurückB = bilder->get( "shop.ltdb/zurück.png" ); if( !zurückB ) { LTDBDatei *datei = new LTDBDatei(); datei->setDatei( new Text( "data/client/bilder/shop.ltdb" ) ); datei->leseDaten( 0 ); zurückB = datei->laden( 0, new Text( "zurück.png" ) ); datei->release(); bilder->add( "shop.ltdb/zurück.png", zurückB->getThis() ); } Bild *weiterB = bilder->get( "shop.ltdb/weiter.png" ); if( !weiterB ) { LTDBDatei *datei = new LTDBDatei(); datei->setDatei( new Text( "data/client/bilder/shop.ltdb" ) ); datei->leseDaten( 0 ); weiterB = datei->laden( 0, new Text( "weiter.png" ) ); datei->release(); bilder->add( "shop.ltdb/weiter.png", weiterB->getThis() ); } laden->setSichtbar( 0 ); laden->setPosition( 365, 200 ); zurück->setStyle( Knopf::Style::Sichtbar | Knopf::Style::Hintergrund | Knopf::Style::HBild | Knopf::Style::KlickBuffer ); zurück->setHintergrundBildZ( zurückB ); initToolTip( zurück, "Eine Seite zurück blättern.", zSchrift->getThis(), hauptScreen ); vor->setStyle( Knopf::Style::Sichtbar | Knopf::Style::Hintergrund | Knopf::Style::HBild | Knopf::Style::KlickBuffer ); vor->setHintergrundBildZ( weiterB ); initToolTip( vor, "Eine Seite weiter blättern.", zSchrift->getThis(), hauptScreen ); statistikF->addMember( tabelle ); statistikF->addMember( zurück ); statistikF->addMember( seiteTF ); statistikF->addMember( vor ); statistikF->addMember( sortSpalte ); statistikF->addMember( sortRichtung ); statistikF->setMausEreignis( _ret1ME ); vor->setMausEreignis( accountStatistikVorME ); zurück->setMausEreignis( accountStatistikZurückME ); } // Destruktor AccountStatistik::~AccountStatistik() { reset( 1 ); statistikF->release(); sortSpalte->release(); sortRichtung->release(); zurück->release(); vor->release(); seiteTF->release(); tabelle->release(); laden->release(); schrift->release(); } // nicht constant void AccountStatistik::reset( bool überschrift ) { statistikF->lockZeichnung(); int zAnz = tabelle->getZeilenAnzahl(); int sAnz = tabelle->getSpaltenAnzahl(); for( int i = !überschrift; i < zAnz; i++ ) { for( int j = 0; j < sAnz; j++ ) { if( !tabelle->zZeichnung( j, !überschrift ) ) continue; ( (TextFeld*)tabelle->zZeichnung( j, !überschrift ) )->release(); } tabelle->removeZeile( !überschrift ); } statistikF->unlockZeichnung(); } void AccountStatistik::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; } this->accId = accId; start(); this->status = 1; } void AccountStatistik::thread() { laden->setSichtbar( 1 ); reset(); Text *name = infoKlient->getSpielerName( accId ); if( name ) { name->insert( 0, "Statistik von " ); statistikF->setTitel( *name ); name->release(); } RCArray< Array< int > > *values = new RCArray< Array< int > >(); RCArray< Text > *namen = new RCArray< Text >(); if( infoKlient->getStatistikListe( accId, &seite, &maxSeite, sortSpalte->getAuswahl(), sortRichtung->getAuswahl(), values, namen ) ) { statistikF->lockZeichnung(); seiteTF->setText( "Seite " ); seiteTF->zText()->append( seite ); seiteTF->zText()->append( " von " ); seiteTF->zText()->append( maxSeite ); statistikF->unlockZeichnung(); zurück->setStyle( Knopf::Style::Erlaubt, seite > 1 ); vor->setStyle( Knopf::Style::Erlaubt, seite < maxSeite ); int zAnz = values->getEintragAnzahl(); if( zAnz ) { int sAnz = values->z( 0 )->getEintragAnzahl(); for( int i = 0; i < zAnz; i++ ) { if( sAnz ) { tabelle->addZeile( Text() += values->z( i )->get( 0 ) ); Text *name = namen->z( i ); if( name ) { TextFeld *tf = initTextFeld( 0, 0, 0, 0, schrift, TextFeld::Style::Text | TextFeld::Style::Center, *name ); tabelle->setZeichnungZ( 0, i + 1, tf ); } } for( int j = 1; j < sAnz; j++ ) { if( j < 1 ) { TextFeld *tf = initTextFeld( 0, 0, 0, 0, schrift, TextFeld::Style::Text | TextFeld::Style::Center, "" ); tf->zText()->append( values->z( i )->get( j ) ); tabelle->setZeichnungZ( j, i + 1, tf ); } if( j > 1 ) { TextFeld *tf = initTextFeld( 0, 0, 0, 0, schrift, TextFeld::Style::Text | TextFeld::Style::Center, "" ); tf->zText()->append( values->z( i )->get( j ) ); tabelle->setZeichnungZ( j - 1, i + 1, tf ); } } } } } else nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ), new Text( "Die Statistiken dieses Spielers konnten nicht abgerufen werden." ), new Text( "Ok" ) ); values->release(); namen->release(); laden->setSichtbar( 0 ); animation &= ~0x4; status = 2; run = 0; } void AccountStatistik::setSichtbar( bool sichtbar, bool nachRechts ) { if( sichtbar ) { if( ( animation | 0x1 ) != animation || ( ( nachRechts && ( animation | 0x2 ) != animation ) || !nachRechts && ( animation | 0x2 ) == animation ) ) { if( nachRechts ) statistikF->setPosition( -810, 40 ); else statistikF->setPosition( 810, 40 ); } animation |= 0x1; } else animation &= ~0x1; if( nachRechts ) animation |= 0x2; else animation &= ~0x2; } bool AccountStatistik::vorME( MausEreignis &me ) { if( me.id == ME_RLinks ) { seite++; start(); } return 1; } bool AccountStatistik::zurückME( MausEreignis &me ) { if( me.id == ME_RLinks ) { seite--; start(); } return 1; } bool AccountStatistik::tick( double zeit ) { statistikF->lockZeichnung(); rend |= statistikF->tick( zeit ); statistikF->unlockZeichnung(); rend |= laden->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( statistikF->getX() != 10 ) { if( statistikF->getX() + valB > 10 ) statistikF->setPosition( 10, statistikF->getY() ); else statistikF->setPosition( statistikF->getX() + valB, statistikF->getY() ); rend = 1; } } else { // Nach Links if( statistikF->getX() != 10 ) { if( statistikF->getX() - valB < 10 ) statistikF->setPosition( 10, statistikF->getY() ); else statistikF->setPosition( statistikF->getX() - valB, statistikF->getY() ); rend = 1; } } } else { // Unsichtbar if( ( animation | 0x2 ) == animation ) { // Nach Rechts if( statistikF->getX() != 810 ) { if( statistikF->getX() + valB > 810 ) statistikF->setPosition( 810, statistikF->getY() ); else statistikF->setPosition( statistikF->getX() + valB, statistikF->getY() ); rend = 1; } } else { // Nach Links if( statistikF->getX() != -810 ) { if( statistikF->getX() - valB < -810 ) statistikF->setPosition( -810, statistikF->getY() ); else statistikF->setPosition( statistikF->getX() - valB, statistikF->getY() ); rend = 1; } } } } bool ret = rend; rend = 0; return ret; } void AccountStatistik::doMausEreignis( MausEreignis &me ) { if( run ) return; bool starten = 0; int sortSpalteS = sortSpalte->getAuswahl(); int sortRichtungS = sortRichtung->getAuswahl(); statistikF->lockZeichnung(); statistikF->doMausEreignis( me ); statistikF->unlockZeichnung(); if( sortSpalte->getAuswahl() != sortSpalteS ) { sortSpalte->einklappen(); starten = 1; } if( sortRichtung->getAuswahl() != sortRichtungS ) { sortRichtung->einklappen(); starten = 1; } if( starten ) start(); } void AccountStatistik::render( Bild &zRObj ) { zRObj.setAlpha( alpha ); statistikF->lockZeichnung(); statistikF->render( zRObj ); statistikF->unlockZeichnung(); if( !zRObj.setDrawOptions( statistikF->getPosition(), statistikF->getSize() ) ) { zRObj.releaseAlpha(); return; } laden->render( zRObj ); zRObj.releaseAlpha(); zRObj.releaseDrawOptions(); } // constant int AccountStatistik::getStatus() const { return status; } // Reference Counting AccountStatistik *AccountStatistik::getThis() { ref++; return this; } AccountStatistik *AccountStatistik::release() { ref--; if( !ref ) delete this; return 0; } // Ereignisse bool accountStatistikVorME( void *p, void *o, MausEreignis me ) { if( p ) return ( (AccountStatistik*)p )->vorME( me ); return 1; } bool accountStatistikZurückME( void *p, void *o, MausEreignis me ) { if( p ) return ( (AccountStatistik*)p )->zurückME( me ); return 1; }