package AbilityTooltipGenerator import public ChannelAbilityPreset @configurable constant TITLE_COLOR = "|cff3B97D3" @configurable constant TITLE_TTYPE = "Targettype:" @configurable constant MAX_TITLES = 10 @configurable constant LEARN_PATTERN = "|cffFFCC00Learn|r $name$ [|cffFFCC00$hotkey$|r]" @configurable constant NORMAL_ACTIVE_PATTERN = "$name$ - $lvl$ [|cffFFCC00$hotkey$|r]" @configurable constant NORMAL_PASSIVE_PATTERN = "$name$ - $lvl$" public class AbilityTooltipGenerator private string name = "" private string hotkey = "" private string hotkeylearn = "" private string description = "" private int maxLevel = 1 private string array[MAX_TITLES] titles private string array[MAX_TITLES] values private int titleCount = 0 Targettype targettype = Targettype.NOTARGET construct(string name, string hotkey, Targettype ttype, int maxLevel, string description) this.name = name this.hotkey = hotkey this.maxLevel = maxLevel this.description = description this.targettype = ttype construct(string name, string hotkey, Targettype ttype, string description) this.name = name this.hotkey = hotkey this.description = description this.targettype = ttype construct(string name, Targettype ttype, string description) this.name = name this.description = description this.targettype = ttype construct() function setExtraLearnHotkey(string hotkey) hotkeylearn = hotkey function addProperty(string title, string value) if titleCount >= MAX_TITLES error("Maximum titles reached") titles[titleCount] = TITLE_COLOR + title + "|r " values[titleCount] = fixValue(value) titleCount++ function addProperty(string title, StringLevelClosure lc) if titleCount >= MAX_TITLES error("Maximum titles reached") titles[titleCount] = TITLE_COLOR + title + "|r " values[titleCount] = "" for i = 1 to maxLevel values[titleCount] += fixValue(lc.run(i)) + "/" values[titleCount] = values[titleCount].substring(0, values[titleCount].length() -1) titleCount++ function applyToDef(AbilityDefinition def) for i = 1 to maxLevel def..setTooltipNormal(i, generateTooltipNormal(i)) ..setTooltipNormalExtended(i, generateTooltipExtended(i, false)) def..setTooltipLearn(generateTooltipLearn()) ..setTooltipLearnExtended(generateTooltipExtended(-1, true)) ..presetHotkey(hotkey)..setLevels(maxLevel)..setName(name) private function generateTooltipLearn() returns string return replaceRefs(LEARN_PATTERN) private function generateTooltipNormal(int lvl) returns string if targettype == Targettype.PASSIVE return replaceRefs(NORMAL_PASSIVE_PATTERN, lvl) else return replaceRefs(NORMAL_ACTIVE_PATTERN, lvl) private function replaceRefs(string old, int lvl) returns string var newString = old newString = newString.replace("$name$", name) newString = newString.replace("$hotkey$", hotkey.toUpperCase()) newString = newString.replace("$hotkeylearn$", hotkeylearn.toUpperCase()) newString = newString.replace("$lvl$", lvl.toString()) return newString private function replaceRefs(string old) returns string var newString = old newString = newString.replace("$name$", name) newString = newString.replace("$hotkey$", hotkey.toUpperCase()) newString = newString.replace("$hotkeylearn$", hotkeylearn.toUpperCase()) return newString private function generateTooltipExtended(int lvl, boolean learn) returns string var s = "" if targettype == Targettype.PASSIVE s += TITLE_COLOR + "Passive|r\n" else if learn s += TITLE_COLOR + TITLE_TTYPE + "|r " + targettype.toString() + "\n" else s += TITLE_COLOR + TITLE_TTYPE + " |cffFFCC00" + targettype.toString() + "|r\n" for i = 0 to titleCount-1 s += titles[i] + colorLevelValue(values[i], lvl, maxLevel) + "\n" s+= "\n" s+= description return s private static function fixValue(string value) returns string var s = value if s.endsWith(".") s = s.substring(0, s.length()-1) else if s.length() > 1 and s.endsWith(".0") s = s.substring(0, s.length()-2) return s private static function colorLevelValue(string oldString, int lvl, int maxLevel) returns string string newString var charCount = 0 var charPosCount = 0 int array charPos for char in oldString if char == "/" charPos[charPosCount] = charCount charPosCount++ charCount++ if lvl == -1 newString = oldString else if charPosCount <= 0 newString = "|cffFFCC00" + oldString + "|r" else if maxLevel <= 1 newString = "|cffFFCC00" + oldString + "|r" else if lvl == 1 newString = "|cffFFCC00" + oldString.substring(0, charPos[0]) + "|r" + oldString.substring(charPos[0], oldString.length()) else if lvl == maxLevel newString = oldString.substring(0, charPos[lvl-2]) + "|cffFFCC00" + oldString.substring(charPos[lvl-2], oldString.length()) + "|r" else newString = oldString.substring(0, charPos[lvl-2]) + "|cffFFCC00" + oldString.substring(charPos[lvl-2], charPos[lvl-1]) + "|r" + oldString.substring(charPos[lvl-1], oldString.length()) return newString