Commit bc0829bf authored by JoyJ's avatar JoyJ

code format

parent c95bd343
This diff is collapsed.
......@@ -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");
......
This diff is collapsed.
......@@ -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;
......
This diff is collapsed.
......@@ -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
}
......
This diff is collapsed.
......@@ -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>
/// 是否调整图片
......
This diff is collapsed.
......@@ -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);
}
}
......
This diff is collapsed.
......@@ -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
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -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;
}
}
}
}
This diff is collapsed.
......@@ -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
......
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