if(this.isVoidPipe()) {
return;
}
final Iterable<PipePart> parts = new TreeSet<>( this.colorParts );
final TextureLoader loader = GraphicsEnv.getInstance().getTextureLoader();
final Segment pipeSegment = this.getSegment();
final Dimension textureDimension;
int gamePosition;
final int upperLimit;
/*
Stampa le texure su schermo.
Game position mantiene la posizione matematica della tubatura (model), e andrà dall'ascissa dell'estremo
più a sinistra se la tubatura è orizzontale oppure dall'ordinata dell'estremo superiore se verticale.
Upperlimit è impostato al limite opposto.
Viene prima dipinta la parte non colorata, poi la parte colorata.
screenPosition mantiene la posizione che deve avere la texture su schermo.
screenPosition viene aggiornato a ogni pezzo di texture come un cursore.
Questa parte riguarda il disegno delle sole parti non modificate in questo step.
*/
Rectangle screenRect;
Point screenPosition;
final Iterator<Map.Entry<Integer, Boolean>> changedIterator = this.changedParts.entrySet()
.iterator();
Map.Entry<Integer, Boolean> nextSkip = changedIterator.hasNext() ? changedIterator.next() : null;
if ( this.isVertical() ) {
textureDimension = loader.getDimension( NON_COLORED_PART_VERTICAL );
gamePosition = pipeSegment.getMinY();
upperLimit = pipeSegment.getMaxY();
for (final PipePart part : parts) {
for (; gamePosition <= upperLimit && gamePosition < part.getStart(); gamePosition++) {
screenRect = GraphicsEnv.getInstance().gamePointAndTextureToScreen( new Point( pipeSegment.getXA(), gamePosition ), textureDimension );
screenPosition = new Point( screenRect.x, screenRect.y );
final String pickTexture;
if ( nextSkip != null && nextSkip.getKey() == gamePosition ) {
pickTexture = ( nextSkip.getValue() ) ? COLORED_PART_VERTICAL : NON_COLORED_PART_VERTICAL;
nextSkip = changedIterator.hasNext() ? changedIterator.next() : null;
} else {
pickTexture = NON_COLORED_PART_VERTICAL;
}
this.doDraw( g2, pickTexture, screenPosition );
}
for (; gamePosition <= part.getEnd(); gamePosition++) {
screenRect = GraphicsEnv.getInstance().gamePointAndTextureToScreen( new Point( pipeSegment.getXA(), gamePosition ), textureDimension );
screenPosition = new Point( screenRect.x, screenRect.y );
final String pickTexture;
if ( nextSkip != null && nextSkip.getKey() == gamePosition ) {
pickTexture = ( nextSkip.getValue() ) ? COLORED_PART_VERTICAL : NON_COLORED_PART_VERTICAL;
nextSkip = changedIterator.hasNext() ? changedIterator.next() : null;
} else {
pickTexture = COLORED_PART_VERTICAL;
}
this.doDraw( g2, pickTexture, screenPosition );
}
}
for (; gamePosition <= upperLimit; gamePosition++) {
screenRect = GraphicsEnv.getInstance().gamePointAndTextureToScreen( new Point( pipeSegment.getXA(), gamePosition ), textureDimension );
screenPosition = new Point( screenRect.x, screenRect.y );
final String pickTexture;
if ( nextSkip != null && nextSkip.getKey() == gamePosition ) {
pickTexture = ( nextSkip.getValue() ) ? COLORED_PART_VERTICAL : NON_COLORED_PART_VERTICAL;
nextSkip = changedIterator.hasNext() ? changedIterator.next() : null;
} else {
pickTexture = NON_COLORED_PART_VERTICAL;
}
this.doDraw( g2, pickTexture, screenPosition );
}
} else {
textureDimension = loader.getDimension( NON_COLORED_PART_HORIZONTAL );
gamePosition = pipeSegment.getMinX();
upperLimit = pipeSegment.getMaxX();
for (final PipePart part : parts) {
for (; gamePosition <= upperLimit && gamePosition < part.getStart(); gamePosition++) {
screenRect = GraphicsEnv.getInstance().gamePointAndTextureToScreen( new Point( gamePosition, pipeSegment.getYA() ), textureDimension );
screenPosition = new Point( screenRect.x, screenRect.y );
final String pickTexture;
if ( nextSkip != null && nextSkip.getKey() == gamePosition ) {
pickTexture = ( nextSkip.getValue() ) ? COLORED_PART_HORIZONTAL : NON_COLORED_PART_HORIZONTAL;
nextSkip = changedIterator.hasNext() ? changedIterator.next() : null;
} else {
pickTexture = NON_COLORED_PART_HORIZONTAL;
}
this.doDraw( g2, pickTexture, screenPosition );
}
for (; gamePosition <= part.getEnd(); gamePosition++) {
screenRect = GraphicsEnv.getInstance().gamePointAndTextureToScreen( new Point( gamePosition, pipeSegment.getYA() ), textureDimension );
screenPosition = new Point( screenRect.x, screenRect.y );
final String pickTexture;
if ( nextSkip != null && nextSkip.getKey() == gamePosition ) {
pickTexture = ( nextSkip.getValue() ) ? COLORED_PART_HORIZONTAL : NON_COLORED_PART_HORIZONTAL;
nextSkip = changedIterator.hasNext() ? changedIterator.next() : null;
} else {
pickTexture = COLORED_PART_HORIZONTAL;
}
this.doDraw( g2, pickTexture, screenPosition );
}
}
for (; gamePosition <= upperLimit; gamePosition++) {
screenRect = GraphicsEnv.getInstance().gamePointAndTextureToScreen( new Point( gamePosition, pipeSegment.getYA() ), textureDimension );
screenPosition = new Point( screenRect.x, screenRect.y );
final String pickTexture;
if ( nextSkip != null && nextSkip.getKey() == gamePosition ) {
pickTexture = ( nextSkip.getValue() ) ? COLORED_PART_HORIZONTAL : NON_COLORED_PART_HORIZONTAL;
nextSkip = changedIterator.hasNext() ? changedIterator.next() : null;
} else {
pickTexture = NON_COLORED_PART_HORIZONTAL;
}
this.doDraw( g2, pickTexture, screenPosition );
}
}
assert ! changedIterator.hasNext();
/*
Draws the modified parts on screen
Modified parts are drawn as slices from the lower coordinate (leftmost X coordinate
is horizontal, upper Y coordinate if vertical) to the upper one of the animation part
*/
if ( ! this.coloringAnimations.isEmpty() ) {
boolean remainingAnimations = false;
if ( this.isVertical() ) {
for (PipeColoringAnimation animation : this.coloringAnimations) {
final Line2D donePart = animation.getDonePart();
if ( donePart == null ) {
continue;
}
final boolean colored = animation.isColoring();
@NonNls
final String selectedTexture = colored ? COLORED_SLICE_VERTICAL : NON_COLORED_SLICE_VERTICAL;
final Dimension sliceDimension = loader.getDimension( selectedTexture );
final Rectangle screenRealPosition = GraphicsEnv.getInstance().gamePointAndTextureToScreen( donePart.getP1(), sliceDimension );
final Rectangle screenRealPositionUpper = GraphicsEnv.getInstance().gamePointAndTextureToScreen( donePart.getP2(), sliceDimension );
final int lowerY = Math.min( screenRealPosition.y, screenRealPositionUpper.y );
final int upperY = Math.max( screenRealPosition.y, screenRealPositionUpper.y );
Point cursor = new Point( screenRealPosition.x, lowerY );
for (; cursor.y < upperY; cursor.y++) {
this.doDraw( g2, selectedTexture, cursor );
}
if ( ! animation.isTerminated() ) {
remainingAnimations = true;
}
}
} else {
for (PipeColoringAnimation animation : this.coloringAnimations) {
final Line2D donePart = animation.getDonePart();
if ( donePart == null ) {
continue;
}
final boolean colored = animation.isColoring();
@NonNls
final String selectedTexture = colored ? COLORED_SLICE_HORIZONTAL : NON_COLORED_SLICE_HORIZONTAL;
final Dimension sliceDimension = loader.getDimension( selectedTexture );
final Rectangle screenRealPosition = GraphicsEnv.getInstance().gamePointAndTextureToScreen( donePart.getP1(), sliceDimension );
final Rectangle screenRealPositionUpper = GraphicsEnv.getInstance().gamePointAndTextureToScreen( donePart.getP2(), sliceDimension );
final int lowerX = Math.min( screenRealPosition.x, screenRealPositionUpper.x );
final int upperX = Math.max( screenRealPosition.x, screenRealPositionUpper.x );