Skip to content

Commit

Permalink
Merge pull request #273 from DarkSynopsis/master
Browse files Browse the repository at this point in the history
Yokai Watch Game Handler Update
  • Loading branch information
IcySon55 authored Aug 21, 2017
2 parents df869b8 + 2e20e2d commit 5418e0d
Show file tree
Hide file tree
Showing 12 changed files with 536 additions and 16 deletions.
160 changes: 144 additions & 16 deletions src/game/game_yokai_watch/Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@

namespace game_yokai_watch
{
public enum Scenes
{
Dialog,
CutsceneBottom
}

public class Handler : IGameHandler
{
#region Properties
Expand All @@ -18,7 +24,7 @@ public class Handler : IGameHandler
public Image Icon => Resources.icon;

// Feature Support
public bool HandlerHasSettings => false;
public bool HandlerHasSettings => true;
public bool HandlerCanGeneratePreviews => true;

#endregion
Expand All @@ -30,10 +36,11 @@ public class Handler : IGameHandler
["\x5c\x6e"] = "\r\n",
};

Dictionary<string, string> _previewPairs = new Dictionary<string, string>
{
["<PNAME>"] = "Nate"
};
// Old Preview Dictionary
//Dictionary<string, string> _previewPairs = new Dictionary<string, string>
//{
//["<PNAME>"] = Properties.Settings.Default.PlayerName
//};

static Lazy<XF> fontInitializer = new Lazy<XF>(() => new XF(new MemoryStream(Resources.ft_nrm)));
static XF font => fontInitializer.Value;
Expand All @@ -49,33 +56,72 @@ public string GetRawString(string kuriimuString)
}

Bitmap textBox = new Bitmap(Resources.blank_top);
Bitmap csBTM = new Bitmap(Resources.cutscene_bottom);

// Previewer
public IList<Bitmap> GeneratePreviews(TextEntry entry)
{
var pages = new List<Bitmap>();
if (entry?.EditedText == null) return pages;

string kuriimuString = _previewPairs.Aggregate(GetKuriimuString(entry.EditedText), (s, pair) => s.Replace(pair.Key, pair.Value));
//string kuriimuString = _previewPairs.Aggregate(GetKuriimuString(entry.EditedText), (s, pair) => s.Replace(pair.Key, pair.Value));

Bitmap img = new Bitmap(textBox.Width, textBox.Height);
// Replaces the need for Preview Dictionary for the time being.
string kuriimuString = GetKuriimuString(entry.EditedText).Replace("<PNAME>", Properties.Settings.Default.PlayerName == string.Empty ? "Nate" : Properties.Settings.Default.PlayerName);

using (Graphics gfx = Graphics.FromImage(img))
//Bitmap img = new Bitmap(textBox.Width, textBox.Height);
Bitmap img = new Bitmap(1, 1);

switch (Enum.Parse(typeof(Scenes), Properties.Settings.Default.Scene))
{
gfx.DrawImage(textBox, 0, 0);
case Scenes.Dialog:
img = new Bitmap(textBox.Width, textBox.Height);
break;

case Scenes.CutsceneBottom:
img = new Bitmap(csBTM.Width, csBTM.Height);
break;
}

using (Graphics gfx = Graphics.FromImage(img))
{
gfx.SmoothingMode = SmoothingMode.HighQuality;
gfx.InterpolationMode = InterpolationMode.Bicubic;
gfx.PixelOffsetMode = PixelOffsetMode.HighQuality;

RectangleF rectText = new RectangleF(40, 43, 370, 100);

//RectangleF rectText = new RectangleF(40, 43, 370, 100);
RectangleF rectText = new RectangleF(0, 0, 0, 0);
Color colorDefault = Color.FromArgb(255, 0, 0, 0);

switch (Enum.Parse(typeof(Scenes), Properties.Settings.Default.Scene))
{
case Scenes.Dialog:
gfx.DrawImage(textBox, 0, 0);
rectText = new RectangleF(40, 43, 370, 100);
colorDefault = Color.FromArgb(255, 0, 0, 0); // Black
break;

case Scenes.CutsceneBottom:
gfx.DrawImage(csBTM, 0, 0);
rectText = new RectangleF(25, 85, 370, 100);
colorDefault = Color.FromArgb(255, 255, 255, 255); // White
break;
}

float scaleDefault = 1.0f;
float scaleCurrent = scaleDefault;
float x = rectText.X, pX = x;
float y = rectText.Y, pY = y;
float fontSize = 0.85f;

bool furigana = false;
bool furiganaUpper = false;
float furiganaLowerWidth = 0;
float furiganaUpperWidth = 0;
float lowerOffset = 0;
float upperOffset = 0;
float bkX = 0;

for (int i = 0; i < kuriimuString.Length; i++)
{
if (kuriimuString[i] == '<')
Expand All @@ -97,13 +143,90 @@ public IList<Bitmap> GeneratePreviews(TextEntry entry)
{
continue;
}
else
else if (kuriimuString[i].ToString() == "[")
{
XF.CharacterMap charMap = font.GetCharacterMap(kuriimuString[i], false);
bkX = x;
furigana = true;

//getting char length from lower and upper furigana string in px
furiganaLowerWidth = 0;
furiganaUpperWidth = 0;
int tmp = i + 1;
bool fin = false;
bool furiganaTmp = false;
bool draw = false;
while (fin == false)
{
if (tmp >= kuriimuString.Length)
{
if (fin == false)
{
draw = true;
}
break;
}

if (kuriimuString[tmp].ToString() == "/")
{
furiganaTmp = true;
tmp++;
}
else if (kuriimuString[tmp].ToString() == "]")
{
fin = true;
if (furiganaTmp == false)
{
draw = true;
}
}
else
{
XF.CharacterMap charMaptmp = font.GetCharacterMap(kuriimuString[tmp++], furiganaTmp);
var t1 = (furiganaTmp) ? furiganaUpperWidth += charMaptmp.CharWidth : furiganaLowerWidth += charMaptmp.CharWidth;
}
}

font.DrawCharacter(kuriimuString[i], colorDefault, gfx, x, y, false);
x += charMap.CharWidth;
//setting furigana offset
var t2 = (furiganaLowerWidth > furiganaUpperWidth) ? upperOffset = (furiganaLowerWidth - furiganaUpperWidth) / 2 : lowerOffset = (furiganaUpperWidth - furiganaLowerWidth) / 2;
if (furiganaLowerWidth < furiganaUpperWidth)
{
x += lowerOffset;
}

if (draw == false)
{
continue;
}
}
else if (kuriimuString[i].ToString() == "/")
{
if (furigana)
{
furiganaUpper = true;
y -= 7;
var t3 = (furiganaUpperWidth < furiganaLowerWidth) ? x = bkX + upperOffset : x = bkX;
continue;
}
}
else if (kuriimuString[i].ToString() == "]")
{
if (furiganaUpper)
{
var t4 = (furiganaUpperWidth > furiganaLowerWidth) ? x = bkX + furiganaUpperWidth : x = bkX + furiganaLowerWidth;
y += 7;
furiganaUpper = false;
furigana = false;
upperOffset = 0;
lowerOffset = 0;
continue;
}
}

XF.CharacterMap charMap = font.GetCharacterMap(kuriimuString[i], furiganaUpper);

//draw regular character
font.DrawCharacter(kuriimuString[i], colorDefault, gfx, x, y, furiganaUpper);
x += charMap.CharWidth-fontSize;
}
}

Expand All @@ -112,6 +235,11 @@ public IList<Bitmap> GeneratePreviews(TextEntry entry)
return pages;
}

public bool ShowSettings(Icon icon) => false;
public bool ShowSettings(Icon icon)
{
var settings = new Settings(icon);
settings.ShowDialog();
return settings.HasChanges;
}
}
}
10 changes: 10 additions & 0 deletions src/game/game_yokai_watch/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/game/game_yokai_watch/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@
<data name="blank_top" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\blank_top.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="cutscene_bottom" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\cutscene_bottom.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="ft_nrm" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\ft_nrm.xf;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
Expand Down
24 changes: 24 additions & 0 deletions src/game/game_yokai_watch/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions src/game/game_yokai_watch/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@
<Setting Name="PluginName" Type="System.String" Scope="Application">
<Value Profile="(Default)">Yokai Watch</Value>
</Setting>
<Setting Name="PlayerName" Type="System.String" Scope="User">
<Value Profile="(Default)">Nate</Value>
</Setting>
<Setting Name="Scene" Type="System.String" Scope="User">
<Value Profile="(Default)">Dialog</Value>
</Setting>
</Settings>
</SettingsFile>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified src/game/game_yokai_watch/Resources/ft_nrm.xf
Binary file not shown.
Loading

0 comments on commit 5418e0d

Please sign in to comment.