-
Notifications
You must be signed in to change notification settings - Fork 78
Expand file tree
/
Copy pathTextEditorScreen.cs
More file actions
781 lines (685 loc) · 31.4 KB
/
Copy pathTextEditorScreen.cs
File metadata and controls
781 lines (685 loc) · 31.4 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
using static Andre.Native.ImGuiBindings;
using SoulsFormats;
using StudioCore.Editor;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using Veldrid;
using Veldrid.Sdl2;
namespace StudioCore.TextEditor;
public unsafe class TextEditorScreen : EditorScreen
{
private readonly PropertyEditor _propEditor;
private FMGEntryGroup _activeEntryGroup;
private FMGInfo _activeFmgInfo;
private int _activeIDCache = -1;
private bool _arrowKeyPressed;
private bool _clearEntryGroup;
private List<FMG.Entry> _entryLabelCache;
private List<FMG.Entry> _EntryLabelCacheFiltered;
private ProjectSettings _projectSettings;
private string _searchFilter = "";
private string _searchFilterCached = "";
private string _fmgSearchAllString = "";
private bool _fmgSearchAllActive = false;
private List<FMGInfo> _filteredFmgInfo = new();
public ActionManager EditorActionManager = new();
public TextEditorScreen(Sdl2Window window, GraphicsDevice device)
{
_propEditor = new PropertyEditor(EditorActionManager);
}
public string EditorName => "Text Editor";
public string CommandEndpoint => "text";
public string SaveType => "Text";
public void DrawEditorMenu()
{
if (Locator.ActiveProject == null)
return;
FMGBank currentFmgBank = Locator.ActiveProject.FMGBank;
if (ImGui.BeginMenu("Edit", Locator.ActiveProject.FMGBank.IsLoaded))
{
if (ImGui.MenuItem("Undo", KeyBindings.Current.Core_Undo.HintText, false,
EditorActionManager.CanUndo()))
{
EditorActionManager.UndoAction();
}
if (ImGui.MenuItem("Redo", KeyBindings.Current.Core_Redo.HintText, false,
EditorActionManager.CanRedo()))
{
EditorActionManager.RedoAction();
}
if (ImGui.MenuItem("Delete Entry", KeyBindings.Current.Core_Delete.HintText, false,
_activeEntryGroup != null))
{
DeleteFMGEntries(_activeEntryGroup);
}
if (ImGui.MenuItem("Duplicate Entry", KeyBindings.Current.Core_Duplicate.HintText, false,
_activeEntryGroup != null))
{
DuplicateFMGEntries(_activeEntryGroup);
}
ImGui.EndMenu();
}
if (ImGui.BeginMenu("Text Language", !Locator.ActiveProject.FMGBank.IsLoading))
{
Dictionary<string, string> folders = Locator.AssetLocator.GetMsgLanguages();
if (folders.Count == 0)
{
ImGui.TextColored(new Vector4(1.0f, 0.0f, 0.0f, 1.0f), "Cannot find language folders.");
}
else
{
foreach (KeyValuePair<string, string> path in folders)
{
string disp = path.Key;
if (Locator.ActiveProject.FMGBank.fmgLangs.ContainsKey(path.Key))
{
disp += "*";
}
if (ImGui.MenuItem(disp, "", Locator.ActiveProject.FMGBank.LanguageFolder == path.Key))
{
ChangeLanguage(path.Key);
}
}
}
ImGui.EndMenu();
}
if (ImGui.BeginMenu("Import/Export", Locator.ActiveProject.FMGBank.IsLoaded))
{
if (ImGui.BeginMenu("Merge"))
{
ImGui.TextColored(new Vector4(0.75f, 0.75f, 0.75f, 1.0f),
"Import: text will be merged with currently loaded text");
if (ImGui.MenuItem("Import text files and merge"))
{
if (FmgExporter.ImportFmgTxt(currentFmgBank.fmgLangs[currentFmgBank.LanguageFolder], true))
{
ClearTextEditorCache();
ResetActionManager();
}
}
ImGui.TextColored(new Vector4(0.75f, 0.75f, 0.75f, 1.0f),
"Export: only modded text (different than vanilla) will be exported");
if (ImGui.MenuItem("Export modded text to text files"))
{
FmgExporter.ExportFmgTxt(currentFmgBank.fmgLangs[currentFmgBank.LanguageFolder], true);
}
ImGui.EndMenu();
}
if (ImGui.BeginMenu("All"))
{
ImGui.TextColored(new Vector4(0.75f, 0.75f, 0.75f, 1.0f),
"Import: text replaces currently loaded text entirely");
if (ImGui.MenuItem("Import text files and replace"))
{
if (FmgExporter.ImportFmgTxt(currentFmgBank.fmgLangs[currentFmgBank.LanguageFolder], false))
{
ClearTextEditorCache();
ResetActionManager();
}
}
ImGui.TextColored(new Vector4(0.75f, 0.75f, 0.75f, 1.0f),
"Export: all text will be exported");
if (ImGui.MenuItem("Export all text to text files"))
{
FmgExporter.ExportFmgTxt(currentFmgBank.fmgLangs[currentFmgBank.LanguageFolder], false);
}
if (ImGui.BeginMenu("Legacy"))
{
ImGui.TextColored(new Vector4(0.75f, 0.75f, 0.75f, 1.0f),
"Old version of text import/export system.\n" +
"Import: text replaces currently loaded text entirely.");
if (ImGui.MenuItem("Import json"))
{
if (FmgExporter.ImportFmgJson(currentFmgBank.fmgLangs[currentFmgBank.LanguageFolder], false))
{
ClearTextEditorCache();
ResetActionManager();
}
}
ImGui.EndMenu();
}
ImGui.EndMenu();
}
ImGui.EndMenu();
}
}
public void OnGUI(string[] initcmd)
{
if (Locator.AssetLocator == null)
{
return;
}
var scale = MapStudioNew.GetUIScale();
// Docking setup
ImGui.PushStyleVarVec2(ImGuiStyleVar.WindowPadding, new Vector2(4, 4) * scale);
Vector2 wins = ImGui.GetWindowSize();
Vector2 winp = ImGui.GetWindowPos();
winp.Y += 20.0f * scale;
wins.Y -= 20.0f * scale;
ImGui.SetNextWindowPos(winp);
ImGui.SetNextWindowSize(wins);
if (!ImGui.IsAnyItemActive() && Locator.ActiveProject != null && Locator.ActiveProject.FMGBank.IsLoaded)
{
// Only allow key shortcuts when an item [text box] is not currently activated
if (EditorActionManager.CanUndo() && InputTracker.GetKeyDown(KeyBindings.Current.Core_Undo))
{
EditorActionManager.UndoAction();
}
if (EditorActionManager.CanRedo() && InputTracker.GetKeyDown(KeyBindings.Current.Core_Redo))
{
EditorActionManager.RedoAction();
}
if (InputTracker.GetKeyDown(KeyBindings.Current.Core_Delete) && _activeEntryGroup != null)
{
DeleteFMGEntries(_activeEntryGroup);
}
if (InputTracker.GetKeyDown(KeyBindings.Current.Core_Duplicate) && _activeEntryGroup != null)
{
DuplicateFMGEntries(_activeEntryGroup);
}
}
var doFocus = false;
// Parse select commands
if (initcmd != null && initcmd[0] == "select")
{
if (initcmd.Length > 1)
{
// Select FMG
doFocus = true;
// Use three possible keys: entry category is for param references,
// binder id and FMG name are for soapstone references.
// This can be revisited as more high-level categories get added.
int? searchId = null;
FmgEntryCategory? searchCategory = null;
string searchName = null;
if (int.TryParse(initcmd[1], out var intId) && intId >= 0)
{
searchId = intId;
}
// Enum.TryParse allows arbitrary ints (thanks C#), so checking definition is required
else if (Enum.TryParse(initcmd[1], out FmgEntryCategory cat)
&& Enum.IsDefined(typeof(FmgEntryCategory), cat))
{
searchCategory = cat;
}
else
{
searchName = initcmd[1];
}
foreach (FMGInfo info in Locator.ActiveProject.FMGBank.FmgInfoBank)
{
var match = false;
// This matches top-level item FMGs
if (info.EntryCategory.Equals(searchCategory) && info.PatchParent == null
&& info.EntryType is FmgEntryTextType.Title
or FmgEntryTextType.TextBody)
{
match = true;
}
else if (searchId is int binderId && binderId == (int)info.FmgID)
{
match = true;
}
else if (info.Name == searchName)
{
match = true;
}
if (match)
{
_activeFmgInfo = info;
break;
}
}
if (initcmd.Length > 2 && _activeFmgInfo != null)
{
// Select Entry
var parsed = int.TryParse(initcmd[2], out var id);
if (parsed)
{
_activeEntryGroup = Locator.ActiveProject.FMGBank.GenerateEntryGroup(id, _activeFmgInfo);
}
}
}
}
EditorGUI(doFocus);
ImGui.PopStyleVar(1);
}
public void OnProjectChanged(ProjectSettings newSettings)
{
_projectSettings = newSettings;
_fmgSearchAllString = "";
_filteredFmgInfo.Clear();
ClearTextEditorCache();
ResetActionManager();
}
public void Save()
{
Locator.ActiveProject.FMGBank.SaveFMGs();
}
public void SaveAll()
{
Locator.ActiveProject.FMGBank.SaveFMGs();
}
private void ClearTextEditorCache()
{
UICache.ClearCaches();
_entryLabelCache = null;
_EntryLabelCacheFiltered = null;
_activeFmgInfo = null;
_activeEntryGroup = null;
_activeIDCache = -1;
_searchFilter = "";
_searchFilterCached = "";
}
private void ResetActionManager()
{
EditorActionManager.Clear();
}
/// <summary>
/// Duplicates all Entries in active EntryGroup from their FMGs
/// </summary>
private void DuplicateFMGEntries(FMGEntryGroup entry)
{
_activeIDCache = entry.GetNextUnusedID();
var action = new DuplicateFMGEntryAction(entry);
EditorActionManager.ExecuteAction(action);
// Lazy method to refresh search filter
// TODO: _searchFilterCached should be cleared whenever CacheBank is cleared.
_searchFilterCached = "";
}
/// <summary>
/// Deletes all Entries within active EntryGroup from their FMGs
/// </summary>
private void DeleteFMGEntries(FMGEntryGroup entry)
{
var action = new DeleteFMGEntryAction(entry);
EditorActionManager.ExecuteAction(action);
_activeEntryGroup = null;
_activeIDCache = -1;
// Lazy method to refresh search filter
_searchFilterCached = "";
}
private void FMGSearchLogic(ref bool doFocus)
{
if (_entryLabelCache != null)
{
if (_searchFilter != _searchFilterCached)
{
List<FMG.Entry> matches = new();
_EntryLabelCacheFiltered = _entryLabelCache;
List<FMG.Entry> mainEntries;
if (_searchFilter.Length > _searchFilterCached.Length)
{
mainEntries = _EntryLabelCacheFiltered;
}
else
{
mainEntries = _entryLabelCache;
}
// Title/Textbody
foreach (FMG.Entry entry in mainEntries)
{
if (entry.ID.ToString().Contains(_searchFilter, StringComparison.CurrentCultureIgnoreCase))
{
// ID search
matches.Add(entry);
}
else if (entry.Text != null)
{
// Text search
if (entry.Text.Contains(_searchFilter, StringComparison.CurrentCultureIgnoreCase))
{
matches.Add(entry);
}
}
}
// Descriptions
foreach (FMG.Entry entry in Locator.ActiveProject.FMGBank.GetFmgEntriesByCategoryAndTextType(_activeFmgInfo.EntryCategory,
FmgEntryTextType.Description, false))
{
if (entry.Text != null)
{
if (entry.Text.Contains(_searchFilter, StringComparison.CurrentCultureIgnoreCase))
{
FMG.Entry search = _entryLabelCache.Find(e => e.ID == entry.ID && !matches.Contains(e));
if (search != null)
{
matches.Add(search);
}
}
}
}
// Summaries
foreach (FMG.Entry entry in Locator.ActiveProject.FMGBank.GetFmgEntriesByCategoryAndTextType(_activeFmgInfo.EntryCategory,
FmgEntryTextType.Summary, false))
{
if (entry.Text != null)
{
if (entry.Text.Contains(_searchFilter, StringComparison.CurrentCultureIgnoreCase))
{
FMG.Entry search = _entryLabelCache.Find(e => e.ID == entry.ID && !matches.Contains(e));
if (search != null)
{
matches.Add(search);
}
}
}
}
// Extra Text
foreach (FMG.Entry entry in Locator.ActiveProject.FMGBank.GetFmgEntriesByCategoryAndTextType(_activeFmgInfo.EntryCategory,
FmgEntryTextType.ExtraText, false))
{
if (entry.Text != null)
{
if (entry.Text.Contains(_searchFilter, StringComparison.CurrentCultureIgnoreCase))
{
FMG.Entry search = _entryLabelCache.Find(e => e.ID == entry.ID && !matches.Contains(e));
if (search != null)
{
matches.Add(search);
}
}
}
}
matches = matches.OrderBy(e => e.ID).ToList();
_EntryLabelCacheFiltered = matches;
_searchFilterCached = _searchFilter;
doFocus = true;
}
else if (_entryLabelCache != _EntryLabelCacheFiltered && _searchFilter == "")
{
_EntryLabelCacheFiltered = _entryLabelCache;
}
}
}
private void CategoryListUI(FmgFileCategory uiType, bool doFocus)
{
IEnumerable<FMGInfo> infos;
if (_fmgSearchAllActive)
infos = _filteredFmgInfo;
else
infos = Locator.ActiveProject.FMGBank.SortedFmgInfoBank;
foreach (var info in infos)
{
if (info.PatchParent == null
&& info.FileCategory == uiType
&& info.EntryType is FmgEntryTextType.Title or FmgEntryTextType.TextBody)
{
string displayName;
if (CFG.Current.FMG_ShowOriginalNames)
{
displayName = info.FileName;
}
else
{
if (!CFG.Current.FMG_NoGroupedFmgEntries)
{
displayName = info.Name.Replace("Title", "");
}
else
{
displayName = info.Name;
}
displayName = displayName.Replace("Modern_", "");
}
if (ImGui.Selectable($@" {displayName}", info == _activeFmgInfo))
{
ClearTextEditorCache();
_activeFmgInfo = info;
if (_fmgSearchAllActive)
{
_searchFilter = _fmgSearchAllString;
_searchFilterCached = "";
}
}
if (doFocus && info == _activeFmgInfo)
{
ImGui.SetScrollHereY();
}
}
}
}
private void EditorGUI(bool doFocus)
{
var scale = MapStudioNew.GetUIScale();
if (Locator.ActiveProject == null || !Locator.ActiveProject.FMGBank.IsLoaded)
{
if (_projectSettings == null)
{
ImGui.Text("No project loaded. File -> New Project");
}
else if (Locator.ActiveProject.FMGBank.IsLoading)
{
ImGui.Text("Loading...");
}
else
{
ImGui.Text("This Editor requires unpacked game files. Use UXM");
// Ascii fatcat (IMPORTANT)
ImGui.TextUnformatted(
"\nPPPPP5555PGGGGGGGBBBBBBGPYJ?????????JJYYYYYY5PPPGGPPPGPPPPPPPPPPPPGGGGGGGGGPPPPPPPPPPPPPPPPPPPPPPPPP\r\nPPPPP5555PGGGGGBBBBBBGGGPYJJ??????JJYY55555Y555PPPPGGGGGGGGGGGGGGGGGPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP\r\nPPPPP555PPGGGGGBBBBBBGGGP5JJ?????JJY55555555YYY555PPPPGGGGGGGPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP\r\nPPPPP555PPGGGGGBBBBBBGBGPYJ?????JJY555555555555555555PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPGPPP\r\nPP55555PPGGGGGGGBBBBBBGGPYJ????JJY555555555555555555555555PPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPPP\r\n555Y55PPGGGGGGGGGGGBBGGG5Y?????JYY5555555P5555P555555555555555PPPPPPPPPPPPPPPPPPGGGGGGGGGPPPPPPPPPPP\r\n555555PPPPPPPPGGGGGBBBBGPJ???JJYY55555555PPPP5555555555555555555PPPPPPPPPPPPPPPPPPPPPPPPPPPPPGGGGGGG\r\nPPPPPPPPPPPGGGGGGGGGBBBBG5YJJJYYYY555555PPP55555555555555555555555PPPPPPPPPGGPPPPPGGGGPPPPPPPPPPPPPP\r\nPPPPPPPGGGGGGGGGGGGBBBBBGP555YYYYYYYYYY55555555555YYYYYYYYY55555555555PPPPPPPPPPPPPPPPPPPPPPPGPPPPPP\r\nPPPPPGGGGGPPPPPPPPGGGGGGPPPP5555YYYYYYYYYY555555YYYYYYYYYY55555YYYYYY5555555555555555555555555555PPP\r\nPPPPPPPPPPPP555555PPPPPPPPPP5555555555YYYYYYYYYYYYYYYYYYYY55YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY\r\n55PPPPPP555555555555555PP55555555555555555YYYYYYYYYYYYYYYYYYYYYYYJJJJJ??JJJJJJ?JJJJJJJJJJJJJJJJJJJJJ\r\nPPPPPPP55555555PP5555555P55555555555555555YYYYYYYYYYYYYYYYJJJJJJJJJ??????????77?????????????????????\r\nPPPPPP5PPPPPPPPPP555555555555555555555555YYYYYYYYYYYYYYYJJ??????????7777777777777?????????7?????????\r\nPPPPPPPPPPPPPPPP55555555555555555555YYYYYYYYYYYYYYYYJJJ???7777777777??7777777777777777????77777?????\r\nGGGGBBBBBBGGGGGGGGGPPPPPPPPP5555555YYYYYYYJJJJJJJJ??????77777777?77??????777777777777777?777777?????\r\nGGGGGGGBBBBBBBBBBBBBBGGGGGPPPPPP5555YYYYJJJJJJ????????7777777?????????????????????7777777777777?????\r\nPPPPPPPPPGGGGGGGGGGBBBBBBBGGPPPPPP555YYYYJJJJJ?????????77777????JJYYYJJJJJ?????????????????777777777\r\nPPP5PPPPPPPPPPPPPPPPPPPGGBBGGGPPPPPP55YYYYYYJJJ??7777????777??JJYY5555YYYYYYYYYYYYYJJJJYJJJJ????????\r\nPPPPPPPPPPPPP5PPPPPP555PPGGGGGPPPPPPP5555YYYJJ???7777?77777???JY555PPPPPPPPPGGGGGGGGGPPPPPPPP555YYYY\r\nPPPPPPPPPPPPP55PPP5555555PPPPPPPPPPPPP555YYJJ????????????777??J5PGGGGGGGGGGGGGGGGBBBBBBBBBBBBBBBBBBB\r\nPPPPPPPPPPPP55555555555PPPPPPPPPPPPPP55YYYYJJJ?????????????77?Y5P555YJJ??JJJJJ??JJJJJJJYYY5555555555\r\nPPP55PPPP5555555555555PPPPPPPPPPPGGPP5YYYYYJJJ????????????777??JJJJ???777777777777777777????????????\r\n555555P55555P55555555PPPPPPPPPPPGGGP55YYYYYJJJJJJJ??JJJ?????????????77777777777777777777777777777777\r\n5555555555PPPP55555PPPPPPPPPPPPPGGPP5YYYYYYJJJJJJJJJJJJJ????????????77777777777777777777777777777777\r\nP5555555555P5555555PPPPPPPPGGGGGGGPP5YYYYYYYYJJJJJYYYYYJJJ??????????77777777777777777777777777777777\r\n555P5555555555555555PPPPPPPGGGGPPPP55YYYYYYYYYYYYYY555YYJJJ????????777777777777777777777777777777777\r\n55555555555555PPP555PPPPPPGGGGGGPPP55YYYYYYYYYYYYYYY55YYJJJ???????7777777777777777777777777777777777\r\nPPPP55PP5555PPPPPPPPPPPPPPPGGGGGGPPP555YYYYYYYYYYY55PP5YJJ???????????7777777777777777777777777777777\r\nPPP555555PPPP55PPPPPPPPPPPGGGGBGGPPPPP555555555PPPGGPP5YJJJJ??????????777777777777777777777777777777\r\nPPPPPPPPPPPPPPPPPPPPPPPPPPGGGGGGGPPPPPPPPPPPPPPPGGGGP55YYYYJJ?????????777777777777777777777777777777\r\nPPPPPPPGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGPPGPPP55YYYYYJJJJ?????????77777777777777777777777777\r\nPPPPPPPPGGGBBBBBBBBBGGGBBBBBBBBBBBBBBBBBBBBGGBBGGGGGGPPP5555YYYYYYYJJJJJJ??????777777777777777777777\r\nPPPPPPPPPPPPPGGBBBGGPPGGBBBBBBBBBBBBBBBBBBBBBBBBBBBGGGGGGGPPPPPPPPP55555YYYYJJJ????77777777777777777\r\nPPPPPPPPPPPPPPPPPPPPPPPPGBBBBBBBBBBBBBBBBBBBBBB##BGGPPGGBBBBGGGGGGGGPPPPPPPP5555YYJJ??????7777777777\r\nPPPPPPPPPPPPPPPPPPP55555PPGGGBBBBBBBBBBBBBBBBBBBGGPPPPGGGGGPPPPPPPPPPP5555555555555YYJJJ????????????\r\nPPPPPPPPPPPPPPPP5PPPPP555PPPPPPPPPPPPPPPPGPPPPPPP555555555555555YYYJJJJJJJJJJJJJJYYYYJJJJJJJJJ??????\r\nPPPPPPPPPPPPPPP555PPPP555555555555555555555555YYYYYYYYYYYJJJJJJJ???777777777777???JJJJJJJJJJJJJJ????\r\nPPP55PPPPP555PP5555555555555555YYYYYYYYYYYYYYJJJJJJJJJJ??????777777777777777777???JJJJJJJJJJJJJJJ???\r\nPPPPPPPP5555555555555555YYYYYYYJJJJJJ????????????????????????????777777777777???JJJJJJJJJJJJJJJJJ???\r\nPPPP5P555555555555555555555YYYYYJJJJJJJJ??????????????????????????????7?????JJJJJJJJJJJJJJJJJJJJJJJJ\r\nPPP55PP55555555555555555555YYYYYYYJJJJJJJJJJJJJJJJ?????????JJJJJJJJ???JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ\r\n555555555555555555555555YYYYYYYYYYYYJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ\r\n55555555555555555555555555555555YYYYYYYYYYYYYYYYYYYYYYYYYYYYYJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ\r\n5555555555555555555555555555555555555555555555555555555YYYYYYYJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ?\r\n55555555555555555555555555555555555555555555555555555555YYYYYYYYYYYYJJJJJJJJJJJJJJJJJJJJJJJJJJJ?????\r\n555555555555555555555555555555555555555555555555555555YYYYYYYYYYYYYYYJJJJJJJJJJJJJJJJJJJJJ??????????");
}
return;
}
var dsid = ImGui.GetID("DockSpace_TextEntries");
ImGui.DockSpace(dsid, new Vector2(0, 0), ImGuiDockNodeFlags.None, null);
ImGui.Begin("Text Categories");
ImGui.Indent();
ImGui.InputText("##SearchAllFmgsInput", ref _fmgSearchAllString, 255);
ImGui.Unindent();
ImGui.SameLine();
if (_fmgSearchAllString == "")
{
_fmgSearchAllActive = false;
ImGui.BeginDisabled();
}
if (ImGui.Button("Search All FMGs##FmgSearchAll"))
{
_fmgSearchAllActive = true;
_filteredFmgInfo.Clear();
foreach (var info in Locator.ActiveProject.FMGBank.SortedFmgInfoBank)
{
if (info.PatchParent == null)
{
foreach (var entry in info.GetPatchedEntries(false))
{
if ((entry.Text != null && entry.Text.Contains(_fmgSearchAllString, StringComparison.CurrentCultureIgnoreCase))
|| entry.ID.ToString().Contains(_fmgSearchAllString))
{
if (info.EntryType is not FmgEntryTextType.Title and not FmgEntryTextType.TextBody)
{
try
{
_filteredFmgInfo.Add(info.GetTitleFmgInfo());
}
catch (Exception e)
{
//This fmginfo lacks a title
_filteredFmgInfo.Add(info);
}
}
else
{
_filteredFmgInfo.Add(info);
}
break;
}
}
}
}
_filteredFmgInfo = _filteredFmgInfo.Distinct().ToList();
}
if (_fmgSearchAllString == "")
{
ImGui.EndDisabled();
}
ImGui.SameLine();
if (ImGui.Button("Reset##FmgSearchAll"))
{
_fmgSearchAllActive = false;
_fmgSearchAllString = "";
_filteredFmgInfo.Clear();
}
ImGui.Separator();
foreach (FmgFileCategory v in Locator.ActiveProject.FMGBank.currentFmgInfoBanks)
{
ImGui.Separator();
ImGui.Text($" {v} Text");
ImGui.Separator();
// Categories
CategoryListUI(v, doFocus);
ImGui.Spacing();
}
if (_activeFmgInfo != null)
{
_entryLabelCache = UICache.GetCached(this, "FMGEntryCache", () =>
{
return _activeFmgInfo.GetPatchedEntries();
});
}
// Needed to ensure EntryGroup is still valid after undo/redo actions while also maintaining highlight-duped-row functionality.
// It's a bit dumb and probably overthinking things.
_clearEntryGroup = UICache.GetCached(this, "FMGClearEntryGroup", () =>
{
if (_clearEntryGroup)
{
return false;
}
return true;
});
if (_clearEntryGroup)
{
if (!doFocus)
{
_activeEntryGroup = null;
}
UICache.RemoveCache(this, "FMGClearEntryGroup");
}
ImGui.End();
ImGui.Begin("Text Entries");
if (ImGui.Button("Clear Text"))
{
_searchFilter = "";
}
ImGui.SameLine();
// Search
if (InputTracker.GetKeyDown(KeyBindings.Current.TextFMG_Search))
{
EditorDecorations.ImGuiSetKeyboardFocusHere();
}
ImGui.InputText($"Search <{KeyBindings.Current.TextFMG_Search.HintText}>", ref _searchFilter, 255);
FMGSearchLogic(ref doFocus);
ImGui.BeginChild("Text Entry List");
if (_activeFmgInfo == null)
{
ImGui.Text("Select a category to see entries");
}
else if (_EntryLabelCacheFiltered == null)
{
ImGui.Text("No entries match search filter");
}
else
{
if (InputTracker.GetKey(Key.Up) || InputTracker.GetKey(Key.Down))
{
_arrowKeyPressed = true;
}
for (var i = 0; i < _EntryLabelCacheFiltered.Count; i++)
{
FMG.Entry r = _EntryLabelCacheFiltered[i];
// Entries
var text = r.Text == null
? "%null%"
: r.Text.Replace("\n", "\n".PadRight(r.ID.ToString().Length + 2));
var label = $@"{r.ID} {text}";
label = Utils.ImGui_WordWrapString(label, ImGui.GetColumnWidth(-1));
if (ImGui.Selectable(label, _activeIDCache == r.ID))
{
_activeEntryGroup = Locator.ActiveProject.FMGBank.GenerateEntryGroup(r.ID, _activeFmgInfo);
}
else if (_activeIDCache == r.ID && _activeEntryGroup == null)
{
_activeEntryGroup = Locator.ActiveProject.FMGBank.GenerateEntryGroup(r.ID, _activeFmgInfo);
_searchFilterCached = "";
}
if (_arrowKeyPressed && ImGui.IsItemFocused()
&& _activeEntryGroup?.ID != r.ID)
{
// Up/Down arrow key selection
_activeEntryGroup = Locator.ActiveProject.FMGBank.GenerateEntryGroup(r.ID, _activeFmgInfo);
_arrowKeyPressed = false;
}
if (doFocus && _activeEntryGroup?.ID == r.ID)
{
ImGui.SetScrollHereY();
doFocus = false;
}
if (ImGui.BeginPopupContextItem())
{
if (ImGui.Selectable("Duplicate Entry"))
{
_activeEntryGroup = Locator.ActiveProject.FMGBank.GenerateEntryGroup(r.ID, _activeFmgInfo);
DuplicateFMGEntries(_activeEntryGroup);
}
if (ImGui.Selectable("Delete Entry"))
{
_activeEntryGroup = Locator.ActiveProject.FMGBank.GenerateEntryGroup(r.ID, _activeFmgInfo);
DeleteFMGEntries(_activeEntryGroup);
}
ImGui.EndPopup();
}
}
}
ImGui.EndChild();
ImGui.End();
ImGui.Begin("Text");
if (_activeEntryGroup == null)
{
ImGui.Text("Select an item to edit text");
}
else
{
ImGui.Columns(2);
ImGui.SetColumnWidth(0, 100 * scale);
ImGui.Text("ID");
ImGui.NextColumn();
_propEditor.PropIDFMG(_activeEntryGroup, _entryLabelCache);
_activeIDCache = _activeEntryGroup.ID;
ImGui.NextColumn();
_propEditor.PropEditorFMGBegin();
if (_activeEntryGroup.TextBody != null)
{
_propEditor.PropEditorFMG(_activeEntryGroup.TextBody, "Text");
}
if (_activeEntryGroup.Title != null)
{
_propEditor.PropEditorFMG(_activeEntryGroup.Title, "Title");
}
if (_activeEntryGroup.Summary != null)
{
_propEditor.PropEditorFMG(_activeEntryGroup.Summary, "Summary");
}
if (_activeEntryGroup.Description != null)
{
_propEditor.PropEditorFMG(_activeEntryGroup.Description, "Description");
}
if (_activeEntryGroup.ExtraText != null)
{
_propEditor.PropEditorFMG(_activeEntryGroup.ExtraText, "Extra");
}
_propEditor.PropEditorFMGEnd();
}
ImGui.End();
}
private void ChangeLanguage(string path)
{
_projectSettings.LastFmgLanguageUsed = path;
_fmgSearchAllString = "";
_filteredFmgInfo.Clear();
ClearTextEditorCache();
ResetActionManager();
Locator.ActiveProject.FMGBank.LoadFMGs(path);
}
}