<?xml version="1.0" encoding="iso-8859-1"?>

<!-- 
  -- Please see the readme.txt file included with this distribution for 
  -- attribution and copyright information.
  -->

<root version="2.0">
	<template name="linkednumber">
		<jpgnumberfield>
			<source mergerule="resetandadd" />
			<script file="scripts/template_linkednumber.lua" />
		</jpgnumberfield>
	</template>
	
	<template name="modifiernumber">
		<linkednumber>
			<nokeyedit />
			<noreset />
			<script file="scripts/template_modifiernumber.lua" />
		</linkednumber>
	</template>
	
	<template name="jpgsheetbonus">
		<modifiernumber>
			<frame>
				<name>bonus_mod</name>
				<offset>5,5,5,5</offset>
			</frame>
			<font>sheetnumber</font>
			<displaysign />
			<readonly />
			<modifiersize>mini</modifiersize>
		</modifiernumber>
	</template>

	<template name="sheetbonus">
		<linkednumber>
			<frame>
				<name>bonus</name>
				<offset>5,5,5,5</offset>
			</frame>
			<font>sheetnumber</font>
			<readonly />
			<displaysign />
			<noreset />
		</linkednumber>
	</template>

	<template name="sheetnumber">
		<linkednumber>
			<frame>
				<name>modifier</name>
				<offset>5,5,5,5</offset>
			</frame>
			<keyeditframe>
				<name>sheetfocus</name>
				<offset>5,5,5,5</offset>
			</keyeditframe>
			<stateframe>
				<drophilight>
					<name>sheetfocus</name>
					<offset>5,5,5,5</offset>
				</drophilight>
			</stateframe>
			<droptypes>
				<type>number</type>
			</droptypes>
			<font>sheetnumber</font>
		</linkednumber>
	</template>

	<template name="sheetmodifier">
		<linkednumber>
			<frame>
				<name>modifier</name>
				<offset>5,5,5,5</offset>
			</frame>
			<keyeditframe>
				<name>sheetfocus</name>
				<offset>5,5,5,5</offset>
			</keyeditframe>
			<stateframe>
				<drophilight>
					<name>sheetfocus</name>
					<offset>5,5,5,5</offset>
				</drophilight>
			</stateframe>
			<droptypes>
				<type>number</type>
			</droptypes>
			<font>sheetnumber</font>
			<displaysign />
		</linkednumber>
	</template>

	<template name="sheetreadonlymodifier">
		<linkednumber>
			<frame>
				<name>modifier</name>
				<offset>5,5,5,5</offset>
			</frame>
			<font>sheetnumber</font>
			<readonly />
			<displaysign />
		</linkednumber>
	</template>

	<template name="abilityscore">
		<jpgnumberfield>
			<noreset />
			<anchored>
				<position>belowleft</position>
				<offset>0,7</offset>
				<size>
					<width>32</width>
					<height>20</height>
				</size>
			</anchored>
			<frame>
				<name>bonus</name>
				<offset>5,5,5,5</offset>
			</frame>
			<keyeditframe>
				<name>sheetfocus</name>
				<offset>5,5,5,5</offset>
			</keyeditframe>
			<font>sheetnumber</font>
			<script>
				function onInit()
					if getValue() == 0 then
						setValue(10);
					end
				end
			</script>
		</jpgnumberfield>
	</template>
	
	<template name="abilitylabel">
		<stringcontrol>
			<anchored>
				<position>lefthigh</position>
				<offset>0,4</offset>
				<size>
					<width>90</width>
					<height>20</height>
				</size>
			</anchored>
			<static />
			<font>sheetlabel</font>
		</stringcontrol>
	</template>

	<template name="abilitydamage">
		<jpgnumberfield>
			<noreset />
			<anchored>
				<position>right</position>
				<offset>51,0</offset>
				<size>
					<width>32</width>
				</size>
			</anchored>
			<frame>
				<name>modifier</name>
				<offset>5,5,5,5</offset>
			</frame>
			<keyeditframe>
				<name>sheetfocus</name>
				<offset>5,5,5,5</offset>
			</keyeditframe>
			<stateframe>
				<drophilight>
					<name>sheetfocus</name>
					<offset>5,5,5,5</offset>
				</drophilight>
			</stateframe>
			<droptypes>
				<type>number</type>
			</droptypes>
			<font>sheetnumber</font>
			<hideonvalue value="0" />
			<nodrag />
			<script>
				function onValueChanged()
					local v = getValue();
					
					if v &gt; window[target[1]].getValue() then
						setValue(window[target[1]].getValue());
					end
				end
			</script>
		</jpgnumberfield>
	</template>
	
	<template name="abilitybonus">
		<jpgsheetbonus>
			<anchored>
				<position>right</position>
				<offset>9,0</offset>
				<size>
					<width>36</width>
				</size>
			</anchored>
			<hideonvalue value="0" />
			<script>
				function onSourceUpdate()
					setValue(math.floor((sources[scorefield[1]].getValue() - sources[damagefield[1]].getValue() - 10) / 2) + getModifier());
				end

				function onInit()
					addSource(scorefield[1]);
					addSource(damagefield[1]);

					super.onInit();
				end

				function onDoubleClick(x,y)
					ChatManager.DoubleClickAction("dice", getValue(), self.description[1].text[1], {pc = window.getDatabaseNode()});
					return true;
				end			
				
				function onDrag(button, x, y, draginfo)
					if OptionsManager.isOption("DRGR", "on") then
						draginfo.setType("dice");
						draginfo.setDieList({ "d20" });
					else
						draginfo.setType("number");
					end
					draginfo.setDescription(self.description[1].text[1]);
					draginfo.setNumberData(getValue());
					draginfo.setShortcutData("charsheet", window.getDatabaseNode().getNodeName());

					return true;
				end
			</script>
		</jpgsheetbonus>
	</template>

	<template name="classstring">
		<stringfield>
			<anchored>
				<top>
					<parent>classanchor</parent>
					<anchor>bottom</anchor>
					<relation>current</relation>
					<offset>5</offset>
				</top>
				<left>
					<parent>classframe</parent>
					<anchor>left</anchor>
					<relation>absolute</relation>
					<offset>15</offset>
				</left>
				<right>
					<parent>classframe</parent>
					<anchor>right</anchor>
					<relation>absolute</relation>
					<offset>-53</offset>
				</right>
				<size>
					<height>20</height>
				</size>
			</anchored>
			<font>sheettext</font>
			<frame>
				<name>textline</name>
			</frame>
		</stringfield>
	</template>

	<template name="levelnumber">
		<jpgnumberfield>
			<noreset />
			<anchored>
				<top>
					<parent>classanchor</parent>
					<anchor>bottom</anchor>
					<relation>relative</relation>
					<offset>3</offset>
				</top>
				<left>
					<parent>classframe</parent>
					<anchor>right</anchor>
					<offset>-46</offset>
				</left>
				<size>
					<width>32</width>
					<height>20</height>
				</size>
			</anchored>
			<font>sheetnumber</font>
			<frame>
				<name>modifier</name>
				<offset>5,4,5,4</offset>
			</frame>
			<keyeditframe>
				<name>sheetfocus</name>
				<offset>5,4,5,4</offset>
			</keyeditframe>
			<noreset />
			<script>
				function onValueChanged()
					window.characterlevel.updateValue();
				end
			</script>
		</jpgnumberfield>
	</template>
	
	<template name="hitpointfield">
		<jpgnumberfield>
			<noreset />
			<frame>
				<name>bonus</name>
				<offset>5,5,5,5</offset>
			</frame>
			<keyeditframe>
				<name>sheetfocus</name>
				<offset>5,5,5,5</offset>
			</keyeditframe>
			<font>sheetnumber</font>
			<stateframe>
				<drophilight>
					<name>sheetfocusplus</name>
					<offset>5,5,5,5</offset>
				</drophilight>
			</stateframe>
			<droptypes>
				<type>number</type>
			</droptypes>
			<script>
				function onDrop(x, y, draginfo)
					if draginfo.isType("number") then
						setValue(getValue() + draginfo.getNumberData());
						return true;
					end
				end
			</script>
		</jpgnumberfield>
	</template>

	<template name="initmain">
		<linkednumber>
			<font>sheetnumber</font>
			<displaysign />
			<script>
				function onDoubleClick(x,y)
					ChatManager.DoubleClickAction("init", getValue(), self.description[1].text[1], {pc = window.getDatabaseNode()});
					return true;
				end			

				function onDrag(button, x, y, draginfo)
					if OptionsManager.isOption("DRGR", "on") then
						draginfo.setType("init");
						draginfo.setDieList({ "d20" });
					else
						draginfo.setType("number");
					end
					draginfo.setDescription(self.description[1].text[1]);
					draginfo.setNumberData(getValue());
					draginfo.setShortcutData("charsheet", window.getDatabaseNode().getNodeName());

					return true;
				end
			</script>
		</linkednumber>
	</template>

	<template name="init">
		<sheetbonus>
			<script>
				function onDoubleClick(x,y)
					ChatManager.DoubleClickAction("init", getValue(), self.description[1].text[1], {pc = window.getDatabaseNode()});
					return true;
				end			

				function onDrag(button, x, y, draginfo)
					if OptionsManager.isOption("DRGR", "on") then
						draginfo.setType("init");
						draginfo.setDieList({ "d20" });
					else
						draginfo.setType("number");
					end
					draginfo.setDescription(self.description[1].text[1]);
					draginfo.setNumberData(getValue());
					draginfo.setShortcutData("charsheet", window.getDatabaseNode().getNodeName());

					return true;
				end
			</script>
		</sheetbonus>
	</template>

	<template name="attack_main">
		<linkednumber>
			<script>
				function onDoubleClick(x,y)
					ChatManager.DoubleClickAction("attack", getValue(), "[ATTACK] " .. self.description[1].text[1], {pc = window.getDatabaseNode()});
					return true;
				end			

				function onDrag(button, x, y, draginfo)
					if OptionsManager.isOption("DRGR", "on") then
						draginfo.setType("attack");
						draginfo.setDieList({ "d20" });
					else
						draginfo.setType("number");
					end
					draginfo.setDescription("[ATTACK] " .. self.description[1].text[1]);
					draginfo.setNumberData(getValue());
					draginfo.setShortcutData("charsheet", window.getDatabaseNode().getNodeName());

					return true;
				end
			</script>
		</linkednumber>
	</template>
	<template name="melee_main">
		<attack_main>
			<frame>
				<name>bonus</name>
				<offset>5,5,5,5</offset>
			</frame>
			<font>sheetnumber</font>
			<displaysign />
			<readonly />
			<description>
				<text>Melee attack</text>
			</description>
			<source>
				<name>attackbonus.base</name>
				<op>+</op>
			</source>
			<source>
				<name>abilities.strength.bonus</name>
				<op>+</op>
			</source>
		</attack_main>
	</template>
	<template name="ranged_main">
		<attack_main>
			<frame>
				<name>bonus</name>
				<offset>5,5,5,5</offset>
			</frame>
			<font>sheetnumber</font>
			<displaysign />
			<readonly />
			<description>
				<text>Ranged attack</text>
			</description>
			<source>
				<name>attackbonus.base</name>
				<op>+</op>
			</source>
			<source>
				<name>abilities.dexterity.bonus</name>
				<op>+</op>
			</source>
		</attack_main>
	</template>

	<template name="attack_combat">
		<sheetbonus>
			<script>
				function onDoubleClick(x,y)
					ChatManager.DoubleClickAction("attack", getValue(), "[ATTACK] " .. self.description[1].text[1], {pc = window.getDatabaseNode()});
					return true;
				end			

				function onDrag(button, x, y, draginfo)
					if OptionsManager.isOption("DRGR", "on") then
						draginfo.setType("attack");
						draginfo.setDieList({ "d20" });
					else
						draginfo.setType("number");
					end
					draginfo.setDescription("[ATTACK] " .. self.description[1].text[1]);
					draginfo.setNumberData(getValue());
					draginfo.setShortcutData("charsheet", window.getDatabaseNode().getNodeName());

					return true;
				end
			</script>
		</sheetbonus>
	</template>
	<template name="melee_combat">
		<attack_combat>
			<description>
				<text>Melee attack</text>
			</description>
			<source>
				<name>abilities.strength.bonus</name>
				<op>+</op>
			</source>
			<source>
				<name>attackbonus.base</name>
				<op>+</op>
			</source>
			<source>
				<name>attackbonus.melee.size</name>
				<op>+</op>
			</source>
			<source>
				<name>attackbonus.melee.misc</name>
				<op>+</op>
			</source>
		</attack_combat>
	</template>
	<template name="ranged_combat">
		<attack_combat>
			<description>
				<text>Ranged attack</text>
			</description>
			<source>
				<name>abilities.dexterity.bonus</name>
				<op>+</op>
			</source>
			<source>
				<name>attackbonus.base</name>
				<op>+</op>
			</source>
			<source>
				<name>attackbonus.ranged.size</name>
				<op>+</op>
			</source>
			<source>
				<name>attackbonus.ranged.misc</name>
				<op>+</op>
			</source>
		</attack_combat>
	</template>
	
	<template name="grapplebonus">
		<sheetbonus>
			<script>
				function onDoubleClick(x,y)
					ChatManager.DoubleClickAction("dice", getValue(), self.description[1].text[1], {pc = window.getDatabaseNode()});
					return true;
				end			

				function onDrag(button, x, y, draginfo)
					if OptionsManager.isOption("DRGR", "on") then
						draginfo.setType("dice");
						draginfo.setDieList({ "d20" });
					else
						draginfo.setType("number");
					end
					draginfo.setDescription(self.description[1].text[1]);
					draginfo.setNumberData(getValue());
					draginfo.setShortcutData("charsheet", window.getDatabaseNode().getNodeName());

					return true;
				end
			</script>
		</sheetbonus>
	</template>

	<template name="savemain">
		<jpgsheetbonus>
			<script>
				function onDoubleClick(x,y)
					ChatManager.DoubleClickAction("save", getValue(), self.description[1].text[1], {pc = window.getDatabaseNode()});
					return true;
				end			

				function onDrag(button, x, y, draginfo)
					if OptionsManager.isOption("DRGR", "on") then
						draginfo.setType("save");
						draginfo.setDieList({ "d20" });
					else
						draginfo.setType("number");
					end
					draginfo.setDescription(self.description[1].text[1]);
					draginfo.setNumberData(getValue());
					draginfo.setShortcutData("charsheet", window.getDatabaseNode().getNodeName());

					return true;
				end
			</script>
		</jpgsheetbonus>
	</template>

	<template name="save_combat">
		<jpgsheetbonus>
			<anchored>
				<position>belowleft</position>
				<offset>0,8</offset>
				<size>
					<width>32</width>
					<height>20</height>
				</size>
			</anchored>
			<script>
				function onInit()
					addSourceWithOp("saves." .. root[1] .. ".base", "+");
					addSourceWithOp("saves." .. root[1] .. ".misc", "+");
					addSourceWithOp("saves." .. root[1] .. ".temporary", "+");

					addSourceWithOp("abilities." .. stat[1] .. ".bonus", "+");
				
					super.onInit();
				end

				function onDoubleClick(x,y)
					ChatManager.DoubleClickAction("save", getValue(), self.description[1].text[1], {pc = window.getDatabaseNode()});
					return true;
				end			

				function onDrag(button, x, y, draginfo)
					if OptionsManager.isOption("DRGR", "on") then
						draginfo.setType("save");
						draginfo.setDieList({ "d20" });
					else
						draginfo.setType("number");
					end
					draginfo.setDescription(self.description[1].text[1]);
					draginfo.setNumberData(getValue());
					draginfo.setShortcutData("charsheet", window.getDatabaseNode().getNodeName());

					return true;
				end
			</script>
		</jpgsheetbonus>
	</template>

	<template name="savelabel">
		<stringcontrol>
			<anchored>
				<position>lefthigh</position>
				<offset>0,4</offset>
				<size>
					<width>80</width>
					<height>20</height>
				</size>
			</anchored>
			<font>sheetlabel</font>
			<static />
		</stringcontrol>
	</template>

	<template name="savebase">				
		<linkednumber>
			<anchored>
				<position>right</position>
				<offset>16,0</offset>
				<size>
					<width>32</width>
				</size>
			</anchored>
			<frame>
				<name>modifier</name>
				<offset>5,5,5,5</offset>
			</frame>
			<keyeditframe>
				<name>sheetfocus</name>
				<offset>5,5,5,5</offset>
			</keyeditframe>
			<font>sheetnumber</font>
			<displaysign />
			<hideonvalue>0</hideonvalue>
			<nodrag />
			<noreset />
		</linkednumber>
	</template>

	<template name="savestatbonus">
		<numbercontrol>
			<anchored>
				<position>right</position>
				<offset>8,0</offset>
				<size>
					<width>32</width>
				</size>
			</anchored>
			<frame>
				<name>modifier</name>
				<offset>5,5,5,5</offset>
			</frame>
			<font>sheetnumber</font>
			<displaysign />
			<hideonvalue>0</hideonvalue>
			<readonly />
			<nodrag />
			<script>
				statNode = nil;
			
				function update(source)
					setValue(statNode.getValue());
				end

				function onInit()
					local node = window.getDatabaseNode().getChild(bonusfield[1]);
					if node then
						statNode = node;
						node.onUpdate = update;
						update();
					end
				end
			</script>
		</numbercontrol>
	</template>

	<template name="savemisc">
		<linkednumber>
			<anchored>
				<position>right</position>
				<offset>8,0</offset>
				<size>
					<width>32</width>
				</size>
			</anchored>
			<frame>
				<name>modifier</name>
				<offset>5,5,5,5</offset>
			</frame>
			<keyeditframe>
				<name>sheetfocus</name>
				<offset>5,5,5,5</offset>
			</keyeditframe>
			<font>sheetnumber</font>
			<displaysign />
			<hideonvalue>0</hideonvalue>
			<nodrag />
			<noreset />
		</linkednumber>
	</template>

	<template name="savemodifier">
		<linkednumber>
			<anchored>
				<position>right</position>
				<offset>8,0</offset>
				<size>
					<width>32</width>
				</size>
			</anchored>
			<frame>
				<name>modifier</name>
				<offset>5,5,5,5</offset>
			</frame>
			<keyeditframe>
				<name>sheetfocus</name>
				<offset>5,5,5,5</offset>
			</keyeditframe>
			<font>sheetnumber</font>
			<displaysign />
			<hideonvalue>0</hideonvalue>
			<nodrag />
			<noreset />
		</linkednumber>
	</template>

	<template name="skillsetcontrol">
		<genericcontrol>
			<stateicons>
				<on>indicator_checkon</on>
				<off>indicator_checkoff</off>
			</stateicons>
			<script>
				function disable()
					if activesetnode and activesetnode.getValue() == tonumber(setid[1]) then
						activesetnode.setValue(1);
					end

					setVisible(false);
				end
			
				function update(source)
					local state = false;
					if activesetnode and activesetnode.getValue() == tonumber(setid[1]) then
						state = true;
					end
					
					if not state then
						setIcon(stateicons[1].off[1]);
					else
						setIcon(stateicons[1].on[1]);
					end
				end
				
				function onClickDown(button, x, y)
					if activesetnode and setid[1] ~= 0 and activesetnode.getValue() ~= tonumber(setid[1]) then
						activesetnode.setValue(setid[1]);
					end
				end

				function onInit()
					activesetnode = window.getDatabaseNode().getChild("activeskillset");

					--[[ If the active skill set is not yet set, initialize it to the first set ]]
					if not activesetnode then
						activesetnode = NodeManager.createSafeChild(window.getDatabaseNode(), "activeskillset", "number");
						if activesetnode then
							activesetnode.setValue(1);
						end
					end
				
					if activesetnode then
						activesetnode.onUpdate = update;
						update(activesetnode);
					end
				end
			</script>
		</genericcontrol>
	</template>
	
	<template name="skillsetlabel">
		<stringfield>
			<font>sheettextsmall</font>
			<static />
			<script>
				function onClickDown(button, x, y)
					window[target[1]].onClickDown(button, x, y);
				end
			
				function updateVisibility()
					if defaultset then
						return;
					end
				
					if getValue() == "" then
						setVisible(false);
						window[target[1]].disable();
					else
						setVisible(true);
						window[target[1]].setVisible(true);
					end
				end

				function onValueChanged()
					updateVisibility();
				end
			
				function onInit()
					updateVisibility();
				end
			</script>
		</stringfield>
	</template>
	
	<template name="spellcounter">
		<genericcontrol>
			<stateicons>
				<on>indicator_checkon</on>
				<off>indicator_checkoff</off>
			</stateicons>
			<spacing>10</spacing>
			<script file="scripts/charsheet_spellcounter.lua" />
		</genericcontrol>
	</template>
	
	<template name="spellsavailable">
		<jpgnumberfield>
			<noreset />
			<anchored>
				<top>
					<anchor>top</anchor>
					<offset>8</offset>
				</top>
				<size>
					<width>25</width>
					<height>22</height>
				</size>
			</anchored>
			<frame>
				<name>modifier</name>
				<offset>4,1,3,1</offset>
			</frame>
			<keyeditframe>
				<name>sheetfocus</name>
				<offset>4,1,3,1</offset>
			</keyeditframe>
			<font>sheetnumbersmall</font>
			<script>
				function updateVisibility()
					local state = false;
					if modnode then
						state = (modenode.getValue () ~= 0);
					end
					
					if not state and not isVisible() then
						setVisible(true);
						if window[getName() .. "label"] then
							window[getName() .. "label"].setVisible(true);
						end
					elseif state and isVisible() then
						setVisible(false);
						if window[getName() .. "label"] then
							window[getName() .. "label"].setVisible(false);
						end
					end
				end
				
				function onValueChanged()
					window.spelllevellist.applyFilter();
				end
			
				function onInit()
					modenode = NodeManager.createSafeChild(getDatabaseNode(), "....castingmode", "number");
					if modenode then
						modenode.onUpdate = updateVisibility;
					end
					updateVisibility();
				end
			</script>
		</jpgnumberfield>
	</template>
	
	<template name="weaponattack">
		<modifiernumber>
			<displaysign />
			<readonly />
			<modifiersize>mini</modifiersize>
			<script file="scripts/charsheet_weaponattack.lua" />
		</modifiernumber>
	</template>
	
	<template name="weapondamage">
		<diefield>
			<noreset />
			<script>
				function getDamage()
					local basedice = getDice();
					local basebonus = window.damagebonus.getValue();

					local dmg_text = "[DAMAGE] " .. window.name.getValue()
					local dmg_dice = {};
					local dmg_bonus = 0;

					local isCritical = Input.isShiftPressed();
					if isCritical then
						local s = window.critmultiplier.getValue();
						local crit_str = string.match(s, "%d+");
						local critmult = 2;
						if crit_str then
							critmult = tonumber(crit_str) or 0;
							if critmult &lt; 2 then
								critmult = 2;
							end
						end
						
						for i = 1, critmult do
							for j = 1, #basedice do
								table.insert(dmg_dice, basedice[j]);
							end
						end
						
						dmg_bonus = critmult * basebonus;
						
						dmg_text = dmg_text .. " [CRITICAL]";
					else
						dmg_dice = basedice;
						dmg_bonus = basebonus
					end
					
					return dmg_text, dmg_dice, dmg_bonus;
				end
				
				function onDoubleClick(x,y)
					local dmg_text, dmg_dice, dmg_bonus = getDamage();
					ChatManager.DoubleClickDieControl("damage", dmg_bonus, dmg_text, {pc = window.getDatabaseNode().getParent().getParent()}, dmg_dice);
					return true;
				end			

				function onDrag(button, x, y, draginfo)
					local dmg_text, dmg_dice, dmg_bonus = getDamage();
					draginfo.setType("damage");
					draginfo.setDieList(dmg_dice);
					draginfo.setNumberData(dmg_bonus);
					draginfo.setDescription(dmg_text);
					draginfo.setShortcutData("charsheet", window.getDatabaseNode().getParent().getParent().getNodeName());

					return true;
				end
			</script>
		</diefield>
	</template>

	<template name="specialabilitynumber">
		<numbercontrol>
			<noreset />
			<invisible />
			<script>
				function enable(state)
					if state then
						source = NodeManager.createSafeChild(window.getDatabaseNode(), "number", "number");
						if source then
							source.onDelete = onDelete;
							source.onUpdate = onUpdate;
							setValue(source.getValue());
						end
					else
						source.delete();
						source = nil;
					end

					setVisible(state);
				end
				
				function checkSource()
					source = window.getDatabaseNode().getChild("number");
					if source then
						enable(true);
					end
				end
				
				function setSourceValue(value)
					if source then
						source.setValue(value);
					end
				end
				
				function onDelete()
					source = nil;
					setVisible(false);
				end
				
				function onUpdate()
					if source then
						setValue(source.getValue());
					end
				end
			
				function onValueChanged()
					if source then
						source.setValue(getValue());
					end
					if window.use_button then
						window.updateVisibility();
					end
				end
				
				function onInit()
					registerMenuItem("Delete number value", "delete", 4);
					
					--[[ Set up monitoring for the creation of the data node ]]
					window.getDatabaseNode().onChildAdded = checkSource;
					checkSource();
				end
				
				function onMenuSelection(selection)
					if selection == 4 then
						enable(false);
					end
				end
				
				function onDrag(button, x, y, draginfo)
					if source then
						draginfo.setType("number");
						draginfo.setDescription(window.value.getValue());
						draginfo.setNumberData(getValue());
						return true;
					end
				end
			</script>
		</numbercontrol>
	</template>

	<template name="specialabilitydice">
		<diecontrol>
			<invisible />
			<noreset />
			<script>
				function enable(state)
					if state then
						source = NodeManager.createSafeChild(window.getDatabaseNode(), "dice", "dice");
						if source then
							source.onDelete = onDelete;
							source.onUpdate = onUpdate;
							setDice(source.getValue());
						end
					else
						source.delete();
						source = nil;
					end

					setVisible(state);
				end
				
				function checkSource()
					source = window.getDatabaseNode().getChild("dice");
					if source then
						enable(true);
					end
				end
				
				function setSourceValue(value)
					local dietypetable = {};
					
					--[[ Allow both dragdata style and database style die lists ]]
					for k,v in ipairs(value) do
						if type(v) == "table" then
							table.insert(dietypetable, v.type);
						else
							table.insert(dietypetable, v);
						end
					end
				
					if source then
						source.setValue(dietypetable);
					end
				end
				
				function onDelete()
					source = nil;
					setVisible(false);
				end
				
				function onUpdate()
					if source then
						setDice(source.getValue());
					end
				end
			
				function onValueChanged()
					if source then
						source.setValue(getValue());
					end
				end
				
				function onInit()
					registerMenuItem("Delete dice", "delete", 3);
					
					--[[ Set up monitoring for the creation of the data node ]]
					window.getDatabaseNode().onChildAdded = checkSource;
					checkSource();
				end
				
				function onMenuSelection(selection)
					if selection == 3 then
						enable(false);
					end
				end
				
				function getDescriptionString()
					local desc = "Ability [" .. window.value.getValue() .. "]";
					return desc;
				end
				
				function onDrag(button, x, y, draginfo)
					if source then
						draginfo.setType("dice");
						draginfo.setDescription(getDescriptionString());
						draginfo.setDieList(getDice());
						draginfo.setShortcutData("charsheet", window.getDatabaseNode().getParent().getParent().getNodeName());
						return true;
					end
				end

				function onDoubleClick(x,y)
					ChatManager.DoubleClickDieControl("dice", 0, getDescriptionString(), {pc = window.getDatabaseNode().getParent().getParent()}, getDice());
					return true;
				end			
			</script>
		</diecontrol>
	</template>

	<template name="inventorydice">
		<diecontrol>
			<invisible />
			<noreset />
			<script file="scripts/charsheet_inventorydice.lua" />
		</diecontrol>
	</template>

	<template name="inventorybonus">
		<numbercontrol>
			<invisible />
			<noreset />
			<displaysign />
			<font>sheetnumbersmall</font>
			<script file="scripts/charsheet_inventorybonus.lua" />
		</numbercontrol>
	</template>

	<template name="spelldice">
		<diecontrol>
			<invisible />
			<noreset />
			<script file="scripts/charsheet_spelldice.lua" />
		</diecontrol>
	</template>

	<template name="spellbonus">
		<numbercontrol>
			<invisible />
			<noreset />
			<displaysign />
			<font>sheetnumbersmall</font>
			<script file="scripts/charsheet_spellbonus.lua" />
		</numbercontrol>
	</template>

</root>