001package com.fs.starfarer.api.impl.campaign;
002
003import java.awt.Color;
004import java.util.List;
005
006import org.lwjgl.opengl.GL11;
007
008import com.fs.starfarer.api.Global;
009import com.fs.starfarer.api.campaign.BaseCustomUIPanelPlugin;
010import com.fs.starfarer.api.graphics.SpriteAPI;
011import com.fs.starfarer.api.input.InputEventAPI;
012import com.fs.starfarer.api.ui.PositionAPI;
013
014public class ExampleCustomUIPanel extends BaseCustomUIPanelPlugin {
015
016        private PositionAPI p;
017        private SpriteAPI sprite;
018
019        private float mouseX, mouseY;
020        
021        public ExampleCustomUIPanel() {
022                sprite = Global.getSettings().getSprite("graphics/ships/wolf/wolf_base.png");
023        }
024
025        public void positionChanged(PositionAPI position) {
026                p = position;
027                mouseX = p.getX() + p.getWidth() / 2f;
028                mouseY = p.getY() + p.getHeight() / 2f;
029        }
030        
031        public void advance(float amount) {
032                if (p == null) return;
033                
034        }
035
036        public void processInput(List<InputEventAPI> events) {
037                if (p == null) return;
038                
039                for (InputEventAPI event : events) {
040                        if (event.isConsumed()) continue;
041                        
042                        if (event.isMouseMoveEvent()) {
043                                if (p.containsEvent(event)) {
044                                        mouseX = event.getX();
045                                        mouseY = event.getY();
046                                        //System.out.println("x,y: " + x + "," + y);
047                                } else {
048                                        mouseX = p.getX() + p.getWidth() / 2f;
049                                        mouseY = p.getY() + p.getHeight() / 2f;
050                                }
051                        }
052                }
053        }
054
055        public void render(float alphaMult) {
056                if (p == null) return;
057                
058                float x = p.getX();
059                float y = p.getY();
060                float w = p.getWidth();
061                float h = p.getHeight();
062                
063                GL11.glDisable(GL11.GL_TEXTURE_2D);
064                GL11.glEnable(GL11.GL_BLEND);
065                GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
066
067                Color color = Color.cyan;
068                
069                GL11.glColor4ub((byte)color.getRed(),
070                                                (byte)color.getGreen(),
071                                                (byte)color.getBlue(),
072                                                (byte)(color.getAlpha() * alphaMult * 0.25f));
073                
074                GL11.glBegin(GL11.GL_QUADS);
075                {
076                        GL11.glVertex2f(x, y);
077                        GL11.glVertex2f(x, y + h);
078                        GL11.glVertex2f(x + w, y + h);
079                        GL11.glVertex2f(x + w, y);
080                }
081                GL11.glEnd();
082                
083//              mouseX = Mouse.getX();
084//              mouseY = Mouse.getY();
085                sprite.setAlphaMult(alphaMult);
086                sprite.renderAtCenter(mouseX, mouseY);
087                
088        }
089
090        public void renderBelow(float alphaMult) {
091                
092        }
093
094        @Override
095        public void buttonPressed(Object buttonId) {
096                super.buttonPressed(buttonId);
097        }
098        
099        
100
101}