-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCustomCharacterHandler.cs
More file actions
61 lines (58 loc) · 2.48 KB
/
Copy pathCustomCharacterHandler.cs
File metadata and controls
61 lines (58 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using Modding;
using System.IO;
using System.Reflection;
using Satchel.BetterMenus;
using System.Linq;
namespace AlphabetRando {
public static class CustomCharacterHandler {
private static Menu MenuRef;
private static string defaultChars = ".,?!'\"-_()[]:+";
public static void LoadFile(bool manualReload) {
Assembly assembly = Assembly.GetExecutingAssembly();
string filename = Path.GetDirectoryName(assembly.Location) + "/CustomCharacters.txt";
if(!File.Exists(filename)) {
using FileStream fs = File.Create(filename);
using(StreamWriter writer = new(fs)) {
writer.Write(defaultChars);
};
}
string content = File.ReadAllText(filename);
string previous = AlphabetRando.globalSettings.CustomCharacters;
AlphabetRando.globalSettings.CustomCharacters = "";
foreach(char c in content) {
if(char.IsWhiteSpace(c))
continue;
if(c == '<' || c == '>')
continue;
if(Consts.allLetters.Contains(c.ToString().ToUpper()))
continue;
if(AlphabetRando.globalSettings.CustomCharacters.Contains(c))
continue;
AlphabetRando.globalSettings.CustomCharacters += c;
}
if(manualReload)
RandoInterop.DefineCustomCharacterItems(previous);
}
public static MenuScreen GetMenuScreen(MenuScreen modListMenu, ModToggleDelegates? modtoggledelegates) {
MenuRef ??= new Menu(
name: "Alphabet Rando",
elements: new Element[] {
new MenuButton(
name: "Reload Custom Characters",
description: "",
submitAction: (Mbutton) => {
LoadFile(true);
MenuRef.Find("AbcReloadDisplay").Name = AlphabetRando.globalSettings.CustomCharacters;
MenuRef.Update();
},
Id: "AbcReloadBtn"
),
new TextPanel(""),
new TextPanel("Current Characters:"),
new TextPanel(AlphabetRando.globalSettings.CustomCharacters, Id: "AbcReloadDisplay")
}
);
return MenuRef.GetMenuScreen(modListMenu);
}
}
}