001package com.fs.starfarer.api.impl.campaign.eventide; 002 003import java.awt.Color; 004import java.util.List; 005 006import org.lwjgl.opengl.GL11; 007 008import com.fs.starfarer.api.campaign.BaseCustomUIPanelPlugin; 009import com.fs.starfarer.api.campaign.CustomVisualDialogDelegate.DialogCallbacks; 010import com.fs.starfarer.api.campaign.InteractionDialogAPI; 011import com.fs.starfarer.api.input.InputEventAPI; 012import com.fs.starfarer.api.ui.CustomPanelAPI; 013import com.fs.starfarer.api.ui.LabelAPI; 014import com.fs.starfarer.api.ui.PositionAPI; 015import com.fs.starfarer.api.ui.TooltipMakerAPI; 016import com.fs.starfarer.api.util.FaderUtil; 017import com.fs.starfarer.api.util.Misc; 018 019public class DuelTutorialPanel extends BaseCustomUIPanelPlugin { 020 021 public static enum TutStage { 022 INIT, 023 MOVE_FORWARD, 024 MOVE_BACK, 025 ATTACK, 026 BLOCK, 027 LEAVE; 028 029 private static TutStage [] vals = values(); 030 public TutStage next() { 031 int index = this.ordinal() + 1; 032 if (index >= vals.length) index = vals.length - 1; 033 return vals[index]; 034 } 035 } 036 037 protected InteractionDialogAPI dialog; 038 protected DialogCallbacks callbacks; 039 protected CustomPanelAPI panel; 040 protected PositionAPI p; 041 042 protected TutStage curr = null; 043 protected TooltipMakerAPI info; 044 protected float untilNext = 0f; 045 protected boolean triggeredNext = false; 046 protected FaderUtil flash = new FaderUtil(0f, 0.125f, 0.5f, false, true); 047 048 public DuelTutorialPanel() { 049 } 050 051 public void init(CustomPanelAPI panel, DialogCallbacks callbacks, InteractionDialogAPI dialog) { 052 this.panel = panel; 053 this.callbacks = callbacks; 054 this.dialog = dialog; 055 curr = TutStage.INIT; 056 showNext(); 057 } 058 059 public void showNext() { 060 if (curr == TutStage.LEAVE) return; 061 curr = curr.next(); 062 if (info != null) { 063 panel.removeComponent(info); 064 } 065 float opad = 10f; 066 Color h = Misc.getHighlightColor(); 067 info = panel.createUIElement(p.getWidth() - 20f, 1000f, false); 068 info.setParaInsigniaLarge(); 069 070 if (curr == TutStage.MOVE_FORWARD) { 071 info.addPara("Press RIGHT to move forward.", 0f, h, "RIGHT"); 072 } else if (curr == TutStage.MOVE_BACK) { 073 info.addPara("Press LEFT to move backwards.", 0f, h, "LEFT"); 074 } else if (curr == TutStage.ATTACK) { 075 info.addPara("Press SPACE to attack.", 0f, h, "SPACE"); 076 } else if (curr == TutStage.BLOCK) { 077 LabelAPI label = info.addPara("Press UP to block or parry. " 078 + "A skilled fighter can also execute a quick attack, or a \"riposte\", by attacking immediately after deflecting their opponent's attack.", 0f, h, "UP"); 079 label.setHighlightColors(h, Misc.getStoryOptionColor()); 080 label.setHighlight("UP", "skilled fighter"); 081 } else if (curr == TutStage.LEAVE) { 082 info.addPara("Your health is in the top left of the screen.\n\n" 083 + "Make a few practice moves, then press ESCAPE to continue.", 0f, h, "ESCAPE"); 084 } 085 086 panel.addUIElement(info).inTL(opad, opad); 087 flash.fadeIn(); 088 } 089 090 public void reportAction(String actionId) { 091 boolean triggered = false; 092 triggered |= curr == TutStage.MOVE_FORWARD && Actions.MOVE_FORWARD.equals(actionId); 093 triggered |= curr == TutStage.MOVE_BACK && Actions.MOVE_BACK.equals(actionId); 094 triggered |= curr == TutStage.ATTACK && Actions.ATTACK.equals(actionId); 095 triggered |= curr == TutStage.BLOCK && Actions.BLOCK.equals(actionId); 096 if (triggered) { 097 triggeredNext = true; 098 untilNext = 1f; 099 } 100 } 101 102 public CustomPanelAPI getPanel() { 103 return panel; 104 } 105 106 public PositionAPI getPosition() { 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