<?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="combattrackerffsource">
		<genericcontrol>
			<script>
				function onInit()
					setHoverCursor("hand");
				end
			
				function onDrag(button, x, y, draginfo)
					draginfo.setType("combattrackerff");

					draginfo.setIcon(icon[1]);
					draginfo.setStringData(value[1]);

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

	<windowclass name="combattracker_effect">
		<sizelimits>
			<minimum>
				<height>22</height>
			</minimum>
		</sizelimits>
		<playercontrol />
		<script file="scripts/combattracker_effectitem.lua" />
		<sheetdata>
			<jpglistitemlabel name="label">
				<bounds>0,4,75,17</bounds>
				<stateframe>
					<drophilight>
						<name>sheetfocus</name>
						<offset>5,4,5,4</offset>
					</drophilight>
				</stateframe>
				<droptypes>
					<type>combattrackerentry</type>
				</droptypes>
				<tabtarget>
					<next>duration</next>
					<prev>adjustment</prev>
				</tabtarget>
				<script>
					function onDrag(button, x, y, draginfo)
						return window.onDrag(button, x, y, draginfo);
					end

					function onDrop(x, y, draginfo)
						return window.onDrop(x, y, draginfo);
					end

					function onGainFocus()
						if getValue() == "" then
							wasempty = true;
						else
							wasempty = false;
						end
					end
					
					function onValueChanged()
						if wasempty then
							casterentry = window.windowlist.window.windowlist.getActiveEntry();
							if casterentry then
								window.caster.setSource(casterentry);
							end
							
							wasempty = false;
						end
					end
				</script>
			</jpglistitemlabel>
			
			<jpgnumberfield name="duration">
				<anchored>
					<left>
						<parent>label</parent>
						<anchor>right</anchor>
					</left>
					<top>
						<anchor>top</anchor>
					</top>
					<size>
						<width>30</width>
						<height>22</height>
					</size>
				</anchored>
				<font>sheetnumbersmall</font>
				<frame>
					<name>bonus</name>
					<offset>2,2,2,1</offset>
				</frame>
				<keyeditframe>
					<name>sheetfocus</name>
					<offset>2,2,2,2</offset>
				</keyeditframe>
				<droptypes>
					<type>number</type>
				</droptypes>
				<tabtarget>
					<next>adjustment</next>
					<prev>label</prev>
				</tabtarget>
				<script>
					function onDrag(button, x, y, draginfo)
						return window.onDrag(button, x, y, draginfo);
					end

					function onDrop(x, y, draginfo)
						if draginfo.getType() ~= "number" then
							return window.onDrop(x, y, draginfo);
						end
					end
				</script>
			</jpgnumberfield>
			<jpgnumberfield name="adjustment">
				<anchored>
					<left>
						<parent>duration</parent>
						<anchor>right</anchor>
					</left>
					<top>
						<anchor>top</anchor>
					</top>
					<size>
						<width>30</width>
						<height>22</height>
					</size>
				</anchored>
				<font>sheetnumbersmall</font>
				<hideonvalue>0</hideonvalue>
				<displaysign />
				<frame>
					<name>durationadjustment</name>
					<offset>2,2,2,2</offset>
				</frame>
				<keyeditframe>
					<name>sheetfocus</name>
					<offset>2,2,2,2</offset>
				</keyeditframe>
				<droptypes>
					<type>combattrackerentry</type>
				</droptypes>
				<stateframe>
					<drophilight>
						<name>sheetfocus</name>
						<offset>2,2,2,2</offset>
					</drophilight>
				</stateframe>
				<droptypes>
					<type>number</type>
				</droptypes>
				<tabtarget>
					<next>label</next>
					<prev>duration</prev>
				</tabtarget>
				<script>
					function onValueChanged()
						window.caster.updateVisibility();
					end
					
					function onDrag(button, x, y, draginfo)
						return window.onDrag(button, x, y, draginfo);
					end

					function onDrop(x, y, draginfo)
						if draginfo.getType() ~= "number" then
							return window.onDrop(x, y, draginfo);
						end
					end
				</script>
			</jpgnumberfield>

			<stringfield name="caster_ref_node">
				<invisible />
				<bounds>0,0,1,1</bounds>
				<script>
					function onValueChanged()
						window.caster.update();
					end
				</script>
			</stringfield>
			<stringfield name="caster">
				<anchored>
					<right>
						<parent>adjustment</parent>
						<anchor>right</anchor>
						<offset>-5</offset>
					</right>
					<top>
						<parent>duration</parent>
						<anchor>bottom</anchor>
					</top>
					<size>
						<height>12</height>
					</size>
				</anchored>
				<center />
				<static />
				<font>sheetlabelsmall</font>
				<color>#7f000000</color>
				<empty>&#171; unnamed &#187;</empty>
				<invisible />
				<script>
					function onDrag(button, x, y, draginfo)
						return window.onDrag(button, x, y, draginfo);
					end

					function onDrop(x, y, draginfo)
						return window.onDrop(x, y, draginfo);
					end

					function onClickDown(button, x, y)
						if button == 2 then
							setSource(nil);
						end
					end
					
					function updateVisibility()
						if sourceentry and window.adjustment.getValue() ~= 0 then
							setVisible(true);
						else
							setVisible(false);
						end
					end
				
					function update()
						if sourceentry then
							sourceentry.removeObserver(self);
							sourceentry = nil;
						end
					
						local caster_nodename = window.caster_ref_node.getValue();
						if caster_nodename ~= "" then
							local ctchildren = window.windowlist.window.windowlist.getWindows();
							for k,v in pairs(ctchildren) do
								if v.getDatabaseNode().getNodeName() == caster_nodename then
									sourceentry = v;
								end
							end
						end
						
						if sourceentry then
							sourceentry.addObserver(self);
							observedNameChanged(self);
						end
						
						updateVisibility();
					end
					
					function getSource()
						return sourceentry;
					end
				
					function setSource(entry)
						if entry then
							window.caster_ref_node.setValue(entry.getDatabaseNode().getNodeName());
						else
							window.caster_ref_node.setValue("");
						end
					end
					
					function observedNameChanged(source)
						setValue("Update on: " .. sourceentry.name.getValue());
					end
					
					function observedClosed(source)
						if source == sourceentry then
							sourceentry = nil;
							setValue("");
							updateVisibility();
						end
					end
				</script>
			</stringfield>
		</sheetdata>
	</windowclass>

	<windowclass name="combattracker_entry">
		<datasource>combattracker</datasource>
		<frame>ctentrybox</frame>
		<sizelimits>
			<minimum>
				<height>40</height>
			</minimum>
		</sizelimits>
		<script file="scripts/combattracker_entry.lua" />
		<sheetdata>
			<!-- Hidden fields -->
			<stringfield name="type">
				<invisible />
				<bounds>0,0,1,1</bounds>
				<script>
					function onInit()
						if User.isHost() and getValue() == "" then
							setValue("npc");
						else
							window.onTypeChanged();
						end
					end
					
					function onValueChanged()
						window.onTypeChanged();
					end
				</script>
			</stringfield>
			<stringfield name="tokenrefid">
				<invisible />
				<bounds>0,0,1,1</bounds>
			</stringfield>
			<stringfield name="tokenrefnode">
				<invisible />
				<bounds>0,0,1,1</bounds>
			</stringfield>
			<stringfield name="status">
				<invisible />
				<bounds>0,0,1,1</bounds>
				<script file="scripts/combattracker_status.lua" />
			</stringfield>
			
			<!-- Basics -->
			<tokenfield name="token">
				<bounds>33,6,23,23</bounds>
				<empty>indicator_emptytoken</empty>
				<script file="scripts/combattracker_token.lua" />
			</tokenfield>
			
			<ctnumberfield name="initresult">
				<anchored>
					<position>righthigh</position>
					<offset>-363,7</offset>
					<size>
						<width>34</width>
						<height>23</height>
					</size>
				</anchored>
				<hideonvalue>0</hideonvalue>
				<script>
					function update()
						window.windowlist.applySort();
					end
				</script>
			</ctnumberfield>
			<ctstringfield name="name">
				<anchored>
					<to>token</to>
					<position>righthigh</position>
					<offset>1,5</offset>
					<right>
						<parent>initresult</parent>
						<anchor>left</anchor>
						<offset>-4,0</offset>
					</right>
				</anchored>
				<script>
					function update()
						window.token.setName(getValue());
					end
					
					function onDrag(button, x, y, draginfo)
						draginfo.setType("combattrackerentry");
						draginfo.setStringData(getValue());
						draginfo.setCustomData(window);
						return true;
					end
					
					function onInit()
						super.onInit();
						setHoverCursor("hand");
					end
				</script>
			</ctstringfield>
			
			<ctnumberfield name="hp">
				<anchored>
					<to>initresult</to>
					<position>right</position>
					<offset>5,0</offset>
					<size>
						<width>34</width>
					</size>
				</anchored>
				<script>
					function update()
						window.onWoundsChanged();
					end
				</script>
			</ctnumberfield>
			<ctnumberfield name="wounds">
				<anchored>
					<to>hp</to>
					<position>right</position>
					<offset>0,0</offset>
					<size>
						<width>34</width>
					</size>
				</anchored>
				<hideonvalue value="0" />
				<script>
					function handleDrop(draginfo)
						if draginfo.getType() == "number" then
							setValue(getValue() + draginfo.getNumberData());
							return true;
						end
					end

					function update()
						window.onWoundsChanged();
					end
				</script>
			</ctnumberfield>
			
			<ctnumberfield name="space">
				<anchored>
					<to>wounds</to>
					<position>right</position>
					<offset>28,0</offset>
					<size>
						<width>34</width>
					</size>
				</anchored>
				<hideonvalue value="0" />
				<script>
					function onInit()
						if getValue() == 0 then
							setValue(5);
						end

						super.onInit();
					end
					
					function onValueChanged()
						window.token.updateUnderlay();
					end
				</script>
			</ctnumberfield>
			<ctnumberfield name="reach">
				<anchored>
					<to>space</to>
					<position>right</position>
					<offset>25,0</offset>
					<size>
						<width>34</width>
					</size>
				</anchored>
				<hideonvalue value="0" />
				<script>
					function onInit()
						if getValue() == 0 then
							setValue(5);
						end

						super.onInit();
					end
					
					function onValueChanged()
						window.token.updateUnderlay();
					end
				</script>
			</ctnumberfield>
			<genericcontrol>
				<anchored>
					<to>space</to>
					<position>left</position>
					<offset>2,0</offset>
					<size>
						<width>18</width>
					</size>
				</anchored>
				<icon>indicator_space</icon>
			</genericcontrol>
			<genericcontrol>
				<anchored>
					<to>reach</to>
					<position>left</position>
					<offset>2,0</offset>
					<size>
						<width>18</width>
					</size>
				</anchored>
				<icon>indicator_reach</icon>
			</genericcontrol>

			<windowreferencefield name="link">
				<anchored>
					<right>
						<anchor>right</anchor>
						<offset>-6</offset>
					</right>
					<top>
						<anchor>top</anchor>
						<offset>7</offset>
					</top>
					<size>
						<width>20</width>
						<height>20</height>
					</size>
				</anchored>
				<icon>
					<normal>button_dragtarget</normal>
				</icon>
				<invisible />
				<script>
					function onInit()
						if getValue() then
							setVisible(true);
						end
					end
				</script>
			</windowreferencefield>
			<button_toggle name="activateeffects">
				<anchored>
					<right>
						<anchor>right</anchor>
						<offset>-29</offset>
					</right>
					<top>
						<parent>link</parent>
						<anchor>top</anchor>
					</top>
					<size>
						<width>20</width>
						<height>21</height>
					</size>
				</anchored>
				<icon>indicator_effect</icon>
				<script>
					function onValueChanged()
						window.windowlist.onEntrySectionToggle();
					end

					function onHover(oncontrol)
						window.setEffectsVisible(oncontrol);
					end
				</script>
			</button_toggle>
			<button_toggle name="activateactive">
				<anchored>
					<right>
						<parent>activateeffects</parent>
						<anchor>left</anchor>
					</right>
					<top>
						<parent>link</parent>
						<anchor>top</anchor>
					</top>
					<size>
						<width>20</width>
						<height>21</height>
					</size>
				</anchored>
				<icon>indicator_sword</icon>
				<script>
					function onValueChanged()
						window.windowlist.onEntrySectionToggle();
					end

					function onHover(oncontrol)
						window.setActiveVisible(oncontrol);
					end
				</script>
			</button_toggle>
			<button_toggle name="activatedefensive">
				<anchored>
					<right>
						<parent>activateactive</parent>
						<anchor>left</anchor>
					</right>
					<top>
						<parent>link</parent>
						<anchor>top</anchor>
					</top>
					<size>
						<width>20</width>
						<height>21</height>
					</size>
				</anchored>
				<icon>indicator_shield</icon>
				<script>
					function onValueChanged()
						window.windowlist.onEntrySectionToggle();
					end

					function onHover(oncontrol)
						window.setDefensiveVisible(oncontrol);
					end
				</script>
			</button_toggle>

			<iconcycler name="friendfoe">
				<anchored>
					<right>
						<parent>activatedefensive</parent>
						<anchor>left</anchor>
						<offset>-8</offset>
					</right>
					<top>
						<parent>link</parent>
						<anchor>top</anchor>
						<offset>1</offset>
					</top>
					<size>
						<width>20</width>
						<height>20</height>
					</size>
				</anchored>
				<sourcefields>
					<icons>indicator_ctfffriend|indicator_ctffneutral|indicator_ctfffoe</icons>
					<values>friend|neutral|foe</values>
					<tooltips>Friend|Neutral|Foe</tooltips>
					<srcnode>friendfoe</srcnode>
					<defaulticon>indicator_ctffempty</defaulticon>
				</sourcefields>
				<gmonly />
				<script>
					function onValueChanged()
						window.onFOFChanged();
					end
					
					function onDrop(x, y, draginfo)
						if draginfo.isType("combattrackerff") then
							setSourceValue(draginfo.getStringData());
						end
					end
				</script>
			</iconcycler>

			<checkbox name="show_npc">
				<anchored>
					<right>
						<parent>friendfoe</parent>
						<anchor>left</anchor>
						<offset>0</offset>
					</right>
					<top>
						<anchor>top</anchor>
						<offset>7</offset>
					</top>
					<size>
						<width>20</width>
						<height>20</height>
					</size>
				</anchored>
				<tooltip>
					<text>Show NPC</text>
				</tooltip>
				<invisible/>
			</checkbox>

			<!-- Defensive -->
			<genericcontrol name="defensiveicon">
				<anchored>
					<left>
						<anchor>left</anchor>
						<offset>48</offset>
					</left>
					<top>
						<parent>name</parent>
						<anchor>bottom</anchor>
						<relation>current</relation>
					</top>
					<size>
						<width>20</width>
						<height>21</height>
					</size>
				</anchored>
				<icon>indicator_shield</icon>
			</genericcontrol>

			<genericcontrol name="targeting">
				<anchored>
					<right>
						<anchor>right</anchor>
						<offset>-6</offset>
					</right>
					<top>
						<parent>name</parent>
						<anchor>bottom</anchor>
						<relation>current</relation>
					</top>
					<size>
						<width>100</width>
						<height>20</height>
					</size>
				</anchored>
				<iconspacing>21</iconspacing>
				<script file="scripts/combattracker_targeting.lua" />
			</genericcontrol>

			<ctnumberfield name="willsave">
				<anchored>
					<right>
						<parent>targeting</parent>
						<anchor>left</anchor>
						<offset>-5</offset>
					</right>
					<top>
						<parent>name</parent>
						<anchor>bottom</anchor>
						<relation>current</relation>
					</top>
					<size>
						<width>25</width>
						<height>15</height>
					</size>
				</anchored>
				<displaysign />
				<frame>
					<name>textlinesmall</name>
					<offset>0,-1,0,0</offset>
				</frame>
				<keyeditframe>
					<name>sheetfocus</name>
					<offset>5,5,5,5</offset>
				</keyeditframe>
				<description>
					<text>Will save</text>
				</description>
				<script>
					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("npc", window.getDatabaseNode().getNodeName());
						
						return true;
					end

					function onDoubleClick(x,y)	
						ChatManager.DoubleClickNPC("save", getValue(), self.description[1].text[1], {npc = window.getDatabaseNode()});
					end
				</script>
			</ctnumberfield>
			<stringcontrol name="willsavelabel">
				<anchored>
					<right>
						<parent>willsave</parent>
						<anchor>left</anchor>
						<offset>-3</offset>
					</right>
					<top>
						<parent>willsave</parent>
						<anchor>top</anchor>
						<offset>3</offset>
					</top>
				</anchored>
				<font>sheetlabelsmall</font>
				<static>W</static>
			</stringcontrol>
			<ctnumberfield name="reflexsave">
				<anchored>
					<right>
						<parent>willsavelabel</parent>
						<anchor>left</anchor>
						<offset>-5</offset>
					</right>
					<top>
						<parent>name</parent>
						<anchor>bottom</anchor>
						<relation>current</relation>
					</top>
					<size>
						<width>25</width>
						<height>15</height>
					</size>
				</anchored>
				<displaysign />
				<frame>
					<name>textlinesmall</name>
					<offset>0,-1,0,0</offset>
				</frame>
				<keyeditframe>
					<name>sheetfocus</name>
					<offset>5,5,5,5</offset>
				</keyeditframe>
				<description>
					<text>Reflex save</text>
				</description>
				<script>
					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("npc", window.getDatabaseNode().getNodeName());
						
						return true;
					end

					function onDoubleClick(x,y)	
						ChatManager.DoubleClickNPC("save", getValue(), self.description[1].text[1], {npc = window.getDatabaseNode()});
					end
				</script>
			</ctnumberfield>
			<stringcontrol name="reflexsavelabel">
				<anchored>
					<right>
						<parent>reflexsave</parent>
						<anchor>left</anchor>
						<offset>-3</offset>
					</right>
					<top>
						<parent>willsave</parent>
						<anchor>top</anchor>
						<offset>3</offset>
					</top>
				</anchored>
				<font>sheetlabelsmall</font>
				<static>R</static>
			</stringcontrol>
			<ctnumberfield name="fortitudesave">
				<anchored>
					<right>
						<parent>reflexsavelabel</parent>
						<anchor>left</anchor>
						<offset>-5</offset>
					</right>
					<top>
						<parent>name</parent>
						<anchor>bottom</anchor>
						<relation>current</relation>
					</top>
					<size>
						<width>25</width>
						<height>15</height>
					</size>
				</anchored>
				<displaysign />
				<frame>
					<name>textlinesmall</name>
					<offset>0,-1,0,0</offset>
				</frame>
				<keyeditframe>
					<name>sheetfocus</name>
					<offset>5,5,5,5</offset>
				</keyeditframe>
				<description>
					<text>Fortitude save</text>
				</description>
				<script>
					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("npc", window.getDatabaseNode().getNodeName());
						
						return true;
					end

					function onDoubleClick(x,y)	
						ChatManager.DoubleClickNPC("save", getValue(), self.description[1].text[1], {npc = window.getDatabaseNode()});
					end
				</script>
			</ctnumberfield>
			<stringcontrol name="fortitudesavelabel">
				<anchored>
					<right>
						<parent>fortitudesave</parent>
						<anchor>left</anchor>
						<offset>-3</offset>
					</right>
					<top>
						<parent>willsave</parent>
						<anchor>top</anchor>
						<offset>3</offset>
					</top>
				</anchored>
				<font>sheetlabelsmall</font>
				<static>F</static>
			</stringcontrol>

			<stringfield name="ac">
				<anchored>
					<left>
						<parent>name</parent>
						<anchor>left</anchor>
						<offset>35</offset>
					</left>
					<right>
						<parent>fortitudesavelabel</parent>
						<anchor>left</anchor>
						<offset>-8</offset>
					</right>
					<top>
						<parent>name</parent>
						<anchor>bottom</anchor>
						<relation>relative</relation>
					</top>
				</anchored>
				<font>sheettextsmall</font>
				<frame>
					<name>textlinesmall</name>
					<offset>0,-1,0,0</offset>
				</frame>
				<multilinespacing>14</multilinespacing>
				<script>
					function onLinkUpdated()
						local value = "";
					
						if acnode then
							value = value .. acnode.getValue();
						end
						if touchnode then
							value = value .. ", touch " .. touchnode.getValue();
						end
						if flatfootednode then
							value = value .. ", flatfooted " .. flatfootednode.getValue();
						end
						
						setValue(value);
					end
					
					function setLink(ac, touch, flatfooted)
						if ac and touch and flatfooted then
							acnode = ac;
							touchnode = touch;
							flatfootednode = flatfooted;

							acnode.onUpdate = onLinkUpdated;
							touchnode.onUpdate = onLinkUpdated;
							flatfootednode.onUpdate = onLinkUpdated;

							addBitmapWidget("indicator_linked").setPosition("bottomright", -5, -5);

							setReadOnly(true);
							setFrame(nil);

							onLinkUpdated();
						end
					end
				</script>
			</stringfield>
			<stringcontrol name="aclabel">
				<anchored>
					<left>
						<parent>name</parent>
						<anchor>left</anchor>
						<offset>10</offset>
					</left>
					<top>
						<parent>ac</parent>
						<anchor>top</anchor>
						<offset>4</offset>
					</top>
				</anchored>
				<font>sheetlabelsmall</font>
				<static>AC</static>
			</stringcontrol>

			<!-- Active -->
			<genericcontrol name="activeicon">
				<anchored>
					<left>
						<anchor>left</anchor>
						<offset>48</offset>
					</left>
					<top>
						<parent>name</parent>
						<anchor>bottom</anchor>
						<relation>current</relation>
					</top>
					<size>
						<width>20</width>
						<height>21</height>
					</size>
				</anchored>
				<icon>indicator_sword</icon>
			</genericcontrol>

			<ctstringfield name="speed">
				<anchored>
					<left>
						<parent>name</parent>
						<anchor>left</anchor>
						<offset>35</offset>
					</left>
					<top>
						<parent>name</parent>
						<anchor>bottom</anchor>
						<relation>current</relation>
					</top>
					<size>
						<width>40</width>
						<height>17</height>
					</size>
				</anchored>
			</ctstringfield>
			<stringcontrol name="speedlabel">
				<anchored>
					<left>
						<parent>name</parent>
						<anchor>left</anchor>
						<offset>10</offset>
					</left>
					<top>
						<parent>speed</parent>
						<anchor>top</anchor>
						<offset>4</offset>
					</top>
				</anchored>
				<font>sheetlabelsmall</font>
				<static>Spd</static>
			</stringcontrol>

			<ctstringfield name="atk">
				<anchored>
					<left>
						<parent>name</parent>
						<anchor>left</anchor>
						<offset>122</offset>
					</left>
					<right>
						<anchor>right</anchor>
						<offset>-7</offset>
					</right>
					<top>
						<parent>name</parent>
						<anchor>bottom</anchor>
						<relation>relative</relation>
					</top>
				</anchored>
				<multilinespacing>14</multilinespacing>
				<script file="scripts/npcattackfield.lua" />
			</ctstringfield>
			<stringcontrol name="atklabel">
				<anchored>
					<left>
						<parent>name</parent>
						<anchor>left</anchor>
						<offset>82</offset>
					</left>
					<top>
						<parent>atk</parent>
						<anchor>top</anchor>
						<offset>4</offset>
					</top>
				</anchored>
				<font>sheetlabelsmall</font>
				<static>Atk</static>
			</stringcontrol>

			<ctstringfield name="fullatk">
				<anchored>
					<left>
						<parent>name</parent>
						<anchor>left</anchor>
						<offset>122</offset>
					</left>
					<right>
						<anchor>right</anchor>
						<offset>-7</offset>
					</right>
					<top>
						<parent>name</parent>
						<anchor>bottom</anchor>
						<relation>relative</relation>
					</top>
				</anchored>
				<multilinespacing>14</multilinespacing>
				<script file="scripts/npcattackfield.lua" />
			</ctstringfield>
			<stringcontrol name="fullatklabel">
				<anchored>
					<left>
						<parent>name</parent>
						<anchor>left</anchor>
						<offset>82</offset>
					</left>
					<top>
						<parent>fullatk</parent>
						<anchor>top</anchor>
						<offset>4</offset>
					</top>
				</anchored>
				<font>sheetlabelsmall</font>
				<static>Full atk</static>
			</stringcontrol>

			<ctnumberfield name="init">
				<anchored>
					<left>
						<parent>name</parent>
						<anchor>left</anchor>
						<offset>35</offset>
					</left>
					<top>
						<parent>speed</parent>
						<anchor>bottom</anchor>
						<offset>1</offset>
					</top>
					<size>
						<width>40</width>
						<height>15</height>
					</size>
				</anchored>
				<displaysign />
				<frame>
					<name>textlinesmall</name>
					<offset>0,-1,0,0</offset>
				</frame>
				<keyeditframe>
					<name>sheetfocus</name>
					<offset>5,5,5,5</offset>
				</keyeditframe>
				<description>
					<text>Initiative</text>
				</description>
				<script>
					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("Initiative");
						draginfo.setNumberData(getValue());
						draginfo.setShortcutData("npc", window.getDatabaseNode().getNodeName());
						
						return true;
					end

					function onDoubleClick(x,y)	
						ChatManager.DoubleClickNPC("init", getValue(), "Initiative", {npc = window.getDatabaseNode()});
					end
				</script>
			</ctnumberfield>
			<stringcontrol name="initlabel">
				<anchored>
					<left>
						<parent>name</parent>
						<anchor>left</anchor>
						<offset>10</offset>
					</left>
					<top>
						<parent>init</parent>
						<anchor>top</anchor>
						<offset>4</offset>
					</top>
				</anchored>
				<font>sheetlabelsmall</font>
				<static>Init</static>
			</stringcontrol>

			<!-- Effects -->
			<genericcontrol name="effecticon">
				<anchored>
					<left>
						<anchor>left</anchor>
						<offset>48</offset>
					</left>
					<top>
						<parent>name</parent>
						<anchor>bottom</anchor>
						<relation>current</relation>
					</top>
					<size>
						<width>20</width>
						<height>21</height>
					</size>
				</anchored>
				<icon>indicator_effect</icon>
			</genericcontrol>

			<jpglist name="effects">
				<anchored>
					<left>
						<parent>effecticon</parent>
						<anchor>right</anchor>
						<offset>8</offset>
					</left>
					<right>
						<anchor>right</anchor>
						<offset>-12</offset>
					</right>
					<top>
						<parent>name</parent>
						<anchor>bottom</anchor>
						<relation>relative</relation>
						<offset>8</offset>
					</top>
				</anchored>
				<datasource>.effects</datasource>
				<class>combattracker_effect</class>
				<menutext>Effect</menutext>
				<frame>
					<name>modifier</name>
					<offset>8,8,8,8</offset>
				</frame>
				<columns>
					<width>144</width>
					<fillwidth />
				</columns>
				<script file="scripts/combattracker_effects.lua" />
			</jpglist>

			<!-- Spacer -->
			<genericcontrol name="spacer">
				<anchored>
					<top>
						<parent>name</parent>
						<anchor>bottom</anchor>
						<relation>current</relation>
					</top>
					<left>
						<anchor>left</anchor>
					</left>
					<right>
						<anchor>right</anchor>
					</right>
					<size>
						<height>10</height>
					</size>
				</anchored>
				<invisible />
				<disabled />
			</genericcontrol>

			<genericcontrol name="active">
				<anchored>
					<top>
						<anchor>top</anchor>
					</top>
					<bottom>
						<anchor>bottom</anchor>
					</bottom>
					<left>
						<anchor>left</anchor>
					</left>
					<size>
						<width>33</width>
					</size>
				</anchored>
				<icon>indicator_ctpassive</icon>
				<activeicon>indicator_ctactive</activeicon>
				<script file="scripts/combattracker_active.lua" />
			</genericcontrol>
		</sheetdata>
	</windowclass>

	<windowclass name="combattracker_window">
		<frame>ctbox</frame>
		<placement>
			<size>
				<width>534</width>
				<height>512</height>
			</size>
		</placement>
		<sizelimits>
			<minimum>
				<width>534</width>
				<height>210</height>
			</minimum>
			<dynamic>
				<resize>both</resize>
			</dynamic>
		</sizelimits>
		<nodelete />
		<sheetdata>
			<stringcontrol>
				<bounds>60,15,30,10</bounds>
				<font>sheetlabelsmall</font>
				<color>#ffffffff</color>
				<static>Name</static>
			</stringcontrol>
			<stringcontrol>
				<anchored>
					<position>right</position>
					<offset>-374,-15</offset>
				</anchored>
				<font>sheetlabelsmall</font>
				<color>#ffffffff</color>
				<static>Init</static>
			</stringcontrol>
			<stringcontrol>
				<anchored>
					<position>right</position>
					<offset>-334,-15</offset>
				</anchored>
				<font>sheetlabelsmall</font>
				<color>#ffffffff</color>
				<static>HP</static>
			</stringcontrol>
			<stringcontrol>
				<anchored>
					<position>right</position>
					<offset>-310,-15</offset>
				</anchored>
				<font>sheetlabelsmall</font>
				<color>#ffffffff</color>
				<static>Wounds</static>
			</stringcontrol>

			<genericcontrol name="button_global_frame">
				<bounds>-120,3,80,30</bounds>
				<frame>
					<name>sheetgroup</name>
				</frame>
			</genericcontrol>
			
			<button_toggle name="button_global_defensive">
				<anchored>
					<right>
						<anchor>right</anchor>
						<offset>-90</offset>
					</right>
					<top>
						<anchor>top</anchor>
						<offset>8</offset>
					</top>
					<size>
						<width>20</width>
						<height>21</height>
					</size>
				</anchored>
				<icon>indicator_shield</icon>
				<script>
					function onValueChanged()
						window.list.toggleDefensive();
					end
				</script>
			</button_toggle>
			<button_toggle name="button_global_active">
				<anchored>
					<to>button_global_defensive</to>
					<position>right</position>
					<offset>0,0</offset>
					<size>
						<width>20</width>
					</size>
				</anchored>
				<icon>indicator_sword</icon>
				<script>
					function onValueChanged()
						window.list.toggleActive();
					end
				</script>
			</button_toggle>
			<button_toggle name="button_global_effects">
				<anchored>
					<to>button_global_active</to>
					<position>right</position>
					<offset>0,0</offset>
					<size>
						<width>20</width>
					</size>
				</anchored>
				<icon>indicator_effect</icon>
				<script>
					function onValueChanged()
						window.list.toggleEffects();
					end
				</script>
			</button_toggle>
				
			<windowlist name="list">
				<datasource>.</datasource>
				<class>combattracker_entry</class>
				<skipempty />
				<bounds>0,30,-20,-50</bounds>

				<acceptdrop class="mini_charsheet" fields="name,#hp,#wounds" />
				<acceptdrop class="charsheet" fields="name,#hp,#wounds" />
				<acceptdrop class="npc" fields="name,hp" />
				<acceptdrop class="monster" fields="name,hp" />
				
				<script file="scripts/combattracker.lua" />
			</windowlist>

			<scrollercontrol>
				<anchored>
					<to>list</to>
					<position>insidebottomright</position>
					<size>
						<width>45</width>
						<height>27</height>
					</size>
				</anchored>
				<target>list</target>
				<button>
					<normal>button_scroller</normal>
					<pressed>button_scroller_down</pressed>
				</button>
			</scrollercontrol>
			
			<genericcontrol>
				<bounds>28,-53,33,40</bounds>
				<activeicon>indicator_ctactive</activeicon>
				<script>
					function onInit()
						widget = addBitmapWidget(activeicon[1]);
						setHoverCursor("hand");
					end
					
					function onDrag(button, x, y, draginfo)
						draginfo.setType("combattrackeractivation");
						draginfo.setIcon(activeicon[1]);
						widget.setVisible(false);
						
						return true;
					end
					
					function onDragEnd(draginfo)
						widget.setVisible(true);
					end
				</script>
			</genericcontrol>
			<buttoncontrol>
				<bounds>62,-45,33,26</bounds>
				<icon>
					<normal>button_ctnextactor</normal>
					<pressed>button_ctnextactor_down</pressed>
				</icon>
				<tooltip>
					<text>Next actor</text>
				</tooltip>
				<script>
					function onButtonPress()
						window.list.nextActor();
					end
					
					function onDrag(button, x, y, draginfo)
						draginfo.setType("combattrackernextactor");
						draginfo.setIcon(icon[1].normal[1]);
						return true;
					end
				</script>
			</buttoncontrol>

			<combattrackerffsource>
				<bounds>200,-43,20,20</bounds>
				<icon>indicator_ctfffriend</icon>
				<value>friend</value>
				<tooltip>
					<text>Friendly</text>
				</tooltip>
			</combattrackerffsource>
			<combattrackerffsource>
				<bounds>227,-43,20,20</bounds>
				<icon>indicator_ctffneutral</icon>
				<value>neutral</value>
				<tooltip>
					<text>Neutral</text>
				</tooltip>
			</combattrackerffsource>
			<combattrackerffsource>
				<bounds>254,-43,20,20</bounds>
				<icon>indicator_ctfffoe</icon>
				<value>foe</value>
				<tooltip>
					<text>Hostile</text>
				</tooltip>
			</combattrackerffsource>
			
			<buttoncontrol name="button_menu">
				<bounds>-210,-40,40,15</bounds>
				<icon>
					<normal>button_menu</normal>
					<pressed>button_menu_down</pressed>
				</icon>
				<tooltip>
					<text>Right click for CT menu</text>
				</tooltip>
				<script>
					function onInit()
						if User.isHost() then
							registerMenuItem("Initiative", "turn", 7);
							registerMenuItem("Roll All Initiatives", "shuffle", 7, 8);
							registerMenuItem("Roll NPC Initiatives", "mask", 7, 7);
							registerMenuItem("Roll PC Initiatives", "portrait", 7, 6);
							registerMenuItem("Clear All Initiatives", "pointer_circle", 7, 4);

							registerMenuItem("Delete NPCs from tracker", "delete", 3);
							registerMenuItem("Confirm NPC Delete", "delete", 3, 1);

							registerMenuItem("Clear All Effects", "hand", 5);
						end
					end
					
					function onMenuSelection(selection, subselection, subsubselection)
						if User.isHost() then
							if selection == 7 then
								if subselection == 4 then
									window.list.resetInit();
									window.roundcounter.setValue(0);
								elseif subselection == 8 then
									window.list.rollAllInit();
								elseif subselection == 7 then
									window.list.rollNPCInit();
								elseif subselection == 6 then
									window.list.rollPCInit();
								end
							end
							if selection == 5 then
								window.list.resetEffects();
							end
							if selection == 3 then
								if subselection == 1 then
									window.list.deleteNPCs();
								end
							end
						end
					end
				</script>
			</buttoncontrol>

			<stringcontrol name="roundcounterlabel">
				<anchored>
					<right>
						<anchor>right</anchor>
						<offset>-108</offset>
					</right>
					<top>
						<anchor>bottom</anchor>
						<offset>-39</offset>
					</top>
					<size>
						<width>50</width>
						<height>15</height>
					</size>
				</anchored>
				<font>sheetlabel</font>
				<color>#ffffffff</color>
				<static>Round</static>
			</stringcontrol>
			<jpgnumberfield name="roundcounter" source="..combattracker_props.round">
				<anchored>
					<left>
						<parent>roundcounterlabel</parent>
						<anchor>right</anchor>
					</left>
					<top>
						<parent>roundcounterlabel</parent>
						<anchor>top</anchor>
						<offset>-6</offset>
					</top>
					<size>
						<width>40</width>
						<height>25</height>
					</size>
				</anchored>
				<frame>
					<name>modifier</name>
					<offset>3,3,3,3</offset>
				</frame>
				<font>sheetnumber</font>
				<gmonly />
			</jpgnumberfield>
			<buttoncontrol name="advance_round">
				<anchored>
					<to>roundcounter</to>
					<position>righthigh</position>
					<offset>5,0</offset>
					<size>
						<width>33</width>
						<height>26</height>
					</size>
				</anchored>
				<icon>
					<normal>button_ctnextround</normal>
					<pressed>button_ctnextround_down</pressed>
				</icon>
				<tooltip>
					<text>Next round</text>
				</tooltip>
				<script>
					function onButtonPress()
						window.list.nextRound();
					end
					
					function onDrag(button, x, y, draginfo)
						draginfo.setType("combattrackernextround");
						draginfo.setIcon(icon[1].normal[1]);
						return true;
					end
				</script>
			</buttoncontrol>
			
			<closebutton_combattracker />
		</sheetdata>
	</windowclass>
</root>
