Skip to content
This repository was archived by the owner on May 30, 2026. It is now read-only.

Commit 2214582

Browse files
committed
CodeEditorFix
1 parent afd94f3 commit 2214582

4 files changed

Lines changed: 74 additions & 67 deletions

File tree

Overlayer/CodeEditor/CodeEditor.cs

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Overlayer.Utils;
44
using System;
55
using System.Collections.Generic;
6+
using System.Linq;
67
using System.Text;
78
using System.Text.RegularExpressions;
89

@@ -12,6 +13,69 @@
1213
namespace Overlayer.CodeEditor;
1314

1415
public class CodeEditor {
16+
public static CodeEditor instance = new("OverlayerCodeEditor", new CodeTheme {
17+
background = "#333333",
18+
linenumbg = "#222222",
19+
color = "#FFFFFF",
20+
selection = "#264F78",
21+
cursor = "#D4D4D4"
22+
});
23+
24+
public static Regex color = new("<<b></b>color=(.*?)>", RegexOptions.Compiled);
25+
26+
public static void Initialize() {
27+
instance.highlighter = str => {
28+
str = str.Replace("<", "<<b></b>");
29+
30+
var colorHighlighted = new List<string>();
31+
foreach(Match m in color.Matches(str)) {
32+
if(!colorHighlighted.Contains(m.Groups[1].Value) && ColorUtility.TryParseHtmlString(m.Groups[1].Value, out _)) {
33+
str = str.Replace("<<b></b>color=" + m.Groups[1].Value + ">",
34+
"<<b></b>color=<color=" + m.Groups[1].Value + ">" + m.Groups[1].Value + "</color>>");
35+
colorHighlighted.Add(m.Groups[1].Value);
36+
}
37+
}
38+
39+
var highlighted = new List<string>();
40+
41+
foreach(Match match in tagRegex.Matches(str)) {
42+
if(highlighted.Contains(match.Groups[1].Value)) {
43+
continue;
44+
}
45+
46+
var fullTag = match.Groups[1].Value;
47+
var splitChar = fullTag.Contains(':') ? ':' : (fullTag.Contains(';') ? ';' : '\0');
48+
var name = splitChar != '\0' ? fullTag.Split(splitChar)[0] : fullTag;
49+
50+
if(TagManager.tags.ContainsKey(name)) {
51+
if(splitChar == ';') {
52+
str = str.Replace("{" + fullTag + "}", "<color=blue>{" + fullTag + "}</color>");
53+
} else if((Main.Settings.MovingManEditor && name == nameof(Effect.MovingMan)) ||
54+
(Main.Settings.ColorRangeEditor && name == nameof(Effect.ColorRange)) ||
55+
(Main.Settings.EasedValueEditor && name == nameof(Effect.EasedValue))) {
56+
str = str.Replace("{" + fullTag + "}", "<color=orange>{" + fullTag + "}</color>");
57+
} else if(name.EndsWith("Hex")) {
58+
try {
59+
var val = (string)TagManager.tags[name].Tag.Getter.Invoke(null,
60+
new object[] { "-1", Overlayer.Utils.Extensions.DefaultTrimStr });
61+
str = str.Replace("{" + fullTag + "}", "<color=#" + val + ">{" + fullTag + "}</color>");
62+
} catch {
63+
str = str.Replace("{" + fullTag + "}", "<color=lightblue>{" + fullTag + "}</color>");
64+
}
65+
} else {
66+
str = str.Replace("{" + fullTag + "}", "<color=lightblue>{" + fullTag + "}</color>");
67+
}
68+
} else {
69+
str = str.Replace("{" + fullTag + "}", "<color=red>{" + fullTag + "}</color>");
70+
}
71+
72+
highlighted.Add(fullTag);
73+
}
74+
75+
return str;
76+
};
77+
}
78+
1579
public string controlName { get; set; }
1680
public System.Action onValueChange;
1781
public int tabSpaces = 2;
@@ -278,8 +342,11 @@ public string Draw(string code, GUIStyle style, string id, params GUILayoutOptio
278342
}
279343

280344
if(rect.Contains(Event.current.mousePosition)) {
281-
var pars = match.Groups[1].Value.Split('(')[0].Split(':')[0];
282-
Main.tooltip = TagManager.tags.ContainsKey(pars) ? Tooltip.GetTagDescription(pars) : Main.Lang.Get("NOT_EXIST_TAG", "This tag does not exist");
345+
var pars = match.Groups[1].Value.Split('(')[0]
346+
.Split([':', ';'], 2)[0];
347+
Main.tooltip = TagManager.tags.ContainsKey(pars)
348+
? Tooltip.GetTagDescription(pars)
349+
: Main.Lang.Get("NOT_EXIST_TAG", "This tag does not exist");
283350
}
284351

285352
if(special) {

Overlayer/Core/Drawer.cs

Lines changed: 3 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using DG.Tweening;
22
using HarmonyLib;
3-
using Overlayer.CodeEditor;
43
using Overlayer.Models;
54
using Overlayer.Tags;
65
using Overlayer.Utils;
@@ -19,17 +18,6 @@
1918
namespace Overlayer.Core;
2019

2120
public static class Drawer {
22-
public static CodeEditor.CodeEditor codeEditor = new("OverlayerCodeEditor",
23-
new CodeTheme {
24-
background = "#333333",
25-
linenumbg = "#222222",
26-
color = "#FFFFFF",
27-
selection = "#264F78",
28-
cursor = "#D4D4D4"
29-
});
30-
31-
public static Regex highlight = new("{(.*?)}", RegexOptions.Compiled);
32-
public static Regex color = new("<<b></b>color=(.*?)>", RegexOptions.Compiled);
3321
public static GUIStyle myButton;
3422
public static GUIStyle myTextField;
3523
public static GUIStyle myTextFieldNoPad;
@@ -77,55 +65,7 @@ public static void SetStyle(bool legacy) {
7765
public static Texture2D black;
7866

7967
static Drawer() {
80-
codeEditor.highlighter = str => {
81-
str = str.Replace("<", "<<b></b>");
82-
83-
var colorHighlighted = new List<string>();
84-
foreach(Match m in color.Matches(str)) {
85-
if(!colorHighlighted.Contains(m.Groups[1].Value) && ColorUtility.TryParseHtmlString(m.Groups[1].Value, out _)) {
86-
str = str.Replace("<<b></b>color=" + m.Groups[1].Value + ">",
87-
"<<b></b>color=<color=" + m.Groups[1].Value + ">" + m.Groups[1].Value + "</color>>");
88-
colorHighlighted.Add(m.Groups[1].Value);
89-
}
90-
}
91-
92-
var highlighted = new List<string>();
93-
94-
foreach(Match match in highlight.Matches(str)) {
95-
if(highlighted.Contains(match.Groups[1].Value)) {
96-
continue;
97-
}
98-
99-
var name = match.Groups[1].Value.Split('(')[0].Split(':')[0];
100-
if(TagManager.tags.ContainsKey(name)) {
101-
if((Main.Settings.MovingManEditor && name == nameof(Effect.MovingMan)) || (Main.Settings.ColorRangeEditor && name == nameof(Effect.ColorRange)) || (Main.Settings.EasedValueEditor && name == nameof(Effect.EasedValue))) {
102-
str = str.Replace("{" + match.Groups[1].Value + "}",
103-
"<color=orange>{" + match.Groups[1].Value + "}</color>");
104-
} else if(name.EndsWith("Hex")) {
105-
try {
106-
var val = (string)TagManager.tags[name].Tag.Getter.Invoke(null,
107-
["-1", Overlayer.Utils.Extensions.DefaultTrimStr]);
108-
str = str.Replace("{" + match.Groups[1].Value + "}",
109-
"<color=#" + val + ">{" + match.Groups[1].Value + "}</color>");
110-
} catch {
111-
str = str.Replace("{" + match.Groups[1].Value + "}",
112-
"<color=lightblue>{" + match.Groups[1].Value + "}</color>");
113-
}
114-
} else {
115-
str = str.Replace("{" + match.Groups[1].Value + "}",
116-
"<color=lightblue>{" + match.Groups[1].Value + "}</color>");
117-
}
118-
} else {
119-
str = str.Replace("{" + match.Groups[1].Value + "}",
120-
"<color=red>{" + match.Groups[1].Value + "}</color>");
121-
}
122-
123-
highlighted.Add(match.Groups[1].Value);
124-
}
125-
126-
return str;
127-
};
128-
68+
CodeEditor.CodeEditor.Initialize();
12969
InitializeImages();
13070

13171
myButton = new GUIStyle(GUI.skin.button);
@@ -633,7 +573,7 @@ public static bool DrawCodeEditor(string label, string id, ref string value) {
633573
wordWrap = false,
634574
richText = false
635575
};
636-
value = codeEditor.Draw(value, sk, id);
576+
value = CodeEditor.CodeEditor.instance.Draw(value, sk, id);
637577
return prev != value;
638578
}
639579

@@ -651,7 +591,7 @@ public static bool DrawCodeEditor(Texture2D icon, string label, string id, ref s
651591
wordWrap = false,
652592
richText = false
653593
};
654-
value = codeEditor.Draw(value, sk, id);
594+
value = CodeEditor.CodeEditor.instance.Draw(value, sk, id);
655595
return prev != value;
656596
}
657597

Overlayer/Core/TextReplacing/Parsing/Parser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static IEnumerable<IParsed> Parse(string input, List<Tag> tags) {
7070
}
7171
}
7272

73-
private static readonly Regex TagRegex = new(
73+
public static readonly Regex TagRegex = new(
7474
@"\{(\w+)([:;\(]?)([^}]*)\}",
7575
RegexOptions.Compiled
7676
);

Overlayer/Main.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ public static void OnGUI(ModEntry modEntry) {
305305
public static void OnHideGUI(ModEntry modEntry) {
306306
IsShowGUI = false;
307307
//CodeEditor.CodeEditor.ignoreTextAreaNext.Clear();
308-
Drawer.codeEditor.undoRedoManagers.Clear();
308+
CodeEditor.CodeEditor.instance.undoRedoManagers.Clear();
309309
GUI.Flush();
310310
}
311311

0 commit comments

Comments
 (0)