Added more functionality to FontRenderer

This commit is contained in:
William Moorehouse 2015-06-13 15:46:29 -04:00
parent fff19e4737
commit 56ac35352c
17 changed files with 7781 additions and 458 deletions

View File

@ -0,0 +1,88 @@
using System;
using System.Text;
namespace TrueCraft.API
{
/// <summary>
/// Provides constants and functions for working with chat formatting.
/// </summary>
public static class ChatFormat
{
/// <summary>
/// The following text should be obfuscated.
/// </summary>
public const string Obfuscated = "§k";
/// <summary>
/// The following text should be bold.
/// </summary>
public const string Bold = "§l";
/// <summary>
/// The following text should be striked-through.
/// </summary>
public const string Strikethrough = "§m";
/// <summary>
/// The following text should be underlined.
/// </summary>
public const string Underline = "§n";
/// <summary>
/// The following text should be italicized.
/// </summary>
public const string Italic = "§o";
/// <summary>
/// The following text should be reset to normal.
/// </summary>
public const string Reset = "§r";
/// <summary>
/// Returns whether the specified chat code is a valid formatting one.
/// </summary>
/// <param name="code"></param>
/// <returns></returns>
public static bool IsValid(string code)
{
if (string.IsNullOrEmpty(code))
return false;
var comparison = StringComparison.InvariantCultureIgnoreCase;
return
code.Equals(ChatFormat.Obfuscated, comparison) ||
code.Equals(ChatFormat.Bold, comparison) ||
code.Equals(ChatFormat.Strikethrough, comparison) ||
code.Equals(ChatFormat.Underline, comparison) ||
code.Equals(ChatFormat.Italic, comparison) ||
code.Equals(ChatFormat.Reset, comparison);
}
/// <summary>
/// Removes any format codes from a chat string.
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
public static string Remove(string text)
{
if (string.IsNullOrEmpty(text))
return string.Empty;
var builder = new StringBuilder(text.Length);
for (int i = 0; i < text.Length; i++)
{
if (text[i] == '§')
{
i++;
var code = new string('§', text[i]);
if (IsValid(code))
continue;
else
builder.Append(code);
}
builder.Append(text[i]);
}
return builder.ToString();
}
}
}

View File

@ -37,6 +37,7 @@
<ItemGroup>
<Compile Include="Configuration.cs" />
<Compile Include="Coordinates3D.cs" />
<Compile Include="ChatFormat.cs" />
<Compile Include="IAccessConfiguration.cs" />
<Compile Include="PlantSpecies.cs" />
<Compile Include="OreTypes.cs" />

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

View File

@ -1,329 +0,0 @@
<?xml version="1.0"?>
<font>
<info face="DejaVu Sans Mono" size="32" bold="0" italic="0" charset="" unicode="1" stretchH="100" smooth="1" aa="1" padding="0,0,0,0" spacing="1,1" outline="0"/>
<common lineHeight="31" base="25" scaleW="512" scaleH="512" pages="1" packed="0" alphaChnl="1" redChnl="0" greenChnl="0" blueChnl="0"/>
<pages>
<page id="0" file="dejavu_0.png" />
</pages>
<chars count="319">
<char id="32" x="499" y="181" width="3" height="1" xoffset="-1" yoffset="30" xadvance="16" page="0" chnl="15" />
<char id="33" x="503" y="98" width="5" height="20" xoffset="6" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="34" x="106" y="209" width="9" height="7" xoffset="4" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="35" x="16" y="194" width="18" height="18" xoffset="-1" yoffset="7" xadvance="16" page="0" chnl="15" />
<char id="36" x="109" y="81" width="14" height="24" xoffset="2" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="37" x="468" y="123" width="17" height="20" xoffset="-1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="38" x="0" y="152" width="17" height="20" xoffset="0" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="39" x="504" y="181" width="4" height="7" xoffset="6" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="40" x="171" y="80" width="8" height="24" xoffset="5" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="41" x="502" y="52" width="8" height="24" xoffset="4" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="42" x="0" y="214" width="14" height="12" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="43" x="366" y="189" width="16" height="14" xoffset="0" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="44" x="504" y="153" width="6" height="8" xoffset="5" yoffset="21" xadvance="16" page="0" chnl="15" />
<char id="45" x="240" y="207" width="9" height="2" xoffset="4" yoffset="17" xadvance="16" page="0" chnl="15" />
<char id="46" x="183" y="208" width="5" height="4" xoffset="5" yoffset="21" xadvance="16" page="0" chnl="15" />
<char id="47" x="487" y="78" width="15" height="22" xoffset="0" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="48" x="176" y="171" width="15" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="49" x="413" y="165" width="13" height="20" xoffset="3" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="50" x="248" y="147" width="15" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="51" x="264" y="147" width="15" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="52" x="180" y="150" width="16" height="20" xoffset="0" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="53" x="312" y="147" width="15" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="54" x="344" y="147" width="15" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="55" x="360" y="146" width="15" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="56" x="376" y="145" width="15" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="57" x="392" y="145" width="15" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="58" x="504" y="138" width="5" height="14" xoffset="5" yoffset="11" xadvance="16" page="0" chnl="15" />
<char id="59" x="504" y="119" width="6" height="18" xoffset="4" yoffset="11" xadvance="16" page="0" chnl="15" />
<char id="60" x="400" y="187" width="16" height="13" xoffset="0" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="61" x="89" y="210" width="16" height="7" xoffset="0" yoffset="13" xadvance="16" page="0" chnl="15" />
<char id="62" x="383" y="188" width="16" height="13" xoffset="0" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="63" x="399" y="166" width="13" height="20" xoffset="2" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="64" x="277" y="79" width="17" height="22" xoffset="0" yoffset="7" xadvance="16" page="0" chnl="15" />
<char id="65" x="18" y="152" width="17" height="20" xoffset="0" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="66" x="144" y="171" width="15" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="67" x="284" y="168" width="14" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="68" x="192" y="171" width="15" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="69" x="239" y="169" width="14" height="20" xoffset="2" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="70" x="314" y="168" width="14" height="20" xoffset="2" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="71" x="64" y="172" width="15" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="72" x="208" y="170" width="15" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="73" x="371" y="167" width="13" height="20" xoffset="2" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="74" x="357" y="168" width="13" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="75" x="162" y="150" width="17" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="76" x="224" y="170" width="14" height="20" xoffset="2" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="77" x="231" y="148" width="16" height="20" xoffset="0" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="78" x="128" y="172" width="15" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="79" x="112" y="172" width="15" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="80" x="96" y="172" width="15" height="20" xoffset="2" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="81" x="46" y="81" width="15" height="24" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="82" x="214" y="149" width="16" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="83" x="48" y="172" width="15" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="84" x="144" y="150" width="17" height="20" xoffset="0" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="85" x="299" y="168" width="14" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="86" x="126" y="151" width="17" height="20" xoffset="0" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="87" x="394" y="123" width="18" height="20" xoffset="-1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="88" x="375" y="124" width="18" height="20" xoffset="0" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="89" x="108" y="151" width="17" height="20" xoffset="0" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="90" x="440" y="144" width="15" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="91" x="162" y="80" width="8" height="24" xoffset="5" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="92" x="0" y="107" width="15" height="22" xoffset="0" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="93" x="153" y="80" width="8" height="24" xoffset="4" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="94" x="72" y="210" width="16" height="7" xoffset="0" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="95" x="200" y="208" width="18" height="2" xoffset="-1" yoffset="29" xadvance="16" page="0" chnl="15" />
<char id="96" x="151" y="208" width="8" height="5" xoffset="3" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="97" x="232" y="191" width="15" height="15" xoffset="1" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="98" x="192" y="127" width="15" height="21" xoffset="2" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="99" x="352" y="189" width="13" height="15" xoffset="2" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="100" x="160" y="128" width="15" height="21" xoffset="1" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="101" x="248" y="190" width="15" height="15" xoffset="1" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="102" x="240" y="125" width="14" height="21" xoffset="2" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="103" x="487" y="101" width="15" height="21" xoffset="1" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="104" x="313" y="125" width="13" height="21" xoffset="2" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="105" x="0" y="130" width="15" height="21" xoffset="1" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="106" x="160" y="0" width="10" height="27" xoffset="2" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="107" x="80" y="129" width="15" height="21" xoffset="2" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="108" x="128" y="128" width="15" height="21" xoffset="0" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="109" x="147" y="192" width="17" height="15" xoffset="0" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="110" x="310" y="189" width="13" height="15" xoffset="2" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="111" x="216" y="191" width="15" height="15" xoffset="1" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="112" x="144" y="128" width="15" height="21" xoffset="2" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="113" x="16" y="130" width="15" height="21" xoffset="1" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="114" x="499" y="165" width="12" height="15" xoffset="4" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="115" x="296" y="189" width="13" height="15" xoffset="2" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="116" x="0" y="194" width="15" height="19" xoffset="1" yoffset="6" xadvance="16" page="0" chnl="15" />
<char id="117" x="338" y="189" width="13" height="15" xoffset="2" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="118" x="182" y="192" width="16" height="15" xoffset="0" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="119" x="110" y="193" width="18" height="15" xoffset="-1" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="120" x="165" y="192" width="16" height="15" xoffset="0" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="121" x="436" y="101" width="16" height="21" xoffset="0" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="122" x="324" y="189" width="13" height="15" xoffset="2" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="123" x="418" y="52" width="13" height="25" xoffset="2" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="124" x="171" y="0" width="4" height="27" xoffset="6" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="125" x="432" y="52" width="13" height="25" xoffset="2" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="126" x="160" y="208" width="16" height="4" xoffset="0" yoffset="15" xadvance="16" page="0" chnl="15" />
<char id="160" x="504" y="162" width="3" height="1" xoffset="-1" yoffset="30" xadvance="16" page="0" chnl="15" />
<char id="161" x="503" y="77" width="5" height="20" xoffset="6" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="162" x="211" y="79" width="13" height="23" xoffset="2" yoffset="6" xadvance="16" page="0" chnl="15" />
<char id="163" x="32" y="173" width="15" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="164" x="15" y="214" width="13" height="11" xoffset="2" yoffset="11" xadvance="16" page="0" chnl="15" />
<char id="165" x="54" y="151" width="17" height="20" xoffset="0" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="166" x="504" y="0" width="4" height="24" xoffset="6" yoffset="6" xadvance="16" page="0" chnl="15" />
<char id="167" x="225" y="79" width="13" height="23" xoffset="2" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="168" x="189" y="208" width="10" height="3" xoffset="3" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="169" x="72" y="193" width="18" height="16" xoffset="-1" yoffset="7" xadvance="16" page="0" chnl="15" />
<char id="170" x="417" y="186" width="12" height="13" xoffset="2" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="171" x="489" y="185" width="14" height="12" xoffset="1" yoffset="11" xadvance="16" page="0" chnl="15" />
<char id="172" x="116" y="209" width="16" height="6" xoffset="0" yoffset="14" xadvance="16" page="0" chnl="15" />
<char id="173" x="230" y="207" width="9" height="2" xoffset="4" yoffset="17" xadvance="16" page="0" chnl="15" />
<char id="174" x="53" y="193" width="18" height="16" xoffset="-1" yoffset="7" xadvance="16" page="0" chnl="15" />
<char id="175" x="219" y="207" width="10" height="2" xoffset="3" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="176" x="61" y="210" width="10" height="8" xoffset="3" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="177" x="199" y="192" width="16" height="15" xoffset="0" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="178" x="51" y="212" width="9" height="11" xoffset="3" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="179" x="40" y="212" width="10" height="11" xoffset="3" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="180" x="142" y="209" width="8" height="5" xoffset="5" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="181" x="32" y="129" width="15" height="21" xoffset="2" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="182" x="196" y="80" width="14" height="23" xoffset="0" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="183" x="177" y="208" width="5" height="4" xoffset="5" yoffset="14" xadvance="16" page="0" chnl="15" />
<char id="184" x="133" y="209" width="8" height="5" xoffset="4" yoffset="25" xadvance="16" page="0" chnl="15" />
<char id="185" x="29" y="213" width="10" height="11" xoffset="3" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="186" x="430" y="186" width="12" height="13" xoffset="2" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="187" x="474" y="186" width="14" height="12" xoffset="2" yoffset="11" xadvance="16" page="0" chnl="15" />
<char id="188" x="486" y="0" width="17" height="25" xoffset="-1" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="189" x="142" y="28" width="16" height="25" xoffset="-1" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="190" x="450" y="0" width="17" height="25" xoffset="-1" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="191" x="385" y="166" width="13" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="192" x="432" y="0" width="17" height="25" xoffset="0" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="193" x="396" y="0" width="17" height="25" xoffset="0" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="194" x="90" y="29" width="17" height="25" xoffset="0" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="195" x="72" y="29" width="17" height="25" xoffset="0" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="196" x="54" y="29" width="17" height="25" xoffset="0" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="197" x="36" y="29" width="17" height="25" xoffset="0" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="198" x="486" y="123" width="17" height="20" xoffset="-1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="199" x="92" y="55" width="14" height="25" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="200" x="257" y="53" width="14" height="25" xoffset="2" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="201" x="122" y="54" width="14" height="25" xoffset="2" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="202" x="107" y="55" width="14" height="25" xoffset="2" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="203" x="62" y="55" width="14" height="25" xoffset="2" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="204" x="446" y="52" width="13" height="25" xoffset="2" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="205" x="460" y="52" width="13" height="25" xoffset="2" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="206" x="474" y="52" width="13" height="25" xoffset="2" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="207" x="488" y="52" width="13" height="25" xoffset="2" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="208" x="432" y="123" width="17" height="20" xoffset="-1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="209" x="303" y="27" width="15" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="210" x="255" y="27" width="15" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="211" x="271" y="27" width="15" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="212" x="367" y="26" width="15" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="213" x="399" y="26" width="15" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="214" x="463" y="26" width="15" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="215" x="459" y="186" width="14" height="12" xoffset="1" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="216" x="258" y="79" width="18" height="22" xoffset="-1" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="217" x="347" y="52" width="14" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="218" x="167" y="54" width="14" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="219" x="137" y="54" width="14" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="220" x="77" y="55" width="14" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="221" x="18" y="29" width="17" height="25" xoffset="0" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="222" x="160" y="171" width="15" height="20" xoffset="2" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="223" x="208" y="127" width="15" height="21" xoffset="2" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="224" x="327" y="79" width="15" height="22" xoffset="1" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="225" x="112" y="106" width="15" height="22" xoffset="1" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="226" x="471" y="78" width="15" height="22" xoffset="1" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="227" x="224" y="126" width="15" height="21" xoffset="1" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="228" x="0" y="173" width="15" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="229" x="180" y="80" width="15" height="23" xoffset="1" yoffset="2" xadvance="16" page="0" chnl="15" />
<char id="230" x="129" y="193" width="17" height="15" xoffset="0" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="231" x="455" y="165" width="13" height="20" xoffset="2" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="232" x="423" y="78" width="15" height="22" xoffset="1" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="233" x="359" y="78" width="15" height="22" xoffset="1" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="234" x="343" y="79" width="15" height="22" xoffset="1" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="235" x="472" y="144" width="15" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="236" x="311" y="79" width="15" height="22" xoffset="1" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="237" x="295" y="79" width="15" height="22" xoffset="1" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="238" x="80" y="106" width="15" height="22" xoffset="1" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="239" x="424" y="144" width="15" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="240" x="48" y="129" width="15" height="21" xoffset="1" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="241" x="299" y="125" width="13" height="21" xoffset="2" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="242" x="48" y="106" width="15" height="22" xoffset="1" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="243" x="32" y="106" width="15" height="22" xoffset="1" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="244" x="375" y="78" width="15" height="22" xoffset="1" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="245" x="64" y="129" width="15" height="21" xoffset="1" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="246" x="408" y="144" width="15" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="247" x="443" y="186" width="15" height="12" xoffset="1" yoffset="11" xadvance="16" page="0" chnl="15" />
<char id="248" x="35" y="194" width="17" height="17" xoffset="0" yoffset="9" xadvance="16" page="0" chnl="15" />
<char id="249" x="310" y="102" width="13" height="22" xoffset="2" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="250" x="268" y="102" width="13" height="22" xoffset="2" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="251" x="240" y="102" width="13" height="22" xoffset="2" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="252" x="329" y="168" width="13" height="20" xoffset="2" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="253" x="17" y="0" width="16" height="28" xoffset="0" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="254" x="112" y="0" width="15" height="27" xoffset="2" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="255" x="194" y="0" width="16" height="26" xoffset="0" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="256" x="28" y="81" width="17" height="24" xoffset="0" yoffset="1" xadvance="16" page="0" chnl="15" />
<char id="257" x="16" y="173" width="15" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="258" x="0" y="29" width="17" height="25" xoffset="0" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="259" x="391" y="78" width="15" height="22" xoffset="1" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="260" x="322" y="0" width="18" height="25" xoffset="0" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="261" x="197" y="149" width="16" height="20" xoffset="1" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="262" x="317" y="53" width="14" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="263" x="156" y="105" width="13" height="22" xoffset="2" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="264" x="197" y="53" width="14" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="265" x="142" y="105" width="13" height="22" xoffset="2" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="266" x="272" y="53" width="14" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="267" x="343" y="168" width="13" height="20" xoffset="2" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="268" x="182" y="54" width="14" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="269" x="128" y="105" width="13" height="22" xoffset="2" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="270" x="431" y="26" width="15" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="271" x="378" y="101" width="19" height="21" xoffset="1" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="272" x="36" y="151" width="17" height="20" xoffset="-1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="273" x="398" y="101" width="18" height="21" xoffset="1" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="274" x="124" y="80" width="14" height="24" xoffset="2" yoffset="1" xadvance="16" page="0" chnl="15" />
<char id="275" x="280" y="147" width="15" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="276" x="302" y="53" width="14" height="25" xoffset="2" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="277" x="407" y="78" width="15" height="22" xoffset="1" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="278" x="242" y="53" width="14" height="25" xoffset="2" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="279" x="328" y="147" width="15" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="280" x="227" y="53" width="14" height="25" xoffset="2" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="281" x="488" y="144" width="15" height="20" xoffset="1" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="282" x="152" y="54" width="14" height="25" xoffset="2" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="283" x="439" y="78" width="15" height="22" xoffset="1" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="284" x="415" y="26" width="15" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="285" x="34" y="0" width="15" height="28" xoffset="1" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="286" x="383" y="26" width="15" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="287" x="50" y="0" width="15" height="28" xoffset="1" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="288" x="351" y="26" width="15" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="289" x="260" y="0" width="15" height="26" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="290" x="276" y="0" width="15" height="26" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="291" x="66" y="0" width="15" height="28" xoffset="1" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="292" x="319" y="27" width="15" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="293" x="390" y="52" width="13" height="25" xoffset="2" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="294" x="355" y="125" width="19" height="20" xoffset="-1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="295" x="112" y="129" width="15" height="21" xoffset="0" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="296" x="376" y="52" width="13" height="25" xoffset="2" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="297" x="96" y="129" width="15" height="21" xoffset="1" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="298" x="139" y="80" width="13" height="24" xoffset="2" yoffset="1" xadvance="16" page="0" chnl="15" />
<char id="299" x="80" y="172" width="15" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="300" x="362" y="52" width="13" height="25" xoffset="2" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="301" x="455" y="78" width="15" height="22" xoffset="1" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="302" x="14" y="81" width="13" height="25" xoffset="2" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="303" x="228" y="0" width="15" height="26" xoffset="1" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="304" x="404" y="52" width="13" height="25" xoffset="2" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="305" x="264" y="189" width="15" height="15" xoffset="1" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="306" x="413" y="123" width="18" height="20" xoffset="-1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="307" x="94" y="0" width="17" height="27" xoffset="-1" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="308" x="0" y="81" width="13" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="309" x="82" y="0" width="11" height="28" xoffset="2" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="310" x="176" y="0" width="17" height="26" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="311" x="144" y="0" width="15" height="27" xoffset="2" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="312" x="280" y="189" width="15" height="15" xoffset="2" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="313" x="335" y="26" width="15" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="314" x="239" y="27" width="15" height="25" xoffset="0" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="315" x="307" y="0" width="14" height="26" xoffset="2" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="316" x="128" y="0" width="15" height="27" xoffset="0" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="317" x="269" y="168" width="14" height="20" xoffset="2" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="318" x="470" y="101" width="16" height="21" xoffset="0" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="319" x="254" y="168" width="14" height="20" xoffset="2" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="320" x="453" y="101" width="16" height="21" xoffset="0" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="321" x="90" y="151" width="17" height="20" xoffset="-1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="322" x="176" y="128" width="15" height="21" xoffset="0" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="323" x="495" y="26" width="15" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="324" x="170" y="105" width="13" height="22" xoffset="2" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="325" x="244" y="0" width="15" height="26" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="326" x="341" y="125" width="13" height="21" xoffset="2" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="327" x="0" y="55" width="15" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="328" x="184" y="104" width="13" height="22" xoffset="2" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="329" x="417" y="101" width="18" height="21" xoffset="-1" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="330" x="292" y="0" width="14" height="26" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="331" x="327" y="125" width="13" height="21" xoffset="2" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="332" x="78" y="81" width="15" height="24" xoffset="1" yoffset="1" xadvance="16" page="0" chnl="15" />
<char id="333" x="296" y="147" width="15" height="20" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="334" x="479" y="26" width="15" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="335" x="96" y="106" width="15" height="22" xoffset="1" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="336" x="287" y="27" width="15" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="337" x="16" y="107" width="15" height="22" xoffset="1" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="338" x="450" y="123" width="17" height="20" xoffset="0" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="339" x="91" y="193" width="18" height="15" xoffset="-1" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="340" x="108" y="28" width="16" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="341" x="352" y="102" width="12" height="22" xoffset="4" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="342" x="211" y="0" width="16" height="26" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="343" x="270" y="125" width="14" height="21" xoffset="2" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="344" x="125" y="28" width="16" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="345" x="365" y="101" width="12" height="22" xoffset="4" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="346" x="223" y="27" width="15" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="347" x="324" y="102" width="13" height="22" xoffset="2" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="348" x="207" y="27" width="15" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="349" x="254" y="102" width="13" height="22" xoffset="2" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="350" x="191" y="27" width="15" height="25" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="351" x="427" y="165" width="13" height="20" xoffset="2" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="352" x="175" y="28" width="15" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="353" x="282" y="102" width="13" height="22" xoffset="2" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="354" x="360" y="0" width="17" height="25" xoffset="0" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="355" x="62" y="81" width="15" height="24" xoffset="1" yoffset="6" xadvance="16" page="0" chnl="15" />
<char id="356" x="378" y="0" width="17" height="25" xoffset="0" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="357" x="64" y="106" width="15" height="22" xoffset="1" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="358" x="72" y="151" width="17" height="20" xoffset="0" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="359" x="483" y="165" width="15" height="19" xoffset="1" yoffset="6" xadvance="16" page="0" chnl="15" />
<char id="360" x="32" y="55" width="14" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="361" x="285" y="125" width="13" height="21" xoffset="2" yoffset="4" xadvance="16" page="0" chnl="15" />
<char id="362" x="94" y="81" width="14" height="24" xoffset="1" yoffset="1" xadvance="16" page="0" chnl="15" />
<char id="363" x="441" y="165" width="13" height="20" xoffset="2" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="364" x="332" y="53" width="14" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="365" x="198" y="104" width="13" height="22" xoffset="2" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="366" x="212" y="53" width="14" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="367" x="212" y="103" width="13" height="22" xoffset="2" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="368" x="287" y="53" width="14" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="369" x="226" y="103" width="13" height="22" xoffset="2" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="370" x="47" y="55" width="14" height="25" xoffset="1" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="371" x="456" y="144" width="15" height="20" xoffset="2" yoffset="10" xadvance="16" page="0" chnl="15" />
<char id="372" x="341" y="0" width="18" height="25" xoffset="-1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="373" x="239" y="79" width="18" height="22" xoffset="-1" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="374" x="468" y="0" width="17" height="25" xoffset="0" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="375" x="0" y="0" width="16" height="28" xoffset="0" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="376" x="414" y="0" width="17" height="25" xoffset="0" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="377" x="159" y="28" width="15" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="378" x="296" y="102" width="13" height="22" xoffset="2" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="379" x="16" y="55" width="15" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="380" x="469" y="165" width="13" height="20" xoffset="2" yoffset="5" xadvance="16" page="0" chnl="15" />
<char id="381" x="447" y="26" width="15" height="25" xoffset="1" yoffset="0" xadvance="16" page="0" chnl="15" />
<char id="382" x="338" y="102" width="13" height="22" xoffset="2" yoffset="3" xadvance="16" page="0" chnl="15" />
<char id="383" x="255" y="125" width="14" height="21" xoffset="2" yoffset="4" xadvance="16" page="0" chnl="15" />
</chars>
</font>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 76 KiB

View File

@ -1,121 +0,0 @@
using System;
using System.Collections.Generic;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using TrueCraft.API;
namespace TrueCraft.Client
{
public class FontRenderer
{
public FontRenderer(FontFile fontFile, Texture2D fontTexture)
{
_fontFile = fontFile;
_texture = fontTexture;
_characterMap = new Dictionary<char, FontChar>();
foreach (var fontCharacter in _fontFile.Chars)
{
char c = (char)fontCharacter.ID;
_characterMap.Add(c, fontCharacter);
}
}
private Dictionary<char, FontChar> _characterMap;
private FontFile _fontFile;
private Texture2D _texture;
public void DrawText(SpriteBatch spriteBatch, int x, int y, string text)
{
var dx = x;
var dy = y;
var color = Color.White;
for (int i = 0; i < text.Length; i++)
{
if (text[i] == '§')
{
i++;
var code = string.Format("§{0}", text[i]);
color = GetColor(code);
}
else
{
FontChar fc;
if (_characterMap.TryGetValue(text[i], out fc))
{
var sourceRectangle = new Rectangle(fc.X, fc.Y, fc.Width, fc.Height);
var position = new Vector2(dx + fc.XOffset, dy + fc.YOffset);
spriteBatch.Draw(_texture, position, sourceRectangle, color);
dx += fc.XAdvance;
}
}
}
}
// RGB values taken from http://minecraft.gamepedia.com/Formatting_codes
private static Color GetColor(string colorCode)
{
colorCode = colorCode.ToLowerInvariant();
switch (colorCode)
{
case ChatColor.Black:
return new Color(0, 0, 0);
case ChatColor.DarkBlue:
return new Color(0, 0, 170);
case ChatColor.DarkGreen:
return new Color(0, 170, 0);
case ChatColor.DarkCyan:
return new Color(0, 170, 170);
case ChatColor.DarkRed:
return new Color(170, 0, 0);
case ChatColor.Purple:
return new Color(170, 0, 170);
case ChatColor.Orange:
return new Color(255, 170, 0);
case ChatColor.Gray:
return new Color(170, 170, 170);
case ChatColor.DarkGray:
return new Color(85, 85, 85);
case ChatColor.Blue:
return new Color(85, 85, 255);
case ChatColor.BrightGreen:
return new Color(85, 255, 85);
case ChatColor.Cyan:
return new Color(85, 255, 255);
case ChatColor.Red:
return new Color(255, 85, 85);
case ChatColor.Pink:
return new Color(255, 85, 255);
case ChatColor.Yellow:
return new Color(255, 255, 85);
case ChatColor.White:
return new Color(255, 255, 255);
default:
break;
}
// Technically this means we have an invalid color code,
// should we throw an exception?
return Color.White;
}
}
}

View File

@ -3,6 +3,7 @@ using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using TrueCraft.Client.Events;
using System.Collections.Generic;
using TrueCraft.Client.Rendering;
namespace TrueCraft.Client.Interface
{

View File

@ -0,0 +1,98 @@
using System;
using System.IO;
using System.Collections.Generic;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
namespace TrueCraft.Client.Rendering
{
/// <summary>
/// Represents a font.
/// </summary>
public class Font
{
private FontFile _definition;
private Texture2D[] _textures;
private Dictionary<char, FontChar> _glyphs;
/// <summary>
///
/// </summary>
public string Name { get; private set; }
/// <summary>
///
/// </summary>
public FontStyle Style { get; private set; }
/// <summary>
///
/// </summary>
/// <param name="contentManager"></param>
/// <param name="name"></param>
/// <param name="style"></param>
public Font(ContentManager contentManager, string name, FontStyle style = FontStyle.Regular)
{
Name = name;
Style = style;
LoadContent(contentManager);
GenerateGlyphs();
}
/// <summary>
///
/// </summary>
/// <param name="page"></param>
/// <returns></returns>
public Texture2D GetTexture(int page = 0)
{
return _textures[page];
}
/// <summary>
///
/// </summary>
/// <param name="ch"></param>
/// <returns></returns>
public FontChar GetGlyph(char ch)
{
FontChar glyph = null;
_glyphs.TryGetValue(ch, out glyph);
return glyph;
}
/// <summary>
///
/// </summary>
/// <param name="contentManager"></param>
private void LoadContent(ContentManager contentManager)
{
var definitionPath = string.Format("{0}_{1}.fnt", Name.ToLowerInvariant(), Style.ToString().ToLowerInvariant());
using (var contents = File.OpenRead(Path.Combine(contentManager.RootDirectory, definitionPath)))
_definition = FontLoader.Load(contents);
// We need to support multiple texture pages for more than plain ASCII text.
_textures = new Texture2D[_definition.Pages.Count];
for (int i = 0; i < _definition.Pages.Count; i++)
{
var texturePath = string.Format("{0}_{1}_{2}.png", Name.ToLowerInvariant(), Style.ToString().ToLowerInvariant(), i.ToString());
_textures[i] = contentManager.Load<Texture2D>(texturePath);
}
}
/// <summary>
///
/// </summary>
private void GenerateGlyphs()
{
_glyphs = new Dictionary<char, FontChar>();
foreach (var glyph in _definition.Chars)
{
char c = (char)glyph.ID;
_glyphs.Add(c, glyph);
}
}
}
}

View File

@ -0,0 +1,199 @@
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using TrueCraft.API;
namespace TrueCraft.Client.Rendering
{
/// <summary>
/// Represents a font renderer.
/// </summary>
public class FontRenderer
{
/// <summary>
///
/// </summary>
public Font[] Fonts { get; private set; }
/// <summary>
///
/// </summary>
/// <param name="font"></param>
public FontRenderer(Font font)
{
if (font == null)
throw new ArgumentNullException("font");
Fonts = new Font[]
{
font
};
}
/// <summary>
///
/// </summary>
/// <param name="regular"></param>
/// <param name="bold"></param>
/// <param name="strikethrough"></param>
/// <param name="underline"></param>
/// <param name="italic"></param>
public FontRenderer(Font regular, Font bold, Font strikethrough, Font underline, Font italic)
{
if (regular == null)
throw new ArgumentNullException("regular");
Fonts = new Font[]
{
regular,
bold ?? regular,
strikethrough ?? regular,
underline ?? regular,
italic ?? regular
};
}
/// <summary>
///
/// </summary>
/// <param name="spriteBatch"></param>
/// <param name="x"></param>
/// <param name="y"></param>
/// <param name="text"></param>
/// <param name="scale"></param>
public void DrawText(SpriteBatch spriteBatch, int x, int y, string text, float scale = 1.0f)
{
var dx = x;
var dy = y;
var color = Color.White;
var font = Fonts[0];
for (int i = 0; i < text.Length; i++)
{
if (text[i] == '§')
{
i++;
var code = string.Format("§{0}", text[i]);
if (ChatFormat.IsValid(code))
font = GetFont(code);
else
color = GetColor(code);
}
else
{
var glyph = font.GetGlyph(text[i]);
if (glyph != null)
{
var sourceRectangle = new Rectangle(glyph.X, glyph.Y, glyph.Width, glyph.Height);
var destRectangle = new Rectangle(
dx + (int)(glyph.XOffset * scale),
dy + (int)(glyph.YOffset * scale),
(int)(glyph.Width * scale),
(int)(glyph.Height * scale));
spriteBatch.Draw(font.GetTexture(glyph.Page), destRectangle, sourceRectangle, color);
dx += (int)(glyph.XAdvance * scale);
}
}
}
}
private Font GetFont(string formatCode)
{
// If we are a mono-font renderer, we don't actually care about formatting codes.
if (Fonts.Length == 1)
return Fonts[0];
// Otherwise, determine which font to switch to.
formatCode = formatCode.ToLowerInvariant();
switch (formatCode)
{
case ChatFormat.Obfuscated: // We don't support obfuscated text yet.
return Fonts[(int)FontStyle.Regular];
case ChatFormat.Bold:
return Fonts[(int)FontStyle.Bold];
case ChatFormat.Strikethrough:
return Fonts[(int)FontStyle.Strikethrough];
case ChatFormat.Underline:
return Fonts[(int)FontStyle.Underline];
case ChatFormat.Italic:
return Fonts[(int)FontStyle.Italic];
case ChatFormat.Reset:
return Fonts[(int)FontStyle.Regular];
default:
return Fonts[0];
}
}
// RGB values taken from http://minecraft.gamepedia.com/Formatting_codes
private static Color GetColor(string colorCode)
{
colorCode = colorCode.ToLowerInvariant();
switch (colorCode)
{
case ChatColor.Black:
return new Color(0, 0, 0);
case ChatColor.DarkBlue:
return new Color(0, 0, 170);
case ChatColor.DarkGreen:
return new Color(0, 170, 0);
case ChatColor.DarkCyan:
return new Color(0, 170, 170);
case ChatColor.DarkRed:
return new Color(170, 0, 0);
case ChatColor.Purple:
return new Color(170, 0, 170);
case ChatColor.Orange:
return new Color(255, 170, 0);
case ChatColor.Gray:
return new Color(170, 170, 170);
case ChatColor.DarkGray:
return new Color(85, 85, 85);
case ChatColor.Blue:
return new Color(85, 85, 255);
case ChatColor.BrightGreen:
return new Color(85, 255, 85);
case ChatColor.Cyan:
return new Color(85, 255, 255);
case ChatColor.Red:
return new Color(255, 85, 85);
case ChatColor.Pink:
return new Color(255, 85, 255);
case ChatColor.Yellow:
return new Color(255, 255, 85);
case ChatColor.White:
return new Color(255, 255, 255);
default:
break;
}
// Technically this means we have an invalid color code,
// should we throw an exception?
return Color.White;
}
}
}

View File

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TrueCraft.Client.Rendering
{
/// <summary>
/// Enumerates the styles of fonts.
/// </summary>
public enum FontStyle
{
/// <summary>
/// Regular font.
/// </summary>
Regular = 0,
/// <summary>
/// Bolded font.
/// </summary>
Bold = 1,
/// <summary>
/// Striked-through font.
/// </summary>
Strikethrough = 2,
/// <summary>
/// Underlined font.
/// </summary>
Underline = 3,
/// <summary>
/// Italicized font.
/// </summary>
Italic = 4,
}
}

View File

@ -97,6 +97,9 @@
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Rendering\Camera.cs" />
<Compile Include="Rendering\Font.cs" />
<Compile Include="Rendering\FontRenderer.cs" />
<Compile Include="Rendering\FontStyle.cs" />
<Compile Include="TrueCraftGame.cs" />
<Compile Include="MultiplayerClient.cs" />
<Compile Include="Handlers\PacketHandlers.cs" />
@ -104,7 +107,6 @@
<Compile Include="Interface\ChatInterface.cs" />
<Compile Include="Interface\IGameInterface.cs" />
<Compile Include="BMFont.cs" />
<Compile Include="FontRenderer.cs" />
<Compile Include="Handlers\ChunkHandler.cs" />
<Compile Include="ReadOnlyWorld.cs" />
<Compile Include="Events\ChunkEventArgs.cs" />
@ -154,10 +156,13 @@
<ItemGroup />
<ItemGroup />
<ItemGroup>
<Content Include="Content\dejavu_0.png">
<Content Include="Content\Fonts\dejavu_bold_0.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\dejavu.fnt">
<Content Include="Content\Fonts\dejavu_italic_0.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\Fonts\dejavu_regular_0.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Content\items.png">
@ -166,6 +171,15 @@
<Content Include="Content\terrain.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="Content\Fonts\dejavu_bold.fnt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Fonts\dejavu_italic.fnt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="Content\Fonts\dejavu_regular.fnt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="OpenTK.dll.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>

View File

@ -110,11 +110,12 @@ namespace TrueCraft.Client
protected override void LoadContent()
{
FontFile fontFile;
using (var f = File.OpenRead(Path.Combine(Content.RootDirectory, "dejavu.fnt")))
fontFile = FontLoader.Load(f);
var fontTexture = Content.Load<Texture2D>("dejavu_0.png");
DejaVu = new FontRenderer(fontFile, fontTexture);
DejaVu = new FontRenderer(
new Font(Content, "Fonts/DejaVu", FontStyle.Regular),
new Font(Content, "Fonts/DejaVu", FontStyle.Bold),
null, // No support for underlined or strikethrough yet. The FontRenderer will revert to using the regular font style.
null, // (I don't think BMFont has those options?)
new Font(Content, "Fonts/DejaVu", FontStyle.Italic));
Interfaces.Add(ChatInterface = new ChatInterface(Client, DejaVu));
OpaqueEffect = new BasicEffect(GraphicsDevice);