(str: string, y: number, x1: number, x2: number, speechClass: string = null, translatedText: string = null)
| 296 | } |
| 297 | |
| 298 | public drawSpeech(str: string, y: number, x1: number, x2: number, speechClass: string = null, translatedText: string = null): number{ |
| 299 | var currentLine: string = ""; // Current line |
| 300 | var lastWordIndex: number = 0; // Index of the last word drawn |
| 301 | var width: number = x2-x1-1; // We calculate the speech's width (-1 because we need space for the " characters) |
| 302 | var words: string[] = str.split(" "); // We split the strings into an array of words |
| 303 | var xPos: number; // Used to store some position at some time |
| 304 | |
| 305 | // Draw the first " character |
| 306 | this.drawString("\"", x1, y); |
| 307 | |
| 308 | for(var i = 0; i < words.length; i++){ |
| 309 | // If adding the current word to the line would exceed the width or we're working on the last word |
| 310 | if(currentLine.length + words[i].length >= width){ |
| 311 | // We draw the current line |
| 312 | xPos = x1 + 1 + width/2-(currentLine.length/2); |
| 313 | this.drawString(currentLine, xPos, y); |
| 314 | // If a speechClass is specified, we add tags |
| 315 | if(speechClass != null) this.addTwoTags(xPos, xPos + currentLine.length, y, "<span class=\"" + speechClass + "\">", "</span>"); |
| 316 | // We go to the line below |
| 317 | currentLine = ""; |
| 318 | y++; |
| 319 | } |
| 320 | // We add a space before the word if there's at least one word before |
| 321 | if(currentLine != "") currentLine += " "; |
| 322 | // We add the word to the current line |
| 323 | currentLine += words[i]; |
| 324 | // If we're working on the last word, we draw the line anyway |
| 325 | if(i == words.length-1){ |
| 326 | xPos = x1 + 1 + width/2-(currentLine.length/2); |
| 327 | this.drawString(currentLine, xPos, y); |
| 328 | // If a speechClass is specified, we add tags |
| 329 | if(speechClass != null) this.addTwoTags(xPos, xPos + currentLine.length, y, "<span class=\"" + speechClass + "\">", "</span>"); |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | // Draw the second " character |
| 334 | this.drawString("\"", x2, y); |
| 335 | |
| 336 | // If we should add a translation, then we add it and the translated text isn't empty |
| 337 | if(translatedText != null && translatedText != ""){ |
| 338 | this.addTooltip(speechClass + "Tooltip", translatedText); |
| 339 | this.addLinkOnHoverShowTooltip("." + speechClass, "." + speechClass + "Tooltip"); |
| 340 | } |
| 341 | |
| 342 | // We return y, which is the y position of the last speech line |
| 343 | return y; |
| 344 | } |
| 345 | |
| 346 | public drawString(str: string, x: number = 0, y: number = 0, translated: boolean = false, transparency: RenderTransparency = null): boolean{ |
| 347 | var indexFirst: number; |
nothing calls this directly
no test coverage detected