Introduction to Dialogs and Frames

From MapToolDoc
Jump to: navigation, search
ADVANCED
THIS IS AN ADVANCED ARTICLE

An Introduction to MapTool Macro Dialogs and Frames

Please note I will be using CSS and HTML in this tutorial but I will not really be explaining them, if you need a refresher on either a search on google will point you to many resources that do a better job than I could.


The [dialog():] and [frame():] roll types create a new dialog or frame where all the output from the commands within the {} will be displayed. dialog create a dialog box that hovers over other windows. frame creates a frame that can be docked like the other maptool windows. The dialog and frame windows can be used to display HTML and rolls the same as the chat output window.

This tutorial starts with the standard blank campaign you get when you start MapTool, anything else we need we will add along the way.

First Steps

So lets jump in and create your first dialog, you can use the code below to create a dialog.

  1. [dialog("Test"): {
  2.   Your first dialog!
  3. }]
Example Dialog

I know its pretty boring but before we start adding more to it lets create a frame so that you can see the difference

  1. [frame("Test"): {
  2.   Your first frame!
  3. }]
Example Frame


And a picture of your first frame docked.


Example Docked Frame

Back to the dialog you can spice it up a little with some dice rolls and HTML formatting.


  1. [dialog("Test"): {
  2.   <b>1d4</b> -> [1d4]<br>
  3.   <b>1d6</b> -> [1d6]<br>
  4.   <b>1d8</b> -> [1d8]<br>
  5.   <b>1d10</b> -> [1d10]<br>
  6.   <b>1d12</b> -> [1d12]<br>
  7.   <b>1d20</b> -> [1d20]<br>
  8.   <b>1d100</b> -> [1d100]<br>
  9. }]


Adding Some HTML

This will create a dialog box with some HTML formatting and dice rolls. The dice rolls will have all the tooltips that you would normally get in the chat output.

Still the title is boring (it defaults to the name of the dialog). You can use the HTML <title> tag to change the title. Run the code below, there is no need to close the dialog from the code above.


  1. [dialog("Test"): {
  2.   <html>
  3.     <head>
  4.       <title>Dice Roll Dialog</title>
  5.     </head>
  6.     <body>
  7.       <b>1d4</b> -> [1d4]<br>
  8.       <b>1d6</b> -> [1d6]<br>
  9.       <b>1d8</b> -> [1d8]<br>
  10.       <b>1d10</b> -> [1d10]<br>
  11.       <b>1d12</b> -> [1d12]<br>
  12.       <b>1d20</b> -> [1d20]<br>
  13.       <b>1d100</b> -> [1d100]<br>
  14.     </body>
  15.   </html>
  16. }]
Example Dice Roll Dialog

Notice that the dialog command did not open a new dialog window, instead it replaced the contents of the dialog you had open. When you use [dialog()] with the name of a dialog that already exists the contents of that dialog are replaced, ([frame()] works the same way). You can use this behavior to update your dialogs. Create a token called Lib:Test with a macro (created on that lib:Test token) called Test

Copy the following code into the Test macro.

  1. [dialog("Test"): {
  2.   <html>
  3.     <head>
  4.       <title>Dice Roll Dialog</title>
  5.     </head>
  6.     <body>
  7.       <b>1d4</b> -> [1d4]<br>
  8.       <b>1d6</b> -> [1d6]<br>
  9.       <b>1d8</b> -> [1d8]<br>
  10.       <b>1d10</b> -> [1d10]<br>
  11.       <b>1d12</b> -> [1d12]<br>
  12.       <b>1d20</b> -> [1d20]<br>
  13.       <b>1d100</b> -> [1d100]<br>
  14.       <br>
  15.       [macroLink("Refresh", "Test@Lib:Test")]
  16.     </body>
  17.   </html>
  18. }]
Example Dice Roll Dialog with Refresh macroLink


The above macro uses the macroLink() function to create a link that will call Test on Lib:Test when ever it is clicked (which will update the dialog with new rolls).

The above would be really useful if you needed a window that provided you with a bunch of dice rolls all the time. But I assume that is not what most people will want to do with the dialogs.

Drag another token out on to the map, and fill in the token properties. We can create a simple character sheet with a dialog. On the Lib:Test token create a macro called CharSheet and paste the following code into it.

  1. [h: propNames = "Strength, Dexterity, Constitution, Intelligence, Wisdom, Charisma"]
  2. [dialog("CharSheetTest"): {
  3.   <html>
  4.     <head>
  5.       <title>Character Sheet</title>
  6.     </head>
  7.     <body>
  8.       <table>
  9.         [foreach(prop, propNames, ""), code: {
  10.           <tr>
  11.             <td>[r: prop]</td>
  12.             <td>[r: getProperty(prop)]</td>
  13.           </tr>
  14.         }]
  15.       </table>
  16.     </body>
  17.   </html>
  18. }]

On the new Token that you placed on the map create a macro button called CharSheet and paste the following into it.

  1. [macro("CharSheet@Lib:Test"): ""]
  2. [abort(0)]

Click on the new macro button.

Now for a dash of CSS

Again we are not going to set the world on fire with this character sheet dialog. Lets spice it up a little, I will show you how to use some CSS for formatting.

To use CSS you insert a link like the following into the HTML to be displayed.

  1. [dialog("Test"): {
  2.     <link rel='stylesheet' type='text/css' href='myCSS@Lib:Test'></link>
  3. }]


Although you can (and probably should) use the getMacroLocation() function to make sure it comes from the same Lib:Token as the macro. So,

  1. [dialog("Test"): {
  2.     <link rel='stylesheet' type='text/css' href='myCSS@[r: getMacroLocation()]'></link>
  3. }]

Edit the CharSheet macro on the Lib:Test Token and paste in the following.

  1. [h: propNames = "Strength, Dexterity, Constitution, Intelligence, Wisdom, Charisma"]
  2. [dialog("CharSheetTest"): {
  3.   <html>
  4.     <head>
  5.       <link rel="stylesheet" type="text/css" href="CharSheet_css@[r: getMacroLocation()]">
  6.       <title>Character Sheet</title>
  7.     </head>
  8.     <body>
  9.       <table id="stats">
  10.         <tr>
  11.           <th>Name</th>
  12.           <th>Score</th>
  13.         </tr>
  14.         [h: class = "oddRow"]
  15.         [foreach(prop, propNames, ""), code: {
  16.           <tr class="[r:class]">
  17.             <td>[r: prop]</td>
  18.             <td>[r: getProperty(prop)]</td>
  19.           </tr>
  20.           [h: class = if(class=="oddRow", "evenRow", "oddRow")]
  21.         }]
  22.       </table>
  23.     </body>
  24.   </html>
  25. }]

Also create a new macro button on Lib:Test called CharSheet_css and paste the following CSS code into it.

  1. .oddRow { background-color: #FFFFFF }
  2. .evenRow { background-color: #EEEEAA }
  3. #stats th { background-color: #113311; color: #FFFFFF }

Click on the CharSheet macro button on your Token.

Simple Character Sheet with a Style Sheet

Looks much better already!

Getting better... Lets make some more changes. Change the CharSheet macro on Lib:Test to

  1. [h: propNames = "Strength, Dexterity, Constitution, Intelligence, Wisdom, Charisma"]
  2. [dialog("CharSheetTest"): {
  3.   <html>
  4.     <head>
  5.       <link rel="stylesheet" type="text/css" href="CharSheet_css@[r: getMacroLocation()]">
  6.       <title>Character Sheet</title>
  7.     </head>
  8.     <body>
  9.       <table>
  10.         <tr>
  11.           <td>
  12.             <img src='[r: getTokenImage(100)]'></img>
  13.           </td>
  14.           <td>
  15.             <table id="stats">
  16.               <tr>
  17.                 <th>Name</th>
  18.                 <th>Score</th>
  19.               </tr>
  20.               [h: class = "oddRow"]
  21.               [foreach(prop, propNames, ""), code: {
  22.                 <tr class="[r:class]">
  23.                   <td>[r: prop]</td>
  24.                   <td>[r: getProperty(prop)]</td>
  25.                 </tr>
  26.                 [h: class = if(class=="oddRow", "evenRow", "oddRow")]
  27.               }]
  28.             </table>
  29.           </td>
  30.         </tr>
  31.       </table>
  32.       <hr>
  33.       <table>
  34.         <tr>
  35.           <th>Hit Points:</th>
  36.           <td>[r: HP]</td>
  37.           <th>Armor Class:</th>
  38.           <td>[r: AC]</td>
  39.         </tr>
  40.       </table>
  41.     </body>
  42.   </html>
  43. }]
Simple Character Sheet with Token Image

Looks much better already!

And a Touch more formatting

Ok in Edit->Campaign Properties, Token Properties Tab, Basic Token type, add the following properties

  • *@MaxHP
  • *@XP
  • *@NextLevelXP


Then edit your Token and set some values in your new properties.

Time to create a new macro button on the Lib:Test called TrafficLightBar and paste the following code into it.

  1. <!-- ======================================================================
  2.      ====
  3.      ==== Outputs a red/yellow/green bar
  4.      ====
  5.      ==== Parameters (accepts a string property list with following keys)
  6.      ====
  7.      ====   MaxLen - Maximum length of status bar.
  8.      ====   MaxValue - The "Full" value for the bar.
  9.      ====   Value - The current value for the bar.
  10.      ====   Label - The label for the bar.
  11.      ====
  12.      ====================================================================== -->
  13. <!-- Set up the colors for our "Traffic Lights" -->
  14. [h: r0=200] [h: g0=200] [h: b0=200]
  15. [h: r1=200] [h: g1=0]   [h: b1=0]
  16. [h: r2=255] [h: g2=140] [h: b2=0]
  17. [h: r3=0]   [h: g3=200] [h: b3=0]
  18. [h: MaxLen=getStrProp(macro.args, "MaxLen")]
  19. [h: MaxValue=getStrProp(macro.args, "MaxValue")]
  20. [h: Value=getStrProp(macro.args, "Value")]
  21. [h: Label=getStrProp(macro.args, "Label")]
  22. [h: Len=max(min(round(Value*MaxLen/MaxValue+0.4999),MaxLen),0)]
  23. [h: Len=if(Value>=MaxValue,MaxLen, Len)]
  24. [h: c=min(round(Value*3/MaxValue+0.4999),3)]
  25. [h: col=min(max(Len,0),1)*c]
  26. [h: r=eval("r"+col)] [h: g=eval("g"+col)] [h: b=eval("b"+col)]
  27. <table>
  28.   <tr>
  29.     <td><span title="{Value}/{MaxValue}">{Label}</span></td>
  30.     <td style="background-color: rgb({r},{g},{b})">
  31.       <span title="{Value}/{MaxValue}">[c(Len, ""),r: "&nbsp;"]</span>
  32.     </td>
  33.     [if(MaxLen-Len>0), code: {
  34.       <td style="background-color: rgb({r0},{g0},{b0})">
  35.         <span title="{Value}/{MaxValue}">[c(MaxLen-Len,""),r: "&nbsp;"]</span>
  36.       </td>
  37.     }]
  38.   </tr>
  39. </table>

Create another macro button on Lib:Test called StatusBar and copy the following code into it.

  1. <!-- ======================================================================
  2.      ====
  3.      ==== Outputs a "progress" bar
  4.      ====
  5.      ==== Parameters (accepts a string property list with following keys)
  6.      ====
  7.      ====   MaxLen - Maximum length of status bar.
  8.      ====   MaxValue - The "Full" value for the bar.
  9.      ====   Value - The current value for the bar.
  10.      ====   Label - The label for the bar.
  11.      ====   Color - R,G,B color
  12.      ====
  13.      ====================================================================== -->
  14. [h: r0=200] [h: g0=200] [h: b0=200]
  15. [h: MaxLen=getStrProp(macro.args, "MaxLen")]
  16. [h: MaxValue=getStrProp(macro.args, "MaxValue")]
  17. [h: Value=getStrProp(macro.args, "Value")]
  18. [h: Color=getStrProp(macro.args, "Color")]
  19. [h: Label=getStrProp(macro.args, "Label")]
  20. [h: r1=listGet(Color,0)]
  21. [h: g1=listGet(Color,1)]
  22. [h: b1=listGet(Color,2)]
  23. [h: Len=max(min(round(Value*MaxLen/MaxValue+0.4999),MaxLen),0)]
  24. [h: c=min(round(Value/MaxValue+0.4999),1)]
  25. [h: col=min(max(Len,0),1)*c]
  26. [h: r=eval("r"+col)] [h: g=eval("g"+col)] [h: b=eval("b"+col)]
  27. [h: r=eval("r"+col)] [h: g=eval("g"+col)] [h: b=eval("b"+col)]
  28. <table>
  29.   <tr>
  30.     <td><span title="{Value}/{MaxValue}">{Label}</span></td>
  31.     <td style="background-color: rgb({r},{g},{b})">
  32.       <span title="{Value}/{MaxValue}">[c(Len, ""),r: "&nbsp;"]</span>
  33.     </td>
  34.     [if(MaxLen-Len>0), code: {
  35.       <td style="background-color: rgb({r0},{g0},{b0})">
  36.         <span title="{Value}/{MaxValue}">[c(MaxLen-Len,""),r: "&nbsp;"]</span>
  37.       </td>
  38.     }]
  39.   </tr>
  40. </table>

I am really going to gloss over the previous two functions a bit as they are not important to understanding how to use dialogs or frames, but so you know what they do TrafficLightBar creates a red/yellow/green bar where the color is based on how full the bar is. StatusBar just creates a bar that is one color.

Just a quick point for those who may not know this already, but when you call a macro with [macro("name"): arguments] the arguments are available in the macro in the variable macro.args. To return a value from the macro you read the variable macro.return, the calling macro can then read macro.return to get this value.

Then we change the CharSheet macro on Lib:Test to

  1. [h: propNames = "Strength, Dexterity, Constitution, Intelligence, Wisdom, Charisma"]
  2. [dialog("CharSheetTest"): {
  3.   <html>
  4.     <head>
  5.       <link rel="stylesheet" type="text/css" href="CharSheet_css@[r: getMacroLocation()]">
  6.       <title>Character Sheet</title>
  7.     </head>
  8.     <body>
  9.       <table>
  10.         <tr>
  11.           <td>
  12.             <img src='[r: getTokenImage(100)]'></img>
  13.           </td>
  14.           <td>
  15.             <table id="stats">
  16.               <tr>
  17.                 <th>Name</th>
  18.                 <th>Score</th>
  19.               </tr>
  20.               [h: class = "oddRow"]
  21.               [foreach(prop, propNames, ""), code: {
  22.                 <tr class="[r:class]">
  23.                   <td>[r: prop]</td>
  24.                   <td>[r: getProperty(prop)]</td>
  25.                 </tr>
  26.                 [h: class = if(class=="oddRow", "evenRow", "oddRow")]
  27.               }]
  28.             </table>
  29.           </td>
  30.         </tr>
  31.       </table>
  32.       <hr>
  33.       <table>
  34.         <tr>
  35.           <td>
  36.             [h: hpBarArgs = strformat("MaxLen=50; Value=%{HP}; MaxValue=%{MaxHP}; Label=HP")]
  37.             [macro("TrafficLightBar@this"): hpBarArgs]
  38.           </td>
  39.         </tr>
  40.         <tr>
  41.           <td>
  42.             [h: hpBarArgs = strformat("MaxLen=50; Value=%{XP}; MaxValue=%{NextLevelXP}; Label=XP; Color=120,120,255")]
  43.             [macro("StatusBar@this"): hpBarArgs]
  44.           </td>
  45.         </tr>
  46.       </table>
  47.     </body>
  48.   </html>
  49. }]


Click on the CharSheet macro button on your Token again and you will have a new character sheet.

Simple Character Sheet with Progress Bars


The above example uses strformat() which allows you to insert variables in a string using the %{var} syntax. It also has other flags that can be used to format variable output

Creating Support Functions

Lets leave the character sheet at this for the moment and move on to a new example.

Edit->Campaign Properties, Token Properties Tab, Basic Token type, add the following properties

  • Weapons
  • Items


We are going to store our weapons in a string property list with the following keys.

  • NumWeapons - The number of weapons in our property list.
  • UsingWeapon - The weapon we are currently using.
  • WeaponXName - The name of weapon number X
  • WeaponXDamage - The damage of weapon number X
  • WeaponXBonus - The bonus of weapon number X

We could add a lot more, but lest keep it semi simple for this post.

The first thing we need is a way to enter weapons, we could use the input() function but since this is a tutorial on frames and dialogs, I should probably show you how to do it in a dialog.

But first we need to do some set up, when the player creates a new weapon we will need to get NumWeapons add 1 to it, save it back to the property and use that number (lets not worry about what happens if a player cancels the entry of the weapon as we are not really that worried if we have gaps in our numbering scheme). One problem is though what do we do first time around since the string property list would be empty so trying to use the token property Weapons in strProp*() functions would result in the user being prompted for a value. We could add a default value in the campaign for the token, but there are also other methods. One thing we can do is use the isPropertyEmpty() function to check if the property is empty and if so use a initial value for it, or the getProperty() function that will just return an empty string ("") not prompt if there is no property.

So lets create a macro that returns the number of a new weapon. Create a macro button called NextWeaponNumber and then paste the following code into it.

  1. <!--
  2.   Returns the number for the next weapon as well as updating the
  3.   the counter.
  4.   -->
  5.  
  6. <!-- If Weapons token property is empty set it to a default value -->
  7. [h,if(isPropertyEmpty("Weapons")): Weapons = "NumWeapons=0;"]
  8.  
  9. [h: numWeapons = getStrProp(Weapons, "NumWeapons") + 1]
  10.  
  11. <!-- Now update our property -->
  12. [h: Weapons = setStrProp(Weapons, "NumWeapons", numWeapons)]
  13.  
  14. <!-- Finally set out return value -->
  15. [h: macro.return = numWeapons]


You can test it by running the following code from chat a few times

  1. [macro("NextWeaponNumber@Lib:Test"): ""] [macro.return]


When you are done you can reset the weapon count simply by editing the token properties and clearing out the text for weapons.

Lets also make a macro button called AddWeapon which takes a string property list with the following keys

  • Name
  • Damage
  • Bonus
  • Number

And adds or updates the weapon in the string property list.

  1. <!--
  2.   Adds a weapon to the Weapons property list
  3.  
  4.   Parameters (in a string property list)
  5.  
  6.   Name = Name of Weapon
  7.   Damage = Damage Weapon does
  8.   Bonus = Bonus of Weapon
  9.   Number = The index number of the Weapon
  10. -->
  11. [h: num = getStrProp(macro.args, "Number")]
  12. [h: damage = getStrProp(macro.args, "Damage")]
  13. [h: name = getStrProp(macro.args, "Name")]
  14. [h: bonus = getStrProp(macro.args, "Bonus")]
  15. [h: Weapons = setStrProp(Weapons, strformat("Weapon%{num}Name"), name)]
  16. [h: Weapons = setStrProp(Weapons, strformat("Weapon%{num}Damage"), damage)]
  17. [h: Weapons = setStrProp(Weapons, strformat("Weapon%{num}Bonus"), bonus)]

You can test this macro too by a little typing at the command line.

  1. [macro("AddWeapon@Lib:Test"): "Number=1; Damage=1d8; Name=LongSword; Bonus=0"]

Look at the Weapons [Token_Property|property]] and see how its built up our string property list for us. It wont have modified NumWeapons but that is ok we are going to assume that NextWeaponNumber is always used before adding a new weapon. Before clearing out the Weapons property to reset it lets write a function to retrieve a weapon.

Create a macro button called GetWeapon on your Lib:Test Token and paste the following into it.

  1. <!--
  2.   Retrieves a weapon from the Weapons Property list.
  3.  
  4.   Parameters
  5.     Weapon Number
  6.  
  7.   Returns
  8.     A string property list with following keys
  9.       Name = Name of Weapon
  10.       Damage = Damage Weapon does
  11.       Bonus = Bonus of Weapon
  12.       Number = The index number of the Weapon
  13.     If the weapon is not found then an empty string ("") is returned.
  14. -->
  15. [h: num = macro.args]
  16. [h: damage = getStrProp(Weapons, strformat("Weapon%{num}Damage"))]
  17. [h: name = getStrProp(Weapons, strformat("Weapon%{num}Name"))]
  18. [h: bonus = getStrProp(Weapons, strformat("Weapon%{num}Bonus"))]
  19. [h, if(name == ""):
  20.    macro.return = ""
  21. ;
  22.    macro.return = strformat("Number=%{num}; Damage=%{damage}; Bonus=%{bonus}; Name=%{name}")
  23. ]


Test it with

  1. [h, macro("GetWeapon@Lib:Test"): 1] [macro.return]

Lets add a way to delete items. Create a macro button called DeleteWeapon and paste the following code.

  1. <!-- ============================================================ -->
  2. <!-- ============================================================ -->
  3. <!-- ============================================================ -->
  4. <!--
  5.   Deletes a weapon from the Weapons property List.
  6.  
  7.   Parameters
  8.     The weapon number
  9. -->
  10. [h: num = macro.args]
  11. [h: Weapons = deleteStrProp(Weapons, strformat("Weapon%{num}Damage"))]
  12. [h: Weapons = deleteStrProp(Weapons, strformat("Weapon%{num}Name"))]
  13. [h: Weapons = deleteStrProp(Weapons, strformat("Weapon%{num}Bonus"))]

One more "setup" function then we should be good to go. Lets create a function that returns a string list of all the item numbers (remember we can have gaps because a user could cancel the addition of the item after calling NextWeaponNumber or they could delete a weapon). Create a macro button on Lib:Test called GetWeaponNumbers

  1. <!--
  2.   Gets a string list of the valid weapon numbers
  3. -->
  4. <!-- If Weapons token property is empty set it to a default value -->
  5. [h,if(isPropertyEmpty("Weapons")): Weapons = "NumWeapons=0;"]
  6.  
  7. [h: maxNum = getStrProp(Weapons, "NumWeapons")]
  8. [h: wnumList=""]
  9. [h,c(maxNum), code: {
  10.   [h: wnum = roll.count+1]
  11.   [h: name = getStrProp(Weapons, strformat("Weapon%{wnum}Name"))]
  12.   [if(name != ""):
  13.     wnumList = listAppend(string(wnumList), string(wnum))
  14.   ]
  15. }]
  16. [h: macro.return = wnumList]


The string() around the arguments in listAppend() is to convert the arguments to strings, as of b48 listAppend() seems to have problems with arguments that could be interpreted as numbers.

Input Dialogs

So now we can get back to the dialogs. Lets create a dialog to edit weapons. Create a macro button on your Lib:Test called EditWeaponDialog and paste the following into it.

  1. [dialog("weaponInput"): {
  2.   [h: weaponNum = getStrProp(macro.args, "Number")]
  3.   [h: name = getStrProp(macro.args, "Name")]
  4.   [h: bonus = getStrProp(macro.args, "Bonus")]
  5.   [h: damage = getStrProp(macro.args, "Damage")]
  6.   <!-- If we do not have a weapon number grab the next one -->
  7.   [h, if(weaponNum == ""), code: {
  8.     [h,macro("NextWeaponNumber@this"): ""]
  9.     [h: weaponNum = macro.return]
  10.   }]
  11.   <html>
  12.     <head>
  13.       <title>Edit Weapon Dialog</title>
  14.       <meta name="input" content="true">
  15.     </head>
  16.     <body>
  17.       <form name="weaponInput" action="[r:macroLinkText('AddWeapon@Lib:Test')]">
  18.         <table>
  19.           <tr>
  20.             <th>
  21.               <label for="Name">Weapon Name</label>
  22.             </th>
  23.             <td>
  24.               <input type="text" name="Name" value="[r: name]"></input> <br>
  25.             </td>
  26.           </tr>
  27.           <tr>
  28.             <th>
  29.               <label for="Damage">Weapon Damage</label>
  30.             </th>
  31.             <td>
  32.               <input type="text" name="Damage" value="[r: damage]"></input> <br>
  33.             </td>
  34.           </tr>
  35.           <tr>
  36.             <th>
  37.               <label for="Bonus">Weapon Bonus</label>
  38.             </th>
  39.             <td>
  40.               <input type="text" name="Bonus" value="[r: bonus]"></input>
  41.             </td>
  42.           </tr>
  43.           </table>
  44.         <!-- hidden input with the weapon number -->
  45.         <input type="hidden" name="Number" value="[r: weaponNum]"></input>
  46.  
  47.         <input type="submit" name="Save" value="Save"> </input>
  48.       </form>
  49.     </body>
  50.   </html>
  51. }]
Edit Weapon Dialog


One thing to note is @this will not work in a macro link, so we build the @ portion of the macro to call when the form is submitted.

The action=... portion of the form tag specifies which macro to call when any submit button is pushed for the form. If the dialog is specified as a input dialog, the close button down the bottom is not displayed and when any form on the dialog is submitted it is closed.

The arguments to the macro that is called when the form is submitted is a string property list with the names of the input fields as the keys and the entered value as the values. Since I named all my inputs the same as the keys in the parameter for the AddWeaponMacro I can call that straight from the submit action on the form (some times is seems like I almost know what I am doing).

The only problem is our edit weapon is kinda plain compared to our character sheet so time to add a little bling.

Change your EditWeaponDialog macro button on Lib:Test to

  1. [dialog("weaponInput"): {
  2.   [h: weaponNum = getStrProp(macro.args, "Number")]
  3.   [h: name = getStrProp(macro.args, "Name")]
  4.   [h: bonus = getStrProp(macro.args, "Bonus")]
  5.   [h: damage = getStrProp(macro.args, "Damage")]
  6.   <!-- If we do not have a weapon number grab the next one -->
  7.   [h, if(weaponNum == ""), code: {
  8.     [h,macro("NextWeaponNumber@this"): ""]
  9.     [h: weaponNum = macro.return]
  10.   }]
  11.   <html>
  12.     <head>
  13.       <title>Edit Weapon Dialog</title>
  14.       <meta name="input" content="true">
  15.       <link rel="stylesheet" type="text/css" href="EditWeapon_css@[r: getMacroLocation()]">
  16.     </head>
  17.     <body>
  18.       <form name="weaponInput" action="[r:macroLinkText('AddWeapon@Lib:Test')]">
  19.         <table>
  20.           <tr>
  21.             <td>
  22.               <table>
  23.                 <tr>
  24.                   <th>
  25.                     <label for="Name">Weapon Name</label>
  26.                   </th>
  27.                   <td>
  28.                     <input type="text" name="Name" value="[r: name]">
  29.                     </input> <br>
  30.                   </td>
  31.                 </tr>
  32.                 <tr>
  33.                   <th>
  34.                     <label for="Damage">Weapon Damage</label>
  35.                   </th>
  36.                   <td>
  37.                     <input type="text" name="Damage" value="[r: damage]">
  38.                     </input> <br>
  39.                   </td>
  40.                 </tr>
  41.                 <tr>
  42.                   <th>
  43.                     <label for="Bonus">Weapon Bonus</label>
  44.                   </th>
  45.                   <td>
  46.                     <input type="text" name="Bonus" value="[r: bonus]">
  47.                     </input>
  48.                   </td>
  49.                 </tr>
  50.               </table>
  51.             </td>
  52.             <td>
  53.               <img src='[r: getTokenImage(100)]'></img>
  54.             </td>
  55.           </tr>
  56.         </table>
  57.         <!-- hidden input with the weapon number -->
  58.         <input type="hidden" name="Number" value="[r: weaponNum]">
  59.         </input>
  60.         <input id="saveButton" type="submit" name="Save" value="Save">
  61.         </input>
  62.       </form>
  63.     </body>
  64.   </html>
  65. }]

And add macro button EditWeapon_css to Lib:Test that contains

  1. body {
  2.    background-color: #CCBBBB
  3. }

And you might as well add a AddWeapon macro button to your Token that contains

  1. [macro("EditWeaponDialog@Lib:Test"): "" ]
  2. [abort(0)]

Now our dialog looks like

Edit Weapon Dialog with a Style Sheet

Ok now lets make a quick dialog to display our weapons. Create a new macro button on your Lib:Test called ViewWeapons and paste in the following

  1. [dialog("Weapons"): {
  2.   <html>
  3.     <head>
  4.       <title>Weapons</title>
  5.       <link rel="stylesheet" type="text/css" href="ViewWeapon_css@[r: getMacroLocation()]">
  6.     </head>
  7.     <body>
  8.       [h,macro("GetWeaponNumbers@this"): ""]
  9.       [h: wpList = macro.return]
  10.       <table>
  11.         [foreach(weapon, wpList, ""), code: {
  12.           [h,macro("GetWeapon@this"): weapon]
  13.           [h: wProp = macro.return]
  14.           <tr class="WeaponName">
  15.             <th>
  16.               [r: getStrProp(wProp, "Name")]
  17.             </th>
  18.           </tr>
  19.           <tr>
  20.             <th>Damage</th>
  21.             <td>[r: getStrProp(wProp, "Damage")]</td>
  22.             <th>Bonus</th>
  23.             <td>[r: getStrProp(wProp, "Bonus")]</td>
  24.           </tr>
  25.         }]
  26.       </table>
  27.     </body>
  28.   </html>
  29. }]

For good measure create a macro button called ViewWeapon_css on Lib:Test paste in the following.

  1. .WeaponName {
  2.     background-color: #55AA55;
  3.     color: white;
  4.     text-align: center;
  5. }

Add a macro button to your Token called ViewWeapons which contains.

  1. [macro("ViewWeapons@Lib:Test"): ""]
  2. [abort(0)]


And this is what it looks like.

Weapon List Dialog

Creating a Simple Character Sheet Frame

Up until now I havent talked at all about frames, but don't worry , change [dialog():] to [frame():] above and it will work (except you cant have a frame that closes when you submit a form, what would be the point?).

But lets make some final changes to show some frames, I am going to make all of these in one go as everything in them has been discussed previously in this post.

First we are going to completely change the CharSheet macro button on Lib:Test to

  1. [frame("CharSheet"): {
  2.   [h: page = getStrProp(macro.args, "Page")]
  3.   [h,if(page==""): page="Main"]
  4.   <html>
  5.     <head>
  6.       <title>Character Sheet</title>
  7.       <link rel="stylesheet" type="text/css" href="CharSheet_css@[r: getMacroLocation()]">
  8.     </head>
  9.     <body>
  10.       [macro("CharSheetHeader@this"): page]
  11.       <br>
  12.       [macro("CharSheet"+page+"@this"): ""]
  13.     </body>
  14.   </html>
  15. }]

Create a CharSheetHeader macro button on Lib:Test and paste the following into it.

  1. [h: currentPage = macro.args]
  2. [h: pages = "Main,Weapons"]
  3. <table>
  4.   <tr>
  5.     [foreach(page, pages,""), code: {
  6.       [h,if (page == currentPage): class="currentPage" ; class="page"]
  7.       [h: callback = "CharSheet@"+getMacroLocation()]
  8.       <td class="[r: class]">
  9.         [r: macroLink(page, callback, "none", "Page="+page)]
  10.       </td>
  11.     }]
  12.   </tr>
  13. </table>

Create a CharSheetMain macro button on Lib:Test and paste the following into it.

  1. [h: propNames = "Strength, Dexterity, Constitution, Intelligence, Wisdom, Charisma"]
  2. <table>
  3.   <tr>
  4.     <td>
  5.       <img src='[r: getTokenImage(100)]'></img>
  6.     </td>
  7.     <td>
  8.       <table id="stats">
  9.         <tr>
  10.           <th>Name</th>
  11.           <th>Score</th>
  12.         </tr>
  13.         [h: class = "oddRow"]
  14.         [foreach(prop, propNames, ""), code: {
  15.           <tr class="[r:class]">
  16.             <td>[r: prop]</td>
  17.             <td>[r: getProperty(prop)]</td>
  18.           </tr>
  19.           [h: class = if(class=="oddRow", "evenRow", "oddRow")]
  20.         }]
  21.       </table>
  22.     </td>
  23.   </tr>
  24. </table>
  25. <hr>
  26. <table>
  27.   <tr>
  28.     <td>
  29.       [h: hpBarArgs = strformat("MaxLen=50; Value=%{HP}; MaxValue=%{MaxHP}; Label=HP")]
  30.       [macro("TrafficLightBar@this"): hpBarArgs]
  31.     </td>
  32.   </tr>
  33.   <tr>
  34.     <td>
  35.       [h: hpBarArgs = strformat("MaxLen=50; Value=%{XP}; MaxValue=%{NextLevelXP}; Label=XP; Color=120,120,255")]
  36.       [macro("StatusBar@this"): hpBarArgs]
  37.     </td>
  38.   </tr>
  39. </table>

Create a CharSheetWeapons macro button on Lib:Test and paste the following into it.

  1. [h,macro("GetWeaponNumbers@this"): ""]
  2. [h: wpList = macro.return]
  3. <table>
  4.   [foreach(weapon, wpList, ""), code: {
  5.     [h,macro("GetWeapon@this"): weapon]
  6.     [h: wProp = macro.return]
  7.     <tr class="WeaponName">
  8.       <th>
  9.         [h: name = getStrProp(wProp, "Name")]
  10.         [h: bonus = getStrProp(wProp, "Bonus")]
  11.         [h: damage = getStrProp(wProp, "Damage")]
  12.         [h: callback = "EditWeaponDialog@" + getMacroLocation()]
  13.         [h: args = strformat("Number=%{weapon}; Name=%{name}; Damage=%{damage}; Bonus=%{bonus}")]
  14.         [r: macroLink(name, callback, "none", args)]
  15.       </th>
  16.     </tr>
  17.     <tr>
  18.       <th>Damage</th>
  19.       <td>[r: getStrProp(wProp, "Damage")]</td>
  20.       <th>Bonus</th>
  21.       <td>[r: getStrProp(wProp, "Bonus")]</td>
  22.     </tr>
  23.   }]
  24. </table>

And the last change to make is the CharSheet_css macro button on Lib:Test an paste the following into it.

  1. .oddRow { background-color: #FFFFFF }
  2. .evenRow { background-color: #EEEEAA }
  3. #stats th { background-color: #113311; color: #FFFFFF }
  4. .WeaponName a {
  5.     background-color: #55AA55;
  6.     color: white;
  7.     text-align: center;
  8. }
  9. .page a {
  10.    background-color: #5555CC;
  11.    color: white;
  12. }
  13. .currentPage a {
  14.    background-color: #7777FF;
  15.    color: white;
  16. }

So what does this give us? A shiny new frame. Unlike Dialogs, Frames act like any of the other maptool windows and can be docked on the sides, or with other windows (forming a tab).

Simple Character Sheet in a Frame


Where it says Main and Weapons on the top, they are links, if you click on Weapons it will change the CharacerSheet frame to

Weapon List in a Frame

And as an added bonus, the weapon names are links, if you click on them it will open up the edit dialog where you can edit them. (note this will not update the character sheet at this time, but that is left as an exercise for the reader).

This has just been a short example of what can be done, I am sure people will come up with some great ideas how to use this.

The campaign file with the dialogs we have created can be found at campaign

Related Pages