1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
| package edu.bgp.global.utilities;
import java.awt.Font; import java.util.List; import java.util.ArrayList;
import org.newdawn.slick.Image; import org.newdawn.slick.Graphics; import org.newdawn.slick.TrueTypeFont; import org.newdawn.slick.Color; import org.newdawn.slick.SlickException; import org.newdawn.slick.Input; import org.newdawn.slick.GameContainer;
public class textBoxBase{ TrueTypeFont trueTypeFont; Image textBox; Image textDown; int line = 0; int size = 0; int cooldown = 0; static final int COOLDOWNSET = 20; float boxFader = 0; int boxSlider = 160; int textFader = 0; public boolean rendering = false; String textToRender[]; String personTalking = ""; List <String> textQueue = new ArrayList<String>(); List <String> nameQueue = new ArrayList<String>(); public textBoxBase(){ try{ trueTypeFont = new TrueTypeFont(new Font("Arial", Font.ITALIC, 16), true); textBox = new Image("res/gui/textBox.png"); textDown = new Image("res/gui/textDown.png"); }catch(SlickException e){} } public void render(Graphics g, GameContainer gc){ Input input = gc.getInput(); g.drawImage(textBox, 90, 360+boxSlider, new Color(1f,1f,1f,boxFader)); if (cooldown == 0){ g.drawImage(textDown, 650, 500+boxSlider,new Color(1f,1f,1f,boxFader)); } if (rendering){ if (boxFader < 1){ boxFader += 0.10; boxSlider -= 15; } if (textFader != 255){ textFader += 15; } try{ trueTypeFont.drawString(170, 410, personTalking, Color.black); trueTypeFont.drawString(200, 430, textToRender[line] , new Color(0, 0, 0, textFader)); trueTypeFont.drawString(200, 450, textToRender[line+1] , new Color(0, 0, 0, textFader)); trueTypeFont.drawString(200, 470, textToRender[line+2] , new Color(0, 0, 0, textFader)); }catch(Exception e){} if (input.isMouseButtonDown(input.MOUSE_LEFT_BUTTON)){ if (line <= size && cooldown == 0){line+=3; cooldown = COOLDOWNSET; textFader = 0;} } if (line > size){ rendering = false; } if (cooldown != 0){cooldown--;} } if (!rendering){ line = 0; if (!textQueue.isEmpty()){ spliceText(textQueue.get(0), nameQueue.get(0)); textQueue.remove(0); nameQueue.remove(0); }else{ if (boxFader != 0){ boxFader -= 0.30; boxSlider+=40; } } textFader = 0; } } public void spliceText(String text, String name){ int mark = 0; personTalking = name; textToRender = new String[text.length()/50+4]; size = text.length()/50; for (int x = 0; x < text.length(); x++){ if (x > mark+50){ textToRender[mark/50] = text.substring(mark, x); textToRender[(mark/50)+1] = ""; textToRender[(mark/50)+2] = ""; mark = x; }else{ if (mark+50 > text.length()){ textToRender[mark/50] = text.substring(mark, text.length()); } } } rendering = true; } public void newMessage(String text, String name){ if (rendering == false){ spliceText(text, name); }else if (rendering){ textQueue.add(text); nameQueue.add(name); } } } |