Commit 55323482 authored by mercury233's avatar mercury233

minor refactor, support png input

parent 13b7981f
......@@ -4,9 +4,10 @@ namespace ImgGen
using System.Collections.Generic;
using System.Data.SQLite;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.IO;
using System.Text.RegularExpressions;
public class DataManager
{
......@@ -30,9 +31,9 @@ namespace ImgGen
private static Font typeFont;
private static Font scaleFontNormal;
private static Font scaleFontSmall;
private static SolidBrush nameShadowBrush = new SolidBrush(Color.FromArgb(64, 64, 0));
private static SolidBrush pendBgBrush = new SolidBrush(Color.FromArgb(0, 125, 105));
private static SolidBrush textBrush = new SolidBrush(Color.FromArgb(0, 0, 0));
private static SolidBrush nameShadowBrush;
private static SolidBrush pendBgBrush;
private static SolidBrush textBrush;
private static StringFormat justifyFormat;
private static StringFormat rightAlignFormat;
......@@ -46,100 +47,8 @@ namespace ImgGen
private static string fontName = "文泉驿微米黑";
private static string numfontName = "MatrixBoldSmallCaps";
private static string spfontName = "黑体";
private static List<int> zeroStarCards = new List<int>();
public static Bitmap GetImage(int code)
{
if (!cardImages.ContainsKey(code))
{
LoadCard(code);
}
return cardImages[code];
}
private static string GetTypeString(Data data)
{
string str = "【";
switch (data.race)
{
case Race.RACE_WARRIOR: str = str + "战士族"; break;
case Race.RACE_SPELLCASTER: str = str + "魔法师族"; break;
case Race.RACE_FAIRY: str = str + "天使族"; break;
case Race.RACE_FIEND: str = str + "恶魔族"; break;
case Race.RACE_ZOMBIE: str = str + "不死族"; break;
case Race.RACE_MACHINE: str = str + "机械族"; break;
case Race.RACE_AQUA: str = str + "水族"; break;
case Race.RACE_PYRO: str = str + "炎族"; break;
case Race.RACE_ROCK: str = str + "岩石族"; break;
case Race.RACE_WINDBEAST: str = str + "鸟兽族"; break;
case Race.RACE_PLANT: str = str + "植物族"; break;
case Race.RACE_INSECT: str = str + "昆虫族"; break;
case Race.RACE_THUNDER: str = str + "雷族"; break;
case Race.RACE_DRAGON: str = str + "龙族"; break;
case Race.RACE_BEAST: str = str + "兽族"; break;
case Race.RACE_BEASTWARRIOR: str = str + "兽战士族"; break;
case Race.RACE_DINOSAUR: str = str + "恐龙族"; break;
case Race.RACE_FISH: str = str + "鱼族"; break;
case Race.RACE_SEASERPENT: str = str + "海龙族"; break;
case Race.RACE_REPTILE: str = str + "爬虫族"; break;
case Race.RACE_PSYCHO: str = str + "念动力族"; break;
case Race.RACE_DEVINE: str = str + "幻神兽族"; break;
case Race.RACE_CREATORGOD: str = str + "创造神族"; break;
case Race.RACE_WYRM: str = str + "幻龙族"; break;
case Race.RACE_CYBERS: str = str + "电子界族"; break;
default: str = str + "???"; break;
}
if (data.isType(Type.TYPE_FUSION)) str = str + "/融合";
if (data.isType(Type.TYPE_SYNCHRO)) str = str + "/同调";
if (data.isType(Type.TYPE_LINK)) str = str + "/连接";
if (data.isType(Type.TYPE_XYZ)) str = str + "/" + xyzString;
if (data.isType(Type.TYPE_RITUAL)) str = str + "/仪式";
if (data.isType(Type.TYPE_SPSUMMON)) str = str + "/特殊召唤";
if (data.isType(Type.TYPE_PENDULUM)) str = str + "/灵摆";
if (data.isType(Type.TYPE_SPIRIT)) str = str + "/灵魂";
if (data.isType(Type.TYPE_DUAL)) str = str + "/二重";
if (data.isType(Type.TYPE_UNION)) str = str + "/同盟";
if (data.isType(Type.TYPE_FLIP)) str = str + "/反转";
if (data.isType(Type.TYPE_TOON)) str = str + "/卡通";
if (data.isType(Type.TYPE_TUNER)) str = str + "/调整";
if (data.isType(Type.TYPE_EFFECT)) str = str + "/效果";
if (data.isType(Type.TYPE_NORMAL)) str = str + "/通常";
return (str + "】");
}
private static string GetStandardText(string r)
{
char[] chArray = r.ToCharArray();
for (int i = 0; i < chArray.Length; i++)
{
if ((chArray[i] > ' ') && (chArray[i] < '\x007f'))
{
chArray[i] = (char)(chArray[i] + 0xfee0);
}
if (chArray[i] == '\x00b7')
{
chArray[i] = '・';
}
}
string desc = new string(chArray);
desc = desc.Replace(Environment.NewLine, "\n");
desc = Regex.Replace(desc, @"(?<=。)([\n\s]+)(?=[①②③④⑤⑥⑦⑧⑨⑩])", "");
desc = Regex.Replace(desc, @"([\n\s]+)(?=●)", "");
return desc;
}
private static string GetPendulumDesc(string cdesc, string regx)
{
string desc = cdesc;
desc = desc.Replace(Environment.NewLine, "\n");
Regex regex = new Regex(regx, RegexOptions.Multiline);
Match mc = regex.Match(desc);
if (mc.Success)
return ((mc.Groups.Count > 1) ?
mc.Groups[1].Value : mc.Groups[0].Value);
//.Trim('\n').Replace("\n", "\n\t\t");
return "";
}
private static List<int> zeroStarCards = new List<int>();
public static void InitialDatas(string dbPath)
{
......@@ -169,10 +78,14 @@ namespace ImgGen
scaleFontNormal = new Font(numfontName, 30, GraphicsUnit.Pixel);
scaleFontSmall = new Font(numfontName, 27, GraphicsUnit.Pixel);
nameShadowBrush = new SolidBrush(Color.FromArgb(64, 64, 0));
pendBgBrush = new SolidBrush(Color.FromArgb(0, 125, 105));
textBrush = new SolidBrush(Color.FromArgb(0, 0, 0));
justifyFormat = new StringFormat(StringFormat.GenericTypographic);
justifyFormat.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces;
justifyFormat.FormatFlags |= StringFormatFlags.FitBlackBox;
rightAlignFormat= new StringFormat();
rightAlignFormat = new StringFormat();
rightAlignFormat.Alignment = StringAlignment.Far;
bTemplates[0] = new Bitmap("./textures/card_spell.png");
......@@ -217,6 +130,15 @@ namespace ImgGen
}
}
public static Bitmap GetImage(int code)
{
if (!cardImages.ContainsKey(code))
{
LoadCard(code);
}
return cardImages[code];
}
private static int LoadCard(int code)
{
lock (locker)
......@@ -233,8 +155,11 @@ namespace ImgGen
try
{
conn.Open();
SQLiteCommand command = new SQLiteCommand(string.Format("select * from datas where id={0}", code), conn);
SQLiteDataReader reader = command.ExecuteReader();
SQLiteCommand command = new SQLiteCommand(conn);
SQLiteDataReader reader;
command.CommandText = string.Format("select * from datas where id={0}", code);
reader = command.ExecuteReader();
if (reader.Read())
{
data.code = reader.GetInt32(0);
......@@ -248,8 +173,8 @@ namespace ImgGen
data.attribute = (Attribute)reader.GetInt32(9);
}
reader.Close();
string str = string.Format("select * from texts where id={0}", code);
command.CommandText = str;
command.CommandText = string.Format("select * from texts where id={0}", code);
reader = command.ExecuteReader();
if (reader.Read())
{
......@@ -269,52 +194,86 @@ namespace ImgGen
if (!cardImages.ContainsKey(code))
{
Bitmap bitmap;
bitmap = DrawImage(code, data, text);
bitmap = DrawCard(data, text);
cardImages.Add(code, bitmap);
}
return 0;
}
}
private static Bitmap DrawImage(int code, Data data, Text text)
private static string FormatCardDesc(string r)
{
Bitmap bitmap = new Bitmap(400, 580);
Graphics graphics = Graphics.FromImage(bitmap);
graphics.CompositingMode = CompositingMode.SourceOver;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
try
char[] chArray = r.ToCharArray();
for (int i = 0; i < chArray.Length; i++)
{
Bitmap image = new Bitmap("./pico/" + code.ToString() + ".jpg");
if (data.isType(Type.TYPE_PENDULUM))
if ((chArray[i] > ' ') && (chArray[i] < '\x007f')) // 半角转全角
{
if (image.Width == 347 && image.Height == 444)
graphics.DrawImage(image, 26, 103, 347, 444);
else
{
graphics.FillRectangle(pendBgBrush, new Rectangle(23, 362, 354, 189));
float ar = image.Width / image.Height;
if ((ar >= 1.3) && (ar <= 1.4))
graphics.DrawImage(image, 26, 103, 347, 260);
else
graphics.DrawImage(image, new Rectangle(26, 103, 347, 260), new Rectangle(0, 0, image.Width, image.Width * 260 / 347), GraphicsUnit.Pixel);
}
chArray[i] = (char)(chArray[i] + 0xfee0);
}
else
if (chArray[i] == '\x00b7') // another middle dot
{
graphics.DrawImage(image, 48, 106, 304, 304);
chArray[i] = '・';
}
}
string desc = new string(chArray);
desc = desc.Replace(Environment.NewLine, "\n");
desc = Regex.Replace(desc, @"(?<=。)([\n\s]+)(?=[①②③④⑤⑥⑦⑧⑨⑩])", ""); // 去掉效果编号前的换行
desc = Regex.Replace(desc, @"([\n\s]+)(?=●)", ""); // 去掉●号前的换行
return desc;
}
private static string FormatCardName(string r)
{
return r.Replace('\x00b7', '・'); // another middle dot
}
private static string GetMonsterDesc(string desc, string regex)
{
// 拆分灵摆卡的灵摆效果和怪兽效果
Regex r = new Regex(regex, RegexOptions.Multiline);
Match match = r.Match(desc);
if (match.Success)
return (match.Groups.Count > 1) ? match.Groups[1].Value : match.Groups[0].Value;
return "";
}
private static void DrawPicture(Graphics graphics, Data data)
{
Bitmap image;
string filename = "./pico/" + data.code.ToString() + ".png";
if (!File.Exists(filename))
filename = "./pico/" + data.code.ToString() + ".jpg";
try
{
image = new Bitmap(filename);
}
catch (Exception e)
{
Console.WriteLine("Error prasing {0} {1}", data.code, e);
return;
}
if (data.isType(Type.TYPE_PENDULUM))
{
if (image.Width == 347 && image.Height == 444)
graphics.DrawImage(image, 26, 103, 347, 444);
else
{
graphics.FillRectangle(pendBgBrush, new Rectangle(23, 362, 354, 189));
float ar = image.Width / image.Height;
if ((ar >= 1.3) && (ar <= 1.4))
graphics.DrawImage(image, 26, 103, 347, 260);
else
graphics.DrawImage(image, new Rectangle(26, 103, 347, 260), new Rectangle(0, 0, image.Width, image.Width * 260 / 347), GraphicsUnit.Pixel);
}
}
else
{
graphics.DrawImage(image, 48, 106, 304, 304);
}
}
private static void DrawTemplate(Graphics graphics, Data data)
{
Bitmap template;
if (data.isType(Type.TYPE_SPELL))
{
......@@ -380,156 +339,217 @@ namespace ImgGen
template = new Bitmap(bTemplates[8]);
}
graphics.DrawImage(template, 0, 0, 400, 580);
}
text.text = GetStandardText(text.text);
if (data.isType(Type.TYPE_MONSTER))
private static void DrawStars(Graphics graphics, Data data)
{
if (!zeroStarCards.Contains(data.code))
{
if (!zeroStarCards.Contains(data.code))
int nStar;
int level = data.level & 0xff;
if (data.isType(Type.TYPE_XYZ))
{
int nStar;
int level = data.level & 0xff;
if (data.isType(Type.TYPE_XYZ))
for (nStar = 0; nStar < level; nStar++)
{
for (nStar = 0; nStar < level; nStar++)
{
graphics.DrawImage(bStar[1], (int)41 + (26.5f * nStar), 69, 28, 28);
}
graphics.DrawImage(bStar[1], 41f + (26.5f * nStar), 69, 28, 28);
}
else if (!data.isType(Type.TYPE_LINK))
{
for (nStar = 0; nStar < level; nStar++)
{
graphics.DrawImage(bStar[0], (int)332 - (26.5f * nStar), 69, 28, 28);
}
}
}
int nAttr = -1;
if (data.attribute == Attribute.ATTRIBUTE_EARTH) nAttr = 0;
else if (data.attribute == Attribute.ATTRIBUTE_WATER) nAttr = 1;
else if (data.attribute == Attribute.ATTRIBUTE_FIRE) nAttr = 2;
else if (data.attribute == Attribute.ATTRIBUTE_WIND) nAttr = 3;
else if (data.attribute == Attribute.ATTRIBUTE_LIGHT) nAttr = 4;
else if (data.attribute == Attribute.ATTRIBUTE_DARK) nAttr = 5;
else if (data.attribute == Attribute.ATTRIBUTE_DEVINE) nAttr = 6;
if (nAttr >= 0)
graphics.DrawImage(bAttributes[nAttr], 334, 28, 36, 36);
if (data.attack >= 0)
{
graphics.DrawString(data.attack.ToString(), numFont, Brushes.Black, new Rectangle(248, 530, 42, 17), rightAlignFormat);
}
else
{
graphics.DrawString("?", numUnknownFont, textBrush, 274, 527);
}
if (data.isType(Type.TYPE_LINK))
else if (!data.isType(Type.TYPE_LINK))
{
graphics.DrawImage(bLinkNums[data.level - 1], 353, 530, 13, 13);
}
else
{
if (data.defence >= 0)
for (nStar = 0; nStar < level; nStar++)
{
graphics.DrawString(data.defence.ToString(), numFont, Brushes.Black, new Rectangle(329, 530, 42, 17), rightAlignFormat);
}
else
{
graphics.DrawString("?", numUnknownFont, textBrush, 355, 527);
graphics.DrawImage(bStar[0], 332f - (26.5f * nStar), 69, 28, 28);
}
}
}
}
string type_string = GetTypeString(data);
float tWidth = graphics.MeasureString(type_string, typeFont).Width;
float sx1 = 1f;
if (tWidth > 330f)
{
sx1 *= 330f / tWidth;
}
graphics.ScaleTransform(sx1, 1f);
graphics.DrawString(type_string, typeFont, Brushes.Black, 26, 438);
graphics.ResetTransform();
private static void DrawAttributes(Graphics graphics, Data data)
{
int nAttr = -1;
if (data.attribute == Attribute.ATTRIBUTE_EARTH) nAttr = 0;
else if (data.attribute == Attribute.ATTRIBUTE_WATER) nAttr = 1;
else if (data.attribute == Attribute.ATTRIBUTE_FIRE) nAttr = 2;
else if (data.attribute == Attribute.ATTRIBUTE_WIND) nAttr = 3;
else if (data.attribute == Attribute.ATTRIBUTE_LIGHT) nAttr = 4;
else if (data.attribute == Attribute.ATTRIBUTE_DARK) nAttr = 5;
else if (data.attribute == Attribute.ATTRIBUTE_DEVINE) nAttr = 6;
if (nAttr >= 0)
graphics.DrawImage(bAttributes[nAttr], 334, 28, 36, 36);
}
string monster_effect = text.text;
if (data.isType(Type.TYPE_PENDULUM))
{
monster_effect = GetPendulumDesc(text.text, regex_monster);
}
DrawJustifiedText(graphics, monster_effect, 33, 453, 335, 75);
private static void DrawAtkDef(Graphics graphics, Data data)
{
if (data.attack >= 0)
{
graphics.DrawString(data.attack.ToString(), numFont, textBrush, new Rectangle(248, 530, 42, 17), rightAlignFormat);
}
else
{
graphics.DrawString("?", numUnknownFont, textBrush, 274, 527);
}
if (data.isType(Type.TYPE_PENDULUM))
{
int lscale = (data.level >> 0x18) & 0xff;
int rscale = (data.level >> 0x10) & 0xff;
if (lscale > 9)
{
graphics.DrawString("1", scaleFontSmall, Brushes.Black, 26, 397);
graphics.DrawString((lscale - 10).ToString(), scaleFontSmall, Brushes.Black, 37, 397);
}
else
{
graphics.DrawString(lscale.ToString(), scaleFontNormal, Brushes.Black, 31, 396);
}
if (rscale > 9)
{
graphics.DrawString("1", scaleFontSmall, Brushes.Black, 341, 397);
graphics.DrawString((rscale - 10).ToString(), scaleFontSmall, Brushes.Black, 352, 397);
}
else
{
graphics.DrawString(rscale.ToString(), scaleFontNormal, Brushes.Black, 346, 396);
}
string pendulum_effect = GetPendulumDesc(text.text, regex_pendulum);
DrawJustifiedText(graphics, pendulum_effect, 65, 369, 272, 58);
}
if (data.isType(Type.TYPE_LINK))
{
graphics.DrawImage(bLinkNums[data.level - 1], 353, 530, 13, 13);
}
else
{
if (data.isType(Type.TYPE_SPELL))
if (data.defence >= 0)
{
int nType = 0;
if (data.isType(Type.TYPE_QUICKPLAY)) nType = 1;
if (data.isType(Type.TYPE_CONTINUOUS)) nType = 2;
if (data.isType(Type.TYPE_EQUIP)) nType = 3;
if (data.isType(Type.TYPE_FIELD)) nType = 4;
if (data.isType(Type.TYPE_RITUAL)) nType = 5;
graphics.DrawImage(bType[nType], 221, 69, 137, 26);
graphics.DrawString(data.defence.ToString(), numFont, textBrush, new Rectangle(329, 530, 42, 17), rightAlignFormat);
}
else if (data.isType(Type.TYPE_TRAP))
else
{
int nType = 6;
if (data.isType(Type.TYPE_CONTINUOUS)) nType = 7;
if (data.isType(Type.TYPE_COUNTER)) nType = 8;
graphics.DrawImage(bType[nType], 243, 68, 115, 27);
graphics.DrawString("?", numUnknownFont, textBrush, 355, 527);
}
DrawJustifiedText(graphics, text.text, 33, 439, 335, 108);
}
if (data.isType(Type.TYPE_LINK))
}
private static void DrawMonsterType(Graphics graphics, Data data)
{
string str = "【";
switch (data.race)
{
case Race.RACE_WARRIOR: str += "战士族"; break;
case Race.RACE_SPELLCASTER: str += "魔法师族"; break;
case Race.RACE_FAIRY: str += "天使族"; break;
case Race.RACE_FIEND: str += "恶魔族"; break;
case Race.RACE_ZOMBIE: str += "不死族"; break;
case Race.RACE_MACHINE: str += "机械族"; break;
case Race.RACE_AQUA: str += "水族"; break;
case Race.RACE_PYRO: str += "炎族"; break;
case Race.RACE_ROCK: str += "岩石族"; break;
case Race.RACE_WINDBEAST: str += "鸟兽族"; break;
case Race.RACE_PLANT: str += "植物族"; break;
case Race.RACE_INSECT: str += "昆虫族"; break;
case Race.RACE_THUNDER: str += "雷族"; break;
case Race.RACE_DRAGON: str += "龙族"; break;
case Race.RACE_BEAST: str += "兽族"; break;
case Race.RACE_BEASTWARRIOR: str += "兽战士族"; break;
case Race.RACE_DINOSAUR: str += "恐龙族"; break;
case Race.RACE_FISH: str += "鱼族"; break;
case Race.RACE_SEASERPENT: str += "海龙族"; break;
case Race.RACE_REPTILE: str += "爬虫族"; break;
case Race.RACE_PSYCHO: str += "念动力族"; break;
case Race.RACE_DEVINE: str += "幻神兽族"; break;
case Race.RACE_CREATORGOD: str += "创造神族"; break;
case Race.RACE_WYRM: str += "幻龙族"; break;
case Race.RACE_CYBERS: str += "电子界族"; break;
default: str += "???"; break;
}
if (data.isType(Type.TYPE_FUSION)) str += "/融合";
if (data.isType(Type.TYPE_SYNCHRO)) str += "/同调";
if (data.isType(Type.TYPE_LINK)) str += "/连接";
if (data.isType(Type.TYPE_XYZ)) str = str + "/" + xyzString;
if (data.isType(Type.TYPE_RITUAL)) str += "/仪式";
if (data.isType(Type.TYPE_SPSUMMON)) str += "/特殊召唤";
if (data.isType(Type.TYPE_PENDULUM)) str += "/灵摆";
if (data.isType(Type.TYPE_SPIRIT)) str += "/灵魂";
if (data.isType(Type.TYPE_DUAL)) str += "/二重";
if (data.isType(Type.TYPE_UNION)) str += "/同盟";
if (data.isType(Type.TYPE_FLIP)) str += "/反转";
if (data.isType(Type.TYPE_TOON)) str += "/卡通";
if (data.isType(Type.TYPE_TUNER)) str += "/调整";
if (data.isType(Type.TYPE_EFFECT)) str += "/效果";
if (data.isType(Type.TYPE_NORMAL)) str += "/通常";
str += "】";
float tWidth = graphics.MeasureString(str, typeFont).Width;
float sx1 = 1f;
if (tWidth > 330f)
{
sx1 *= 330f / tWidth;
}
graphics.ScaleTransform(sx1, 1f);
graphics.DrawString(str, typeFont, textBrush, 26, 438);
graphics.ResetTransform();
}
private static void DrawScales(Graphics graphics, Data data)
{
int lscale = (data.level >> 0x18) & 0xff;
int rscale = (data.level >> 0x10) & 0xff;
if (lscale > 9)
{
graphics.DrawString("1", scaleFontSmall, textBrush, 26, 397);
graphics.DrawString((lscale - 10).ToString(), scaleFontSmall, textBrush, 37, 397);
}
else
{
graphics.DrawString(lscale.ToString(), scaleFontNormal, textBrush, 31, 396);
}
if (rscale > 9)
{
graphics.DrawString("1", scaleFontSmall, textBrush, 341, 397);
graphics.DrawString((rscale - 10).ToString(), scaleFontSmall, textBrush, 352, 397);
}
else
{
graphics.DrawString(rscale.ToString(), scaleFontNormal, textBrush, 346, 396);
}
}
private static void DrawMonsterEffect(Graphics graphics, string text)
{
DrawJustifiedText(graphics, text, 33, 453, 335, 75);
}
private static void DrawPendulumEffect(Graphics graphics, string text)
{
DrawJustifiedText(graphics, text, 65, 369, 272, 58);
}
private static void DrawSpellTrapEffect(Graphics graphics, string text)
{
DrawJustifiedText(graphics, text, 33, 439, 335, 108);
}
private static void DrawSpellTrapType(Graphics graphics, Data data)
{
if (data.isType(Type.TYPE_SPELL))
{
LinkMarker lm = (LinkMarker)data.defence;
if ((lm & LinkMarker.LINK_MARKER_BOTTOM_LEFT) > 0)
graphics.DrawImage(bLinkMarkers[0], 34, 387, 38, 37);
if ((lm & LinkMarker.LINK_MARKER_BOTTOM) > 0)
graphics.DrawImage(bLinkMarkers[1], 163, 406, 73, 25);
if ((lm & LinkMarker.LINK_MARKER_BOTTOM_RIGHT) > 0)
graphics.DrawImage(bLinkMarkers[2], 329, 387, 37, 37);
if ((lm & LinkMarker.LINK_MARKER_LEFT) > 0)
graphics.DrawImage(bLinkMarkers[3], 27, 222, 24, 72);
if ((lm & LinkMarker.LINK_MARKER_RIGHT) > 0)
graphics.DrawImage(bLinkMarkers[5], 349, 221, 24, 72);
if ((lm & LinkMarker.LINK_MARKER_TOP_LEFT) > 0)
graphics.DrawImage(bLinkMarkers[6], 34, 91, 37, 37);
if ((lm & LinkMarker.LINK_MARKER_TOP) > 0)
graphics.DrawImage(bLinkMarkers[7], 163, 85, 74, 23);
if ((lm & LinkMarker.LINK_MARKER_TOP_RIGHT) > 0)
graphics.DrawImage(bLinkMarkers[8], 329, 91, 37, 37);
}
string nametext = text.name.Replace('\x00b7', '・');
float width = graphics.MeasureString(nametext, nameFont).Width;
int nType = 0;
if (data.isType(Type.TYPE_QUICKPLAY)) nType = 1;
if (data.isType(Type.TYPE_CONTINUOUS)) nType = 2;
if (data.isType(Type.TYPE_EQUIP)) nType = 3;
if (data.isType(Type.TYPE_FIELD)) nType = 4;
if (data.isType(Type.TYPE_RITUAL)) nType = 5;
graphics.DrawImage(bType[nType], 221, 69, 137, 26);
}
else if (data.isType(Type.TYPE_TRAP))
{
int nType = 6;
if (data.isType(Type.TYPE_CONTINUOUS)) nType = 7;
if (data.isType(Type.TYPE_COUNTER)) nType = 8;
graphics.DrawImage(bType[nType], 243, 68, 115, 27);
}
}
private static void DrawLinkMarkers(Graphics graphics, Data data)
{
LinkMarker lm = (LinkMarker)data.defence;
if ((lm & LinkMarker.LINK_MARKER_BOTTOM_LEFT) > 0)
graphics.DrawImage(bLinkMarkers[0], 34, 387, 38, 37);
if ((lm & LinkMarker.LINK_MARKER_BOTTOM) > 0)
graphics.DrawImage(bLinkMarkers[1], 163, 406, 73, 25);
if ((lm & LinkMarker.LINK_MARKER_BOTTOM_RIGHT) > 0)
graphics.DrawImage(bLinkMarkers[2], 329, 387, 37, 37);
if ((lm & LinkMarker.LINK_MARKER_LEFT) > 0)
graphics.DrawImage(bLinkMarkers[3], 27, 222, 24, 72);
if ((lm & LinkMarker.LINK_MARKER_RIGHT) > 0)
graphics.DrawImage(bLinkMarkers[5], 349, 221, 24, 72);
if ((lm & LinkMarker.LINK_MARKER_TOP_LEFT) > 0)
graphics.DrawImage(bLinkMarkers[6], 34, 91, 37, 37);
if ((lm & LinkMarker.LINK_MARKER_TOP) > 0)
graphics.DrawImage(bLinkMarkers[7], 163, 85, 74, 23);
if ((lm & LinkMarker.LINK_MARKER_TOP_RIGHT) > 0)
graphics.DrawImage(bLinkMarkers[8], 329, 91, 37, 37);
}
private static void DrawName(Graphics graphics, string name)
{
float width = graphics.MeasureString(name, nameFont).Width;
float sx = 1f;
if (width > 310f)
{
......@@ -537,9 +557,59 @@ namespace ImgGen
}
graphics.TranslateTransform(26, 28);
graphics.ScaleTransform(sx, 1f);
graphics.DrawString(nametext, nameFont, nameShadowBrush, 0f, 0f);
graphics.DrawString(nametext, nameFont, Brushes.Gold, 1f, 1f);
graphics.DrawString(name, nameFont, nameShadowBrush, 0f, 0f);
graphics.DrawString(name, nameFont, Brushes.Gold, 1f, 1f);
graphics.ResetTransform();
}
private static Bitmap DrawCard(Data data, Text text)
{
Bitmap bitmap = new Bitmap(400, 580);
Graphics graphics = Graphics.FromImage(bitmap);
graphics.CompositingMode = CompositingMode.SourceOver;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
graphics.CompositingQuality = CompositingQuality.HighQuality;
graphics.SmoothingMode = SmoothingMode.AntiAlias;
graphics.TextRenderingHint = TextRenderingHint.AntiAlias;
string name = FormatCardName(text.name);
string desc = FormatCardDesc(text.text);
DrawPicture(graphics, data);
DrawTemplate(graphics, data);
DrawName(graphics, name);
if (data.isType(Type.TYPE_MONSTER))
{
DrawStars(graphics, data);
DrawAttributes(graphics, data);
DrawMonsterType(graphics, data);
DrawAtkDef(graphics, data);
if (data.isType(Type.TYPE_PENDULUM))
{
DrawScales(graphics, data);
DrawPendulumEffect(graphics, GetMonsterDesc(desc, regex_pendulum));
DrawMonsterEffect(graphics, GetMonsterDesc(desc, regex_monster));
}
else
{
DrawMonsterEffect(graphics, desc);
}
if (data.isType(Type.TYPE_LINK))
{
DrawLinkMarkers(graphics, data);
}
}
else
{
DrawSpellTrapType(graphics, data);
DrawSpellTrapEffect(graphics, desc);
}
return bitmap;
}
......@@ -553,14 +623,15 @@ namespace ImgGen
return size / 5f;
}
private static void DrawJustifiedText(Graphics graphics, string text, float x, float y, float w, float h)
private static void DrawJustifiedText(Graphics graphics, string text, float areaX, float areaY, float areaWidth, float areaHeight)
{
float size = txtFont.Size;
var font = new Font(txtFont.Name, size, txtFont.Style, txtFont.Unit);
List<string> lines = new List<string> { };
List<float> paddings = new List<float> { };
List<float> paddings = new List<float> { }; // 每行文字两端对齐须补充的像素
while (true)
{
// 自动缩小字体直到寻找到行数不溢出区域的值
int pos = 0;
string line = "";
float linewidth = 0;
......@@ -580,15 +651,17 @@ namespace ImgGen
SizeF doublesize = graphics.MeasureString(word + nextword, font, 99, justifyFormat);
SizeF singlesize = graphics.MeasureString(word, font, 99, justifyFormat);
float wordwidth = doublesize.Width - singlesize.Width;
if (linewidth + wordwidth > w || (non_start_chars.Contains(nextword) && linewidth + doublesize.Width > w) || (non_end_chars.Contains(nextword) && linewidth + doublesize.Width < w && linewidth + doublesize.Width + size > w))
if (linewidth + wordwidth > areaWidth
|| (non_start_chars.Contains(nextword) && linewidth + doublesize.Width > areaWidth)
|| (non_end_chars.Contains(nextword) && linewidth + doublesize.Width < areaWidth && linewidth + doublesize.Width + size > areaWidth))
{
lines.Add(line);
paddings.Add(w - linewidth);
paddings.Add(areaWidth - linewidth);
line = "";
linewidth = 0;
}
line += word;
linewidth = linewidth + wordwidth;
linewidth += wordwidth;
pos++;
}
if (linewidth > 0)
......@@ -596,15 +669,15 @@ namespace ImgGen
lines.Add(line);
paddings.Add(0);
}
if (lines.Count * (size + GetLineSpacing(size)) <= h - GetLineSpacing(size))
if (lines.Count * (size + GetLineSpacing(size)) <= areaHeight - GetLineSpacing(size))
break;
size -= 0.5f;
font = new Font(txtFont.Name, size, txtFont.Style, txtFont.Unit);
lines.Clear();
paddings.Clear();
}
float dx = x;
float dy = y;
float dx = areaX;
float dy = areaY;
for (int i = 0; i < lines.Count; i++)
{
string line = lines[i];
......@@ -613,6 +686,7 @@ namespace ImgGen
{
string word = line.Substring(pos, 1);
string nextword = GetNextWord(line, pos);
if (word == "●")
{
Font spFont = new Font(spfontName, size * 0.9f, txtFont.Style, txtFont.Unit);
......@@ -630,12 +704,13 @@ namespace ImgGen
}
else
graphics.DrawString(word, font, textBrush, dx, dy, justifyFormat);
SizeF doublesize = graphics.MeasureString(word + nextword, font, 99, justifyFormat);
SizeF singlesize = graphics.MeasureString(word, font, 99, justifyFormat);
float dw = doublesize.Width - singlesize.Width;
dx += dw + exspace;
}
dx = x;
dx = areaX;
dy += size + GetLineSpacing(size);
}
}
......@@ -646,23 +721,20 @@ namespace ImgGen
{
Bitmap b = new Bitmap(newWidth, newHeight);
Graphics graphics = Graphics.FromImage(b);
//合成:高质量,低速度
graphics.CompositingQuality = CompositingQuality.HighQuality;
//去除锯齿
graphics.SmoothingMode = SmoothingMode.HighQuality;
//偏移:高质量,低速度
graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
//插补算法
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
Rectangle newRect = new Rectangle(0, 0, newWidth, newHeight);
Rectangle srcRect = new Rectangle(0, 0, sourceBitmap.Width, sourceBitmap.Height);
graphics.DrawImage(sourceBitmap, newRect, srcRect, GraphicsUnit.Pixel);
graphics.Dispose();
return b;
}
return sourceBitmap;
return null;
}
}
}
namespace ImgGen
{
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
......@@ -35,7 +36,9 @@
EncoderParameters encoderParams = new EncoderParameters(1);
EncoderParameter parameter = new EncoderParameter(quality, 90L);
encoderParams.Param[0] = parameter;
string[] files = Directory.GetFiles("./pico", "*.jpg");
List<string> files = new List<string>();
files.AddRange(Directory.GetFiles("./pico", "*.png"));
files.AddRange(Directory.GetFiles("./pico", "*.jpg"));
bool generateLarge = System.Configuration.ConfigurationManager.AppSettings["GenerateLarge"] == "False" ? false : true; // true if AppSettings null
bool generateSmall = System.Configuration.ConfigurationManager.AppSettings["GenerateSmall"] == "True" ? true : false;
bool generateThumb = System.Configuration.ConfigurationManager.AppSettings["GenerateThumb"] == "True" ? true : false;
......@@ -48,7 +51,7 @@
foreach (string str in files)
{
int code = int.Parse(Path.GetFileNameWithoutExtension(str));
string fileName = Path.GetFileName(str);
string fileName = code.ToString() + ".jpg";
Console.WriteLine("Generating {0}", fileName);
Bitmap image = DataManager.GetImage(code);
if (generateLarge)
......
YGOPro卡图生成工具
YGOPro卡图生成工具
------------------------------------------------
使用:
放到游戏主目录Gen目录,即执行目录上级有cards.cdb
使用:
放到游戏主目录Gen目录,即执行目录上级有cards.cdb
必备字体:
文泉驿微米黑
必备字体:
文泉驿微米黑
生成卡图:
在执行目录创建pico目录,放入对应密码的中间图规格的jpg图片,运行ImgGen.exe,即可在picn目录内生成卡图。
生成卡图:
在执行目录创建pico目录,放入对应密码的中间图规格的jpg图片,运行ImgGen.exe,即可在picn目录内生成卡图。
普通中间图尺寸:256x256
灵摆中间图尺寸:292x217
普通中间图尺寸:304x304
灵摆中间图尺寸:347x260
参数:
参数:
自定义数据库
自定义数据库
ImgGen.exe ..\expansions\pre-release.cdb
配置:
配置:
XyzString
自定义Xyz的翻译,默认为超量
自定义Xyz的翻译,默认为超量
FontName
自定义字体,默认为文泉驿微米黑
自定义字体,默认为文泉驿微米黑
ZeroStarCards
红龙等没有星星的怪兽卡,用逗号分开
红龙等没有星星的怪兽卡,用逗号分开
GenerateLarge
生成大图,默认为True
生成大图,默认为True
GenerateSmall
生成小图,默认为False
生成小图,默认为False
GenerateThumb
生成缩略图,默认为False
生成缩略图,默认为False
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment