Starsector API
Loading...
Searching...
No Matches
ExampleCustomUIPanel.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign;
2
3import java.awt.Color;
4import java.util.List;
5
6import org.lwjgl.opengl.GL11;
7
8import com.fs.starfarer.api.Global;
9import com.fs.starfarer.api.campaign.BaseCustomUIPanelPlugin;
10import com.fs.starfarer.api.graphics.SpriteAPI;
11import com.fs.starfarer.api.input.InputEventAPI;
12import com.fs.starfarer.api.ui.PositionAPI;
13
14public class ExampleCustomUIPanel extends BaseCustomUIPanelPlugin {
15
16 private PositionAPI p;
17 private SpriteAPI sprite;
18
19 private float mouseX, mouseY;
20
22 sprite = Global.getSettings().getSprite("graphics/ships/wolf/wolf_base.png");
23 }
24
25 public void positionChanged(PositionAPI position) {
26 p = position;
27 mouseX = p.getX() + p.getWidth() / 2f;
28 mouseY = p.getY() + p.getHeight() / 2f;
29 }
30
31 public void advance(float amount) {
32 if (p == null) return;
33
34 }
35
36 public void processInput(List<InputEventAPI> events) {
37 if (p == null) return;
38
39 for (InputEventAPI event : events) {
40 if (event.isConsumed()) continue;
41
42 if (event.isMouseMoveEvent()) {
43 if (p.containsEvent(event)) {
44 mouseX = event.getX();
45 mouseY = event.getY();
46 //System.out.println("x,y: " + x + "," + y);
47 } else {
48 mouseX = p.getX() + p.getWidth() / 2f;
49 mouseY = p.getY() + p.getHeight() / 2f;
50 }
51 }
52 }
53 }
54
55 public void render(float alphaMult) {
56 if (p == null) return;
57
58 float x = p.getX();
59 float y = p.getY();
60 float w = p.getWidth();
61 float h = p.getHeight();
62
63 GL11.glDisable(GL11.GL_TEXTURE_2D);
64 GL11.glEnable(GL11.GL_BLEND);
65 GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
66
67 Color color = Color.cyan;
68
69 GL11.glColor4ub((byte)color.getRed(),
70 (byte)color.getGreen(),
71 (byte)color.getBlue(),
72 (byte)(color.getAlpha() * alphaMult * 0.25f));
73
74 GL11.glBegin(GL11.GL_QUADS);
75 {
76 GL11.glVertex2f(x, y);
77 GL11.glVertex2f(x, y + h);
78 GL11.glVertex2f(x + w, y + h);
79 GL11.glVertex2f(x + w, y);
80 }
81 GL11.glEnd();
82
83// mouseX = Mouse.getX();
84// mouseY = Mouse.getY();
85 sprite.setAlphaMult(alphaMult);
86 sprite.renderAtCenter(mouseX, mouseY);
87
88 }
89
90 public void renderBelow(float alphaMult) {
91
92 }
93
94 @Override
95 public void buttonPressed(Object buttonId) {
96 super.buttonPressed(buttonId);
97 }
98
99
100
101}
static SettingsAPI getSettings()
Definition Global.java:51
SpriteAPI getSprite(String filename)