Skip to content

Commit e5940f3

Browse files
committed
feat: button delete
1 parent e03606a commit e5940f3

3 files changed

Lines changed: 76 additions & 29 deletions

File tree

Assets/Code/Localization/Editor/LocalizationEditorWindow.cs

Lines changed: 76 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,35 @@ private static void OpenWindow()
2222
window.Show();
2323
}
2424

25+
[ShowInInspector, PropertyOrder(-1)]
2526
[FoldoutGroup("Localization File", expanded: true)]
2627
[ValueDropdown("GetAvailableLanguages")]
2728
[OnValueChanged("LoadLocalizationFile")]
28-
public string SelectedLanguage;
29+
private string _selectedLanguage;
2930

3031
[FoldoutGroup("Localization File")]
32+
[ShowInInspector, PropertyOrder(1)]
33+
[OnValueChanged("FilterEntries")]
34+
[LabelText("🔍 Search Key")]
35+
private string _searchKey = string.Empty;
36+
37+
[FoldoutGroup("Localization File")]
38+
[ShowInInspector, PropertyOrder(2)]
3139
[TableList(AlwaysExpanded = true)]
32-
public List<LocalizationEntry> Entries = new();
40+
private List<LocalizationEntry> _entries = new();
41+
42+
private List<LocalizationEntry> _allEntries = new();
3343

3444
[FoldoutGroup("Localization File", expanded: true)]
45+
[ShowInInspector, PropertyOrder(3)]
3546
[Button("💾 Save Current Language", ButtonSizes.Large), GUIColor(0.6f, 1f, 0.6f)]
3647
private void Save()
3748
{
38-
if (string.IsNullOrEmpty(SelectedLanguage)) return;
49+
if (string.IsNullOrEmpty(_selectedLanguage)) return;
3950

40-
string path = Path.Combine(LocalizationFolder, SelectedLanguage + ".txt");
51+
string path = Path.Combine(LocalizationFolder, _selectedLanguage + ".txt");
4152
List<string> lines = new();
42-
foreach (var entry in Entries)
53+
foreach (var entry in _entries)
4354
{
4455
lines.Add($"{entry.Key}={entry.Value.Replace("\n", "\\n")}");
4556
}
@@ -50,22 +61,50 @@ private void Save()
5061
Debug.Log($"✅ Saved language file: {path}");
5162
}
5263

64+
[FoldoutGroup("Localization File", expanded: true)]
65+
[ShowInInspector, PropertyOrder(4)]
66+
[Button("🗑 Delete Selected Language", ButtonSizes.Large), GUIColor(1f, 0.4f, 0.4f)]
67+
private void DeleteSelectedLanguage()
68+
{
69+
if (string.IsNullOrEmpty(_selectedLanguage))
70+
{
71+
Debug.LogWarning("⚠ No language selected to delete.");
72+
return;
73+
}
74+
75+
string path = Path.Combine(LocalizationFolder, _selectedLanguage + ".txt");
76+
if (File.Exists(path))
77+
{
78+
File.Delete(path);
79+
AssetDatabase.Refresh();
80+
Debug.Log($"🗑 Deleted language file: {path}");
81+
82+
_selectedLanguage = null;
83+
_entries.Clear();
84+
_allEntries.Clear();
85+
}
86+
else
87+
{
88+
Debug.LogWarning($"⚠ File not found: {path}");
89+
}
90+
}
91+
5392
[FoldoutGroup("Add New Language", expanded: true)]
5493
[ShowInInspector, PropertyOrder(0)]
5594
[ValueDropdown("GetNewLanguages")]
56-
private SystemLanguage _newLanguage = SystemLanguage.Afrikaans;
95+
private SystemLanguage _NewLanguage = SystemLanguage.Afrikaans;
5796

5897
[FoldoutGroup("Add New Language")]
5998
[ShowInInspector, PropertyOrder(1)]
6099
[ValueDropdown("GetAvailableLanguages")]
61-
private string _baseLanguage = "English";
100+
private string _BaseLanguage = "English";
62101

63102
[FoldoutGroup("Add New Language")]
64103
[ShowInInspector, PropertyOrder(2)]
65104
[Button("🆕 Create New Language From Base", ButtonSizes.Large), GUIColor(0.1f, 0.8f, 1f)]
66105
private void CreateNewLanguageFromBase()
67106
{
68-
string newLang = _newLanguage.ToString();
107+
string newLang = _NewLanguage.ToString();
69108
string targetPath = Path.Combine(LocalizationFolder, newLang + ".txt");
70109

71110
if (File.Exists(targetPath))
@@ -74,23 +113,25 @@ private void CreateNewLanguageFromBase()
74113
return;
75114
}
76115

77-
string basePath = Path.Combine(LocalizationFolder, _baseLanguage + ".txt");
116+
string basePath = Path.Combine(LocalizationFolder, _BaseLanguage + ".txt");
78117
if (!File.Exists(basePath))
79118
{
80-
Debug.LogError($"Base language file '{_baseLanguage}.txt' not found!");
119+
Debug.LogError($"Base language file '{_BaseLanguage}.txt' not found!");
81120
return;
82121
}
83122

84123
File.Copy(basePath, targetPath);
85124
AssetDatabase.Refresh();
86125

87-
Debug.Log($"✅ Created '{newLang}' from '{_baseLanguage}'.");
126+
Debug.Log($"✅ Created '{newLang}' from '{_BaseLanguage}'.");
88127
}
89128

90129
private void LoadLocalizationFile()
91130
{
92-
Entries.Clear();
93-
string path = Path.Combine(LocalizationFolder, SelectedLanguage + ".txt");
131+
_entries.Clear();
132+
_allEntries.Clear();
133+
134+
string path = Path.Combine(LocalizationFolder, _selectedLanguage + ".txt");
94135
if (!File.Exists(path))
95136
{
96137
Debug.LogWarning($"File not found: {path}");
@@ -105,9 +146,29 @@ private void LoadLocalizationFile()
105146
string[] pair = line.Split(new[] { '=' }, 2);
106147
if (pair.Length == 2)
107148
{
108-
Entries.Add(new LocalizationEntry { Key = pair[0].Trim(), Value = pair[1].Trim().Replace("\\n", "\n") });
149+
var entry = new LocalizationEntry
150+
{
151+
Key = pair[0].Trim(),
152+
Value = pair[1].Trim().Replace("\\n", "\n")
153+
};
154+
_allEntries.Add(entry);
109155
}
110156
}
157+
158+
FilterEntries();
159+
}
160+
161+
private void FilterEntries()
162+
{
163+
if (string.IsNullOrEmpty(_searchKey))
164+
{
165+
_entries = new List<LocalizationEntry>(_allEntries);
166+
}
167+
else
168+
{
169+
_entries = _allEntries.FindAll(e =>
170+
e.Key.IndexOf(_searchKey, StringComparison.OrdinalIgnoreCase) >= 0);
171+
}
111172
}
112173

113174
private IEnumerable<string> GetAvailableLanguages()
@@ -129,7 +190,7 @@ private IEnumerable<SystemLanguage> GetNewLanguages()
129190
yield return lang;
130191
}
131192
}
132-
193+
133194
[Serializable]
134195
public class LocalizationEntry
135196
{

Assets/Code/Localization/Intro/Resources/Localization/Romanian.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.

Assets/Code/Localization/Intro/Resources/Localization/Romanian.txt.meta

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)