Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
UndoManager.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3
4public class UndoManager
5{
6 public class Item
7 {
8 public List<Task> list = new List<Task>();
9
10 public string name
11 {
12 get
13 {
14 if (list.Count <= 0)
15 {
16 return "none".lang();
17 }
18 return list[0].Name;
19 }
20 }
21
22 public int Count()
23 {
24 int num = 0;
25 foreach (Task item in list)
26 {
27 if (!item.isDestroyed)
28 {
29 num++;
30 }
31 }
32 return num;
33 }
34 }
35
36 public List<Item> items = new List<Item>();
37
38 public Item lastItem => items.LastItem();
39
40 public void Validate()
41 {
42 for (int num = items.Count - 1; num >= 0; num--)
43 {
44 if (items[num].Count() == 0)
45 {
46 items.RemoveAt(num);
47 }
48 }
49 }
50
51 public void NewItem()
52 {
53 items.Add(new Item());
54 if (items.Count > 10)
55 {
56 items.RemoveAt(0);
57 }
58 }
59
60 public void Add(Task t)
61 {
62 lastItem.list.Add(t);
63 }
64
65 public string GetText()
66 {
67 string text = "";
68 text = "tUndo".lang() + Environment.NewLine;
69 if (items.Count == 0)
70 {
71 return text + "tUndoNone".lang();
72 }
73 return text + "tUndoNote".lang(lastItem.Count().ToString() ?? "", lastItem.name ?? "");
74 }
75
76 public void WriteNote(UINote n)
77 {
78 Validate();
79 n.Clear();
80 n.Space(10);
81 n.AddText("NoteText_topic", "tUndo".lang());
82 if (items.Count == 0)
83 {
84 n.AddText("tUndoNone".lang());
85 }
86 else
87 {
88 n.AddText("tUndoNote".lang(lastItem.Count().ToString() ?? "", lastItem.name ?? ""));
89 }
90 n.Build();
91 }
92
93 public void Perform()
94 {
95 Validate();
96 if (items.Count == 0)
97 {
98 SE.Beep();
99 return;
100 }
101 foreach (Task item in lastItem.list)
102 {
103 item.Destroy();
104 }
105 items.Remove(lastItem);
106 SE.Play("trash");
107 }
108}
Definition: Task.cs:4
Definition: UINote.cs:6
void Clear()
Definition: UINote.cs:35
UIItem AddText(string text, FontColor color=FontColor.DontChange)
Definition: UINote.cs:113
void Space(int sizeY=0, int sizeX=1)
Definition: UINote.cs:62
void Build()
Definition: UINote.cs:49
List< Task > list
Definition: UndoManager.cs:8
void WriteNote(UINote n)
Definition: UndoManager.cs:76
Item lastItem
Definition: UndoManager.cs:38
List< Item > items
Definition: UndoManager.cs:36
void Validate()
Definition: UndoManager.cs:40
void Perform()
Definition: UndoManager.cs:93
string GetText()
Definition: UndoManager.cs:65
void Add(Task t)
Definition: UndoManager.cs:60
void NewItem()
Definition: UndoManager.cs:51