package Texter import BaseObject import Escaper import StringUtils import Decoration constant INFO_TEXTER_ID = compiletime(ABIL_ID_GEN.next()) constant EVENT_RADIUS = 32. let stdcolors = ["white", "red", "blue", "teal", "purple", "yellow", "orange", "green", "pink", "gray", "lightblue", "darkgreen", "brown"] public class Texter extends StaticBaseObject FText text var hidden = true var col = color(255,255,255) construct(vec2 pos, player owner) super(pos, createUnit(owner, TEXTER_ID, pos, angle(0)), EVENT_RADIUS, function Texter.onStep, null) setEnabled(false) text = createCenterFText(actor.getPos3Zero(), "", 12) text.tt..setColor(col.red,col.green,col.blue, 0)..setVisibility(false) function show() text.tt.setVisibility(true) hidden = false createFText(pos, vec2(0,0.05), "Shown", 10, 2., colorA(255,255,255,0), owner) function hide() text.tt.setVisibility(false) hidden = true createFText(pos, vec2(0,0.05), "Hidden", 10, 2., colorA(255,255,255,0), owner) static function onStep() let u = GetTriggerUnit() let e = u.getEntity() let obj = GetTriggeringTrigger().getSource().getEntity() castTo Texter if e instanceof Escaper obj.show() function onShow() forUnitsOfPlayer(owner) u -> if IsUnitSelected(u, owner) let ent = u.getEntity() if ent instanceof Texter let obj = u.getEntity() castTo thistype obj.show() function onHide() forUnitsOfPlayer(owner) u -> if IsUnitSelected(u, owner) let ent = u.getEntity() if ent instanceof Texter let obj = u.getEntity() castTo thistype obj.hide() function setText(string txt) clearQuestionmark() text.tt.center(getPos(), txt, 10) if hidden createFText(pos, vec2(0,0.05), txt, 10, 2., COLOR_WHITE, owner) static function setColor(Entity ent, string color) let textcolor = getColorFromString(color + " ") if ent instanceof Texter let obj = ent castTo Texter if obj.col != textcolor obj.col = textcolor obj.text.tt.setColor(obj.col.red,obj.col.green,obj.col.blue, 0) createFText(obj.pos, vec2(0,0.05), "Color Set", 10, 2., obj.col.withAlpha(0), obj.owner) else if ent instanceof Decoration let obj = ent castTo Decoration obj.actor.setVertexColor(textcolor) obj.setup.setVertexColor(textcolor) else if ent instanceof SetupObject let obj = ent castTo SetupObject obj.actor.setVertexColor(textcolor) obj.setup.setVertexColor(textcolor) ondestroy destroy text override function serialize() returns Json let json = super.serialize() json..addProperty(new Property(KEY_TYPE, TEXTER_INDEX.toString())) return json override function activate() show() override function deactivate() super.deactivate() hide() function getColorFromString(string s) returns color boolean isstdcolor = false color stringcolor = color(255,255,255) for int i = 1 to 12 if stdcolors[i]+ " " == s stringcolor = players[i-1].getColor().toColor() isstdcolor = true if not isstdcolor int component = 0 string tempstring = "" for int ii = 0 to StringLength(s) - 1 if SubString(s, ii, ii + 1) != " " tempstring += SubString(s, ii, ii + 1) else switch component case 0 stringcolor.red = S2I(tempstring) case 1 stringcolor.green = S2I(tempstring) case 2 stringcolor.blue = S2I(tempstring) component++ tempstring = "" return stringcolor interface TexterClsr function run(Texter texter) function forSelectedTexters(TexterClsr cb) let p = GetTriggerPlayer() forUnitsOfPlayer(p) u -> if IsUnitSelected(u, GetTriggerPlayer()) and u.getTypeId() == TEXTER_ID cb.run(u.getEntity() castTo Texter) init EventListener.add(EVENT_PLAYER_CHAT_FILTER) -> let text = GetEventPlayerChatString() if text.contains(" ") let tokens = text.split(" ") switch tokens.dequeue() case "-st" forSelectedTexters(t -> t.setText(tokens.joinBy(" "))) case "-sc" forUnitsOfPlayer(GetTriggerPlayer()) u -> if IsUnitSelected(u, GetTriggerPlayer()) Texter.setColor(u.getEntity(), tokens.joinBy(" ")) else switch text case "-sht" forSelectedTexters(t -> t.show()) case "-ht" forSelectedTexters(t -> t.hide()) @objectgen function genTexter() new ChannelAbilityPreset(INFO_TEXTER_ID, 1, TRUE) ..setName("Information: Texter") ..presetTooltipNormal(lvl -> "Information: Texter") ..presetTooltipNormalExtended(lvl -> "Use these commands while having the texter selected." + "\nAll Commands:" + "\n-sht (shows the currently set text)" + "\n-ht (hides the currently set text)" + "\n-sc (set the color of the text)" + "\nExamples:" + "\n-st Some Text" + "\n-sc red/green/orange" + "\n-sc 125 125 255" + "\nThe text gets automatically displayed if an Escaper walks over the texter.") ..presetIcon("ReplaceableTextures\\CommandButtons\\PASInfo.blp") ..presetButtonPosNormal(0, 0) ..presetTargetTypes(Targettype.PASSIVE) ..setHeroAbility(FALSE) new BuildingDefinition(TEXTER_ID, 'ncop') ..setName("|cff08DEFFTexter ") ..setHotkey("F") ..setTooltipBasic("|cffFFCC00Build |cff08DEFFTexter [F]") ..setTooltipExtended("Creates floating textes that are shown by command or when an Escaper walks over it." + "\nFloating texts can be colored.") ..setIconGameInterface("ReplaceableTextures\\CommandButtons\\BTNTexter.blp") ..setNormalAbilities(commaList(INFO_TEXTER_ID, REMOVE_OBJECT_ID, MAKE_UNIT_INVISIBLE_ID, GHOST_VIS_ID, INVULNERABILITY_ID)) ..setButtonPositionX(3) ..setButtonPositionY(1) ..setTintingColorRed(0) ..setSightRadiusDay(0) ..setSightRadiusNight(0) ..setBuildTime(1) ..setCollisionSize(0) ..setScalingValue(0.8) ..setSelectionScale(2.2) ..setUnitClassification("ancient,standon") ..setHideMinimapDisplay(true)