Commit bc0829bf authored by JoyJ's avatar JoyJ

code format

parent c95bd343
This diff is collapsed.
...@@ -8,10 +8,10 @@ public class Area ...@@ -8,10 +8,10 @@ public class Area
{ {
public Area() public Area()
{ {
left = 0; this.left = 0;
top = 0; this.top = 0;
width = 0; this.width = 0;
height = 0; this.height = 0;
} }
/// <summary> /// <summary>
/// 左 /// 左
......
...@@ -78,21 +78,23 @@ public static bool CheckVersion(string ver, string oldver) ...@@ -78,21 +78,23 @@ public static bool CheckVersion(string ver, string oldver)
string[] oldvers = oldver.Split('.'); string[] oldvers = oldver.Split('.');
if (vers.Length == oldvers.Length) if (vers.Length == oldvers.Length)
{ {
int j, k;//从左到右比较数字 //从左到右比较数字
for (int i = 0; i < oldvers.Length; i++) for (int i = 0; i < oldvers.Length; i++)
{ {
int.TryParse(vers[i], out j); int.TryParse(vers[i], out int j);
int.TryParse(oldvers[i], out k); int.TryParse(oldvers[i], out int k);
if (j > k)//新的版本号大于旧的 if (j > k)//新的版本号大于旧的
{ {
hasNew = true; hasNew = true;
break; break;
}else if(j < k){ }
hasNew = false; else if (j < k)
break; {
} hasNew = false;
} break;
} }
}
}
return hasNew; return hasNew;
} }
#endregion #endregion
...@@ -147,8 +149,11 @@ public static bool DownLoad(string filename) ...@@ -147,8 +149,11 @@ public static bool DownLoad(string filename)
try try
{ {
if (File.Exists(filename)) 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(); HttpWebResponse myrp = (HttpWebResponse)Myrq.GetResponse();
long totalBytes = myrp.ContentLength; long totalBytes = myrp.ContentLength;
......
...@@ -20,7 +20,10 @@ public static string getValue(string line) ...@@ -20,7 +20,10 @@ public static string getValue(string line)
{ {
int t = line.IndexOf('='); int t = line.IndexOf('=');
if (t > 0) if (t > 0)
{
return line.Substring(t + 1).Trim(); return line.Substring(t + 1).Trim();
}
return ""; return "";
} }
/// <summary> /// <summary>
...@@ -32,7 +35,10 @@ public static string getValue1(string word) ...@@ -32,7 +35,10 @@ public static string getValue1(string word)
{ {
int i = word.IndexOf(SEP_LINE); int i = word.IndexOf(SEP_LINE);
if (i > 0) if (i > 0)
{
return word.Substring(0, i); return word.Substring(0, i);
}
return word; return word;
} }
/// <summary> /// <summary>
...@@ -44,7 +50,10 @@ public static string getValue2(string word) ...@@ -44,7 +50,10 @@ public static string getValue2(string word)
{ {
int i = word.IndexOf(SEP_LINE); int i = word.IndexOf(SEP_LINE);
if (i > 0) if (i > 0)
{
return word.Substring(i + SEP_LINE.Length); return word.Substring(i + SEP_LINE.Length);
}
return ""; return "";
} }
/// <summary> /// <summary>
...@@ -78,9 +87,13 @@ public static string getRegex(string word) ...@@ -78,9 +87,13 @@ public static string getRegex(string word)
public static bool getBooleanValue(string line) public static bool getBooleanValue(string line)
{ {
if (getValue(line).ToLower() == "true") if (getValue(line).ToLower() == "true")
{
return true; return true;
}
else else
{
return false; return false;
}
} }
/// <summary> /// <summary>
/// 获取int值 /// 获取int值
...@@ -113,10 +126,11 @@ public static void DicAdd(SortedList<long, string> dic, string line) ...@@ -113,10 +126,11 @@ public static void DicAdd(SortedList<long, string> dic, string line)
{ {
string strkey = line.Substring(i + 2, j - i - 1); string strkey = line.Substring(i + 2, j - i - 1);
string strval = line.Substring(j + 1); string strval = line.Substring(j + 1);
long key; long.TryParse(strkey, NumberStyles.HexNumber, null, out long key);
long.TryParse(strkey, NumberStyles.HexNumber, null, out key);
if (!dic.ContainsKey(key)) if (!dic.ContainsKey(key))
{
dic.Add(key, strval.Trim()); dic.Add(key, strval.Trim());
}
} }
} }
} }
......
...@@ -17,7 +17,10 @@ public static class MyBitmap ...@@ -17,7 +17,10 @@ public static class MyBitmap
public static Bitmap readImage(string file) public static Bitmap readImage(string file)
{ {
if (!File.Exists(file)) if (!File.Exists(file))
{
return null; return null;
}
MemoryStream ms = new MemoryStream(File.ReadAllBytes(file)); MemoryStream ms = new MemoryStream(File.ReadAllBytes(file));
return (Bitmap)Image.FromStream(ms); return (Bitmap)Image.FromStream(ms);
} }
...@@ -124,9 +127,15 @@ public static bool SaveAsJPEG(Bitmap bitmap, string filename, int quality=90) ...@@ -124,9 +127,15 @@ public static bool SaveAsJPEG(Bitmap bitmap, string filename, int quality=90)
{ {
string path=Path.GetDirectoryName(filename); string path=Path.GetDirectoryName(filename);
if(!Directory.Exists(path))//创建文件夹 if(!Directory.Exists(path))//创建文件夹
Directory.CreateDirectory(path); {
if(File.Exists(filename))//删除旧文件 Directory.CreateDirectory(path);
File.Delete(filename); }
if (File.Exists(filename))//删除旧文件
{
File.Delete(filename);
}
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders(); ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
ImageCodecInfo ici = null; ImageCodecInfo ici = null;
foreach ( ImageCodecInfo codec in codecs ) foreach ( ImageCodecInfo codec in codecs )
...@@ -138,7 +147,10 @@ public static bool SaveAsJPEG(Bitmap bitmap, string filename, int quality=90) ...@@ -138,7 +147,10 @@ public static bool SaveAsJPEG(Bitmap bitmap, string filename, int quality=90)
} }
} }
if (quality < 0 || quality > 100) if (quality < 0 || quality > 100)
{
quality = 60; quality = 60;
}
EncoderParameters encoderParams = new EncoderParameters(); EncoderParameters encoderParams = new EncoderParameters();
encoderParams.Param[0] = new EncoderParameter(Encoder.Quality, (long)quality); encoderParams.Param[0] = new EncoderParameter(Encoder.Quality, (long)quality);
if (ici != null) if (ici != null)
......
...@@ -52,7 +52,7 @@ public static string Combine(params string[] paths) ...@@ -52,7 +52,7 @@ public static string Combine(params string[] paths)
} }
if (!firstPath.EndsWith(spliter)) if (!firstPath.EndsWith(spliter))
{ {
firstPath = firstPath + spliter; firstPath += spliter;
} }
builder.Append(firstPath); builder.Append(firstPath);
for (int i = 1; i < paths.Length; i++) for (int i = 1; i < paths.Length; i++)
...@@ -70,7 +70,7 @@ public static string Combine(params string[] paths) ...@@ -70,7 +70,7 @@ public static string Combine(params string[] paths)
} }
else else
{ {
nextPath = nextPath + spliter; nextPath += spliter;
} }
} }
builder.Append(nextPath); builder.Append(nextPath);
...@@ -96,7 +96,10 @@ public static string CheckDir(string dir,string defalut) ...@@ -96,7 +96,10 @@ public static string CheckDir(string dir,string defalut)
fo = new DirectoryInfo(defalut); fo = new DirectoryInfo(defalut);
} }
if (!fo.Exists) if (!fo.Exists)
{
fo.Create(); fo.Create();
}
dir = fo.FullName; dir = fo.FullName;
return dir; return dir;
} }
...@@ -121,21 +124,29 @@ public static string getFullFileName(string tag, string file) ...@@ -121,21 +124,29 @@ public static string getFullFileName(string tag, string file)
{ {
string name = Path.GetFileNameWithoutExtension(file); string name = Path.GetFileNameWithoutExtension(file);
if (!name.StartsWith(tag + "_")) if (!name.StartsWith(tag + "_"))
{
return ""; return "";
}
else else
{
return name.Replace(tag + "_", ""); return name.Replace(tag + "_", "");
}
} }
public static void CreateDir(string dir) public static void CreateDir(string dir)
{ {
if (!Directory.Exists(dir)) if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir); Directory.CreateDirectory(dir);
}
} }
public static void CreateDirByFile(string file) public static void CreateDirByFile(string file)
{ {
string dir = Path.GetDirectoryName(file); string dir = Path.GetDirectoryName(file);
if (!Directory.Exists(dir)) if (!Directory.Exists(dir))
{
Directory.CreateDirectory(dir); Directory.CreateDirectory(dir);
}
} }
} }
} }
...@@ -32,9 +32,11 @@ public new void Add(K key, V value) ...@@ -32,9 +32,11 @@ public new void Add(K key, V value)
} }
} }
if (flag == 1) if (flag == 1)
return; //跳出函数 {
//否则就加入 return; //跳出函数
base.Add(key, value); }
//否则就加入
base.Add(key, value);
} }
} }
} }
...@@ -9,22 +9,30 @@ public class StrUtil ...@@ -9,22 +9,30 @@ public class StrUtil
public static string AutoEnter(string str, int lineNum, char re) public static string AutoEnter(string str, int lineNum, char re)
{ {
if (str == null || str.Length == 0) if (str == null || str.Length == 0)
return ""; {
str = " "+str.Replace("\r\n", "\n"); return "";
}
str = " "+str.Replace("\r\n", "\n");
char[] ch = str.ToCharArray(); char[] ch = str.ToCharArray();
int count = ch.Length; _ = ch.Length;
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
int i = 0; int i = 0;
foreach (char c in ch) foreach (char c in ch)
{ {
int ic = c; int ic = c;
if (ic > 128) if (ic > 128)
i += 2; {
else i += 2;
i += 1; }
if (c == '\n' || c == '\r') else
{
i += 1;
}
if (c == '\n' || c == '\r')
{ {
sb.Append(re); sb.Append(re);
i = 0; i = 0;
......
...@@ -25,7 +25,9 @@ public static void Save(string appKey, string appValue) ...@@ -25,7 +25,9 @@ public static void Save(string appKey, string appValue)
XmlElement xElem = (XmlElement)xNode.SelectSingleNode("//add[@key='" + appKey + "']"); XmlElement xElem = (XmlElement)xNode.SelectSingleNode("//add[@key='" + appKey + "']");
if (xElem != null) //存在,则更新 if (xElem != null) //存在,则更新
{
xElem.SetAttribute("value", appValue); xElem.SetAttribute("value", appValue);
}
else//不存在,则插入 else//不存在,则插入
{ {
XmlElement xNewElem = xDoc.CreateElement("add"); XmlElement xNewElem = xDoc.CreateElement("add");
......
This diff is collapsed.
...@@ -15,29 +15,29 @@ public class CodeConfig ...@@ -15,29 +15,29 @@ public class CodeConfig
#region 成员 #region 成员
public CodeConfig() public CodeConfig()
{ {
tooltipDic = new SortedList<string, string>(); this.tooltipDic = new SortedList<string, string>();
longTooltipDic = new SortedList<string, string>(); this.longTooltipDic = new SortedList<string, string>();
items = new List<AutocompleteItem>(); this.items = new List<AutocompleteItem>();
} }
//函数提示 //函数提示
SortedList<string, string> tooltipDic; readonly SortedList<string, string> tooltipDic;
SortedList<string, string> longTooltipDic; readonly SortedList<string, string> longTooltipDic;
List<AutocompleteItem> items; readonly List<AutocompleteItem> items;
/// <summary> /// <summary>
/// 输入提示 /// 输入提示
/// </summary> /// </summary>
public SortedList<string, string> TooltipDic public SortedList<string, string> TooltipDic
{ {
get { return tooltipDic; } get { return this.tooltipDic; }
} }
public SortedList<string, string> LongTooltipDic public SortedList<string, string> LongTooltipDic
{ {
get { return longTooltipDic; } get { return this.longTooltipDic; }
} }
public AutocompleteItem[] Items public AutocompleteItem[] Items
{ {
get { return items.ToArray(); } get { return this.items.ToArray(); }
} }
#endregion #endregion
...@@ -51,9 +51,9 @@ public void SetNames(Dictionary<long, string> dic) ...@@ -51,9 +51,9 @@ public void SetNames(Dictionary<long, string> dic)
foreach (long k in dic.Keys) foreach (long k in dic.Keys)
{ {
string key = "0x" + k.ToString("x"); 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) ...@@ -75,7 +75,7 @@ public void AddStrings(string file)
string[] ws = line.Split(' '); string[] ws = line.Split(' ');
if (ws.Length > 2) if (ws.Length > 2)
{ {
AddToolIipDic(ws[1], ws[2]); this.AddToolIipDic(ws[1], ws[2]);
} }
} }
} }
...@@ -88,7 +88,10 @@ public void AddStrings(string file) ...@@ -88,7 +88,10 @@ public void AddStrings(string file)
public void AddFunction(string funtxt) public void AddFunction(string funtxt)
{ {
if (!File.Exists(funtxt)) if (!File.Exists(funtxt))
{
return; return;
}
string[] lines = File.ReadAllLines(funtxt); string[] lines = File.ReadAllLines(funtxt);
bool isFind = false; bool isFind = false;
string name = ""; string name = "";
...@@ -98,11 +101,14 @@ public void AddFunction(string funtxt) ...@@ -98,11 +101,14 @@ public void AddFunction(string funtxt)
if (string.IsNullOrEmpty(line) if (string.IsNullOrEmpty(line)
|| line.StartsWith("==") || line.StartsWith("==")
|| line.StartsWith("#")) || line.StartsWith("#"))
{
continue; continue;
}
if (line.StartsWith("●")) if (line.StartsWith("●"))
{ {
//add //add
AddToolIipDic(name, desc); this.AddToolIipDic(name, desc);
int w = line.IndexOf("("); int w = line.IndexOf("(");
int t = line.IndexOf(" "); int t = line.IndexOf(" ");
...@@ -119,7 +125,7 @@ public void AddFunction(string funtxt) ...@@ -119,7 +125,7 @@ public void AddFunction(string funtxt)
desc += Environment.NewLine + line; desc += Environment.NewLine + line;
} }
} }
AddToolIipDic(name, desc); this.AddToolIipDic(name, desc);
} }
#endregion #endregion
...@@ -128,21 +134,26 @@ public void AddConstant(string conlua) ...@@ -128,21 +134,26 @@ public void AddConstant(string conlua)
{ {
//conList.Add("con"); //conList.Add("con");
if (!File.Exists(conlua)) if (!File.Exists(conlua))
{
return; return;
}
string[] lines = File.ReadAllLines(conlua); string[] lines = File.ReadAllLines(conlua);
foreach (string line in lines) foreach (string line in lines)
{ {
if (line.StartsWith("--")) if (line.StartsWith("--"))
{
continue; continue;
string k = line, desc = line; }
int t = line.IndexOf("="); int t = line.IndexOf("=");
int t2 = line.IndexOf("--"); _ = line.IndexOf("--");
//常量 = 0x1 ---注释 //常量 = 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; : line;
desc = (t > 0) ? line.Substring(t + 1).Replace("--", "\n") string desc = (t > 0) ? line.Substring(t + 1).Replace("--", "\n")
: line; : line;
AddToolIipDic(k, desc); this.AddToolIipDic(k, desc);
} }
} }
#endregion #endregion
...@@ -150,60 +161,81 @@ public void AddConstant(string conlua) ...@@ -150,60 +161,81 @@ public void AddConstant(string conlua)
#region 处理 #region 处理
public void InitAutoMenus() public void InitAutoMenus()
{ {
items.Clear(); this.items.Clear();
foreach (string k in tooltipDic.Keys) foreach (string k in this.tooltipDic.Keys)
{ {
AutocompleteItem item = new AutocompleteItem(k); AutocompleteItem item = new AutocompleteItem(k)
item.ToolTipTitle = k; {
item.ToolTipText = tooltipDic[k]; ToolTipTitle = k,
items.Add(item); 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; continue;
AutocompleteItem item = new AutocompleteItem(k); }
item.ToolTipTitle = k;
item.ToolTipText = longTooltipDic[k]; AutocompleteItem item = new AutocompleteItem(k)
items.Add(item); {
ToolTipTitle = k,
ToolTipText = this.longTooltipDic[k]
};
this.items.Add(item);
} }
} }
string GetShortName(string name) string GetShortName(string name)
{ {
int t = name.IndexOf("."); int t = name.IndexOf(".");
if (t > 0) if (t > 0)
{
return name.Substring(t + 1); return name.Substring(t + 1);
}
else else
{
return name; return name;
}
} }
void AddToolIipDic(string key, string val) void AddToolIipDic(string key, string val)
{ {
string skey = GetShortName(key); string skey = this.GetShortName(key);
if (tooltipDic.ContainsKey(skey))//存在 if (this.tooltipDic.ContainsKey(skey))//存在
{ {
string nval = tooltipDic[skey]; string nval = this.tooltipDic[skey];
if (!nval.EndsWith(Environment.NewLine)) if (!nval.EndsWith(Environment.NewLine))
{
nval += Environment.NewLine; nval += Environment.NewLine;
}
nval += Environment.NewLine +val; nval += Environment.NewLine +val;
tooltipDic[skey] = nval; this.tooltipDic[skey] = nval;
} }
else else
tooltipDic.Add(skey, val); {
this.tooltipDic.Add(skey, val);
}
// //
AddLongToolIipDic(key, val); this.AddLongToolIipDic(key, val);
} }
void AddLongToolIipDic(string key, string 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)) if (!nval.EndsWith(Environment.NewLine))
{
nval += Environment.NewLine; nval += Environment.NewLine;
}
nval += Environment.NewLine + val; nval += Environment.NewLine + val;
longTooltipDic[key] = nval; this.longTooltipDic[key] = nval;
} }
else else
longTooltipDic.Add(key, val); {
this.longTooltipDic.Add(key, val);
}
} }
#endregion #endregion
} }
......
...@@ -18,11 +18,11 @@ public class DataConfig ...@@ -18,11 +18,11 @@ public class DataConfig
{ {
public 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) public DataConfig(string conf)
{ {
InitMember(conf); this.InitMember(conf);
} }
/// <summary> /// <summary>
/// 初始化成员 /// 初始化成员
...@@ -33,26 +33,26 @@ public void InitMember(string conf) ...@@ -33,26 +33,26 @@ public void InitMember(string conf)
//conf = MyPath.Combine(datapath, MyConfig.FILE_INFO); //conf = MyPath.Combine(datapath, MyConfig.FILE_INFO);
if(!File.Exists(conf)) if(!File.Exists(conf))
{ {
dicCardRules = new Dictionary<long, string>(); this.dicCardRules = new Dictionary<long, string>();
dicSetnames = new Dictionary<long, string>(); this.dicSetnames = new Dictionary<long, string>();
dicCardTypes = new Dictionary<long, string>(); this.dicCardTypes = new Dictionary<long, string>();
dicLinkMarkers = new Dictionary<long, string>(); this.dicLinkMarkers = new Dictionary<long, string>();
dicCardcategorys = new Dictionary<long, string>(); this.dicCardcategorys = new Dictionary<long, string>();
dicCardAttributes = new Dictionary<long, string>(); this.dicCardAttributes = new Dictionary<long, string>();
dicCardRaces = new Dictionary<long, string>(); this.dicCardRaces = new Dictionary<long, string>();
dicCardLevels = new Dictionary<long, string>(); this.dicCardLevels = new Dictionary<long, string>();
return; return;
} }
//提取内容 //提取内容
string text = File.ReadAllText(conf); string text = File.ReadAllText(conf);
dicCardRules = DataManager.Read(text, MyConfig.TAG_RULE); this.dicCardRules = DataManager.Read(text, MyConfig.TAG_RULE);
dicSetnames = DataManager.Read(text, MyConfig.TAG_SETNAME); this.dicSetnames = DataManager.Read(text, MyConfig.TAG_SETNAME);
dicCardTypes = DataManager.Read(text, MyConfig.TAG_TYPE); this.dicCardTypes = DataManager.Read(text, MyConfig.TAG_TYPE);
dicLinkMarkers = DataManager.Read(text, MyConfig.TAG_MARKER); this.dicLinkMarkers = DataManager.Read(text, MyConfig.TAG_MARKER);
dicCardcategorys = DataManager.Read(text, MyConfig.TAG_CATEGORY); this.dicCardcategorys = DataManager.Read(text, MyConfig.TAG_CATEGORY);
dicCardAttributes = DataManager.Read(text, MyConfig.TAG_ATTRIBUTE); this.dicCardAttributes = DataManager.Read(text, MyConfig.TAG_ATTRIBUTE);
dicCardRaces = DataManager.Read(text, MyConfig.TAG_RACE); this.dicCardRaces = DataManager.Read(text, MyConfig.TAG_RACE);
dicCardLevels = DataManager.Read(text, MyConfig.TAG_LEVEL); this.dicCardLevels = DataManager.Read(text, MyConfig.TAG_LEVEL);
} }
/// <summary> /// <summary>
......
...@@ -77,6 +77,8 @@ public static string subString(string content, string tag) ...@@ -77,6 +77,8 @@ public static string subString(string content, string tag)
public static Dictionary<long, string> Read(string content) public static Dictionary<long, string> Read(string content)
{ {
string text = reReturn(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')); return Read(text.Split('\n'));
} }
/// <summary> /// <summary>
...@@ -90,18 +92,31 @@ public static string subString(string content, string tag) ...@@ -90,18 +92,31 @@ public static string subString(string content, string tag)
long lkey; long lkey;
foreach (string line in lines) foreach (string line in lines)
{ {
if (line.StartsWith("#")) string l = line.Trim(); //姑且做一下Trim 190324 by JoyJ
if (l.StartsWith("#"))
{
continue; continue;
string[] words = line.Split(SEP_LINE); }
string[] words = l.Split(SEP_LINE);
if (words.Length < 2) if (words.Length < 2)
{
continue; continue;
}
if (words[0].StartsWith("0x")) if (words[0].StartsWith("0x"))
{
long.TryParse(words[0].Replace("0x", ""), NumberStyles.HexNumber, null, out lkey); long.TryParse(words[0].Replace("0x", ""), NumberStyles.HexNumber, null, out lkey);
}
else else
{
long.TryParse(words[0], out lkey); long.TryParse(words[0], out lkey);
}
// N/A 的数据不显示 // N/A 的数据不显示
if (!tempDic.ContainsKey(lkey) && words[1] != "N/A") if (!tempDic.ContainsKey(lkey) && words[1] != "N/A")
{
tempDic.Add(lkey, words[1]); tempDic.Add(lkey, words[1]);
}
} }
return tempDic; return tempDic;
} }
...@@ -136,8 +151,11 @@ public static string[] GetValues(Dictionary<long, string> dic) ...@@ -136,8 +151,11 @@ public static string[] GetValues(Dictionary<long, string> dic)
public static string GetValue(Dictionary<long, string> dic, long key) public static string GetValue(Dictionary<long, string> dic, long key)
{ {
if(dic.ContainsKey(key)) if(dic.ContainsKey(key))
return dic[key].Trim(); {
return key.ToString("x"); return dic[key].Trim();
}
return key.ToString("x");
} }
#endregion #endregion
} }
......
...@@ -18,7 +18,7 @@ namespace DataEditorX.Config ...@@ -18,7 +18,7 @@ namespace DataEditorX.Config
public class ImageSet public class ImageSet
{ {
public ImageSet(){ public ImageSet(){
Init(); this.Init();
} }
//初始化 //初始化
void Init() void Init()
......
...@@ -193,9 +193,11 @@ public static string readString(string key) ...@@ -193,9 +193,11 @@ public static string readString(string key)
/// <returns></returns> /// <returns></returns>
public static int readInteger(string key, int def) public static int readInteger(string key, int def)
{ {
int i; if (int.TryParse(readString(key), out int i))
if (int.TryParse(readString(key), out i)) {
return i; return i;
}
return def; return def;
} }
/// <summary> /// <summary>
...@@ -206,9 +208,11 @@ public static int readInteger(string key, int def) ...@@ -206,9 +208,11 @@ public static int readInteger(string key, int def)
/// <returns></returns> /// <returns></returns>
public static float readFloat(string key, float def) public static float readFloat(string key, float def)
{ {
float i; if (float.TryParse(readString(key), out float i))
if (float.TryParse(readString(key), out i)) {
return i; return i;
}
return def; return def;
} }
/// <summary> /// <summary>
...@@ -286,8 +290,11 @@ public static string GetLanguageFile(string path) ...@@ -286,8 +290,11 @@ public static string GetLanguageFile(string path)
{ {
string name = MyPath.getFullFileName(MyConfig.TAG_LANGUAGE, file); string name = MyPath.getFullFileName(MyConfig.TAG_LANGUAGE, file);
if (string.IsNullOrEmpty(name)) if (string.IsNullOrEmpty(name))
continue; {
if (syslang.Equals(name, StringComparison.OrdinalIgnoreCase)) continue;
}
if (syslang.Equals(name, StringComparison.OrdinalIgnoreCase))
{ {
Save(MyConfig.TAG_LANGUAGE, syslang); Save(MyConfig.TAG_LANGUAGE, syslang);
break; break;
......
...@@ -9,17 +9,17 @@ public class YgoPath ...@@ -9,17 +9,17 @@ public class YgoPath
{ {
public YgoPath(string gamepath) public YgoPath(string gamepath)
{ {
SetPath(gamepath); this.SetPath(gamepath);
} }
public void SetPath(string gamepath) public void SetPath(string gamepath)
{ {
this.gamepath = gamepath; this.gamepath = gamepath;
picpath = MyPath.Combine(gamepath, "pics"); this.picpath = MyPath.Combine(gamepath, "pics");
fieldpath = MyPath.Combine(picpath, "field"); this.fieldpath = MyPath.Combine(this.picpath, "field");
picpath2 = MyPath.Combine(picpath, "thumbnail"); this.picpath2 = MyPath.Combine(this.picpath, "thumbnail");
luapath = MyPath.Combine(gamepath, "script"); this.luapath = MyPath.Combine(gamepath, "script");
ydkpath = MyPath.Combine(gamepath, "deck"); this.ydkpath = MyPath.Combine(gamepath, "deck");
replaypath = MyPath.Combine(gamepath, "replay"); this.replaypath = MyPath.Combine(gamepath, "replay");
} }
/// <summary>游戏目录</summary> /// <summary>游戏目录</summary>
public string gamepath; public string gamepath;
...@@ -38,7 +38,7 @@ public void SetPath(string gamepath) ...@@ -38,7 +38,7 @@ public void SetPath(string gamepath)
public string GetImage(long id) public string GetImage(long id)
{ {
return GetImage(id.ToString()); return this.GetImage(id.ToString());
} }
//public string GetImageThum(long id) //public string GetImageThum(long id)
//{ //{
...@@ -46,20 +46,20 @@ public string GetImage(long id) ...@@ -46,20 +46,20 @@ public string GetImage(long id)
//} //}
public string GetImageField(long id) public string GetImageField(long id)
{ {
return GetImageField(id.ToString());//场地图 return this.GetImageField(id.ToString());//场地图
} }
public string GetScript(long id) public string GetScript(long id)
{ {
return GetScript(id.ToString()); return this.GetScript(id.ToString());
} }
public string GetYdk(string name) public string GetYdk(string name)
{ {
return MyPath.Combine(ydkpath, name + ".ydk"); return MyPath.Combine(this.ydkpath, name + ".ydk");
} }
//字符串id //字符串id
public string GetImage(string id) public string GetImage(string id)
{ {
return MyPath.Combine(picpath, id + ".jpg"); return MyPath.Combine(this.picpath, id + ".jpg");
} }
//public string GetImageThum(string id) //public string GetImageThum(string id)
//{ //{
...@@ -67,34 +67,34 @@ public string GetImage(string id) ...@@ -67,34 +67,34 @@ public string GetImage(string id)
//} //}
public string GetImageField(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) 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) public string GetModuleScript(string modulescript)
{ {
return MyPath.Combine(luapath, modulescript + ".lua"); return MyPath.Combine(this.luapath, modulescript + ".lua");
} }
public string[] GetCardfiles(long id) public string[] GetCardfiles(long id)
{ {
string[] files = new string[]{ string[] files = new string[]{
GetImage(id),//大图 this.GetImage(id),//大图
//GetImageThum(id),//小图 //GetImageThum(id),//小图
GetImageField(id),//场地图 this.GetImageField(id),//场地图
GetScript(id) this.GetScript(id)
}; };
return files; return files;
} }
public string[] GetCardfiles(string id) public string[] GetCardfiles(string id)
{ {
string[] files = new string[]{ string[] files = new string[]{
GetImage(id),//大图 this.GetImage(id),//大图
//GetImageThum(id),//小图 //GetImageThum(id),//小图
GetImageField(id),//场地图 this.GetImageField(id),//场地图
GetScript(id) this.GetScript(id)
}; };
return files; return files;
} }
......
...@@ -9,10 +9,10 @@ public class DFlowLayoutPanel : FlowLayoutPanel ...@@ -9,10 +9,10 @@ public class DFlowLayoutPanel : FlowLayoutPanel
{ {
public DFlowLayoutPanel() public DFlowLayoutPanel()
{ {
SetStyle(ControlStyles.OptimizedDoubleBuffer | this.SetStyle(ControlStyles.OptimizedDoubleBuffer |
ControlStyles.AllPaintingInWmPaint, ControlStyles.AllPaintingInWmPaint,
true); true);
UpdateStyles(); this.UpdateStyles();
} }
} }
} }
...@@ -9,10 +9,10 @@ public class DListBox : ListBox ...@@ -9,10 +9,10 @@ public class DListBox : ListBox
{ {
public DListBox() public DListBox()
{ {
SetStyle(ControlStyles.OptimizedDoubleBuffer | this.SetStyle(ControlStyles.OptimizedDoubleBuffer |
ControlStyles.AllPaintingInWmPaint, ControlStyles.AllPaintingInWmPaint,
true); true);
UpdateStyles(); this.UpdateStyles();
} }
} }
} }
...@@ -9,10 +9,10 @@ public class DListView : ListView ...@@ -9,10 +9,10 @@ public class DListView : ListView
{ {
public DListView() public DListView()
{ {
SetStyle(ControlStyles.OptimizedDoubleBuffer | this.SetStyle(ControlStyles.OptimizedDoubleBuffer |
ControlStyles.AllPaintingInWmPaint, ControlStyles.AllPaintingInWmPaint,
true); true);
UpdateStyles(); this.UpdateStyles();
} }
} }
} }
...@@ -20,33 +20,40 @@ public class FastColoredTextBoxEx : FastColoredTextBox ...@@ -20,33 +20,40 @@ public class FastColoredTextBoxEx : FastColoredTextBox
public FastColoredTextBoxEx() : base() public FastColoredTextBoxEx() : base()
{ {
this.SyntaxHighlighter = new MySyntaxHighlighter(); this.SyntaxHighlighter = new MySyntaxHighlighter();
this.TextChangedDelayed += FctbTextChangedDelayed; this.TextChangedDelayed += this.FctbTextChangedDelayed;
} }
public new event EventHandler<ToolTipNeededEventArgs> ToolTipNeeded; public new event EventHandler<ToolTipNeededEventArgs> ToolTipNeeded;
protected override void OnMouseMove(MouseEventArgs e) protected override void OnMouseMove(MouseEventArgs e)
{ {
base.OnMouseMove(e); base.OnMouseMove(e);
lastMouseCoord = e.Location; this.lastMouseCoord = e.Location;
} }
//函数悬停提示 //函数悬停提示
protected override void OnToolTip() protected override void OnToolTip()
{ {
if (ToolTip == null) if (this.ToolTip == null)
return; {
if (ToolTipNeeded == null) return;
return; }
if (ToolTipNeeded == null)
{
return;
}
//get place under mouse //get place under mouse
Place place = PointToPlace(lastMouseCoord); Place place = this.PointToPlace(this.lastMouseCoord);
//check distance //check distance
Point p = PlaceToPoint(place); Point p = this.PlaceToPoint(place);
if (Math.Abs(p.X - lastMouseCoord.X) > CharWidth*2 || if (Math.Abs(p.X - this.lastMouseCoord.X) > this.CharWidth *2 ||
Math.Abs(p.Y - lastMouseCoord.Y) > CharHeight*2) Math.Abs(p.Y - this.lastMouseCoord.Y) > this.CharHeight *2)
return; {
//get word under mouse return;
var r = new Range(this, place, place); }
//get word under mouse
var r = new Range(this, place, place);
string hoveredWord = r.GetFragment("[a-zA-Z0-9_]").Text; string hoveredWord = r.GetFragment("[a-zA-Z0-9_]").Text;
//event handler //event handler
var ea = new ToolTipNeededEventArgs(place, hoveredWord); var ea = new ToolTipNeededEventArgs(place, hoveredWord);
...@@ -54,11 +61,11 @@ protected override void OnToolTip() ...@@ -54,11 +61,11 @@ protected override void OnToolTip()
if (ea.ToolTipText != null) if (ea.ToolTipText != null)
{ {
//show tooltip //show tooltip
ToolTip.ToolTipTitle = ea.ToolTipTitle; this.ToolTip.ToolTipTitle = ea.ToolTipTitle;
ToolTip.ToolTipIcon = ea.ToolTipIcon; this.ToolTip.ToolTipIcon = ea.ToolTipIcon;
//ToolTip.SetToolTip(this, ea.ToolTipText); //ToolTip.SetToolTip(this, ea.ToolTipText);
ToolTip.Show(ea.ToolTipText, this, new Point(lastMouseCoord.X, lastMouseCoord.Y + CharHeight)); 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) ...@@ -75,13 +82,21 @@ void FctbTextChangedDelayed(object sender, TextChangedEventArgs e)
var line = this[i]; var line = this[i];
var spacesCount = line.StartSpacesCount; var spacesCount = line.StartSpacesCount;
if (spacesCount == line.Count) //empty line if (spacesCount == line.Count) //empty line
{
continue; continue;
}
if (currentIndent < spacesCount) if (currentIndent < spacesCount)
{
//append start folding marker //append start folding marker
this[lastNonEmptyLine].FoldingStartMarker = "m" + currentIndent; this[lastNonEmptyLine].FoldingStartMarker = "m" + currentIndent;
}
else if (currentIndent > spacesCount) else if (currentIndent > spacesCount)
{
//append end folding marker //append end folding marker
this[lastNonEmptyLine].FoldingEndMarker = "m" + spacesCount; this[lastNonEmptyLine].FoldingEndMarker = "m" + spacesCount;
}
currentIndent = spacesCount; currentIndent = spacesCount;
lastNonEmptyLine = i; lastNonEmptyLine = i;
} }
......
...@@ -11,55 +11,65 @@ namespace DataEditorX.Controls ...@@ -11,55 +11,65 @@ namespace DataEditorX.Controls
public class History public class History
{ {
IMainForm mainForm; readonly IMainForm mainForm;
string historyFile; string historyFile;
List<string> cdbhistory; readonly List<string> cdbhistory;
List<string> luahistory; readonly List<string> luahistory;
public string[] GetcdbHistory() public string[] GetcdbHistory()
{ {
return cdbhistory.ToArray(); return this.cdbhistory.ToArray();
} }
public string[] GetluaHistory() public string[] GetluaHistory()
{ {
return luahistory.ToArray(); return this.luahistory.ToArray();
} }
public History(IMainForm mainForm) public History(IMainForm mainForm)
{ {
this.mainForm = mainForm; this.mainForm = mainForm;
cdbhistory = new List<string>(); this.cdbhistory = new List<string>();
luahistory = new List<string>(); this.luahistory = new List<string>();
} }
//读取历史记录 //读取历史记录
public void ReadHistory(string historyFile) public void ReadHistory(string historyFile)
{ {
this.historyFile = historyFile; this.historyFile = historyFile;
if (!File.Exists(historyFile)) if (!File.Exists(historyFile))
{
return; return;
}
string[] lines = File.ReadAllLines(historyFile); string[] lines = File.ReadAllLines(historyFile);
AddHistorys(lines); this.AddHistorys(lines);
} }
//添加历史记录 //添加历史记录
void AddHistorys(string[] lines) void AddHistorys(string[] lines)
{ {
luahistory.Clear(); this.luahistory.Clear();
cdbhistory.Clear(); this.cdbhistory.Clear();
foreach (string line in lines) foreach (string line in lines)
{ {
if (string.IsNullOrEmpty(line) || line.StartsWith("#")) if (string.IsNullOrEmpty(line) || line.StartsWith("#"))
{
continue; continue;
}
if (File.Exists(line)) if (File.Exists(line))
{ {
if (YGOUtil.isScript(line)) if (YGOUtil.IsScript(line))
{ {
if (luahistory.Count < MyConfig.MAX_HISTORY if (this.luahistory.Count < MyConfig.MAX_HISTORY
&& luahistory.IndexOf(line) < 0) && this.luahistory.IndexOf(line) < 0)
luahistory.Add(line); {
this.luahistory.Add(line);
}
} }
else else
{ {
if (cdbhistory.Count < MyConfig.MAX_HISTORY if (this.cdbhistory.Count < MyConfig.MAX_HISTORY
&& cdbhistory.IndexOf(line) < 0) && this.cdbhistory.IndexOf(line) < 0)
cdbhistory.Add(line); {
this.cdbhistory.Add(line);
}
} }
} }
} }
...@@ -70,81 +80,89 @@ public void AddHistory(string file) ...@@ -70,81 +80,89 @@ public void AddHistory(string file)
//添加到开始 //添加到开始
tmplist.Add(file); tmplist.Add(file);
//添加旧记录 //添加旧记录
tmplist.AddRange(cdbhistory.ToArray()); tmplist.AddRange(this.cdbhistory.ToArray());
tmplist.AddRange(luahistory.ToArray()); tmplist.AddRange(this.luahistory.ToArray());
// //
AddHistorys(tmplist.ToArray()); this.AddHistorys(tmplist.ToArray());
SaveHistory(); this.SaveHistory();
MenuHistory(); this.MenuHistory();
} }
//保存历史 //保存历史
void SaveHistory() void SaveHistory()
{ {
string texts = "# database history"; string texts = "# database history";
foreach (string str in cdbhistory) foreach (string str in this.cdbhistory)
{ {
if (File.Exists(str)) if (File.Exists(str))
{
texts += Environment.NewLine + str; texts += Environment.NewLine + str;
}
} }
texts += Environment.NewLine + "# script history"; texts += Environment.NewLine + "# script history";
foreach (string str in luahistory) foreach (string str in this.luahistory)
{ {
if (File.Exists(str)) if (File.Exists(str))
{
texts += Environment.NewLine + str; texts += Environment.NewLine + str;
}
}
if(File.Exists(this.historyFile))
{
File.Delete(this.historyFile);
} }
if(File.Exists(historyFile))
File.Delete(historyFile); File.WriteAllText(this.historyFile, texts);
File.WriteAllText(historyFile, texts);
} }
//添加历史记录菜单 //添加历史记录菜单
public void MenuHistory() public void MenuHistory()
{ {
//cdb历史 //cdb历史
mainForm.CdbMenuClear(); this.mainForm.CdbMenuClear();
foreach (string str in cdbhistory) foreach (string str in this.cdbhistory)
{ {
ToolStripMenuItem tsmi = new ToolStripMenuItem(str); ToolStripMenuItem tsmi = new ToolStripMenuItem(str);
tsmi.Click += MenuHistoryItem_Click; tsmi.Click += this.MenuHistoryItem_Click;
mainForm.AddCdbMenu(tsmi); this.mainForm.AddCdbMenu(tsmi);
} }
mainForm.AddCdbMenu(new ToolStripSeparator()); this.mainForm.AddCdbMenu(new ToolStripSeparator());
ToolStripMenuItem tsmiclear = new ToolStripMenuItem(LanguageHelper.GetMsg(LMSG.ClearHistory)); ToolStripMenuItem tsmiclear = new ToolStripMenuItem(LanguageHelper.GetMsg(LMSG.ClearHistory));
tsmiclear.Click += MenuHistoryClear_Click; tsmiclear.Click += this.MenuHistoryClear_Click;
mainForm.AddCdbMenu(tsmiclear); this.mainForm.AddCdbMenu(tsmiclear);
//lua历史 //lua历史
mainForm.LuaMenuClear(); this.mainForm.LuaMenuClear();
foreach (string str in luahistory) foreach (string str in this.luahistory)
{ {
ToolStripMenuItem tsmi = new ToolStripMenuItem(str); ToolStripMenuItem tsmi = new ToolStripMenuItem(str);
tsmi.Click += MenuHistoryItem_Click; tsmi.Click += this.MenuHistoryItem_Click;
mainForm.AddLuaMenu(tsmi); this.mainForm.AddLuaMenu(tsmi);
} }
mainForm.AddLuaMenu(new ToolStripSeparator()); this.mainForm.AddLuaMenu(new ToolStripSeparator());
ToolStripMenuItem tsmiclear2 = new ToolStripMenuItem(LanguageHelper.GetMsg(LMSG.ClearHistory)); ToolStripMenuItem tsmiclear2 = new ToolStripMenuItem(LanguageHelper.GetMsg(LMSG.ClearHistory));
tsmiclear2.Click += MenuHistoryClear2_Click; tsmiclear2.Click += this.MenuHistoryClear2_Click;
mainForm.AddLuaMenu(tsmiclear2); this.mainForm.AddLuaMenu(tsmiclear2);
} }
void MenuHistoryClear2_Click(object sender, EventArgs e) void MenuHistoryClear2_Click(object sender, EventArgs e)
{ {
luahistory.Clear(); this.luahistory.Clear();
MenuHistory(); this.MenuHistory();
SaveHistory(); this.SaveHistory();
} }
void MenuHistoryClear_Click(object sender, EventArgs e) void MenuHistoryClear_Click(object sender, EventArgs e)
{ {
cdbhistory.Clear(); this.cdbhistory.Clear();
MenuHistory(); this.MenuHistory();
SaveHistory(); this.SaveHistory();
} }
void MenuHistoryItem_Click(object sender, EventArgs e) void MenuHistoryItem_Click(object sender, EventArgs e)
{ {
ToolStripMenuItem tsmi = sender as ToolStripMenuItem; if (sender is ToolStripMenuItem tsmi)
if (tsmi != null)
{ {
string file = tsmi.Text; string file = tsmi.Text;
if(File.Exists(file)) if (File.Exists(file))
mainForm.Open(file); {
this.mainForm.Open(file);
}
} }
} }
} }
......
...@@ -20,13 +20,12 @@ namespace FastColoredTextBoxNS ...@@ -20,13 +20,12 @@ namespace FastColoredTextBoxNS
/// </summary> /// </summary>
public class MySyntaxHighlighter : SyntaxHighlighter public class MySyntaxHighlighter : SyntaxHighlighter
{ {
TextStyle mBoldStyle = new TextStyle(Brushes.MediumSlateBlue, null, FontStyle.Regular); readonly TextStyle mNumberStyle = new TextStyle(Brushes.Orange, null, FontStyle.Regular);
TextStyle mNumberStyle = new TextStyle(Brushes.Orange, null, FontStyle.Regular); readonly TextStyle mStrStyle = new TextStyle(Brushes.Gold, null, FontStyle.Regular);
TextStyle mStrStyle = new TextStyle(Brushes.Gold, null, FontStyle.Regular); readonly TextStyle conStyle = new TextStyle(Brushes.YellowGreen, null, FontStyle.Regular);
TextStyle ConStyle = new TextStyle(Brushes.YellowGreen, null, FontStyle.Regular); readonly TextStyle mKeywordStyle = new TextStyle(Brushes.DeepSkyBlue, null, FontStyle.Regular);
TextStyle mKeywordStyle = new TextStyle(Brushes.DeepSkyBlue, null, FontStyle.Regular); readonly TextStyle mGrayStyle = new TextStyle(Brushes.Gray, null, FontStyle.Regular);
TextStyle mGrayStyle = new TextStyle(Brushes.Gray, null, FontStyle.Regular); readonly TextStyle mFunStyle = new TextStyle(Brushes.LightGray, null, FontStyle.Bold);
TextStyle mFunStyle = new TextStyle(Brushes.LightGray, null, FontStyle.Bold);
/// <summary> /// <summary>
...@@ -46,26 +45,28 @@ public override void LuaSyntaxHighlight(Range range) ...@@ -46,26 +45,28 @@ public override void LuaSyntaxHighlight(Range range)
= @"^\s*[\w\.]+(\s\w+)?\s*(?<range>=)\s*(?<range>.+)"; = @"^\s*[\w\.]+(\s\w+)?\s*(?<range>=)\s*(?<range>.+)";
//clear style of changed 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) if (base.LuaStringRegex == null)
base.InitLuaRegex(); {
//string highlighting base.InitLuaRegex();
range.SetStyle(mStrStyle, base.LuaStringRegex); }
//string highlighting
range.SetStyle(this.mStrStyle, base.LuaStringRegex);
//comment highlighting //comment highlighting
range.SetStyle(mGrayStyle, base.LuaCommentRegex1); range.SetStyle(this.mGrayStyle, base.LuaCommentRegex1);
range.SetStyle(mGrayStyle, base.LuaCommentRegex2); range.SetStyle(this.mGrayStyle, base.LuaCommentRegex2);
range.SetStyle(mGrayStyle, base.LuaCommentRegex3); range.SetStyle(this.mGrayStyle, base.LuaCommentRegex3);
//number highlighting //number highlighting
range.SetStyle(mNumberStyle, base.LuaNumberRegex); range.SetStyle(this.mNumberStyle, base.LuaNumberRegex);
//keyword highlighting //keyword highlighting
range.SetStyle(mKeywordStyle, base.LuaKeywordRegex); range.SetStyle(this.mKeywordStyle, base.LuaKeywordRegex);
//functions highlighting //functions highlighting
range.SetStyle(mFunStyle, base.LuaFunctionsRegex); range.SetStyle(this.mFunStyle, base.LuaFunctionsRegex);
range.SetStyle(mNumberStyle, @"\bc\d+\b"); 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]"); //range.SetStyle(mFunStyle, @"[:|\.|\s](?<range>[a-zA-Z0-9_]*?)[\(|\)|\s]");
//clear folding markers //clear folding markers
......
...@@ -38,8 +38,10 @@ public Card(long cardCode) ...@@ -38,8 +38,10 @@ public Card(long cardCode)
this.desc = ""; this.desc = "";
this.str = new string[STR_MAX]; this.str = new string[STR_MAX];
for (int i = 0; i < STR_MAX; i++) for (int i = 0; i < STR_MAX; i++)
{
this.str[i] = ""; this.str[i] = "";
} }
}
#endregion #endregion
#region 成员 #region 成员
...@@ -78,8 +80,10 @@ public string[] Str ...@@ -78,8 +80,10 @@ public string[] Str
{ {
this.str = new string[STR_MAX]; this.str = new string[STR_MAX];
for (int i = 0; i < STR_MAX; i++) for (int i = 0; i < STR_MAX; i++)
this.str[i] = ""; {
this.str[i] = "";
} }
}
return this.str; return this.str;
} }
set { this.str = value; } set { this.str = value; }
...@@ -110,12 +114,11 @@ public void SetSetCode(params string[] setcodes) ...@@ -110,12 +114,11 @@ public void SetSetCode(params string[] setcodes)
{ {
int i = 0; int i = 0;
this.setcode = 0; this.setcode = 0;
long temp;
if (setcodes != null) if (setcodes != null)
{ {
foreach (string sc in setcodes) 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); this.setcode += (temp << i);
i += 0x10; i += 0x10;
} }
...@@ -140,10 +143,14 @@ public long GetRightScale() ...@@ -140,10 +143,14 @@ public long GetRightScale()
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
if (obj is Card) if (obj is Card)
return Equals((Card)obj); // use Equals method below {
else return this.Equals((Card)obj); // use Equals method below
return false; }
} else
{
return false;
}
}
/// <summary> /// <summary>
/// 比较卡片,除脚本提示文本 /// 比较卡片,除脚本提示文本
/// </summary> /// </summary>
...@@ -153,32 +160,59 @@ public bool EqualsData(Card other) ...@@ -153,32 +160,59 @@ public bool EqualsData(Card other)
{ {
bool equalBool = true; bool equalBool = true;
if (this.id != other.id) if (this.id != other.id)
equalBool = false; {
else if (this.ot != other.ot) equalBool = false;
equalBool = false; }
else if (this.alias != other.alias) else if (this.ot != other.ot)
equalBool = false; {
else if (this.setcode != other.setcode) equalBool = false;
equalBool = false; }
else if (this.type != other.type) else if (this.alias != other.alias)
equalBool = false; {
else if (this.atk != other.atk) equalBool = false;
equalBool = false; }
else if (this.def != other.def) else if (this.setcode != other.setcode)
equalBool = false; {
else if (this.level != other.level) equalBool = false;
equalBool = false; }
else if (this.race != other.race) else if (this.type != other.type)
equalBool = false; {
else if (this.attribute != other.attribute) equalBool = false;
equalBool = false; }
else if (this.category != other.category) else if (this.atk != other.atk)
equalBool = false; {
else if (!this.name.Equals(other.name)) equalBool = false;
equalBool = false; }
else if (!this.desc.Equals(other.desc)) else if (this.def != other.def)
equalBool = false; {
return equalBool; 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> /// <summary>
/// 比较卡片是否一致? /// 比较卡片是否一致?
...@@ -187,12 +221,16 @@ public bool EqualsData(Card other) ...@@ -187,12 +221,16 @@ public bool EqualsData(Card other)
/// <returns>结果</returns> /// <returns>结果</returns>
public bool Equals(Card other) public bool Equals(Card other)
{ {
bool equalBool=EqualsData(other); bool equalBool=this.EqualsData(other);
if(!equalBool) if(!equalBool)
return false; {
else if (this.str.Length != other.str.Length) return false;
equalBool = false; }
else else if (this.str.Length != other.str.Length)
{
equalBool = false;
}
else
{ {
int l = this.str.Length; int l = this.str.Length;
for (int i = 0; i < l; i++) for (int i = 0; i < l; i++)
...@@ -213,7 +251,7 @@ public bool Equals(Card other) ...@@ -213,7 +251,7 @@ public bool Equals(Card other)
public override int GetHashCode() public override int GetHashCode()
{ {
// combine the hash codes of all members here (e.g. with XOR operator ^) // 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(); return hashCode;//member.GetHashCode();
} }
/// <summary> /// <summary>
...@@ -230,8 +268,11 @@ public override int GetHashCode() ...@@ -230,8 +268,11 @@ public override int GetHashCode()
/// <returns></returns> /// <returns></returns>
public bool IsType(CardType type){ public bool IsType(CardType type){
if((this.type & (long)type) == (long)type) if((this.type & (long)type) == (long)type)
return true; {
return false; return true;
}
return false;
} }
/// <summary> /// <summary>
/// 是否是某系列 /// 是否是某系列
...@@ -246,8 +287,11 @@ public bool IsSetCode(long sc) ...@@ -246,8 +287,11 @@ public bool IsSetCode(long sc)
while (setcode != 0) while (setcode != 0)
{ {
if ((setcode & 0xfff) == settype && (setcode & 0xf000 & setsubtype) == setsubtype) if ((setcode & 0xfff) == settype && (setcode & 0xf000 & setsubtype) == setsubtype)
{
return true; return true;
setcode = setcode >> 0x10; }
setcode >>= 0x10;
} }
return false; return false;
} }
...@@ -264,47 +308,54 @@ public bool IsSetCode(long sc) ...@@ -264,47 +308,54 @@ public bool IsSetCode(long sc)
/// <summary> /// <summary>
/// 密码字符串 /// 密码字符串
/// </summary> /// </summary>
public string idString public string IdString
{ {
get { return id.ToString("00000000"); } get { return this.id.ToString("00000000"); }
} }
/// <summary> /// <summary>
/// 字符串化 /// 字符串化
/// </summary> /// </summary>
public override string ToString() public override string ToString()
{ {
string str = ""; string str;
if (IsType(CardType.TYPE_MONSTER)){ if (this.IsType(CardType.TYPE_MONSTER)){
str = name + "[" + idString + "]\n[" str = this.name + "[" + this.IdString + "]\n["
+ YGOUtil.GetTypeString(type) + "] " + YGOUtil.GetTypeString(this.type) + "] "
+ YGOUtil.GetRace(race) + "/" + YGOUtil.GetAttributeString(attribute) + YGOUtil.GetRace(this.race) + "/" + YGOUtil.GetAttributeString(this.attribute)
+ "\n" + levelString() + " " + atk + "/" + def + "\n" + redesc(); + "\n" + this.levelString() + " " + this.atk + "/" + this.def + "\n" + this.redesc();
}else }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; return str;
} }
public string ToShortString(){ public string ToShortString(){
return this.name+" ["+idString+"]"; return this.name+" ["+ this.IdString +"]";
} }
public string ToLongString(){ public string ToLongString(){
return ToString(); return this.ToString();
} }
string levelString() string levelString()
{ {
string star = "["; string star = "[";
long i = 0, j = level & 0xff; long j = this.level & 0xff;
long i;
for (i = 0; i < j; i++) for (i = 0; i < j; i++)
{ {
if (i > 0 && (i % 4) == 0) if (i > 0 && (i % 4) == 0)
{
star += " "; star += " ";
}
star += "★"; star += "★";
} }
return star + "]"; return star + "]";
} }
string redesc() string redesc()
{ {
string str = desc.Replace(Environment.NewLine, "\n"); string str = this.desc.Replace(Environment.NewLine, "\n");
str = Regex.Replace(str, "([。|?|?])", "$1\n"); str = Regex.Replace(str, "([。|?|?])", "$1\n");
str = str.Replace("\n\n", "\n"); str = str.Replace("\n\n", "\n");
return str; return str;
......
This diff is collapsed.
...@@ -22,15 +22,15 @@ public interface ICommandManager ...@@ -22,15 +22,15 @@ public interface ICommandManager
} }
public class CommandManager : ICommandManager public class CommandManager : ICommandManager
{ {
private Stack<ICommand> undoStack = new Stack<ICommand>(); private readonly Stack<ICommand> undoStack = new Stack<ICommand>();
private Stack<ICommand> reverseStack = new Stack<ICommand>(); private readonly Stack<ICommand> reverseStack = new Stack<ICommand>();
public event StatusBool UndoStateChanged; public event StatusBool UndoStateChanged;
public CommandManager() public CommandManager()
{ {
UndoStateChanged += new StatusBool(CommandManager_UndoStateChanged); UndoStateChanged += new StatusBool(this.CommandManager_UndoStateChanged);
UndoStateChanged += new StatusBool(CommandManager_ReverseUndoStateChanged); UndoStateChanged += new StatusBool(this.CommandManager_ReverseUndoStateChanged);
} }
private void CommandManager_UndoStateChanged(bool val) private void CommandManager_UndoStateChanged(bool val)
...@@ -46,48 +46,52 @@ private void CommandManager_ReverseUndoStateChanged(bool val) ...@@ -46,48 +46,52 @@ private void CommandManager_ReverseUndoStateChanged(bool val)
#region ICommandManager 成员 #region ICommandManager 成员
public void ExcuteCommand(ICommand command, params object[] args) public void ExcuteCommand(ICommand command, params object[] args)
{ {
if(!command.Excute(args)) return; if(!command.Excute(args))
reverseStack.Clear(); {
return;
}
this.reverseStack.Clear();
if (command is IBackableCommand) if (command is IBackableCommand)
{ {
undoStack.Push((ICommand)command.Clone()); this.undoStack.Push((ICommand)command.Clone());
} }
else else
{ {
undoStack.Clear(); this.undoStack.Clear();
} }
UndoStateChanged(undoStack.Count > 0); UndoStateChanged(this.undoStack.Count > 0);
} }
public void Undo() public void Undo()
{ {
IBackableCommand command = (IBackableCommand)undoStack.Pop(); IBackableCommand command = (IBackableCommand)this.undoStack.Pop();
if (command == null) if (command == null)
{ {
return; return;
} }
command.Undo(); 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); //UndoStateChanged(reverseStack.Count > 0);
} }
public void ReverseUndo() public void ReverseUndo()
{ {
IBackableCommand command = (IBackableCommand)reverseStack.Pop(); IBackableCommand command = (IBackableCommand)this.reverseStack.Pop();
if (command == null) if (command == null)
{ {
return; return;
} }
command.Excute(); command.Excute();
undoStack.Push((ICommand)command.Clone()); this.undoStack.Push((ICommand)command.Clone());
UndoStateChanged(undoStack.Count > 0); UndoStateChanged(this.undoStack.Count > 0);
} }
#endregion #endregion
} }
......
This diff is collapsed.
...@@ -19,26 +19,26 @@ namespace DataEditorX ...@@ -19,26 +19,26 @@ namespace DataEditorX
public class LuaFunction public class LuaFunction
{ {
#region 日志log #region 日志log
static void ResetLog(string file) static void ResetLog()
{ {
File.Delete(logtxt); File.Delete(_logtxt);
} }
static void Log(string str) static void Log(string str)
{ {
File.AppendAllText(logtxt, str+Environment.NewLine); File.AppendAllText(_logtxt, str+Environment.NewLine);
} }
#endregion #endregion
#region old functions #region old functions
static string oldfun; static string _oldfun;
static string logtxt; static string _logtxt;
static string funclisttxt; static string _funclisttxt;
static SortedList<string,string> funclist=new SortedList<string,string>(); static readonly SortedList<string,string> _funclist=new SortedList<string,string>();
//读取旧函数 //读取旧函数
public static void Read(string funtxt) public static void Read(string funtxt)
{ {
funclist.Clear(); _funclist.Clear();
oldfun=funtxt; _oldfun=funtxt;
if(File.Exists(funtxt)) if(File.Exists(funtxt))
{ {
string[] lines=File.ReadAllLines(funtxt); string[] lines=File.ReadAllLines(funtxt);
...@@ -50,8 +50,11 @@ public static void Read(string funtxt) ...@@ -50,8 +50,11 @@ public static void Read(string funtxt)
if(string.IsNullOrEmpty(line) if(string.IsNullOrEmpty(line)
|| line.StartsWith("==") || line.StartsWith("==")
|| line.StartsWith("#")) || line.StartsWith("#"))
continue; {
if(line.StartsWith("●")) continue;
}
if (line.StartsWith("●"))
{ {
//添加之前的函数 //添加之前的函数
AddOldFun(name, desc); AddOldFun(name, desc);
...@@ -76,13 +79,13 @@ static void AddOldFun(string name, string desc) ...@@ -76,13 +79,13 @@ static void AddOldFun(string name, string desc)
{ {
if (!string.IsNullOrEmpty(name)) if (!string.IsNullOrEmpty(name))
{ {
if (funclist.ContainsKey(name))//存在,则添加注释 if (_funclist.ContainsKey(name))//存在,则添加注释
{ {
funclist[name] += Environment.NewLine + desc; _funclist[name] += Environment.NewLine + desc;
} }
else else
{//不存在,则添加函数 {//不存在,则添加函数
funclist.Add(name, desc); _funclist.Add(name, desc);
} }
} }
} }
...@@ -99,10 +102,10 @@ public static bool Find(string path) ...@@ -99,10 +102,10 @@ public static bool Find(string path)
string name="interpreter.cpp"; string name="interpreter.cpp";
string file=Path.Combine(path,name); string file=Path.Combine(path,name);
string file2=Path.Combine(Path.Combine(path, "ocgcore"), name); string file2=Path.Combine(Path.Combine(path, "ocgcore"), name);
logtxt=Path.Combine(path, "find_functions.log"); _logtxt=Path.Combine(path, "find_functions.log");
ResetLog(logtxt); ResetLog();
funclisttxt =Path.Combine(path, "_functions.txt"); _funclisttxt =Path.Combine(path, "_functions.txt");
File.Delete(funclisttxt); File.Delete(_funclisttxt);
if(!File.Exists(file)){//判断用户选择的目录 if(!File.Exists(file)){//判断用户选择的目录
Log("error: no find file "+file); Log("error: no find file "+file);
if(File.Exists(file2)){ if(File.Exists(file2)){
...@@ -135,16 +138,19 @@ public static bool Find(string path) ...@@ -135,16 +138,19 @@ public static bool Find(string path)
//保存 //保存
static void Save() static void Save()
{ {
if (string.IsNullOrEmpty(oldfun)) if (string.IsNullOrEmpty(_oldfun))
{
return; return;
using (FileStream fs = new FileStream(oldfun + "_sort.txt", }
using (FileStream fs = new FileStream(_oldfun + "_sort.txt",
FileMode.Create, FileMode.Create,
FileAccess.Write)) FileAccess.Write))
{ {
StreamWriter sw = new StreamWriter(fs, Encoding.UTF8); 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(); sw.Close();
} }
...@@ -171,8 +177,10 @@ static string ToTitle(string str) ...@@ -171,8 +177,10 @@ static string ToTitle(string str)
string k=ToTitle(name)+"."+m.Groups[1].Value; string k=ToTitle(name)+"."+m.Groups[1].Value;
string v=m.Groups[2].Value; string v=m.Groups[2].Value;
if(!dic.ContainsKey(k)) if(!dic.ContainsKey(k))
dic.Add(k,v); {
} dic.Add(k,v);
}
}
} }
return dic; return dic;
} }
...@@ -189,41 +197,63 @@ static string FindCode(string texts,string name) ...@@ -189,41 +197,63 @@ static string FindCode(string texts,string name)
if(mc.Success) if(mc.Success)
{ {
if(mc.Groups.Count>1) if(mc.Groups.Count>1)
return mc.Groups[0].Value {
return mc.Groups[0].Value
.Replace("\r\n","\n") .Replace("\r\n","\n")
.Replace("\r","\n") .Replace("\r","\n")
.Replace("\n",Environment.NewLine); .Replace("\n",Environment.NewLine);
} }
}
return ""; return "";
} }
#endregion #endregion
#region find return #region find return
//查找返回类型 //查找返回类型
static string FindReturn(string texts,string name) static string FindReturn(string texts)
{ {
string restr=""; string restr="";
if(texts.IndexOf("lua_pushboolean")>=0) if(texts.IndexOf("lua_pushboolean")>=0)
return "bool "; {
else return "bool ";
}
else
{ {
if(texts.IndexOf("interpreter::card2value")>=0) if(texts.IndexOf("interpreter::card2value")>=0)
restr += "Card "; {
if(texts.IndexOf("interpreter::group2value")>=0) restr += "Card ";
restr += "Group "; }
if(texts.IndexOf("interpreter::effect2value")>=0)
restr += "Effect "; if (texts.IndexOf("interpreter::group2value")>=0)
else if(texts.IndexOf("interpreter::function2value")>=0) {
restr += "function "; restr += "Group ";
}
if(texts.IndexOf("lua_pushinteger")>=0)
restr += "int "; if (texts.IndexOf("interpreter::effect2value")>=0)
if(texts.IndexOf("lua_pushstring")>=0) {
restr += "string "; 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)) 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)+" "; restr = restr.Replace(" ","|").Substring(0,restr.Length-1)+" ";
} }
return restr; return restr;
...@@ -235,13 +265,21 @@ static string FindReturn(string texts,string name) ...@@ -235,13 +265,21 @@ static string FindReturn(string texts,string name)
static string getUserType(string str) static string getUserType(string str)
{ {
if(str.IndexOf("card")>=0) if(str.IndexOf("card")>=0)
return "Card"; {
if(str.IndexOf("effect")>=0) return "Card";
return "Effect"; }
if(str.IndexOf("group")>=0)
return "Group"; if (str.IndexOf("effect")>=0)
{
return "Any"; return "Effect";
}
if (str.IndexOf("group")>=0)
{
return "Group";
}
return "Any";
} }
static void AddArgs(string texts,string regx,string arg,SortedList<int,string> dic) 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 ...@@ -256,13 +294,17 @@ static void AddArgs(string texts,string regx,string arg,SortedList<int,string> d
string v=arg; string v=arg;
int k=int.Parse(m.Groups[1].Value); int k=int.Parse(m.Groups[1].Value);
if(dic.ContainsKey(k)) if(dic.ContainsKey(k))
dic[k] = dic[k]+"|"+v; {
else dic[k] = dic[k]+"|"+v;
dic.Add(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>(); SortedList<int,string> dic=new SortedList<int, string>();
//card effect ggroup //card effect ggroup
...@@ -276,10 +318,14 @@ static string FindArgs(string texts,string name) ...@@ -276,10 +318,14 @@ static string FindArgs(string texts,string name)
v = getUserType(v); v = getUserType(v);
int k=int.Parse(m.Groups[2].Value); int k=int.Parse(m.Groups[2].Value);
if(dic.ContainsKey(k)) if(dic.ContainsKey(k))
dic[k] = dic[k]+"|"+v; {
else dic[k] = dic[k]+"|"+v;
dic.Add(k,v); }
} else
{
dic.Add(k,v);
}
}
} }
//function //function
AddArgs(texts AddArgs(texts
...@@ -298,8 +344,11 @@ static string FindArgs(string texts,string name) ...@@ -298,8 +344,11 @@ static string FindArgs(string texts,string name)
args +=dic[i]+", "; args +=dic[i]+", ";
} }
if(args.Length>1) if(args.Length>1)
args = args.Substring(0,args.Length-2); {
args += ")"; args = args.Substring(0,args.Length-2);
}
args += ")";
return args; return args;
} }
#endregion #endregion
...@@ -308,9 +357,12 @@ static string FindArgs(string texts,string name) ...@@ -308,9 +357,12 @@ static string FindArgs(string texts,string name)
//查找旧函数的描述 //查找旧函数的描述
static string FindOldDesc(string name) static string FindOldDesc(string name)
{ {
if(funclist.ContainsKey(name)) if(_funclist.ContainsKey(name))
return funclist[name]; {
return ""; return _funclist[name];
}
return "";
} }
#endregion #endregion
...@@ -337,19 +389,19 @@ public static void GetFunctions(string name,string texts,string file) ...@@ -337,19 +389,19 @@ public static void GetFunctions(string name,string texts,string file)
{ {
StreamWriter sw=new StreamWriter(fs, Encoding.UTF8); StreamWriter sw=new StreamWriter(fs, Encoding.UTF8);
sw.WriteLine("========== "+name+" =========="); sw.WriteLine("========== "+name+" ==========");
File.AppendAllText(funclisttxt, "========== " + name + " ==========" + Environment.NewLine); File.AppendAllText(_funclisttxt, "========== " + name + " ==========" + Environment.NewLine);
foreach(string k in fun.Keys) foreach(string k in fun.Keys)
{ {
string v=fun[k]; string v=fun[k];
string code=FindCode(cpps, v); string code=FindCode(cpps, v);
string txt="●"+FindReturn(code,v)+k+FindArgs(code,v) string txt="●"+FindReturn(code)+k+FindArgs(code)
+Environment.NewLine +Environment.NewLine
+FindOldDesc(k) +FindOldDesc(k)
+Environment.NewLine +Environment.NewLine
+code; +code;
sw.WriteLine(txt); sw.WriteLine(txt);
File.AppendAllText(funclisttxt,txt + Environment.NewLine); File.AppendAllText(_funclisttxt,txt + Environment.NewLine);
} }
sw.Close(); sw.Close();
} }
......
...@@ -31,8 +31,11 @@ public CardPack(long id) ...@@ -31,8 +31,11 @@ public CardPack(long id)
public string getMseRarity(){ public string getMseRarity(){
if(this.rarity==null) 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")) if(rarity.Equals("common") || rarity.Equals("short print"))
{ {
return "common"; return "common";
......
...@@ -63,76 +63,99 @@ public class MSEConfig ...@@ -63,76 +63,99 @@ public class MSEConfig
#endregion #endregion
public MSEConfig(string path) public MSEConfig(string path)
{ {
init(path); this.init(path);
} }
public void SetConfig(string config, string path) public void SetConfig(string config, string path)
{ {
if (!File.Exists(config)) if (!File.Exists(config))
return; {
regx_monster = "(\\s\\S*?)"; return;
regx_pendulum = "(\\s\\S*?)"; }
//设置文件名
configName = MyPath.getFullFileName(MSEConfig.TAG, config);
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>(); this.replaces = new SortedList<string, string>();
raceDic = new SortedList<long, string>();
this.typeDic = new SortedList<long, string>();
this.raceDic = new SortedList<long, string>();
string[] lines = File.ReadAllLines(config, Encoding.UTF8); string[] lines = File.ReadAllLines(config, Encoding.UTF8);
foreach (string line in lines) foreach (string line in lines)
{ {
if (string.IsNullOrEmpty(line) || line.StartsWith("#")) if (string.IsNullOrEmpty(line) || line.StartsWith("#"))
continue; {
if (line.StartsWith(TAG_CN2TW)) continue;
Iscn2tw = ConfHelper.getBooleanValue(line); }
else if (line.StartsWith(TAG_SPELL))
str_spell = ConfHelper.getValue(line); if (line.StartsWith(TAG_CN2TW))
else if (line.StartsWith(TAG_HEAD)) {
head = ConfHelper.getMultLineValue(line); this.Iscn2tw = ConfHelper.getBooleanValue(line);
else if (line.StartsWith(TAG_END)) }
end = ConfHelper.getMultLineValue(line); else if (line.StartsWith(TAG_SPELL))
else if (line.StartsWith(TAG_TEXT)) {
temp_text = ConfHelper.getMultLineValue(line); this.str_spell = ConfHelper.getValue(line);
else if (line.StartsWith(TAG_TRAP)) }
str_trap = ConfHelper.getValue(line); else if (line.StartsWith(TAG_HEAD))
else if (line.StartsWith(TAG_REG_PENDULUM)) {
regx_pendulum = ConfHelper.getValue(line); this.head = ConfHelper.getMultLineValue(line);
else if (line.StartsWith(TAG_REG_MONSTER)) }
regx_monster = ConfHelper.getValue(line); else if (line.StartsWith(TAG_END))
else if (line.StartsWith(TAG_MAXCOUNT)) {
maxcount = ConfHelper.getIntegerValue(line, 0); this.end = ConfHelper.getMultLineValue(line);
else if (line.StartsWith(TAG_WIDTH)){ }
width=ConfHelper.getIntegerValue(line,0); 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)){ else if (line.StartsWith(TAG_HEIGHT)){
height=ConfHelper.getIntegerValue(line,0); this.height =ConfHelper.getIntegerValue(line,0);
} }
else if (line.StartsWith(TAG_PEND_WIDTH)){ 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)){ 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)){ else if(line.StartsWith(TAG_NO_TEN)){
no10 = ConfHelper.getBooleanValue(line); this.no10 = ConfHelper.getBooleanValue(line);
}else if(line.StartsWith(TAG_NO_START_CARDS)){ }else if(line.StartsWith(TAG_NO_START_CARDS)){
string val = ConfHelper.getValue(line); string val = ConfHelper.getValue(line);
string[] cs = val.Split(','); string[] cs = val.Split(',');
noStartCards=new long[cs.Length]; this.noStartCards =new long[cs.Length];
int i=0; int i=0;
foreach(string str in cs){ foreach(string str in cs){
long l = 0; long.TryParse(str, out long l);
long.TryParse(str, out l); this.noStartCards[i++] = l;
noStartCards[i++] = l;
} }
} }
else if (line.StartsWith(TAG_IMAGE)) else if (line.StartsWith(TAG_IMAGE))
{ {
//如果路径不合法,则为后面的路径 //如果路径不合法,则为后面的路径
imagepath = MyPath.CheckDir(ConfHelper.getValue(line), MyPath.Combine(path, PATH_IMAGE)); this.imagepath = MyPath.CheckDir(ConfHelper.getValue(line), MyPath.Combine(path, PATH_IMAGE));
//图片缓存目录 //图片缓存目录
imagecache = MyPath.Combine(imagepath, "cache"); this.imagecache = MyPath.Combine(this.imagepath, "cache");
MyPath.CreateDir(imagecache); MyPath.CreateDir(this.imagecache);
} }
else if (line.StartsWith(TAG_REPALCE)) else if (line.StartsWith(TAG_REPALCE))
{//特数字替换 {//特数字替换
...@@ -140,24 +163,25 @@ public void SetConfig(string config, string path) ...@@ -140,24 +163,25 @@ public void SetConfig(string config, string path)
string p = ConfHelper.getRegex(ConfHelper.getValue1(word)); string p = ConfHelper.getRegex(ConfHelper.getValue1(word));
string r = ConfHelper.getRegex(ConfHelper.getValue2(word)); string r = ConfHelper.getRegex(ConfHelper.getValue2(word));
if (!string.IsNullOrEmpty(p)) if (!string.IsNullOrEmpty(p))
replaces.Add(p, r); {
this.replaces.Add(p, r);
} }
}
else if (line.StartsWith(TAG_RACE)) else if (line.StartsWith(TAG_RACE))
{//种族 {//种族
ConfHelper.DicAdd(raceDic, line); ConfHelper.DicAdd(this.raceDic, line);
} }
else if (line.StartsWith(TAG_TYPE)) else if (line.StartsWith(TAG_TYPE))
{//类型 {//类型
ConfHelper.DicAdd(typeDic, line); ConfHelper.DicAdd(this.typeDic, line);
}else if(line.StartsWith(TAG_REIMAGE)){ }else if(line.StartsWith(TAG_REIMAGE)){
reimage = ConfHelper.getBooleanValue(line); this.reimage = ConfHelper.getBooleanValue(line);
} }
} }
} }
public void init(string path) public void init(string path)
{ {
Iscn2tw = false; this.Iscn2tw = false;
//读取配置 //读取配置
string tmp = MyPath.Combine(path, MyPath.getFileName(MSEConfig.TAG, MyConfig.readString(MyConfig.TAG_MSE))); string tmp = MyPath.Combine(path, MyPath.getFileName(MSEConfig.TAG, MyConfig.readString(MyConfig.TAG_MSE)));
...@@ -166,9 +190,11 @@ public void init(string path) ...@@ -166,9 +190,11 @@ public void init(string path)
{ {
tmp = MyPath.Combine(path, MyPath.getFileName(MSEConfig.TAG, FILE_CONFIG_NAME)); tmp = MyPath.Combine(path, MyPath.getFileName(MSEConfig.TAG, FILE_CONFIG_NAME));
if(!File.Exists(tmp)) if(!File.Exists(tmp))
return;//如果默认的也不存在 {
} return;//如果默认的也不存在
SetConfig(tmp, path); }
}
this.SetConfig(tmp, path);
} }
/// <summary> /// <summary>
/// 是否调整图片 /// 是否调整图片
......
This diff is collapsed.
...@@ -43,7 +43,7 @@ public class CardInfo{ ...@@ -43,7 +43,7 @@ public class CardInfo{
public string copyright; public string copyright;
public override string ToString() 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);
} }
} }
......
This diff is collapsed.
...@@ -13,27 +13,33 @@ namespace DataEditorX.Core ...@@ -13,27 +13,33 @@ namespace DataEditorX.Core
{ {
static class YGOUtil static class YGOUtil
{ {
static DataConfig datacfg; static DataConfig _datacfg;
static YGOUtil() static YGOUtil()
{ {
datacfg = new DataConfig(); _datacfg = new DataConfig();
} }
public static void SetConfig(DataConfig dcfg) public static void SetConfig(DataConfig dcfg)
{ {
datacfg = dcfg; _datacfg = dcfg;
} }
#region 判断文件类型 #region 判断文件类型
public static bool isScript(string file) public static bool IsScript(string file)
{ {
if (file != null && file.EndsWith(".lua", StringComparison.OrdinalIgnoreCase)) if (file != null && file.EndsWith(".lua", StringComparison.OrdinalIgnoreCase))
{
return true; return true;
}
return false; return false;
} }
public static bool isDataBase(string file) public static bool IsDataBase(string file)
{ {
if (file != null && file.EndsWith(".cdb", StringComparison.OrdinalIgnoreCase)) if (file != null && file.EndsWith(".cdb", StringComparison.OrdinalIgnoreCase))
{
return true; return true;
}
return false; return false;
} }
#endregion #endregion
...@@ -41,13 +47,13 @@ public static bool isDataBase(string file) ...@@ -41,13 +47,13 @@ public static bool isDataBase(string file)
#region 获取属性,种族 #region 获取属性,种族
public static string GetAttributeString(int attr) public static string GetAttributeString(int attr)
{ {
return DataManager.GetValue(datacfg.dicCardAttributes, attr); return DataManager.GetValue(_datacfg.dicCardAttributes, attr);
} }
public static string GetRace(long race) public static string GetRace(long race)
{ {
return DataManager.GetValue(datacfg.dicCardRaces, race); return DataManager.GetValue(_datacfg.dicCardRaces, race);
} }
#endregion #endregion
...@@ -82,33 +88,56 @@ public static string GetCardType(Card c) ...@@ -82,33 +88,56 @@ public static string GetCardType(Card c)
str = GetType(CardType.TYPE_EFFECT); str = GetType(CardType.TYPE_EFFECT);
} }
else else
{
str = GetType(CardType.TYPE_NORMAL); str = GetType(CardType.TYPE_NORMAL);
}
str += GetType(CardType.TYPE_MONSTER); str += GetType(CardType.TYPE_MONSTER);
} }
else if (c.IsType(CardType.TYPE_SPELL)) else if (c.IsType(CardType.TYPE_SPELL))
{ {
if (c.IsType(CardType.TYPE_EQUIP)) if (c.IsType(CardType.TYPE_EQUIP))
{
str = GetType(CardType.TYPE_EQUIP); str = GetType(CardType.TYPE_EQUIP);
}
else if (c.IsType(CardType.TYPE_QUICKPLAY)) else if (c.IsType(CardType.TYPE_QUICKPLAY))
{
str = GetType(CardType.TYPE_QUICKPLAY); str = GetType(CardType.TYPE_QUICKPLAY);
}
else if (c.IsType(CardType.TYPE_FIELD)) else if (c.IsType(CardType.TYPE_FIELD))
{
str = GetType(CardType.TYPE_FIELD); str = GetType(CardType.TYPE_FIELD);
}
else if (c.IsType(CardType.TYPE_CONTINUOUS)) else if (c.IsType(CardType.TYPE_CONTINUOUS))
{
str = GetType(CardType.TYPE_CONTINUOUS); str = GetType(CardType.TYPE_CONTINUOUS);
}
else if (c.IsType(CardType.TYPE_RITUAL)) else if (c.IsType(CardType.TYPE_RITUAL))
{
str = GetType(CardType.TYPE_RITUAL); str = GetType(CardType.TYPE_RITUAL);
}
else else
{
str = GetType(CardType.TYPE_NORMAL); str = GetType(CardType.TYPE_NORMAL);
}
str += GetType(CardType.TYPE_SPELL); str += GetType(CardType.TYPE_SPELL);
} }
else if (c.IsType(CardType.TYPE_TRAP)) else if (c.IsType(CardType.TYPE_TRAP))
{ {
if (c.IsType(CardType.TYPE_CONTINUOUS)) if (c.IsType(CardType.TYPE_CONTINUOUS))
{
str = GetType(CardType.TYPE_CONTINUOUS); str = GetType(CardType.TYPE_CONTINUOUS);
}
else if (c.IsType(CardType.TYPE_COUNTER)) else if (c.IsType(CardType.TYPE_COUNTER))
{
str = GetType(CardType.TYPE_COUNTER); str = GetType(CardType.TYPE_COUNTER);
}
else else
{
str = GetType(CardType.TYPE_NORMAL); str = GetType(CardType.TYPE_NORMAL);
}
str += GetType(CardType.TYPE_TRAP); str += GetType(CardType.TYPE_TRAP);
} }
return str.Replace(" ", ""); return str.Replace(" ", "");
...@@ -116,21 +145,28 @@ public static string GetCardType(Card c) ...@@ -116,21 +145,28 @@ public static string GetCardType(Card c)
static string GetType(CardType type) 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) public static string GetTypeString(long type)
{ {
string str = ""; string str = "";
foreach (long k in datacfg.dicCardTypes.Keys) foreach (long k in _datacfg.dicCardTypes.Keys)
{ {
if ((type & k) == k) if ((type & k) == k)
{
str += GetType((CardType)k) + "|"; str += GetType((CardType)k) + "|";
}
} }
if (str.Length > 0) if (str.Length > 0)
{
str = str.Substring(0, str.Length - 1); str = str.Substring(0, str.Length - 1);
}
else else
{
str = "???"; str = "???";
}
return str; return str;
} }
#endregion #endregion
...@@ -142,10 +178,10 @@ public static string GetSetNameString(long setcode) ...@@ -142,10 +178,10 @@ public static string GetSetNameString(long setcode)
long sc2 = (setcode >> 0x10) & 0xffff; long sc2 = (setcode >> 0x10) & 0xffff;
long sc3 = (setcode >> 0x20) & 0xffff; long sc3 = (setcode >> 0x20) & 0xffff;
long sc4 = (setcode >> 0x30) & 0xffff; long sc4 = (setcode >> 0x30) & 0xffff;
string setname = DataManager.GetValue(datacfg.dicSetnames, sc1) string setname = DataManager.GetValue(_datacfg.dicSetnames, sc1)
+ " " + DataManager.GetValue(datacfg.dicSetnames, sc2) + " " + DataManager.GetValue(_datacfg.dicSetnames, sc2)
+ " " + DataManager.GetValue(datacfg.dicSetnames, sc3) + " " + DataManager.GetValue(_datacfg.dicSetnames, sc3)
+ " " + DataManager.GetValue(datacfg.dicSetnames, sc4); + " " + DataManager.GetValue(_datacfg.dicSetnames, sc4);
return setname; return setname;
} }
...@@ -172,7 +208,9 @@ public static string[] ReadYDK(string ydkfile) ...@@ -172,7 +208,9 @@ public static string[] ReadYDK(string ydkfile)
if (!str.StartsWith("!") && !str.StartsWith("#") && str.Length > 0) if (!str.StartsWith("!") && !str.StartsWith("#") && str.Length > 0)
{ {
if (IDs.IndexOf(str) < 0) if (IDs.IndexOf(str) < 0)
{
IDs.Add(str); IDs.Add(str);
}
} }
str = sr.ReadLine(); str = sr.ReadLine();
} }
...@@ -181,7 +219,10 @@ public static string[] ReadYDK(string ydkfile) ...@@ -181,7 +219,10 @@ public static string[] ReadYDK(string ydkfile)
} }
} }
if (IDs.Count == 0) if (IDs.Count == 0)
{
return null; return null;
}
return IDs.ToArray(); return IDs.ToArray();
} }
#endregion #endregion
...@@ -196,7 +237,9 @@ public static string[] ReadImage(string path) ...@@ -196,7 +237,9 @@ public static string[] ReadImage(string path)
{ {
string ex = Path.GetExtension(files[i]).ToLower(); string ex = Path.GetExtension(files[i]).ToLower();
if (ex == ".jpg" || ex == ".png" || ex == ".bmp") if (ex == ".jpg" || ex == ".png" || ex == ".bmp")
{
list.Add(Path.GetFileNameWithoutExtension(files[i])); list.Add(Path.GetFileNameWithoutExtension(files[i]));
}
} }
return list.ToArray(); return list.ToArray();
} }
...@@ -210,8 +253,10 @@ public static void CardDelete(long id, YgoPath ygopath) ...@@ -210,8 +253,10 @@ public static void CardDelete(long id, YgoPath ygopath)
for (int i = 0; i < files.Length; i++) for (int i = 0; i < files.Length; i++)
{ {
if (FileSystem.FileExists(files[i])) if (FileSystem.FileExists(files[i]))
FileSystem.DeleteFile(files[i], UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); {
} FileSystem.DeleteFile(files[i], UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin);
}
}
} }
#endregion #endregion
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -19,7 +19,7 @@ namespace DataEditorX.Language ...@@ -19,7 +19,7 @@ namespace DataEditorX.Language
/// </summary> /// </summary>
public static class MyMsg public static class MyMsg
{ {
static string info, warning, error, question; static readonly string info, warning, error, question;
static MyMsg() static MyMsg()
{ {
info = LanguageHelper.GetMsg(LMSG.titleInfo); info = LanguageHelper.GetMsg(LMSG.titleInfo);
...@@ -47,9 +47,13 @@ public static bool Question(string strQues) ...@@ -47,9 +47,13 @@ public static bool Question(string strQues)
if(MessageBox.Show(strQues, question, if(MessageBox.Show(strQues, question,
MessageBoxButtons.OKCancel, MessageBoxButtons.OKCancel,
MessageBoxIcon.Question)==DialogResult.OK) MessageBoxIcon.Question)==DialogResult.OK)
{
return true; return true;
}
else else
{
return false; return false;
}
} }
public static void Show(LMSG msg) public static void Show(LMSG msg)
{ {
...@@ -71,9 +75,13 @@ public static bool Question(LMSG msg) ...@@ -71,9 +75,13 @@ public static bool Question(LMSG msg)
if(MessageBox.Show(LanguageHelper.GetMsg(msg), question, if(MessageBox.Show(LanguageHelper.GetMsg(msg), question,
MessageBoxButtons.OKCancel, MessageBoxButtons.OKCancel,
MessageBoxIcon.Question)==DialogResult.OK) MessageBoxIcon.Question)==DialogResult.OK)
{
return true; return true;
}
else else
{
return false; return false;
}
} }
} }
} }
This diff is collapsed.
...@@ -31,14 +31,16 @@ private static void Main(string[] args) ...@@ -31,14 +31,16 @@ private static void Main(string[] args)
Environment.Exit(1); Environment.Exit(1);
} }
if (MyConfig.OpenOnExistForm(arg))//在已经存在的窗口打开文件 if (MyConfig.OpenOnExistForm(arg))//在已经存在的窗口打开文件
{
Environment.Exit(1); Environment.Exit(1);
}
else//新建窗口 else//新建窗口
{ {
Application.EnableVisualStyles(); Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false); Application.SetCompatibleTextRenderingDefault(false);
MainForm mainForm = new MainForm(); MainForm mainForm = new MainForm();
//设置将要打开的文件 //设置将要打开的文件
mainForm.setOpenFile(arg); mainForm.SetOpenFile(arg);
//数据目录 //数据目录
mainForm.SetDataPath(MyPath.Combine(Application.StartupPath, MyConfig.TAG_DATA)); mainForm.SetDataPath(MyPath.Combine(Application.StartupPath, MyConfig.TAG_DATA));
......
★更新历史 ★更新历史
2.4.3.7
增加了一些自动完成
2.4.3.6 2.4.3.6
UI位置调整 UI位置调整
2.4.3.5 2.4.3.5
......
This diff is collapsed.
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