package com.fundynamic.d2tm.game.behaviors;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;

/**
 * An implementation of selecting / deselecting something + with drawing effects
 */
public class FadingSelection extends SimpleSelectLogic implements Renderable, Updateable {

    private float selectedIntensity;
    private boolean selectedDarkening;

    private final int width;
    private final int height;

    public FadingSelection(int width, int height) {
        this.width = width;
        this.height = height;
        this.selectedIntensity = 1f;
        this.selectedDarkening = true;
    }

    public void update(float delta) {
        if (selected) {
            float intensityChange = .5f * delta;
            if (selectedDarkening) {
                selectedIntensity -= intensityChange;
            } else {
                selectedIntensity += intensityChange;
            }

            // fade back and forth
            if (selectedIntensity <= 0.0f) {
                selectedIntensity = 0.0f;
                selectedDarkening = false;
            } else if (selectedIntensity >= 1.0f) {
                selectedIntensity = 1.0f;
                selectedDarkening = true;
            }
        } else {
            selectedIntensity = 1f;
            selectedDarkening = true;
        }
    }

    @Override
    public void render(Graphics graphics, int drawX, int drawY) {
        if (selected) {
            graphics.setColor(new Color(selectedIntensity, selectedIntensity, selectedIntensity));
            graphics.setLineWidth(2.f);
            graphics.drawRect(drawX, drawY, width, height - 1);
        }
    }
}

@@ -546,74 +546,21 @@
     
-this.selectedIntensity = 1f;%0A        this.selectedDarkening = true
+resetFading()
 ;%0A  
@@ -622,32 +622,281 @@
 selected) %7B%0A    
+        updateFadingColor(delta);%0A        %7D else %7B%0A            resetFading();%0A        %7D%0A    %7D%0A%0A    public void resetFading() %7B%0A        selectedIntensity = 1f;%0A        selectedDarkening = true;%0A    %7D%0A%0A    public void updateFadingColor(float delta) %7B%0A
         float in
@@ -924,36 +924,32 @@
  delta;%0A        
-   
- 
 if (selectedDark
@@ -953,28 +953,24 @@
 arkening) %7B%0A
-    
             
@@ -1011,28 +1011,24 @@
 ge;%0A        
-    
 %7D else %7B%0A   
@@ -1016,36 +1016,32 @@
        %7D else %7B%0A
-    
             sele
@@ -1082,27 +1082,19 @@
         
-    %7D%0A%0A    
+%7D%0A%0A
         
@@ -1116,20 +1116,16 @@
 d forth%0A
-    
         
@@ -1161,36 +1161,32 @@
 ) %7B%0A            
-    
 selectedIntensit
@@ -1199,36 +1199,32 @@
 0f;%0A            
-   
- 
 selectedDarkenin
@@ -1234,20 +1234,16 @@
  false;%0A
-    
         
@@ -1286,36 +1286,32 @@
 ) %7B%0A            
- 
-   
 selectedIntensit
@@ -1324,117 +1324,8 @@
 0f;%0A
-                selectedDarkening = true;%0A            %7D%0A        %7D else %7B%0A            selectedIntensity = 1f;%0A
     

Make it more explicit when the fading code does what