Starsector API
Loading...
Searching...
No Matches
DuelTutorialPanel.java
Go to the documentation of this file.
1package com.fs.starfarer.api.impl.campaign.eventide;
2
3import java.awt.Color;
4import java.util.List;
5
6import org.lwjgl.opengl.GL11;
7
8import com.fs.starfarer.api.campaign.BaseCustomUIPanelPlugin;
9import com.fs.starfarer.api.campaign.CustomVisualDialogDelegate.DialogCallbacks;
10import com.fs.starfarer.api.campaign.InteractionDialogAPI;
11import com.fs.starfarer.api.input.InputEventAPI;
12import com.fs.starfarer.api.ui.CustomPanelAPI;
13import com.fs.starfarer.api.ui.LabelAPI;
14import com.fs.starfarer.api.ui.PositionAPI;
15import com.fs.starfarer.api.ui.TooltipMakerAPI;
16import com.fs.starfarer.api.util.FaderUtil;
17import com.fs.starfarer.api.util.Misc;
18
20
21 public static enum TutStage {
22 INIT,
23 MOVE_FORWARD,
24 MOVE_BACK,
25 ATTACK,
26 BLOCK,
27 LEAVE;
28
29 private static TutStage [] vals = values();
30 public TutStage next() {
31 int index = this.ordinal() + 1;
32 if (index >= vals.length) index = vals.length - 1;
33 return vals[index];
34 }
35 }
36
40 protected PositionAPI p;
41
42 protected TutStage curr = null;
44 protected float untilNext = 0f;
45 protected boolean triggeredNext = false;
46 protected FaderUtil flash = new FaderUtil(0f, 0.125f, 0.5f, false, true);
47
49 }
50
52 this.panel = panel;
53 this.callbacks = callbacks;
54 this.dialog = dialog;
55 curr = TutStage.INIT;
56 showNext();
57 }
58
59 public void showNext() {
60 if (curr == TutStage.LEAVE) return;
61 curr = curr.next();
62 if (info != null) {
64 }
65 float opad = 10f;
66 Color h = Misc.getHighlightColor();
67 info = panel.createUIElement(p.getWidth() - 20f, 1000f, false);
69
70 if (curr == TutStage.MOVE_FORWARD) {
71 info.addPara("Press RIGHT to move forward.", 0f, h, "RIGHT");
72 } else if (curr == TutStage.MOVE_BACK) {
73 info.addPara("Press LEFT to move backwards.", 0f, h, "LEFT");
74 } else if (curr == TutStage.ATTACK) {
75 info.addPara("Press SPACE to attack.", 0f, h, "SPACE");
76 } else if (curr == TutStage.BLOCK) {
77 LabelAPI label = info.addPara("Press UP to block or parry. "
78 + "A skilled fighter can also execute a quick attack, or a \"riposte\", by attacking immediately after deflecting their opponent's attack.", 0f, h, "UP");
80 label.setHighlight("UP", "skilled fighter");
81 } else if (curr == TutStage.LEAVE) {
82 info.addPara("Your health is in the top left of the screen.\n\n"
83 + "Make a few practice moves, then press ESCAPE to continue.", 0f, h, "ESCAPE");
84 }
85
86 panel.addUIElement(info).inTL(opad, opad);
87 flash.fadeIn();
88 }
89
90 public void reportAction(String actionId) {
91 boolean triggered = false;
92 triggered |= curr == TutStage.MOVE_FORWARD && Actions.MOVE_FORWARD.equals(actionId);
93 triggered |= curr == TutStage.MOVE_BACK && Actions.MOVE_BACK.equals(actionId);
94 triggered |= curr == TutStage.ATTACK && Actions.ATTACK.equals(actionId);
95 triggered |= curr == TutStage.BLOCK && Actions.BLOCK.equals(actionId);
96 if (triggered) {
97 triggeredNext = true;
98 untilNext = 1f;
99 }
100 }
101
103 return panel;
104 }
105
107 return p;
108 }
109
110 public void positionChanged(PositionAPI position) {
111 this.p = position;
112 }
113
114 public void render(float alphaMult) {
115
116 }
117
118 public void renderBelow(float alphaMult) {
119 if (p == null) return;
120 float x = p.getX();
121 float y = p.getY();
122 float cx = p.getCenterX();
123 float cy = p.getCenterY();
124 float w = p.getWidth();
125 float h = p.getHeight();
126
127 GL11.glDisable(GL11.GL_TEXTURE_2D);
128 GL11.glEnable(GL11.GL_BLEND);
129 GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
130
131 Color c = Misc.getBasePlayerColor();
132 float a = alphaMult;
133 Misc.renderQuad(x, y, w, 1, c, a);
134 Misc.renderQuad(x, y + h - 1, w, 1, c, a);
135 Misc.renderQuad(x, y + 1, 1, h - 2, c, a);
136 Misc.renderQuad(x + w - 1, y + 1, 1, h - 2, c, a);
137
138 Misc.renderQuad(x + w, y - 1, 1, h, Color.black, a);
139 Misc.renderQuad(x + 1, y - 1, w - 1, 1, Color.black, a);
140
141 Misc.renderQuad(x + 1, y + 1, w - 2, h - 2, Color.black, a * 0.67f);
142
143 GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
144 Misc.renderQuad(x + 1, y + 1, w - 2, h - 2, Misc.getBrightPlayerColor(), a * 0.25f * flash.getBrightness());
145 }
146
147
148 public void advance(float amount) {
149 if (p == null) return;
150 if (triggeredNext) {
151 untilNext -= amount;
152 if (untilNext <= 0f) {
153 triggeredNext = false;
154 showNext();
155 }
156 }
157 flash.advance(amount);
158 }
159
160 public void processInput(List<InputEventAPI> events) {
161 if (p == null) return;
162
163 }
164
165}
166
167
168
void init(CustomPanelAPI panel, DialogCallbacks callbacks, InteractionDialogAPI dialog)
static Color getStoryOptionColor()
Definition Misc.java:782
static void renderQuad(float x, float y, float width, float height, Color color, float alphaMult)
Definition Misc.java:1842
static Color getBasePlayerColor()
Definition Misc.java:833
static Color getBrightPlayerColor()
Definition Misc.java:830
static Color getHighlightColor()
Definition Misc.java:792
TooltipMakerAPI createUIElement(float width, float height, boolean withScroller)
PositionAPI addUIElement(TooltipMakerAPI element)
void setHighlight(int start, int end)
void setHighlightColors(Color ... colors)
PositionAPI inTL(float xPad, float yPad)
LabelAPI addPara(String format, float pad, Color hl, String... highlights)
void removeComponent(UIComponentAPI component)