<!-- This file is provided under the Open Game License version 1.0a
  -- For more information on OGL and related issues, see 
  --   http://www.wizards.com/d20
  --
  -- For information on the Fantasy Grounds d20 Ruleset licensing and
  -- the OGL license text, see the d20 ruleset license in the program
  -- options.
  --
  -- All producers of work derived from this definition are adviced to
  -- familiarize themselves with the above licenses, and to take special
  -- care in providing the definition of Product Identity (as specified
  -- by the OGL) in their products.
  --
  -- Copyright 2007 SmiteWorks Ltd.
  -->

<?xml version="1.0" encoding="iso-8859-1"?>
<root version="2.0">
	<template name="npctoplabel">
		<stringcontrol>
			<font>sheetlabelsmall_npc</font>
			<center />
			<script>
				function onInit()
					if anchor then
						setAnchor("bottom", anchor[1], "top", "absolute", 2);
						setAnchor("left", anchor[1], "left", "absolute", 0);
						setAnchor("right", anchor[1], "right", "absolute", 0);
					end
				end
			</script>
		</stringcontrol>
	</template>

	<template name="npcabilityfield">
		<numberfield>
			<nodrop />
			<noreset />
			<hideonvalue>0</hideonvalue>
			<font>sheettextsmall_npc</font>
			<frame>
				<name>modifier</name>
				<offset>5,2,5,4</offset>
			</frame>
			<script>
				function onInit()
					setAnchor("top", "specialqualities", "bottom", "absolute", 17);
					
					if anchor then
						setAnchor("left", anchor[1], "right", "relative", 5);
					else
						setAnchor("left", "specialqualities", "left", "absolute", -2);
					end
					
					setAnchoredWidth(20);
					setAnchoredHeight(18);
					
					if getDatabaseNode().isStatic() then
						setFont("chatfont");
					end
				end
			</script>
		</numberfield>
	</template>

	<template name="npcsavefield">
		<numberfield>
			<nodrop />
			<noreset />
			<displaysign />
			<font>sheettextsmall_npc</font>
			<frame>
				<name>modifier</name>
				<offset>5,2,5,4</offset>
			</frame>
			<script>
				function onInit()
					setAnchor("top", "strength", "bottom", "absolute", 17);
					
					if anchor then
						setAnchor("left", anchor[1], "right", "relative", 5);
					else
						setAnchor("left", "strength", "left", "absolute", 0);
					end
					
					setAnchoredWidth(47);
					setAnchoredHeight(18);
					
					if getDatabaseNode().isStatic() then
						setFont("chatfont");
					end
				end
			</script>
		</numberfield>
	</template>

	<windowclass name="npc_combat">
		<datasource>npc</datasource>
		<script>
			--[[ If the size of the window changes, adjust the widths of abilities and saves ]]
			function sizeChanged()
				local winwidth, winheight = getSize();

				local abilitywidth = math.floor(21 + (winwidth - 235) / 6);

				strength.setAnchoredWidth(abilitywidth);
				dexterity.setAnchoredWidth(abilitywidth);
				constitution.setAnchoredWidth(abilitywidth);
				intelligence.setAnchoredWidth(abilitywidth);
				wisdom.setAnchoredWidth(abilitywidth);
				charisma.setAnchoredWidth(abilitywidth);

				local savewidth = math.floor(47 + (winwidth - 235) / 3);

				fortitudesave.setAnchoredWidth(savewidth);
				reflexsave.setAnchoredWidth(savewidth);
				willsave.setAnchoredWidth(savewidth);
			end
			
			function onInit()
				self.onSizeChanged = sizeChanged;
			end
		</script>
		<sheetdata>
			<columnstringfield name="hd">
				<tabtarget next="hp" prev="name" />
			</columnstringfield>
			<columnfieldlabel>
				<anchor>hd</anchor>
				<static>HD</static>
			</columnfieldlabel>

			<columnnumberfield name="hp">
				<anchor>hd</anchor>
				<tabtarget next="mas" prev="hd" />
			</columnnumberfield>
			<columnfieldlabel>
				<anchor>hp</anchor>
				<static>hp</static>
			</columnfieldlabel>

			<columnnumberfield name="mas">
				<anchor>hd</anchor>
				<tabtarget next="init" prev="hp" />
			</columnnumberfield>
			<columnfieldlabel>
				<anchor>mas</anchor>
				<static>Mas</static>
			</columnfieldlabel>
			
			<columnnumberfield name="init">
				<anchor>hd</anchor>
				<displaysign />
				<tabtarget next="actionpoints" prev="hp" />
			</columnnumberfield>
			<columnfieldlabel>
				<anchor>init</anchor>
				<static>Initiative</static>
			</columnfieldlabel>
	
			<columnnumberfield name="actionpoints">
				<anchor>hd</anchor>
				<tabtarget next="speed" prev="init" />
			</columnnumberfield>
			<columnfieldlabel>
				<anchor>actionpoints</anchor>
				<static>Action Points</static>
			</columnfieldlabel>
			
			<columnstringfield name="speed">
				<anchor>hd</anchor>
				<tabtarget next="ac" prev="init" />
			</columnstringfield>
			<columnfieldlabel>
				<anchor>speed</anchor>
				<static>Speed</static>
			</columnfieldlabel>

			<columnstringfield name="ac">
				<anchor>hd</anchor>
				<tabtarget next="babgrp" prev="speed" />
			</columnstringfield>
			<columnfieldlabel>
				<anchor>ac</anchor>
				<static>Defence</static>
			</columnfieldlabel>

			<columnstringfield name="babgrp">
				<anchor>hd</anchor>
				<tabtarget next="atk" prev="ac" />
			</columnstringfield>
			<columnfieldlabel>
				<anchor>babgrp</anchor>
				<static>BAB / Grp</static>
			</columnfieldlabel>

			<columnstringfield name="atk">
				<anchor>hd</anchor>
				<tabtarget next="fullatk" prev="babgrp" />
				<script file="scripts/npcattackfield.lua" />
			</columnstringfield>
			<columnfieldlabel>
				<anchor>atk</anchor>
				<static>Attack</static>
			</columnfieldlabel>

			<columnstringfield name="fullatk">
				<anchor>hd</anchor>
				<tabtarget next="spacereach" prev="atk" />
				<script file="scripts/npcattackfield.lua" />
			</columnstringfield>
			<columnfieldlabel>
				<anchor>fullatk</anchor>
				<static>Full attack</static>
			</columnfieldlabel>
	
			<columnstringfield name="spacereach">
				<anchor>hd</anchor>
				<tabtarget next="specialattacks" prev="fullatk" />
			</columnstringfield>
			<columnfieldlabel>
				<anchor>spacereach</anchor>
				<static>Space/Reach</static>
			</columnfieldlabel>

			<columnstringfield name="specialattacks">
				<anchor>hd</anchor>
				<tabtarget next="specialqualities" prev="spacereach" />
			</columnstringfield>
			<columnfieldlabel>
				<anchor>specialattacks</anchor>
				<static>SA</static>
			</columnfieldlabel>

			<columnstringfield name="specialqualities">
				<anchor>hd</anchor>
				<tabtarget next="strength" prev="specialattacks" />
			</columnstringfield>
			<columnfieldlabel>
				<anchor>specialqualities</anchor>
				<static>SQ</static>
			</columnfieldlabel>


			<npcabilityfield name="strength">
				<tabtarget next="dexterity" prev="specialqualities" />
			</npcabilityfield>
			<npctoplabel>
				<anchor>strength</anchor>
				<static>Str</static>
			</npctoplabel>
			<npcabilityfield name="dexterity">
				<anchor>strength</anchor>
				<tabtarget next="constitution" prev="strength" />
			</npcabilityfield>
			<npctoplabel>
				<anchor>dexterity</anchor>
				<static>Dex</static>
			</npctoplabel>
			<npcabilityfield name="constitution">
				<anchor>strength</anchor>
				<tabtarget next="intelligence" prev="dexterity" />
			</npcabilityfield>
			<npctoplabel>
				<anchor>constitution</anchor>
				<static>Con</static>
			</npctoplabel>
			<npcabilityfield name="intelligence">
				<anchor>strength</anchor>
				<tabtarget next="wisdom" prev="constitution" />
			</npcabilityfield>
			<npctoplabel>
				<anchor>intelligence</anchor>
				<static>Int</static>
			</npctoplabel>
			<npcabilityfield name="wisdom">
				<anchor>strength</anchor>
				<tabtarget next="charisma" prev="intelligence" />
			</npcabilityfield>
			<npctoplabel>
				<anchor>wisdom</anchor>
				<static>Wis</static>
			</npctoplabel>
			<npcabilityfield name="charisma">
				<anchor>strength</anchor>
				<tabtarget next="fortitudesave" prev="wisdom" />
			</npcabilityfield>
			<npctoplabel>
				<anchor>charisma</anchor>
				<static>Cha</static>
			</npctoplabel>

			<columnfieldlabel>
				<anchor>strength</anchor>
				<static>Abilities</static>
			</columnfieldlabel>


			<npcsavefield name="fortitudesave">
				<tabtarget next="reflexsave" prev="charisma" />
			</npcsavefield>
			<npctoplabel>
				<anchor>fortitudesave</anchor>
				<static>Fortitude</static>
			</npctoplabel>
			<npcsavefield name="reflexsave">
				<anchor>fortitudesave</anchor>
				<tabtarget next="willsave" prev="fortitudesave" />
			</npcsavefield>
			<npctoplabel>
				<anchor>reflexsave</anchor>
				<static>Reflex</static>
			</npctoplabel>
			<npcsavefield name="willsave">
				<anchor>fortitudesave</anchor>
				<tabtarget next="name" prev="reflexsave" />
			</npcsavefield>
			<npctoplabel>
				<anchor>willsave</anchor>
				<static>Will</static>
			</npctoplabel>

			<columnfieldlabel>
				<anchor>fortitudesave</anchor>
				<static>Saves</static>
			</columnfieldlabel>

			
			<!-- Spacer -->
			<genericcontrol>
				<anchored>
					<to>fortitudesave</to>
					<position>below</position>
					<size>
						<height>25</height>
					</size>
				</anchored>
			</genericcontrol>
		</sheetdata>
	</windowclass>

	<windowclass name="npc_other">
		<datasource>npc</datasource>
		<sheetdata>
			<columnstringfield name="type">
				<tabtarget next="skills" prev="name" />
			</columnstringfield>
			<columnfieldlabel>
				<anchor>type</anchor>
				<static>Type</static>
			</columnfieldlabel>
			
			<columnstringfield name="skills">
				<anchor>type</anchor>
				<tabtarget next="feats" prev="type" />
				<script file="scripts/npcskillfield.lua" />
			</columnstringfield>
			<columnfieldlabel>
				<anchor>skills</anchor>
				<static>Skills</static>
			</columnfieldlabel>

			<columnstringfield name="feats">
				<anchor>type</anchor>
				<tabtarget next="talents" prev="skills" />
			</columnstringfield>
			<columnfieldlabel>
				<anchor>feats</anchor>
				<static>Feats</static>
			</columnfieldlabel>

			<columnstringfield name="talents">
				<anchor>type</anchor>
				<tabtarget next="environment" prev="feats" />
			</columnstringfield>
			<columnfieldlabel>
				<anchor>talents</anchor>
				<static>Talents</static>
			</columnfieldlabel>
			
			<columnstringfield name="environment">
				<anchor>type</anchor>
				<tabtarget next="organization" prev="feats" />
			</columnstringfield>
			<columnfieldlabel>
				<anchor>environment</anchor>
				<static>Environment</static>
			</columnfieldlabel>

			<columnstringfield name="organization">
				<anchor>type</anchor>
				<tabtarget next="cr" prev="environment" />
			</columnstringfield>
			<columnfieldlabel>
				<anchor>organization</anchor>
				<static>Organization</static>
			</columnfieldlabel>

			<columnnumberfield name="cr">
				<anchor>type</anchor>
				<tabtarget next="treasure" prev="reputation" />
			</columnnumberfield>
			<columnfieldlabel>
				<anchor>cr</anchor>
				<static>CR</static>
			</columnfieldlabel>
			
			<columnnumberfield name="reputation">
				<anchor>type</anchor>
				<displaysign />
				<tabtarget next="treasure" prev="cr" />
			</columnnumberfield>
			<columnfieldlabel>
				<anchor>reputation</anchor>
				<static>Reputation</static>
			</columnfieldlabel>

			<columnstringfield name="treasure">
				<anchor>type</anchor>
				<tabtarget next="alignment" prev="cr" />
			</columnstringfield>
			<columnfieldlabel>
				<anchor>treasure</anchor>
				<static>Treasure</static>
			</columnfieldlabel>

			<columnstringfield name="alignment">
				<anchor>type</anchor>
				<tabtarget next="advancement" prev="treasure" />
			</columnstringfield>
			<columnfieldlabel>
				<anchor>alignment</anchor>
				<static>Allegiance</static>
			</columnfieldlabel>

			<columnstringfield name="advancement">
				<anchor>type</anchor>
				<tabtarget next="leveladjustment" prev="alignment" />
			</columnstringfield>
			<columnfieldlabel>
				<anchor>advancement</anchor>
				<static>Adv.</static>
			</columnfieldlabel>

			<columnstringfield name="leveladjustment">
				<anchor>type</anchor>
				<tabtarget next="name" prev="advancement" />
			</columnstringfield>
			<columnfieldlabel>
				<anchor>leveladjustment</anchor>
				<static value="Level Adj." />
			</columnfieldlabel>

			<!-- Spacer -->
			<genericcontrol>
				<anchored>
					<to>leveladjustment</to>
					<position>below</position>
					<size>
						<height>15</height>
					</size>
				</anchored>
			</genericcontrol>
		</sheetdata>
	</windowclass>

	<windowclass name="npc_description">
		<datasource>npc</datasource>
		<sheetdata>
			<!-- DESCRIPTION -->
			<formattedtextfield name="text">
				<anchored>
					<top>
						<anchor>top</anchor>
					</top>
					<left>
						<anchor>left</anchor>
					</left>
					<right>
						<anchor>right</anchor>
					</right>
				</anchored>
				<font>
					<normal>LED_regularfont</normal>
					<bold>LED_boldfont</bold>
					<italic>LED_italicfont</italic>
					<bolditalic>LED_bolditalicfont</bolditalic>
					<title>LED_defaultstringcontrol</title>
				</font>
				<linkicon>
					<link>button_openwindow</link>
					<emptylink>button_emptytarget</emptylink>
				</linkicon>
				<selectioncolor>#FFD296</selectioncolor>
				<footer>footer_narrow</footer>
				<empty>Click to enter description</empty>
			</formattedtextfield>
		</sheetdata>
	</windowclass>

	<windowclass name="npc">
		<datasource>npc</datasource>
		<frame>charsheet</frame>
		<placement>
			<size>
				<width>300</width>
				<height>400</height>
			</size>
		</placement>
		<sizelimits>
			<minimum>
				<width>270</width>
				<height>400</height>
			</minimum>
			<dynamic />
		</sizelimits>
		<minimize>minimized_npc</minimize>
		<tooltip>
			<field>name</field>
		</tooltip>
		<sheetdata>
			<!-- NAME -->
			<genericcontrol name="nameframe">
				<bounds>38,20,-35,35</bounds>
				<frame>
					<name>sheetgroup</name>
				</frame>
			</genericcontrol>
			<windowopencontrol>
				<anchored>
					<to>nameframe</to>
					<position>insidetopleft</position>
					<offset>13,8</offset>
					<size>
						<width>20</width>
						<height>20</height>
					</size>
				</anchored>
				<icon>
					<normal>button_openwindow</normal>
					<pressed>button_emptytarget</pressed>
				</icon>
				<class>npc</class>
				<description>
					<field>name</field>
				</description>
			</windowopencontrol>
			<stringfield name="name">
				<anchored>
					<top>
						<parent>nameframe</parent>
						<anchor>top</anchor>
						<offset>9</offset>
					</top>
					<left>
						<parent>nameframe</parent>
						<anchor>left</anchor>
						<offset>35</offset>
					</left>
					<right>
						<parent>nameframe</parent>
						<anchor>right</anchor>
						<offset>-15</offset>
					</right>
				</anchored>
				<empty>&#171; New Personality &#187;</empty>
				<font>sheettext_npc</font>
			</stringfield>
			<tokenfield name="token">
				<bounds>13,25,25,25</bounds>
				<empty>indicator_emptytoken</empty>
			</tokenfield>
			<buttoncontrol>
				<bounds>-36,27,23,22</bounds>
				<icon>
					<normal>button_identityactivate</normal>
					<pressed>button_identityactivate_down</pressed>
				</icon>
				<script>
					function onButtonPress()
						GmIdentityManager.addIdentity(window.name.getValue());
					end
				</script>
			</buttoncontrol>

			<genericcontrol name="tabcontentframe">
				<bounds>10,54,-25,-15</bounds>
				<frame>
					<name>sheetgroup</name>
					<offset>0,1,0,0</offset>
				</frame>
			</genericcontrol>

			<!-- SUBWINDOWS -->
			<subwindow name="description">
				<anchored>
					<to>tabcontentframe</to>
					<position>over</position>
					<offset>-15,-7</offset>
				</anchored>
				<class>npc_description</class>
			</subwindow>
			<subwindow name="combat">
				<anchored>
					<to>tabcontentframe</to>
					<position>over</position>
					<offset>-15,-7</offset>
				</anchored>
				<class>npc_combat</class>
			</subwindow>
			<subwindow name="other">
				<anchored>
					<to>tabcontentframe</to>
					<position>over</position>
					<offset>-15,-7</offset>
				</anchored>
				<class>npc_other</class>
			</subwindow>

			<scrollercontrol name="description_scroller">
				<bounds>-79,-50,45,27</bounds>
				<target>description</target>
				<button>
					<normal>button_scroller</normal>
					<pressed>button_scroller_down</pressed>
				</button>
				<invisible />
			</scrollercontrol>
			<scrollercontrol name="combat_scroller">
				<bounds>-79,-50,45,27</bounds>
				<target>combat</target>
				<button>
					<normal>button_scroller</normal>
					<pressed>button_scroller_down</pressed>
				</button>
				<invisible />
			</scrollercontrol>
			<scrollercontrol name="other_scroller">
				<bounds>-79,-50,45,27</bounds>
				<target>other</target>
				<button>
					<normal>button_scroller</normal>
					<pressed>button_scroller_down</pressed>
				</button>
				<invisible />
			</scrollercontrol>

			<tabcontrol name="tabs">
				<bounds>-22,50,18,223</bounds>
				<tab>
					<icon>tab_main</icon>
					<subwindow>description</subwindow>
					<scroller>description_scroller</scroller>
				</tab>
				<tab>
					<icon>tab_combat</icon>
					<subwindow>combat</subwindow>
					<scroller>combat_scroller</scroller>
				</tab>
				<tab>
					<icon>tab_other</icon>
					<subwindow>other</subwindow>
					<scroller>other_scroller</scroller>
				</tab>
				<activate>2</activate>
			</tabcontrol>
		</sheetdata>
	</windowclass>

	<windowclass name="npcsmall">
		<sizelimits>
			<minimum>
				<height>10</height>
			</minimum>
		</sizelimits>
		<sheetdata>
			<windowreferencecontrol name="open">
				<bounds>0,0,20,20</bounds>
				<icon>
					<normal>button_openwindow</normal>
					<pressed>button_emptytarget</pressed>
				</icon>
				<class>npc</class>
				<description>
					<field>name</field>
				</description>
			</windowreferencecontrol>
			<linkstringfield name="name">
				<bounds>25,1,-1,20</bounds>
				<empty>&#171; New Personality &#187;</empty>
				<selectioncolor>#90ffffff</selectioncolor>
				<font>sheettext_npc</font>
				<linktarget>open</linktarget>
			</linkstringfield>
		</sheetdata>
	</windowclass>

	<windowclass name="npclist">
		<frame>scrollboxfortabs</frame>
		<softclose />
		<placement>
			<size>
				<width>275</width>
				<height>350</height>
			</size>
		</placement>
		<sizelimits>
			<dynamic />
			<minimum>
				<width>200</width>
				<height>290</height>
			</minimum>
		</sizelimits>
		<nodelete />
		<sheetdata>
			<genericcontrol>
				<bounds>16,21,30,157</bounds>
				<icon>title_npcs</icon>
			</genericcontrol>
			<windowlist name="list">
				<bounds>50,25,-30,-34</bounds>
				<datasource>.</datasource>
				<class>npcsmall</class>
				<sortfields>name</sortfields>
				<footer>footer_narrow</footer>
				<allowcreate />
				<allowdelete />
				<acceptdrop>
					<class>npc</class>
					<field>name</field>
					<field>text</field>
					<field>hd</field>
					<field>hp</field>
					<field>mas</field>
					<field>init</field>
					<field>speed</field>
					<field>ac</field>
					<field>babgrp</field>
					<field>atk</field>
					<field>fullatk</field>
					<field>spacereach</field>
					<field>specialattacks</field>
					<field>specialqualities</field>
					<field>strength</field>
					<field>dexterity</field>
					<field>constitution</field>
					<field>intelligence</field>
					<field>wisdom</field>
					<field>charisma</field>
					<field>fortitudesave</field>
					<field>reflexsave</field>
					<field>willsave</field>
					<field>type</field>
					<field>skills</field>
					<field>feats</field>
					<field>environment</field>
					<field>organization</field>
					<field>cr</field>
					<field>treasure</field>
					<field>alignment</field>
					<field>advancement</field>
					<field>leveladjustment</field>
				</acceptdrop>
				<script>
					function onSortCompare(w1, w2)
						return w1.name.getValue() &gt; w2.name.getValue();
					end;
					
					function onFilter(w)
						local f = string.lower(window.filter.getValue());
						
						if f == "" then
							return true;
						end
						
						if string.find(string.lower(w.name.getValue()), f, 0, true) then
							return true;
						end
						
						return false;
					end
				</script>
			</windowlist>
			<scrollercontrol>
				<bounds>-105,-61,45,27</bounds>
				<target>list</target>
				<button>
					<normal>button_scroller</normal>
					<pressed>button_scroller_down</pressed>
				</button>
			</scrollercontrol>

			<buttoncontrol>
				<bounds>-55,-58,34,25</bounds>
				<icon>
					<normal>button_newwindow</normal>
					<pressed>button_newwindowdown</pressed>
				</icon>
				<class>npc</class>
				<script>
					function onButtonPress()
						local node = window.getDatabaseNode();
						if node then
							node = node.createChild();
							if node then
								Interface.openWindow(class[1], node.getNodeName());
							end
						end
					end
				</script>
			</buttoncontrol>
			<categoryselectioncontrol>
				<bounds>24,-39,-24,-1</bounds>
				<targetcontrol>list</targetcontrol>
			</categoryselectioncontrol>

			<filter name="filter">
				<bounds>55,-70,-50,20</bounds>
				<target>list</target>
				<trigger>filtertrigger</trigger>
			</filter>
			<filtertrigger name="filtertrigger">
				<bounds>20,-85,21,41</bounds>
				<target>filter</target>
			</filtertrigger>			
		</sheetdata>
	</windowclass>
</root>
