#include "Resource.h" #include 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(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(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; }