001package com.fs.starfarer.api.util;
002
003import java.awt.Color;
004import java.util.ArrayList;
005import java.util.List;
006
007import com.fs.starfarer.api.campaign.SectorEntityToken;
008import com.fs.starfarer.api.util.CampaignEntityMovementUtil.EngineGlowControls;
009
010public class CampaignEngineGlowUtil implements EngineGlowControls {
011
012        public static String KEY1 = "key1";
013        public static String KEY2 = "key2";
014        public static String KEY3 = "key3";
015        public static String KEY4 = "key4";
016        public static String KEY5 = "key5";
017        public static String KEY6 = "key6";
018        
019        protected List<CampaignEngineGlowIndividualEngine> engines = new ArrayList<CampaignEngineGlowIndividualEngine>();
020        protected SectorEntityToken entity;
021        
022        protected ValueShifterUtil glowCoreMult = new ValueShifterUtil(1f);
023        protected ValueShifterUtil glowFringeMult = new ValueShifterUtil(1f);
024        protected ValueShifterUtil glowMult = new ValueShifterUtil(0f);
025        protected ValueShifterUtil lengthMult = new ValueShifterUtil(0f);
026        protected ValueShifterUtil widthMult = new ValueShifterUtil(0f);
027        protected ValueShifterUtil flickerMult = new ValueShifterUtil(0f);
028        protected ValueShifterUtil flickerRateMult = new ValueShifterUtil(1f);
029        protected ValueShifterUtil textureScrollMult = new ValueShifterUtil(1f);
030        protected ColorShifterUtil glowColorCore;
031        protected ColorShifterUtil glowColorFringe;
032        protected ColorShifterUtil flameColor;
033        private float shiftRate;
034        
035        public CampaignEngineGlowUtil(SectorEntityToken entity, 
036                                                Color fringe, Color core, Color flame, float shiftRate) {
037                this.entity = entity;
038                this.shiftRate = shiftRate;
039                glowColorCore = new ColorShifterUtil(core);
040                glowColorFringe = new ColorShifterUtil(fringe);
041                flameColor = new ColorShifterUtil(flame);
042        }
043
044        public void addEngine(CampaignEngineGlowIndividualEngine engine) {
045                engines.add(engine);
046        }
047
048        
049        public void showOtherAction() {
050                glowMult.shift(KEY1, 1.5f, 1f, 1f, 1f);
051                lengthMult.shift(KEY1, 0.33f, 1f, 1f, 1f);
052                widthMult.shift(KEY1, 1f, 1f, 1f, 1f);
053        }
054        public void showAccelerating() {
055                glowMult.shift(KEY2, 1f, 1f, 1f, 1f);
056                lengthMult.shift(KEY2, 1f, 1f, 1f, 1f);
057                widthMult.shift(KEY2, 1f, 1f, 1f, 1f);
058//              glowMult.shift(KEY2, 2f, 1f, 1f, 1f);
059//              lengthMult.shift(KEY2, 2f, 1f, 1f, 1f);
060//              widthMult.shift(KEY2, 2f, 1f, 1f, 1f);
061        }
062        public void showIdling() {
063                //if (true) {
064//              if (Keyboard.isKeyDown(Keyboard.KEY_H)) {
065//                      showSuppressed();
066//                      return;
067//              }
068//              if (Keyboard.isKeyDown(Keyboard.KEY_J)) {
069//                      showOtherAction();
070//                      return;
071//              }
072//              if (Keyboard.isKeyDown(Keyboard.KEY_K)) {
073//                      showAccelerating();
074//                      return;
075//              }
076                
077                glowMult.shift(KEY3, 0.5f, 1f, 1f, 1f);
078                glowFringeMult.shift(KEY3, 1.5f, 1f, 1f, 1f);
079                lengthMult.shift(KEY3, 0.25f, 1f, 1f, 1f);
080                widthMult.shift(KEY3, 1.5f, 1f, 1f, 1f);
081
082                glowColorCore.shift(KEY3, glowColorFringe.getBase(), 1f, 1f, 0.5f);
083                glowColorFringe.shift(KEY3, Color.black, 1f, 1f, 0.5f);
084                flameColor.shift(KEY3, Color.black, 1f, 1f, 0.75f);
085                
086                //flickerMult.shift(KEY3, 0.5f, 1f, 1f, 1f);
087        }
088        
089        public void showSuppressed() {
090                glowMult.shift(KEY4, 0.5f, 1f, 1f, 1f);
091                glowFringeMult.shift(KEY4, 0.5f, 1f, 1f, 1f);
092                lengthMult.shift(KEY4, 0.25f, 1f, 1f, 1f);
093                widthMult.shift(KEY4, 1f, 1f, 1f, 1f);
094                
095//              glowMult.shift(KEY4, 0.5f, 1f, 1f, 1f);
096//              glowFringeMult.shift(KEY4, 1.5f, 1f, 1f, 1f);
097//              lengthMult.shift(KEY4, 0.25f, 1f, 1f, 1f);
098//              widthMult.shift(KEY4, 1.5f, 1f, 1f, 1f);
099                
100                float in = 0.5f;
101                if (lengthMult.getCurr() <= 0f || widthMult.getCurr() <= 0f) {
102                        in = 0f;
103                }
104                glowColorCore.shift(KEY4, Color.black, in, 1f, 1f);
105                glowColorFringe.shift(KEY4, Color.black, in, 1f, 1f);
106                flameColor.shift(KEY4, Color.black, in, 1f, 1f);
107        }
108        
109        
110        public void advance(float amount) {
111                float shiftAmount = amount * shiftRate;
112                //shiftAmount *= 5f;
113                
114                glowMult.advance(shiftAmount);
115                glowFringeMult.advance(shiftAmount);
116                glowCoreMult.advance(shiftAmount);
117                lengthMult.advance(shiftAmount);
118                widthMult.advance(shiftAmount);
119                flickerMult.advance(shiftAmount);
120                flickerRateMult.advance(shiftAmount);
121                textureScrollMult.advance(shiftAmount);
122                
123                glowColorCore.advance(shiftAmount);
124                glowColorFringe.advance(shiftAmount);
125                flameColor.advance(shiftAmount);
126                
127                for (CampaignEngineGlowIndividualEngine engine : engines) {
128                        engine.advance(amount);
129                }
130        }
131        
132        
133        public void render(float alphaMult) {
134                for (CampaignEngineGlowIndividualEngine engine : engines) {
135                        engine.render(entity.getLocation(), entity.getFacing(), alphaMult);
136                }
137        }
138
139        public ValueShifterUtil getGlowMult() {
140                return glowMult;
141        }
142
143        public ValueShifterUtil getLengthMult() {
144                return lengthMult;
145        }
146
147        public ValueShifterUtil getWidthMult() {
148                return widthMult;
149        }
150
151        public ValueShifterUtil getTextureScrollMult() {
152                return textureScrollMult;
153        }
154
155        public ColorShifterUtil getGlowColorCore() {
156                return glowColorCore;
157        }
158
159        public ColorShifterUtil getGlowColorFringe() {
160                return glowColorFringe;
161        }
162
163        public ColorShifterUtil getFlameColor() {
164                return flameColor;
165        }
166
167        public ValueShifterUtil getFlickerMult() {
168                return flickerMult;
169        }
170        public ValueShifterUtil getFlickerRateMult() {
171                return flickerRateMult;
172        }
173
174        public ValueShifterUtil getGlowCoreMult() {
175                return glowCoreMult;
176        }
177
178        public ValueShifterUtil getGlowFringeMult() {
179                return glowFringeMult;
180        }
181        
182}
183
184
185
186
187
188
189
190