123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- #include "Resource.h"
- #include <DateiSystem.h>
- ColorMode::ColorMode()
- : ReferenceCounter()
- {}
- Bild* ColorMode::colorImage( Bild* zImg, int color )
- {
- Bild* result = new Bild();
- result->neuBild( zImg->getBreite(), zImg->getHeight(), 0 );
- result->drawBild( 0, 0, zImg->getBreite(), zImg->getHeight(), *zImg );
- return result;
- }
- AlphaColorMode::AlphaColorMode( unsigned char alpha )
- {
- this->alpha = alpha;
- }
- Bild* AlphaColorMode::colorImage( Bild* zImg, int color )
- {
- Bild* result = ColorMode::colorImage( zImg, color );
- result->alphaRegion( 0, 0, result->getBreite(), result->getHeight(), ((int)alpha << 24) | (color & 0xFFFFFF) );
- return result;
- }
- MaskColorMode::MaskColorMode( int colorToReplace )
- {
- this->colorToReplace = colorToReplace;
- }
- Bild* MaskColorMode::colorImage( Bild* zImg, int color )
- {
- Bild* result = ColorMode::colorImage( zImg, color );
- int* buffer = result->getBuffer();
- int size = result->getBreite() * result->getHeight();
- for( int i = 0; i < size; i++ )
- {
- if( (buffer[ i ] & 0xFFFFFF) == colorToReplace )
- buffer[ i ] = (buffer[ i ] & 0xFF000000) | (color & 0xFFFFFF);
- }
- return result;
- }
- Resource::Resource( ResourceId id, int color )
- : ReferenceCounter()
- {
- this->id = id;
- this->color = color;
- }
- Resource* Resource::createColoredResource( int color, ColorMode* mode ) const
- {
- Resource* r = new Resource( id, color );
- for( auto i : images )
- r->images.add( mode->colorImage( i, color ) );
- mode->release();
- return r;
- }
- Iterator< Bild* > Resource::getImages() const
- {
- return images.begin();
- }
- ResourceId Resource::getId() const
- {
- return id;
- }
- int Resource::getColor() const
- {
- return color;
- }
- Bild* Resource::zImage( int id ) const
- {
- return images.z( id );
- }
- Bild* Resource::getImage( int id ) const
- {
- return images.get( id );
- }
- int Resource::getImageCount() const
- {
- return images.getEintragAnzahl();
- }
- ResourceRegistry::ResourceRegistry( Text spielPfad, Text mapPfad )
- : ReferenceCounter()
- {
- this->spielPfad = spielPfad;
- this->mapPfad = mapPfad;
- }
- ResourceRegistry::~ResourceRegistry()
- {}
- void ResourceRegistry::setUIFactory( UIInit& uiFactory )
- {
- this->uiFactory = uiFactory;
- }
- UIInit& ResourceRegistry::getUIFactory()
- {
- return uiFactory;
- }
- Resource* ResourceRegistry::getResource( ResourceId id, int color, ColorMode* mode, Text path )
- {
- Resource* r = zResource( id, color, mode, path );
- return r ? dynamic_cast<Resource*>(r->getThis()) : 0;
- }
- Resource* ResourceRegistry::zResource( ResourceId id, int color, ColorMode* mode, Text path )
- {
- path.ersetzen( "map:", mapPfad );
- path.ersetzen( "spiel:", spielPfad );
- for( auto r : resources )
- {
- if( r->getId() == id && r->getColor() == color )
- {
- if( mode )
- mode->release();
- return r;
- }
- }
- if( !mode )
- return 0;
- for( auto r : resources )
- {
- if( r->getId() == id )
- {
- Resource* nr = r->createColoredResource( color, mode );
- resources.add( nr );
- return nr;
- }
- }
- if( path.hat( ".ltdb/" ) && path.positionVon( "/", path.anzahlVon( "/" ) - 1 ) == path.positionVon( ".ltdb/", path.anzahlVon( ".ltdb/" ) - 1 ) + 5 )
- {
- LTDBDatei dat;
- dat.setDatei( path.getTeilText( 0, path.positionVon( ".ltdb/", path.anzahlVon( ".ltdb/" ) - 1 ) + 5 ) );
- Bild* b = dat.laden( 0, path.getTeilText( path.positionVon( ".ltdb/", path.anzahlVon( ".ltdb/" ) - 1 ) + 6 ) );
- if( b )
- {
- Resource* r = new Resource( id, color );
- resources.add( r );
- r->images.add( mode->colorImage( b, color ) );
- b->release();
- mode->release();
- return r;
- }
- mode->release();
- return 0;
- }
- LTDBDatei dat;
- dat.setDatei( dynamic_cast<Text*>(path.getThis()) );
- dat.leseDaten( 0 );
- if( !dat.getBildAnzahl() )
- {
- mode->release();
- return 0;
- }
- Resource* r = new Resource( id, color );
- resources.add( r );
- for( int i = 0; i < dat.getBildAnzahl(); i++ )
- {
- Bild* b = dat.laden( 0, dat.zBildListe()->get( i ) );
- r->images.add( mode->colorImage( b, color ) );
- b->release();
- }
- mode->release();
- return r;
- }
|