diff --git a/BizHawk.MultiClient/Config.cs b/BizHawk.MultiClient/Config.cs index 60b3d505e5..4cc94e192b 100644 --- a/BizHawk.MultiClient/Config.cs +++ b/BizHawk.MultiClient/Config.cs @@ -556,7 +556,8 @@ namespace BizHawk.MultiClient public int LuaCommentColor = -16744448; public int LuaStringColor = -8355712; public int LuaSymbolColor = -16777216; - public int LuaLibraryColor = 10349567; + public int EmuluaLibraryColor = 10349567; + public int LuaLibraryColor = -8388480; } public class SMSControllerTemplate diff --git a/BizHawk.MultiClient/tools/LuaWriter.Designer.cs b/BizHawk.MultiClient/tools/LuaWriter.Designer.cs index 25f7f519bb..f56eac28b3 100644 --- a/BizHawk.MultiClient/tools/LuaWriter.Designer.cs +++ b/BizHawk.MultiClient/tools/LuaWriter.Designer.cs @@ -173,6 +173,7 @@ this.LuaText.Text = ""; this.LuaText.WordWrap = false; this.LuaText.ZoomFactor = 2F; + this.LuaText.SelectionChanged += new System.EventHandler(this.LuaText_SelectionChanged); this.LuaText.TextChanged += new System.EventHandler(this.LuaText_TextChanged); this.LuaText.KeyDown += new System.Windows.Forms.KeyEventHandler(this.LuaText_KeyDown); this.LuaText.KeyUp += new System.Windows.Forms.KeyEventHandler(this.LuaText_KeyUp); diff --git a/BizHawk.MultiClient/tools/LuaWriter.cs b/BizHawk.MultiClient/tools/LuaWriter.cs index 27a7f77c8e..0193e975f6 100644 --- a/BizHawk.MultiClient/tools/LuaWriter.cs +++ b/BizHawk.MultiClient/tools/LuaWriter.cs @@ -42,6 +42,7 @@ namespace BizHawk.MultiClient public Regex keyWords = new Regex("and|break|do|else|if|end|false|for|function|in|local|nil|not|or|repeat|return|then|true|until|while|elseif"); char[] Symbols = { '+', '-', '*', '/', '%', '^', '#', '=', '<', '>', '(', ')', '{', '}', '[', ']', ';', ':', ',', '.' }; public Regex libraryWords; + public Regex LuaLibraryWords = new Regex("coroutine|package|debug|file|io|math|os|package|string|table"); Font LuaTextFont = new Font("Courier New", 8); public LuaWriter() @@ -70,13 +71,40 @@ namespace BizHawk.MultiClient LuaText.SelectionColor = Color.FromArgb(Global.Config.LuaDefaultTextColor); ColorReservedWords(); + ColorLibraries(); + ColorLuaLibraries(); ColorComments(); ColorStrings(); ColorSymbols(); - ColorLibraries(); LuaText.Select(selPos, selChars); } + private void ColorLuaLibraries() + { + foreach (Match libraryWordMatch in LuaLibraryWords.Matches(LuaText.Text)) + { + if (libraryWordMatch.Index >= 0) + { + char before = ' ', after = ' '; + + if (libraryWordMatch.Index > 0) + before = LuaText.Text[libraryWordMatch.Index - 1]; + + if (libraryWordMatch.Index + libraryWordMatch.Length != LuaText.Text.Length) + after = LuaText.Text[libraryWordMatch.Index + libraryWordMatch.Length]; + + if (!char.IsLetterOrDigit(before)) + { + if (after == '.') + { + LuaText.Select(libraryWordMatch.Index, libraryWordMatch.Length); + LuaText.SelectionColor = Color.FromArgb(Global.Config.LuaLibraryColor); + } + } + } + } + } + private void ColorSymbols() { foreach (char mark in Symbols) @@ -239,39 +267,18 @@ namespace BizHawk.MultiClient if (libraryWordMatch.Index + libraryWordMatch.Length != LuaText.Text.Length) after = LuaText.Text[libraryWordMatch.Index + libraryWordMatch.Length]; - if (!IsAlphaNumeric(before)) + if (!char.IsLetterOrDigit(before)) { if (after == '.') { LuaText.Select(libraryWordMatch.Index, libraryWordMatch.Length); - if(LuaText.SelectionColor.ToArgb() != Global.Config.LuaCommentColor && LuaText.SelectionColor.ToArgb() != Global.Config.LuaStringColor) - LuaText.SelectionColor = Color.FromArgb(Global.Config.LuaLibraryColor); + LuaText.SelectionColor = Color.FromArgb(Global.Config.EmuluaLibraryColor); } } } } } - private bool IsAlphaNumeric(char x) - { - if (x >= 'a' && x <= 'z') - { - return true; - } - else if (x >= 'A' && x <= 'Z') - { - return true; - } - else if (x >= '0' && x <= '9') - { - return true; - } - else - { - return false; - } - } - private void GenerateLibraryRegex() { StringBuilder list = new StringBuilder(); @@ -419,13 +426,7 @@ namespace BizHawk.MultiClient private void LuaText_KeyUp(object sender, KeyEventArgs e) { - hasChanged = true; - int currentLineIndex = LuaText.GetLineFromCharIndex(LuaText.SelectionStart); - int lastLineIndex = LuaText.GetLineFromCharIndex(LuaText.TextLength); - int currentColumnIndex = LuaText.SelectionStart - LuaText.GetFirstCharIndexFromLine(currentLineIndex); - - PositionLabel.Text = string.Format("Line {0}/{1}, Column {2}", currentLineIndex + 1, lastLineIndex + 1, currentColumnIndex + 1); } private void Changes() @@ -436,6 +437,7 @@ namespace BizHawk.MultiClient private void LuaText_TextChanged(object sender, EventArgs e) { + hasChanged = true; Changes(); } @@ -537,5 +539,17 @@ namespace BizHawk.MultiClient AutoCompleteView.Visible = false; } } + + private void LuaText_SelectionChanged(object sender, EventArgs e) + { + if (!hasChanged) + { + int currentLineIndex = LuaText.GetLineFromCharIndex(LuaText.SelectionStart); + int lastLineIndex = LuaText.GetLineFromCharIndex(LuaText.TextLength); + int currentColumnIndex = LuaText.SelectionStart - LuaText.GetFirstCharIndexFromLine(currentLineIndex); + + PositionLabel.Text = string.Format("Line {0}/{1}, Column {2}", currentLineIndex + 1, lastLineIndex + 1, currentColumnIndex + 1); + } + } } } \ No newline at end of file