123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032 |
- #include "SpielAuswahl.h"
- #include <Datei.h>
- #include <Text.h>
- #include <Schrift.h>
- #include <Rahmen.h>
- #include <Punkt.h>
- #include <DateiSystem.h>
- #include "..\..\..\Global\Initialisierung.h"
- #include <AlphaFeld.h>
- #include <MausEreignis.h>
- #include <KSGTDatei.h>
- #include "..\..\..\Global\Variablen.h"
- void SpielAuswahlKSGSAktion( void *p, RCArray< KSGSVariable > *parameter, KSGSVariable **retVal )
- {
- if( !p )
- return;
- ( (SpielDaten*)p )->ksgsAktion( parameter, retVal );
- }
- SpielDaten::SpielDaten( Schrift *zSchrift, const char *name, int id )
- : Thread()
- {
- beenden = 0;
- this->name = new Text( name );
- hintergrund = 0;
- aAnimation = 0;
- beschreibung = 0;
- ksgs = 0;
- rahmen = new LRahmen();
- rahmen->setFarbe( 0xFFFFFFFF );
- rahmen->setRamenBreite( 1 );
- tickVal = 0;
- animation = 0;
- ausgewählt = 0;
- pos = Punkt( 0, 500 );
- gr = Punkt( 200, 100 );
- schrift = zSchrift->getThis();
- spielId = id;
- aktion = 1;
- geladen = 0;
- erlaubt = 0;
- auswahl = new AlphaFeld();
- auswahl->setFarbe( 0x0000FF00 );
- auswahl->setStrength( 8 );
- auswahl->setSize( 200, 100 );
- ladenBild = 0;
- rend = 0;
- ref = 1;
- alpha = 0;
- tAlpha = 0;
- start();
- }
- SpielDaten::~SpielDaten()
- {
- beenden = 1;
- if( run )
- this->warteAufThread( 5000 );
- if( run )
- ende();
- if( schrift )
- schrift->release();
- name->release();
- if( hintergrund )
- hintergrund->release();
- if( aAnimation )
- aAnimation->release();
- if( beschreibung )
- {
- beschreibung->zurücksetzen();
- beschreibung->release();
- }
- if( ksgs )
- {
- dllDateien->releaseDLL( "KSGScript.dll" );
- ksgs = 0;
- }
- rahmen->release();
- auswahl->release();
- }
- void SpielDaten::ksgsAktion( RCArray< KSGSVariable > *parameter, KSGSVariable **retVal )
- {}
- void SpielDaten::setSichtbar( bool sichtbar )
- {
- if( sichtbar )
- animation |= 0x1;
- else
- {
- animation &= ~0x1;
- setAuswahl( 0 );
- auswahl->setFarbe( auswahl->getFarbe() & 0xFFFFFF );
- }
- if( !erlaubt && sichtbar && ausgewählt )
- updateH->setSichtbar( spielId, 1 );
- hauptScreen->lock();
- if( run && aktion == (sichtbar ? 2 : 0) )
- {
- hauptScreen->unlock();
- rend = 1;
- return;
- }
- beenden = 1;
- if( run )
- this->warteAufThread( 1000 );
- if( run )
- ende();
- beenden = 0;
- aktion = sichtbar ? 2 : 0;
- start();
- hauptScreen->unlock();
- rend = 1;
- }
- void SpielDaten::setSichtbar()
- {
- animation |= 1;
- if( ausgewählt && geladen == 2 )
- {
- animation |= 0x4;
- beschreibung->setPosition( beschreibung->getX(), 0 );
- }
- if( !erlaubt && ausgewählt )
- updateH->setSichtbar( spielId, 1 );
- hauptScreen->lock();
- if( geladen != 2 && !( aktion == 2 && run ) )
- {
- beenden = 1;
- if( run )
- this->warteAufThread( 1000 );
- if( run )
- ende();
- beenden = 0;
- aktion = 2;
- start();
- }
- hauptScreen->unlock();
- rend = 1;
- }
- void SpielDaten::setAuswahl( bool auswahl )
- {
- if( ausgewählt == auswahl )
- return;
- ausgewählt = auswahl;
- if( auswahl )
- {
- if( aAnimation )
- aAnimation->setSichtbar( 1 );
- if( beschreibung && ksgs )
- beschreibung->neuLaden();
- animation |= 0x4;
- }
- else
- animation &= ~0x4;
- if( !erlaubt && ausgewählt )
- updateH->setSichtbar( spielId, 1 );
- if( !erlaubt && !ausgewählt )
- updateH->setSichtbar( spielId, 0 );
- rend = 1;
- }
- void SpielDaten::thread()
- {
- Text *pfad = new Text( "data/spiele/" );
- pfad->append( name->getText() );
- pfad->append( "/data/game.ini" );
- if( !DateiExistiert( pfad->getThis() ) )
- {
- if( !aktion )
- {
- if( aAnimation )
- aAnimation->setSichtbar( 0 );
- geladen = 0;
- ausgewählt = 0;
- hauptScreen->lock();
- if( aAnimation )
- aAnimation = aAnimation->release();
- hauptScreen->unlock();
- if( hintergrund )
- hintergrund = hintergrund->release();
- if( beschreibung )
- {
- beschreibung->zurücksetzen();
- beschreibung = beschreibung->release();
- }
- if( ksgs )
- {
- dllDateien->releaseDLL( "KSGScript.dll" );
- ksgs = 0;
- }
- }
- else
- {
- if( !hintergrund )
- hintergrund = new Bild();
- hintergrund->neuBild( 200, 100, 0xFF000000 );
- schrift->lock();
- schrift->setSchriftSize( 12 );
- schrift->setDrawPosition( 10, 10 );
- schrift->renderText( name, *hintergrund, 0xFFFFFFFF );
- schrift->unlock();
- if( !geladen )
- geladen = 1;
- rend = 1;
- int dgId = infoKlient->getDateiGruppeIdVonSpiel( spielId );
- if( dgId )
- {
- KSGTDatei *dg = new KSGTDatei( "data/dg.ksgt" );
- dg->laden();
- bool gefunden = 0;
- for( int i = 0; i < dg->getZeilenAnzahl(); i++ )
- {
- if( dg->zFeld( i, 0 ) && TextZuInt( dg->zFeld( i, 0 )->getText(), 10 ) == dgId )
- {
- gefunden = 1;
- break;
- }
- }
- if( !gefunden )
- {
- for( int i = 0; i < dg->getZeilenAnzahl(); i++ )
- {
- if( dg->zFeld( i, 3 ) && !dg->zFeld( i, 3 )->istGleich( "SOFORT" ) && !dg->zFeld( i, 3 )->istGleich( "NICHT" ) )
- {
- int platz = TextZuInt( dg->zFeld( i, 3 )->getText(), 10 ) + 1;
- Text *plT = new Text();
- plT->append( platz );
- dg->zFeld( i, 3 )->setText( plT );
- }
- }
- Text *idT = new Text();
- idT->append( dgId );
- Text *pfad = infoKlient->getDateiGruppePfad( dgId );
- if( pfad )
- {
- RCArray< Text > *zeile = new RCArray< Text >();
- zeile->add( idT );
- zeile->add( pfad );
- zeile->add( new Text( "0" ) );
- zeile->add( new Text( "0" ) );
- dg->addZeile( 4, zeile );
- zeile->release();
- }
- else
- idT->release();
- }
- dg->speichern();
- dg->release();
- }
- if( aktion == 2 && !beenden )
- {
- if( beschreibung )
- {
- beschreibung->zurücksetzen();
- beschreibung = beschreibung->release();
- }
- if( !ksgs )
- ksgs = dllDateien->ladeDLL( "KSGScript.dll", "data/bin/KSGScript.dll" );
- if( ksgs )
- {
- KSGSGetZeichnung getKSGScript = (KSGSGetZeichnung)GetProcAddress( ksgs, KSGS_START_FUNKTION );
- if( getKSGScript )
- {
- beschreibung = getKSGScript();
- beschreibung->setBildschirmZ( hauptScreen->getThis() );
- beschreibung->setSchriftZ( schrift->getThis() );
- beschreibung->setSize( 578, 428 );
- beschreibung->setRückrufParam( this );
- beschreibung->setRückrufFunktion( SpielAuswahlKSGSAktion );
- beschreibung->setScriptDatei( "data/script/SpielNichtAktuell.ksgs" );
- }
- else
- {
- nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ),
- new Text( "Der Einstiegspunkt '" KSGS_START_FUNKTION "' in der DLL-Datei "
- "'data/bin/KSGScript.dll' konnte nicht gefunden werden." ),
- new Text( "Ok" ), 0, NachrichtType::nachricht, 0 );
- }
- }
- else
- {
- nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ),
- new Text( "Die DLL-Datei 'data/bin/KSGScript.dll' konnte nicht geladen werden." ),
- new Text( "Ok" ), 0, NachrichtType::nachricht, 0 );
- }
- if( beschreibung )
- geladen = 2;
- if( beschreibung && ksgs && ausgewählt )
- beschreibung->neuLaden();
- }
- }
- pfad->release();
- rend = 1;
- run = 0;
- return;
- }
- Datei *ini = new Datei();
- ini->setDatei( pfad->getText() );
- ini->open( Datei::Style::lesen );
- if( !aktion )
- {
- if( aAnimation )
- aAnimation->setSichtbar( 0 );
- geladen = 0;
- ausgewählt = 0;
- hauptScreen->lock();
- if( aAnimation )
- aAnimation = aAnimation->release();
- hauptScreen->unlock();
- if( hintergrund )
- hintergrund = hintergrund->release();
- if( beschreibung )
- {
- beschreibung->zurücksetzen();
- beschreibung = beschreibung->release();
- }
- if( ksgs )
- {
- dllDateien->releaseDLL( "KSGScript.dll" );
- ksgs = 0;
- }
- rend = 1;
- }
- else
- {
- Text *pf = ini->leseZeile();
- pf->remove( pf->getLength() - 1 );
- pf->insert( 0, "/bilder/" );
- pf->insert( 0, name->getText() );
- pf->insert( 0, "data/spiele/" );
- if( pf->hat( ".ltdb/" ) )
- {
- if( !hintergrund )
- {
- LTDBDatei *bildDatei = new LTDBDatei();
- bildDatei->setDatei( pf->getTeilText( 0, pf->positionVon( ".ltdb" ) + 5 ) );
- bildDatei->leseDaten( 0 );
- hintergrund = bildDatei->laden( 0, pf->getTeilText( pf->positionVon( ".ltdb" ) + 6 ) );
- bildDatei->release();
- }
- }
- else
- {
- if( !hintergrund )
- {
- LTDBDatei *bildDatei = new LTDBDatei();
- bildDatei->setDatei( pf->getThis() );
- bildDatei->leseDaten( 0 );
- hintergrund = bildDatei->laden( 0, bildDatei->zBildListe()->get( 0 ) );
- bildDatei->release();
- }
- }
- pf->release();
- pf = ini->leseZeile();
- pf->release();
- pf = ini->leseZeile();
- pf->remove( pf->getLength() - 1 );
- pf->insert( 0, "/data/" );
- pf->insert( 0, name->getText() );
- pf->insert( 0, "data/spiele/" );
- Datei *idDatei = new Datei();
- idDatei->setDatei( pf->getText() );
- idDatei->open( Datei::Style::lesen );
- idDatei->lese( (char*)&spielId, 4 );
- idDatei->close();
- idDatei->release();
- pf->release();
- if( !geladen )
- geladen = 1;
- rend = 1;
- ini->setLPosition( 0, 0 );
- if( aktion == 2 && !beenden )
- {
- pf = ini->leseZeile();
- pf->remove( pf->getLength() - 1 );
- pf->insert( 0, "/bilder/" );
- pf->insert( 0, name->getText() );
- pf->insert( 0, "data/spiele/" );
- if( !pf->hat( ".ltdb/" ) )
- {
- hauptScreen->lock();
- if( aAnimation )
- aAnimation = aAnimation->release();
- hauptScreen->unlock();
- LTDBDatei *add = new LTDBDatei();
- add->setDatei( pf->getThis() );
- add->leseDaten( 0 );
- Animation2DData *ad = new Animation2DData();
- ad->ladeAnimation( add );
- ad->setWiederhohlend( 1 );
- ad->setFPS( 30 );
- aAnimation = new Animation2D();
- aAnimation->setSize( 200, 100 );
- aAnimation->setPosition( 0, 0 );
- aAnimation->setAnimationDataZ( ad );
- }
- pf->release();
- pf = ini->leseZeile();
- pf->remove( pf->getLength() - 1 );
- pf->insert( 0, "/data/" );
- pf->insert( 0, name->getText() );
- pf->insert( 0, "data/spiele/" );
- if( beschreibung )
- {
- beschreibung->zurücksetzen();
- beschreibung = beschreibung->release();
- }
- if( !ksgs )
- ksgs = dllDateien->ladeDLL( "KSGScript.dll", "data/bin/KSGScript.dll" );
- if( ksgs )
- {
- KSGSGetZeichnung getKSGScript = (KSGSGetZeichnung)GetProcAddress( ksgs, KSGS_START_FUNKTION );
- if( getKSGScript )
- {
- beschreibung = getKSGScript();
- beschreibung->setBildschirmZ( hauptScreen->getThis() );
- beschreibung->setSchriftZ( schrift->getThis() );
- beschreibung->setSize( 578, 428 );
- beschreibung->setRückrufParam( this );
- beschreibung->setRückrufFunktion( SpielAuswahlKSGSAktion );
- beschreibung->setScriptDatei( pf->getText() );
- }
- else
- {
- nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ),
- new Text( "Der Einstiegspunkt '" KSGS_START_FUNKTION "' in der DLL-Datei "
- "'data/bin/KSGScript.dll' konnte nicht gefunden werden." ),
- new Text( "Ok" ), 0, NachrichtType::nachricht, 0 );
- }
- }
- else
- {
- nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ),
- new Text( "Die DLL-Datei 'data/bin/KSGScript.dll' konnte nicht geladen werden." ),
- new Text( "Ok" ), 0, NachrichtType::nachricht, 0 );
- }
- pf->release();
- if( beschreibung )
- geladen = 2;
- if( beschreibung && ksgs && ausgewählt )
- beschreibung->neuLaden();
- rend = 1;
- }
- }
- pfad->release();
- ini->close();
- ini->release();
- if( !erlaubt )
- updateErlaubt();
- aktion = 0;
- run = 0;
- rend = 1;
- }
- void SpielDaten::updateErlaubt()
- {
- bool update = erlaubt;
- erlaubt = 0;
- KSGTDatei *dgt = new KSGTDatei( "data/dg.ksgt" );
- dgt->laden();
- bool ak = 0;
- int dgId = infoKlient->getDateiGruppeIdVonSpiel( spielId );
- for( int i = 0; i < dgt->getZeilenAnzahl(); i++ )
- {
- if( dgt->zFeld( i, 0 ) && TextZuInt( dgt->zFeld( i, 0 )->getText(), 10 ) == dgId )
- {
- int lv = dgt->zFeld( i, 2 ) ? TextZuInt( dgt->zFeld( i, 2 )->getText(), 10 ) : 0;
- int ov = infoKlient->getSpielVersion( spielId );
- if( lv == ov )
- ak = 1;
- break;
- }
- }
- dgt->release();
- erlaubt = ak && infoKlient->istSpielErlaubt( spielId );
- if( !erlaubt && !updateH->hat( spielId ) )
- {
- updateH->erstellen( schrift, spielId );
- if( ausgewählt )
- updateH->setSichtbar( spielId, 1 );
- }
- if( erlaubt && updateH->hat( spielId ) )
- updateH->remove( spielId, 0 );
- }
- void SpielDaten::setPosition( int lPos )
- {
- pos.y = lPos * 100;
- rend = 1;
- }
- bool SpielDaten::tick( double tickVal )
- {
- if( beschreibung )
- rend |= beschreibung->tick( tickVal );
- if( !erlaubt )
- rend |= updateH->tick( spielId, tickVal );
- this->tickVal += tickVal * 500;
- int val = ( int ) this->tickVal;
- if( val < 1 )
- {
- bool ret = rend;
- rend = 0;
- return ret;
- }
- if( val > 17 )
- val = 17;
- this->tickVal -= val;
- if( aAnimation && geladen == 2 && aAnimation->istSichtbar() )
- {
- if( aAnimation->getJetzt() + 1 >= aAnimation->zAnimationData()->getBildAnzahl() )
- {
- rend |= aAnimation->tick( tickVal );
- if( aAnimation->getJetzt() + 1 < aAnimation->zAnimationData()->getBildAnzahl() )
- aAnimation->setSichtbar( 0 );
- }
- else
- rend |= aAnimation->tick( tickVal );
- }
- if( ausgewählt )
- {
- int a = ( auswahl->getFarbe() >> 24 ) & 0xFF;
- if( a != 150 )
- {
- if( a + val > 150 )
- a = 150;
- else
- a += val;
- auswahl->setFarbe( ( ( a << 24 ) & 0xFF000000 ) | ( auswahl->getFarbe() & 0xFFFFFF ) );
- rend = 1;
- }
- }
- else
- {
- int a = ( auswahl->getFarbe() >> 24 ) & 0xFF;
- if( a != 0 )
- {
- if( a - val < 0 )
- a = 0;
- else
- a -= val;
- auswahl->setFarbe( ( ( a << 24 ) & 0xFF000000 ) | ( auswahl->getFarbe() & 0xFFFFFF ) );
- rend = 1;
- }
- }
- if( ( animation | 0x1 ) == animation )
- {
- if( tAlpha != 255 )
- {
- if( tAlpha + val > 255 )
- tAlpha = 255;
- else
- tAlpha += val;
- rend = 1;
- }
- }
- else
- {
- if( tAlpha != 0 )
- {
- if( tAlpha - val < 0 )
- tAlpha = 0;
- else
- tAlpha -= val;
- rend = 1;
- }
- }
- if( geladen == 2 )
- {
- if( ( animation | 0x4 ) == animation )
- {
- if( beschreibung )
- {
- if( alpha != 255 )
- {
- if( alpha + val < 255 )
- alpha += val;
- else
- alpha = 255;
- rend = 1;
- }
- }
- }
- else
- {
- int a = ( auswahl->getFarbe() >> 24 ) & 0xFF;
- if( a != 0 )
- {
- a -= val;
- if( a < 0 )
- a = 0;
- auswahl->setFarbe( ( ( a << 24 ) & 0xFF000000 ) | ( auswahl->getFarbe() & 0xFFFFFF ) );
- rend = 1;
- }
- if( beschreibung )
- {
- if( alpha != 0 )
- {
- if( alpha - val > 0 )
- alpha -= val;
- else
- alpha = 0;
- rend = 1;
- }
- }
- }
- }
- bool ret = rend;
- rend = 0;
- return ret;
- }
- void SpielDaten::doMausEreignis( MausEreignis &me )
- {
- if( !erlaubt && ausgewählt )
- {
- me.mx -= gr.x + 90;
- me.my -= 350;
- updateH->doMausEreignis( spielId, me );
- me.my += 350;
- me.mx += 90;
- if( beschreibung )
- beschreibung->doMausEreignis( me );
- me.mx += gr.x;
- }
- }
- void SpielDaten::render( Bild &zRObj )
- {
- int x = pos.x;
- int y = pos.y;
- int br = gr.x;
- int hö = gr.y;
- if( !zRObj.setDrawOptions( x, y, br, hö ) )
- return;
- zRObj.setAlpha( tAlpha );
- rahmen->setSize( br, hö );
- int rbr = rahmen->getRBreite();
- if( geladen && hintergrund && ( !( ausgewählt && geladen == 2 && aAnimation ) || !aAnimation->istSichtbar() ) )
- zRObj.drawBild( rbr, rbr, br - rbr * 2, hö - rbr * 2, *hintergrund );
- if( aAnimation )
- aAnimation->render( zRObj );
- rahmen->render( zRObj );
- if( auswahl && ( ( auswahl->getFarbe() >> 24 ) & 0xFF ) && ( !( ausgewählt && geladen == 2 && aAnimation ) || !aAnimation->istSichtbar() ) )
- {
- auswahl->setPosition( rbr, rbr );
- auswahl->setSize( br - rbr * 2, hö - rbr * 2 );
- auswahl->render( zRObj );
- }
- zRObj.releaseDrawOptions();
- x = br;
- y = 0;
- br = 580;
- hö = 480;
- if( !zRObj.setDrawOptions( x, y, br, hö ) )
- {
- zRObj.releaseAlpha();
- return;
- }
- if( geladen == 2 && beschreibung )
- {
- zRObj.setAlpha( alpha );
- beschreibung->render( zRObj );
- zRObj.releaseAlpha();
- }
- if( !erlaubt )
- updateH->render( spielId, 90, 350, zRObj );
- if( ausgewählt && geladen != 2 && ladeAnimation->zAnimationData() )
- {
- ladenBild++;
- if( ladenBild >= ladeAnimation->zAnimationData()->getBildAnzahl() )
- ladenBild = 0;
- zRObj.drawBild( 275, 195, 50, 50, *ladeAnimation->zAnimationData()->zBild( ladenBild ) );
- rend = 1;
- }
- zRObj.releaseDrawOptions();
- zRObj.releaseAlpha();
- }
- int SpielDaten::getSpielId() const
- {
- return spielId;
- }
- bool SpielDaten::istausgewählt() const
- {
- return ausgewählt;
- }
- Text *SpielDaten::zName() const
- {
- return name;
- }
- bool SpielDaten::istErlaubt() const
- {
- return erlaubt;
- }
- SpielDaten *SpielDaten::getThis()
- {
- ref++;
- return this;
- }
- SpielDaten *SpielDaten::release()
- {
- ref--;
- if( !ref )
- delete this;
- return 0;
- }
- SpielAuswahlFenster::SpielAuswahlFenster( Schrift *zSchrift )
- : Thread()
- {
- schrift = zSchrift->getThis();
- rahmen = new LRahmen();
- rahmen->setFarbe( 0xFFFFFFFF );
- rahmen->setRamenBreite( 1 );
- rahmen->setSize( 760, 500 );
- members = new RCArray< SpielDaten >();
- anzahl = 0;
- animation = 0;
- auswahl = -1;
- tickVal = 0;
- seite = 0;
- pos = Punkt( 10, 10 );
- gr = Punkt( 780, 430 );
- rend = 0;
- ref = 1;
- alpha = 0;
- start();
- }
- SpielAuswahlFenster::~SpielAuswahlFenster()
- {
- if( run )
- {
- warteAufThread( 5000 );
- ende();
- }
- if( schrift )
- schrift->release();
- if( rahmen )
- rahmen->release();
- if( members )
- members->release();
- }
- void SpielAuswahlFenster::setSichtbar( bool sichtbar )
- {
- if( sichtbar )
- {
- animation |= 0x1;
- start();
- }
- else
- {
- auswahl = -1;
- for( int i = seite * 4; i >= 0 && i < anzahl && i < seite * 4 + 4; i++ )
- members->z( i )->setSichtbar( 0 );
- animation &= ~0x1;
- }
- rend = 1;
- }
- void SpielAuswahlFenster::blättern( bool oben )
- {
- for( int i = seite * 4; i >= 0 && i < anzahl && i < seite * 4 + 4; i++ )
- members->z( i )->setSichtbar( 0 );
- seite += oben ? 1 : -1;
- for( int i = seite * 4; i >= 0 && i < anzahl && i < seite * 4 + 4; i++ )
- {
- members->z( i )->setPosition( i % 4 );
- members->z( i )->setSichtbar( 1 );
- }
- auswahl = -1;
- rend = 1;
- }
- void SpielAuswahlFenster::updateListe()
- {
- if( run )
- return;
- start();
- }
- void SpielAuswahlFenster::thread()
- {
- Array< int > *liste = infoKlient->getAccountSpielArtListe();
- if( !liste )
- {
- nachLogin->zNachrichtenListe()->addNachricht( new Text( "Fehler" ), new Text( infoKlient->getLetzterFehler() ),
- new Text( "Ok" ), 0, NachrichtType::nachricht, 0 );
- run = 0;
- return;
- }
- int anz = liste->getEintragAnzahl();
- for( int i = 0; i < anz; i++ )
- {
- Text *name = infoKlient->getSpielName( liste->hat( i ) ? liste->get( i ) : 0 );
- if( name )
- {
- bool gefunden = 0;
- for( int j = 0; j < anzahl; j++ )
- {
- SpielDaten *tmp = members->z( j );
- if( liste->hat( i ) && tmp->getSpielId() == liste->get( i ) )
- {
- gefunden = 1;
- break;
- }
- }
- if( !gefunden )
- {
- SpielDaten *tmp = new SpielDaten( schrift, name->getText(), liste->hat( i ) ? liste->get( i ) : 0 );
- members->add( tmp, anzahl );
- anzahl++;
- }
- name->release();
- }
- }
- if( liste )
- liste->release();
- for( int i = 0; i < anzahl; i++ )
- members->z( i )->updateErlaubt();
- for( int i = seite * 4; i < anzahl && i >= 0 && i < seite * 4 + 4; i++ )
- {
- members->z( i )->setPosition( i % 4 );
- members->z( i )->setSichtbar();
- }
- rend = 1;
- run = 0;
- }
- bool SpielAuswahlFenster::tick( double tickVal )
- {
- for( int i = 0; i < anzahl; i++ )
- rend |= members->z( i )->tick( tickVal );
- this->tickVal += tickVal * 750;
- int val = ( int )this->tickVal;
- if( val < 1 )
- {
- bool ret = rend;
- rend = 0;
- return ret;
- }
- if( val > 25 )
- val = 25;
- this->tickVal -= val;
- if( ( animation | 0x1 ) == animation )
- {
- if( alpha < 255 )
- {
- if( alpha + val >= 255 )
- {
- alpha = 255;
- for( int i = seite * 4; i < anzahl && i >= 0 && i < seite * 4 + 4; i++ )
- {
- members->z( i )->setPosition( i % 4 );
- members->z( i )->setSichtbar( 1 );
- }
- }
- else
- alpha += val;
- rend = 1;
- }
- }
- else
- {
- if( alpha > 0 )
- {
- if( alpha - val < 0 )
- alpha = 0;
- else
- alpha -= val;
- rend = 1;
- }
- }
- bool ret = rend;
- rend = 0;
- return ret;
- }
- void SpielAuswahlFenster::doMausEreignis( MausEreignis &me )
- {
- if( pos.x != 10 )
- return;
- me.mx -= pos.x;
- me.my -= pos.y;
- for( int i = 0; i < anzahl; i++ )
- members->z( i )->doMausEreignis( me );
- if( me.mx < 0 || me.my < 0 )
- {
- me.mx += pos.x;
- me.my += pos.y;
- return;
- }
- if( me.mx > 200 || me.my > getAnzahlAufSeite() * 100 )
- {
- me.mx += pos.x;
- me.my += pos.y;
- return;
- }
- if( me.id == ME_RLinks )
- {
- int treffer = me.my / 100 + seite * 4;
- if( treffer >= anzahl )
- {
- me.mx += pos.x;
- me.my += pos.y;
- return;
- }
- if( treffer == auswahl )
- {
- me.mx += pos.x;
- me.my += pos.y;
- return;
- }
- if( auswahl >= 0 )
- members->z( auswahl )->setAuswahl( 0 );
- members->z( treffer )->setAuswahl( 1 );
- auswahl = treffer;
- rend = 1;
- }
- me.mx += pos.x;
- me.my += pos.y;
- }
- void SpielAuswahlFenster::render( Bild &zrObj )
- {
- int x = pos.x;
- int y = pos.y;
- int br = gr.x;
- int hö = gr.y;
- if( !zrObj.setDrawOptions( x, y, br, hö ) )
- return;
- zrObj.setAlpha( alpha );
- rahmen->setSize( br, hö );
- rahmen->render( zrObj );
- int rbr = rahmen->getRBreite();
- if( !zrObj.setDrawOptions( rbr, rbr, br - rbr * 2, hö - rbr * 2 ) )
- {
- zrObj.releaseDrawOptions();
- zrObj.releaseAlpha();
- return;
- }
- for( int i = seite * 4; i >= 0 && i < anzahl && i < seite * 4 + 4; i++ )
- members->z( i )->render( zrObj );
- zrObj.releaseDrawOptions();
- if( !anzahl )
- {
- Text t = "Dieser Account besitzt momentan noch keine Spiele.\nBesuche den Shop um neue Spiele zu erwerben!";
- schrift->lock();
- schrift->setDrawPosition( 10, 10 );
- schrift->setSchriftSize( 12 );
- schrift->renderText( &t, zrObj, 0xFFFFFFFF );
- schrift->unlock();
- }
- zrObj.releaseDrawOptions();
- zrObj.releaseAlpha();
- }
- int SpielAuswahlFenster::getAnzahl() const
- {
- return anzahl;
- }
- int SpielAuswahlFenster::getSeiteAnzahl() const
- {
- return ( anzahl / 4.0 == anzahl / 4 ) ? ( anzahl / 4 ) : ( anzahl / 4 + 1 );
- }
- int SpielAuswahlFenster::getSeite() const
- {
- return seite;
- }
- int SpielAuswahlFenster::getAnzahlAufSeite() const
- {
- return ( anzahl < seite * 4 + 4 ) ? ( anzahl - seite * 4 ) : 4;
- }
- bool SpielAuswahlFenster::hatAuswahl() const
- {
- return auswahl != -1;
- }
- SpielDaten *SpielAuswahlFenster::getAuswahl() const
- {
- return members->get( auswahl );
- }
- SpielDaten *SpielAuswahlFenster::zAuswahl() const
- {
- return members->z( auswahl );
- }
- bool SpielAuswahlFenster::istAuswahlErlubt() const
- {
- return auswahl != -1 && members->z( auswahl )->istErlaubt();
- }
- SpielAuswahlFenster *SpielAuswahlFenster::getThis()
- {
- ref++;
- return this;
- }
- SpielAuswahlFenster *SpielAuswahlFenster::release()
- {
- ref--;
- if( !ref )
- delete this;
- return 0;
- }
|