<?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">
	<windowclass name="charsheet_skilllistitem">
		<sizelimits>
			<minimum>
				<height>18</height>
			</minimum>
		</sizelimits>
		<script file="scripts/charsheet_skilllistitem.lua" />
		<sheetdata>
			<!-- Hidden values -->
			<numberfield name="armorcheckmultiplier">
				<invisible />
				<bounds>0,0,1,1</bounds>
				<script>
					function onValueChanged()
						window.onCheckPenaltyChange();
					end
				</script>
			</numberfield>

			<stringfield name="label">
				<anchored>
					<left>
						<anchor>left</anchor>
						<offset>29</offset>
					</left>
					<top>
						<anchor>top</anchor>
						<offset>5</offset>
					</top>
					<size>
						<width>78</width>
					</size>
				</anchored>
				<font>sheetlabelsmall</font>
				<frame>
					<name>textline</name>
					<offset>0,5,0,0</offset>
				</frame>
			</stringfield>
			<stringfield name="sublabel">
				<anchored>
					<left>
						<parent>label</parent>
						<anchor>left</anchor>
						<offset>2</offset>
					</left>
					<right>
						<parent>label</parent>
						<anchor>right</anchor>
					</right>
					<top>
						<parent>label</parent>
						<anchor>bottom</anchor>
						<offset>1</offset>
					</top>
					<size>
						<height>11</height>
					</size>
				</anchored>
				<invisible />
				<font>sheetlabelsmall</font>
				<frame>
					<name>textline</name>
					<offset>0,5,0,0</offset>
				</frame>
				<script>
					function onEnter()
						window.windowlist.addNewInstance(window.label.getValue());
					end
					
					function onDeleteUp()
						if getValue() == "" and window.ranks.getValue() == 0 then
							local target = window.windowlist.getPrevWindow(window);
							if target and target.label.getValue() == window.label.getValue() then
								target.sublabel.setFocus();
							end
							
							window.getDatabaseNode().delete();
						end
					end
				</script>
			</stringfield>

			<genericcontrol name="state">
				<anchored>
					<to>label</to>
					<position>insidetopleft</position>
					<offset>-13,0</offset>
					<size>
						<width>12</width>
						<height>12</height>
					</size>
				</anchored>
				<icon>indicator_checkoff</icon>
				<script file="scripts/charsheet_skillstate.lua" />
			</genericcontrol>
			<checkbox name="showonminisheet">
				<anchored>
					<to>label</to>
					<position>insidetopleft</position>
					<offset>-25,0</offset>
					<size>
						<width>12</width>
						<height>12</height>
					</size>
				</anchored>
			</checkbox>
			<labelcycler name="statlabel">
				<anchored>
					<to>label</to>
					<position>insidetopleft</position>
					<offset>80,0</offset>
					<size>
						<width>20</width>
					</size>
				</anchored>
				<font>sheetlabelsmall</font>
				<center />
				<stateframe>
					<hover>
						<name>sheetfocus</name>
						<offset>6,7,7,5</offset>
					</hover>
				</stateframe>
				<sourcefields>
					<labels>Str|Con|Dex|Int|Wis|Cha</labels>
					<values>strength|constitution|dexterity|intelligence|wisdom|charisma</values>
					<srcnode>statname</srcnode>
				</sourcefields>
				<script>
					function onValueChanged()
						window.onStatNameUpdate();
					end
				</script>
			</labelcycler>
			<numbercontrol name="ranks">
				<anchored>
					<to>label</to>
					<position>insidetopleft</position>
					<offset>103,-3</offset>
					<size>
						<width>21</width>
						<height>14</height>
					</size>
				</anchored>
				<frame>
					<name>textlinesmall</name>
					<offset>0,0,0,0</offset>
				</frame>
				<keyeditframe>
					<name>rowshade</name>
					<offset>1,1,1,1</offset>
				</keyeditframe>
				<stateframe>
					<drophilight>
						<name>rowshade</name>
						<offset>1,1,1,1</offset>
					</drophilight>
				</stateframe>
				<droptypes>
					<type>number</type>
				</droptypes>
				<font>sheetnumbersmall</font>
				<hideonvalue>0</hideonvalue>
				<noreset />
				<nodrag />
				<delaykeyupdate />
				<script file="scripts/charsheet_skillranks.lua" />
			</numbercontrol>
			<numbercontrol name="stat">
				<anchored>
					<to>label</to>
					<position>insidetopleft</position>
					<offset>127,-3</offset>
					<size>
						<width>21</width>
						<height>14</height>
					</size>
				</anchored>
				<frame>
					<name>textlinesmall</name>
					<offset>0,0,0,0</offset>
				</frame>
				<displaysign />
				<hideonvalue>0</hideonvalue>
				<font>sheetnumbersmall</font>
				<disabled />
				<script>
					statnode = nil;
					
					function statUpdate()
						if statnode then
							setValue(statnode.getValue());
						else
							setValue(0);
						end
					end
					
					function nothing() end;
					
					function onStatNameUpdate(statname)
						if statnode then
							statnode.onUpdate = nothing;
							statnode = nil;
						end
						
						if statname and statname ~= "" then
							statnode = NodeManager.createSafeChild(window.getDatabaseNode(), "...abilities." .. statname .. ".bonus", "number");
							if statnode then
								statnode.onUpdate = statUpdate;
							end
						end
						
						statUpdate();
					end
				</script>
			</numbercontrol>
			<jpgnumberfield name="misc">
				<anchored>
					<to>label</to>
					<position>insidetopleft</position>
					<offset>151,-3</offset>
					<size>
						<width>21</width>
						<height>14</height>
					</size>
				</anchored>
				<frame>
					<name>textlinesmall</name>
					<offset>0,0,0,0</offset>
				</frame>
				<keyeditframe>
					<name>rowshade</name>
					<offset>1,1,1,1</offset>
				</keyeditframe>
				<stateframe>
					<drophilight>
						<name>rowshade</name>
						<offset>1,1,1,1</offset>
					</drophilight>
				</stateframe>
				<droptypes>
					<type>number</type>
				</droptypes>
				<font>sheetnumbersmall</font>
				<hideonvalue>0</hideonvalue>
				<noreset />
				<nodrag />
				<displaysign />
			</jpgnumberfield>

			<linkednumber name="total">
				<anchored>
					<to>label</to>
					<position>insidetopleft</position>
					<offset>172,-3</offset>
					<size>
						<width>27</width>
						<height>14</height>
					</size>
				</anchored>
				<frame>
					<name>modifier</name>
					<offset>2,5,5,5</offset>
				</frame>
				<font>sheetnumbersmall</font>
				<readonly />
				<displaysign />
				<hideonvalue>0</hideonvalue>
				<source>
					<name>...encumbrance.armorcheckpenalty</name>
					<op>+</op>
				</source>
				<source>
					<name>ranks</name>
					<op>+</op>
				</source>
				<source>
					<name>halfranks</name>
					<op>+</op>
				</source>
				<source>
					<name>misc</name>
					<op>+</op>
				</source>
				<script>
					armorwidget = nil;

					function onSourceUpdate(source)
						local val = calculateSources();
						val = val + window.stat.getValue();
						setValue(val);
					end
					
					function onSourceValue(source, sourcename)
						if sourcename == "halfranks" then
							return math.floor(0.5 * source.getValue());
						elseif sourcename == "...encumbrance.armorcheckpenalty" then
							return math.min(window.armorcheckmultiplier.getValue() * source.getValue(), 0);
						end

						return super.onSourceValue(source, sourcename);
					end

					function updateStat()
						onSourceUpdate(nil);
					end
					
					function onInit()
						armorwidget = addBitmapWidget("indicator_armorcheck");
						armorwidget.setPosition("center", -110, 1);
						
						local statnamenode = NodeManager.createSafeChild(window.getDatabaseNode(), "statname", "string");
						if statnamenode then
							statnamenode.onUpdate = updateStat;
						end
						updateStat();
						
						super.onInit();
					end
					
					function getDescriptionString()
						local desc = "Skill [" .. window.label.getValue();
						if window.sublabel.getValue() ~= "" then
							desc = desc .. " (" .. window.sublabel.getValue() .. ")";
						end
						desc = desc .. "]";
						
						if Input.isShiftPressed() then
							desc = desc .. " [ASSIST]";
						end
						
						return desc;
					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(getDescriptionString());
						draginfo.setNumberData(getValue());
						draginfo.setShortcutData("charsheet", window.getDatabaseNode().getParent().getParent().getNodeName());
						
						return true;
					end

					function onDoubleClick(x,y)
						ChatManager.DoubleClickAction("dice", getValue(), getDescriptionString(), {pc = window.getDatabaseNode().getParent().getParent()});
						return true;
					end
				</script>
			</linkednumber>
		</sheetdata>
	</windowclass>

	<windowclass name="charsheet_skills">
		<placement>
			<size>
				<width>252</width>
				<height>611</height>
			</size>
		</placement>
		<nodelete />
		<script>
			skillcounter = 0;
			
			function getCounter()
				return skillcounter;
			end
			
			function incrementCounter()
				skillcounter = skillcounter + 1;
			end
			
			function onInit()
			end
		</script>
		<sheetdata>
			<!-- SKILLS -->
			<genericcontrol name="skillframe">
				<bounds>15,20,480,520</bounds>
				<frame>
					<name>sheetgroup</name>
				</frame>
			</genericcontrol>

			<genericcontrol>
				<anchored>
					<to>skillframe</to>
					<position>insidetopleft</position>
					<offset>13,9</offset>
					<size>
						<width>10</width>
						<height>10</height>
					</size>
				</anchored>
				<icon>indicator_quicklist</icon>
				<tooltip>
					<text>Show on mini sheet</text>
				</tooltip>
			</genericcontrol>
			<genericcontrol>
				<anchored>
					<to>skillframe</to>
					<position>insidetopleft</position>
					<offset>25,9</offset>
					<size>
						<width>10</width>
						<height>10</height>
					</size>
				</anchored>
				<icon>indicator_encumbrance</icon>
				<tooltip>
					<text>Class skill</text>
				</tooltip>
			</genericcontrol>
			<stringcontrol>
				<anchored>
					<to>skillframe</to>
					<position>insidetopleft</position>
					<offset>37,9</offset>
				</anchored>
				<font>sheetlabelsmall</font>
				<static>Name</static>
			</stringcontrol>
			<stringcontrol>
				<anchored>
					<to>skillframe</to>
					<position>insidetopleft</position>
					<offset>136,9</offset>
				</anchored>
				<font>sheetlabelsmall</font>
				<static>ranks</static>
			</stringcontrol>
			<stringcontrol>
				<anchored>
					<to>skillframe</to>
					<position>insidetopleft</position>
					<offset>165,9</offset>
				</anchored>
				<font>sheetlabelsmall</font>
				<static>stat</static>
			</stringcontrol>
			<stringcontrol>
				<anchored>
					<to>skillframe</to>
					<position>insidetopleft</position>
					<offset>187,9</offset>
				</anchored>
				<font>sheetlabelsmall</font>
				<static>misc</static>
			</stringcontrol>
			<stringcontrol>
				<anchored>
					<to>skillframe</to>
					<position>insidetopleft</position>
					<offset>211,9</offset>
				</anchored>
				<font>sheetlabelsmall</font>
				<static>total</static>
			</stringcontrol>

			<genericcontrol>
				<anchored>
					<to>skillframe</to>
					<position>insidetopleft</position>
					<offset>245,9</offset>
					<size>
						<width>10</width>
						<height>10</height>
					</size>
				</anchored>
				<icon>indicator_quicklist</icon>
				<tooltip>
					<text>Show on mini sheet</text>
				</tooltip>
			</genericcontrol>
			<genericcontrol>
				<anchored>
					<to>skillframe</to>
					<position>insidetopleft</position>
					<offset>257,9</offset>
					<size>
						<width>10</width>
						<height>10</height>
					</size>
				</anchored>
				<icon>indicator_encumbrance</icon>
				<tooltip>
					<text>Class skill</text>
				</tooltip>
			</genericcontrol>
			<stringcontrol>
				<anchored>
					<to>skillframe</to>
					<position>insidetopleft</position>
					<offset>269,9</offset>
				</anchored>
				<font>sheetlabelsmall</font>
				<static>Name</static>
			</stringcontrol>
			<stringcontrol>
				<anchored>
					<to>skillframe</to>
					<position>insidetopleft</position>
					<offset>368,9</offset>
				</anchored>
				<font>sheetlabelsmall</font>
				<static>ranks</static>
			</stringcontrol>
			<stringcontrol>
				<anchored>
					<to>skillframe</to>
					<position>insidetopleft</position>
					<offset>397,9</offset>
				</anchored>
				<font>sheetlabelsmall</font>
				<static>stat</static>
			</stringcontrol>
			<stringcontrol>
				<anchored>
					<to>skillframe</to>
					<position>insidetopleft</position>
					<offset>419,9</offset>
				</anchored>
				<font>sheetlabelsmall</font>
				<static>misc</static>
			</stringcontrol>
			<stringcontrol>
				<anchored>
					<to>skillframe</to>
					<position>insidetopleft</position>
					<offset>443,9</offset>
				</anchored>
				<font>sheetlabelsmall</font>
				<static>total</static>
			</stringcontrol>

			<windowlist name="skilllist">
				<anchored>
					<to>skillframe</to>
					<position>over</position>
					<offset>-8,-20</offset>
				</anchored>
				<datasource>.skilllist</datasource>
				<class>charsheet_skilllistitem</class>
				<allowcreate />
				<columns>
					<filldown />
					<width>232</width>
				</columns>
				<script file="scripts/charsheet_skilllist.lua" />
			</windowlist>

			<!-- POINTS -->
			<genericcontrol name="skillpointframe">
				<bounds>15,540,480,50</bounds>
				<frame>
					<name>sheetgroup</name>
				</frame>
			</genericcontrol>

			<jpgnumberfield name="unspentskillpoints" source="skillpoints.unspent">
				<anchored>
					<to>skillpointframe</to>
					<position>insidetopleft</position>
					<offset>60,15</offset>
					<size>
						<height>20</height>
						<width>35</width>
					</size>
				</anchored>
				<font>sheetnumbersmall</font>
				<nodrag />
				<frame>
					<name>modifier</name>
					<offset>3,3,3,3</offset>
				</frame>
				<script>
					function onValueChanged()
						if getValue() &lt; 0 then
							setValue(0);
						end
					end
				</script>
			</jpgnumberfield>
			<stringcontrol>
				<anchored>
					<to>skillpointframe</to>
					<position>insidetopleft</position>
					<offset>13,15</offset>
					<size>
						<height>21</height>
						<width>45</width>
					</size>
				</anchored>
				<static>Available ranks</static>
				<font>sheetlabelsmall</font>
				<multilinespacing>10</multilinespacing>
			</stringcontrol>
			
			<numbercontrol name="plannedskillpoints" source="skillpoints.planned">
				<anchored>
					<to>skillpointframe</to>
					<position>insidetopleft</position>
					<offset>150,15</offset>
					<size>
						<height>20</height>
						<width>35</width>
					</size>
				</anchored>
				<font>sheetnumbersmall</font>
				<color>#ffbb0000</color>
				<hideonvalue>0</hideonvalue>
				<readonly />
				<nodrag />
				<frame>
					<name>modifier</name>
					<offset>3,3,3,3</offset>
				</frame>
				<script>
					function calculatePoints()
						local points = 0;
					
						for k, v in pairs(window.skilllist.getDatabaseNode().getChildren()) do
							if v.getChild("plannedranks") then
								points = points + NodeManager.getSafeChildValue(v, "plannedranks", 0);
							end
							if v.getChild("plannedhalfranks") then
								points = points + NodeManager.getSafeChildValue(v, "plannedhalfranks", 0);
							end
						end
						
						setValue(points);
						
						if points ~= 0 and points == window.unspentskillpoints.getValue() then
							window.submitplan.setVisible(true);
						else
							window.submitplan.setVisible(false);
						end
					end
					
					function onClickDown(button, x, y)
						if button == 2 then
							window.skilllist.resetPlannedPoints();
							return true;
						end
					end
					
					function onMenuSelection()
						window.skilllist.submitPlannedPoints();
					end
				
					function onInit()
						calculatePoints();
						registerMenuItem("Submit planned ranks", "edit", 5);
					end
				</script>
			</numbercontrol>
			<stringcontrol>
				<anchored>
					<to>skillpointframe</to>
					<position>insidetopleft</position>
					<offset>103,15</offset>
					<size>
						<height>21</height>
						<width>45</width>
					</size>
				</anchored>
				<static>Planned ranks</static>
				<font>sheetlabelsmall</font>
				<multilinespacing>10</multilinespacing>
			</stringcontrol>
			
			<buttoncontrol name="submitplan">
				<anchored>
					<to>skillpointframe</to>
					<position>insidetopleft</position>
					<offset>190,14</offset>
					<size>
						<width>32</width>
						<height>23</height>
					</size>
				</anchored>
				<icon>
					<normal>button_submit</normal>
					<pressed>button_submit_down</pressed>
				</icon>
				<invisible />
				<script>
					function onButtonPress()
						window.skilllist.submitPlannedPoints();
					end
				</script>
			</buttoncontrol>
			
			<skillsetlabel name="class1" source="classes.slot1.name">
				<anchored>
					<to>skillpointframe</to>
					<position>insidetopleft</position>
					<offset>255,16</offset>
					<size>
						<height>20</height>
						<width>60</width>
					</size>
				</anchored>
				<empty>&#171; Set 1 &#187;</empty>
				<target>class1set</target>
				<defaultset />
			</skillsetlabel>
			<skillsetcontrol name="class1set">
				<anchored>
					<to>class1</to>
					<position>left</position>
					<offset>0,-4</offset>
					<size>
						<width>13</width>
					</size>
				</anchored>
				<setid>1</setid>
			</skillsetcontrol>

			<skillsetlabel name="class2" source="classes.slot2.name">
				<anchored>
					<to>skillpointframe</to>
					<position>insidetopleft</position>
					<offset>330,16</offset>
					<size>
						<height>20</height>
						<width>60</width>
					</size>
				</anchored>
				<target>class2set</target>
			</skillsetlabel>
			<skillsetcontrol name="class2set">
				<anchored>
					<to>class2</to>
					<position>left</position>
					<offset>0,-4</offset>
					<size>
						<width>13</width>
					</size>
				</anchored>
				<setid>2</setid>
			</skillsetcontrol>

			<skillsetlabel name="class3" source="classes.slot3.name">
				<anchored>
					<to>skillpointframe</to>
					<position>insidetopleft</position>
					<offset>405,16</offset>
					<size>
						<height>20</height>
						<width>60</width>
					</size>
				</anchored>
				<target>class3set</target>
			</skillsetlabel>
			<skillsetcontrol name="class3set">
				<anchored>
					<to>class3</to>
					<position>left</position>
					<offset>0,-4</offset>
					<size>
						<width>13</width>
					</size>
				</anchored>
				<setid>3</setid>
			</skillsetcontrol>
		</sheetdata>
	</windowclass>
</root>