package FText import LinkedList import LinkedListModule import GameTimer import ClosureTimers import ErrorHandling import StringUtils /** Creates a permanent centered FText at the target position */ public function createCenterFText(vec3 pos, string text, real size) returns FText let ft = createFText(pos, text, size, 0, ZERO2) ft.tt..center(pos, text, size) return ft /** Creates a permanent FText at the target position */ public function createFText(vec3 pos, string text, real size) returns FText return createFText(pos, text, size, 0, ZERO2) /** Creates a dynamic FText at the target position */ public function createFText(vec3 pos, string text, real size, real lifespan, vec2 vel) returns FText return createFText(pos, text, size, lifespan, vel, COLOR_WHITE) /** Creates a dynamic FText at the target position */ public function createFText(vec3 pos, vec2 vel, string text, real size, real lifespan, colorA col, player p) returns FText return createFText(pos, text, size, lifespan, vel, col, p) /** Creates a dynamic FText at the target position */ public function createFText(vec3 pos,string text, real size, real lifespan, vec2 vel, colorA col, player p) returns FText let ft = createFText(pos, text, size, lifespan, vel, col) ft.tt.setVisibility(GetLocalPlayer() == p) return ft LinkedList recylcer = new LinkedList() /** Creates a dynamic FText at the target position */ public function createFText(vec3 pos, string text, real size, real lifespan, vec2 vel, colorA col) returns FText let permanent = lifespan <= 0. // Get FText instance FText ftext = null if recylcer.size() > 0 ftext = recylcer.dequeue() else if FText.size < 100 // Recycler was empty and we still have space ftext = new FText() else // we maxed out and need to recycle the oldest, dynamic tag for etext in FText if not etext.permanent and (ftext == null or etext.timestamp < ftext.timestamp) ftext = etext if ftext == null error("You have reached the maximum possible permanent texttags") ftext..setup(text, pos, size) ftext.tt.setColor(col) if permanent ftext..setPermanent() else ftext..setDynamic(vel, lifespan) return ftext public class FText use LinkedListModule texttag tt = CreateTextTag() boolean permanent = false real timestamp = 0 CallbackSingle cb = null construct() tt..setPermanent(true) ondestroy if tt != null tt.destr() tt = null function recycle() cb = null timestamp = 0 if permanent destroy this else tt..setVisibility(false) ..setColor(COLOR_BLACK) ..setText("", 0) recylcer.add(this) function setup(string text, vec3 pos, real size) tt..setText(text, size) ..setPos(pos) ..setAge(0) ..setVisibility(true) ..setVelocity(ZERO2.x, ZERO2.y) ..setFadepoint(.45) ..setLifespan(REAL_MAX) function setPermanent() permanent = true if cb != null destroy cb cb = null function setDynamic(vec2 vel, real lifespan) tt..setVelocity(vel.x, vel.y) ..setLifespan(lifespan) timestamp = getElapsedGameTime() if cb != null destroy cb cb = doAfter(lifespan-0.025, () -> this.recycle())