Commit bc0829bf authored by JoyJ's avatar JoyJ

code format

parent c95bd343
......@@ -28,7 +28,7 @@ public partial class CodeEditForm : DockContent, IEditForm
{
#region Style
SortedDictionary<long, string> cardlist;
MarkerStyle SameWordsStyle = new MarkerStyle(new SolidBrush(Color.FromArgb(40, Color.White)));
readonly MarkerStyle sameWordsStyle = new MarkerStyle(new SolidBrush(Color.FromArgb(40, Color.White)));
#endregion
#region init 函数提示菜单
......@@ -43,46 +43,60 @@ public partial class CodeEditForm : DockContent, IEditForm
string nowcdb;
public CodeEditForm()
{
InitForm();
this.InitForm();
}
void InitForm()
{
cardlist = new SortedDictionary<long, string>();
tooltipDic = new SortedList<string, string>();
InitializeComponent();
this.cardlist = new SortedDictionary<long, string>();
this.tooltipDic = new SortedList<string, string>();
this.InitializeComponent();
//设置字体,大小
string fontname = MyConfig.readString(MyConfig.TAG_FONT_NAME);
float fontsize = MyConfig.readFloat(MyConfig.TAG_FONT_SIZE, fctb.Font.Size);
fctb.Font = new Font(fontname, fontsize);
float fontsize = MyConfig.readFloat(MyConfig.TAG_FONT_SIZE, this.fctb.Font.Size);
this.fctb.Font = new Font(fontname, fontsize);
if (MyConfig.readBoolean(MyConfig.TAG_IME))
fctb.ImeMode = ImeMode.On;
{
this.fctb.ImeMode = ImeMode.On;
}
if (MyConfig.readBoolean(MyConfig.TAG_WORDWRAP))
fctb.WordWrap = true;
{
this.fctb.WordWrap = true;
}
else
fctb.WordWrap = false;
{
this.fctb.WordWrap = false;
}
if (MyConfig.readBoolean(MyConfig.TAG_TAB2SPACES))
tabisspaces = true;
{
this.tabisspaces = true;
}
else
tabisspaces = false;
{
this.tabisspaces = false;
}
Font ft = new Font(fctb.Font.Name, fctb.Font.Size / 1.2f, FontStyle.Regular);
popupMenu = new FastColoredTextBoxNS.AutocompleteMenu(fctb);
popupMenu.MinFragmentLength = 2;
popupMenu.Items.Font = ft;
popupMenu.Items.MaximumSize = new System.Drawing.Size(200, 400);
popupMenu.Items.Width = 300;
popupMenu.BackColor = fctb.BackColor;
popupMenu.ForeColor = fctb.ForeColor;
popupMenu.Closed += new ToolStripDropDownClosedEventHandler(popupMenu_Closed);
Font ft = new Font(this.fctb.Font.Name, this.fctb.Font.Size / 1.2f, FontStyle.Regular);
this.popupMenu = new FastColoredTextBoxNS.AutocompleteMenu(this.fctb)
{
MinFragmentLength = 2
};
this.popupMenu.Items.Font = ft;
this.popupMenu.Items.MaximumSize = new System.Drawing.Size(200, 400);
this.popupMenu.Items.Width = 300;
this.popupMenu.BackColor = this.fctb.BackColor;
this.popupMenu.ForeColor = this.fctb.ForeColor;
this.popupMenu.Closed += new ToolStripDropDownClosedEventHandler(this.popupMenu_Closed);
popupMenu.SelectedColor = Color.LightGray;
this.popupMenu.SelectedColor = Color.LightGray;
title = this.Text;
this.title = this.Text;
}
void popupMenu_Closed(object sender, ToolStripDropDownClosedEventArgs e)
{
popupMenu.Items.SetAutocompleteItems(items);
this.popupMenu.Items.SetAutocompleteItems(this.items);
}
#endregion
......@@ -93,19 +107,19 @@ public void SetActived()
}
public bool CanOpen(string file)
{
return YGOUtil.isScript(file);
return YGOUtil.IsScript(file);
}
public string GetOpenFile()
{
return nowFile;
return this.nowFile;
}
public bool Create(string file)
{
return Open(file);
return this.Open(file);
}
public bool Save()
{
return savefile(string.IsNullOrEmpty(nowFile));
return this.savefile(string.IsNullOrEmpty(this.nowFile));
}
public bool Open(string file)
{
......@@ -116,13 +130,13 @@ public bool Open(string file)
FileStream fs = new FileStream(file, FileMode.Create);
fs.Close();
}
nowFile = file;
this.nowFile = file;
string cdb = MyPath.Combine(
Path.GetDirectoryName(file), "../cards.cdb");
SetCardDB(cdb);//后台加载卡片数据
fctb.OpenFile(nowFile, new UTF8Encoding(false));
oldtext = fctb.Text;
SetTitle();
this.SetCardDB(cdb);//后台加载卡片数据
this.fctb.OpenFile(this.nowFile, new UTF8Encoding(false));
this.oldtext = this.fctb.Text;
this.SetTitle();
return true;
}
return false;
......@@ -134,17 +148,17 @@ public bool Open(string file)
//文档视图
void ShowMapToolStripMenuItemClick(object sender, EventArgs e)
{
if (menuitem_showmap.Checked)
if (this.menuitem_showmap.Checked)
{
documentMap1.Visible = false;
menuitem_showmap.Checked = false;
fctb.Width += documentMap1.Width;
this.documentMap1.Visible = false;
this.menuitem_showmap.Checked = false;
this.fctb.Width += this.documentMap1.Width;
}
else
{
documentMap1.Visible = true;
menuitem_showmap.Checked = true;
fctb.Width -= documentMap1.Width;
this.documentMap1.Visible = true;
this.menuitem_showmap.Checked = true;
this.fctb.Width -= this.documentMap1.Width;
}
}
#endregion
......@@ -152,39 +166,51 @@ void ShowMapToolStripMenuItemClick(object sender, EventArgs e)
#region 设置标题
void SetTitle()
{
string str = title;
if (string.IsNullOrEmpty(nowFile))
str = title;
string str;
if (string.IsNullOrEmpty(this.nowFile))
{
str = this.title;
}
else
str = nowFile + "-" + title;
{
str = this.nowFile + "-" + this.title;
}
if (this.MdiParent != null)//如果父容器不为空
{
if (string.IsNullOrEmpty(nowFile))
this.Text = title;
if (string.IsNullOrEmpty(this.nowFile))
{
this.Text = this.title;
}
else
this.Text = Path.GetFileName(nowFile);
{
this.Text = Path.GetFileName(this.nowFile);
}
this.MdiParent.Text = str;
}
else
{
this.Text = str;
}
}
void CodeEditFormEnter(object sender, EventArgs e)
{
SetTitle();
this.SetTitle();
}
#endregion
#region 自动完成
public void LoadXml(string xmlfile)
{
fctb.DescriptionFile = xmlfile;
this.fctb.DescriptionFile = xmlfile;
}
public void InitTooltip(CodeConfig codeconfig)
{
this.tooltipDic = codeconfig.TooltipDic;
items = codeconfig.Items;
popupMenu.Items.SetAutocompleteItems(items);
this.items = codeconfig.Items;
this.popupMenu.Items.SetAutocompleteItems(this.items);
}
#endregion
......@@ -193,14 +219,19 @@ public void InitTooltip(CodeConfig codeconfig)
string FindTooltip(string word)
{
string desc = "";
foreach (string v in tooltipDic.Keys)
foreach (string v in this.tooltipDic.Keys)
{
int t = v.IndexOf(".");
string k = v;
if (t > 0)
{
k = v.Substring(t + 1);
}
if (word == k)
desc = tooltipDic[v];
{
desc = this.tooltipDic[v];
}
}
return desc;
}
......@@ -222,11 +253,16 @@ void FctbToolTipNeeded(object sender, ToolTipNeededEventArgs e)
if (tl > 0)
{
//获取卡片信息
if (cardlist.ContainsKey(tl))
desc = cardlist[tl];
if (this.cardlist.ContainsKey(tl))
{
desc = this.cardlist[tl];
}
}
else
desc = FindTooltip(e.HoveredWord);
{
desc = this.FindTooltip(e.HoveredWord);
}
if (!string.IsNullOrEmpty(desc))
{
e.ToolTipTitle = e.HoveredWord;
......@@ -239,9 +275,12 @@ void FctbToolTipNeeded(object sender, ToolTipNeededEventArgs e)
#region 保存文件
bool savefile(bool saveas)
{
string alltext = fctb.Text;
if (!tabisspaces)
string alltext = this.fctb.Text;
if (!this.tabisspaces)
{
alltext = alltext.Replace(" ", "\t");
}
if (saveas)
{
using (SaveFileDialog sfdlg = new SaveFileDialog())
......@@ -249,30 +288,32 @@ bool savefile(bool saveas)
sfdlg.Filter = LanguageHelper.GetMsg(LMSG.ScriptFilter);
if (sfdlg.ShowDialog() == DialogResult.OK)
{
nowFile = sfdlg.FileName;
SetTitle();
this.nowFile = sfdlg.FileName;
this.SetTitle();
}
else
{
return false;
}
}
}
oldtext = fctb.Text;
File.WriteAllText(nowFile, alltext, new UTF8Encoding(false));
this.oldtext = this.fctb.Text;
File.WriteAllText(this.nowFile, alltext, new UTF8Encoding(false));
return true;
}
public bool SaveAs()
{
return savefile(true);
return this.savefile(true);
}
void SaveToolStripMenuItemClick(object sender, EventArgs e)
{
Save();
this.Save();
}
void SaveAsToolStripMenuItemClick(object sender, EventArgs e)
{
SaveAs();
this.SaveAs();
}
#endregion
......@@ -280,40 +321,43 @@ void SaveAsToolStripMenuItemClick(object sender, EventArgs e)
//显示/隐藏输入框
void Menuitem_showinputClick(object sender, EventArgs e)
{
if (menuitem_showinput.Checked)
if (this.menuitem_showinput.Checked)
{
menuitem_showinput.Checked = false;
tb_input.Visible = false;
this.menuitem_showinput.Checked = false;
this.tb_input.Visible = false;
}
else
{
menuitem_showinput.Checked = true;
tb_input.Visible = true;
this.menuitem_showinput.Checked = true;
this.tb_input.Visible = true;
}
}
//如果是作为mdi,则隐藏菜单
void HideMenu()
{
if (this.MdiParent == null)
{
return;
mainMenu.Visible = false;
menuitem_file.Visible = false;
menuitem_file.Enabled = false;
}
this.mainMenu.Visible = false;
this.menuitem_file.Visible = false;
this.menuitem_file.Enabled = false;
}
void CodeEditFormLoad(object sender, EventArgs e)
{
HideMenu();
fctb.OnTextChangedDelayed(fctb.Range);
this.HideMenu();
this.fctb.OnTextChangedDelayed(this.fctb.Range);
}
void Menuitem_findClick(object sender, EventArgs e)
{
fctb.ShowFindDialog();
this.fctb.ShowFindDialog();
}
void Menuitem_replaceClick(object sender, EventArgs e)
{
fctb.ShowReplaceDialog();
this.fctb.ShowReplaceDialog();
}
void QuitToolStripMenuItemClick(object sender, EventArgs e)
......@@ -326,7 +370,7 @@ void AboutToolStripMenuItemClick(object sender, EventArgs e)
MyMsg.Show(
LanguageHelper.GetMsg(LMSG.About) + "\t" + Application.ProductName + "\n"
+ LanguageHelper.GetMsg(LMSG.Version) + "\t1.1.0.0\n"
+ LanguageHelper.GetMsg(LMSG.Author) + "\tNanahira");
+ LanguageHelper.GetMsg(LMSG.Author) + "\t菜菜");
}
void Menuitem_openClick(object sender, EventArgs e)
......@@ -336,8 +380,8 @@ void Menuitem_openClick(object sender, EventArgs e)
sfdlg.Filter = LanguageHelper.GetMsg(LMSG.ScriptFilter);
if (sfdlg.ShowDialog() == DialogResult.OK)
{
nowFile = sfdlg.FileName;
fctb.OpenFile(nowFile, new UTF8Encoding(false));
this.nowFile = sfdlg.FileName;
this.fctb.OpenFile(this.nowFile, new UTF8Encoding(false));
}
}
}
......@@ -350,15 +394,17 @@ void Tb_inputKeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
string key = tb_input.Text;
string key = this.tb_input.Text;
List<AutocompleteItem> list =new List<AutocompleteItem>();
foreach (AutocompleteItem item in items)
foreach (AutocompleteItem item in this.items)
{
if (item.ToolTipText.Contains(key))
{
list.Add(item);
}
}
popupMenu.Items.SetAutocompleteItems(list.ToArray());
popupMenu.Show(true);
this.popupMenu.Items.SetAutocompleteItems(list.ToArray());
this.popupMenu.Show(true);
}
}
#endregion
......@@ -366,18 +412,22 @@ void Tb_inputKeyDown(object sender, KeyEventArgs e)
#region 提示保存
void CodeEditFormFormClosing(object sender, FormClosingEventArgs e)
{
if (!string.IsNullOrEmpty(oldtext))
if (!string.IsNullOrEmpty(this.oldtext))
{
if (fctb.Text != oldtext)
if (this.fctb.Text != this.oldtext)
{
if (MyMsg.Question(LMSG.IfSaveScript))
Save();
{
this.Save();
}
}
}
else if (fctb.Text.Length > 0)
else if (this.fctb.Text.Length > 0)
{
if (MyMsg.Question(LMSG.IfSaveScript))
Save();
{
this.Save();
}
}
}
#endregion
......@@ -386,43 +436,52 @@ void CodeEditFormFormClosing(object sender, FormClosingEventArgs e)
public void SetCDBList(string[] cdbs)
{
if (cdbs == null)
{
return;
}
foreach (string cdb in cdbs)
{
ToolStripMenuItem tsmi = new ToolStripMenuItem(cdb);
tsmi.Click += MenuItem_Click;
menuitem_setcard.DropDownItems.Add(tsmi);
tsmi.Click += this.MenuItem_Click;
this.menuitem_setcard.DropDownItems.Add(tsmi);
}
}
void MenuItem_Click(object sender, EventArgs e)
{
ToolStripMenuItem tsmi = sender as ToolStripMenuItem;
if (tsmi != null)
if (sender is ToolStripMenuItem tsmi)
{
string file = tsmi.Text;
SetCardDB(file);
this.SetCardDB(file);
}
}
public void SetCardDB(string name)
{
nowcdb = name;
if (!backgroundWorker1.IsBusy)
backgroundWorker1.RunWorkerAsync();
this.nowcdb = name;
if (!this.backgroundWorker1.IsBusy)
{
this.backgroundWorker1.RunWorkerAsync();
}
}
private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
if (nowcdb != null && File.Exists(nowcdb))
SetCards(DataBase.Read(nowcdb, true, ""));
if (this.nowcdb != null && File.Exists(this.nowcdb))
{
this.SetCards(DataBase.Read(this.nowcdb, true, ""));
}
}
public void SetCards(Card[] cards)
{
if (cards == null)
{
return;
cardlist.Clear();
}
this.cardlist.Clear();
foreach (Card c in cards)
{
cardlist.Add(c.id, c.ToString());
this.cardlist.Add(c.id, c.ToString());
}
}
#endregion
......@@ -430,36 +489,45 @@ public void SetCards(Card[] cards)
#region 选择高亮
void FctbSelectionChangedDelayed(object sender, EventArgs e)
{
tb_input.Text = fctb.SelectedText;
fctb.VisibleRange.ClearStyle(SameWordsStyle);
if (!fctb.Selection.IsEmpty)
this.tb_input.Text = this.fctb.SelectedText;
this.fctb.VisibleRange.ClearStyle(this.sameWordsStyle);
if (!this.fctb.Selection.IsEmpty)
{
return;//user selected diapason
}
//get fragment around caret
var fragment = fctb.Selection.GetFragment(@"\w");
var fragment = this.fctb.Selection.GetFragment(@"\w");
string text = fragment.Text;
if (text.Length == 0)
{
return;
}
//highlight same words
var ranges = fctb.VisibleRange.GetRanges("\\b" + text + "\\b");
var ranges = this.fctb.VisibleRange.GetRanges("\\b" + text + "\\b");
foreach (var r in ranges)
r.SetStyle(SameWordsStyle);
{
r.SetStyle(this.sameWordsStyle);
}
}
#endregion
#region 调转函数
void FctbMouseClick(object sender, MouseEventArgs e)
{
var fragment = fctb.Selection.GetFragment(@"\w");
var fragment = this.fctb.Selection.GetFragment(@"\w");
string text = fragment.Text;
if (text.Length == 0)
{
return;
}
if (e.Button == MouseButtons.Left && Control.ModifierKeys == Keys.Control)
{
List<int> linenums = fctb.FindLines(@"function\s+?\S+?\." + text + @"\(", RegexOptions.Singleline);
List<int> linenums = this.fctb.FindLines(@"function\s+?\S+?\." + text + @"\(", RegexOptions.Singleline);
if (linenums.Count > 0)
{
fctb.Navigate(linenums[0]);
this.fctb.Navigate(linenums[0]);
//MessageBox.Show(linenums[0].ToString());
}
}
......
......@@ -8,10 +8,10 @@ public class Area
{
public Area()
{
left = 0;
top = 0;
width = 0;
height = 0;
this.left = 0;
this.top = 0;
this.width = 0;
this.height = 0;
}
/// <summary>
/// 左
......
......@@ -78,21 +78,23 @@ public static bool CheckVersion(string ver, string oldver)
string[] oldvers = oldver.Split('.');
if (vers.Length == oldvers.Length)
{
int j, k;//从左到右比较数字
for (int i = 0; i < oldvers.Length; i++)
{
int.TryParse(vers[i], out j);
int.TryParse(oldvers[i], out k);
if (j > k)//新的版本号大于旧的
{
hasNew = true;
break;
}else if(j < k){
hasNew = false;
break;
}
}
}
//从左到右比较数字
for (int i = 0; i < oldvers.Length; i++)
{
int.TryParse(vers[i], out int j);
int.TryParse(oldvers[i], out int k);
if (j > k)//新的版本号大于旧的
{
hasNew = true;
break;
}
else if (j < k)
{
hasNew = false;
break;
}
}
}
return hasNew;
}
#endregion
......@@ -147,8 +149,11 @@ public static bool DownLoad(string filename)
try
{
if (File.Exists(filename))
File.Delete(filename);
HttpWebRequest Myrq = (HttpWebRequest)System.Net.HttpWebRequest.Create(URL);
{
File.Delete(filename);
}
HttpWebRequest Myrq = (HttpWebRequest)System.Net.HttpWebRequest.Create(URL);
HttpWebResponse myrp = (HttpWebResponse)Myrq.GetResponse();
long totalBytes = myrp.ContentLength;
......
......@@ -20,7 +20,10 @@ public static string getValue(string line)
{
int t = line.IndexOf('=');
if (t > 0)
{
return line.Substring(t + 1).Trim();
}
return "";
}
/// <summary>
......@@ -32,7 +35,10 @@ public static string getValue1(string word)
{
int i = word.IndexOf(SEP_LINE);
if (i > 0)
{
return word.Substring(0, i);
}
return word;
}
/// <summary>
......@@ -44,7 +50,10 @@ public static string getValue2(string word)
{
int i = word.IndexOf(SEP_LINE);
if (i > 0)
{
return word.Substring(i + SEP_LINE.Length);
}
return "";
}
/// <summary>
......@@ -78,9 +87,13 @@ public static string getRegex(string word)
public static bool getBooleanValue(string line)
{
if (getValue(line).ToLower() == "true")
{
return true;
}
else
{
return false;
}
}
/// <summary>
/// 获取int值
......@@ -113,10 +126,11 @@ public static void DicAdd(SortedList<long, string> dic, string line)
{
string strkey = line.Substring(i + 2, j - i - 1);
string strval = line.Substring(j + 1);
long key;
long.TryParse(strkey, NumberStyles.HexNumber, null, out key);
long.TryParse(strkey, NumberStyles.HexNumber, null, out long key);
if (!dic.ContainsKey(key))
{
dic.Add(key, strval.Trim());
}
}
}
}
......
......@@ -17,7 +17,10 @@ public static class MyBitmap
public static Bitmap readImage(string file)
{
if (!File.Exists(file))
{
return null;
}
MemoryStream ms = new MemoryStream(File.ReadAllBytes(file));
return (Bitmap)Image.FromStream(ms);
}
......@@ -124,9 +127,15 @@ public static bool SaveAsJPEG(Bitmap bitmap, string filename, int quality=90)
{
string path=Path.GetDirectoryName(filename);
if(!Directory.Exists(path))//创建文件夹
Directory.CreateDirectory(path);
if(File.Exists(filename))//删除旧文件
File.Delete(filename);
{
Directory.CreateDirectory(path);
}
if (File.Exists(filename))//删除旧文件
{
File.Delete(filename);
}
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
ImageCodecInfo ici = null;
foreach ( ImageCodecInfo codec in codecs )
......@@ -138,7 +147,10 @@ public static bool SaveAsJPEG(Bitmap bitmap, string filename, int quality=90)
}
}
if (quality < 0 || quality > 100)
{
quality = 60;
}
EncoderParameters encoderParams = new EncoderParameters();
encoderParams.Param[0] = new EncoderParameter(Encoder.Quality, (long)quality);
if (ici != null)
......
......@@ -52,7 +52,7 @@ public static string Combine(params string[] paths)
}
if (!firstPath.EndsWith(spliter))
{
firstPath = firstPath + spliter;
firstPath += spliter;
}
builder.Append(firstPath);
for (int i = 1; i < paths.Length; i++)
......@@ -70,7 +70,7 @@ public static string Combine(params string[] paths)
}
else
{
nextPath = nextPath + spliter;
nextPath += spliter;
}
}
builder.Append(nextPath);
......@@ -96,7 +96,10 @@ public static string CheckDir(string dir,string defalut)
fo = new DirectoryInfo(defalut);
}
if (!fo.Exists)
{
fo.Create();
}
dir = fo.FullName;
return dir;
}
......@@ -121,21 +124,29 @@ public static string getFullFileName(string tag, string file)
{
string name = Path.GetFileNameWithoutExtension(file);
if (!name.StartsWith(tag + "_"))
{
return "";
}
else
{
return name.Replace(tag + "_", "");
}
}
public static void CreateDir(string dir)
{
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
}
public static void CreateDirByFile(string file)
{
string dir = Path.GetDirectoryName(file);
if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir);
}
}
}
}
......@@ -32,9 +32,11 @@ public new void Add(K key, V value)
}
}
if (flag == 1)
return; //跳出函数
//否则就加入
base.Add(key, value);
{
return; //跳出函数
}
//否则就加入
base.Add(key, value);
}
}
}
......@@ -9,22 +9,30 @@ public class StrUtil
public static string AutoEnter(string str, int lineNum, char re)
{
if (str == null || str.Length == 0)
return "";
str = " "+str.Replace("\r\n", "\n");
{
return "";
}
str = " "+str.Replace("\r\n", "\n");
char[] ch = str.ToCharArray();
int count = ch.Length;
_ = ch.Length;
StringBuilder sb = new StringBuilder();
StringBuilder sb = new StringBuilder();
int i = 0;
foreach (char c in ch)
{
int ic = c;
if (ic > 128)
i += 2;
else
i += 1;
if (c == '\n' || c == '\r')
{
i += 2;
}
else
{
i += 1;
}
if (c == '\n' || c == '\r')
{
sb.Append(re);
i = 0;
......
......@@ -25,7 +25,9 @@ public static void Save(string appKey, string appValue)
XmlElement xElem = (XmlElement)xNode.SelectSingleNode("//add[@key='" + appKey + "']");
if (xElem != null) //存在,则更新
{
xElem.SetAttribute("value", appValue);
}
else//不存在,则插入
{
XmlElement xNewElem = xDoc.CreateElement("add");
......
......@@ -68,7 +68,7 @@ public override string ToString()
#region Private fields
// List of files to store
private List<ZipFileEntry> Files = new List<ZipFileEntry>();
private readonly List<ZipFileEntry> Files = new List<ZipFileEntry>();
// Filename of storage file
private string FileName;
// Stream object of storage file
......@@ -82,9 +82,9 @@ public override string ToString()
// File access for Open method
private FileAccess Access;
// Static CRC32 Table
private static UInt32[] CrcTable = null;
private static readonly uint[] CrcTable = null;
// Default filename encoder
private static Encoding DefaultEncoding = Encoding.GetEncoding(437);
private static readonly Encoding DefaultEncoding = Encoding.GetEncoding(437);
#endregion
#region Public methods
......@@ -92,16 +92,20 @@ public override string ToString()
static ZipStorer()
{
// Generate CRC32 table
CrcTable = new UInt32[256];
CrcTable = new uint[256];
for (int i = 0; i < CrcTable.Length; i++)
{
UInt32 c = (UInt32)i;
uint c = (uint)i;
for (int j = 0; j < 8; j++)
{
if ((c & 1) != 0)
{
c = 3988292384 ^ (c >> 1);
}
else
{
c >>= 1;
}
}
CrcTable[i] = c;
}
......@@ -130,10 +134,12 @@ public static ZipStorer Create(string _filename, string _comment)
/// <returns>A valid ZipStorer object</returns>
public static ZipStorer Create(Stream _stream, string _comment)
{
ZipStorer zip = new ZipStorer();
zip.Comment = _comment;
zip.ZipFileStream = _stream;
zip.Access = FileAccess.Write;
ZipStorer zip = new ZipStorer
{
Comment = _comment,
ZipFileStream = _stream,
Access = FileAccess.Write
};
return zip;
}
......@@ -161,15 +167,21 @@ public static ZipStorer Open(string _filename, FileAccess _access)
public static ZipStorer Open(Stream _stream, FileAccess _access)
{
if (!_stream.CanSeek && _access != FileAccess.Read)
{
throw new InvalidOperationException("Stream cannot seek");
}
ZipStorer zip = new ZipStorer();
//zip.FileName = _filename;
zip.ZipFileStream = _stream;
zip.Access = _access;
ZipStorer zip = new ZipStorer
{
//zip.FileName = _filename;
ZipFileStream = _stream,
Access = _access
};
if (zip.ReadFileInfo())
{
return zip;
}
throw new System.IO.InvalidDataException();
}
......@@ -183,11 +195,13 @@ public static ZipStorer Open(Stream _stream, FileAccess _access)
public void AddFile(string _pathname, string _filenameInZip, string _comment)
{
Compression _method=Compression.Deflate;
if (Access == FileAccess.Read)
if (this.Access == FileAccess.Read)
{
throw new InvalidOperationException("Writing is not alowed");
}
FileStream stream = new FileStream(_pathname, FileMode.Open, FileAccess.Read);
AddStream(_method, _filenameInZip, stream, File.GetLastWriteTime(_pathname), _comment);
this.AddStream(_method, _filenameInZip, stream, File.GetLastWriteTime(_pathname), _comment);
stream.Close();
}
/// <summary>
......@@ -199,11 +213,13 @@ public void AddFile(string _pathname, string _filenameInZip, string _comment)
/// <param name="_comment">Comment for stored file</param>
public void AddFile(Compression _method, string _pathname, string _filenameInZip, string _comment)
{
if (Access == FileAccess.Read)
if (this.Access == FileAccess.Read)
{
throw new InvalidOperationException("Writing is not alowed");
}
FileStream stream = new FileStream(_pathname, FileMode.Open, FileAccess.Read);
AddStream(_method, _filenameInZip, stream, File.GetLastWriteTime(_pathname), _comment);
this.AddStream(_method, _filenameInZip, stream, File.GetLastWriteTime(_pathname), _comment);
stream.Close();
}
/// <summary>
......@@ -216,41 +232,45 @@ public void AddFile(Compression _method, string _pathname, string _filenameInZip
/// <param name="_comment">Comment for stored file</param>
public void AddStream(Compression _method, string _filenameInZip, Stream _source, DateTime _modTime, string _comment)
{
if (Access == FileAccess.Read)
if (this.Access == FileAccess.Read)
{
throw new InvalidOperationException("Writing is not alowed");
}
long offset;
if (this.Files.Count==0)
offset = 0;
{
}
else
{
ZipFileEntry last = this.Files[this.Files.Count-1];
offset = last.HeaderOffset + last.HeaderSize;
_ = last.HeaderOffset + last.HeaderSize;
}
// Prepare the fileinfo
ZipFileEntry zfe = new ZipFileEntry();
zfe.Method = _method;
zfe.EncodeUTF8 = this.EncodeUTF8;
zfe.FilenameInZip = NormalizedFilename(_filenameInZip);
zfe.Comment = (_comment == null ? "" : _comment);
ZipFileEntry zfe = new ZipFileEntry
{
Method = _method,
EncodeUTF8 = this.EncodeUTF8,
FilenameInZip = this.NormalizedFilename(_filenameInZip),
Comment = (_comment ?? ""),
// Even though we write the header now, it will have to be rewritten, since we don't know compressed size or crc.
zfe.Crc32 = 0; // to be updated later
zfe.HeaderOffset = (uint)this.ZipFileStream.Position; // offset within file of the start of this local record
zfe.ModifyTime = _modTime;
// Even though we write the header now, it will have to be rewritten, since we don't know compressed size or crc.
Crc32 = 0, // to be updated later
HeaderOffset = (uint)this.ZipFileStream.Position, // offset within file of the start of this local record
ModifyTime = _modTime
};
// Write local header
WriteLocalHeader(ref zfe);
this.WriteLocalHeader(ref zfe);
zfe.FileOffset = (uint)this.ZipFileStream.Position;
// Write file to zip (store)
Store(ref zfe, _source);
this.Store(ref zfe, _source);
_source.Close();
this.UpdateCrcAndSizes(ref zfe);
Files.Add(zfe);
this.Files.Add(zfe);
}
/// <summary>
/// Updates central directory (if pertinent) and close the Zip storage
......@@ -264,19 +284,25 @@ public void Close()
uint centralSize = 0;
if (this.CentralDirImage != null)
this.ZipFileStream.Write(CentralDirImage, 0, CentralDirImage.Length);
{
this.ZipFileStream.Write(this.CentralDirImage, 0, this.CentralDirImage.Length);
}
for (int i = 0; i < Files.Count; i++)
for (int i = 0; i < this.Files.Count; i++)
{
long pos = this.ZipFileStream.Position;
this.WriteCentralDirRecord(Files[i]);
this.WriteCentralDirRecord(this.Files[i]);
centralSize += (uint)(this.ZipFileStream.Position - pos);
}
if (this.CentralDirImage != null)
this.WriteEndRecord(centralSize + (uint)CentralDirImage.Length, centralOffset);
{
this.WriteEndRecord(centralSize + (uint)this.CentralDirImage.Length, centralOffset);
}
else
{
this.WriteEndRecord(centralSize, centralOffset);
}
}
if (this.ZipFileStream != null)
......@@ -293,42 +319,50 @@ public void Close()
public List<ZipFileEntry> ReadCentralDir()
{
if (this.CentralDirImage == null)
{
throw new InvalidOperationException("Central directory currently does not exist");
}
List<ZipFileEntry> result = new List<ZipFileEntry>();
for (int pointer = 0; pointer < this.CentralDirImage.Length; )
{
uint signature = BitConverter.ToUInt32(CentralDirImage, pointer);
uint signature = BitConverter.ToUInt32(this.CentralDirImage, pointer);
if (signature != 0x02014b50)
{
break;
}
bool encodeUTF8 = (BitConverter.ToUInt16(CentralDirImage, pointer + 8) & 0x0800) != 0;
ushort method = BitConverter.ToUInt16(CentralDirImage, pointer + 10);
uint modifyTime = BitConverter.ToUInt32(CentralDirImage, pointer + 12);
uint crc32 = BitConverter.ToUInt32(CentralDirImage, pointer + 16);
uint comprSize = BitConverter.ToUInt32(CentralDirImage, pointer + 20);
uint fileSize = BitConverter.ToUInt32(CentralDirImage, pointer + 24);
ushort filenameSize = BitConverter.ToUInt16(CentralDirImage, pointer + 28);
ushort extraSize = BitConverter.ToUInt16(CentralDirImage, pointer + 30);
ushort commentSize = BitConverter.ToUInt16(CentralDirImage, pointer + 32);
uint headerOffset = BitConverter.ToUInt32(CentralDirImage, pointer + 42);
bool encodeUTF8 = (BitConverter.ToUInt16(this.CentralDirImage, pointer + 8) & 0x0800) != 0;
ushort method = BitConverter.ToUInt16(this.CentralDirImage, pointer + 10);
uint modifyTime = BitConverter.ToUInt32(this.CentralDirImage, pointer + 12);
uint crc32 = BitConverter.ToUInt32(this.CentralDirImage, pointer + 16);
uint comprSize = BitConverter.ToUInt32(this.CentralDirImage, pointer + 20);
uint fileSize = BitConverter.ToUInt32(this.CentralDirImage, pointer + 24);
ushort filenameSize = BitConverter.ToUInt16(this.CentralDirImage, pointer + 28);
ushort extraSize = BitConverter.ToUInt16(this.CentralDirImage, pointer + 30);
ushort commentSize = BitConverter.ToUInt16(this.CentralDirImage, pointer + 32);
uint headerOffset = BitConverter.ToUInt32(this.CentralDirImage, pointer + 42);
uint headerSize = (uint)( 46 + filenameSize + extraSize + commentSize);
Encoding encoder = encodeUTF8 ? Encoding.UTF8 : DefaultEncoding;
ZipFileEntry zfe = new ZipFileEntry();
zfe.Method = (Compression)method;
zfe.FilenameInZip = encoder.GetString(CentralDirImage, pointer + 46, filenameSize);
zfe.FileOffset = GetFileOffset(headerOffset);
zfe.FileSize = fileSize;
zfe.CompressedSize = comprSize;
zfe.HeaderOffset = headerOffset;
zfe.HeaderSize = headerSize;
zfe.Crc32 = crc32;
zfe.ModifyTime = DosTimeToDateTime(modifyTime);
ZipFileEntry zfe = new ZipFileEntry
{
Method = (Compression)method,
FilenameInZip = encoder.GetString(this.CentralDirImage, pointer + 46, filenameSize),
FileOffset = this.GetFileOffset(headerOffset),
FileSize = fileSize,
CompressedSize = comprSize,
HeaderOffset = headerOffset,
HeaderSize = headerSize,
Crc32 = crc32,
ModifyTime = this.DosTimeToDateTime(modifyTime)
};
if (commentSize > 0)
zfe.Comment = encoder.GetString(CentralDirImage, pointer + 46 + filenameSize + extraSize, commentSize);
{
zfe.Comment = encoder.GetString(this.CentralDirImage, pointer + 46 + filenameSize + extraSize, commentSize);
}
result.Add(zfe);
pointer += (46 + filenameSize + extraSize + commentSize);
......@@ -349,15 +383,21 @@ public bool ExtractFile(ZipFileEntry _zfe, string _filename)
string path = System.IO.Path.GetDirectoryName(_filename);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
// Check it is directory. If so, do nothing
if (Directory.Exists(_filename))
{
return true;
}
Stream output = new FileStream(_filename, FileMode.Create, FileAccess.Write);
bool result = ExtractFile(_zfe, output);
bool result = this.ExtractFile(_zfe, output);
if (result)
{
output.Close();
}
File.SetCreationTime(_filename, _zfe.ModifyTime);
File.SetLastWriteTime(_filename, _zfe.ModifyTime);
......@@ -374,23 +414,33 @@ public bool ExtractFile(ZipFileEntry _zfe, string _filename)
public bool ExtractFile(ZipFileEntry _zfe, Stream _stream)
{
if (!_stream.CanWrite)
{
throw new InvalidOperationException("Stream cannot be written");
}
// check signature
byte[] signature = new byte[4];
this.ZipFileStream.Seek(_zfe.HeaderOffset, SeekOrigin.Begin);
this.ZipFileStream.Read(signature, 0, 4);
if (BitConverter.ToUInt32(signature, 0) != 0x04034b50)
{
return false;
}
// Select input stream for inflating or just reading
Stream inStream;
if (_zfe.Method == Compression.Store)
{
inStream = this.ZipFileStream;
}
else if (_zfe.Method == Compression.Deflate)
{
inStream = new DeflateStream(this.ZipFileStream, CompressionMode.Decompress, true);
}
else
{
return false;
}
// Buffered copy
byte[] buffer = new byte[16384];
......@@ -405,7 +455,10 @@ public bool ExtractFile(ZipFileEntry _zfe, Stream _stream)
_stream.Flush();
if (_zfe.Method == Compression.Deflate)
{
inStream.Dispose();
}
return true;
}
/// <summary>
......@@ -418,7 +471,9 @@ public bool ExtractFile(ZipFileEntry _zfe, Stream _stream)
public static bool RemoveEntries(ref ZipStorer _zip, List<ZipFileEntry> _zfes)
{
if (!(_zip.ZipFileStream is FileStream))
{
throw new InvalidOperationException("RemoveEntries is allowed just over streams of type FileStream");
}
//Get full list of entries
......@@ -457,9 +512,14 @@ public static bool RemoveEntries(ref ZipStorer _zip, List<ZipFileEntry> _zfes)
finally
{
if (File.Exists(tempZipName))
{
File.Delete(tempZipName);
}
if (File.Exists(tempEntryName))
{
File.Delete(tempEntryName);
}
}
return true;
}
......@@ -504,7 +564,7 @@ private void WriteLocalHeader(ref ZipFileEntry _zfe)
this.ZipFileStream.Write(new byte[] { 80, 75, 3, 4, 20, 0}, 0, 6); // No extra header
this.ZipFileStream.Write(BitConverter.GetBytes((ushort)(_zfe.EncodeUTF8 ? 0x0800 : 0)), 0, 2); // filename and comment encoding
this.ZipFileStream.Write(BitConverter.GetBytes((ushort)_zfe.Method), 0, 2); // zipping method
this.ZipFileStream.Write(BitConverter.GetBytes(DateTimeToDosTime(_zfe.ModifyTime)), 0, 4); // zipping date and time
this.ZipFileStream.Write(BitConverter.GetBytes(this.DateTimeToDosTime(_zfe.ModifyTime)), 0, 4); // zipping date and time
this.ZipFileStream.Write(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 0, 12); // unused CRC, un/compressed size, updated later
this.ZipFileStream.Write(BitConverter.GetBytes((ushort)encodedFilename.Length), 0, 2); // filename length
this.ZipFileStream.Write(BitConverter.GetBytes((ushort)0), 0, 2); // extra length
......@@ -544,7 +604,7 @@ private void WriteCentralDirRecord(ZipFileEntry _zfe)
this.ZipFileStream.Write(new byte[] { 80, 75, 1, 2, 23, 0xB, 20, 0 }, 0, 8);
this.ZipFileStream.Write(BitConverter.GetBytes((ushort)(_zfe.EncodeUTF8 ? 0x0800 : 0)), 0, 2); // filename and comment encoding
this.ZipFileStream.Write(BitConverter.GetBytes((ushort)_zfe.Method), 0, 2); // zipping method
this.ZipFileStream.Write(BitConverter.GetBytes(DateTimeToDosTime(_zfe.ModifyTime)), 0, 4); // zipping date and time
this.ZipFileStream.Write(BitConverter.GetBytes(this.DateTimeToDosTime(_zfe.ModifyTime)), 0, 4); // zipping date and time
this.ZipFileStream.Write(BitConverter.GetBytes(_zfe.Crc32), 0, 4); // file CRC
this.ZipFileStream.Write(BitConverter.GetBytes(_zfe.CompressedSize), 0, 4); // compressed file size
this.ZipFileStream.Write(BitConverter.GetBytes(_zfe.FileSize), 0, 4); // uncompressed file size
......@@ -583,8 +643,8 @@ private void WriteEndRecord(uint _size, uint _offset)
byte[] encodedComment = encoder.GetBytes(this.Comment);
this.ZipFileStream.Write(new byte[] { 80, 75, 5, 6, 0, 0, 0, 0 }, 0, 8);
this.ZipFileStream.Write(BitConverter.GetBytes((ushort)Files.Count+ExistingFiles), 0, 2);
this.ZipFileStream.Write(BitConverter.GetBytes((ushort)Files.Count+ExistingFiles), 0, 2);
this.ZipFileStream.Write(BitConverter.GetBytes((ushort)this.Files.Count+ this.ExistingFiles), 0, 2);
this.ZipFileStream.Write(BitConverter.GetBytes((ushort)this.Files.Count+ this.ExistingFiles), 0, 2);
this.ZipFileStream.Write(BitConverter.GetBytes(_size), 0, 4);
this.ZipFileStream.Write(BitConverter.GetBytes(_offset), 0, 4);
this.ZipFileStream.Write(BitConverter.GetBytes((ushort)encodedComment.Length), 0, 2);
......@@ -602,9 +662,13 @@ private void Store(ref ZipFileEntry _zfe, Stream _source)
long sourceStart = _source.Position;
if (_zfe.Method == Compression.Store)
{
outStream = this.ZipFileStream;
}
else
{
outStream = new DeflateStream(this.ZipFileStream, CompressionMode.Compress, true);
}
_zfe.Crc32 = 0 ^ 0xffffffff;
......@@ -625,7 +689,9 @@ private void Store(ref ZipFileEntry _zfe, Stream _source)
outStream.Flush();
if (_zfe.Method == Compression.Deflate)
{
outStream.Dispose();
}
_zfe.Crc32 ^= 0xffffffff;
_zfe.FileSize = totalRead;
......@@ -702,7 +768,9 @@ private string NormalizedFilename(string _filename)
int pos = filename.IndexOf(':');
if (pos >= 0)
{
filename = filename.Remove(0, pos + 1);
}
return filename.Trim('/');
}
......@@ -710,7 +778,9 @@ private string NormalizedFilename(string _filename)
private bool ReadFileInfo()
{
if (this.ZipFileStream.Length < 22)
{
return false;
}
try
{
......@@ -719,19 +789,21 @@ private bool ReadFileInfo()
do
{
this.ZipFileStream.Seek(-5, SeekOrigin.Current);
UInt32 sig = br.ReadUInt32();
uint sig = br.ReadUInt32();
if (sig == 0x06054b50)
{
this.ZipFileStream.Seek(6, SeekOrigin.Current);
UInt16 entries = br.ReadUInt16();
Int32 centralSize = br.ReadInt32();
UInt32 centralDirOffset = br.ReadUInt32();
UInt16 commentSize = br.ReadUInt16();
ushort entries = br.ReadUInt16();
int centralSize = br.ReadInt32();
uint centralDirOffset = br.ReadUInt32();
ushort commentSize = br.ReadUInt16();
// check if comment field is the very last data in file
if (this.ZipFileStream.Position + commentSize != this.ZipFileStream.Length)
{
return false;
}
// Copy entire central directory to a memory buffer
this.ExistingFiles = entries;
......
......@@ -15,29 +15,29 @@ public class CodeConfig
#region 成员
public CodeConfig()
{
tooltipDic = new SortedList<string, string>();
longTooltipDic = new SortedList<string, string>();
items = new List<AutocompleteItem>();
this.tooltipDic = new SortedList<string, string>();
this.longTooltipDic = new SortedList<string, string>();
this.items = new List<AutocompleteItem>();
}
//函数提示
SortedList<string, string> tooltipDic;
SortedList<string, string> longTooltipDic;
List<AutocompleteItem> items;
readonly SortedList<string, string> tooltipDic;
readonly SortedList<string, string> longTooltipDic;
readonly List<AutocompleteItem> items;
/// <summary>
/// 输入提示
/// </summary>
public SortedList<string, string> TooltipDic
{
get { return tooltipDic; }
get { return this.tooltipDic; }
}
public SortedList<string, string> LongTooltipDic
{
get { return longTooltipDic; }
get { return this.longTooltipDic; }
}
public AutocompleteItem[] Items
{
get { return items.ToArray(); }
get { return this.items.ToArray(); }
}
#endregion
......@@ -51,9 +51,9 @@ public void SetNames(Dictionary<long, string> dic)
foreach (long k in dic.Keys)
{
string key = "0x" + k.ToString("x");
if (!tooltipDic.ContainsKey(key))
if (!this.tooltipDic.ContainsKey(key))
{
AddToolIipDic(key, dic[k]);
this.AddToolIipDic(key, dic[k]);
}
}
}
......@@ -75,7 +75,7 @@ public void AddStrings(string file)
string[] ws = line.Split(' ');
if (ws.Length > 2)
{
AddToolIipDic(ws[1], ws[2]);
this.AddToolIipDic(ws[1], ws[2]);
}
}
}
......@@ -88,7 +88,10 @@ public void AddStrings(string file)
public void AddFunction(string funtxt)
{
if (!File.Exists(funtxt))
{
return;
}
string[] lines = File.ReadAllLines(funtxt);
bool isFind = false;
string name = "";
......@@ -98,11 +101,14 @@ public void AddFunction(string funtxt)
if (string.IsNullOrEmpty(line)
|| line.StartsWith("==")
|| line.StartsWith("#"))
{
continue;
}
if (line.StartsWith("●"))
{
//add
AddToolIipDic(name, desc);
this.AddToolIipDic(name, desc);
int w = line.IndexOf("(");
int t = line.IndexOf(" ");
......@@ -119,7 +125,7 @@ public void AddFunction(string funtxt)
desc += Environment.NewLine + line;
}
}
AddToolIipDic(name, desc);
this.AddToolIipDic(name, desc);
}
#endregion
......@@ -128,21 +134,26 @@ public void AddConstant(string conlua)
{
//conList.Add("con");
if (!File.Exists(conlua))
{
return;
}
string[] lines = File.ReadAllLines(conlua);
foreach (string line in lines)
{
if (line.StartsWith("--"))
{
continue;
string k = line, desc = line;
}
int t = line.IndexOf("=");
int t2 = line.IndexOf("--");
_ = line.IndexOf("--");
//常量 = 0x1 ---注释
k = (t > 0) ? line.Substring(0, t).TrimEnd(new char[] { ' ', '\t' })
string k = (t > 0) ? line.Substring(0, t).TrimEnd(new char[] { ' ', '\t' })
: line;
desc = (t > 0) ? line.Substring(t + 1).Replace("--", "\n")
: line;
AddToolIipDic(k, desc);
string desc = (t > 0) ? line.Substring(t + 1).Replace("--", "\n")
: line;
this.AddToolIipDic(k, desc);
}
}
#endregion
......@@ -150,60 +161,81 @@ public void AddConstant(string conlua)
#region 处理
public void InitAutoMenus()
{
items.Clear();
foreach (string k in tooltipDic.Keys)
this.items.Clear();
foreach (string k in this.tooltipDic.Keys)
{
AutocompleteItem item = new AutocompleteItem(k);
item.ToolTipTitle = k;
item.ToolTipText = tooltipDic[k];
items.Add(item);
AutocompleteItem item = new AutocompleteItem(k)
{
ToolTipTitle = k,
ToolTipText = this.tooltipDic[k]
};
this.items.Add(item);
}
foreach (string k in longTooltipDic.Keys)
foreach (string k in this.longTooltipDic.Keys)
{
if (tooltipDic.ContainsKey(k))
if (this.tooltipDic.ContainsKey(k))
{
continue;
AutocompleteItem item = new AutocompleteItem(k);
item.ToolTipTitle = k;
item.ToolTipText = longTooltipDic[k];
items.Add(item);
}
AutocompleteItem item = new AutocompleteItem(k)
{
ToolTipTitle = k,
ToolTipText = this.longTooltipDic[k]
};
this.items.Add(item);
}
}
string GetShortName(string name)
{
int t = name.IndexOf(".");
if (t > 0)
{
return name.Substring(t + 1);
}
else
{
return name;
}
}
void AddToolIipDic(string key, string val)
{
string skey = GetShortName(key);
if (tooltipDic.ContainsKey(skey))//存在
string skey = this.GetShortName(key);
if (this.tooltipDic.ContainsKey(skey))//存在
{
string nval = tooltipDic[skey];
string nval = this.tooltipDic[skey];
if (!nval.EndsWith(Environment.NewLine))
{
nval += Environment.NewLine;
}
nval += Environment.NewLine +val;
tooltipDic[skey] = nval;
this.tooltipDic[skey] = nval;
}
else
tooltipDic.Add(skey, val);
{
this.tooltipDic.Add(skey, val);
}
//
AddLongToolIipDic(key, val);
this.AddLongToolIipDic(key, val);
}
void AddLongToolIipDic(string key, string val)
{
if (longTooltipDic.ContainsKey(key))//存在
if (this.longTooltipDic.ContainsKey(key))//存在
{
string nval = longTooltipDic[key];
string nval = this.longTooltipDic[key];
if (!nval.EndsWith(Environment.NewLine))
{
nval += Environment.NewLine;
}
nval += Environment.NewLine + val;
longTooltipDic[key] = nval;
this.longTooltipDic[key] = nval;
}
else
longTooltipDic.Add(key, val);
{
this.longTooltipDic.Add(key, val);
}
}
#endregion
}
......
......@@ -18,11 +18,11 @@ public class DataConfig
{
public DataConfig()
{
InitMember(MyPath.Combine(Application.StartupPath, MyConfig.TAG_CARDINFO+".txt"));
this.InitMember(MyPath.Combine(Application.StartupPath, MyConfig.TAG_CARDINFO+".txt"));
}
public DataConfig(string conf)
{
InitMember(conf);
this.InitMember(conf);
}
/// <summary>
/// 初始化成员
......@@ -33,26 +33,26 @@ public void InitMember(string conf)
//conf = MyPath.Combine(datapath, MyConfig.FILE_INFO);
if(!File.Exists(conf))
{
dicCardRules = new Dictionary<long, string>();
dicSetnames = new Dictionary<long, string>();
dicCardTypes = new Dictionary<long, string>();
dicLinkMarkers = new Dictionary<long, string>();
dicCardcategorys = new Dictionary<long, string>();
dicCardAttributes = new Dictionary<long, string>();
dicCardRaces = new Dictionary<long, string>();
dicCardLevels = new Dictionary<long, string>();
this.dicCardRules = new Dictionary<long, string>();
this.dicSetnames = new Dictionary<long, string>();
this.dicCardTypes = new Dictionary<long, string>();
this.dicLinkMarkers = new Dictionary<long, string>();
this.dicCardcategorys = new Dictionary<long, string>();
this.dicCardAttributes = new Dictionary<long, string>();
this.dicCardRaces = new Dictionary<long, string>();
this.dicCardLevels = new Dictionary<long, string>();
return;
}
//提取内容
string text = File.ReadAllText(conf);
dicCardRules = DataManager.Read(text, MyConfig.TAG_RULE);
dicSetnames = DataManager.Read(text, MyConfig.TAG_SETNAME);
dicCardTypes = DataManager.Read(text, MyConfig.TAG_TYPE);
dicLinkMarkers = DataManager.Read(text, MyConfig.TAG_MARKER);
dicCardcategorys = DataManager.Read(text, MyConfig.TAG_CATEGORY);
dicCardAttributes = DataManager.Read(text, MyConfig.TAG_ATTRIBUTE);
dicCardRaces = DataManager.Read(text, MyConfig.TAG_RACE);
dicCardLevels = DataManager.Read(text, MyConfig.TAG_LEVEL);
this.dicCardRules = DataManager.Read(text, MyConfig.TAG_RULE);
this.dicSetnames = DataManager.Read(text, MyConfig.TAG_SETNAME);
this.dicCardTypes = DataManager.Read(text, MyConfig.TAG_TYPE);
this.dicLinkMarkers = DataManager.Read(text, MyConfig.TAG_MARKER);
this.dicCardcategorys = DataManager.Read(text, MyConfig.TAG_CATEGORY);
this.dicCardAttributes = DataManager.Read(text, MyConfig.TAG_ATTRIBUTE);
this.dicCardRaces = DataManager.Read(text, MyConfig.TAG_RACE);
this.dicCardLevels = DataManager.Read(text, MyConfig.TAG_LEVEL);
}
/// <summary>
......
......@@ -77,6 +77,8 @@ public static string subString(string content, string tag)
public static Dictionary<long, string> Read(string content)
{
string text = reReturn(content);
text = text.Replace("\r", "\n");
text = text.Replace("\n\n", "\n"); //Linux & MacOS 适配 190324 by JoyJ
return Read(text.Split('\n'));
}
/// <summary>
......@@ -90,18 +92,31 @@ public static string subString(string content, string tag)
long lkey;
foreach (string line in lines)
{
if (line.StartsWith("#"))
string l = line.Trim(); //姑且做一下Trim 190324 by JoyJ
if (l.StartsWith("#"))
{
continue;
string[] words = line.Split(SEP_LINE);
}
string[] words = l.Split(SEP_LINE);
if (words.Length < 2)
{
continue;
}
if (words[0].StartsWith("0x"))
{
long.TryParse(words[0].Replace("0x", ""), NumberStyles.HexNumber, null, out lkey);
}
else
{
long.TryParse(words[0], out lkey);
}
// N/A 的数据不显示
if (!tempDic.ContainsKey(lkey) && words[1] != "N/A")
{
tempDic.Add(lkey, words[1]);
}
}
return tempDic;
}
......@@ -136,8 +151,11 @@ public static string[] GetValues(Dictionary<long, string> dic)
public static string GetValue(Dictionary<long, string> dic, long key)
{
if(dic.ContainsKey(key))
return dic[key].Trim();
return key.ToString("x");
{
return dic[key].Trim();
}
return key.ToString("x");
}
#endregion
}
......
......@@ -18,7 +18,7 @@ namespace DataEditorX.Config
public class ImageSet
{
public ImageSet(){
Init();
this.Init();
}
//初始化
void Init()
......
......@@ -193,9 +193,11 @@ public static string readString(string key)
/// <returns></returns>
public static int readInteger(string key, int def)
{
int i;
if (int.TryParse(readString(key), out i))
if (int.TryParse(readString(key), out int i))
{
return i;
}
return def;
}
/// <summary>
......@@ -206,9 +208,11 @@ public static int readInteger(string key, int def)
/// <returns></returns>
public static float readFloat(string key, float def)
{
float i;
if (float.TryParse(readString(key), out i))
if (float.TryParse(readString(key), out float i))
{
return i;
}
return def;
}
/// <summary>
......@@ -286,8 +290,11 @@ public static string GetLanguageFile(string path)
{
string name = MyPath.getFullFileName(MyConfig.TAG_LANGUAGE, file);
if (string.IsNullOrEmpty(name))
continue;
if (syslang.Equals(name, StringComparison.OrdinalIgnoreCase))
{
continue;
}
if (syslang.Equals(name, StringComparison.OrdinalIgnoreCase))
{
Save(MyConfig.TAG_LANGUAGE, syslang);
break;
......
......@@ -9,17 +9,17 @@ public class YgoPath
{
public YgoPath(string gamepath)
{
SetPath(gamepath);
this.SetPath(gamepath);
}
public void SetPath(string gamepath)
{
this.gamepath = gamepath;
picpath = MyPath.Combine(gamepath, "pics");
fieldpath = MyPath.Combine(picpath, "field");
picpath2 = MyPath.Combine(picpath, "thumbnail");
luapath = MyPath.Combine(gamepath, "script");
ydkpath = MyPath.Combine(gamepath, "deck");
replaypath = MyPath.Combine(gamepath, "replay");
this.picpath = MyPath.Combine(gamepath, "pics");
this.fieldpath = MyPath.Combine(this.picpath, "field");
this.picpath2 = MyPath.Combine(this.picpath, "thumbnail");
this.luapath = MyPath.Combine(gamepath, "script");
this.ydkpath = MyPath.Combine(gamepath, "deck");
this.replaypath = MyPath.Combine(gamepath, "replay");
}
/// <summary>游戏目录</summary>
public string gamepath;
......@@ -38,7 +38,7 @@ public void SetPath(string gamepath)
public string GetImage(long id)
{
return GetImage(id.ToString());
return this.GetImage(id.ToString());
}
//public string GetImageThum(long id)
//{
......@@ -46,20 +46,20 @@ public string GetImage(long id)
//}
public string GetImageField(long id)
{
return GetImageField(id.ToString());//场地图
return this.GetImageField(id.ToString());//场地图
}
public string GetScript(long id)
{
return GetScript(id.ToString());
return this.GetScript(id.ToString());
}
public string GetYdk(string name)
{
return MyPath.Combine(ydkpath, name + ".ydk");
return MyPath.Combine(this.ydkpath, name + ".ydk");
}
//字符串id
public string GetImage(string id)
{
return MyPath.Combine(picpath, id + ".jpg");
return MyPath.Combine(this.picpath, id + ".jpg");
}
//public string GetImageThum(string id)
//{
......@@ -67,34 +67,34 @@ public string GetImage(string id)
//}
public string GetImageField(string id)
{
return MyPath.Combine(fieldpath, id+ ".png");//场地图
return MyPath.Combine(this.fieldpath, id+ ".png");//场地图
}
public string GetScript(string id)
{
return MyPath.Combine(luapath, "c" + id + ".lua");
return MyPath.Combine(this.luapath, "c" + id + ".lua");
}
public string GetModuleScript(string modulescript)
{
return MyPath.Combine(luapath, modulescript + ".lua");
return MyPath.Combine(this.luapath, modulescript + ".lua");
}
public string[] GetCardfiles(long id)
{
string[] files = new string[]{
GetImage(id),//大图
this.GetImage(id),//大图
//GetImageThum(id),//小图
GetImageField(id),//场地图
GetScript(id)
this.GetImageField(id),//场地图
this.GetScript(id)
};
return files;
}
public string[] GetCardfiles(string id)
{
string[] files = new string[]{
GetImage(id),//大图
this.GetImage(id),//大图
//GetImageThum(id),//小图
GetImageField(id),//场地图
GetScript(id)
this.GetImageField(id),//场地图
this.GetScript(id)
};
return files;
}
......
......@@ -9,10 +9,10 @@ public class DFlowLayoutPanel : FlowLayoutPanel
{
public DFlowLayoutPanel()
{
SetStyle(ControlStyles.OptimizedDoubleBuffer |
this.SetStyle(ControlStyles.OptimizedDoubleBuffer |
ControlStyles.AllPaintingInWmPaint,
true);
UpdateStyles();
this.UpdateStyles();
}
}
}
......@@ -9,10 +9,10 @@ public class DListBox : ListBox
{
public DListBox()
{
SetStyle(ControlStyles.OptimizedDoubleBuffer |
this.SetStyle(ControlStyles.OptimizedDoubleBuffer |
ControlStyles.AllPaintingInWmPaint,
true);
UpdateStyles();
this.UpdateStyles();
}
}
}
......@@ -9,10 +9,10 @@ public class DListView : ListView
{
public DListView()
{
SetStyle(ControlStyles.OptimizedDoubleBuffer |
this.SetStyle(ControlStyles.OptimizedDoubleBuffer |
ControlStyles.AllPaintingInWmPaint,
true);
UpdateStyles();
this.UpdateStyles();
}
}
}
......@@ -20,33 +20,40 @@ public class FastColoredTextBoxEx : FastColoredTextBox
public FastColoredTextBoxEx() : base()
{
this.SyntaxHighlighter = new MySyntaxHighlighter();
this.TextChangedDelayed += FctbTextChangedDelayed;
this.TextChangedDelayed += this.FctbTextChangedDelayed;
}
public new event EventHandler<ToolTipNeededEventArgs> ToolTipNeeded;
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
lastMouseCoord = e.Location;
this.lastMouseCoord = e.Location;
}
//函数悬停提示
protected override void OnToolTip()
{
if (ToolTip == null)
return;
if (ToolTipNeeded == null)
return;
if (this.ToolTip == null)
{
return;
}
if (ToolTipNeeded == null)
{
return;
}
//get place under mouse
Place place = PointToPlace(lastMouseCoord);
//get place under mouse
Place place = this.PointToPlace(this.lastMouseCoord);
//check distance
Point p = PlaceToPoint(place);
if (Math.Abs(p.X - lastMouseCoord.X) > CharWidth*2 ||
Math.Abs(p.Y - lastMouseCoord.Y) > CharHeight*2)
return;
//get word under mouse
var r = new Range(this, place, place);
Point p = this.PlaceToPoint(place);
if (Math.Abs(p.X - this.lastMouseCoord.X) > this.CharWidth *2 ||
Math.Abs(p.Y - this.lastMouseCoord.Y) > this.CharHeight *2)
{
return;
}
//get word under mouse
var r = new Range(this, place, place);
string hoveredWord = r.GetFragment("[a-zA-Z0-9_]").Text;
//event handler
var ea = new ToolTipNeededEventArgs(place, hoveredWord);
......@@ -54,11 +61,11 @@ protected override void OnToolTip()
if (ea.ToolTipText != null)
{
//show tooltip
ToolTip.ToolTipTitle = ea.ToolTipTitle;
ToolTip.ToolTipIcon = ea.ToolTipIcon;
//ToolTip.SetToolTip(this, ea.ToolTipText);
ToolTip.Show(ea.ToolTipText, this, new Point(lastMouseCoord.X, lastMouseCoord.Y + CharHeight));
//show tooltip
this.ToolTip.ToolTipTitle = ea.ToolTipTitle;
this.ToolTip.ToolTipIcon = ea.ToolTipIcon;
//ToolTip.SetToolTip(this, ea.ToolTipText);
this.ToolTip.Show(ea.ToolTipText, this, new Point(this.lastMouseCoord.X, this.lastMouseCoord.Y + this.CharHeight));
}
}
//高亮当前词
......@@ -75,13 +82,21 @@ void FctbTextChangedDelayed(object sender, TextChangedEventArgs e)
var line = this[i];
var spacesCount = line.StartSpacesCount;
if (spacesCount == line.Count) //empty line
{
continue;
}
if (currentIndent < spacesCount)
{
//append start folding marker
this[lastNonEmptyLine].FoldingStartMarker = "m" + currentIndent;
}
else if (currentIndent > spacesCount)
{
//append end folding marker
this[lastNonEmptyLine].FoldingEndMarker = "m" + spacesCount;
}
currentIndent = spacesCount;
lastNonEmptyLine = i;
}
......
......@@ -11,55 +11,65 @@ namespace DataEditorX.Controls
public class History
{
IMainForm mainForm;
readonly IMainForm mainForm;
string historyFile;
List<string> cdbhistory;
List<string> luahistory;
readonly List<string> cdbhistory;
readonly List<string> luahistory;
public string[] GetcdbHistory()
{
return cdbhistory.ToArray();
return this.cdbhistory.ToArray();
}
public string[] GetluaHistory()
{
return luahistory.ToArray();
return this.luahistory.ToArray();
}
public History(IMainForm mainForm)
{
this.mainForm = mainForm;
cdbhistory = new List<string>();
luahistory = new List<string>();
this.cdbhistory = new List<string>();
this.luahistory = new List<string>();
}
//读取历史记录
public void ReadHistory(string historyFile)
{
this.historyFile = historyFile;
if (!File.Exists(historyFile))
{
return;
}
string[] lines = File.ReadAllLines(historyFile);
AddHistorys(lines);
this.AddHistorys(lines);
}
//添加历史记录
void AddHistorys(string[] lines)
{
luahistory.Clear();
cdbhistory.Clear();
this.luahistory.Clear();
this.cdbhistory.Clear();
foreach (string line in lines)
{
if (string.IsNullOrEmpty(line) || line.StartsWith("#"))
{
continue;
}
if (File.Exists(line))
{
if (YGOUtil.isScript(line))
if (YGOUtil.IsScript(line))
{
if (luahistory.Count < MyConfig.MAX_HISTORY
&& luahistory.IndexOf(line) < 0)
luahistory.Add(line);
if (this.luahistory.Count < MyConfig.MAX_HISTORY
&& this.luahistory.IndexOf(line) < 0)
{
this.luahistory.Add(line);
}
}
else
{
if (cdbhistory.Count < MyConfig.MAX_HISTORY
&& cdbhistory.IndexOf(line) < 0)
cdbhistory.Add(line);
if (this.cdbhistory.Count < MyConfig.MAX_HISTORY
&& this.cdbhistory.IndexOf(line) < 0)
{
this.cdbhistory.Add(line);
}
}
}
}
......@@ -70,81 +80,89 @@ public void AddHistory(string file)
//添加到开始
tmplist.Add(file);
//添加旧记录
tmplist.AddRange(cdbhistory.ToArray());
tmplist.AddRange(luahistory.ToArray());
tmplist.AddRange(this.cdbhistory.ToArray());
tmplist.AddRange(this.luahistory.ToArray());
//
AddHistorys(tmplist.ToArray());
SaveHistory();
MenuHistory();
this.AddHistorys(tmplist.ToArray());
this.SaveHistory();
this.MenuHistory();
}
//保存历史
void SaveHistory()
{
string texts = "# database history";
foreach (string str in cdbhistory)
foreach (string str in this.cdbhistory)
{
if (File.Exists(str))
{
texts += Environment.NewLine + str;
}
}
texts += Environment.NewLine + "# script history";
foreach (string str in luahistory)
foreach (string str in this.luahistory)
{
if (File.Exists(str))
{
texts += Environment.NewLine + str;
}
}
if(File.Exists(this.historyFile))
{
File.Delete(this.historyFile);
}
if(File.Exists(historyFile))
File.Delete(historyFile);
File.WriteAllText(historyFile, texts);
File.WriteAllText(this.historyFile, texts);
}
//添加历史记录菜单
public void MenuHistory()
{
//cdb历史
mainForm.CdbMenuClear();
foreach (string str in cdbhistory)
this.mainForm.CdbMenuClear();
foreach (string str in this.cdbhistory)
{
ToolStripMenuItem tsmi = new ToolStripMenuItem(str);
tsmi.Click += MenuHistoryItem_Click;
mainForm.AddCdbMenu(tsmi);
tsmi.Click += this.MenuHistoryItem_Click;
this.mainForm.AddCdbMenu(tsmi);
}
mainForm.AddCdbMenu(new ToolStripSeparator());
this.mainForm.AddCdbMenu(new ToolStripSeparator());
ToolStripMenuItem tsmiclear = new ToolStripMenuItem(LanguageHelper.GetMsg(LMSG.ClearHistory));
tsmiclear.Click += MenuHistoryClear_Click;
mainForm.AddCdbMenu(tsmiclear);
tsmiclear.Click += this.MenuHistoryClear_Click;
this.mainForm.AddCdbMenu(tsmiclear);
//lua历史
mainForm.LuaMenuClear();
foreach (string str in luahistory)
this.mainForm.LuaMenuClear();
foreach (string str in this.luahistory)
{
ToolStripMenuItem tsmi = new ToolStripMenuItem(str);
tsmi.Click += MenuHistoryItem_Click;
mainForm.AddLuaMenu(tsmi);
tsmi.Click += this.MenuHistoryItem_Click;
this.mainForm.AddLuaMenu(tsmi);
}
mainForm.AddLuaMenu(new ToolStripSeparator());
this.mainForm.AddLuaMenu(new ToolStripSeparator());
ToolStripMenuItem tsmiclear2 = new ToolStripMenuItem(LanguageHelper.GetMsg(LMSG.ClearHistory));
tsmiclear2.Click += MenuHistoryClear2_Click;
mainForm.AddLuaMenu(tsmiclear2);
tsmiclear2.Click += this.MenuHistoryClear2_Click;
this.mainForm.AddLuaMenu(tsmiclear2);
}
void MenuHistoryClear2_Click(object sender, EventArgs e)
{
luahistory.Clear();
MenuHistory();
SaveHistory();
this.luahistory.Clear();
this.MenuHistory();
this.SaveHistory();
}
void MenuHistoryClear_Click(object sender, EventArgs e)
{
cdbhistory.Clear();
MenuHistory();
SaveHistory();
this.cdbhistory.Clear();
this.MenuHistory();
this.SaveHistory();
}
void MenuHistoryItem_Click(object sender, EventArgs e)
{
ToolStripMenuItem tsmi = sender as ToolStripMenuItem;
if (tsmi != null)
if (sender is ToolStripMenuItem tsmi)
{
string file = tsmi.Text;
if(File.Exists(file))
mainForm.Open(file);
if (File.Exists(file))
{
this.mainForm.Open(file);
}
}
}
}
......
......@@ -20,13 +20,12 @@ namespace FastColoredTextBoxNS
/// </summary>
public class MySyntaxHighlighter : SyntaxHighlighter
{
TextStyle mBoldStyle = new TextStyle(Brushes.MediumSlateBlue, null, FontStyle.Regular);
TextStyle mNumberStyle = new TextStyle(Brushes.Orange, null, FontStyle.Regular);
TextStyle mStrStyle = new TextStyle(Brushes.Gold, null, FontStyle.Regular);
TextStyle ConStyle = new TextStyle(Brushes.YellowGreen, null, FontStyle.Regular);
TextStyle mKeywordStyle = new TextStyle(Brushes.DeepSkyBlue, null, FontStyle.Regular);
TextStyle mGrayStyle = new TextStyle(Brushes.Gray, null, FontStyle.Regular);
TextStyle mFunStyle = new TextStyle(Brushes.LightGray, null, FontStyle.Bold);
readonly TextStyle mNumberStyle = new TextStyle(Brushes.Orange, null, FontStyle.Regular);
readonly TextStyle mStrStyle = new TextStyle(Brushes.Gold, null, FontStyle.Regular);
readonly TextStyle conStyle = new TextStyle(Brushes.YellowGreen, null, FontStyle.Regular);
readonly TextStyle mKeywordStyle = new TextStyle(Brushes.DeepSkyBlue, null, FontStyle.Regular);
readonly TextStyle mGrayStyle = new TextStyle(Brushes.Gray, null, FontStyle.Regular);
readonly TextStyle mFunStyle = new TextStyle(Brushes.LightGray, null, FontStyle.Bold);
/// <summary>
......@@ -46,26 +45,28 @@ public override void LuaSyntaxHighlight(Range range)
= @"^\s*[\w\.]+(\s\w+)?\s*(?<range>=)\s*(?<range>.+)";
//clear style of changed range
range.ClearStyle(mStrStyle, mGrayStyle,ConStyle, mNumberStyle, mKeywordStyle, mFunStyle);
range.ClearStyle(this.mStrStyle, this.mGrayStyle, this.conStyle, this.mNumberStyle, this.mKeywordStyle, this.mFunStyle);
//
if (base.LuaStringRegex == null)
base.InitLuaRegex();
//string highlighting
range.SetStyle(mStrStyle, base.LuaStringRegex);
{
base.InitLuaRegex();
}
//string highlighting
range.SetStyle(this.mStrStyle, base.LuaStringRegex);
//comment highlighting
range.SetStyle(mGrayStyle, base.LuaCommentRegex1);
range.SetStyle(mGrayStyle, base.LuaCommentRegex2);
range.SetStyle(mGrayStyle, base.LuaCommentRegex3);
range.SetStyle(this.mGrayStyle, base.LuaCommentRegex1);
range.SetStyle(this.mGrayStyle, base.LuaCommentRegex2);
range.SetStyle(this.mGrayStyle, base.LuaCommentRegex3);
//number highlighting
range.SetStyle(mNumberStyle, base.LuaNumberRegex);
range.SetStyle(this.mNumberStyle, base.LuaNumberRegex);
//keyword highlighting
range.SetStyle(mKeywordStyle, base.LuaKeywordRegex);
range.SetStyle(this.mKeywordStyle, base.LuaKeywordRegex);
//functions highlighting
range.SetStyle(mFunStyle, base.LuaFunctionsRegex);
range.SetStyle(mNumberStyle, @"\bc\d+\b");
range.SetStyle(this.mFunStyle, base.LuaFunctionsRegex);
range.SetStyle(this.mNumberStyle, @"\bc\d+\b");
range.SetStyle(ConStyle, @"[\s|\(|+|,]{0,1}(?<range>[A-Z_]+?)[\)|+|\s|,|;]");
range.SetStyle(this.conStyle, @"[\s|\(|+|,]{0,1}(?<range>[A-Z_]+?)[\)|+|\s|,|;]");
//range.SetStyle(mFunStyle, @"[:|\.|\s](?<range>[a-zA-Z0-9_]*?)[\(|\)|\s]");
//clear folding markers
......
......@@ -38,8 +38,10 @@ public Card(long cardCode)
this.desc = "";
this.str = new string[STR_MAX];
for (int i = 0; i < STR_MAX; i++)
{
this.str[i] = "";
}
}
}
#endregion
#region 成员
......@@ -78,8 +80,10 @@ public string[] Str
{
this.str = new string[STR_MAX];
for (int i = 0; i < STR_MAX; i++)
this.str[i] = "";
{
this.str[i] = "";
}
}
return this.str;
}
set { this.str = value; }
......@@ -110,12 +114,11 @@ public void SetSetCode(params string[] setcodes)
{
int i = 0;
this.setcode = 0;
long temp;
if (setcodes != null)
{
foreach (string sc in setcodes)
{
long.TryParse(sc, NumberStyles.HexNumber, null, out temp);
long.TryParse(sc, NumberStyles.HexNumber, null, out long temp);
this.setcode += (temp << i);
i += 0x10;
}
......@@ -140,10 +143,14 @@ public long GetRightScale()
public override bool Equals(object obj)
{
if (obj is Card)
return Equals((Card)obj); // use Equals method below
else
return false;
}
{
return this.Equals((Card)obj); // use Equals method below
}
else
{
return false;
}
}
/// <summary>
/// 比较卡片,除脚本提示文本
/// </summary>
......@@ -153,32 +160,59 @@ public bool EqualsData(Card other)
{
bool equalBool = true;
if (this.id != other.id)
equalBool = false;
else if (this.ot != other.ot)
equalBool = false;
else if (this.alias != other.alias)
equalBool = false;
else if (this.setcode != other.setcode)
equalBool = false;
else if (this.type != other.type)
equalBool = false;
else if (this.atk != other.atk)
equalBool = false;
else if (this.def != other.def)
equalBool = false;
else if (this.level != other.level)
equalBool = false;
else if (this.race != other.race)
equalBool = false;
else if (this.attribute != other.attribute)
equalBool = false;
else if (this.category != other.category)
equalBool = false;
else if (!this.name.Equals(other.name))
equalBool = false;
else if (!this.desc.Equals(other.desc))
equalBool = false;
return equalBool;
{
equalBool = false;
}
else if (this.ot != other.ot)
{
equalBool = false;
}
else if (this.alias != other.alias)
{
equalBool = false;
}
else if (this.setcode != other.setcode)
{
equalBool = false;
}
else if (this.type != other.type)
{
equalBool = false;
}
else if (this.atk != other.atk)
{
equalBool = false;
}
else if (this.def != other.def)
{
equalBool = false;
}
else if (this.level != other.level)
{
equalBool = false;
}
else if (this.race != other.race)
{
equalBool = false;
}
else if (this.attribute != other.attribute)
{
equalBool = false;
}
else if (this.category != other.category)
{
equalBool = false;
}
else if (!this.name.Equals(other.name))
{
equalBool = false;
}
else if (!this.desc.Equals(other.desc))
{
equalBool = false;
}
return equalBool;
}
/// <summary>
/// 比较卡片是否一致?
......@@ -187,12 +221,16 @@ public bool EqualsData(Card other)
/// <returns>结果</returns>
public bool Equals(Card other)
{
bool equalBool=EqualsData(other);
bool equalBool=this.EqualsData(other);
if(!equalBool)
return false;
else if (this.str.Length != other.str.Length)
equalBool = false;
else
{
return false;
}
else if (this.str.Length != other.str.Length)
{
equalBool = false;
}
else
{
int l = this.str.Length;
for (int i = 0; i < l; i++)
......@@ -213,7 +251,7 @@ public bool Equals(Card other)
public override int GetHashCode()
{
// combine the hash codes of all members here (e.g. with XOR operator ^)
int hashCode = id.GetHashCode() + name.GetHashCode();
int hashCode = this.id.GetHashCode() + this.name.GetHashCode();
return hashCode;//member.GetHashCode();
}
/// <summary>
......@@ -230,8 +268,11 @@ public override int GetHashCode()
/// <returns></returns>
public bool IsType(CardType type){
if((this.type & (long)type) == (long)type)
return true;
return false;
{
return true;
}
return false;
}
/// <summary>
/// 是否是某系列
......@@ -246,8 +287,11 @@ public bool IsSetCode(long sc)
while (setcode != 0)
{
if ((setcode & 0xfff) == settype && (setcode & 0xf000 & setsubtype) == setsubtype)
{
return true;
setcode = setcode >> 0x10;
}
setcode >>= 0x10;
}
return false;
}
......@@ -264,47 +308,54 @@ public bool IsSetCode(long sc)
/// <summary>
/// 密码字符串
/// </summary>
public string idString
public string IdString
{
get { return id.ToString("00000000"); }
get { return this.id.ToString("00000000"); }
}
/// <summary>
/// 字符串化
/// </summary>
public override string ToString()
{
string str = "";
if (IsType(CardType.TYPE_MONSTER)){
str = name + "[" + idString + "]\n["
+ YGOUtil.GetTypeString(type) + "] "
+ YGOUtil.GetRace(race) + "/" + YGOUtil.GetAttributeString(attribute)
+ "\n" + levelString() + " " + atk + "/" + def + "\n" + redesc();
string str;
if (this.IsType(CardType.TYPE_MONSTER)){
str = this.name + "[" + this.IdString + "]\n["
+ YGOUtil.GetTypeString(this.type) + "] "
+ YGOUtil.GetRace(this.race) + "/" + YGOUtil.GetAttributeString(this.attribute)
+ "\n" + this.levelString() + " " + this.atk + "/" + this.def + "\n" + this.redesc();
}else
str = name +"[" +idString +"]\n["+YGOUtil.GetTypeString(type)+"]\n"+redesc();
{
str = this.name +"[" + this.IdString +"]\n["+YGOUtil.GetTypeString(this.type)+"]\n"+ this.redesc();
}
return str;
}
public string ToShortString(){
return this.name+" ["+idString+"]";
return this.name+" ["+ this.IdString +"]";
}
public string ToLongString(){
return ToString();
return this.ToString();
}
string levelString()
{
string star = "[";
long i = 0, j = level & 0xff;
long j = this.level & 0xff;
long i;
for (i = 0; i < j; i++)
{
if (i > 0 && (i % 4) == 0)
{
star += " ";
}
star += "★";
}
return star + "]";
}
string redesc()
{
string str = desc.Replace(Environment.NewLine, "\n");
string str = this.desc.Replace(Environment.NewLine, "\n");
str = Regex.Replace(str, "([。|?|?])", "$1\n");
str = str.Replace("\n\n", "\n");
return str;
......
......@@ -10,7 +10,7 @@ namespace DataEditorX.Core
{
public class CardEdit
{
IDataForm dataform;
readonly IDataForm dataform;
public AddCommand addCard;
public ModCommand modCard;
public DelCommand delCard;
......@@ -30,9 +30,8 @@ public CardEdit(IDataForm dataform)
public class AddCommand: IBackableCommand
{
private string _undoSQL;
CardEdit cardedit;
IDataForm dataform;
readonly CardEdit cardedit;
readonly IDataForm dataform;
public AddCommand(CardEdit cardedit)
{
this.cardedit = cardedit;
......@@ -41,15 +40,18 @@ public AddCommand(CardEdit cardedit)
public bool Excute(params object[] args)
{
if (!dataform.CheckOpen())
return false;
Card c = dataform.GetCard();
if (!this.dataform.CheckOpen())
{
return false;
}
Card c = this.dataform.GetCard();
if (c.id <= 0)//卡片密码不能小于等于0
{
MyMsg.Error(LMSG.CodeCanNotIsZero);
return false;
}
Card[] cards = dataform.GetCardList(false);
Card[] cards = this.dataform.GetCardList(false);
foreach (Card ckey in cards)//卡片id存在
{
if (c.id == ckey.id)
......@@ -58,13 +60,13 @@ public bool Excute(params object[] args)
return false;
}
}
if (DataBase.Command(dataform.GetOpenFile(),
if (DataBase.Command(this.dataform.GetOpenFile(),
DataBase.GetInsertSQL(c, true)) >= 2)
{
MyMsg.Show(LMSG.AddSucceed);
_undoSQL = DataBase.GetDeleteSQL(c);
dataform.Search(true);
dataform.SetCard(c);
this._undoSQL = DataBase.GetDeleteSQL(c);
this.dataform.Search(true);
this.dataform.SetCard(c);
return true;
}
MyMsg.Error(LMSG.AddFail);
......@@ -72,7 +74,7 @@ public bool Excute(params object[] args)
}
public void Undo()
{
DataBase.Command(dataform.GetOpenFile(), _undoSQL);
DataBase.Command(this.dataform.GetOpenFile(), this._undoSQL);
}
public object Clone()
......@@ -91,9 +93,8 @@ public class ModCommand: IBackableCommand
private long oldid;
private long newid;
private bool delold;
CardEdit cardedit;
IDataForm dataform;
readonly CardEdit cardedit;
readonly IDataForm dataform;
public ModCommand(CardEdit cardedit)
{
this.cardedit = cardedit;
......@@ -102,12 +103,15 @@ public ModCommand(CardEdit cardedit)
public bool Excute(params object[] args)
{
if (!dataform.CheckOpen())
return false;
bool modfiles = (bool)args[0];
if (!this.dataform.CheckOpen())
{
return false;
}
Card c = dataform.GetCard();
Card oldCard = dataform.GetOldCard();
bool modfiles = (bool)args[0];
Card c = this.dataform.GetCard();
Card oldCard = this.dataform.GetOldCard();
if (c.Equals(oldCard))//没有修改
{
MyMsg.Show(LMSG.ItIsNotChanged);
......@@ -125,7 +129,7 @@ public bool Excute(params object[] args)
bool delold = MyMsg.Question(LMSG.IfDeleteCard);
if (delold)//是否删除旧卡片
{
if (DataBase.Command(dataform.GetOpenFile(),
if (DataBase.Command(this.dataform.GetOpenFile(),
DataBase.GetDeleteSQL(oldCard)) < 2)
{
//删除失败
......@@ -134,19 +138,26 @@ public bool Excute(params object[] args)
}
else
{//删除成功,添加还原sql
_undoSQL = DataBase.GetDeleteSQL(c) + DataBase.GetInsertSQL(oldCard, false);
this._undoSQL = DataBase.GetDeleteSQL(c) + DataBase.GetInsertSQL(oldCard, false);
}
}
else
_undoSQL = DataBase.GetDeleteSQL(c);//还原就是删除
//如果删除旧卡片,则把资源修改名字,否则复制资源
if(modfiles)
{
this._undoSQL = DataBase.GetDeleteSQL(c);//还原就是删除
}
//如果删除旧卡片,则把资源修改名字,否则复制资源
if (modfiles)
{
if (delold)
YGOUtil.CardRename(c.id, oldCard.id, dataform.GetPath());
else
YGOUtil.CardCopy(c.id, oldCard.id, dataform.GetPath());
this.modifiled = true;
{
YGOUtil.CardRename(c.id, oldCard.id, this.dataform.GetPath());
}
else
{
YGOUtil.CardCopy(c.id, oldCard.id, this.dataform.GetPath());
}
this.modifiled = true;
this.oldid = oldCard.id;
this.newid = c.id;
this.delold = delold;
......@@ -155,30 +166,37 @@ public bool Excute(params object[] args)
else
{//更新数据
sql = DataBase.GetUpdateSQL(c);
_undoSQL = DataBase.GetUpdateSQL(oldCard);
this._undoSQL = DataBase.GetUpdateSQL(oldCard);
}
if (DataBase.Command(dataform.GetOpenFile(), sql) > 0)
if (DataBase.Command(this.dataform.GetOpenFile(), sql) > 0)
{
MyMsg.Show(LMSG.ModifySucceed);
dataform.Search(true);
dataform.SetCard(c);
this.dataform.Search(true);
this.dataform.SetCard(c);
return true;
}
else
MyMsg.Error(LMSG.ModifyFail);
return false;
{
MyMsg.Error(LMSG.ModifyFail);
}
return false;
}
public void Undo()
{
DataBase.Command(dataform.GetOpenFile(), _undoSQL);
DataBase.Command(this.dataform.GetOpenFile(), this._undoSQL);
if (this.modifiled)
{
if (this.delold)
YGOUtil.CardRename(this.oldid, this.newid, dataform.GetPath());
else
YGOUtil.CardDelete(this.newid, dataform.GetPath());
}
{
YGOUtil.CardRename(this.oldid, this.newid, this.dataform.GetPath());
}
else
{
YGOUtil.CardDelete(this.newid, this.dataform.GetPath());
}
}
}
public object Clone()
......@@ -193,9 +211,8 @@ public object Clone()
public class DelCommand : IBackableCommand
{
private string _undoSQL;
CardEdit cardedit;
IDataForm dataform;
readonly CardEdit cardedit;
readonly IDataForm dataform;
public DelCommand(CardEdit cardedit)
{
this.cardedit = cardedit;
......@@ -204,17 +221,26 @@ public DelCommand(CardEdit cardedit)
public bool Excute(params object[] args)
{
if (!dataform.CheckOpen())
return false;
bool deletefiles = (bool)args[0];
if (!this.dataform.CheckOpen())
{
return false;
}
Card[] cards = dataform.GetCardList(true);
bool deletefiles = (bool)args[0];
Card[] cards = this.dataform.GetCardList(true);
if (cards == null || cards.Length == 0)
return false;
string undo = "";
{
return false;
}
string undo = "";
if (!MyMsg.Question(LMSG.IfDeleteCard))
return false;
List<string> sql = new List<string>();
{
return false;
}
List<string> sql = new List<string>();
foreach (Card c in cards)
{
sql.Add(DataBase.GetDeleteSQL(c));//删除
......@@ -222,26 +248,26 @@ public bool Excute(params object[] args)
//删除资源
if (deletefiles)
{
YGOUtil.CardDelete(c.id, dataform.GetPath());
YGOUtil.CardDelete(c.id, this.dataform.GetPath());
}
}
if (DataBase.Command(dataform.GetOpenFile(), sql.ToArray()) >= (sql.Count * 2))
if (DataBase.Command(this.dataform.GetOpenFile(), sql.ToArray()) >= (sql.Count * 2))
{
MyMsg.Show(LMSG.DeleteSucceed);
dataform.Search(true);
_undoSQL = undo;
this.dataform.Search(true);
this._undoSQL = undo;
return true;
}
else
{
MyMsg.Error(LMSG.DeleteFail);
dataform.Search(true);
this.dataform.Search(true);
}
return false;
}
public void Undo()
{
DataBase.Command(dataform.GetOpenFile(), _undoSQL);
DataBase.Command(this.dataform.GetOpenFile(), this._undoSQL);
}
public object Clone()
......@@ -255,15 +281,18 @@ public object Clone()
//打开脚本
public bool OpenScript(bool openinthis, string addrequire)
{
if (!dataform.CheckOpen())
return false;
Card c = dataform.GetCard();
if (!this.dataform.CheckOpen())
{
return false;
}
Card c = this.dataform.GetCard();
long id = c.id;
string lua;
if (c.id > 0) {
lua = dataform.GetPath().GetScript(id);
lua = this.dataform.GetPath().GetScript(id);
} else if (addrequire.Length > 0) {
lua = dataform.GetPath().GetModuleScript(addrequire);
lua = this.dataform.GetPath().GetModuleScript(addrequire);
} else {
return false;
}
......@@ -307,10 +336,15 @@ public bool OpenScript(bool openinthis, string addrequire)
if (File.Exists(lua))//如果存在,则打开文件
{
if (openinthis)//是否用本程序打开
MyConfig.OpenFileInThis(lua);
else
System.Diagnostics.Process.Start(lua);
return true;
{
MyConfig.OpenFileInThis(lua);
}
else
{
System.Diagnostics.Process.Start(lua);
}
return true;
}
return false;
}
......@@ -323,9 +357,8 @@ public class CopyCommand : IBackableCommand
Card[] NewCards;
bool replace;
Card[] OldCards;
CardEdit cardedit;
IDataForm dataform;
readonly CardEdit cardedit;
readonly IDataForm dataform;
public CopyCommand(CardEdit cardedit)
{
this.cardedit = cardedit;
......@@ -334,14 +367,20 @@ public CopyCommand(CardEdit cardedit)
public bool Excute(params object[] args)
{
if (!dataform.CheckOpen())
return false;
Card[] cards = (Card[])args[0];
if (!this.dataform.CheckOpen())
{
return false;
}
Card[] cards = (Card[])args[0];
if (cards == null || cards.Length == 0)
return false;
bool replace = false;
Card[] oldcards = DataBase.Read(dataform.GetOpenFile(), true, "");
{
return false;
}
bool replace = false;
Card[] oldcards = DataBase.Read(this.dataform.GetOpenFile(), true, "");
if (oldcards != null && oldcards.Length != 0)
{
int i = 0;
......@@ -360,10 +399,12 @@ public bool Excute(params object[] args)
}
}
if (i > 0)
break;
}
{
break;
}
}
}
DataBase.CopyDB(dataform.GetOpenFile(), !replace, cards);
DataBase.CopyDB(this.dataform.GetOpenFile(), !replace, cards);
this.copied = true;
this.NewCards = cards;
this.replace = replace;
......@@ -372,19 +413,24 @@ public bool Excute(params object[] args)
}
public void Undo()
{
DataBase.DeleteDB(dataform.GetOpenFile(), this.NewCards);
DataBase.CopyDB(dataform.GetOpenFile(), !this.replace, this.OldCards);
DataBase.DeleteDB(this.dataform.GetOpenFile(), this.NewCards);
DataBase.CopyDB(this.dataform.GetOpenFile(), !this.replace, this.OldCards);
}
public object Clone()
{
CopyCommand replica = new CopyCommand(cardedit);
replica.copied = this.copied;
replica.NewCards = (Card[])this.NewCards.Clone();
replica.replace = this.replace;
if (this.OldCards != null)
replica.OldCards = (Card[])this.OldCards.Clone();
return replica;
CopyCommand replica = new CopyCommand(this.cardedit)
{
copied = this.copied,
NewCards = (Card[])this.NewCards.Clone(),
replace = this.replace
};
if (this.OldCards != null)
{
replica.OldCards = (Card[])this.OldCards.Clone();
}
return replica;
}
}
#endregion
......
......@@ -22,15 +22,15 @@ public interface ICommandManager
}
public class CommandManager : ICommandManager
{
private Stack<ICommand> undoStack = new Stack<ICommand>();
private Stack<ICommand> reverseStack = new Stack<ICommand>();
private readonly Stack<ICommand> undoStack = new Stack<ICommand>();
private readonly Stack<ICommand> reverseStack = new Stack<ICommand>();
public event StatusBool UndoStateChanged;
public CommandManager()
{
UndoStateChanged += new StatusBool(CommandManager_UndoStateChanged);
UndoStateChanged += new StatusBool(CommandManager_ReverseUndoStateChanged);
UndoStateChanged += new StatusBool(this.CommandManager_UndoStateChanged);
UndoStateChanged += new StatusBool(this.CommandManager_ReverseUndoStateChanged);
}
private void CommandManager_UndoStateChanged(bool val)
......@@ -46,48 +46,52 @@ private void CommandManager_ReverseUndoStateChanged(bool val)
#region ICommandManager 成员
public void ExcuteCommand(ICommand command, params object[] args)
{
if(!command.Excute(args)) return;
reverseStack.Clear();
if(!command.Excute(args))
{
return;
}
this.reverseStack.Clear();
if (command is IBackableCommand)
{
undoStack.Push((ICommand)command.Clone());
this.undoStack.Push((ICommand)command.Clone());
}
else
{
undoStack.Clear();
this.undoStack.Clear();
}
UndoStateChanged(undoStack.Count > 0);
UndoStateChanged(this.undoStack.Count > 0);
}
public void Undo()
{
IBackableCommand command = (IBackableCommand)undoStack.Pop();
IBackableCommand command = (IBackableCommand)this.undoStack.Pop();
if (command == null)
{
return;
}
command.Undo();
reverseStack.Push((ICommand)command.Clone());
this.reverseStack.Push((ICommand)command.Clone());
UndoStateChanged(undoStack.Count > 0);
UndoStateChanged(this.undoStack.Count > 0);
//UndoStateChanged(reverseStack.Count > 0);
}
public void ReverseUndo()
{
IBackableCommand command = (IBackableCommand)reverseStack.Pop();
IBackableCommand command = (IBackableCommand)this.reverseStack.Pop();
if (command == null)
{
return;
}
command.Excute();
undoStack.Push((ICommand)command.Clone());
this.undoStack.Push((ICommand)command.Clone());
UndoStateChanged(undoStack.Count > 0);
UndoStateChanged(this.undoStack.Count > 0);
}
#endregion
}
......
......@@ -19,12 +19,12 @@ namespace DataEditorX.Core
public static class DataBase
{
#region 默认
static string defaultSQL;
static string defaultTableSQL;
static readonly string _defaultSQL;
static readonly string _defaultTableSQL;
static DataBase()
{
defaultSQL =
_defaultSQL =
"SELECT datas.*,texts.* FROM datas,texts WHERE datas.id=texts.id ";
StringBuilder st = new StringBuilder();
st.Append(@"CREATE TABLE texts(id integer primary key,name text,desc text");
......@@ -39,24 +39,27 @@ static DataBase()
st.Append("id integer primary key,ot integer,alias integer,");
st.Append("setcode integer,type integer,atk integer,def integer,");
st.Append("level integer,race integer,attribute integer,category integer) ");
defaultTableSQL=st.ToString();
_defaultTableSQL=st.ToString();
st.Remove(0,st.Length);
st=null;
}
#endregion
#region 创建数据库
/// <summary>
/// 创建数据库
/// </summary>
/// <param name="Db">新数据库路径</param>
public static bool Create(string Db)
}
#endregion
#region 创建数据库
/// <summary>
/// 创建数据库
/// </summary>
/// <param name="Db">新数据库路径</param>
public static bool Create(string Db)
{
if ( File.Exists(Db) )
File.Delete(Db);
try{
{
File.Delete(Db);
}
try
{
SQLiteConnection.CreateFile(Db);
Command(Db, defaultTableSQL);
Command(Db, _defaultTableSQL);
}
catch
{
......@@ -67,7 +70,7 @@ public static bool Create(string Db)
public static bool CheckTable(string db)
{
try{
Command(db, defaultTableSQL);
Command(db, _defaultTableSQL);
}
catch
{
......@@ -125,28 +128,32 @@ public static int Command(string DB, params string[] SQLs)
#region 根据SQL读取
static Card ReadCard(SQLiteDataReader reader,bool reNewLine)
{
Card c = new Card(0);
c.id = reader.GetInt64(reader.GetOrdinal("id"));
c.ot = reader.GetInt32(reader.GetOrdinal("ot"));
c.alias = reader.GetInt64(reader.GetOrdinal("alias"));
c.setcode = reader.GetInt64(reader.GetOrdinal("setcode"));
c.type = reader.GetInt64(reader.GetOrdinal("type"));
c.atk = reader.GetInt32(reader.GetOrdinal("atk"));
c.def = reader.GetInt32(reader.GetOrdinal("def"));
c.level = reader.GetInt64(reader.GetOrdinal("level"));
c.race = reader.GetInt64(reader.GetOrdinal("race"));
c.attribute = reader.GetInt32(reader.GetOrdinal("attribute"));
c.category = reader.GetInt64(reader.GetOrdinal("category"));
c.name = reader.GetString(reader.GetOrdinal("name"));
c.desc = reader.GetString(reader.GetOrdinal("desc"));
if(reNewLine)
c.desc=Retext(c.desc);
string temp = null;
for ( int i = 0; i < 0x10; i++ )
Card c = new Card(0)
{
id = reader.GetInt64(reader.GetOrdinal("id")),
ot = reader.GetInt32(reader.GetOrdinal("ot")),
alias = reader.GetInt64(reader.GetOrdinal("alias")),
setcode = reader.GetInt64(reader.GetOrdinal("setcode")),
type = reader.GetInt64(reader.GetOrdinal("type")),
atk = reader.GetInt32(reader.GetOrdinal("atk")),
def = reader.GetInt32(reader.GetOrdinal("def")),
level = reader.GetInt64(reader.GetOrdinal("level")),
race = reader.GetInt64(reader.GetOrdinal("race")),
attribute = reader.GetInt32(reader.GetOrdinal("attribute")),
category = reader.GetInt64(reader.GetOrdinal("category")),
name = reader.GetString(reader.GetOrdinal("name")),
desc = reader.GetString(reader.GetOrdinal("desc"))
};
if (reNewLine)
{
c.desc=Retext(c.desc);
}
for ( int i = 0; i < 0x10; i++ )
{
temp = reader.GetString(reader.GetOrdinal("str"+(i+1).ToString()));
c.Str[i]= ( temp == null ) ? "":temp;
string temp = reader.GetString(reader.GetOrdinal("str" + (i + 1).ToString()));
c.Str[i]= temp ?? "";
}
return c;
}
......@@ -179,54 +186,68 @@ public static Card[] Read(string DB,bool reNewLine, params string[] SQLs)
{
List<Card> list=new List<Card>();
List<long> idlist=new List<long>();
string SQLstr = "";
if ( File.Exists(DB) && SQLs != null )
{
using ( SQLiteConnection sqliteconn = new SQLiteConnection(@"Data Source=" + DB) )
{
sqliteconn.Open();
using ( SQLiteTransaction trans = sqliteconn.BeginTransaction() )
{
using ( SQLiteCommand sqlitecommand = new SQLiteCommand(sqliteconn) )
{
foreach ( string str in SQLs )
{
int tmp;
int.TryParse(str, out tmp);
if ( string.IsNullOrEmpty(str) )
SQLstr = defaultSQL;
else if ( tmp >0)
SQLstr = defaultSQL + " and datas.id=" + tmp.ToString();
else if ( str.StartsWith("select",StringComparison.OrdinalIgnoreCase))
SQLstr = str;
else if(str.IndexOf("and ")>=0)
SQLstr = defaultSQL + str;
else
SQLstr = defaultSQL + " and texts.name like '%" + str+"%'";
sqlitecommand.CommandText = SQLstr;
using ( SQLiteDataReader reader = sqlitecommand.ExecuteReader() )
{
while ( reader.Read() )
{
Card c=ReadCard(reader,reNewLine);
if(idlist.IndexOf(c.id)<0){//不存在,则添加
idlist.Add(c.id);
list.Add(c);
}
}
reader.Close();
}
}
}
trans.Commit();
}
sqliteconn.Close();
}
}
if(list.Count==0)
return null;
return list.ToArray();
if (File.Exists(DB) && SQLs != null)
{
using (SQLiteConnection sqliteconn = new SQLiteConnection(@"Data Source=" + DB))
{
sqliteconn.Open();
using (SQLiteTransaction trans = sqliteconn.BeginTransaction())
{
using (SQLiteCommand sqlitecommand = new SQLiteCommand(sqliteconn))
{
foreach (string str in SQLs)
{
int.TryParse(str, out int tmp);
string SQLstr;
if (string.IsNullOrEmpty(str))
{
SQLstr = _defaultSQL;
}
else if (tmp > 0)
{
SQLstr = _defaultSQL + " and datas.id=" + tmp.ToString();
}
else if (str.StartsWith("select", StringComparison.OrdinalIgnoreCase))
{
SQLstr = str;
}
else if (str.IndexOf("and ") >= 0)
{
SQLstr = _defaultSQL + str;
}
else
{
SQLstr = _defaultSQL + " and texts.name like '%" + str + "%'";
}
sqlitecommand.CommandText = SQLstr;
using (SQLiteDataReader reader = sqlitecommand.ExecuteReader())
{
while (reader.Read())
{
Card c=ReadCard(reader,reNewLine);
if (idlist.IndexOf(c.id) < 0)
{//不存在,则添加
idlist.Add(c.id);
list.Add(c);
}
}
reader.Close();
}
}
}
trans.Commit();
}
sqliteconn.Close();
}
}
if (list.Count==0)
{
return null;
}
return list.ToArray();
}
#endregion
......@@ -326,37 +347,76 @@ public static string GetSelectSQL(Card c)
StringBuilder sb=new StringBuilder();
sb.Append("SELECT datas.*,texts.* FROM datas,texts WHERE datas.id=texts.id ");
if (c == null)
return sb.ToString();
if(!string.IsNullOrEmpty(c.name)){
{
return sb.ToString();
}
if (!string.IsNullOrEmpty(c.name)){
if(c.name.IndexOf("%%")>=0)
c.name=c.name.Replace("%%","%");
else
c.name="%"+c.name.Replace("%","/%").Replace("_","/_")+"%";
sb.Append(" and texts.name like '"+c.name.Replace("'", "''")+"' ");
{
c.name=c.name.Replace("%%","%");
}
else
{
c.name="%"+c.name.Replace("%","/%").Replace("_","/_")+"%";
}
sb.Append(" and texts.name like '"+c.name.Replace("'", "''")+"' ");
}
if(!string.IsNullOrEmpty(c.desc))
sb.Append(" and texts.desc like '%"+c.desc.Replace("'", "''") + "%' ");
if(c.ot>0)
sb.Append(" and datas.ot = "+c.ot.ToString());
if(c.attribute>0)
sb.Append(" and datas.attribute = "+c.attribute.ToString());
if ((c.level & 0xff) > 0)
sb.Append(" and (datas.level & 255) = "+toInt(c.level & 0xff));
{
sb.Append(" and texts.desc like '%"+c.desc.Replace("'", "''") + "%' ");
}
if (c.ot>0)
{
sb.Append(" and datas.ot = "+c.ot.ToString());
}
if (c.attribute>0)
{
sb.Append(" and datas.attribute = "+c.attribute.ToString());
}
if ((c.level & 0xff) > 0)
{
sb.Append(" and (datas.level & 255) = "+toInt(c.level & 0xff));
}
if ((c.level & 0xff000000) > 0)
{
sb.Append(" and (datas.level & 4278190080) = " + toInt(c.level & 0xff000000));
}
if ((c.level & 0xff0000) > 0)
{
sb.Append(" and (datas.level & 16711680) = " + toInt(c.level & 0xff0000));
}
if (c.race>0)
sb.Append(" and datas.race = "+toInt(c.race));
if(c.type>0)
sb.Append(" and datas.type & "+toInt(c.type)+" = "+toInt(c.type));
if(c.category>0)
sb.Append(" and datas.category & "+toInt(c.category)+" = "+toInt(c.category));
if(c.atk==-1)
sb.Append(" and datas.type & 1 = 1 and datas.atk = 0");
else if(c.atk<0 || c.atk>0)
sb.Append(" and datas.atk = "+c.atk.ToString());
{
sb.Append(" and datas.race = "+toInt(c.race));
}
if (c.type>0)
{
sb.Append(" and datas.type & "+toInt(c.type)+" = "+toInt(c.type));
}
if (c.category>0)
{
sb.Append(" and datas.category & "+toInt(c.category)+" = "+toInt(c.category));
}
if (c.atk==-1)
{
sb.Append(" and datas.type & 1 = 1 and datas.atk = 0");
}
else if(c.atk<0 || c.atk>0)
{
sb.Append(" and datas.atk = "+c.atk.ToString());
}
if (c.IsType(Info.CardType.TYPE_LINK))
{
sb.Append(" and datas.def &" + c.def.ToString() + "=" + c.def.ToString());
......@@ -364,20 +424,29 @@ public static string GetSelectSQL(Card c)
else
{
if (c.def == -1)
{
sb.Append(" and datas.type & 1 = 1 and datas.def = 0");
}
else if (c.def < 0 || c.def > 0)
{
sb.Append(" and datas.def = " + c.def.ToString());
}
}
if(c.id>0 && c.alias>0)
sb.Append(" and datas.id BETWEEN "+c.alias.ToString()+" and "+c.id.ToString());
else if(c.id>0)
{
sb.Append(" and datas.id BETWEEN "+c.alias.ToString()+" and "+c.id.ToString());
}
else if(c.id>0)
{
sb.Append(" and ( datas.id="+c.id.ToString()+" or datas.alias="+c.id.ToString()+") ");
}
else if(c.alias>0)
sb.Append(" and datas.alias= "+c.alias.ToString());
return sb.ToString();
{
sb.Append(" and datas.alias= "+c.alias.ToString());
}
return sb.ToString();
}
#endregion
......@@ -393,10 +462,15 @@ public static string GetInsertSQL(Card c, bool ignore,bool hex= false)
{
StringBuilder st = new StringBuilder();
if(ignore)
st.Append("INSERT or ignore into datas values(");
else
st.Append("INSERT or replace into datas values(");
st.Append(c.id.ToString()); st.Append(",");
{
st.Append("INSERT or ignore into datas values(");
}
else
{
st.Append("INSERT or replace into datas values(");
}
st.Append(c.id.ToString()); st.Append(",");
st.Append(c.ot.ToString()); st.Append(",");
st.Append(c.alias.ToString()); st.Append(",");
if(hex){
......@@ -420,10 +494,15 @@ public static string GetInsertSQL(Card c, bool ignore,bool hex= false)
st.Append(c.category.ToString()); st.Append(")");
}
if(ignore)
st.Append(";\nINSERT or ignore into texts values(");
else
st.Append(";\nINSERT or replace into texts values(");
st.Append(c.id.ToString()); st.Append(",'");
{
st.Append(";\nINSERT or ignore into texts values(");
}
else
{
st.Append(";\nINSERT or replace into texts values(");
}
st.Append(c.id.ToString()); st.Append(",'");
st.Append(c.name.Replace("'", "''")); st.Append("','");
st.Append(c.desc.Replace("'", "''"));
for ( int i = 0; i < 0x10; i++ )
......@@ -432,8 +511,7 @@ public static string GetInsertSQL(Card c, bool ignore,bool hex= false)
}
st.Append("');");
string sql = st.ToString();
st = null;
return sql;
return sql;
}
#endregion
......@@ -471,8 +549,7 @@ public static string GetUpdateSQL(Card c)
st.Append("' where id="); st.Append(c.id.ToString());
st.Append(";");
string sql = st.ToString();
st = null;
return sql;
return sql;
}
#endregion
......@@ -491,7 +568,7 @@ public static string GetDeleteSQL(Card c)
#endregion
public static void exportSql(String file,params Card[] cards){
public static void ExportSql(string file,params Card[] cards){
using (FileStream fs = new FileStream(file, FileMode.Create, FileAccess.Write))
{
StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
......@@ -503,7 +580,7 @@ public static string GetDeleteSQL(Card c)
}
}
public static CardPack findPack(string db, long id){
public static CardPack FindPack(string db, long id){
CardPack cardpack=null;
if ( File.Exists(db) && id>=0)
{
......@@ -517,12 +594,14 @@ public static string GetDeleteSQL(Card c)
{
if(reader.Read())
{
cardpack=new CardPack(id);
cardpack.pack_id=reader.GetString(1);
cardpack.pack_name=reader.GetString(2);
cardpack.rarity=reader.GetString(3);
cardpack.date=reader.GetString(4);
}
cardpack = new CardPack(id)
{
pack_id = reader.GetString(1),
pack_name = reader.GetString(2),
rarity = reader.GetString(3),
date = reader.GetString(4)
};
}
reader.Close();
}
}
......
......@@ -19,26 +19,26 @@ namespace DataEditorX
public class LuaFunction
{
#region 日志log
static void ResetLog(string file)
static void ResetLog()
{
File.Delete(logtxt);
File.Delete(_logtxt);
}
static void Log(string str)
{
File.AppendAllText(logtxt, str+Environment.NewLine);
File.AppendAllText(_logtxt, str+Environment.NewLine);
}
#endregion
#region old functions
static string oldfun;
static string logtxt;
static string funclisttxt;
static SortedList<string,string> funclist=new SortedList<string,string>();
static string _oldfun;
static string _logtxt;
static string _funclisttxt;
static readonly SortedList<string,string> _funclist=new SortedList<string,string>();
//读取旧函数
public static void Read(string funtxt)
{
funclist.Clear();
oldfun=funtxt;
_funclist.Clear();
_oldfun=funtxt;
if(File.Exists(funtxt))
{
string[] lines=File.ReadAllLines(funtxt);
......@@ -50,8 +50,11 @@ public static void Read(string funtxt)
if(string.IsNullOrEmpty(line)
|| line.StartsWith("==")
|| line.StartsWith("#"))
continue;
if(line.StartsWith("●"))
{
continue;
}
if (line.StartsWith("●"))
{
//添加之前的函数
AddOldFun(name, desc);
......@@ -76,13 +79,13 @@ static void AddOldFun(string name, string desc)
{
if (!string.IsNullOrEmpty(name))
{
if (funclist.ContainsKey(name))//存在,则添加注释
if (_funclist.ContainsKey(name))//存在,则添加注释
{
funclist[name] += Environment.NewLine + desc;
_funclist[name] += Environment.NewLine + desc;
}
else
{//不存在,则添加函数
funclist.Add(name, desc);
_funclist.Add(name, desc);
}
}
}
......@@ -99,10 +102,10 @@ public static bool Find(string path)
string name="interpreter.cpp";
string file=Path.Combine(path,name);
string file2=Path.Combine(Path.Combine(path, "ocgcore"), name);
logtxt=Path.Combine(path, "find_functions.log");
ResetLog(logtxt);
funclisttxt =Path.Combine(path, "_functions.txt");
File.Delete(funclisttxt);
_logtxt=Path.Combine(path, "find_functions.log");
ResetLog();
_funclisttxt =Path.Combine(path, "_functions.txt");
File.Delete(_funclisttxt);
if(!File.Exists(file)){//判断用户选择的目录
Log("error: no find file "+file);
if(File.Exists(file2)){
......@@ -135,16 +138,19 @@ public static bool Find(string path)
//保存
static void Save()
{
if (string.IsNullOrEmpty(oldfun))
if (string.IsNullOrEmpty(_oldfun))
{
return;
using (FileStream fs = new FileStream(oldfun + "_sort.txt",
}
using (FileStream fs = new FileStream(_oldfun + "_sort.txt",
FileMode.Create,
FileAccess.Write))
{
StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
foreach (string k in funclist.Keys)
foreach (string k in _funclist.Keys)
{
sw.WriteLine("●" + funclist[k]);
sw.WriteLine("●" + _funclist[k]);
}
sw.Close();
}
......@@ -171,8 +177,10 @@ static string ToTitle(string str)
string k=ToTitle(name)+"."+m.Groups[1].Value;
string v=m.Groups[2].Value;
if(!dic.ContainsKey(k))
dic.Add(k,v);
}
{
dic.Add(k,v);
}
}
}
return dic;
}
......@@ -189,41 +197,63 @@ static string FindCode(string texts,string name)
if(mc.Success)
{
if(mc.Groups.Count>1)
return mc.Groups[0].Value
{
return mc.Groups[0].Value
.Replace("\r\n","\n")
.Replace("\r","\n")
.Replace("\n",Environment.NewLine);
}
}
}
return "";
}
#endregion
#region find return
//查找返回类型
static string FindReturn(string texts,string name)
static string FindReturn(string texts)
{
string restr="";
if(texts.IndexOf("lua_pushboolean")>=0)
return "bool ";
else
{
return "bool ";
}
else
{
if(texts.IndexOf("interpreter::card2value")>=0)
restr += "Card ";
if(texts.IndexOf("interpreter::group2value")>=0)
restr += "Group ";
if(texts.IndexOf("interpreter::effect2value")>=0)
restr += "Effect ";
else if(texts.IndexOf("interpreter::function2value")>=0)
restr += "function ";
if(texts.IndexOf("lua_pushinteger")>=0)
restr += "int ";
if(texts.IndexOf("lua_pushstring")>=0)
restr += "string ";
}
{
restr += "Card ";
}
if (texts.IndexOf("interpreter::group2value")>=0)
{
restr += "Group ";
}
if (texts.IndexOf("interpreter::effect2value")>=0)
{
restr += "Effect ";
}
else if(texts.IndexOf("interpreter::function2value")>=0)
{
restr += "function ";
}
if (texts.IndexOf("lua_pushinteger")>=0)
{
restr += "int ";
}
if (texts.IndexOf("lua_pushstring")>=0)
{
restr += "string ";
}
}
if(string.IsNullOrEmpty(restr))
restr="void ";
if(restr.IndexOf(" ") !=restr.Length-1){
{
restr ="void ";
}
if (restr.IndexOf(" ") !=restr.Length-1){
restr = restr.Replace(" ","|").Substring(0,restr.Length-1)+" ";
}
return restr;
......@@ -235,13 +265,21 @@ static string FindReturn(string texts,string name)
static string getUserType(string str)
{
if(str.IndexOf("card")>=0)
return "Card";
if(str.IndexOf("effect")>=0)
return "Effect";
if(str.IndexOf("group")>=0)
return "Group";
return "Any";
{
return "Card";
}
if (str.IndexOf("effect")>=0)
{
return "Effect";
}
if (str.IndexOf("group")>=0)
{
return "Group";
}
return "Any";
}
static void AddArgs(string texts,string regx,string arg,SortedList<int,string> dic)
......@@ -256,13 +294,17 @@ static void AddArgs(string texts,string regx,string arg,SortedList<int,string> d
string v=arg;
int k=int.Parse(m.Groups[1].Value);
if(dic.ContainsKey(k))
dic[k] = dic[k]+"|"+v;
else
dic.Add(k,v);
}
{
dic[k] = dic[k]+"|"+v;
}
else
{
dic.Add(k,v);
}
}
}
}
static string FindArgs(string texts,string name)
static string FindArgs(string texts)
{
SortedList<int,string> dic=new SortedList<int, string>();
//card effect ggroup
......@@ -276,10 +318,14 @@ static string FindArgs(string texts,string name)
v = getUserType(v);
int k=int.Parse(m.Groups[2].Value);
if(dic.ContainsKey(k))
dic[k] = dic[k]+"|"+v;
else
dic.Add(k,v);
}
{
dic[k] = dic[k]+"|"+v;
}
else
{
dic.Add(k,v);
}
}
}
//function
AddArgs(texts
......@@ -298,8 +344,11 @@ static string FindArgs(string texts,string name)
args +=dic[i]+", ";
}
if(args.Length>1)
args = args.Substring(0,args.Length-2);
args += ")";
{
args = args.Substring(0,args.Length-2);
}
args += ")";
return args;
}
#endregion
......@@ -308,9 +357,12 @@ static string FindArgs(string texts,string name)
//查找旧函数的描述
static string FindOldDesc(string name)
{
if(funclist.ContainsKey(name))
return funclist[name];
return "";
if(_funclist.ContainsKey(name))
{
return _funclist[name];
}
return "";
}
#endregion
......@@ -337,19 +389,19 @@ public static void GetFunctions(string name,string texts,string file)
{
StreamWriter sw=new StreamWriter(fs, Encoding.UTF8);
sw.WriteLine("========== "+name+" ==========");
File.AppendAllText(funclisttxt, "========== " + name + " ==========" + Environment.NewLine);
File.AppendAllText(_funclisttxt, "========== " + name + " ==========" + Environment.NewLine);
foreach(string k in fun.Keys)
{
string v=fun[k];
string code=FindCode(cpps, v);
string txt="●"+FindReturn(code,v)+k+FindArgs(code,v)
string txt="●"+FindReturn(code)+k+FindArgs(code)
+Environment.NewLine
+FindOldDesc(k)
+Environment.NewLine
+code;
sw.WriteLine(txt);
File.AppendAllText(funclisttxt,txt + Environment.NewLine);
File.AppendAllText(_funclisttxt,txt + Environment.NewLine);
}
sw.Close();
}
......
......@@ -31,8 +31,11 @@ public CardPack(long id)
public string getMseRarity(){
if(this.rarity==null)
return "common";
string rarity=this.rarity.Trim().ToLower();
{
return "common";
}
string rarity=this.rarity.Trim().ToLower();
if(rarity.Equals("common") || rarity.Equals("short print"))
{
return "common";
......
......@@ -63,76 +63,99 @@ public class MSEConfig
#endregion
public MSEConfig(string path)
{
init(path);
this.init(path);
}
public void SetConfig(string config, string path)
{
if (!File.Exists(config))
return;
regx_monster = "(\\s\\S*?)";
regx_pendulum = "(\\s\\S*?)";
//设置文件名
configName = MyPath.getFullFileName(MSEConfig.TAG, config);
{
return;
}
replaces = new SortedList<string, string>();
this.regx_monster = "(\\s\\S*?)";
this.regx_pendulum = "(\\s\\S*?)";
//设置文件名
this.configName = MyPath.getFullFileName(MSEConfig.TAG, config);
typeDic = new SortedList<long, string>();
raceDic = new SortedList<long, string>();
this.replaces = new SortedList<string, string>();
this.typeDic = new SortedList<long, string>();
this.raceDic = new SortedList<long, string>();
string[] lines = File.ReadAllLines(config, Encoding.UTF8);
foreach (string line in lines)
{
if (string.IsNullOrEmpty(line) || line.StartsWith("#"))
continue;
if (line.StartsWith(TAG_CN2TW))
Iscn2tw = ConfHelper.getBooleanValue(line);
else if (line.StartsWith(TAG_SPELL))
str_spell = ConfHelper.getValue(line);
else if (line.StartsWith(TAG_HEAD))
head = ConfHelper.getMultLineValue(line);
else if (line.StartsWith(TAG_END))
end = ConfHelper.getMultLineValue(line);
else if (line.StartsWith(TAG_TEXT))
temp_text = ConfHelper.getMultLineValue(line);
else if (line.StartsWith(TAG_TRAP))
str_trap = ConfHelper.getValue(line);
else if (line.StartsWith(TAG_REG_PENDULUM))
regx_pendulum = ConfHelper.getValue(line);
else if (line.StartsWith(TAG_REG_MONSTER))
regx_monster = ConfHelper.getValue(line);
else if (line.StartsWith(TAG_MAXCOUNT))
maxcount = ConfHelper.getIntegerValue(line, 0);
else if (line.StartsWith(TAG_WIDTH)){
width=ConfHelper.getIntegerValue(line,0);
{
continue;
}
if (line.StartsWith(TAG_CN2TW))
{
this.Iscn2tw = ConfHelper.getBooleanValue(line);
}
else if (line.StartsWith(TAG_SPELL))
{
this.str_spell = ConfHelper.getValue(line);
}
else if (line.StartsWith(TAG_HEAD))
{
this.head = ConfHelper.getMultLineValue(line);
}
else if (line.StartsWith(TAG_END))
{
this.end = ConfHelper.getMultLineValue(line);
}
else if (line.StartsWith(TAG_TEXT))
{
this.temp_text = ConfHelper.getMultLineValue(line);
}
else if (line.StartsWith(TAG_TRAP))
{
this.str_trap = ConfHelper.getValue(line);
}
else if (line.StartsWith(TAG_REG_PENDULUM))
{
this.regx_pendulum = ConfHelper.getValue(line);
}
else if (line.StartsWith(TAG_REG_MONSTER))
{
this.regx_monster = ConfHelper.getValue(line);
}
else if (line.StartsWith(TAG_MAXCOUNT))
{
this.maxcount = ConfHelper.getIntegerValue(line, 0);
}
else if (line.StartsWith(TAG_WIDTH)){
this.width =ConfHelper.getIntegerValue(line,0);
}
else if (line.StartsWith(TAG_HEIGHT)){
height=ConfHelper.getIntegerValue(line,0);
this.height =ConfHelper.getIntegerValue(line,0);
}
else if (line.StartsWith(TAG_PEND_WIDTH)){
pwidth=ConfHelper.getIntegerValue(line,0);
this.pwidth =ConfHelper.getIntegerValue(line,0);
}
else if (line.StartsWith(TAG_PEND_HEIGHT)){
pheight=ConfHelper.getIntegerValue(line,0);
this.pheight =ConfHelper.getIntegerValue(line,0);
}
else if(line.StartsWith(TAG_NO_TEN)){
no10 = ConfHelper.getBooleanValue(line);
this.no10 = ConfHelper.getBooleanValue(line);
}else if(line.StartsWith(TAG_NO_START_CARDS)){
string val = ConfHelper.getValue(line);
string[] cs = val.Split(',');
noStartCards=new long[cs.Length];
this.noStartCards =new long[cs.Length];
int i=0;
foreach(string str in cs){
long l = 0;
long.TryParse(str, out l);
noStartCards[i++] = l;
long.TryParse(str, out long l);
this.noStartCards[i++] = l;
}
}
else if (line.StartsWith(TAG_IMAGE))
{
//如果路径不合法,则为后面的路径
imagepath = MyPath.CheckDir(ConfHelper.getValue(line), MyPath.Combine(path, PATH_IMAGE));
//图片缓存目录
imagecache = MyPath.Combine(imagepath, "cache");
MyPath.CreateDir(imagecache);
//如果路径不合法,则为后面的路径
this.imagepath = MyPath.CheckDir(ConfHelper.getValue(line), MyPath.Combine(path, PATH_IMAGE));
//图片缓存目录
this.imagecache = MyPath.Combine(this.imagepath, "cache");
MyPath.CreateDir(this.imagecache);
}
else if (line.StartsWith(TAG_REPALCE))
{//特数字替换
......@@ -140,24 +163,25 @@ public void SetConfig(string config, string path)
string p = ConfHelper.getRegex(ConfHelper.getValue1(word));
string r = ConfHelper.getRegex(ConfHelper.getValue2(word));
if (!string.IsNullOrEmpty(p))
replaces.Add(p, r);
}
{
this.replaces.Add(p, r);
}
}
else if (line.StartsWith(TAG_RACE))
{//种族
ConfHelper.DicAdd(raceDic, line);
ConfHelper.DicAdd(this.raceDic, line);
}
else if (line.StartsWith(TAG_TYPE))
{//类型
ConfHelper.DicAdd(typeDic, line);
ConfHelper.DicAdd(this.typeDic, line);
}else if(line.StartsWith(TAG_REIMAGE)){
reimage = ConfHelper.getBooleanValue(line);
this.reimage = ConfHelper.getBooleanValue(line);
}
}
}
public void init(string path)
{
Iscn2tw = false;
this.Iscn2tw = false;
//读取配置
string tmp = MyPath.Combine(path, MyPath.getFileName(MSEConfig.TAG, MyConfig.readString(MyConfig.TAG_MSE)));
......@@ -166,9 +190,11 @@ public void init(string path)
{
tmp = MyPath.Combine(path, MyPath.getFileName(MSEConfig.TAG, FILE_CONFIG_NAME));
if(!File.Exists(tmp))
return;//如果默认的也不存在
}
SetConfig(tmp, path);
{
return;//如果默认的也不存在
}
}
this.SetConfig(tmp, path);
}
/// <summary>
/// 是否调整图片
......
......@@ -73,25 +73,25 @@ public class MseMaker
MSEConfig cfg;
public int MaxNum
{
get { return cfg.maxcount; }
get { return this.cfg.maxcount; }
}
public string ImagePath
{
get { return cfg.imagepath; }
get { return this.cfg.imagepath; }
}
public MseMaker(MSEConfig mcfg)
{
SetConfig(mcfg);
this.SetConfig(mcfg);
}
public void SetConfig(MSEConfig mcfg)
{
cfg = mcfg;
this.cfg = mcfg;
}
public MSEConfig GetConfig()
{
return cfg;
return this.cfg;
}
#endregion
......@@ -102,19 +102,19 @@ public string GetLine(string key, string word)
return " " + key + ": " + word;
}
//特殊字
public string reItalic(string str)
public string ReItalic(string str)
{
str = cn2tw(str);
foreach (string rs in cfg.replaces.Keys)
str = this.CN2TW(str);
foreach (string rs in this.cfg.replaces.Keys)
{
str = Regex.Replace(str, rs, cfg.replaces[rs]);
str = Regex.Replace(str, rs, this.cfg.replaces[rs]);
}
return str;
}
//简体转繁体
public string cn2tw(string str)
public string CN2TW(string str)
{
if (cfg.Iscn2tw)
if (this.cfg.Iscn2tw)
{
str = Strings.StrConv(str, VbStrConv.TraditionalChinese, 0);
str = str.Replace("巖", "岩");
......@@ -126,37 +126,58 @@ public string GetSpellTrapSymbol(Card c, bool isSpell)
{
string level;
if (c.IsType(CardType.TYPE_EQUIP))
level = MseSpellTrap.EQUIP;
else if (c.IsType(CardType.TYPE_QUICKPLAY))
level = MseSpellTrap.QUICKPLAY;
else if (c.IsType(CardType.TYPE_FIELD))
level = MseSpellTrap.FIELD;
else if (c.IsType(CardType.TYPE_CONTINUOUS))
level = MseSpellTrap.CONTINUOUS;
else if (c.IsType(CardType.TYPE_RITUAL))
level = MseSpellTrap.RITUAL;
else if (c.IsType(CardType.TYPE_COUNTER))
level = MseSpellTrap.COUNTER;
else if (cfg.str_spell == MSEConfig.TAG_REP && cfg.str_trap == MSEConfig.TAG_REP)
level = MseSpellTrap.NORMAL;//带文字的图片
else
level = "";
{
level = MseSpellTrap.EQUIP;
}
else if (c.IsType(CardType.TYPE_QUICKPLAY))
{
level = MseSpellTrap.QUICKPLAY;
}
else if (c.IsType(CardType.TYPE_FIELD))
{
level = MseSpellTrap.FIELD;
}
else if (c.IsType(CardType.TYPE_CONTINUOUS))
{
level = MseSpellTrap.CONTINUOUS;
}
else if (c.IsType(CardType.TYPE_RITUAL))
{
level = MseSpellTrap.RITUAL;
}
else if (c.IsType(CardType.TYPE_COUNTER))
{
level = MseSpellTrap.COUNTER;
}
else if (this.cfg.str_spell == MSEConfig.TAG_REP && this.cfg.str_trap == MSEConfig.TAG_REP)
{
level = MseSpellTrap.NORMAL;//带文字的图片
}
else
{
level = "";
}
if (isSpell)
level = cfg.str_spell.Replace(MSEConfig.TAG_REP, level);
else
level = cfg.str_trap.Replace(MSEConfig.TAG_REP, level);
return level;
if (isSpell)
{
level = this.cfg.str_spell.Replace(MSEConfig.TAG_REP, level);
}
else
{
level = this.cfg.str_trap.Replace(MSEConfig.TAG_REP, level);
}
return level;
}
//获取图片路径
public static string GetCardImagePath(string picpath, Card c)
{
//密码,带0密码,卡名
string jpg = MyPath.Combine(picpath, c.id + ".jpg");
string jpg2 = MyPath.Combine(picpath, c.idString + ".jpg");
string jpg2 = MyPath.Combine(picpath, c.IdString + ".jpg");
string jpg3 = MyPath.Combine(picpath, c.name + ".jpg");
string png = MyPath.Combine(picpath, c.id + ".png");
string png2 = MyPath.Combine(picpath, c.idString + ".png");
string png2 = MyPath.Combine(picpath, c.IdString + ".png");
string png3 = MyPath.Combine(picpath, c.name + ".png");
if (File.Exists(jpg))
{
......@@ -232,9 +253,12 @@ public static string GetDesc(string cdesc, string regx)
Regex regex = new Regex(regx, RegexOptions.Multiline);
Match mc = regex.Match(desc);
if (mc.Success)
return ((mc.Groups.Count > 1) ?
{
return ((mc.Groups.Count > 1) ?
mc.Groups[1].Value : mc.Groups[0].Value);
return "";
}
return "";
}
public string ReText(string text)
......@@ -260,17 +284,23 @@ public static string GetStar(long level)
//获取种族
public string GetRace(long race)
{
if (cfg.raceDic.ContainsKey(race))
return cfg.raceDic[race].Trim();
return race.ToString("x");
if (this.cfg.raceDic.ContainsKey(race))
{
return this.cfg.raceDic[race].Trim();
}
return race.ToString("x");
}
//获取类型文字
public string GetType(CardType ctype)
{
long type = (long)ctype;
if (cfg.typeDic.ContainsKey(type))
return cfg.typeDic[type].Trim();
return type.ToString("x");
if (this.cfg.typeDic.ContainsKey(type))
{
return this.cfg.typeDic[type].Trim();
}
return type.ToString("x");
}
//获取卡片类型
......@@ -285,10 +315,10 @@ public string[] GetTypes(Card c)
}
if (c.IsType(CardType.TYPE_MONSTER))
{
CardType[] cardTypes = CardTypes.GetMonsterTypes(c.type, cfg.no10);
CardType[] cardTypes = CardTypes.GetMonsterTypes(c.type, this.cfg.no10);
int count = cardTypes.Length;
for(int i=0; i<count && i<MAX_TYPE; i++){
types[i+1] = GetType(cardTypes[i]);
types[i+1] = this.GetType(cardTypes[i]);
}
if(cardTypes.Length>0){
if(c.IsType(CardType.TYPE_LINK)){
......@@ -345,12 +375,12 @@ public string[] GetTypes(Card c)
{
// MessageBox.Show(""+cfg.replaces.Keys[0]+"/"+cfg.replaces[cfg.replaces.Keys[0]]);
Dictionary<Card, string> list = new Dictionary<Card, string>();
string pic = cfg.imagepath;
string pic = this.cfg.imagepath;
using (FileStream fs = new FileStream(file,
FileMode.Create, FileAccess.Write))
{
StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
sw.WriteLine(cfg.head);
sw.WriteLine(this.cfg.head);
foreach (Card c in cards)
{
string jpg = GetCardImagePath(pic, c);
......@@ -359,13 +389,17 @@ public string[] GetTypes(Card c)
list.Add(c, jpg);
jpg = Path.GetFileName(jpg);
}
CardPack cardpack=DataBase.findPack(cardpack_db, c.id);
CardPack cardpack=DataBase.FindPack(cardpack_db, c.id);
if (c.IsType(CardType.TYPE_SPELL) || c.IsType(CardType.TYPE_TRAP))
sw.WriteLine(getSpellTrap(c, jpg, c.IsType(CardType.TYPE_SPELL), cardpack,rarity));
else
sw.WriteLine(getMonster(c, jpg, cardpack,rarity));
}
sw.WriteLine(cfg.end);
{
sw.WriteLine(this.getSpellTrap(c, jpg, c.IsType(CardType.TYPE_SPELL), cardpack,rarity));
}
else
{
sw.WriteLine(this.getMonster(c, jpg, cardpack,rarity));
}
}
sw.WriteLine(this.cfg.end);
sw.Close();
}
......@@ -386,15 +420,15 @@ public string[] GetTypes(Card c)
string getMonster(Card c, string img,CardPack cardpack=null,bool rarity=true)
{
StringBuilder sb = new StringBuilder();
string[] types = GetTypes(c);
string race = GetRace(c.race);
string[] types = this.GetTypes(c);
string race = this.GetRace(c.race);
sb.AppendLine(TAG_CARD + ":");
sb.AppendLine(GetLine(TAG_CARDTYPE, types[0]));
sb.AppendLine(GetLine(TAG_NAME, reItalic(c.name)));
sb.AppendLine(GetLine(TAG_ATTRIBUTE, GetAttribute(c.attribute)));
sb.AppendLine(this.GetLine(TAG_CARDTYPE, types[0]));
sb.AppendLine(this.GetLine(TAG_NAME, this.ReItalic(c.name)));
sb.AppendLine(this.GetLine(TAG_ATTRIBUTE, GetAttribute(c.attribute)));
bool noStar = false;
if(cfg.noStartCards != null){
foreach(long id in cfg.noStartCards){
if(this.cfg.noStartCards != null){
foreach(long id in this.cfg.noStartCards){
if(c.alias == id || c.id == id){
noStar = true;
break;
......@@ -402,72 +436,75 @@ string getMonster(Card c, string img,CardPack cardpack=null,bool rarity=true)
}
}
if(!noStar){
sb.AppendLine(GetLine(TAG_LEVEL, GetStar(c.level)));
}
sb.AppendLine(GetLine(TAG_IMAGE, img));
sb.AppendLine(GetLine(TAG_TYPE1, cn2tw(race)));
sb.AppendLine(GetLine(TAG_TYPE2, cn2tw(types[1])));
sb.AppendLine(GetLine(TAG_TYPE3, cn2tw(types[2])));
sb.AppendLine(GetLine(TAG_TYPE4, cn2tw(types[3])));
sb.AppendLine(GetLine(TAG_TYPE5, cn2tw(types[4])));
sb.AppendLine(this.GetLine(TAG_LEVEL, GetStar(c.level)));
}
sb.AppendLine(this.GetLine(TAG_IMAGE, img));
sb.AppendLine(this.GetLine(TAG_TYPE1, this.CN2TW(race)));
sb.AppendLine(this.GetLine(TAG_TYPE2, this.CN2TW(types[1])));
sb.AppendLine(this.GetLine(TAG_TYPE3, this.CN2TW(types[2])));
sb.AppendLine(this.GetLine(TAG_TYPE4, this.CN2TW(types[3])));
sb.AppendLine(this.GetLine(TAG_TYPE5, this.CN2TW(types[4])));
if(cardpack!=null){
sb.AppendLine(GetLine(TAG_NUMBER, cardpack.pack_id));
sb.AppendLine(this.GetLine(TAG_NUMBER, cardpack.pack_id));
if(rarity){
sb.AppendLine(GetLine(TAG_RARITY, cardpack.getMseRarity()));
sb.AppendLine(this.GetLine(TAG_RARITY, cardpack.getMseRarity()));
}
}
if(c.IsType(CardType.TYPE_LINK)){
if(CardLink.isLink(c.def, CardLink.DownLeft)){
sb.AppendLine(GetLine(TAG_Link_Marker_DL, "yes"));
sb.AppendLine(this.GetLine(TAG_Link_Marker_DL, "yes"));
}
if(CardLink.isLink(c.def, CardLink.Down)){
sb.AppendLine(GetLine(TAG_Link_Marker_Down, "yes"));
sb.AppendLine(this.GetLine(TAG_Link_Marker_Down, "yes"));
}
if(CardLink.isLink(c.def, CardLink.DownRight)){
sb.AppendLine(GetLine(TAG_Link_Marker_DR, "yes"));
sb.AppendLine(this.GetLine(TAG_Link_Marker_DR, "yes"));
}
if(CardLink.isLink(c.def, CardLink.UpLeft)){
sb.AppendLine(GetLine(TAG_Link_Marker_UL, "yes"));
sb.AppendLine(this.GetLine(TAG_Link_Marker_UL, "yes"));
}
if(CardLink.isLink(c.def, CardLink.Up)){
sb.AppendLine(GetLine(TAG_Link_Marker_Up, "yes"));
sb.AppendLine(this.GetLine(TAG_Link_Marker_Up, "yes"));
}
if(CardLink.isLink(c.def, CardLink.UpRight)){
sb.AppendLine(GetLine(TAG_Link_Marker_UR, "yes"));
sb.AppendLine(this.GetLine(TAG_Link_Marker_UR, "yes"));
}
if(CardLink.isLink(c.def, CardLink.Left)){
sb.AppendLine(GetLine(TAG_Link_Marker_Left, "yes"));
sb.AppendLine(this.GetLine(TAG_Link_Marker_Left, "yes"));
}
if(CardLink.isLink(c.def, CardLink.Right)){
sb.AppendLine(GetLine(TAG_Link_Marker_Right, "yes"));
sb.AppendLine(this.GetLine(TAG_Link_Marker_Right, "yes"));
}
sb.AppendLine(GetLine(TAG_Link_Number, ""+getLinkNumber(c.def)));
sb.AppendLine(this.GetLine(TAG_Link_Number, ""+ this.getLinkNumber(c.def)));
sb.AppendLine(" " + TAG_TEXT + ":");
sb.AppendLine(" " + ReText(reItalic(c.desc)));
sb.AppendLine(" " + this.ReText(this.ReItalic(c.desc)));
}else{
if (c.IsType(CardType.TYPE_PENDULUM))//P怪兽
{
string text = GetDesc(c.desc, cfg.regx_monster);
string text = GetDesc(c.desc, this.cfg.regx_monster);
if (string.IsNullOrEmpty(text))
text = c.desc;
sb.AppendLine(" " + TAG_TEXT + ":");
{
text = c.desc;
}
sb.AppendLine(" " + TAG_TEXT + ":");
//sb.AppendLine(cfg.regx_monster + ":" + cfg.regx_pendulum);
sb.AppendLine(" " + ReText(reItalic(text)));
sb.AppendLine(GetLine(TAG_PENDULUM, "medium"));
sb.AppendLine(GetLine(TAG_PSCALE1, ((c.level >> 0x18) & 0xff).ToString()));
sb.AppendLine(GetLine(TAG_PSCALE2, ((c.level >> 0x10) & 0xff).ToString()));
sb.AppendLine(" " + this.ReText(this.ReItalic(text)));
sb.AppendLine(this.GetLine(TAG_PENDULUM, "medium"));
sb.AppendLine(this.GetLine(TAG_PSCALE1, ((c.level >> 0x18) & 0xff).ToString()));
sb.AppendLine(this.GetLine(TAG_PSCALE2, ((c.level >> 0x10) & 0xff).ToString()));
sb.AppendLine(" " + TAG_PEND_TEXT + ":");
sb.AppendLine(" " + ReText(reItalic(GetDesc(c.desc, cfg.regx_pendulum))));
sb.AppendLine(" " + this.ReText(this.ReItalic(GetDesc(c.desc, this.cfg.regx_pendulum))));
}else//一般怪兽
{
sb.AppendLine(" " + TAG_TEXT + ":");
sb.AppendLine(" " + ReText(reItalic(c.desc)));
sb.AppendLine(" " + this.ReText(this.ReItalic(c.desc)));
}
sb.AppendLine(GetLine(TAG_DEF, (c.def < 0) ? UNKNOWN_ATKDEF : c.def.ToString()));
sb.AppendLine(this.GetLine(TAG_DEF, (c.def < 0) ? UNKNOWN_ATKDEF : c.def.ToString()));
}
sb.AppendLine(GetLine(TAG_ATK, (c.atk < 0) ? UNKNOWN_ATKDEF : c.atk.ToString()));
sb.AppendLine(this.GetLine(TAG_ATK, (c.atk < 0) ? UNKNOWN_ATKDEF : c.atk.ToString()));
sb.AppendLine(GetLine(TAG_CODE, c.idString));
sb.AppendLine(this.GetLine(TAG_CODE, c.IdString));
return sb.ToString();
}
//魔法陷阱
......@@ -475,20 +512,20 @@ string getSpellTrap(Card c, string img, bool isSpell,CardPack cardpack=null,bool
{
StringBuilder sb = new StringBuilder();
sb.AppendLine(TAG_CARD + ":");
sb.AppendLine(GetLine(TAG_CARDTYPE, isSpell ? "spell card" : "trap card"));
sb.AppendLine(GetLine(TAG_NAME, reItalic(c.name)));
sb.AppendLine(GetLine(TAG_ATTRIBUTE, isSpell ? "spell" : "trap"));
sb.AppendLine(GetLine(TAG_LEVEL, GetSpellTrapSymbol(c, isSpell)));
sb.AppendLine(GetLine(TAG_IMAGE, img));
sb.AppendLine(this.GetLine(TAG_CARDTYPE, isSpell ? "spell card" : "trap card"));
sb.AppendLine(this.GetLine(TAG_NAME, this.ReItalic(c.name)));
sb.AppendLine(this.GetLine(TAG_ATTRIBUTE, isSpell ? "spell" : "trap"));
sb.AppendLine(this.GetLine(TAG_LEVEL, this.GetSpellTrapSymbol(c, isSpell)));
sb.AppendLine(this.GetLine(TAG_IMAGE, img));
if(cardpack!=null){
sb.AppendLine(GetLine(TAG_NUMBER, cardpack.pack_id));
sb.AppendLine(this.GetLine(TAG_NUMBER, cardpack.pack_id));
if(rarity){
sb.AppendLine(GetLine(TAG_RARITY, cardpack.getMseRarity()));
sb.AppendLine(this.GetLine(TAG_RARITY, cardpack.getMseRarity()));
}
}
sb.AppendLine(" " + TAG_TEXT + ":");
sb.AppendLine(" " + ReText(reItalic(c.desc)));
sb.AppendLine(GetLine(TAG_CODE, c.idString));
sb.AppendLine(" " + this.ReText(this.ReItalic(c.desc)));
sb.AppendLine(this.GetLine(TAG_CODE, c.IdString));
return sb.ToString();
}
#endregion
......@@ -527,11 +564,13 @@ long GetRaceInt(string race)
{
if (!string.IsNullOrEmpty(race))
{
foreach (long key in cfg.raceDic.Keys)
foreach (long key in this.cfg.raceDic.Keys)
{
if (race.Equals(cfg.raceDic[key]))
return key;
}
if (race.Equals(this.cfg.raceDic[key]))
{
return key;
}
}
}
return (long)CardRace.RACE_NONE;
}
......@@ -539,11 +578,13 @@ long GetTypeInt(string type)
{
if (!string.IsNullOrEmpty(type))
{
foreach (long key in cfg.typeDic.Keys)
foreach (long key in this.cfg.typeDic.Keys)
{
if (type.Equals(cfg.typeDic[key]))
return key;
}
if (type.Equals(this.cfg.typeDic[key]))
{
return key;
}
}
}
return 0;
}
......@@ -554,8 +595,10 @@ static string GetValue(string content, string tag)
if (m.Success)
{
if (m.Groups.Count >= 2)
return RemoveTag(m.Groups[1].Value);
}
{
return RemoveTag(m.Groups[1].Value);
}
}
return "";
}
//多行
......@@ -580,28 +623,50 @@ long GetSpellTrapType(string level)
long type = 0;
//魔法陷阱
if (level.Contains(MseSpellTrap.EQUIP))
type = (long)CardType.TYPE_EQUIP;
if (level.Contains(MseSpellTrap.QUICKPLAY))
type = (long)CardType.TYPE_QUICKPLAY;
if (level.Contains(MseSpellTrap.FIELD))
type = (long)CardType.TYPE_FIELD;
if (level.Contains(MseSpellTrap.CONTINUOUS))
type = (long)CardType.TYPE_CONTINUOUS;
if (level.Contains(MseSpellTrap.RITUAL))
type = (long)CardType.TYPE_RITUAL;
if (level.Contains(MseSpellTrap.COUNTER))
type = (long)CardType.TYPE_COUNTER;
return type;
{
type = (long)CardType.TYPE_EQUIP;
}
if (level.Contains(MseSpellTrap.QUICKPLAY))
{
type = (long)CardType.TYPE_QUICKPLAY;
}
if (level.Contains(MseSpellTrap.FIELD))
{
type = (long)CardType.TYPE_FIELD;
}
if (level.Contains(MseSpellTrap.CONTINUOUS))
{
type = (long)CardType.TYPE_CONTINUOUS;
}
if (level.Contains(MseSpellTrap.RITUAL))
{
type = (long)CardType.TYPE_RITUAL;
}
if (level.Contains(MseSpellTrap.COUNTER))
{
type = (long)CardType.TYPE_COUNTER;
}
return type;
}
long GetMonsterType(string cardtype)
{
long type = 0;
if (cardtype.Equals(MseCardType.CARD_SPELL))
type = (long)CardType.TYPE_SPELL;
else if (cardtype.Equals(MseCardType.CARD_TRAP))
type = (long)CardType.TYPE_TRAP;
else
long type;
if (cardtype.Equals(MseCardType.CARD_SPELL))
{
type = (long)CardType.TYPE_SPELL;
}
else if (cardtype.Equals(MseCardType.CARD_TRAP))
{
type = (long)CardType.TYPE_TRAP;
}
else
{
type = (long)CardType.TYPE_MONSTER;
switch (cardtype)
......@@ -640,13 +705,16 @@ long GetCardType(string cardtype, string level, params string[] types)
{
long type = 0;
//魔法陷阱
type |= GetSpellTrapType(level);
type |= this.GetSpellTrapType(level);
//怪兽
type |= GetMonsterType(cardtype);
type |= this.GetMonsterType(cardtype);
//types是识别怪兽效果类型
foreach(string typ in types)
type |= GetTypeInt(typ);
return type;
{
type |= this.GetTypeInt(typ);
}
return type;
}
static string RemoveTag(string word)
......@@ -659,57 +727,70 @@ static string RemoveTag(string word)
public Card ReadCard(string content, out string img)
{
string tmp;
int itmp;
Card c = new Card();
c.ot = (int)CardRule.OCGTCG;
//卡名
c.name = GetValue(content, TAG_NAME);
tmp = GetValue(content, TAG_LEVEL);
Card c = new Card
{
ot = (int)CardRule.OCGTCG,
//卡名
name = GetValue(content, TAG_NAME)
};
tmp = GetValue(content, TAG_LEVEL);
//卡片种族
c.race = GetRaceInt(GetValue(content, TAG_TYPE1));
c.race = this.GetRaceInt(GetValue(content, TAG_TYPE1));
//卡片类型
c.type = GetCardType(GetValue(content, TAG_CARDTYPE), tmp,
c.type = this.GetCardType(GetValue(content, TAG_CARDTYPE), tmp,
GetValue(content, TAG_TYPE2),
GetValue(content, TAG_TYPE3),
GetValue(content, TAG_TYPE4),
GetValue(content, TAG_TYPE5));
long t = GetSpellTrapType(GetValue(content, TAG_LEVEL));
long t = this.GetSpellTrapType(GetValue(content, TAG_LEVEL));
//不是魔法,陷阱卡片的星数
if (!(c.IsType(CardType.TYPE_SPELL)
|| c.IsType(CardType.TYPE_TRAP)) && t == 0)
c.level = GetValue(content, TAG_LEVEL).Length;
{
c.level = GetValue(content, TAG_LEVEL).Length;
}
//属性
c.attribute = GetAttributeInt(GetValue(content, TAG_ATTRIBUTE));
//属性
c.attribute = GetAttributeInt(GetValue(content, TAG_ATTRIBUTE));
//密码
long.TryParse(GetValue(content, TAG_CODE), out c.id);
//ATK
tmp = GetValue(content, TAG_ATK);
if (tmp == UNKNOWN_ATKDEF)
c.atk = UNKNOWN_ATKDEF_VALUE;
else
int.TryParse(tmp, out c.atk);
//DEF
tmp = GetValue(content, TAG_DEF);
{
c.atk = UNKNOWN_ATKDEF_VALUE;
}
else
{
int.TryParse(tmp, out c.atk);
}
//DEF
tmp = GetValue(content, TAG_DEF);
if (tmp == UNKNOWN_ATKDEF)
c.def = UNKNOWN_ATKDEF_VALUE;
else
int.TryParse(tmp, out c.def);
//图片
img = GetValue(content, TAG_IMAGE);
{
c.def = UNKNOWN_ATKDEF_VALUE;
}
else
{
int.TryParse(tmp, out c.def);
}
//图片
img = GetValue(content, TAG_IMAGE);
//摇摆
if (c.IsType(CardType.TYPE_PENDULUM))
{//根据预设的模版,替换内容
tmp = cfg.temp_text.Replace(TAG_REP_TEXT,
tmp = this.cfg.temp_text.Replace(TAG_REP_TEXT,
GetMultiValue(content,TAG_TEXT));
tmp = tmp.Replace(TAG_REP_PTEXT,
GetMultiValue(content, TAG_PEND_TEXT));
c.desc = tmp;
}
else
c.desc = GetMultiValue(content,TAG_TEXT);
//摇摆刻度
int.TryParse(GetValue(content, TAG_PSCALE1), out itmp);
{
c.desc = GetMultiValue(content,TAG_TEXT);
}
//摇摆刻度
int.TryParse(GetValue(content, TAG_PSCALE1), out int itmp);
c.level += (itmp << 0x18);
int.TryParse(GetValue(content, TAG_PSCALE2), out itmp);
c.level += (itmp << 0x10);
......@@ -720,8 +801,11 @@ public Card[] ReadCards(string set, bool repalceOld)
{
List<Card> cards = new List<Card>();
if (!File.Exists(set))
return null;
string allcontent = File.ReadAllText(set, Encoding.UTF8);
{
return null;
}
string allcontent = File.ReadAllText(set, Encoding.UTF8);
Regex regx = new Regex(@"^card:[\S\s]+?gamecode:[\S\s]+?$",
RegexOptions.Multiline);
......@@ -732,21 +816,27 @@ public Card[] ReadCards(string set, bool repalceOld)
{
string content = match.Groups[0].Value;
i++;
string img;
Card c = ReadCard(content, out img);
if (c.id <= 0)
c.id = i;
//添加卡片
cards.Add(c);
Card c = this.ReadCard(content, out string img);
if (c.id <= 0)
{
c.id = i;
}
//添加卡片
cards.Add(c);
//已经解压出来的图片
string saveimg = MyPath.Combine(cfg.imagepath, img);
string saveimg = MyPath.Combine(this.cfg.imagepath, img);
if (!File.Exists(saveimg))//没有解压相应的图片
continue;
//改名后的图片
img = MyPath.Combine(cfg.imagepath, c.idString + ".jpg");
{
continue;
}
//改名后的图片
img = MyPath.Combine(this.cfg.imagepath, c.IdString + ".jpg");
if (img == saveimg)//文件名相同
continue;
if (File.Exists(img))
{
continue;
}
if (File.Exists(img))
{
if (repalceOld)//如果存在,则备份原图
{
......@@ -756,8 +846,10 @@ public Card[] ReadCards(string set, bool repalceOld)
}
}
else
File.Move(saveimg, img);
}
{
File.Move(saveimg, img);
}
}
File.Delete(set);
return cards.ToArray();
}
......@@ -770,33 +862,38 @@ public Card[] ReadCards(string set, bool repalceOld)
/// <param name="img"></param>
/// <param name="card"></param>
/// <returns></returns>
public string getImageCache(string img,Card card){
if(!cfg.reimage){
public string GetImageCache(string img,Card card){
if(!this.cfg.reimage){
//不需要调整
return img;
}
bool isPendulum = card.IsType(CardType.TYPE_PENDULUM);
if(isPendulum){
if(cfg.pwidth<=0 && cfg.pheight<=0)
return img;
}else{
if(cfg.width<=0 && cfg.height<=0)
return img;
}
if(this.cfg.pwidth<=0 && this.cfg.pheight<=0)
{
return img;
}
}
else{
if(this.cfg.width<=0 && this.cfg.height<=0)
{
return img;
}
}
string md5=MyUtils.GetMD5HashFromFile(img);
if(MyUtils.Md5isEmpty(md5)||cfg.imagecache==null){
if(MyUtils.Md5isEmpty(md5)|| this.cfg.imagecache==null){
//md5为空
return img;
}
string file = MyPath.Combine(cfg.imagecache, md5);
string file = MyPath.Combine(this.cfg.imagecache, md5);
if(!File.Exists(file)){
//生成缓存
Bitmap bmp=MyBitmap.readImage(img);
//缩放
if(isPendulum){
bmp=MyBitmap.Zoom(bmp, cfg.pwidth,cfg.pheight);
bmp=MyBitmap.Zoom(bmp, this.cfg.pwidth, this.cfg.pheight);
}else{
bmp=MyBitmap.Zoom(bmp, cfg.width,cfg.height);
bmp=MyBitmap.Zoom(bmp, this.cfg.width, this.cfg.height);
}
//保存文件
MyBitmap.SaveAsJPEG(bmp, file,100);
......@@ -806,8 +903,8 @@ public Card[] ReadCards(string set, bool repalceOld)
#endregion
#region export
static System.Diagnostics.Process mseProcess;
static EventHandler exitHandler;
static System.Diagnostics.Process _mseProcess;
static EventHandler _exitHandler;
private static void exportSetThread(object obj){
string[] args=(string[])obj;
if(args==null||args.Length<3){
......@@ -822,19 +919,19 @@ public Card[] ReadCards(string set, bool repalceOld)
return;
}else{
string cmd=" --export "+setfile.Replace("\\\\","\\").Replace("\\","/")+" {card.gamecode}.png";
mseProcess = new System.Diagnostics.Process();
mseProcess.StartInfo.FileName = mse_path;
mseProcess.StartInfo.Arguments = cmd;
mseProcess.StartInfo.WorkingDirectory=path;
mseProcess.EnableRaisingEvents=true;
_mseProcess = new System.Diagnostics.Process();
_mseProcess.StartInfo.FileName = mse_path;
_mseProcess.StartInfo.Arguments = cmd;
_mseProcess.StartInfo.WorkingDirectory=path;
_mseProcess.EnableRaisingEvents=true;
MyPath.CreateDir(path);
try{
mseProcess.Start();
_mseProcess.Start();
//等待结束,需要把当前方法放到线程里面
mseProcess.WaitForExit();
mseProcess.Exited += new EventHandler(exitHandler);
mseProcess.Close();
mseProcess=null;
_mseProcess.WaitForExit();
_mseProcess.Exited += new EventHandler(_exitHandler);
_mseProcess.Close();
_mseProcess=null;
System.Windows.Forms.MessageBox.Show(Language.LanguageHelper.GetMsg(LMSG.exportMseImages));
}catch{
......@@ -843,37 +940,39 @@ public Card[] ReadCards(string set, bool repalceOld)
}
public static bool MseIsRunning(){
return mseProcess != null;
return _mseProcess != null;
}
public static void MseStop(){
try{
mseProcess.Kill();
mseProcess.Close();
_mseProcess.Kill();
_mseProcess.Close();
}catch{}
}
public static void exportSet(string mse_path,string setfile,string path,EventHandler handler){
public static void ExportSet(string mse_path,string setfile,string path,EventHandler handler){
if(string.IsNullOrEmpty(mse_path)||setfile==null||setfile.Length==0){
return;
}
ParameterizedThreadStart ParStart = new ParameterizedThreadStart(exportSetThread);
Thread myThread = new Thread(ParStart);
myThread.IsBackground=true;
myThread.Start(new string[]{mse_path,setfile,path});
exitHandler = handler;
Thread myThread = new Thread(ParStart)
{
IsBackground = true
};
myThread.Start(new string[]{mse_path,setfile,path});
_exitHandler = handler;
}
#endregion
public void testPendulum(string desc)
public void TestPendulum(string desc)
{
List<string> table = GetMPText(desc);
List<string> table = this.GetMPText(desc);
if (table == null && table.Count != 2)
{
MessageBox.Show("desc is null", "info");
}
else
{
MessageBox.Show(reItalic(table[0]), "Monster Effect");
MessageBox.Show(reItalic(table[1]), "Pendulum Effect");
MessageBox.Show(this.ReItalic(table[0]), "Monster Effect");
MessageBox.Show(this.ReItalic(table[1]), "Pendulum Effect");
}
}
......@@ -886,8 +985,8 @@ public List<string> GetMPText(string desc)
}
else
{
string ptext = null;
string text = null;
string ptext;
string text;
if (Regex.IsMatch(desc, "【灵摆】"))
{
ptext = GetDesc(desc, @"\A←[ ]*\d*[ ]*【灵摆】[ ]*\d*[ ]*→[\r\n]*([\S\s]*?)[\r\n]*【");
......@@ -899,11 +998,16 @@ public List<string> GetMPText(string desc)
text = GetDesc(desc, @"\A([\S\s]*?)[\r\n]*【灵摆效果】[\r\n]*[\S\s]*?\z");
}
if (string.IsNullOrEmpty(text))
{
text = desc;
List<string> val = new List<string>();
val.Add(text);
val.Add(ptext);
return val;
}
List<string> val = new List<string>
{
text,
ptext
};
return val;
}
}
......@@ -911,17 +1015,25 @@ public string ConvertPTextOld(string text, string ptext, bool normal, int pscale
{
string str = normal ? "【怪兽描述】" : "【怪兽效果】";
if (string.IsNullOrEmpty(ptext))
{
return string.Format("←{0} 【灵摆】 {1}→\r\n{2}\r\n{3}", pscale_l, pscale_r, str, text);
}
else
{
return string.Format("←{0} 【灵摆】 {1}→\r\n{2}\r\n{3}\r\n{4}", pscale_l, pscale_r, ptext, str, text);
}
}
public string ConvertPTextNew(string text, string ptext)
{
if (string.IsNullOrEmpty(ptext))
{
return text;
}
else
{
return string.Format("{0}\r\n\r\n【灵摆效果】\r\n{1}", text, ptext);
}
}
public string ReplaceText(string text, string name)
......@@ -929,9 +1041,11 @@ public string ReplaceText(string text, string name)
// pendulum format
if (Regex.IsMatch(text, @"【灵摆】"))
{
List<string> table = GetMPText(text);
List<string> table = this.GetMPText(text);
if (table != null)
text = ConvertPTextNew(table[0], table[1]);
{
text = this.ConvertPTextNew(table[0], table[1]);
}
}
// give
......
......@@ -43,7 +43,7 @@ public class CardInfo{
public string copyright;
public override string ToString()
{
return string.Format("[CardInfo Title={0}, Artwork={1}, Artwork_crop={2}, Background={3}, Rarity={4}, Attribute={5}, Level={6}, Icon={7}, Description={8}, Pendulum_description={9}, Pendulum_scales={10}, Subtypes={11}, Atk={12}, Def={13}, Edition={14}, Set={15}, Card_number={16}, Limitation={17}, Sticker={18}, Copyright={19}]", title, artwork, artwork_crop, background, rarity, attribute, level, icon, description, pendulum_description, pendulum_scales, subtypes, atk, def, edition, set, card_number, limitation, sticker, copyright);
return string.Format("[CardInfo Title={0}, Artwork={1}, Artwork_crop={2}, Background={3}, Rarity={4}, Attribute={5}, Level={6}, Icon={7}, Description={8}, Pendulum_description={9}, Pendulum_scales={10}, Subtypes={11}, Atk={12}, Def={13}, Edition={14}, Set={15}, Card_number={16}, Limitation={17}, Sticker={18}, Copyright={19}]", this.title, this.artwork, this.artwork_crop, this.background, this.rarity, this.attribute, this.level, this.icon, this.description, this.pendulum_description, this.pendulum_scales, this.subtypes, this.atk, this.def, this.edition, this.set, this.card_number, this.limitation, this.sticker, this.copyright);
}
}
......
......@@ -47,7 +47,7 @@ public class TaskHelper
/// </summary>
public Card[] CardList
{
get { return cardlist; }
get { return this.cardlist; }
}
/// <summary>
/// 任务参数
......@@ -56,11 +56,11 @@ public Card[] CardList
/// <summary>
/// 图片设置
/// </summary>
private ImageSet imgSet;
private readonly ImageSet imgSet;
/// <summary>
/// MSE转换
/// </summary>
private MseMaker mseHelper;
private readonly MseMaker mseHelper;
/// <summary>
/// 是否取消
/// </summary>
......@@ -72,38 +72,38 @@ public Card[] CardList
/// <summary>
/// 后台工作线程
/// </summary>
private BackgroundWorker worker;
private readonly BackgroundWorker worker;
public TaskHelper(string datapath, BackgroundWorker worker, MSEConfig mcfg)
{
this.worker = worker;
mseHelper = new MseMaker(mcfg);
imgSet = new ImageSet();
this.mseHelper = new MseMaker(mcfg);
this.imgSet = new ImageSet();
}
public MseMaker MseHelper
{
get { return mseHelper; }
get { return this.mseHelper; }
}
public bool IsRuning()
{
return isRun;
return this.isRun;
}
public bool IsCancel()
{
return isCancel;
return this.isCancel;
}
public void Cancel()
{
isRun = false;
isCancel = true;
this.isRun = false;
this.isCancel = true;
}
public MyTask getLastTask()
{
return lastTask;
return this.lastTask;
}
public void testPendulumText(string desc){
mseHelper.testPendulum(desc);
this.mseHelper.TestPendulum(desc);
}
#endregion
......@@ -111,19 +111,22 @@ public MyTask getLastTask()
//设置任务
public void SetTask(MyTask myTask, Card[] cards, params string[] args)
{
nowTask = myTask;
cardlist = cards;
mArgs = args;
this.nowTask = myTask;
this.cardlist = cards;
this.mArgs = args;
}
//转换图片
//public void ToImg(string img, string saveimg1, string saveimg2)
public void ToImg(string img, string saveimg1)
{
if (!File.Exists(img))
return;
Bitmap bmp = new Bitmap(img);
MyBitmap.SaveAsJPEG(MyBitmap.Zoom(bmp, imgSet.W, imgSet.H),
saveimg1, imgSet.quilty);
{
return;
}
Bitmap bmp = new Bitmap(img);
MyBitmap.SaveAsJPEG(MyBitmap.Zoom(bmp, this.imgSet.W, this.imgSet.H),
saveimg1, this.imgSet.quilty);
//MyBitmap.SaveAsJPEG(MyBitmap.Zoom(bmp, imgSet.w, imgSet.h),
// saveimg2, imgSet.quilty);
bmp.Dispose();
......@@ -137,30 +140,44 @@ public static void CheckVersion(bool showNew)
if (newver == CheckUpdate.DEFALUT)
{ //检查失败
if (!showNew)
return;
MyMsg.Error(LMSG.CheckUpdateFail);
{
return;
}
MyMsg.Error(LMSG.CheckUpdateFail);
return;
}
if (CheckUpdate.CheckVersion(newver, Application.ProductVersion))
{//有最新版本
if (!MyMsg.Question(LMSG.HaveNewVersion))
return;
}
{
return;
}
}
else
{//现在就是最新版本
if (!showNew)
return;
if (!MyMsg.Question(LMSG.NowIsNewVersion))
return;
}
{
return;
}
if (!MyMsg.Question(LMSG.NowIsNewVersion))
{
return;
}
}
//下载文件
if (CheckUpdate.DownLoad(
MyPath.Combine(Application.StartupPath, newver + ".zip")))
MyMsg.Show(LMSG.DownloadSucceed);
else
MyMsg.Show(LMSG.DownloadFail);
}
{
MyMsg.Show(LMSG.DownloadSucceed);
}
else
{
MyMsg.Show(LMSG.DownloadFail);
}
}
public void OnCheckUpdate(bool showNew)
{
TaskHelper.CheckVersion(showNew);
......@@ -170,34 +187,37 @@ public void OnCheckUpdate(bool showNew)
#region 裁剪图片
public void CutImages(string imgpath, bool isreplace)
{
int count = cardlist.Length;
int count = this.cardlist.Length;
int i = 0;
foreach (Card c in cardlist)
foreach (Card c in this.cardlist)
{
if (isCancel)
break;
i++;
worker.ReportProgress((i / count), string.Format("{0}/{1}", i, count));
if (this.isCancel)
{
break;
}
i++;
this.worker.ReportProgress((i / count), string.Format("{0}/{1}", i, count));
string jpg = MyPath.Combine(imgpath, c.id + ".jpg");
string savejpg = MyPath.Combine(mseHelper.ImagePath, c.id + ".jpg");
string savejpg = MyPath.Combine(this.mseHelper.ImagePath, c.id + ".jpg");
if (File.Exists(jpg) && (isreplace || !File.Exists(savejpg)))
{
Bitmap bp = new Bitmap(jpg);
Bitmap bmp = null;
if (c.IsType(CardType.TYPE_XYZ))//超量
Bitmap bmp;
if (c.IsType(CardType.TYPE_XYZ))//超量
{
bmp = MyBitmap.Cut(bp, imgSet.xyzArea);
bmp = MyBitmap.Cut(bp, this.imgSet.xyzArea);
}
else if (c.IsType(CardType.TYPE_PENDULUM))//P怪兽
{
bmp = MyBitmap.Cut(bp, imgSet.pendulumArea);
bmp = MyBitmap.Cut(bp, this.imgSet.pendulumArea);
}
else//一般
{
bmp = MyBitmap.Cut(bp, imgSet.normalArea);
bmp = MyBitmap.Cut(bp, this.imgSet.normalArea);
}
bp.Dispose();
MyBitmap.SaveAsJPEG(bmp, savejpg, imgSet.quilty);
MyBitmap.SaveAsJPEG(bmp, savejpg, this.imgSet.quilty);
//bmp.Save(savejpg, ImageFormat.Png);
}
}
......@@ -216,10 +236,13 @@ public void ConvertImages(string imgpath, string gamepath, bool isreplace)
foreach (string f in files)
{
if (isCancel)
break;
i++;
worker.ReportProgress(i / count, string.Format("{0}/{1}", i, count));
if (this.isCancel)
{
break;
}
i++;
this.worker.ReportProgress(i / count, string.Format("{0}/{1}", i, count));
string ex = Path.GetExtension(f).ToLower();
string name = Path.GetFileNameWithoutExtension(f);
string jpg_b = MyPath.Combine(picspath, name + ".jpg");
......@@ -233,8 +256,8 @@ public void ConvertImages(string imgpath, string gamepath, bool isreplace)
if (isreplace || !File.Exists(jpg_b))
{
MyBitmap.SaveAsJPEG(MyBitmap.Zoom(bmp, imgSet.W, imgSet.H),
jpg_b, imgSet.quilty);
MyBitmap.SaveAsJPEG(MyBitmap.Zoom(bmp, this.imgSet.W, this.imgSet.H),
jpg_b, this.imgSet.quilty);
}
//小图,如果替换,或者不存在
//if (isreplace || !File.Exists(jpg_s))
......@@ -252,50 +275,63 @@ public void ConvertImages(string imgpath, string gamepath, bool isreplace)
#region MSE存档
public string MSEImagePath
{
get { return mseHelper.ImagePath; }
get { return this.mseHelper.ImagePath; }
}
public void SaveMSEs(string file, Card[] cards,bool isUpdate)
{
if(cards == null)
return;
string pack_db=MyPath.GetRealPath(MyConfig.readString("pack_db"));
{
return;
}
string pack_db=MyPath.GetRealPath(MyConfig.readString("pack_db"));
bool rarity=MyConfig.readBoolean("mse_auto_rarity", false);
#if DEBUG
MessageBox.Show("db = "+pack_db+",auto rarity="+rarity);
#endif
int c = cards.Length;
//不分开,或者卡片数小于单个存档的最大值
if (mseHelper.MaxNum == 0 || c < mseHelper.MaxNum)
SaveMSE(1, file, cards,pack_db, rarity, isUpdate);
else
if (this.mseHelper.MaxNum == 0 || c < this.mseHelper.MaxNum)
{
this.SaveMSE(1, file, cards,pack_db, rarity, isUpdate);
}
else
{
int nums = c / mseHelper.MaxNum;
if (nums * mseHelper.MaxNum < c)//计算需要分多少个存档
nums++;
List<Card> clist = new List<Card>();
int nums = c / this.mseHelper.MaxNum;
if (nums * this.mseHelper.MaxNum < c)//计算需要分多少个存档
{
nums++;
}
List<Card> clist = new List<Card>();
for (int i = 0; i < nums; i++)//分别生成存档
{
clist.Clear();
for (int j = 0; j < mseHelper.MaxNum; j++)
for (int j = 0; j < this.mseHelper.MaxNum; j++)
{
int index = i * mseHelper.MaxNum + j;
int index = i * this.mseHelper.MaxNum + j;
if (index < c)
clist.Add(cards[index]);
}
{
clist.Add(cards[index]);
}
}
int t = file.LastIndexOf(".mse-set");
string fname = (t > 0) ? file.Substring(0, t) : file;
fname = fname + string.Format("_{0}.mse-set", i + 1);
SaveMSE(i + 1, fname, clist.ToArray(),pack_db, rarity, isUpdate);
fname += string.Format("_{0}.mse-set", i + 1);
this.SaveMSE(i + 1, fname, clist.ToArray(),pack_db, rarity, isUpdate);
}
}
}
public void SaveMSE(int num, string file, Card[] cards,string pack_db,bool rarity, bool isUpdate)
{
string setFile = file + ".txt";
Dictionary<Card, string> images = mseHelper.WriteSet(setFile, cards,pack_db,rarity);
Dictionary<Card, string> images = this.mseHelper.WriteSet(setFile, cards,pack_db,rarity);
if (isUpdate)//仅更新文字
return;
int i = 0;
{
return;
}
int i = 0;
int count = images.Count;
using (ZipStorer zips = ZipStorer.Create(file, ""))
{
......@@ -304,12 +340,15 @@ public void SaveMSE(int num, string file, Card[] cards,string pack_db,bool rarit
foreach (Card c in images.Keys)
{
string img=images[c];
if (isCancel)
break;
i++;
worker.ReportProgress(i / count, string.Format("{0}/{1}-{2}", i, count, num));
if (this.isCancel)
{
break;
}
i++;
this.worker.ReportProgress(i / count, string.Format("{0}/{1}-{2}", i, count, num));
//TODO 先裁剪图片
zips.AddFile(mseHelper.getImageCache(img,c), Path.GetFileName(img), "");
zips.AddFile(this.mseHelper.GetImageCache(img,c), Path.GetFileName(img), "");
}
}
File.Delete(setFile);
......@@ -325,13 +364,13 @@ public Card[] ReadMSE(string mseset, bool repalceOld)
int i = 0;
foreach (ZipStorer.ZipFileEntry file in files)
{
worker.ReportProgress(i / count, string.Format("{0}/{1}", i, count));
string savefilename = MyPath.Combine(mseHelper.ImagePath, file.FilenameInZip);
this.worker.ReportProgress(i / count, string.Format("{0}/{1}", i, count));
string savefilename = MyPath.Combine(this.mseHelper.ImagePath, file.FilenameInZip);
zips.ExtractFile(file, savefilename);
}
}
string setfile = MyPath.Combine(mseHelper.ImagePath, "set");
return mseHelper.ReadCards(setfile, repalceOld);
string setfile = MyPath.Combine(this.mseHelper.ImagePath, "set");
return this.mseHelper.ReadCards(setfile, repalceOld);
}
#endregion
......@@ -339,10 +378,13 @@ public Card[] ReadMSE(string mseset, bool repalceOld)
public void ExportData(string path, string zipname, string _cdbfile, string modulescript)
{
int i = 0;
Card[] cards = cardlist;
Card[] cards = this.cardlist;
if (cards == null || cards.Length == 0)
return;
int count = cards.Length;
{
return;
}
int count = cards.Length;
YgoPath ygopath = new YgoPath(path);
string name = Path.GetFileNameWithoutExtension(zipname);
//数据库
......@@ -354,30 +396,44 @@ public void ExportData(string path, string zipname, string _cdbfile, string modu
//module scripts
string extra_script = "";
if (modulescript.Length > 0)
extra_script = ygopath.GetModuleScript(modulescript);
File.Delete(cdbfile);
{
extra_script = ygopath.GetModuleScript(modulescript);
}
File.Delete(cdbfile);
DataBase.Create(cdbfile);
DataBase.CopyDB(cdbfile, false, cardlist);
DataBase.CopyDB(cdbfile, false, this.cardlist);
if (File.Exists(zipname))
File.Delete(zipname);
using (ZipStorer zips = ZipStorer.Create(zipname, ""))
{
File.Delete(zipname);
}
using (ZipStorer zips = ZipStorer.Create(zipname, ""))
{
zips.AddFile(cdbfile, Path.GetFileNameWithoutExtension(_cdbfile) + ".cdb", "");
if (File.Exists(readme))
zips.AddFile(readme, "readme_" + name + ".txt", "");
if (File.Exists(deckydk))
zips.AddFile(deckydk, "deck/" + name + ".ydk", "");
if (modulescript.Length > 0 && File.Exists(extra_script))
zips.AddFile(extra_script, extra_script.Replace(path, ""), "");
foreach (Card c in cards)
{
zips.AddFile(readme, "readme_" + name + ".txt", "");
}
if (File.Exists(deckydk))
{
zips.AddFile(deckydk, "deck/" + name + ".ydk", "");
}
if (modulescript.Length > 0 && File.Exists(extra_script))
{
zips.AddFile(extra_script, extra_script.Replace(path, ""), "");
}
foreach (Card c in cards)
{
i++;
worker.ReportProgress(i / count, string.Format("{0}/{1}", i, count));
this.worker.ReportProgress(i / count, string.Format("{0}/{1}", i, count));
string[] files = ygopath.GetCardfiles(c.id);
foreach (string file in files)
{
if (!String.Equals(file, extra_script) && File.Exists(file))
if (!string.Equals(file, extra_script) && File.Exists(file))
{
zips.AddFile(file, file.Replace(path,""), "");
}
......@@ -391,81 +447,92 @@ public void ExportData(string path, string zipname, string _cdbfile, string modu
#region 运行
public void Run()
{
isCancel = false;
isRun = true;
this.isCancel = false;
this.isRun = true;
bool replace;
bool showNew;
switch (nowTask)
switch (this.nowTask)
{
case MyTask.ExportData:
if (mArgs != null && mArgs.Length >= 3)
if (this.mArgs != null && this.mArgs.Length >= 3)
{
ExportData(mArgs[0], mArgs[1], mArgs[2], mArgs[3]);
this.ExportData(this.mArgs[0], this.mArgs[1], this.mArgs[2], this.mArgs[3]);
}
break;
case MyTask.CheckUpdate:
showNew = false;
if (mArgs != null && mArgs.Length >= 1)
if (this.mArgs != null && this.mArgs.Length >= 1)
{
showNew = (mArgs[0] == Boolean.TrueString) ? true : false;
showNew = (this.mArgs[0] == bool.TrueString) ? true : false;
}
OnCheckUpdate(showNew);
this.OnCheckUpdate(showNew);
break;
case MyTask.CutImages:
if (mArgs != null && mArgs.Length >= 2)
if (this.mArgs != null && this.mArgs.Length >= 2)
{
replace = true;
if (mArgs.Length >= 2)
if (this.mArgs.Length >= 2)
{
if (mArgs[1] == Boolean.FalseString)
replace = false;
}
CutImages(mArgs[0], replace);
if (this.mArgs[1] == bool.FalseString)
{
replace = false;
}
}
this.CutImages(this.mArgs[0], replace);
}
break;
case MyTask.SaveAsMSE:
if (mArgs != null && mArgs.Length >= 2)
if (this.mArgs != null && this.mArgs.Length >= 2)
{
replace = false;
if (mArgs.Length >= 2)
if (this.mArgs.Length >= 2)
{
if (mArgs[1] == Boolean.TrueString)
replace = true;
}
SaveMSEs(mArgs[0], cardlist, replace);
if (this.mArgs[1] == bool.TrueString)
{
replace = true;
}
}
this.SaveMSEs(this.mArgs[0], this.cardlist, replace);
}
break;
case MyTask.ReadMSE:
if (mArgs != null && mArgs.Length >= 2)
if (this.mArgs != null && this.mArgs.Length >= 2)
{
replace = false;
if (mArgs.Length >= 2)
if (this.mArgs.Length >= 2)
{
if (mArgs[1] == Boolean.TrueString)
replace = true;
}
cardlist = ReadMSE(mArgs[0], replace);
if (this.mArgs[1] == bool.TrueString)
{
replace = true;
}
}
this.cardlist = this.ReadMSE(this.mArgs[0], replace);
}
break;
case MyTask.ConvertImages:
if (mArgs != null && mArgs.Length >= 2)
if (this.mArgs != null && this.mArgs.Length >= 2)
{
replace = true;
if (mArgs.Length >= 3)
if (this.mArgs.Length >= 3)
{
if (mArgs[2] == Boolean.FalseString)
replace = false;
}
ConvertImages(mArgs[0], mArgs[1], replace);
if (this.mArgs[2] == bool.FalseString)
{
replace = false;
}
}
this.ConvertImages(this.mArgs[0], this.mArgs[1], replace);
}
break;
}
isRun = false;
lastTask = nowTask;
nowTask = MyTask.NONE;
if(lastTask != MyTask.ReadMSE)
cardlist = null;
mArgs = null;
this.isRun = false;
this.lastTask = this.nowTask;
this.nowTask = MyTask.NONE;
if(this.lastTask != MyTask.ReadMSE)
{
this.cardlist = null;
}
this.mArgs = null;
}
#endregion
}
......
......@@ -13,27 +13,33 @@ namespace DataEditorX.Core
{
static class YGOUtil
{
static DataConfig datacfg;
static DataConfig _datacfg;
static YGOUtil()
{
datacfg = new DataConfig();
_datacfg = new DataConfig();
}
public static void SetConfig(DataConfig dcfg)
{
datacfg = dcfg;
_datacfg = dcfg;
}
#region 判断文件类型
public static bool isScript(string file)
public static bool IsScript(string file)
{
if (file != null && file.EndsWith(".lua", StringComparison.OrdinalIgnoreCase))
{
return true;
}
return false;
}
public static bool isDataBase(string file)
public static bool IsDataBase(string file)
{
if (file != null && file.EndsWith(".cdb", StringComparison.OrdinalIgnoreCase))
{
return true;
}
return false;
}
#endregion
......@@ -41,13 +47,13 @@ public static bool isDataBase(string file)
#region 获取属性,种族
public static string GetAttributeString(int attr)
{
return DataManager.GetValue(datacfg.dicCardAttributes, attr);
return DataManager.GetValue(_datacfg.dicCardAttributes, attr);
}
public static string GetRace(long race)
{
return DataManager.GetValue(datacfg.dicCardRaces, race);
return DataManager.GetValue(_datacfg.dicCardRaces, race);
}
#endregion
......@@ -82,33 +88,56 @@ public static string GetCardType(Card c)
str = GetType(CardType.TYPE_EFFECT);
}
else
{
str = GetType(CardType.TYPE_NORMAL);
}
str += GetType(CardType.TYPE_MONSTER);
}
else if (c.IsType(CardType.TYPE_SPELL))
{
if (c.IsType(CardType.TYPE_EQUIP))
{
str = GetType(CardType.TYPE_EQUIP);
}
else if (c.IsType(CardType.TYPE_QUICKPLAY))
{
str = GetType(CardType.TYPE_QUICKPLAY);
}
else if (c.IsType(CardType.TYPE_FIELD))
{
str = GetType(CardType.TYPE_FIELD);
}
else if (c.IsType(CardType.TYPE_CONTINUOUS))
{
str = GetType(CardType.TYPE_CONTINUOUS);
}
else if (c.IsType(CardType.TYPE_RITUAL))
{
str = GetType(CardType.TYPE_RITUAL);
}
else
{
str = GetType(CardType.TYPE_NORMAL);
}
str += GetType(CardType.TYPE_SPELL);
}
else if (c.IsType(CardType.TYPE_TRAP))
{
if (c.IsType(CardType.TYPE_CONTINUOUS))
{
str = GetType(CardType.TYPE_CONTINUOUS);
}
else if (c.IsType(CardType.TYPE_COUNTER))
{
str = GetType(CardType.TYPE_COUNTER);
}
else
{
str = GetType(CardType.TYPE_NORMAL);
}
str += GetType(CardType.TYPE_TRAP);
}
return str.Replace(" ", "");
......@@ -116,21 +145,28 @@ public static string GetCardType(Card c)
static string GetType(CardType type)
{
return DataManager.GetValue(datacfg.dicCardTypes, (long)type);
return DataManager.GetValue(_datacfg.dicCardTypes, (long)type);
}
public static string GetTypeString(long type)
{
string str = "";
foreach (long k in datacfg.dicCardTypes.Keys)
foreach (long k in _datacfg.dicCardTypes.Keys)
{
if ((type & k) == k)
{
str += GetType((CardType)k) + "|";
}
}
if (str.Length > 0)
{
str = str.Substring(0, str.Length - 1);
}
else
{
str = "???";
}
return str;
}
#endregion
......@@ -142,10 +178,10 @@ public static string GetSetNameString(long setcode)
long sc2 = (setcode >> 0x10) & 0xffff;
long sc3 = (setcode >> 0x20) & 0xffff;
long sc4 = (setcode >> 0x30) & 0xffff;
string setname = DataManager.GetValue(datacfg.dicSetnames, sc1)
+ " " + DataManager.GetValue(datacfg.dicSetnames, sc2)
+ " " + DataManager.GetValue(datacfg.dicSetnames, sc3)
+ " " + DataManager.GetValue(datacfg.dicSetnames, sc4);
string setname = DataManager.GetValue(_datacfg.dicSetnames, sc1)
+ " " + DataManager.GetValue(_datacfg.dicSetnames, sc2)
+ " " + DataManager.GetValue(_datacfg.dicSetnames, sc3)
+ " " + DataManager.GetValue(_datacfg.dicSetnames, sc4);
return setname;
}
......@@ -172,7 +208,9 @@ public static string[] ReadYDK(string ydkfile)
if (!str.StartsWith("!") && !str.StartsWith("#") && str.Length > 0)
{
if (IDs.IndexOf(str) < 0)
{
IDs.Add(str);
}
}
str = sr.ReadLine();
}
......@@ -181,7 +219,10 @@ public static string[] ReadYDK(string ydkfile)
}
}
if (IDs.Count == 0)
{
return null;
}
return IDs.ToArray();
}
#endregion
......@@ -196,7 +237,9 @@ public static string[] ReadImage(string path)
{
string ex = Path.GetExtension(files[i]).ToLower();
if (ex == ".jpg" || ex == ".png" || ex == ".bmp")
{
list.Add(Path.GetFileNameWithoutExtension(files[i]));
}
}
return list.ToArray();
}
......@@ -210,8 +253,10 @@ public static void CardDelete(long id, YgoPath ygopath)
for (int i = 0; i < files.Length; i++)
{
if (FileSystem.FileExists(files[i]))
FileSystem.DeleteFile(files[i], UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
}
{
FileSystem.DeleteFile(files[i], UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
}
}
}
#endregion
......
......@@ -520,7 +520,7 @@ private void InitializeComponent()
this.tb_cardname.Location = new System.Drawing.Point(5, 3);
this.tb_cardname.Name = "tb_cardname";
this.tb_cardname.Size = new System.Drawing.Size(339, 21);
this.tb_cardname.TabIndex = 4;
this.tb_cardname.TabIndex = 1;
this.tb_cardname.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
this.tb_cardname.KeyDown += new System.Windows.Forms.KeyEventHandler(this.Tb_cardnameKeyDown);
//
......@@ -643,7 +643,8 @@ private void InitializeComponent()
this.tb_cardtext.Name = "tb_cardtext";
this.tb_cardtext.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.tb_cardtext.Size = new System.Drawing.Size(340, 200);
this.tb_cardtext.TabIndex = 4;
this.tb_cardtext.TabIndex = 121;
this.tb_cardtext.KeyDown += new System.Windows.Forms.KeyEventHandler(this.tb_cardtext_KeyDown);
//
// tb_edittext
//
......@@ -675,7 +676,7 @@ private void InitializeComponent()
this.tb_pleft.MaxLength = 12;
this.tb_pleft.Name = "tb_pleft";
this.tb_pleft.Size = new System.Drawing.Size(40, 21);
this.tb_pleft.TabIndex = 8;
this.tb_pleft.TabIndex = 115;
this.tb_pleft.Text = "0";
this.tb_pleft.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
......@@ -685,7 +686,7 @@ private void InitializeComponent()
this.tb_pright.MaxLength = 12;
this.tb_pright.Name = "tb_pright";
this.tb_pright.Size = new System.Drawing.Size(40, 21);
this.tb_pright.TabIndex = 8;
this.tb_pright.TabIndex = 116;
this.tb_pright.Text = "0";
this.tb_pright.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
......@@ -780,7 +781,7 @@ private void InitializeComponent()
this.tb_atk.MaxLength = 12;
this.tb_atk.Name = "tb_atk";
this.tb_atk.Size = new System.Drawing.Size(40, 21);
this.tb_atk.TabIndex = 8;
this.tb_atk.TabIndex = 117;
this.tb_atk.Text = "0";
this.tb_atk.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
......@@ -790,7 +791,7 @@ private void InitializeComponent()
this.tb_def.MaxLength = 12;
this.tb_def.Name = "tb_def";
this.tb_def.Size = new System.Drawing.Size(40, 21);
this.tb_def.TabIndex = 8;
this.tb_def.TabIndex = 118;
this.tb_def.Text = "0";
this.tb_def.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
//
......@@ -801,7 +802,7 @@ private void InitializeComponent()
this.tb_cardcode.MaxLength = 12;
this.tb_cardcode.Name = "tb_cardcode";
this.tb_cardcode.Size = new System.Drawing.Size(67, 21);
this.tb_cardcode.TabIndex = 8;
this.tb_cardcode.TabIndex = 120;
this.tb_cardcode.Text = "0";
this.tb_cardcode.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.tb_cardcode.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.Tb_cardcodeKeyPress);
......@@ -823,7 +824,7 @@ private void InitializeComponent()
this.tb_cardalias.MaxLength = 12;
this.tb_cardalias.Name = "tb_cardalias";
this.tb_cardalias.Size = new System.Drawing.Size(67, 21);
this.tb_cardalias.TabIndex = 8;
this.tb_cardalias.TabIndex = 119;
this.tb_cardalias.Text = "0";
this.tb_cardalias.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
//
......@@ -984,7 +985,7 @@ private void InitializeComponent()
this.tb_setcode1.MaxLength = 4;
this.tb_setcode1.Name = "tb_setcode1";
this.tb_setcode1.Size = new System.Drawing.Size(30, 21);
this.tb_setcode1.TabIndex = 18;
this.tb_setcode1.TabIndex = 111;
this.tb_setcode1.Text = "0";
this.tb_setcode1.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.tb_setcode1.TextChanged += new System.EventHandler(this.tb_setcode1_TextChanged);
......@@ -996,7 +997,7 @@ private void InitializeComponent()
this.tb_setcode2.MaxLength = 4;
this.tb_setcode2.Name = "tb_setcode2";
this.tb_setcode2.Size = new System.Drawing.Size(30, 21);
this.tb_setcode2.TabIndex = 18;
this.tb_setcode2.TabIndex = 112;
this.tb_setcode2.Text = "0";
this.tb_setcode2.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.tb_setcode2.TextChanged += new System.EventHandler(this.tb_setcode2_TextChanged);
......@@ -1008,7 +1009,7 @@ private void InitializeComponent()
this.tb_setcode3.MaxLength = 4;
this.tb_setcode3.Name = "tb_setcode3";
this.tb_setcode3.Size = new System.Drawing.Size(30, 21);
this.tb_setcode3.TabIndex = 18;
this.tb_setcode3.TabIndex = 113;
this.tb_setcode3.Text = "0";
this.tb_setcode3.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.tb_setcode3.TextChanged += new System.EventHandler(this.tb_setcode3_TextChanged);
......@@ -1020,7 +1021,7 @@ private void InitializeComponent()
this.tb_setcode4.MaxLength = 4;
this.tb_setcode4.Name = "tb_setcode4";
this.tb_setcode4.Size = new System.Drawing.Size(30, 21);
this.tb_setcode4.TabIndex = 18;
this.tb_setcode4.TabIndex = 114;
this.tb_setcode4.Text = "0";
this.tb_setcode4.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
this.tb_setcode4.TextChanged += new System.EventHandler(this.tb_setcode4_TextChanged);
......@@ -1248,7 +1249,7 @@ private void InitializeComponent()
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "DataEditorX";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.DataEditFormFormClosing);
this.Load += new System.EventHandler(this.DataEditFormLoad);
this.Load += new System.EventHandler(this.DataEditForm_Load);
this.SizeChanged += new System.EventHandler(this.DataEditFormSizeChanged);
this.Enter += new System.EventHandler(this.DataEditFormEnter);
this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.DataEditForm_KeyDown);
......
......@@ -25,23 +25,27 @@ public partial class DataEditForm : DockContent, IDataForm
{
private string addrequire_str;
public string addrequire
public string Addrequire
{
get
{
if (!string.IsNullOrEmpty(addrequire_str))
return addrequire_str;
else
if (!string.IsNullOrEmpty(this.addrequire_str))
{
return this.addrequire_str;
}
else
{
string cdbName = Path.GetFileNameWithoutExtension(nowCdbFile);
if (cdbName.Length > 0 && File.Exists(GetPath().GetModuleScript(cdbName)))
return cdbName;
}
string cdbName = Path.GetFileNameWithoutExtension(this.nowCdbFile);
if (cdbName.Length > 0 && File.Exists(this.GetPath().GetModuleScript(cdbName)))
{
return cdbName;
}
}
return "";
}
set
{
addrequire_str = value;
this.addrequire_str = value;
}
}
......@@ -64,35 +68,36 @@ public string addrequire
//初始标题
string title;
string nowCdbFile = "";
int MaxRow = 20;
int maxRow = 20;
int page = 1, pageNum = 1;
/// <summary>
/// 卡片总数
/// </summary>
int cardcount;
/// <summary>
/// 搜索结果
/// </summary>
List<Card> cardlist = new List<Card>();
//setcode正在输入
bool[] setcodeIsedit = new bool[5];
readonly List<Card> cardlist = new List<Card>();
CommandManager cmdManager = new CommandManager();
//setcode正在输入
readonly bool[] setcodeIsedit = new bool[5];
readonly CommandManager cmdManager = new CommandManager();
Image m_cover;
Image cover;
MSEConfig msecfg;
string datapath, confcover;
public DataEditForm(string datapath, string cdbfile)
{
Initialize(datapath);
nowCdbFile = cdbfile;
this.Initialize(datapath);
this.nowCdbFile = cdbfile;
}
public DataEditForm(string datapath)
{
Initialize(datapath);
this.Initialize(datapath);
}
public DataEditForm()
{//默认启动
......@@ -101,25 +106,29 @@ public DataEditForm()
{
Application.Exit();
}
datapath = MyPath.Combine(Application.StartupPath, dir);
this.datapath = MyPath.Combine(Application.StartupPath, dir);
Initialize(datapath);
this.Initialize(this.datapath);
}
void Initialize(string datapath)
{
cardedit = new CardEdit(this);
tmpCodes = new List<string>();
ygopath = new YgoPath(Application.StartupPath);
InitPath(datapath);
InitializeComponent();
title = this.Text;
nowCdbFile = "";
cmdManager.UndoStateChanged += delegate (bool val)
this.cardedit = new CardEdit(this);
this.tmpCodes = new List<string>();
this.ygopath = new YgoPath(Application.StartupPath);
this.InitPath(datapath);
this.InitializeComponent();
this.title = this.Text;
this.nowCdbFile = "";
this.cmdManager.UndoStateChanged += delegate (bool val)
{
if (val)
btn_undo.Enabled = true;
{
this.btn_undo.Enabled = true;
}
else
btn_undo.Enabled = false;
{
this.btn_undo.Enabled = false;
}
};
}
......@@ -132,15 +141,15 @@ public void SetActived()
}
public string GetOpenFile()
{
return nowCdbFile;
return this.nowCdbFile;
}
public bool CanOpen(string file)
{
return YGOUtil.isDataBase(file);
return YGOUtil.IsDataBase(file);
}
public bool Create(string file)
{
return Open(file);
return this.Open(file);
}
public bool Save()
{
......@@ -153,38 +162,40 @@ public bool Save()
void DataEditFormLoad(object sender, EventArgs e)
{
//InitListRows();//调整卡片列表的函数
HideMenu();//是否需要隐藏菜单
SetTitle();//设置标题
//加载
msecfg = new MSEConfig(datapath);
tasker = new TaskHelper(datapath, bgWorker1, msecfg);
this.HideMenu();//是否需要隐藏菜单
this.SetTitle();//设置标题
//加载
this.msecfg = new MSEConfig(this.datapath);
this.tasker = new TaskHelper(this.datapath, this.bgWorker1, this.msecfg);
//设置空白卡片
oldCard = new Card(0);
SetCard(oldCard);
this.oldCard = new Card(0);
this.SetCard(this.oldCard);
//删除资源
menuitem_operacardsfile.Checked = MyConfig.readBoolean(MyConfig.TAG_DELETE_WITH);
this.menuitem_operacardsfile.Checked = MyConfig.readBoolean(MyConfig.TAG_DELETE_WITH);
//用CodeEditor打开脚本
menuitem_openfileinthis.Checked = MyConfig.readBoolean(MyConfig.TAG_OPEN_IN_THIS);
this.menuitem_openfileinthis.Checked = MyConfig.readBoolean(MyConfig.TAG_OPEN_IN_THIS);
//自动检查更新
menuitem_autocheckupdate.Checked = MyConfig.readBoolean(MyConfig.TAG_AUTO_CHECK_UPDATE);
//add require automatically
addrequire = MyConfig.readString(MyConfig.TAG_ADD_REQUIRE);
menuitem_addrequire.Checked = (addrequire.Length > 0);
if (nowCdbFile != null && File.Exists(nowCdbFile))
Open(nowCdbFile);
this.menuitem_autocheckupdate.Checked = MyConfig.readBoolean(MyConfig.TAG_AUTO_CHECK_UPDATE);
//add require automatically
this.Addrequire = MyConfig.readString(MyConfig.TAG_ADD_REQUIRE);
this.menuitem_addrequire.Checked = (this.Addrequire.Length > 0);
if (this.nowCdbFile != null && File.Exists(this.nowCdbFile))
{
this.Open(this.nowCdbFile);
}
//获取MSE配菜单
AddMenuItemFormMSE();
this.AddMenuItemFormMSE();
//
GetLanguageItem();
this.GetLanguageItem();
// CheckUpdate(false);//检查更新
}
//窗体关闭
void DataEditFormFormClosing(object sender, FormClosingEventArgs e)
{
//当前有任务执行,是否结束
if (tasker != null && tasker.IsRuning())
if (this.tasker != null && this.tasker.IsRuning())
{
if (!CancelTask())
if (!this.CancelTask())
{
e.Cancel = true;
return;
......@@ -194,7 +205,7 @@ void DataEditFormFormClosing(object sender, FormClosingEventArgs e)
//窗体激活
void DataEditFormEnter(object sender, EventArgs e)
{
SetTitle();
this.SetTitle();
}
#endregion
......@@ -203,16 +214,22 @@ void DataEditFormEnter(object sender, EventArgs e)
void HideMenu()
{
if (this.MdiParent == null)
{
return;
mainMenu.Visible = false;
menuitem_file.Visible = false;
menuitem_file.Enabled = false;
}
this.mainMenu.Visible = false;
this.menuitem_file.Visible = false;
this.menuitem_file.Enabled = false;
//this.SuspendLayout();
this.ResumeLayout(true);
foreach (Control c in this.Controls)
{
if (c.GetType() == typeof(MenuStrip))
{
continue;
}
Point p = c.Location;
c.Location = new Point(p.X, p.Y - 25);
}
......@@ -232,78 +249,169 @@ string RemoveTag(string text)
//设置标题
void SetTitle()
{
string str = title;
string str2 = RemoveTag(title);
if (!string.IsNullOrEmpty(nowCdbFile))
string str = this.title;
string str2 = this.RemoveTag(this.title);
if (!string.IsNullOrEmpty(this.nowCdbFile))
{
str = nowCdbFile + "-" + str;
str2 = Path.GetFileName(nowCdbFile);
str = this.nowCdbFile + "-" + str;
str2 = Path.GetFileName(this.nowCdbFile);
}
if (this.MdiParent != null) //父容器不为空
{
this.Text = str2;
if (tasker != null && tasker.IsRuning())
if (this.tasker != null && this.tasker.IsRuning())
{
if (DockPanel.ActiveContent == this)
if (this.DockPanel.ActiveContent == this)
{
this.MdiParent.Text = str;
}
}
else
{
this.MdiParent.Text = str;
}
}
else
{
this.Text = str;
}
}
//按cdb路径设置目录
void SetCDB(string cdb)
{
this.nowCdbFile = cdb;
SetTitle();
this.SetTitle();
string path = Application.StartupPath;
if (cdb.Length > 0)
{
path = Path.GetDirectoryName(cdb);
}
ygopath.SetPath(path);
this.ygopath.SetPath(path);
}
//初始化文件路径
void InitPath(string datapath)
{
this.datapath = datapath;
confcover = MyPath.Combine(datapath, "cover.jpg");
if (File.Exists(confcover))
m_cover = MyBitmap.readImage(confcover);
this.confcover = MyPath.Combine(datapath, "cover.jpg");
if (File.Exists(this.confcover))
{
this.cover = MyBitmap.readImage(this.confcover);
}
else
m_cover = null;
{
this.cover = null;
}
}
#endregion
#region 界面控件
//初始化控件
public void InitControl(DataConfig datacfg)
{
if (datacfg == null)
{
//为了进行错误定位而进行改造 190324 by JoyJ
if (datacfg == null)
{
return;
//选择框
InitComboBox(cb_cardrace, datacfg.dicCardRaces);
InitComboBox(cb_cardattribute, datacfg.dicCardAttributes);
InitComboBox(cb_cardrule, datacfg.dicCardRules);
InitComboBox(cb_cardlevel, datacfg.dicCardLevels);
//卡片类型
InitCheckPanel(pl_cardtype, datacfg.dicCardTypes);
//连接标记
InitCheckPanel(pl_markers, datacfg.dicLinkMarkers);
SetEnabled(pl_markers, false);
//效果类型
InitCheckPanel(pl_category, datacfg.dicCardcategorys);
//系列名
List<long> setcodes = DataManager.GetKeys(datacfg.dicSetnames);
string[] setnames = DataManager.GetValues(datacfg.dicSetnames);
InitComboBox(cb_setname1, setcodes, setnames);
InitComboBox(cb_setname2, setcodes, setnames);
InitComboBox(cb_setname3, setcodes, setnames);
InitComboBox(cb_setname4, setcodes, setnames);
//
}
try
{
this.InitComboBox(this.cb_cardrace, datacfg.dicCardRaces);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "启动错误-cb_cardrace");
}
try
{
this.InitComboBox(this.cb_cardattribute, datacfg.dicCardAttributes);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "启动错误-cb_cardattribute");
}
try
{
this.InitComboBox(this.cb_cardrule, datacfg.dicCardRules);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "启动错误-cb_cardrule");
}
try
{
this.InitComboBox(this.cb_cardlevel, datacfg.dicCardLevels);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "启动错误-cb_cardlevel");
}
try
{
this.InitCheckPanel(this.pl_cardtype, datacfg.dicCardTypes);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "启动错误-pl_cardtype");
}
try
{
this.InitCheckPanel(this.pl_markers, datacfg.dicLinkMarkers);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "启动错误-pl_markers");
}
try
{
this.InitCheckPanel(this.pl_category, datacfg.dicCardcategorys);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "启动错误-pl_category");
}
try
{
this.SetEnabled(this.pl_markers, false);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "启动错误-pl_markers");
}
List<long> setcodes = DataManager.GetKeys(datacfg.dicSetnames);
string[] setnames = DataManager.GetValues(datacfg.dicSetnames);
try
{
this.InitComboBox(this.cb_setname1, setcodes, setnames);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "启动错误-cb_setname1");
}
try
{
this.InitComboBox(this.cb_setname2, setcodes, setnames);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "启动错误-cb_setname2");
}
try
{
this.InitComboBox(this.cb_setname3, setcodes, setnames);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "启动错误-cb_setname3");
}
try
{
this.InitComboBox(this.cb_setname4, setcodes, setnames);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "启动错误-cb_setname4");
}
}
//初始化FlowLayoutPanel
void InitCheckPanel(FlowLayoutPanel fpanel, Dictionary<long, string> dic)
......@@ -324,13 +432,15 @@ void InitCheckPanel(FlowLayoutPanel fpanel, Dictionary<long, string> dic)
lab.Margin = fpanel.Margin;
fpanel.Controls.Add(lab);
}else{
CheckBox _cbox = new CheckBox();
//_cbox.Name = fpanel.Name + key.ToString("x");
_cbox.Tag = key;//绑定值
_cbox.Text = value;
_cbox.AutoSize = true;
_cbox.Margin = fpanel.Margin;
_cbox.CheckedChanged += _cbox_CheckedChanged;
CheckBox _cbox = new CheckBox
{
//_cbox.Name = fpanel.Name + key.ToString("x");
Tag = key,//绑定值
Text = value,
AutoSize = true,
Margin = fpanel.Margin
};
_cbox.CheckedChanged += this._cbox_CheckedChanged;
//_cbox.Click += PanelOnCheckClick;
fpanel.Controls.Add(_cbox);
}
......@@ -341,24 +451,13 @@ void InitCheckPanel(FlowLayoutPanel fpanel, Dictionary<long, string> dic)
private void _cbox_CheckedChanged(object sender, EventArgs e)
{
CheckBox cbox = (CheckBox)sender;
if(cbox.Parent== pl_cardtype)
{
if ((long)cbox.Tag == (long)Core.Info.CardType.TYPE_LINK)
{
SetEnabled(pl_markers, cbox.Checked);
tb_def.ReadOnly = cbox.Checked;
tb_link.ReadOnly = !cbox.Checked;
}
}else if(cbox.Parent == pl_markers){
setLinkMarks(GetCheck(pl_markers));
}
}
//初始化ComboBox
void InitComboBox(ComboBox cb, Dictionary<long, string> tempdic)
{
InitComboBox(cb, DataManager.GetKeys(tempdic),
this.InitComboBox(cb, DataManager.GetKeys(tempdic),
DataManager.GetValues(tempdic));
}
//初始化ComboBox
......@@ -366,34 +465,42 @@ void InitComboBox(ComboBox cb, List<long> keys, string[] values)
{
cb.Items.Clear();
cb.Tag = keys;
cb.Items.AddRange(values);
cb.SelectedIndex = 0;
//Improve 190324 by JoyJ
if (cb.Items.Count > 0)
{
cb.Items.AddRange(values);
cb.SelectedIndex = 0;
}
}
//计算list最大行数
void InitListRows()
{
bool addTest = lv_cardlist.Items.Count == 0;
bool addTest = this.lv_cardlist.Items.Count == 0;
if (addTest)
{
ListViewItem item = new ListViewItem();
item.Text = "Test";
lv_cardlist.Items.Add(item);
ListViewItem item = new ListViewItem
{
Text = "Test"
};
this.lv_cardlist.Items.Add(item);
}
int headH = lv_cardlist.Items[0].GetBounds(ItemBoundsPortion.ItemOnly).Y;
int itemH = lv_cardlist.Items[0].GetBounds(ItemBoundsPortion.ItemOnly).Height;
int headH = this.lv_cardlist.Items[0].GetBounds(ItemBoundsPortion.ItemOnly).Y;
int itemH = this.lv_cardlist.Items[0].GetBounds(ItemBoundsPortion.ItemOnly).Height;
if (itemH > 0)
{
int n = (lv_cardlist.Height - headH) / itemH;
int n = (this.lv_cardlist.Height - headH) / itemH;
if (n > 0){
MaxRow = n;
this.maxRow = n;
}
//MessageBox.Show("height="+lv_cardlist.Height+",item="+itemH+",head="+headH+",max="+MaxRow);
}
if(addTest){
lv_cardlist.Items.Clear();
this.lv_cardlist.Items.Clear();
}
if (this.maxRow < 10)
{
this.maxRow = 20;
}
if (MaxRow < 10)
MaxRow = 20;
}
//设置checkbox
void SetCheck(FlowLayoutPanel fpl, long number)
......@@ -402,13 +509,16 @@ void SetCheck(FlowLayoutPanel fpl, long number)
//string strType = "";
foreach (Control c in fpl.Controls)
{
if (c is CheckBox)
if (c is CheckBox cbox)
{
CheckBox cbox = (CheckBox)c;
if (cbox.Tag == null)
{
temp = 0;
}
else
{
temp = (long)cbox.Tag;
}
if ((temp & number) == temp && temp != 0)
{
......@@ -416,7 +526,9 @@ void SetCheck(FlowLayoutPanel fpl, long number)
//strType += "/" + c.Text;
}
else
{
cbox.Checked = false;
}
}
}
//return strType;
......@@ -425,8 +537,7 @@ void SetEnabled(FlowLayoutPanel fpl, bool set)
{
foreach (Control c in fpl.Controls)
{
CheckBox cbox= c as CheckBox;
if(cbox != null)
if (c is CheckBox cbox)
{
cbox.Enabled = set;
}
......@@ -443,9 +554,9 @@ void SetSelect(ComboBox cb, long k)
List<long> keys = (List<long>)cb.Tag;
int index = keys.IndexOf(k);
if (index >= 0 && index < cb.Items.Count)
{
cb.SelectedIndex = index;
else
cb.SelectedIndex = 0;
}
}
//得到所选值
long GetSelect(ComboBox cb)
......@@ -457,9 +568,13 @@ long GetSelect(ComboBox cb)
List<long> keys = (List<long>)cb.Tag;
int index = cb.SelectedIndex;
if (index >= keys.Count)
{
return 0;
}
else
{
return keys[index];
}
}
//得到checkbox的总值
long GetCheck(FlowLayoutPanel fpl)
......@@ -468,15 +583,21 @@ long GetCheck(FlowLayoutPanel fpl)
long temp;
foreach (Control c in fpl.Controls)
{
if (c is CheckBox)
if (c is CheckBox cbox)
{
CheckBox cbox = (CheckBox)c;
if (cbox.Tag == null)
{
temp = 0;
}
else
{
temp = (long)cbox.Tag;
}
if (cbox.Checked)
{
number += temp;
}
}
}
return number;
......@@ -487,38 +608,56 @@ void AddListView(int p)
int i, j, istart, iend;
if (p <= 0)
{
p = 1;
else if (p >= pageNum)
p = pageNum;
istart = (p - 1) * MaxRow;
iend = p * MaxRow;
if (iend > cardcount)
iend = cardcount;
page = p;
lv_cardlist.BeginUpdate();
lv_cardlist.Items.Clear();
}
else if (p >= this.pageNum)
{
p = this.pageNum;
}
istart = (p - 1) * this.maxRow;
iend = p * this.maxRow;
if (iend > this.cardcount)
{
iend = this.cardcount;
}
this.page = p;
this.lv_cardlist.BeginUpdate();
this.lv_cardlist.Items.Clear();
if ((iend - istart) > 0)
{
ListViewItem[] items = new ListViewItem[iend - istart];
Card mcard;
for (i = istart, j = 0; i < iend; i++, j++)
{
mcard = cardlist[i];
items[j] = new ListViewItem();
items[j].Tag = i;
items[j].Text = mcard.id.ToString();
if (mcard.id == oldCard.id)
mcard = this.cardlist[i];
items[j] = new ListViewItem
{
Tag = i,
Text = mcard.id.ToString()
};
if (mcard.id == this.oldCard.id)
{
items[j].Checked = true;
}
if (i % 2 == 0)
{
items[j].BackColor = Color.GhostWhite;
}
else
{
items[j].BackColor = Color.White;
}
items[j].SubItems.Add(mcard.name);
}
lv_cardlist.Items.AddRange(items);
this.lv_cardlist.Items.AddRange(items);
}
lv_cardlist.EndUpdate();
tb_page.Text = page.ToString();
this.lv_cardlist.EndUpdate();
this.tb_page.Text = this.page.ToString();
}
#endregion
......@@ -526,119 +665,138 @@ void AddListView(int p)
#region 设置卡片
public YgoPath GetPath()
{
return ygopath;
return this.ygopath;
}
public Card GetOldCard()
{
return oldCard;
return this.oldCard;
}
private void setLinkMarks(long mark,bool setCheck=false)
{
if(setCheck)
{
SetCheck(pl_markers, mark);
this.SetCheck(this.pl_markers, mark);
}
tb_link.Text= Convert.ToString(mark, 2).PadLeft(9,'0');
this.tb_link.Text= Convert.ToString(mark, 2).PadLeft(9,'0');
}
public void SetCard(Card c)
{
oldCard = c;
this.oldCard = c;
tb_cardname.Text = c.name;
tb_cardtext.Text = c.desc;
this.tb_cardname.Text = c.name;
this.tb_cardtext.Text = c.desc;
strs = new string[c.Str.Length];
Array.Copy(c.Str, strs, Card.STR_MAX);
lb_scripttext.Items.Clear();
lb_scripttext.Items.AddRange(c.Str);
tb_edittext.Text = "";
this.strs = new string[c.Str.Length];
Array.Copy(c.Str, this.strs, Card.STR_MAX);
this.lb_scripttext.Items.Clear();
this.lb_scripttext.Items.AddRange(c.Str);
this.tb_edittext.Text = "";
//data
SetSelect(cb_cardrule, c.ot);
SetSelect(cb_cardattribute, c.attribute);
SetSelect(cb_cardlevel, (c.level & 0xff));
SetSelect(cb_cardrace, c.race);
this.SetSelect(this.cb_cardrule, c.ot);
this.SetSelect(this.cb_cardattribute, c.attribute);
this.SetSelect(this.cb_cardlevel, (c.level & 0xff));
this.SetSelect(this.cb_cardrace, c.race);
//setcode
long[] setcodes = c.GetSetCode();
tb_setcode1.Text = setcodes[0].ToString("x");
tb_setcode2.Text = setcodes[1].ToString("x");
tb_setcode3.Text = setcodes[2].ToString("x");
tb_setcode4.Text = setcodes[3].ToString("x");
this.tb_setcode1.Text = setcodes[0].ToString("x");
this.tb_setcode2.Text = setcodes[1].ToString("x");
this.tb_setcode3.Text = setcodes[2].ToString("x");
this.tb_setcode4.Text = setcodes[3].ToString("x");
//type,category
SetCheck(pl_cardtype, c.type);
this.SetCheck(this.pl_cardtype, c.type);
if (c.IsType(Core.Info.CardType.TYPE_LINK)){
setLinkMarks(c.def, true);
this.setLinkMarks(c.def, true);
}
else{
tb_link.Text="";
SetCheck(pl_markers, 0);
this.tb_link.Text="";
this.SetCheck(this.pl_markers, 0);
}
SetCheck(pl_category, c.category);
this.SetCheck(this.pl_category, c.category);
//Pendulum
tb_pleft.Text = ((c.level >> 24) & 0xff).ToString();
tb_pright.Text = ((c.level >> 16) & 0xff).ToString();
this.tb_pleft.Text = ((c.level >> 24) & 0xff).ToString();
this.tb_pright.Text = ((c.level >> 16) & 0xff).ToString();
//atk,def
tb_atk.Text = (c.atk < 0) ? "?" : c.atk.ToString();
this.tb_atk.Text = (c.atk < 0) ? "?" : c.atk.ToString();
if (c.IsType(Core.Info.CardType.TYPE_LINK))
tb_def.Text = "0";
{
this.tb_def.Text = "0";
}
else
tb_def.Text = (c.def < 0) ? "?" : c.def.ToString();
tb_cardcode.Text = c.id.ToString();
tb_cardalias.Text = c.alias.ToString();
SetImage(c.id.ToString());
{
this.tb_def.Text = (c.def < 0) ? "?" : c.def.ToString();
}
this.tb_cardcode.Text = c.id.ToString();
this.tb_cardalias.Text = c.alias.ToString();
this.SetImage(c.id.ToString());
}
#endregion
#region 获取卡片
public Card GetCard()
{
int temp;
Card c = new Card(0);
c.name = tb_cardname.Text;
c.desc = tb_cardtext.Text;
Card c = new Card(0)
{
name = this.tb_cardname.Text,
desc = this.tb_cardtext.Text
};
Array.Copy(strs, c.Str, Card.STR_MAX);
Array.Copy(this.strs, c.Str, Card.STR_MAX);
c.ot = (int)GetSelect(cb_cardrule);
c.attribute = (int)GetSelect(cb_cardattribute);
c.level = (int)GetSelect(cb_cardlevel);
c.race = (int)GetSelect(cb_cardrace);
c.ot = (int)this.GetSelect(this.cb_cardrule);
c.attribute = (int)this.GetSelect(this.cb_cardattribute);
c.level = (int)this.GetSelect(this.cb_cardlevel);
c.race = (int)this.GetSelect(this.cb_cardrace);
//系列
c.SetSetCode(
tb_setcode1.Text,
tb_setcode2.Text,
tb_setcode3.Text,
tb_setcode4.Text);
this.tb_setcode1.Text,
this.tb_setcode2.Text,
this.tb_setcode3.Text,
this.tb_setcode4.Text);
c.type = GetCheck(pl_cardtype);
c.category = GetCheck(pl_category);
c.type = this.GetCheck(this.pl_cardtype);
c.category = this.GetCheck(this.pl_category);
int.TryParse(tb_pleft.Text, out temp);
int.TryParse(this.tb_pleft.Text, out int temp);
c.level += (temp << 24);
int.TryParse(tb_pright.Text, out temp);
int.TryParse(this.tb_pright.Text, out temp);
c.level += (temp << 16);
if (tb_atk.Text == "?" || tb_atk.Text == "?")
if (this.tb_atk.Text == "?" || this.tb_atk.Text == "?")
{
c.atk = -2;
else if (tb_atk.Text == ".")
}
else if (this.tb_atk.Text == ".")
{
c.atk = -1;
}
else
int.TryParse(tb_atk.Text, out c.atk);
{
int.TryParse(this.tb_atk.Text, out c.atk);
}
if (c.IsType(Core.Info.CardType.TYPE_LINK))
{
c.def = (int)GetCheck(pl_markers);
c.def = (int)this.GetCheck(this.pl_markers);
}
else
{
if (tb_def.Text == "?" || tb_def.Text == "?")
if (this.tb_def.Text == "?" || this.tb_def.Text == "?")
{
c.def = -2;
else if (tb_def.Text == ".")
}
else if (this.tb_def.Text == ".")
{
c.def = -1;
}
else
int.TryParse(tb_def.Text, out c.def);
{
int.TryParse(this.tb_def.Text, out c.def);
}
}
long.TryParse(tb_cardcode.Text, out c.id);
long.TryParse(tb_cardalias.Text, out c.alias);
long.TryParse(this.tb_cardcode.Text, out c.id);
long.TryParse(this.tb_cardalias.Text, out c.alias);
return c;
}
......@@ -648,14 +806,14 @@ public Card GetCard()
//列表选择
void Lv_cardlistSelectedIndexChanged(object sender, EventArgs e)
{
if (lv_cardlist.SelectedItems.Count > 0)
if (this.lv_cardlist.SelectedItems.Count > 0)
{
int sel = lv_cardlist.SelectedItems[0].Index;
int index = (page - 1) * MaxRow + sel;
if (index < cardlist.Count)
int sel = this.lv_cardlist.SelectedItems[0].Index;
int index = (this.page - 1) * this.maxRow + sel;
if (index < this.cardlist.Count)
{
Card c = cardlist[index];
SetCard(c);
Card c = this.cardlist[index];
this.SetCard(c);
}
}
}
......@@ -665,41 +823,48 @@ void Lv_cardlistKeyDown(object sender, KeyEventArgs e)
switch (e.KeyCode)
{
case Keys.Delete:
cmdManager.ExcuteCommand(cardedit.delCard, menuitem_operacardsfile.Checked);
this.cmdManager.ExcuteCommand(this.cardedit.delCard, this.menuitem_operacardsfile.Checked);
break;
case Keys.Right:
Btn_PageDownClick(null, null);
this.Btn_PageDownClick(null, null);
break;
case Keys.Left:
Btn_PageUpClick(null, null);
this.Btn_PageUpClick(null, null);
break;
}
}
//上一页
void Btn_PageUpClick(object sender, EventArgs e)
{
if (!CheckOpen())
if (!this.CheckOpen())
{
return;
page--;
AddListView(page);
}
this.page--;
this.AddListView(this.page);
}
//下一页
void Btn_PageDownClick(object sender, EventArgs e)
{
if (!CheckOpen())
if (!this.CheckOpen())
{
return;
page++;
AddListView(page);
}
this.page++;
this.AddListView(this.page);
}
//跳转到指定页数
void Tb_pageKeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == (char)Keys.Enter)
{
int p;
int.TryParse(tb_page.Text, out p);
int.TryParse(this.tb_page.Text, out int p);
if (p > 0)
AddListView(p);
{
this.AddListView(p);
}
}
}
#endregion
......@@ -708,30 +873,31 @@ void Tb_pageKeyPress(object sender, KeyPressEventArgs e)
//检查是否打开数据库
public bool CheckOpen()
{
if (File.Exists(nowCdbFile))
if (File.Exists(this.nowCdbFile))
{
return true;
}
else
{
MyMsg.Warning(LMSG.NotSelectDataBase);
return false;
}
}
//打开数据库
public bool Open(string file)
{
SetCDB(file);
this.SetCDB(file);
if (!File.Exists(file))
{
MyMsg.Error(LMSG.FileIsNotExists);
return false;
}
//清空
tmpCodes.Clear();
cardlist.Clear();
this.tmpCodes.Clear();
this.cardlist.Clear();
//检查表是否存在
DataBase.CheckTable(file);
srcCard = new Card();
SetCards(DataBase.Read(file, true, ""), false);
this.srcCard = new Card();
this.SetCards(DataBase.Read(file, true, ""), false);
return true;
}
......@@ -740,7 +906,10 @@ public bool CardFilter(Card c, Card sc)
{
bool res = true;
if (sc.setcode != 0)
{
res &= c.IsSetCode(sc.setcode & 0xffff);
}
return res;
}
//设置卡片列表的结果
......@@ -748,70 +917,83 @@ public void SetCards(Card[] cards, bool isfresh)
{
if (cards != null)
{
cardlist.Clear();
this.cardlist.Clear();
foreach (Card c in cards)
{
if (CardFilter(c, srcCard))
cardlist.Add(c);
if (this.CardFilter(c, this.srcCard))
{
this.cardlist.Add(c);
}
}
this.cardcount = this.cardlist.Count;
this.pageNum = this.cardcount / this.maxRow;
if (this.cardcount % this.maxRow > 0)
{
this.pageNum++;
}
cardcount = cardlist.Count;
pageNum = cardcount / MaxRow;
if (cardcount % MaxRow > 0)
pageNum++;
else if (cardcount == 0)
pageNum = 1;
tb_pagenum.Text = pageNum.ToString();
else if (this.cardcount == 0)
{
this.pageNum = 1;
}
this.tb_pagenum.Text = this.pageNum.ToString();
if (isfresh)//是否跳到之前页数
AddListView(page);
{
this.AddListView(this.page);
}
else
AddListView(1);
{
this.AddListView(1);
}
}
else
{//结果为空
cardcount = 0;
page = 1;
pageNum = 1;
tb_page.Text = page.ToString();
tb_pagenum.Text = pageNum.ToString();
cardlist.Clear();
lv_cardlist.Items.Clear();
this.cardcount = 0;
this.page = 1;
this.pageNum = 1;
this.tb_page.Text = this.page.ToString();
this.tb_pagenum.Text = this.pageNum.ToString();
this.cardlist.Clear();
this.lv_cardlist.Items.Clear();
//SetCard(new Card(0));
}
}
//搜索卡片
public void Search(bool isfresh)
{
Search(srcCard, isfresh);
this.Search(this.srcCard, isfresh);
}
void Search(Card c, bool isfresh)
{
if (!CheckOpen())
if (!this.CheckOpen())
{
return;
}
//如果临时卡片不为空,则更新,这个在搜索的时候清空
if (tmpCodes.Count > 0)
if (this.tmpCodes.Count > 0)
{
Card[] mcards = DataBase.Read(nowCdbFile,
true, tmpCodes.ToArray());
SetCards(getCompCards(), true);
_ = DataBase.Read(this.nowCdbFile,
true, this.tmpCodes.ToArray());
this.SetCards(this.getCompCards(), true);
}
else
{
srcCard = c;
this.srcCard = c;
string sql = DataBase.GetSelectSQL(c);
SetCards(DataBase.Read(nowCdbFile, true, sql), isfresh);
this.SetCards(DataBase.Read(this.nowCdbFile, true, sql), isfresh);
}
if (lv_cardlist.Items.Count > 0)
if (this.lv_cardlist.Items.Count > 0)
{
lv_cardlist.SelectedIndices.Clear();
lv_cardlist.SelectedIndices.Add(0);
this.lv_cardlist.SelectedIndices.Clear();
this.lv_cardlist.SelectedIndices.Add(0);
}
}
//更新临时卡片
public void Reset()
{
oldCard = new Card(0);
SetCard(oldCard);
this.oldCard = new Card(0);
this.SetCard(this.oldCard);
}
#endregion
......@@ -819,51 +1001,59 @@ public void Reset()
//搜索卡片
void Btn_serachClick(object sender, EventArgs e)
{
tmpCodes.Clear();//清空临时的结果
Search(GetCard(), false);
this.tmpCodes.Clear();//清空临时的结果
this.Search(this.GetCard(), false);
}
//重置卡片
void Btn_resetClick(object sender, EventArgs e)
{
Reset();
this.Reset();
}
//添加
void Btn_addClick(object sender, EventArgs e)
{
if (cardedit != null)
cmdManager.ExcuteCommand(cardedit.addCard);
if (this.cardedit != null)
{
this.cmdManager.ExcuteCommand(this.cardedit.addCard);
}
}
//修改
void Btn_modClick(object sender, EventArgs e)
{
if (cardedit != null)
cmdManager.ExcuteCommand(cardedit.modCard, menuitem_operacardsfile.Checked);
if (this.cardedit != null)
{
this.cmdManager.ExcuteCommand(this.cardedit.modCard, this.menuitem_operacardsfile.Checked);
}
}
//打开脚本
void Btn_luaClick(object sender, EventArgs e)
{
if (cardedit != null)
cardedit.OpenScript(menuitem_openfileinthis.Checked, addrequire);
if (this.cardedit != null)
{
this.cardedit.OpenScript(this.menuitem_openfileinthis.Checked, this.Addrequire);
}
}
//删除
void Btn_delClick(object sender, EventArgs e)
{
if (cardedit != null)
cmdManager.ExcuteCommand(cardedit.delCard, menuitem_operacardsfile.Checked);
if (this.cardedit != null)
{
this.cmdManager.ExcuteCommand(this.cardedit.delCard, this.menuitem_operacardsfile.Checked);
}
}
//撤销
void Btn_undoClick(object sender, EventArgs e)
{
if (cardedit != null)
if (this.cardedit != null)
{
cmdManager.Undo();
Search(true);
this.cmdManager.Undo();
this.Search(true);
}
}
//导入卡图
void Btn_imgClick(object sender, EventArgs e)
{
ImportImageFromSelect();
this.ImportImageFromSelect();
}
#endregion
......@@ -874,11 +1064,11 @@ void Tb_cardcodeKeyPress(object sender, KeyPressEventArgs e)
if (e.KeyChar == (char)Keys.Enter)
{
Card c = new Card(0);
long.TryParse(tb_cardcode.Text, out c.id);
long.TryParse(this.tb_cardcode.Text, out c.id);
if (c.id > 0)
{
tmpCodes.Clear();//清空临时的结果
Search(c, false);
this.tmpCodes.Clear();//清空临时的结果
this.Search(c, false);
}
}
}
......@@ -887,26 +1077,28 @@ void Tb_cardnameKeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
Card c = new Card(0);
c.name = tb_cardname.Text;
Card c = new Card(0)
{
name = this.tb_cardname.Text
};
if (c.name.Length > 0)
{
tmpCodes.Clear();//清空临时的结果
Search(c, false);
this.tmpCodes.Clear();//清空临时的结果
this.Search(c, false);
}
}
if (e.KeyCode == Keys.R && e.Control)
{
Btn_resetClick(null, null);
this.Btn_resetClick(null, null);
}
}
//卡片描述编辑
void Setscripttext(string str)
{
int index = -1;
int index;
try
{
index = lb_scripttext.SelectedIndex;
index = this.lb_scripttext.SelectedIndex;
}
catch
{
......@@ -915,20 +1107,20 @@ void Setscripttext(string str)
}
if (index >= 0)
{
strs[index] = str;
this.strs[index] = str;
lb_scripttext.Items.Clear();
lb_scripttext.Items.AddRange(strs);
lb_scripttext.SelectedIndex = index;
this.lb_scripttext.Items.Clear();
this.lb_scripttext.Items.AddRange(this.strs);
this.lb_scripttext.SelectedIndex = index;
}
}
string Getscripttext()
{
int index = -1;
int index;
try
{
index = lb_scripttext.SelectedIndex;
index = this.lb_scripttext.SelectedIndex;
}
catch
{
......@@ -936,20 +1128,24 @@ string Getscripttext()
MyMsg.Error(LMSG.NotSelectScriptText);
}
if (index >= 0)
return strs[index];
{
return this.strs[index];
}
else
{
return "";
}
}
//脚本文本
void Lb_scripttextSelectedIndexChanged(object sender, EventArgs e)
{
tb_edittext.Text = Getscripttext();
this.tb_edittext.Text = this.Getscripttext();
}
//脚本文本
void Tb_edittextTextChanged(object sender, EventArgs e)
{
Setscripttext(tb_edittext.Text);
this.Setscripttext(this.tb_edittext.Text);
}
#endregion
......@@ -964,35 +1160,40 @@ void Menuitem_aboutClick(object sender, EventArgs e)
void Menuitem_checkupdateClick(object sender, EventArgs e)
{
CheckUpdate(true);
this.CheckUpdate(true);
}
public void CheckUpdate(bool showNew)
{
if (!isRun())
if (!this.isRun())
{
tasker.SetTask(MyTask.CheckUpdate, null, showNew.ToString());
Run(LanguageHelper.GetMsg(LMSG.checkUpdate));
this.tasker.SetTask(MyTask.CheckUpdate, null, showNew.ToString());
this.Run(LanguageHelper.GetMsg(LMSG.checkUpdate));
}
}
bool CancelTask()
{
bool bl = false;
if (tasker != null && tasker.IsRuning())
if (this.tasker != null && this.tasker.IsRuning())
{
bl = MyMsg.Question(LMSG.IfCancelTask);
if (bl)
{
if (tasker != null)
tasker.Cancel();
if (bgWorker1.IsBusy)
bgWorker1.CancelAsync();
if (this.tasker != null)
{
this.tasker.Cancel();
}
if (this.bgWorker1.IsBusy)
{
this.bgWorker1.CancelAsync();
}
}
}
return bl;
}
void Menuitem_cancelTaskClick(object sender, EventArgs e)
{
CancelTask();
this.CancelTask();
}
void Menuitem_githubClick(object sender, EventArgs e)
{
......@@ -1010,7 +1211,7 @@ void Menuitem_openClick(object sender, EventArgs e)
dlg.Filter = LanguageHelper.GetMsg(LMSG.CdbType);
if (dlg.ShowDialog() == DialogResult.OK)
{
Open(dlg.FileName);
this.Open(dlg.FileName);
}
}
}
......@@ -1026,7 +1227,9 @@ void Menuitem_newClick(object sender, EventArgs e)
if (DataBase.Create(dlg.FileName))
{
if (MyMsg.Question(LMSG.IfOpenDataBase))
Open(dlg.FileName);
{
this.Open(dlg.FileName);
}
}
}
}
......@@ -1034,18 +1237,21 @@ void Menuitem_newClick(object sender, EventArgs e)
//读取ydk
void Menuitem_readydkClick(object sender, EventArgs e)
{
if (!CheckOpen())
if (!this.CheckOpen())
{
return;
}
using (OpenFileDialog dlg = new OpenFileDialog())
{
dlg.Title = LanguageHelper.GetMsg(LMSG.SelectYdkPath);
dlg.Filter = LanguageHelper.GetMsg(LMSG.ydkType);
if (dlg.ShowDialog() == DialogResult.OK)
{
tmpCodes.Clear();
this.tmpCodes.Clear();
string[] ids = YGOUtil.ReadYDK(dlg.FileName);
tmpCodes.AddRange(ids);
SetCards(DataBase.Read(nowCdbFile, true,
this.tmpCodes.AddRange(ids);
this.SetCards(DataBase.Read(this.nowCdbFile, true,
ids), false);
}
}
......@@ -1053,17 +1259,20 @@ void Menuitem_readydkClick(object sender, EventArgs e)
//从图片文件夹读取
void Menuitem_readimagesClick(object sender, EventArgs e)
{
if (!CheckOpen())
if (!this.CheckOpen())
{
return;
}
using (FolderBrowserDialog fdlg = new FolderBrowserDialog())
{
fdlg.Description = LanguageHelper.GetMsg(LMSG.SelectImagePath);
if (fdlg.ShowDialog() == DialogResult.OK)
{
tmpCodes.Clear();
this.tmpCodes.Clear();
string[] ids = YGOUtil.ReadImage(fdlg.SelectedPath);
tmpCodes.AddRange(ids);
SetCards(DataBase.Read(nowCdbFile, true,
this.tmpCodes.AddRange(ids);
this.SetCards(DataBase.Read(this.nowCdbFile, true,
ids), false);
}
}
......@@ -1079,7 +1288,7 @@ void Menuitem_quitClick(object sender, EventArgs e)
//是否在执行
bool isRun()
{
if (tasker != null && tasker.IsRuning())
if (this.tasker != null && this.tasker.IsRuning())
{
MyMsg.Warning(LMSG.RunError);
return true;
......@@ -1089,52 +1298,61 @@ bool isRun()
//执行任务
void Run(string name)
{
if (isRun())
if (this.isRun())
{
return;
taskname = name;
title = title + " (" + taskname + ")";
SetTitle();
bgWorker1.RunWorkerAsync();
}
this.taskname = name;
this.title = this.title + " (" + this.taskname + ")";
this.SetTitle();
this.bgWorker1.RunWorkerAsync();
}
//线程任务
void BgWorker1DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
tasker.Run();
this.tasker.Run();
}
void BgWorker1ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e)
{
title = string.Format("{0} ({1}-{2})",
RemoveTag(title),
taskname,
this.title = string.Format("{0} ({1}-{2})",
this.RemoveTag(this.title),
this.taskname,
// e.ProgressPercentage,
e.UserState);
SetTitle();
this.SetTitle();
}
//任务完成
void BgWorker1RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
{
//还原标题
int t = title.LastIndexOf(" (");
int t = this.title.LastIndexOf(" (");
if (t > 0)
{
title = title.Substring(0, t);
SetTitle();
this.title = this.title.Substring(0, t);
this.SetTitle();
}
if (e.Error != null)
{//出错
if (tasker != null)
tasker.Cancel();
if (bgWorker1.IsBusy)
bgWorker1.CancelAsync();
if (this.tasker != null)
{
this.tasker.Cancel();
}
if (this.bgWorker1.IsBusy)
{
this.bgWorker1.CancelAsync();
}
MyMsg.Show(LanguageHelper.GetMsg(LMSG.TaskError) + "\n" + e.Error);
}
else if (tasker.IsCancel() || e.Cancelled)
else if (this.tasker.IsCancel() || e.Cancelled)
{//取消任务
MyMsg.Show(LMSG.CancelTask);
}
else
{
MyTask mt = tasker.getLastTask();
MyTask mt = this.tasker.getLastTask();
switch (mt)
{
case MyTask.CheckUpdate:
......@@ -1153,7 +1371,7 @@ void BgWorker1RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerC
break;
case MyTask.ReadMSE:
//保存读取的卡片
SaveCards(tasker.CardList);
this.SaveCards(this.tasker.CardList);
MyMsg.Show(LMSG.ReadMSEisOK);
break;
}
......@@ -1165,24 +1383,37 @@ void BgWorker1RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerC
//得到卡片列表,是否是选中的
public Card[] GetCardList(bool onlyselect)
{
if (!CheckOpen())
if (!this.CheckOpen())
{
return null;
}
List<Card> cards = new List<Card>();
if (onlyselect)
{
foreach (ListViewItem lvitem in lv_cardlist.SelectedItems)
foreach (ListViewItem lvitem in this.lv_cardlist.SelectedItems)
{
int index;
if (lvitem.Tag != null)
{
index = (int)lvitem.Tag;
}
else
index = lvitem.Index + (page - 1) * MaxRow;
if (index>=0 && index < cardlist.Count)
cards.Add(cardlist[index]);
{
index = lvitem.Index + (this.page - 1) * this.maxRow;
}
if (index>=0 && index < this.cardlist.Count)
{
cards.Add(this.cardlist[index]);
}
}
}
else
cards.AddRange(cardlist.ToArray());
{
cards.AddRange(this.cardlist.ToArray());
}
if (cards.Count == 0)
{
//MyMsg.Show(LMSG.NoSelectCard);
......@@ -1191,28 +1422,36 @@ public Card[] GetCardList(bool onlyselect)
}
void Menuitem_copytoClick(object sender, EventArgs e)
{
if (!CheckOpen())
if (!this.CheckOpen())
{
return;
CopyTo(GetCardList(false));
}
this.CopyTo(this.GetCardList(false));
}
void Menuitem_copyselecttoClick(object sender, EventArgs e)
{
if (!CheckOpen())
if (!this.CheckOpen())
{
return;
CopyTo(GetCardList(true));
}
this.CopyTo(this.GetCardList(true));
}
//保存卡片到当前数据库
public void SaveCards(Card[] cards)
{
cmdManager.ExcuteCommand(cardedit.copyCard, cards);
Search(srcCard, true);
this.cmdManager.ExcuteCommand(this.cardedit.copyCard, cards);
this.Search(this.srcCard, true);
}
//卡片另存为
void CopyTo(Card[] cards)
{
if (cards == null || cards.Length == 0)
{
return;
}
//select file
bool replace = false;
string filename = null;
......@@ -1239,35 +1478,49 @@ void CopyTo(Card[] cards)
//裁剪图片
void Menuitem_cutimagesClick(object sender, EventArgs e)
{
if (!CheckOpen())
if (!this.CheckOpen())
{
return;
if (isRun())
}
if (this.isRun())
{
return;
}
bool isreplace = MyMsg.Question(LMSG.IfReplaceExistingImage);
tasker.SetTask(MyTask.CutImages, cardlist.ToArray(),
ygopath.picpath, isreplace.ToString());
Run(LanguageHelper.GetMsg(LMSG.CutImage));
this.tasker.SetTask(MyTask.CutImages, this.cardlist.ToArray(),
this.ygopath.picpath, isreplace.ToString());
this.Run(LanguageHelper.GetMsg(LMSG.CutImage));
}
void Menuitem_saveasmse_selectClick(object sender, EventArgs e)
{
//选择
SaveAsMSE(true);
this.SaveAsMSE(true);
}
void Menuitem_saveasmseClick(object sender, EventArgs e)
{
//全部
SaveAsMSE(false);
this.SaveAsMSE(false);
}
void SaveAsMSE(bool onlyselect)
{
if (!CheckOpen())
if (!this.CheckOpen())
{
return;
if (isRun())
}
if (this.isRun())
{
return;
Card[] cards = GetCardList(onlyselect);
}
Card[] cards = this.GetCardList(onlyselect);
if (cards == null)
{
return;
}
//select save mse-set
using (SaveFileDialog dlg = new SaveFileDialog())
{
......@@ -1278,10 +1531,10 @@ void SaveAsMSE(bool onlyselect)
bool isUpdate = false;
#if DEBUG
isUpdate=MyMsg.Question(LMSG.OnlySet);
#endif
tasker.SetTask(MyTask.SaveAsMSE, cards,
#endif
this.tasker.SetTask(MyTask.SaveAsMSE, cards,
dlg.FileName, isUpdate.ToString());
Run(LanguageHelper.GetMsg(LMSG.SaveMse));
this.Run(LanguageHelper.GetMsg(LMSG.SaveMse));
}
}
}
......@@ -1290,107 +1543,126 @@ void SaveAsMSE(bool onlyselect)
#region 导入卡图
void ImportImageFromSelect()
{
string tid = tb_cardcode.Text;
string tid = this.tb_cardcode.Text;
if (tid == "0" || tid.Length == 0)
{
return;
}
using (OpenFileDialog dlg = new OpenFileDialog())
{
dlg.Title = LanguageHelper.GetMsg(LMSG.SelectImage) + "-" + tb_cardname.Text;
dlg.Title = LanguageHelper.GetMsg(LMSG.SelectImage) + "-" + this.tb_cardname.Text;
dlg.Filter = LanguageHelper.GetMsg(LMSG.ImageType);
if (dlg.ShowDialog() == DialogResult.OK)
{
//dlg.FileName;
ImportImage(dlg.FileName, tid);
this.ImportImage(dlg.FileName, tid);
}
}
}
private void pl_image_DoubleClick(object sender, EventArgs e)
{
ImportImageFromSelect();
this.ImportImageFromSelect();
}
void Pl_imageDragDrop(object sender, DragEventArgs e)
{
string[] files = e.Data.GetData(DataFormats.FileDrop) as string[];
if (File.Exists(files[0]))
ImportImage(files[0], tb_cardcode.Text);
{
this.ImportImage(files[0], this.tb_cardcode.Text);
}
}
void Pl_imageDragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Link; //重要代码:表明是链接类型的数据,比如文件路径
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void menuitem_importmseimg_Click(object sender, EventArgs e)
{
string tid = tb_cardcode.Text;
menuitem_importmseimg.Checked = !menuitem_importmseimg.Checked;
SetImage(tid);
string tid = this.tb_cardcode.Text;
this.menuitem_importmseimg.Checked = !this.menuitem_importmseimg.Checked;
this.SetImage(tid);
}
void ImportImage(string file, string tid)
{
string f;
if (pl_image.BackgroundImage != null
&& pl_image.BackgroundImage != m_cover)
if (this.pl_image.BackgroundImage != null
&& this.pl_image.BackgroundImage != this.cover)
{//释放图片资源
pl_image.BackgroundImage.Dispose();
pl_image.BackgroundImage = m_cover;
this.pl_image.BackgroundImage.Dispose();
this.pl_image.BackgroundImage = this.cover;
}
if (menuitem_importmseimg.Checked)
if (this.menuitem_importmseimg.Checked)
{
if (!Directory.Exists(tasker.MSEImagePath))
Directory.CreateDirectory(tasker.MSEImagePath);
f = MyPath.Combine(tasker.MSEImagePath, tid + ".jpg");
if (!Directory.Exists(this.tasker.MSEImagePath))
{
Directory.CreateDirectory(this.tasker.MSEImagePath);
}
f = MyPath.Combine(this.tasker.MSEImagePath, tid + ".jpg");
File.Copy(file, f, true);
}
else
{
// tasker.ToImg(file, ygopath.GetImage(tid),
// ygopath.GetImageThum(tid));
tasker.ToImg(file, ygopath.GetImage(tid));
// tasker.ToImg(file, ygopath.GetImage(tid),
// ygopath.GetImageThum(tid));
this.tasker.ToImg(file, this.ygopath.GetImage(tid));
}
SetImage(tid);
this.SetImage(tid);
}
public void SetImage(string id)
{
long t;
long.TryParse(id, out t);
SetImage(t);
long.TryParse(id, out long t);
this.SetImage(t);
}
public void SetImage(long id)
{
string pic = ygopath.GetImage(id);
if (menuitem_importmseimg.Checked)//显示MSE图片
string pic = this.ygopath.GetImage(id);
if (this.menuitem_importmseimg.Checked)//显示MSE图片
{
string msepic = MseMaker.GetCardImagePath(tasker.MSEImagePath, oldCard);
string msepic = MseMaker.GetCardImagePath(this.tasker.MSEImagePath, this.oldCard);
if(File.Exists(msepic))
{
pl_image.BackgroundImage = MyBitmap.readImage(msepic);
this.pl_image.BackgroundImage = MyBitmap.readImage(msepic);
}
}
else if (File.Exists(pic))
{
pl_image.BackgroundImage = MyBitmap.readImage(pic);
this.pl_image.BackgroundImage = MyBitmap.readImage(pic);
}
else
pl_image.BackgroundImage = m_cover;
{
this.pl_image.BackgroundImage = this.cover;
}
}
void Menuitem_convertimageClick(object sender, EventArgs e)
{
if (!CheckOpen())
if (!this.CheckOpen())
{
return;
if (isRun())
}
if (this.isRun())
{
return;
}
using (FolderBrowserDialog fdlg = new FolderBrowserDialog())
{
fdlg.Description = LanguageHelper.GetMsg(LMSG.SelectImagePath);
if (fdlg.ShowDialog() == DialogResult.OK)
{
bool isreplace = MyMsg.Question(LMSG.IfReplaceExistingImage);
tasker.SetTask(MyTask.ConvertImages, null,
fdlg.SelectedPath, ygopath.gamepath, isreplace.ToString());
Run(LanguageHelper.GetMsg(LMSG.ConvertImage));
this.tasker.SetTask(MyTask.ConvertImages, null,
fdlg.SelectedPath, this.ygopath.gamepath, isreplace.ToString());
this.Run(LanguageHelper.GetMsg(LMSG.ConvertImage));
}
}
}
......@@ -1399,23 +1671,29 @@ void Menuitem_convertimageClick(object sender, EventArgs e)
#region 导出数据包
void Menuitem_exportdataClick(object sender, EventArgs e)
{
if (!CheckOpen())
if (!this.CheckOpen())
{
return;
if (isRun())
}
if (this.isRun())
{
return;
}
using (SaveFileDialog dlg = new SaveFileDialog())
{
dlg.InitialDirectory = ygopath.gamepath;
dlg.InitialDirectory = this.ygopath.gamepath;
dlg.Filter = "Zip|(*.zip|All Files(*.*)|*.*";
if (dlg.ShowDialog() == DialogResult.OK)
{
tasker.SetTask(MyTask.ExportData,
GetCardList(false),
ygopath.gamepath,
this.tasker.SetTask(MyTask.ExportData,
this.GetCardList(false),
this.ygopath.gamepath,
dlg.FileName,
GetOpenFile(),
addrequire);
Run(LanguageHelper.GetMsg(LMSG.ExportData));
this.GetOpenFile(),
this.Addrequire);
this.Run(LanguageHelper.GetMsg(LMSG.ExportData));
}
}
......@@ -1431,43 +1709,60 @@ bool CheckCard(Card[] cards, Card card, bool checkinfo)
foreach (Card c in cards)
{
if (c.id != card.id)
{
continue;
}
//data数据不一样
if (checkinfo)
{
return card.EqualsData(c);
}
else
{
return true;
}
}
return false;
}
//读取将要对比的数据
Card[] getCompCards()
{
if (tmpCodes.Count == 0)
if (this.tmpCodes.Count == 0)
{
return null;
if (!CheckOpen())
}
if (!this.CheckOpen())
{
return null;
return DataBase.Read(nowCdbFile, true, tmpCodes.ToArray());
}
return DataBase.Read(this.nowCdbFile, true, this.tmpCodes.ToArray());
}
public void CompareCards(string cdbfile, bool checktext)
{
if (!CheckOpen())
if (!this.CheckOpen())
{
return;
tmpCodes.Clear();
srcCard = new Card();
Card[] mcards = DataBase.Read(nowCdbFile, true, "");
}
this.tmpCodes.Clear();
this.srcCard = new Card();
Card[] mcards = DataBase.Read(this.nowCdbFile, true, "");
Card[] cards = DataBase.Read(cdbfile, true, "");
foreach (Card card in mcards)
{
if (!CheckCard(cards, card, checktext))//添加到id集合
tmpCodes.Add(card.id.ToString());
if (!this.CheckCard(cards, card, checktext))//添加到id集合
{
this.tmpCodes.Add(card.id.ToString());
}
}
if (tmpCodes.Count == 0)
if (this.tmpCodes.Count == 0)
{
SetCards(null, false);
this.SetCards(null, false);
return;
}
SetCards(getCompCards(), false);
this.SetCards(this.getCompCards(), false);
}
#endregion
......@@ -1475,36 +1770,48 @@ public void CompareCards(string cdbfile, bool checktext)
//把文件添加到菜单
void AddMenuItemFormMSE()
{
if(!Directory.Exists(datapath))
if(!Directory.Exists(this.datapath))
{
return;
menuitem_mseconfig.DropDownItems.Clear();//清空
string[] files = Directory.GetFiles(datapath);
}
this.menuitem_mseconfig.DropDownItems.Clear();//清空
string[] files = Directory.GetFiles(this.datapath);
foreach (string file in files)
{
string name = MyPath.getFullFileName(MSEConfig.TAG, file);
//是否是MSE配置文件
if (string.IsNullOrEmpty(name))
{
continue;
}
//菜单文字是语言
ToolStripMenuItem tsmi = new ToolStripMenuItem(name);
tsmi.ToolTipText = file;//提示文字为真实路径
tsmi.Click += SetMseConfig_Click;
if (msecfg.configName.Equals(name, StringComparison.OrdinalIgnoreCase))
ToolStripMenuItem tsmi = new ToolStripMenuItem(name)
{
ToolTipText = file//提示文字为真实路径
};
tsmi.Click += this.SetMseConfig_Click;
if (this.msecfg.configName.Equals(name, StringComparison.OrdinalIgnoreCase))
{
tsmi.Checked = true;//如果是当前,则打勾
menuitem_mseconfig.DropDownItems.Add(tsmi);
}
this.menuitem_mseconfig.DropDownItems.Add(tsmi);
}
}
void SetMseConfig_Click(object sender, EventArgs e)
{
if (isRun())//正在执行任务
if (this.isRun())//正在执行任务
{
return;
if (sender is ToolStripMenuItem)
}
if (sender is ToolStripMenuItem tsmi)
{
ToolStripMenuItem tsmi = (ToolStripMenuItem)sender;
//读取新的配置
msecfg.SetConfig(tsmi.ToolTipText, datapath);
this.msecfg.SetConfig(tsmi.ToolTipText, this.datapath);
//刷新菜单
AddMenuItemFormMSE();
this.AddMenuItemFormMSE();
//保存配置
MyConfig.Save(MyConfig.TAG_MSE, tsmi.Text);
}
......@@ -1514,7 +1821,7 @@ void SetMseConfig_Click(object sender, EventArgs e)
#region 查找lua函数
private void menuitem_findluafunc_Click(object sender, EventArgs e)
{
string funtxt = MyPath.Combine(datapath, MyConfig.FILE_FUNCTION);
string funtxt = MyPath.Combine(this.datapath, MyConfig.FILE_FUNCTION);
using (FolderBrowserDialog fd = new FolderBrowserDialog())
{
fd.Description = "Folder Name: ocgcore";
......@@ -1533,38 +1840,43 @@ private void menuitem_findluafunc_Click(object sender, EventArgs e)
//系列名输入时
void setCode_InputText(int index, ComboBox cb, TextBox tb)
{
if(index>=0 && index < setcodeIsedit.Length)
if(index>=0 && index < this.setcodeIsedit.Length)
{
if (setcodeIsedit[index])//如果正在编辑
if (this.setcodeIsedit[index])//如果正在编辑
{
return;
setcodeIsedit[index] = true;
int temp;
int.TryParse(tb.Text, NumberStyles.HexNumber, null, out temp);
}
this.setcodeIsedit[index] = true;
int.TryParse(tb.Text, NumberStyles.HexNumber, null, out int temp);
//tb.Text = temp.ToString("x");
if (temp == 0 && (tb.Text != "0" || tb.Text.Length == 0))
{
temp = -1;
SetSelect(cb, temp);
setcodeIsedit[index] = false;
}
this.SetSelect(cb, temp);
this.setcodeIsedit[index] = false;
}
}
private void tb_setcode1_TextChanged(object sender, EventArgs e)
{
setCode_InputText(1, cb_setname1, tb_setcode1);
this.setCode_InputText(1, this.cb_setname1, this.tb_setcode1);
}
private void tb_setcode2_TextChanged(object sender, EventArgs e)
{
setCode_InputText(2, cb_setname2, tb_setcode2);
this.setCode_InputText(2, this.cb_setname2, this.tb_setcode2);
}
private void tb_setcode3_TextChanged(object sender, EventArgs e)
{
setCode_InputText(3, cb_setname3, tb_setcode3);
this.setCode_InputText(3, this.cb_setname3, this.tb_setcode3);
}
private void tb_setcode4_TextChanged(object sender, EventArgs e)
{
setCode_InputText(4, cb_setname4, tb_setcode4);
this.setCode_InputText(4, this.cb_setname4, this.tb_setcode4);
}
#endregion
......@@ -1572,44 +1884,52 @@ private void tb_setcode4_TextChanged(object sender, EventArgs e)
//系列选择框 选择时
void setCode_Selected(int index, ComboBox cb, TextBox tb)
{
if (index >= 0 && index < setcodeIsedit.Length)
if (index >= 0 && index < this.setcodeIsedit.Length)
{
if (setcodeIsedit[index])//如果正在编辑
if (this.setcodeIsedit[index])//如果正在编辑
{
return;
setcodeIsedit[index] = true;
long tmp = GetSelect(cb);
}
this.setcodeIsedit[index] = true;
long tmp = this.GetSelect(cb);
tb.Text = tmp.ToString("x");
setcodeIsedit[index] = false;
this.setcodeIsedit[index] = false;
}
}
private void cb_setname1_SelectedIndexChanged(object sender, EventArgs e)
{
setCode_Selected(1, cb_setname1, tb_setcode1);
this.setCode_Selected(1, this.cb_setname1, this.tb_setcode1);
}
private void cb_setname2_SelectedIndexChanged(object sender, EventArgs e)
{
setCode_Selected(2, cb_setname2, tb_setcode2);
this.setCode_Selected(2, this.cb_setname2, this.tb_setcode2);
}
private void cb_setname3_SelectedIndexChanged(object sender, EventArgs e)
{
setCode_Selected(3, cb_setname3, tb_setcode3);
this.setCode_Selected(3, this.cb_setname3, this.tb_setcode3);
}
private void cb_setname4_SelectedIndexChanged(object sender, EventArgs e)
{
setCode_Selected(4, cb_setname4, tb_setcode4);
this.setCode_Selected(4, this.cb_setname4, this.tb_setcode4);
}
#endregion
#region 读取MSE存档
private void menuitem_readmse_Click(object sender, EventArgs e)
{
if (!CheckOpen())
if (!this.CheckOpen())
{
return;
if (isRun())
}
if (this.isRun())
{
return;
}
//select open mse-set
using (OpenFileDialog dlg = new OpenFileDialog())
{
......@@ -1617,11 +1937,10 @@ private void menuitem_readmse_Click(object sender, EventArgs e)
dlg.Filter = LanguageHelper.GetMsg(LMSG.MseType);
if (dlg.ShowDialog() == DialogResult.OK)
{
bool isUpdate = false;//是否替换存在的图片
isUpdate = MyMsg.Question(LMSG.IfReplaceExistingImage);
tasker.SetTask(MyTask.ReadMSE, null,
bool isUpdate = MyMsg.Question(LMSG.IfReplaceExistingImage);
this.tasker.SetTask(MyTask.ReadMSE, null,
dlg.FileName, isUpdate.ToString());
Run(LanguageHelper.GetMsg(LMSG.ReadMSE));
this.Run(LanguageHelper.GetMsg(LMSG.ReadMSE));
}
}
}
......@@ -1630,9 +1949,12 @@ private void menuitem_readmse_Click(object sender, EventArgs e)
#region 压缩数据库
private void menuitem_compdb_Click(object sender, EventArgs e)
{
if (!CheckOpen())
if (!this.CheckOpen())
{
return;
DataBase.Compression(nowCdbFile);
}
DataBase.Compression(this.nowCdbFile);
MyMsg.Show(LMSG.CompDBOK);
}
#endregion
......@@ -1641,60 +1963,73 @@ private void menuitem_compdb_Click(object sender, EventArgs e)
//删除卡片的时候,是否要删除图片和脚本
private void menuitem_deletecardsfile_Click(object sender, EventArgs e)
{
menuitem_operacardsfile.Checked = !menuitem_operacardsfile.Checked;
MyConfig.Save(MyConfig.TAG_DELETE_WITH, menuitem_operacardsfile.Checked.ToString().ToLower());
this.menuitem_operacardsfile.Checked = !this.menuitem_operacardsfile.Checked;
MyConfig.Save(MyConfig.TAG_DELETE_WITH, this.menuitem_operacardsfile.Checked.ToString().ToLower());
}
//用CodeEditor打开lua
private void menuitem_openfileinthis_Click(object sender, EventArgs e)
{
menuitem_openfileinthis.Checked = !menuitem_openfileinthis.Checked;
MyConfig.Save(MyConfig.TAG_OPEN_IN_THIS, menuitem_openfileinthis.Checked.ToString().ToLower());
this.menuitem_openfileinthis.Checked = !this.menuitem_openfileinthis.Checked;
MyConfig.Save(MyConfig.TAG_OPEN_IN_THIS, this.menuitem_openfileinthis.Checked.ToString().ToLower());
}
//自动检查更新
private void menuitem_autocheckupdate_Click(object sender, EventArgs e)
{
menuitem_autocheckupdate.Checked = !menuitem_autocheckupdate.Checked;
MyConfig.Save(MyConfig.TAG_AUTO_CHECK_UPDATE, menuitem_autocheckupdate.Checked.ToString().ToLower());
this.menuitem_autocheckupdate.Checked = !this.menuitem_autocheckupdate.Checked;
MyConfig.Save(MyConfig.TAG_AUTO_CHECK_UPDATE, this.menuitem_autocheckupdate.Checked.ToString().ToLower());
}
//add require automatically
private void menuitem_addrequire_Click(object sender, EventArgs e)
{
addrequire = Microsoft.VisualBasic.Interaction.InputBox("Module script?\n\nPress \"Cancel\" to remove module script.", "", addrequire);
menuitem_addrequire.Checked = (addrequire.Length > 0);
MyConfig.Save(MyConfig.TAG_ADD_REQUIRE, addrequire);
this.Addrequire = Microsoft.VisualBasic.Interaction.InputBox("Module script?\n\nPress \"Cancel\" to remove module script.", "", this.Addrequire);
this.menuitem_addrequire.Checked = (this.Addrequire.Length > 0);
MyConfig.Save(MyConfig.TAG_ADD_REQUIRE, this.Addrequire);
}
#endregion
#region 语言菜单
void GetLanguageItem()
{
if (!Directory.Exists(datapath))
if (!Directory.Exists(this.datapath))
{
return;
menuitem_language.DropDownItems.Clear();
string[] files = Directory.GetFiles(datapath);
}
this.menuitem_language.DropDownItems.Clear();
string[] files = Directory.GetFiles(this.datapath);
foreach (string file in files)
{
string name = MyPath.getFullFileName(MyConfig.TAG_LANGUAGE, file);
if (string.IsNullOrEmpty(name))
{
continue;
}
TextInfo txinfo = new CultureInfo(CultureInfo.InstalledUICulture.Name).TextInfo;
ToolStripMenuItem tsmi = new ToolStripMenuItem(txinfo.ToTitleCase(name));
tsmi.ToolTipText = file;
tsmi.Click += SetLanguage_Click;
ToolStripMenuItem tsmi = new ToolStripMenuItem(txinfo.ToTitleCase(name))
{
ToolTipText = file
};
tsmi.Click += this.SetLanguage_Click;
if (MyConfig.readString(MyConfig.TAG_LANGUAGE).Equals(name, StringComparison.OrdinalIgnoreCase))
{
tsmi.Checked = true;
menuitem_language.DropDownItems.Add(tsmi);
}
this.menuitem_language.DropDownItems.Add(tsmi);
}
}
void SetLanguage_Click(object sender, EventArgs e)
{
if (isRun())
if (this.isRun())
{
return;
if (sender is ToolStripMenuItem)
}
if (sender is ToolStripMenuItem tsmi)
{
ToolStripMenuItem tsmi = (ToolStripMenuItem)sender;
MyConfig.Save(MyConfig.TAG_LANGUAGE, tsmi.Text);
GetLanguageItem();
this.GetLanguageItem();
MyMsg.Show(LMSG.PlzRestart);
}
}
......@@ -1703,17 +2038,20 @@ void SetLanguage_Click(object sender, EventArgs e)
//把mse存档导出为图片
void Menuitem_exportMSEimageClick(object sender, EventArgs e)
{
if (isRun())
if (this.isRun())
{
return;
}
string msepath=MyPath.GetRealPath(MyConfig.readString(MyConfig.TAG_MSE_PATH));
if(!File.Exists(msepath)){
MyMsg.Error(LMSG.exportMseImagesErr);
menuitem_exportMSEimage.Checked=false;
this.menuitem_exportMSEimage.Checked=false;
return;
}else{
if(MseMaker.MseIsRunning()){
MseMaker.MseStop();
menuitem_exportMSEimage.Checked=false;
this.menuitem_exportMSEimage.Checked=false;
return;
}else{
......@@ -1728,27 +2066,27 @@ void Menuitem_exportMSEimageClick(object sender, EventArgs e)
{
string mseset=dlg.FileName;
string exportpath=MyPath.GetRealPath(MyConfig.readString(MyConfig.TAG_MSE_EXPORT));
MseMaker.exportSet(msepath, mseset, exportpath, delegate{
menuitem_exportMSEimage.Checked=false;
MseMaker.ExportSet(msepath, mseset, exportpath, delegate{
this.menuitem_exportMSEimage.Checked=false;
});
menuitem_exportMSEimage.Checked=true;
this.menuitem_exportMSEimage.Checked=true;
}else{
menuitem_exportMSEimage.Checked=false;
this.menuitem_exportMSEimage.Checked=false;
}
}
}
void Menuitem_testPendulumTextClick(object sender, EventArgs e)
{
Card c = GetCard();
Card c = this.GetCard();
if(c != null){
tasker.testPendulumText(c.desc);
this.tasker.testPendulumText(c.desc);
}
}
void Menuitem_export_select_sqlClick(object sender, EventArgs e)
{
using(SaveFileDialog dlg = new SaveFileDialog()){
if(dlg.ShowDialog() == DialogResult.OK){
DataBase.exportSql(dlg.FileName, GetCardList(true));
DataBase.ExportSql(dlg.FileName, this.GetCardList(true));
MyMsg.Show("OK");
}
}
......@@ -1757,25 +2095,31 @@ void Menuitem_export_all_sqlClick(object sender, EventArgs e)
{
using(SaveFileDialog dlg = new SaveFileDialog()){
if(dlg.ShowDialog() == DialogResult.OK){
DataBase.exportSql(dlg.FileName, GetCardList(false));
DataBase.ExportSql(dlg.FileName, this.GetCardList(false));
MyMsg.Show("OK");
}
}
}
void Menuitem_autoreturnClick(object sender, EventArgs e)
{
if (!CheckOpen())
if (!this.CheckOpen())
{
return;
}
using (SaveFileDialog dlg = new SaveFileDialog())
{
dlg.Title = LanguageHelper.GetMsg(LMSG.SelectDataBasePath);
dlg.Filter = LanguageHelper.GetMsg(LMSG.CdbType);
if (dlg.ShowDialog() == DialogResult.OK)
{
Card[] cards = DataBase.Read(nowCdbFile, true, "");
Card[] cards = DataBase.Read(this.nowCdbFile, true, "");
int count = cards.Length;
if (cards == null || cards.Length == 0)
{
return;
}
if (DataBase.Create(dlg.FileName))
{
//
......@@ -1795,27 +2139,33 @@ void Menuitem_autoreturnClick(object sender, EventArgs e)
void Menuitem_replaceClick(object sender, EventArgs e)
{
if (!CheckOpen())
return;
using (SaveFileDialog dlg = new SaveFileDialog())
if (!this.CheckOpen())
{
return;
}
using (SaveFileDialog dlg = new SaveFileDialog())
{
dlg.Title = LanguageHelper.GetMsg(LMSG.SelectDataBasePath);
dlg.Filter = LanguageHelper.GetMsg(LMSG.CdbType);
if (dlg.ShowDialog() == DialogResult.OK)
{
Card[] cards = DataBase.Read(nowCdbFile, true, "");
Card[] cards = DataBase.Read(this.nowCdbFile, true, "");
int count = cards.Length;
if (cards == null || cards.Length == 0)
return;
if (DataBase.Create(dlg.FileName))
{
return;
}
if (DataBase.Create(dlg.FileName))
{
//
int len = MyConfig.readInteger(MyConfig.TAG_AUTO_LEN, 30);
for (int i = 0; i < count; i++)
//
_ = MyConfig.readInteger(MyConfig.TAG_AUTO_LEN, 30);
for (int i = 0; i < count; i++)
{
if (cards[i].desc != null)
{
cards[i].desc = tasker.MseHelper.ReplaceText(cards[i].desc, cards[i].name);
cards[i].desc = this.tasker.MseHelper.ReplaceText(cards[i].desc, cards[i].name);
}
}
DataBase.CopyDB(dlg.FileName, false, cards);
......@@ -1829,7 +2179,7 @@ private void text2LinkMarks(string text)
{
try{
long mark=Convert.ToInt64(text, 2);
setLinkMarks(mark, true);
this.setLinkMarks(mark, true);
}catch{
//
}
......@@ -1837,30 +2187,50 @@ private void text2LinkMarks(string text)
void Tb_linkTextChanged(object sender, EventArgs e)
{
text2LinkMarks(tb_link.Text);
this.text2LinkMarks(this.tb_link.Text);
}
private void DataEditForm_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control && e.KeyCode == Keys.F)
{
tb_cardname.Focus();
tb_cardname.SelectAll();
this.tb_cardname.Focus();
this.tb_cardname.SelectAll();
}
}
void Tb_linkKeyPress(object sender, KeyPressEventArgs e)
private void tb_cardtext_KeyDown(object sender, KeyEventArgs e)
{
if (e.Modifiers == Keys.Control && e.KeyCode == Keys.R)
{
this.Btn_resetClick(null, null);
}
else if (e.Modifiers == Keys.Control && e.KeyCode == Keys.F)
{
this.tb_cardname.Focus();
}
}
private void DataEditForm_Load(object sender, EventArgs e)
{
}
void Tb_linkKeyPress(object sender, KeyPressEventArgs e)
{
if(e.KeyChar != '0' && e.KeyChar != '1' && e.KeyChar != 1 && e.KeyChar!=22 && e.KeyChar!=3 && e.KeyChar != 8){
// MessageBox.Show("key="+(int)e.KeyChar);
e.Handled = true;
}else{
text2LinkMarks(tb_link.Text);
this.text2LinkMarks(this.tb_link.Text);
}
}
void DataEditFormSizeChanged(object sender, EventArgs e)
{
InitListRows();
this.InitListRows();
this.AddListView(this.page);
this.tmpCodes.Clear();//清空临时的结果
this.Search(true);
}
}
......
......@@ -19,19 +19,23 @@ namespace DataEditorX.Language
/// </summary>
public class LanguageHelper
{
static Dictionary<string, string> gWordsList = new Dictionary<string, string>();
static SortedList<LMSG, string> gMsgList = new SortedList<LMSG, string>();
static readonly Dictionary<string, string> gWordsList = new Dictionary<string, string>();
static readonly SortedList<LMSG, string> gMsgList = new SortedList<LMSG, string>();
const char SEP_CONTROL = '.';
const char SEP_LINE = '\t';
Dictionary<string, string> mWordslist = new Dictionary<string, string>();
readonly Dictionary<string, string> mWordslist = new Dictionary<string, string>();
#region 获取消息文字
public static string GetMsg(LMSG lMsg)
{
if (gMsgList.IndexOfKey(lMsg) >= 0)
{
return gMsgList[lMsg];
}
else
{
return lMsg.ToString().Replace("_", " ");
}
}
#endregion
......@@ -43,7 +47,9 @@ public static string GetMsg(LMSG lMsg)
public static void SetFormLabel(Form fm)
{
if (fm == null)
{
return;
}
// fm.SuspendLayout();
fm.ResumeLayout(true);
SetControlLabel(fm, "", fm.Name);
......@@ -53,8 +59,7 @@ public static void SetFormLabel(Form fm)
static bool GetLabel(string key, out string title)
{
string v;
if (gWordsList.TryGetValue(key, out v))
if (gWordsList.TryGetValue(key, out string v))
{
title = v;
return true;
......@@ -66,23 +71,26 @@ static bool GetLabel(string key, out string title)
static void SetControlLabel(Control c, string pName, string formName)
{
if (!string.IsNullOrEmpty(pName))
{
pName += SEP_CONTROL;
}
pName += c.Name;
string title;
if (c is ListView)
if (c is ListView lv)
{
ListView lv = (ListView)c;
int i, count = lv.Columns.Count;
for (i = 0; i < count; i++)
{
ColumnHeader ch = lv.Columns[i];
if (GetLabel(pName + SEP_CONTROL + i.ToString(), out title))
{
ch.Text = title;
}
}
}
else if (c is ToolStrip)
else if (c is ToolStrip ms)
{
ToolStrip ms = (ToolStrip)c;
foreach (ToolStripItem tsi in ms.Items)
{
SetMenuItem(formName + SEP_CONTROL + ms.Name, tsi);
......@@ -91,7 +99,9 @@ static void SetControlLabel(Control c, string pName, string formName)
else
{
if (GetLabel(pName, out title))
{
c.Text = title;
}
}
if (c.Controls.Count > 0)
......@@ -115,11 +125,13 @@ static void SetMenuItem(string pName, ToolStripItem tsi)
{
string title;
if (tsi is ToolStripMenuItem)
if (tsi is ToolStripMenuItem tsmi)
{
ToolStripMenuItem tsmi = (ToolStripMenuItem)tsi;
if (GetLabel(pName + SEP_CONTROL + tsmi.Name, out title))
{
tsmi.Text = title;
}
if (tsmi.HasDropDownItems)
{
foreach (ToolStripItem subtsi in tsmi.DropDownItems)
......@@ -128,11 +140,12 @@ static void SetMenuItem(string pName, ToolStripItem tsi)
}
}
}
else if (tsi is ToolStripLabel)
else if (tsi is ToolStripLabel tlbl)
{
ToolStripLabel tlbl = (ToolStripLabel)tsi;
if (GetLabel(pName + SEP_CONTROL + tlbl.Name, out title))
{
tlbl.Text = title;
}
}
}
......@@ -142,56 +155,64 @@ static void SetMenuItem(string pName, ToolStripItem tsi)
public void GetFormLabel(Form fm)
{
if (fm == null)
{
return;
}
// fm.SuspendLayout();
//fm.ResumeLayout(true);
GetControlLabel(fm, "", fm.Name);
this.GetControlLabel(fm, "", fm.Name);
//fm.ResumeLayout(false);
//fm.PerformLayout();
}
void AddLabel(string key, string title)
{
if (!mWordslist.ContainsKey(key))
mWordslist.Add(key, title);
if (!this.mWordslist.ContainsKey(key))
{
this.mWordslist.Add(key, title);
}
}
void GetControlLabel(Control c, string pName,
string formName)
{
if (!string.IsNullOrEmpty(pName))
{
pName += SEP_CONTROL;
}
if (string.IsNullOrEmpty(c.Name))
{
return;
}
pName += c.Name;
if (c is ListView)
if (c is ListView lv)
{
ListView lv = (ListView)c;
int i, count = lv.Columns.Count;
for (i = 0; i < count; i++)
{
AddLabel(pName + SEP_CONTROL + i.ToString(),
this.AddLabel(pName + SEP_CONTROL + i.ToString(),
lv.Columns[i].Text);
}
}
else if (c is ToolStrip)
else if (c is ToolStrip ms)
{
ToolStrip ms = (ToolStrip)c;
foreach (ToolStripItem tsi in ms.Items)
{
GetMenuItem(formName + SEP_CONTROL + ms.Name, tsi);
this.GetMenuItem(formName + SEP_CONTROL + ms.Name, tsi);
}
}
else
{
AddLabel(pName, c.Text);
this.AddLabel(pName, c.Text);
}
if (c.Controls.Count > 0)
{
foreach (Control sc in c.Controls)
{
GetControlLabel(sc, pName, formName);
this.GetControlLabel(sc, pName, formName);
}
}
ContextMenuStrip conms = c.ContextMenuStrip;
......@@ -199,7 +220,7 @@ void AddLabel(string key, string title)
{
foreach (ToolStripItem ts in conms.Items)
{
GetMenuItem(formName + SEP_CONTROL + conms.Text, ts);
this.GetMenuItem(formName + SEP_CONTROL + conms.Text, ts);
}
}
}
......@@ -207,23 +228,24 @@ void AddLabel(string key, string title)
void GetMenuItem(string pName, ToolStripItem tsi)
{
if (string.IsNullOrEmpty(tsi.Name))
{
return;
if (tsi is ToolStripMenuItem)
}
if (tsi is ToolStripMenuItem tsmi)
{
ToolStripMenuItem tsmi = (ToolStripMenuItem)tsi;
AddLabel(pName + SEP_CONTROL + tsmi.Name, tsmi.Text);
this.AddLabel(pName + SEP_CONTROL + tsmi.Name, tsmi.Text);
if (tsmi.HasDropDownItems)
{
foreach (ToolStripItem subtsi in tsmi.DropDownItems)
{
GetMenuItem(pName, subtsi);
this.GetMenuItem(pName, subtsi);
}
}
}
else if (tsi is ToolStripLabel)
else if (tsi is ToolStripLabel tlbl)
{
ToolStripLabel tlbl = (ToolStripLabel)tsi;
AddLabel(pName + SEP_CONTROL + tlbl.Name, tlbl.Text);
this.AddLabel(pName + SEP_CONTROL + tlbl.Name, tlbl.Text);
}
}
......@@ -235,9 +257,9 @@ public bool SaveLanguage(string conf)
using (FileStream fs = new FileStream(conf, FileMode.Create, FileAccess.Write))
{
StreamWriter sw = new StreamWriter(fs, Encoding.UTF8);
foreach (string k in mWordslist.Keys)
foreach (string k in this.mWordslist.Keys)
{
sw.WriteLine(k + SEP_LINE + mWordslist[k]);
sw.WriteLine(k + SEP_LINE + this.mWordslist[k]);
}
sw.WriteLine("#");
foreach (LMSG k in gMsgList.Keys)
......@@ -248,7 +270,9 @@ public bool SaveLanguage(string conf)
foreach (LMSG k in Enum.GetValues(typeof(LMSG)))
{
if (!gMsgList.ContainsKey(k))
{
sw.WriteLine("0x" + ((uint)k).ToString("x") + SEP_LINE + k.ToString());
}
}
sw.Close();
fs.Close();
......@@ -261,33 +285,45 @@ public bool SaveLanguage(string conf)
public static void LoadFormLabels(string f)
{
if (!File.Exists(f))
{
return;
}
gWordsList.Clear();
gMsgList.Clear();
using (FileStream fs = new FileStream(f, FileMode.Open, FileAccess.Read))
{
StreamReader sr = new StreamReader(fs, Encoding.UTF8);
string line;
uint utemp;
LMSG ltemp;
while ((line = sr.ReadLine()) != null)
{
if (line.Length == 0)
{
continue;
}
string[] words = line.Split(SEP_LINE);
if (words.Length < 2)
{
continue;
}
if (line.StartsWith("0x"))//加载消息文字
{
uint.TryParse(words[0].Replace("0x", ""), NumberStyles.HexNumber, null, out utemp);
uint.TryParse(words[0].Replace("0x", ""), NumberStyles.HexNumber, null, out uint utemp);
ltemp = (LMSG)utemp;
if (gMsgList.IndexOfKey(ltemp) < 0)//记得替换换行符
{
gMsgList.Add(ltemp, words[1].Replace("\\n", "\n"));
}
}
else if (!line.StartsWith("#"))//加载界面语言
{
if (!gWordsList.ContainsKey(words[0]))
{
gWordsList.Add(words[0], words[1]);
}
}
}
sr.Close();
......
......@@ -19,7 +19,7 @@ namespace DataEditorX.Language
/// </summary>
public static class MyMsg
{
static string info, warning, error, question;
static readonly string info, warning, error, question;
static MyMsg()
{
info = LanguageHelper.GetMsg(LMSG.titleInfo);
......@@ -47,9 +47,13 @@ public static bool Question(string strQues)
if(MessageBox.Show(strQues, question,
MessageBoxButtons.OKCancel,
MessageBoxIcon.Question)==DialogResult.OK)
{
return true;
}
else
{
return false;
}
}
public static void Show(LMSG msg)
{
......@@ -71,9 +75,13 @@ public static bool Question(LMSG msg)
if(MessageBox.Show(LanguageHelper.GetMsg(msg), question,
MessageBoxButtons.OKCancel,
MessageBoxIcon.Question)==DialogResult.OK)
{
return true;
}
else
{
return false;
}
}
}
}
......@@ -43,70 +43,73 @@ public partial class MainForm : Form, IMainForm
public MainForm()
{
//初始化控件
InitializeComponent();
this.InitializeComponent();
}
public void SetDataPath(string datapath)
{
//判断是否合法
if (string.IsNullOrEmpty(datapath))
{
return;
tCards = null;
}
this.tCards = null;
//数据目录
this.datapath = datapath;
if (MyConfig.readBoolean(MyConfig.TAG_ASYNC))
{
//后台加载数据
bgWorker1.RunWorkerAsync();
this.bgWorker1.RunWorkerAsync();
}
else
{
Init();
InitForm();
this.Init();
this.InitForm();
}
}
void CheckUpdate()
{
TaskHelper.CheckVersion(false);
}
public void setOpenFile(string file)
public void SetOpenFile(string file)
{
this.openfile = file;
}
void Init()
{
//文件路径
conflang = MyConfig.GetLanguageFile(datapath);
this.conflang = MyConfig.GetLanguageFile(this.datapath);
//游戏数据,MSE数据
datacfg = new DataConfig(MyConfig.GetCardInfoFile(datapath));
this.datacfg = new DataConfig(MyConfig.GetCardInfoFile(this.datapath));
//初始化YGOUtil的数据
YGOUtil.SetConfig(datacfg);
YGOUtil.SetConfig(this.datacfg);
//代码提示
string funtxt = MyPath.Combine(datapath, MyConfig.FILE_FUNCTION);
string conlua = MyPath.Combine(datapath, MyConfig.FILE_CONSTANT);
string confstring = MyPath.Combine(datapath, MyConfig.FILE_STRINGS);
codecfg = new CodeConfig();
string funtxt = MyPath.Combine(this.datapath, MyConfig.FILE_FUNCTION);
string conlua = MyPath.Combine(this.datapath, MyConfig.FILE_CONSTANT);
string confstring = MyPath.Combine(this.datapath, MyConfig.FILE_STRINGS);
this.codecfg = new CodeConfig();
//添加函数
codecfg.AddFunction(funtxt);
this.codecfg.AddFunction(funtxt);
//添加指示物
codecfg.AddStrings(confstring);
this.codecfg.AddStrings(confstring);
//添加常量
codecfg.AddConstant(conlua);
codecfg.SetNames(datacfg.dicSetnames);
this.codecfg.AddConstant(conlua);
this.codecfg.SetNames(this.datacfg.dicSetnames);
//生成菜单
codecfg.InitAutoMenus();
history = new History(this);
this.codecfg.InitAutoMenus();
this.history = new History(this);
//读取历史记录
history.ReadHistory(MyPath.Combine(datapath, MyConfig.FILE_HISTORY));
this.history.ReadHistory(MyPath.Combine(this.datapath, MyConfig.FILE_HISTORY));
//加载多语言
LanguageHelper.LoadFormLabels(conflang);
LanguageHelper.LoadFormLabels(this.conflang);
}
void InitForm()
{
LanguageHelper.SetFormLabel(this);
//设置所有窗口的语言
DockContentCollection contents = dockPanel1.Contents;
DockContentCollection contents = this.dockPanel1.Contents;
foreach (DockContent dc in contents)
{
if (dc is Form)
......@@ -115,13 +118,17 @@ void InitForm()
}
}
//添加历史菜单
history.MenuHistory();
this.history.MenuHistory();
//如果没有将要打开的文件,则打开一个空数据库标签
if (string.IsNullOrEmpty(openfile))
OpenDataBase(null);
if (string.IsNullOrEmpty(this.openfile))
{
this.OpenDataBase(null);
}
else
Open(openfile);
{
this.Open(this.openfile);
}
}
#endregion
......@@ -129,39 +136,38 @@ void InitForm()
//清除cdb历史
public void CdbMenuClear()
{
menuitem_history.DropDownItems.Clear();
this.menuitem_history.DropDownItems.Clear();
}
//清除lua历史
public void LuaMenuClear()
{
menuitem_shistory.DropDownItems.Clear();
this.menuitem_shistory.DropDownItems.Clear();
}
//添加cdb历史
public void AddCdbMenu(ToolStripItem item)
{
menuitem_history.DropDownItems.Add(item);
this.menuitem_history.DropDownItems.Add(item);
}
//添加lua历史
public void AddLuaMenu(ToolStripItem item)
{
menuitem_shistory.DropDownItems.Add(item);
this.menuitem_shistory.DropDownItems.Add(item);
}
#endregion
#region 处理窗口消息
protected override void DefWndProc(ref System.Windows.Forms.Message m)
{
string file = null;
switch (m.Msg)
{
case MyConfig.WM_OPEN://处理消息
file = MyPath.Combine(Application.StartupPath, MyConfig.FILE_TEMP);
string file = MyPath.Combine(Application.StartupPath, MyConfig.FILE_TEMP);
if (File.Exists(file))
{
this.Activate();
String openfile = File.ReadAllText(file);
string openfile = File.ReadAllText(file);
//获取需要打开的文件路径
Open(openfile);
this.Open(openfile);
//File.Delete(file);
}
break;
......@@ -180,26 +186,30 @@ void OpenScript(string file)
//设置界面语言
LanguageHelper.SetFormLabel(cf);
//设置cdb列表
cf.SetCDBList(history.GetcdbHistory());
cf.SetCDBList(this.history.GetcdbHistory());
//初始化函数提示
cf.InitTooltip(codecfg);
cf.InitTooltip(this.codecfg);
//打开文件
cf.Open(file);
cf.Show(dockPanel1, DockState.Document);
cf.Show(this.dockPanel1, DockState.Document);
}
//打开数据库
void OpenDataBase(string file)
{
DataEditForm def;
if (string.IsNullOrEmpty(file) || !File.Exists(file))
def = new DataEditForm(datapath);
{
def = new DataEditForm(this.datapath);
}
else
def = new DataEditForm(datapath, file);
{
def = new DataEditForm(this.datapath, file);
}
//设置语言
LanguageHelper.SetFormLabel(def);
//初始化界面数据
def.InitControl(datacfg);
def.Show(dockPanel1, DockState.Document);
def.InitControl(this.datacfg);
def.Show(this.dockPanel1, DockState.Document);
}
//打开文件
public void Open(string file)
......@@ -209,28 +219,40 @@ public void Open(string file)
return;
}
//添加历史
history.AddHistory(file);
this.history.AddHistory(file);
//检查是否已经打开
if (FindEditForm(file, true))
if (this.FindEditForm(file, true))
{
return;
}
//检查可用的
if (FindEditForm(file, false))
if (this.FindEditForm(file, false))
{
return;
if (YGOUtil.isScript(file))
OpenScript(file);
else if (YGOUtil.isDataBase(file))
OpenDataBase(file);
}
if (YGOUtil.IsScript(file))
{
this.OpenScript(file);
}
else if (YGOUtil.IsDataBase(file))
{
this.OpenDataBase(file);
}
}
//检查是否打开
bool FindEditForm(string file, bool isOpen)
{
DockContentCollection contents = dockPanel1.Contents;
DockContentCollection contents = this.dockPanel1.Contents;
//遍历所有标签
foreach (DockContent dc in contents)
{
IEditForm edform = (IEditForm)dc;
if (edform == null)
{
continue;
}
if (isOpen)//是否检查打开
{
if (file != null && file.Equals(edform.GetOpenFile()))
......@@ -257,24 +279,26 @@ bool FindEditForm(string file, bool isOpen)
//关闭当前
void CloseToolStripMenuItemClick(object sender, EventArgs e)
{
if (dockPanel1.ActiveContent.DockHandler != null)
dockPanel1.ActiveContent.DockHandler.Close();
if (this.dockPanel1.ActiveContent.DockHandler != null)
{
this.dockPanel1.ActiveContent.DockHandler.Close();
}
}
//打开脚本编辑
void Menuitem_codeeditorClick(object sender, EventArgs e)
{
OpenScript(null);
this.OpenScript(null);
}
//新建DataEditorX
void DataEditorToolStripMenuItemClick(object sender, EventArgs e)
{
OpenDataBase(null);
this.OpenDataBase(null);
}
//关闭其他或者所有
void CloseMdi(bool isall)
{
DockContentCollection contents = dockPanel1.Contents;
DockContentCollection contents = this.dockPanel1.Contents;
int num = contents.Count - 1;
try
{
......@@ -283,9 +307,13 @@ void CloseMdi(bool isall)
if (contents[num].DockHandler.DockState == DockState.Document)
{
if (isall)
{
contents[num].DockHandler.Close();
else if (dockPanel1.ActiveContent != contents[num])
}
else if (this.dockPanel1.ActiveContent != contents[num])
{
contents[num].DockHandler.Close();
}
}
num--;
}
......@@ -295,12 +323,12 @@ void CloseMdi(bool isall)
//关闭其他
void CloseOtherToolStripMenuItemClick(object sender, EventArgs e)
{
CloseMdi(false);
this.CloseMdi(false);
}
//关闭所有
void CloseAllToolStripMenuItemClick(object sender, EventArgs e)
{
CloseMdi(true);
this.CloseMdi(true);
}
#endregion
......@@ -308,7 +336,7 @@ void CloseAllToolStripMenuItemClick(object sender, EventArgs e)
//得到当前的数据编辑
DataEditForm GetActive()
{
DataEditForm df = dockPanel1.ActiveContent as DataEditForm;
DataEditForm df = this.dockPanel1.ActiveContent as DataEditForm;
return df;
}
//打开文件
......@@ -317,14 +345,19 @@ void Menuitem_openClick(object sender, EventArgs e)
using (OpenFileDialog dlg = new OpenFileDialog())
{
dlg.Title = LanguageHelper.GetMsg(LMSG.OpenFile);
if (GetActive() != null || dockPanel1.Contents.Count == 0)//判断当前窗口是不是DataEditor
if (this.GetActive() != null || this.dockPanel1.Contents.Count == 0)//判断当前窗口是不是DataEditor
{
dlg.Filter = LanguageHelper.GetMsg(LMSG.CdbType);
}
else
{
dlg.Filter = LanguageHelper.GetMsg(LMSG.ScriptFilter);
}
if (dlg.ShowDialog() == DialogResult.OK)
{
string file = dlg.FileName;
Open(file);
this.Open(file);
}
}
}
......@@ -340,27 +373,36 @@ void Menuitem_newClick(object sender, EventArgs e)
using (SaveFileDialog dlg = new SaveFileDialog())
{
dlg.Title = LanguageHelper.GetMsg(LMSG.NewFile);
if (GetActive() != null)//判断当前窗口是不是DataEditor
if (this.GetActive() != null)//判断当前窗口是不是DataEditor
{
dlg.Filter = LanguageHelper.GetMsg(LMSG.CdbType);
}
else
{
dlg.Filter = LanguageHelper.GetMsg(LMSG.ScriptFilter);
}
if (dlg.ShowDialog() == DialogResult.OK)
{
string file = dlg.FileName;
if(File.Exists(file))
{
File.Delete(file);
}
//是否是数据库
if (YGOUtil.isDataBase(file))
if (YGOUtil.IsDataBase(file))
{
if (DataBase.Create(file))//是否创建成功
{
if (MyMsg.Question(LMSG.IfOpenDataBase))//是否打开新建的数据库
Open(file);
{
this.Open(file);
}
}
}
else
{
Open(file);
this.Open(file);
}
}
}
......@@ -368,11 +410,12 @@ void Menuitem_newClick(object sender, EventArgs e)
//保存文件
void Menuitem_saveClick(object sender, EventArgs e)
{
IEditForm cf = dockPanel1.ActiveContent as IEditForm;
if (cf != null)
if (this.dockPanel1.ActiveContent is IEditForm cf)
{
if (cf.Save())//是否保存成功
{
MyMsg.Show(LMSG.SaveFileOK);
}
}
}
#endregion
......@@ -381,13 +424,13 @@ void Menuitem_saveClick(object sender, EventArgs e)
//复制选中
void Menuitem_copyselecttoClick(object sender, EventArgs e)
{
DataEditForm df = GetActive();//获取当前的数据库编辑
DataEditForm df = this.GetActive();//获取当前的数据库编辑
if (df != null)
{
tCards = df.GetCardList(true); //获取选中的卡片
if (tCards != null)
this.tCards = df.GetCardList(true); //获取选中的卡片
if (this.tCards != null)
{
SetCopyNumber(tCards.Length);//显示复制卡片的数量
this.SetCopyNumber(this.tCards.Length);//显示复制卡片的数量
MyMsg.Show(LMSG.CopyCards);
}
}
......@@ -395,13 +438,13 @@ void Menuitem_copyselecttoClick(object sender, EventArgs e)
//复制当前结果
void Menuitem_copyallClick(object sender, EventArgs e)
{
DataEditForm df = GetActive();//获取当前的数据库编辑
DataEditForm df = this.GetActive();//获取当前的数据库编辑
if (df != null)
{
tCards = df.GetCardList(false);//获取结果的所有卡片
if (tCards != null)
this.tCards = df.GetCardList(false);//获取结果的所有卡片
if (this.tCards != null)
{
SetCopyNumber(tCards.Length);//显示复制卡片的数量
this.SetCopyNumber(this.tCards.Length);//显示复制卡片的数量
MyMsg.Show(LMSG.CopyCards);
}
}
......@@ -409,22 +452,31 @@ void Menuitem_copyallClick(object sender, EventArgs e)
//显示复制卡片的数量
void SetCopyNumber(int c)
{
string tmp = menuitem_pastecards.Text;
string tmp = this.menuitem_pastecards.Text;
int t = tmp.LastIndexOf(" (");
if (t > 0)
{
tmp = tmp.Substring(0, t);
}
tmp = tmp + " (" + c.ToString() + ")";
menuitem_pastecards.Text = tmp;
this.menuitem_pastecards.Text = tmp;
}
//粘贴卡片
void Menuitem_pastecardsClick(object sender, EventArgs e)
{
if (tCards == null)
if (this.tCards == null)
{
return;
DataEditForm df = GetActive();
}
DataEditForm df = this.GetActive();
if (df == null)
{
return;
df.SaveCards(tCards);//保存卡片
}
df.SaveCards(this.tCards);//保存卡片
MyMsg.Show(LMSG.PasteCards);
}
......@@ -434,42 +486,47 @@ void Menuitem_pastecardsClick(object sender, EventArgs e)
//设置数据库1
void Menuitem_comp1Click(object sender, EventArgs e)
{
compare1 = GetActive();
if (compare1 != null && !string.IsNullOrEmpty(compare1.GetOpenFile()))
this.compare1 = this.GetActive();
if (this.compare1 != null && !string.IsNullOrEmpty(this.compare1.GetOpenFile()))
{
menuitem_comp2.Enabled = true;
CompareDB();
this.menuitem_comp2.Enabled = true;
this.CompareDB();
}
}
//设置数据库2
void Menuitem_comp2Click(object sender, EventArgs e)
{
compare2 = GetActive();
if (compare2 != null && !string.IsNullOrEmpty(compare2.GetOpenFile()))
this.compare2 = this.GetActive();
if (this.compare2 != null && !string.IsNullOrEmpty(this.compare2.GetOpenFile()))
{
CompareDB();
this.CompareDB();
}
}
//对比数据库
void CompareDB()
{
if (compare1 == null || compare2 == null)
if (this.compare1 == null || this.compare2 == null)
{
return;
string cdb1 = compare1.GetOpenFile();
string cdb2 = compare2.GetOpenFile();
}
string cdb1 = this.compare1.GetOpenFile();
string cdb2 = this.compare2.GetOpenFile();
if (string.IsNullOrEmpty(cdb1)
|| string.IsNullOrEmpty(cdb2)
|| cdb1 == cdb2)
{
return;
}
bool checktext = MyMsg.Question(LMSG.CheckText);
//分别对比数据库
compare1.CompareCards(cdb2, checktext);
compare2.CompareCards(cdb1, checktext);
this.compare1.CompareCards(cdb2, checktext);
this.compare2.CompareCards(cdb1, checktext);
MyMsg.Show(LMSG.CompareOK);
menuitem_comp2.Enabled = false;
compare1 = null;
compare2 = null;
this.menuitem_comp2.Enabled = false;
this.compare1 = null;
this.compare2 = null;
}
#endregion
......@@ -477,14 +534,14 @@ void CompareDB()
#region 后台加载数据
private void bgWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
Init();
this.Init();
}
private void bgWorker1_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
{
//更新UI
InitForm();
this.InitForm();
}
#endregion
......@@ -492,10 +549,15 @@ private void MainForm_Load(object sender, EventArgs e)
{
//检查更新
if (!MyConfig.readBoolean(MyConfig.TAG_AUTO_CHECK_UPDATE))
return;
Thread th = new Thread(CheckUpdate);
th.IsBackground = true;//如果exe结束,则线程终止
th.Start();
{
return;
}
Thread th = new Thread(this.CheckUpdate)
{
IsBackground = true//如果exe结束,则线程终止
};
th.Start();
}
}
}
......@@ -31,14 +31,16 @@ private static void Main(string[] args)
Environment.Exit(1);
}
if (MyConfig.OpenOnExistForm(arg))//在已经存在的窗口打开文件
{
Environment.Exit(1);
}
else//新建窗口
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
MainForm mainForm = new MainForm();
//设置将要打开的文件
mainForm.setOpenFile(arg);
mainForm.SetOpenFile(arg);
//数据目录
mainForm.SetDataPath(MyPath.Combine(Application.StartupPath, MyConfig.TAG_DATA));
......
★更新历史
2.4.3.7
增加了一些自动完成
2.4.3.6
UI位置调整
2.4.3.5
......
......@@ -48,7 +48,7 @@
!system 94 是否现在使用这张卡的效果?
!system 95 是否使用[%ls]的效果?
!system 96 是否使用[%ls]的效果代替破坏?
!system 97 是否把[%ls]在魔法与陷阱区域放置
!system 97 是否把[%ls]在魔法与陷阱区域盖放
!system 98 是否要解放对方怪兽?
!system 100 先攻
!system 101 后攻
......@@ -68,6 +68,15 @@
!system 213 已选择种族:
!system 214 已选择属性:
!system 215 已选择数字:
!system 216 在连锁%d发动
!system 217 被连锁%d的[%ls]选择为对象
!system 218 是否使用[%ls]的效果代替支付基本分?
!system 219 是否使用[%ls]的效果代替取除超量素材?
!system 220 是否使用[%ls]的效果代替取除指示物?
!system 221 是否在[%ls]发动[%ls]的诱发效果?
!system 222 是否要发动诱发效果?
!system 223 稍后将询问其他可以发动的效果。
!system 224 已用正规方法特殊召唤
!system 500 请选择要解放的卡
!system 501 请选择要丢弃的手卡
!system 502 请选择要破坏的卡
......@@ -95,13 +104,14 @@
!system 524 请选择里侧攻击表示的怪兽
!system 525 请选择里侧守备表示的怪兽
!system 526 请选择给对方确认的卡
!system 527 请选择要放置到场上的卡
!system 527 请选择要盖放到场上的卡
!system 528 请选择要改变表示形式的怪兽
!system 529 请选择自己的卡
!system 530 请选择对方的卡
!system 531 请选择上级召唤用需要解放的怪兽
!system 532 请选择要取除超量素材的怪兽
!system 533 请选择连接召唤的素材
!system 534 请选择要保留在场上的卡
!system 549 请选择攻击的对象
!system 550 请选择要发动的效果
!system 551 请选择效果的对象
......@@ -229,17 +239,23 @@
!system 1150 发动
!system 1151 召唤
!system 1152 特殊召唤
!system 1153 放置
!system 1153 盖放
!system 1154 反转召唤
!system 1155 守备表示
!system 1156 攻击表示
!system 1157 攻击
!system 1158 查看列表
!system 1159 当魔法卡放置
!system 1159 当魔法卡盖放
!system 1160 在灵摆区域发动
!system 1161 效果处理
!system 1162 效果重置
!system 1163 灵摆召唤
!system 1164 同调召唤
!system 1165 超量召唤
!system 1166 连接召唤
!system 1190 加入手卡
!system 1191 送去墓地
!system 1192 除外
#menu
!system 1200 联机模式
!system 1201 单人模式
......@@ -305,7 +321,7 @@
!system 1279 开启音效
!system 1280 开启音乐
!system 1281 按场景切换音乐
!system 1290 忽略对方发言
!system 1290 禁用聊天功能
!system 1291 忽略观战者发言
!system 1292 忽略时点
!system 1293 显示时点
......@@ -314,6 +330,7 @@
!system 1296 完成选择
!system 1297 切洗手卡
!system 1298 辅助功能
!system 1299 加快动画效果
!system 1300 禁限卡表:
!system 1301 卡组列表:
!system 1302 保存
......@@ -366,8 +383,6 @@
!system 1351 投降
!system 1352 主要信息:
!system 1353 播放起始于回合:
!system 1354 不显示卡片系列
!system 1355 不显示提示按钮
!system 1356 是否要放弃对卡组的修改?
!system 1357 不提示保留对卡组的修改
!system 1358 键入关键字后自动进行搜索
......@@ -377,11 +392,15 @@
!system 1363 是否删除这个录像?
!system 1364 重命名录像
!system 1365 重命名失败,可能存在同名文件
!system 1366 自动保存录像
!system 1367 录像已自动保存为%ls.yrp
!system 1370 星数↑
!system 1371 攻击↑
!system 1372 守备↑
!system 1373 名称↓
!system 1374 连接标记
!system 1378 使用多个关键词搜索卡片
!system 1379 启用扩展卡包调试模式
!system 1380 人机模式
!system 1381 残局模式
!system 1382 人机信息:
......@@ -412,6 +431,7 @@
!system 1418 额外卡组数量应不超过15张,当前卡组数量为%d张。
!system 1419 副卡组数量应不超过15张,当前卡组数量为%d张。
!system 1420 有额外卡组卡片存在于主卡组,可能是额外卡组数量超过15张。
!system 1421 宣言的卡不符合条件,或无法被主机识别。
!system 1500 决斗结束。
!system 1501 录像结束。
!system 1502 连接已断开。
......@@ -419,7 +439,7 @@
!system 1511 对方宣言了:[%ls]
!system 1512 对方选择了:[%d]
!system 1600 卡片改变了表示形式
!system 1601 放置了卡片
!system 1601 盖放了卡片
!system 1602 卡的控制权改变了
!system 1603 [%ls]召唤中
!system 1604 怪兽召唤成功
......@@ -464,6 +484,9 @@
!victory 0x1a 「魂之接力」效果胜利
!victory 0x1b 「鬼计惰天使」效果胜利
!victory 0x1c 「幻煌龙的天涡」效果胜利
!victory 0x1d 「方程式运动员胜利团队」效果胜利
!victory 0x1e 「飞行象」效果胜利
!victory 0x1f 「守护神 艾克佐迪亚」效果胜利
!victory 0x20 由于「%ls」的效果获得比赛胜利
#counters
!counter 0x1 魔力指示物
......@@ -531,6 +554,14 @@
!counter 0x1045 鳞粉指示物
!counter 0x46 指示物(刚鬼死斗)
!counter 0x47 指示物(限制代码)
!counter 0x48 指示物(连接死亡炮塔)
!counter 0x1049 警逻指示物
!counter 0x4a 运动员指示物
!counter 0x4b 枪管指示物
!counter 0x4c 召唤指示物
!counter 0x104d 信号指示物
!counter 0x4e 指示物(魂之灵摆)
!counter 0x104f 蛊指示物
#setnames, using tab for comment
!setname 0x1 正义盟军 AOJ
!setname 0x2 次世代 ジェネクス
......@@ -714,7 +745,7 @@
!setname 0x82 怒怒怒 ドドド
!setname 0x83 机关傀儡 ギミック・パペット
!setname 0x84 燃烧拳击手 BK(バーニングナックラー)
!setname 0x85 超级防机器人 SDロボ
!setname 0x85 超级防机器人 SDロボ
!setname 0x86 光天使
!setname 0x87 阴影 アンブラル
!setname 0x88 武神
......@@ -725,7 +756,7 @@
#setname 0x8c 德鲁伊 ドルイド
!setname 0x8d 鬼计 ゴーストリック
!setname 0x8e 吸血鬼 ヴァンパイア
!setname 0x8f啦啦 ズババ
!setname 0x8f拉拉 ズババ
!setname 0x90 森罗 森羅
!setname 0x91 王家长眠之谷 ネクロバレー
!setname 0x92 纹章 メダリオン
......@@ -792,6 +823,7 @@
!setname 0xbf 灵使 霊使い
!setname 0xc0 凭依装着 憑依装着
!setname 0xc1 PSY骨架 PSYフレーム
!setname 0x10c1 PSY骨架装备 PSYフレームギア
!setname 0xc2 动力工具 パワー・ツール
!setname 0xc3 锋利小鬼 エッジインプ
!setname 0xc4 神数 セフィラ
......@@ -814,9 +846,10 @@
!setname 0xd4 伯吉斯异兽 バージェストマ
!setname 0xd5 但丁 ダンテ
!setname 0xd6 破坏剑 破壊剣
!setname 0xd7 巴斯达·布雷达 バスター・ブレイダー
!setname 0xd7 破坏之剑士 バスター・ブレイダー
!setname 0xd8 雾动机龙 ダイナミスト
!setname 0xd9 不知火
!setname 0x10d9 妖刀-不知火 妖刀-不知火
!setname 0xda 龙魔王 竜魔王
!setname 0xdb 幻影 ファントム
!setname 0x10db 幻影骑士团 幻影騎士団
......@@ -891,3 +924,23 @@
!setname 0x114 空牙团 空牙団
!setname 0x115 闪刀 閃刀
!setname 0x1115 闪刀姬 閃刀姫
!setname 0x116 圣像骑士 パラディオン
!setname 0x117 魔神仪 魔神儀
!setname 0x118 电脑网 サイバネット
!setname 0x119 转生炎兽 サラマングレイト
!setname 0x11a 恐龙摔跤手 ダイナレスラー
!setname 0x11b 自奏圣乐 オルフェゴール
!setname 0x11c 雷龙 サンダー·ドラゴン
!setname 0x11d 禁忌的 禁じられた
!setname 0x11e 危险! Danger!
!setname 0x11f 奈芙提斯 ネフティス
!setname 0x120 调皮宝贝 プランキッズ
!setname 0x121 魔妖
!setname 0x122 女武神 Valkyrie
!setname 0x123 蔷薇龙 ローズ・ドラゴン
!setname 0x124 机械天使 機械天使
!setname 0x125 笑容 スマイル
!setname 0x126 时间怪盗 Time Thief
!setname 0x127 无限起动 無限起動
!setname 0x128 魔女术 ウィッチクラフト
!setname 0x129 咒眼 呪眼
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