1. Melee Mapping contest #3 - Poll is up! Vote for the best 4v4 melee maps!
    Dismiss Notice
  2. The 30th edition of the Modeling Contest is finally up! The Portable Buildings need your attention, so come along and have a blast!
    Dismiss Notice
  3. We have a new contest going on right now! Join the 11th Music Contest! You are to make a Cinematic modern sound-track for this contest, so come and compete with other people for fun.
    Dismiss Notice

[Wurst] Ability Tooltip Generator

Discussion in 'Wurst Resources' started by Frotty, Jun 13, 2014.

  1. Frotty

    Frotty

    Wurst Reviewer

    Joined:
    Jan 1, 2009
    Messages:
    1,321
    Resources:
    9
    Models:
    3
    Tools:
    1
    Maps:
    3
    Tutorials:
    1
    Wurst:
    1
    Resources:
    9
    Allows you to create tooltips like these:
    [​IMG]

    Repo dep: Frotty/Ability-Tooltip-Generator

    The value for the current level is highlighted, supports custom patterns.

    Use the stdlib api of
    ChannelAbilityPreset
    with
    tooltipStartListen()
    and
    tooltipStopListen()
    .

    Example:

    Code (WurstScript):
    package Snowball
    import AbilityTooltipGenerator

    public constant SNOWBALL_SPELL_ID = compiletime(ABIL_ID_GEN.next())

    constant SPEED = 19.5
    constant RealLevelClosure RANGE = lvl -> 900. + lvl * 100

    @compiletime function getObjs()
        let tgen = new AbilityTooltipGenerator("An ordinary snowball.")
        new ChannelAbilityPreset(SNOWBALL_SPELL_ID, 4, true, tgen)
        ..setHeroAbility(false)
        ..presetButtonPosNormal(0, 2)
        ..presetTargetTypes(Targettype.POINT)
        ..tooltipStartListen()
        ..presetHotkey("Q")
        ..setName("Snowball")
        ..presetIcon("BTNFrostBolt")
        ..presetCooldown(lvl -> 1.75 - (lvl / 4))
        ..presetManaCost(lvl -> 4 - (lvl / 3).toInt())
        ..presetCastRange(RANGE)
        ..setLevelSkipRequirement(0)
        ..tooltipStopListen()


    RANGE
    is external here so it can be used in the actual spell mechanic as well.

    Code:
    Code (WurstScript):
    package AbilityTooltipGenerator
    import public ChannelAbilityPreset
    import HashMap

    @configurable constant TITLE_COLOR = "|cff3B97D3"
    @configurable constant TITLE_TTYPE = "Targettype:"
    @configurable constant MAX_TITLES = 10
    @configurable constant LEARN_PATTERN = "[|cffFFCC00$hotkey$|r] |cffFFCC00Learn|r $name$ - [|cffffcc00Level %d|r]"
    @configurable constant NORMAL_ACTIVE_PATTERN = "$name$ - Level $lvl$ [|cffFFCC00$hotkey$|r]"
    @configurable constant NORMAL_PASSIVE_PATTERN = "$name$ - Level $lvl$"

    public class AbilityTooltipGenerator implements TooltipGenerator
        private constant propMap = new IterableMap<string, StringLevelClosure>
        private var description = ""

        private var levels = 1
        private var hotkey = ""
        private var name = ""
        private var targettype = Targettype.NONE

        construct(string description)
            this.description = description

        construct()

        override function addProperty(string title, StringLevelClosure lc)
            propMap.put(title, lc)

        override function applyToDef(AbilityDefinition def)
            levels = propMap.has("Levels") ? fixValue(propMap.getAndRemove("Levels").run(0)).toInt() : 1
            name = propMap.has("Name") ? propMap.getAndRemove("Name").run(0) : "unnamed"
            hotkey = propMap.has("Hotkey") ? propMap.getAndRemove("Hotkey").run(0) : "Q"
            targettype = propMap.has("Targettype") ? propMap.get("Targettype").run(0).toInt() castTo Targettype : Targettype.NONE
            def..setTooltipLearn(generateTooltipLearn())
            ..setTooltipLearnExtended(generateTooltipExtended(-1, true))
            for i = 1 to levels
                def..setTooltipNormal(i, generateTooltipNormal(i))
                ..setTooltipNormalExtended(i, generateTooltipExtended(i, false))

        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("$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())
            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 key in propMap
                var tmp = ""
                for i = 1 to levels
                    tmp += fixValue(propMap.get(key).run(i)) + "/"
                s += TITLE_COLOR + key + ":|r " + colorLevelValue(tmp.substring(0, tmp.length() - 1), lvl, levels) + "\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
            var _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
            else if maxLevel <= 1
                _newString = "|cffFFCC00" + oldString
            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
     
    Last edited: Jan 6, 2019
  2. pred1980

    pred1980

    Joined:
    Mar 19, 2010
    Messages:
    844
    Resources:
    1
    Maps:
    1
    Resources:
    1
    is it possible to change the tooltips while playing the map?
     
  3. Frotty

    Frotty

    Wurst Reviewer

    Joined:
    Jan 1, 2009
    Messages:
    1,321
    Resources:
    9
    Models:
    3
    Tools:
    1
    Maps:
    3
    Tutorials:
    1
    Wurst:
    1
    Resources:
    9
    Sure, but not with this script.
     
  4. edo494

    edo494

    Joined:
    Apr 16, 2012
    Messages:
    3,856
    Resources:
    5
    Spells:
    1
    JASS:
    4
    Resources:
    5
    how is it possible to change tooltip of ability while playing game? and this writes the data for the ability into the map archive am I right? Because if not, then you have some sorcery going on in here :D
     
  5. Frotty

    Frotty

    Wurst Reviewer

    Joined:
    Jan 1, 2009
    Messages:
    1,321
    Resources:
    9
    Models:
    3
    Tools:
    1
    Maps:
    3
    Tutorials:
    1
    Wurst:
    1
    Resources:
    9
    well you can change it by replacing the ability with another one.
    This just sets value to an existing definition, and since the definition has to be already created it gets created by wurst.

    If you have injection on it also gets injected into the map, yes.
     
  6. TriggerHappy

    TriggerHappy

    Code Moderator

    Joined:
    Jun 23, 2007
    Messages:
    3,514
    Resources:
    22
    Spells:
    11
    Tutorials:
    2
    JASS:
    9
    Resources:
    22
    Approved, but maybe you should add a simple example.
     
  7. Frotty

    Frotty

    Wurst Reviewer

    Joined:
    Jan 1, 2009
    Messages:
    1,321
    Resources:
    9
    Models:
    3
    Tools:
    1
    Maps:
    3
    Tutorials:
    1
    Wurst:
    1
    Resources:
    9
    There is an Example in the config package..?
     
  8. Zwiebelchen

    Zwiebelchen

    Joined:
    Sep 17, 2009
    Messages:
    6,775
    Resources:
    11
    Models:
    4
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    JASS:
    4
    Resources:
    11
    Can you do a tooltip generator for items?
     
  9. Frotty

    Frotty

    Wurst Reviewer

    Joined:
    Jan 1, 2009
    Messages:
    1,321
    Resources:
    9
    Models:
    3
    Tools:
    1
    Maps:
    3
    Tutorials:
    1
    Wurst:
    1
    Resources:
    9
    Sure, but based on what template?
     
  10. GywGod133

    GywGod133

    Joined:
    Jul 16, 2012
    Messages:
    647
    Resources:
    3
    Maps:
    1
    Spells:
    1
    Tutorials:
    1
    Resources:
    3
    oh... tooltip description changer... maybe its useful in LoL-Like map,
     
  11. Xonok

    Xonok

    Joined:
    Mar 27, 2012
    Messages:
    3,041
    Resources:
    8
    Spells:
    3
    Tutorials:
    5
    Resources:
    8
    It doesn't work at runtime. Wurst isn't magic :D
     
  12. Donach

    Donach

    Joined:
    Jan 12, 2011
    Messages:
    95
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Just tested this out, just a few quirks I had to overcome... Besides that, works like a charm!
    Thanks!
     
  13. Frotty

    Frotty

    Wurst Reviewer

    Joined:
    Jan 1, 2009
    Messages:
    1,321
    Resources:
    9
    Models:
    3
    Tools:
    1
    Maps:
    3
    Tutorials:
    1
    Wurst:
    1
    Resources:
    9
    Funny someone is still using this!
    Originally I didn't want to continue, since HappyTauren was working on a better version, but it doesn't look like he will finish that.
    So I might bring something like this back as git repo dependency and up to date.
    Thanks in any case, glad you like it ;)
     
  14. Donach

    Donach

    Joined:
    Jan 12, 2011
    Messages:
    95
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Glad to hear that!

    I will actually have to alter the system a bit, cause I am implementing so called "Ranks" for abilities- meaning, I have one ability definition, and after certain level, another Rank takes place (1-3, 4-6 ex...), and each rank needs to have different values (and possibly effects).
    The problem arises when the ability has over 8 or so levels (I have 12 so far and gonna be more maybe...). The text is just getting wrapped and it does not look so neat and pretty.

    But besides that, its really awesome!
     
  15. Frotty

    Frotty

    Wurst Reviewer

    Joined:
    Jan 1, 2009
    Messages:
    1,321
    Resources:
    9
    Models:
    3
    Tools:
    1
    Maps:
    3
    Tutorials:
    1
    Wurst:
    1
    Resources:
    9
    Alright, I finally updated the generator since I needed it myself @Donach :p
    The learn level is now displayed in the tooltip and using the listener api you have fine grained control over how each tooltip is generated.
    I'm enjoying it so far. Also added example and git repo to first post.