Tooltip problem

These are tools and utilities that make it easier to run games. This includes Lib: macro tokens dropped into MapTool to manage the game, a conversion file for CharacterTool to allow use in MapTool, or just about anything else you can think of -- except graphics with macros and anything specific to a particular campaign framework. Those are already covered by the Tilesets subforum and the Links and External Resources forum.

Moderators: dorpond, trevor, Azhrei, giliath, Gamerdude, jay, Mr.Ice

neofax
Great Wyrm
Posts: 1694
Joined: Tue May 26, 2009 8:51 pm
Location: Philadelphia, PA
Contact:

Tooltip problem

Post by neofax »

I am trying to get the tooltip to display HTML code. Is this even possible? If not, is there a way to use the tooltip inside in the macro to display HTML without using a Lib:Token?

Here is my current code snippet:

Code: Select all

[H: Attack2 = AttackRoll2 + " <b>(1d20)</b> <br> + " + LevelBonus + " (Level Bonus) + " + Ability + " (Ability Bonus) + " + WeapProf + " (Weapon Proficiency) + " + ItemEnh + " (Item Enhancement)" + if(AtkFeat != 0, " + " + AtkFeat + " (Expertise Feat)", "") + if(MiscAtk1 != 0, " + " + MiscAtk1 + " (Misc. Attack Mod)", "") + if(CA1 != 0, " + " + CA1 + " (Combat Advantage)", "") + "----------" +  AttackResult2]

User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Re: Tooltip problem

Post by Rumble »

Yes, you can do it - you can use it as the title attribute in <span> tags - just make sure to enclose the tooltip itself in <html> tags. Or did you mean the tooltip for the macro button itself?

You might also consider using strformat() to build the tooltip. I've started using it a lot, and it simplifies building strings quite a bit.

neofax
Great Wyrm
Posts: 1694
Joined: Tue May 26, 2009 8:51 pm
Location: Philadelphia, PA
Contact:

Re: Tooltip problem

Post by neofax »

Here is the error I get:

ava.lang.NullPointerException error executing expression Attack2 =
AttackRoll2 + " (1d20) " + LevelBonus + " (Level Bonus) + " + Ability + " (Ability Bonus) + " + WeapProf + " (Weapon Proficiency) + " + ItemEnh + " (Item Enhancement)" + if(AtkFeat != 0, " + " + AtkFeat + " (Expertise Feat)", "") + if(MiscAtk1 != 0, " + " + MiscAtk1 + " (Misc. Attack Mod)", "") + if(CA1 != 0, " + " + CA1 + " (Combat Advantage)", "") + AttackResult2

and the code:

Code: Select all

<!-- Set a few variables --!>
[H: PowerName = "Day's First Light"]
[H: PowerLevel = "Avenger Feature"]
[H: PowerType = "Encounter"]
[H: Keywords = "Divine, Implement, Radiant"]
[H: ActionType = "Standard Action"]
[H: Color = "Maroon"]
[H: Range = "Melee touch"]
[H: Ability = WisBonus]
[H: TargetDefense = "Ref"]
[H: TargetVar = "One creature"]
[H: DamageRoll1 = "1d8"]
[H: CritDamageRoll1 = "20"]
[H: DamageType = "radiant"]
[H: WeapProf = "3"]
[H: ItemEnh = "0"]
[H: AtkFeat = "0"]
[H: DmgFeat = "0"]
[H: TargetAllies = 0]
[H: TargetFoes = 1]
[H: MinRange = 1]
[H: MaxRange = 1]
[H: HitEffect = ". If the target willingly moves before the start of your next turn, it takes 5 + your Wisdom modifier (+" + Ability + ") radiant damage."]


<!-- Display attack header --!>
<table width=400 cellpadding=1>
   <tr bgcolor="[R: Color]">
      <td>
         <font color="#FFFFFF">
            <b>[R: PowerName]</b>
         </font>
      </td>
      <td align=right>
         <font color="#FFFFFF">
            <b>[R: PowerLevel]</b>
         </font>
      </td>
   </tr>
   <tr>
      <td>
         <font color="#000000">
            <b>[R: PowerType]&#9830;[R: Keywords]</b>
         </font>
      </td>
   </tr>
   <tr>
      <td>
         <font color="#000000">
            <b>[R: ActionType]</b>
         </font>
      </td>
      <td align=right>
         <font color="#000000">
            <b>[R: Range]</b>
         </font>
      </td>
   </tr>
   <tr>
      <td>
         <font color="#000000">
            <b>Target:</b>&nbsp;&nbsp;[R: TargetVar]
         </font>
      </td>
   </tr>
</table>


<!-- Attack --!>
<table width=400 cellpadding=1>
   <tr>
      <td>
         [FOR(looper, 1, Qty + 1, 1, "<br>"), CODE:
         {
            [H: CreateTarget1List()]
            
            
            <!-- Attack Roll1 Tooltips --!>
            [H: AttackRoll1 = 1d20]
            [H: AttackResult1 = AttackRoll1 + LevelBonus + Ability + WeapProf + ItemEnh + AtkFeat + MiscAtk1 + CA1]
            [H: Attack1 = AttackRoll1 + " (1d20) + " + LevelBonus + " (Level Bonus) + " + Ability + " (Ability Bonus) + " + WeapProf + " (Weapon Proficiency) + " + ItemEnh + " (Item Enhancement)" + if(AtkFeat != 0, " + " + AtkFeat + " (Expertise Feat)", "") + if(MiscAtk1 != 0, " + " + MiscAtk1 + " (Misc. Attack Mod)", "") + if(CA1 != 0, " + " + CA1 + " (Combat Advantage)", "")]
            
            <!-- Attack Roll2 Tooltips --!>
            [H: AttackRoll2 = 1d20]
            [H: AttackResult2 = AttackRoll2 + LevelBonus + Ability + WeapProf + ItemEnh + AtkFeat + MiscAtk1 + CA1]
            [H: Attack2 = <html> AttackRoll2 + " (1d20) <br>" + LevelBonus + " (Level Bonus) + " + Ability + " (Ability Bonus) + " + WeapProf + " (Weapon Proficiency) + " + ItemEnh + " (Item Enhancement)" + if(AtkFeat != 0, " + " + AtkFeat + " (Expertise Feat)", "") + if(MiscAtk1 != 0, " + " + MiscAtk1 + " (Misc. Attack Mod)", "") + if(CA1 != 0, " + " + CA1 + " (Combat Advantage)", "") + AttackResult2 </html>]
            
            
            <!-- Display Tooltips --!>
            <b>[R: token.name] </b>attacks <b><font color="navy">[R: Target1]</font>:</b>
            <br>
            <font color="navy">[t(AttackResult1): Attack1]</font> vs [R: TargetDefense]
            [if(AttackRoll1 == 20), code:
            {
               <b><font color="red">Critical hit!</font></b><br>
            };{
               <br>
            }]


            <font color="navy">[t(AttackResult2): Attack2]</font> vs [R: TargetDefense]
            [if(AttackRoll2 == 20), code:
            {
               <b><font color="red">Critical hit!</font></b><br>
            };{
               <br>
            }]
            
            <!-- Damage Roll Tooltips --!>
            [H: DamageResult1 = eval(string(DamageRoll1)) + Ability + ItemEnh + ConBonus + DmgFeat + MiscDmg1]
            [H: DamageRoll = DamageRoll1 + " + " + (Ability + ItemEnh + ConBonus + DmgFeat + MiscDmg1)]
            [H: CritDamageResult1 = eval(string(CritDamageRoll1)) + Ability + ItemEnh + ConBonus + DmgFeat + MiscDmg1]
            [H: CritDamage = CritDamageRoll1 + " + " + (Ability + ItemEnh + ConBonus + DmgFeat + MiscDmg1)]
         }]

<!-- Damage --!>
         <b>Hit: </b>  [if(AttackRoll1 == 20 || AttackRoll2 == 20), code:
         {
            <font color="navy">[t(CritDamageResult1): CritDamage]</font> [R: DamageType] damage
         };{
            <font color="navy">[t(DamageResult1): DamageRoll]</font> [R: DamageType] damage
         }]
      </td>
   </tr>
</table>

User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Re: Tooltip problem

Post by Rumble »

Those html tags should be part of the quoted string, rather than outside the quotes, like:

Code: Select all

[H: Attack2 = "<html>"+ AttackRoll2 + " (1d20) <br>" + LevelBonus + " (Level Bonus) + " + Ability + " (Ability Bonus) + " + WeapProf + " (Weapon Proficiency) + " + ItemEnh + " (Item Enhancement)" + if(AtkFeat != 0, " + " + AtkFeat + " (Expertise Feat)", "") + if(MiscAtk1 != 0, " + " + MiscAtk1 + " (Misc. Attack Mod)", "") + if(CA1 != 0, " + " + CA1 + " (Combat Advantage)", "") + AttackResult2 + "</html>"]

neofax
Great Wyrm
Posts: 1694
Joined: Tue May 26, 2009 8:51 pm
Location: Philadelphia, PA
Contact:

Re: Tooltip problem

Post by neofax »

OK, the macro executed this time, but the tooltip now displays the words Attack2 = <html> 19 (1d20) <br> 1 (LevelBonus)... Instead of:
19 (1d20)
01 (LevelBonus)
05 (AbilityBonus)
--
25 Attack!

Yes, I know it currently does not have the extra bit, but I am trying to get the first bit to work before doing the whole line. Also, this is the tooltip on mouse over inside the chat and not via the built-in version on the macro screen.

User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Re: Tooltip problem

Post by Rumble »

Ah, okay. Hm. It may be possible that the tooltip roll option cannot support HTML formatted tooltips. If that is the case, you may need to use the SPAN tag to put in a tooltip.

User avatar
CoveredInFish
Demigod
Posts: 3104
Joined: Mon Jun 29, 2009 10:37 am
Location: Germany
Contact:

Re: Tooltip problem

Post by CoveredInFish »

Awesome. It didn't know that title tooltips support html. That will come handy :-)

User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Re: Tooltip problem

Post by Rumble »

CoveredInFish wrote:Awesome. It didn't know that title tooltips support html. That will come handy :-)


Oh, yeah - I use it to create a full breakdown of an attack, but in a table form - so much easier to read than in single line:
Attachments
tooltip-screenshot.png
tooltip-screenshot.png (109.71 KiB) Viewed 5872 times

User avatar
biodude
Dragon
Posts: 444
Joined: Sun Jun 15, 2008 2:40 pm
Location: Montréal, QC

Re: Tooltip problem

Post by biodude »

I was doing this so often in different macros, I wrote a custom function to take the data and do all formatting all consistent-like. It takes label/value pairs that are so often added up in RPGs, and shows the total and breakdown of what it received.
I later wrote a wrapper function that is more game-system specific to highlight natural 1s & 20s :P

Anyway, here's my "FormatToolTip" function if anybody is interested. It could be streamlined by using strformat more, but I haven't gotten around to that yet.
[spoiler=FormatToolTip]

Code: Select all

<!-----===== FormatTooltip =====----->
<!--
 This function takes a JSON object of variables (labels) and values 
to be formatted into a table for a tooltip pop
-up in the MapTools non-standard HTML interpreter,
overtop the sum, which is automatically calculated -->
[
H: numArgs = argCount() ]
[
H: tValues = arg(0) ]    <!-- macro.args if not a user-defined function -->
[
H, IF( numArgs>): sumValues = arg(1) ; sumValues = 1 ]    <!-- optional switch to calculate sum or just return formatted table -->
[
H, IF( numArgs>): vsDC = arg(2) ; vsDC = "" ]    <!-- optional value to compare to sum as success threshold (DC) -->
[
H, if( isNumber( vsDC ) ): vsDC = number( vsDC ) ; vsDC = 0 ]
[
H: tNames = json.fields( tValues )]
[
H: toolTipHead = "<html><head>"+
    "<style><!--"+
    "    td    { font-family: Verdana,sans-serif ; }
        td.var {
            font-style: italic;
            text-align: left;
        }
        td.value {
            text-align: right;
        }
        tr.total {
            font-weight: bold;
            color: #333333;
            background: #CCCCFF;
        }
        tr.dc, tr.dcfail {
            font-weight: normal;
            font-size: 100%;
            color: #000000;
            background: #CCFFCC;
        }
        tr.dcfail {
            color: #660000;
            background: #CCCCCC;
        }
    "
+
    "--></style></head><body>" ]
[
H: toolTipFoot = "</body></html>" ]
[
H: toolTipContents = "<table>"]
[
H: valueSum = 0 ]
[
H, FOREACH( var, tNames, "" ): valueSum = valueSum + json.get( tValues, var )]
[
H: marginDC = valueSum - vsDC ]    <!-- margin of the roll vs DC.  >=0 is a pass, <0 is a fail -->
[
H, FOREACH( var, tNames, "" ): toolTipContents = toolTipContents + "<tr><td class='var'><em>"+ var +"</em></td><td class='value' style='text-align: right;'>"+ json.get( tValues,var ) +"</td></tr>" ]
[
H: toolTipContents = toolTipContents + "<tr class='total' ><td class='var'><em>Total</em></td><td class='value' >"+ valueSum +"</td></tr>" ]
[
H, if( vsDC!=): toolTipContents = toolTipContents + "<tr class='"+ if( marginDC<0, "dcfail", "dc" )  +"' >" ]
[
H, if( vsDC!=): toolTipContents = toolTipContents + "<td class='var'><strong>"+ if( marginDC>0, "+", "" )+ marginDC + "</strong></td><td class='value' style='text-align: right;'><em>vs.</em> "+ vsDC +" </td></tr>" ]
[
H: toolTipContents = toolTipContents + "</table>" ]
[
H: toolTipHTML = toolTipHead + toolTipContents + toolTipFoot ]
[
H, if( vsDC!=): textBG = if( marginDC<0, "#FFCCCC", "#CCFFCC" ); textBG = "#EEEEEE" ]
[
H, IF( sumValues ): formattedToolTip = strformat('<span style="background:%s" title="%s" >%s</span>', textBG, toolTipHTML, if( vsDC==0, valueSum, if( marginDC>0, "+", "" )+ marginDC ) ) ; formattedToolTip = toolTipContents ]
[
H: macro.return = formattedToolTip ]
 

onCampaignLoad:

Code: Select all

[R: defineFunction( "toolTip", "[email protected]", 1 )] 
 
[/spoiler]
"The trouble with communicating is believing you have achieved it"
[ d20 StatBlock Importer ] [ Batch Edit Macros ] [ Canned Speech UI ] [ Lib: Math ]


User avatar
Azhrei
Site Admin
Posts: 12058
Joined: Mon Jun 12, 2006 1:20 pm
Location: Tampa, FL

Re: Tooltip problem

Post by Azhrei »

(I've moved this to the Drop-In Resources forum since biodude posted a generally useful tooltip UDF that anyone can use. (Thanks, dude!) I left a shadow topic in the previous forum so others can still find it.)

User avatar
wolph42
Deity
Posts: 9791
Joined: Fri Mar 20, 2009 5:40 am
Location: Netherlands
Contact:

Re: Tooltip problem

Post by wolph42 »

I just discovered this. And it seems there is a bug in the formatttooltip. When you set the sumValues to 0 (as in do not sum it up) the output is not a tooltip but just text to chat.

edit: never mind, its suppose to do that, isn't very clear though. Nice addon though, thnx

Ok, it wasn't very clear to me how it worked, now it does, so I restructured it a bit and added lots of comment so other can have a use for this too (I hope) and made more use of strformat, hopefully to make things even more clear.

[spoiler=formatTooltip restructured and with comment]

Code: Select all

<!-----===== FormatTooltip =====----->
<!--
 This function takes a JSON object of variables (labels) and values 
to be formatted into a table for a tooltip pop
-up in the MapTools non-standard HTML interpreter,
overtop the sum, which is automatically calculated -->
[
H: numArgs = argCount() ]
[
H: tValues = arg(0) ]    <!-- macro.args if not a user-defined function -->
[
H, IF( numArgs>): sumValues = arg(1) ; sumValues = 1 ]    <!-- optional switch to calculate sum or just return formatted table -->
[
H, IF( numArgs>): vsDC = arg(2) ; vsDC = "" ]    <!-- optional value to compare to sum as success threshold (DC) -->
[
H, if( isNumber( vsDC ) ): vsDC = number( vsDC ) ; vsDC = 0 ]
[
H: tNames = json.fields( tValues )]

<!--
calculte sum of value-->
[
H: valueSum = 0 ]
[
H, FOREACH( var, tNames, "" ): valueSum = valueSum + json.get( tValues, var )]
<!--
calculate the the result vs the DC-->
[
H: marginDC = valueSum - vsDC ]    <!-- margin of the roll vs DC.  >=0 is a pass, <0 is a fail -->

<!--
create basic tooltip html-->
<!--
HEADER-->
[
H: ttHead = "<html><head>"+
    "<style><!--"+
    "   td              { font-family: Verdana,sans-serif ; }
        td.var          {font-style: italic;
                        text-align: left;}
        td.value        {text-align: right;}
        tr.total        {font-weight: bold;
                        color: #333333;
                        background: #CCCCFF;}
        tr.dc, tr.dcfail{font-weight: normal;
                        font-size: 100%;
                        color: #000000;
                        background: #CCFFCC;}
        tr.dcfail       {color: #660000;
                        background: #CCCCCC;}
    --></style></head><body>"
]

<!--
CONTENT-->
[
H:                             ttContents = "<table>"]
<!--
add labels with values-->
[
H, FOREACH( var, tNames, "" ):ttContents = ttContents + strformat("<tr><td class='var'>%s</td><td class='value' style='text-align: right;'>%s</td></tr>", var, json.get( tValues,var ))]
<!--
add the sum of values-->
[
H:                             ttContents = ttContents + strformat("<tr class='total'><td class='var'><em>Total</em></td><td class='value' >%s</td></tr>",valueSum)]
<!--
add DC is it is set-->
[
H, if( vsDC!=):             ttContents = ttContents + strformat("<tr class='%s'><td class='var'><strong>%s</strong></td><td class='value' style='text-align: right;'><em>vs.</em>%s</td></tr>", if( marginDC<0, "dcfail", "dc" ), if( marginDC>0, "+", "" )+ marginDC, vsDC)]
<!--
end of the content-->
[
H:                             ttContents = ttContents + "</table>" ]

<!--
FOOTER-->
[
H: ttFoot = "</body></html>" ]

<!--
add HEADER, CONTENT and FOOTER-->
[
H: ttHTML = ttHead + ttContents + ttFoot ]

<!--
set background color for output text (to chat-->
[
H: textBG = if(vsDC!=0, if( marginDC<0, "#FFCCCC", "#CCFFCC" ), "#EEEEEE")]

[
H, IF( sumValues ), CODE:{
    <!--create output with tt-->
    [formattedtt = strformat('<span style="background:%s" title="%s" >%s</span>', textBG, ttHTML, if( vsDC==0, valueSum, if( marginDC>0, "+", "" )+ marginDC ) ) ]
};{
    <!--create output without tt, just show list of values-->
    [formattedtt = ttContents ]
}]

<!--
return value to calling macro-->
[
H: macro.return = formattedtt ]
  
[/spoiler]
The layout is created such that its best viewed in a text editor a la notepad2

qschilling
Kobold
Posts: 9
Joined: Tue Oct 26, 2010 8:28 am

Re: Tooltip problem

Post by qschilling »

I may be using this incorrectly but when I attempt to use this function I get the error in the chat screen of "Unknown JSON type "" in function "json.fields""

Please help as I would find this option very useful.


User avatar
Rumble
Deity
Posts: 6235
Joined: Tue Jul 01, 2008 7:48 pm

Re: Tooltip problem

Post by Rumble »

There's only one call to json.fields in there, so it looks like the macro isn't receiving any arguments when called (that is, it's getting a blank string, "", which is not a valid data type for the json.fields() function.

How are you calling this function and what are you sending to it as an argument?

Post Reply

Return to “Drop-In Macro Resources”