Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
WidgetSearch.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using Newtonsoft.Json;
3using UnityEngine;
4
6{
7 public class Extra
8 {
9 [JsonProperty]
10 public string lastSearch;
11
12 [JsonProperty]
13 public List<Word> words;
14 }
15
16 public class Word
17 {
18 [JsonProperty]
19 public string text;
20
21 [JsonProperty]
22 public int type;
23 }
24
25 public static WidgetSearch Instance;
26
27 public HashSet<Card> cards = new HashSet<Card>();
28
29 public static Card selected;
30
31 public CanvasGroup cgResult;
32
34
35 public Extra extra => base.config.extra as Extra;
36
37 public override SearchType type => SearchType.Search;
38
39 public override object CreateExtra()
40 {
41 return new Extra();
42 }
43
44 public override void OnActivate()
45 {
46 base.OnActivate();
47 Instance = this;
48 selected = null;
49 if (extra.words == null)
50 {
51 extra.words = new List<Word>();
52 string[] array = Lang.GetList("search_words");
53 foreach (string text in array)
54 {
55 extra.words.Add(new Word
56 {
57 text = text
58 });
59 }
60 }
63 if (!extra.lastSearch.IsEmpty())
64 {
65 field.text = extra.lastSearch;
66 }
67 }
68
69 public override bool CheckClose()
70 {
71 if (Input.GetKey(KeyCode.LeftControl))
72 {
73 return Input.GetKeyDown(KeyCode.F);
74 }
75 return false;
76 }
77
78 private new void Update()
79 {
81 {
82 EMono.ui.widgets.DeactivateWidget(this);
83 }
84 else
85 {
86 base.Update();
87 }
88 }
89
90 public override void Search(string s)
91 {
92 if (!s.IsEmpty())
93 {
94 extra.lastSearch = s;
95 }
96 s = s.ToLower();
97 buttonClear.SetActive(field.text != "");
98 if (s == lastSearch || s.Length == 0)
99 {
100 return;
101 }
102 lastSearch = s;
103 bool encSearch = s.Length >= 2 && (s[0] == '@' || s[1] == '@');
104 if (encSearch)
105 {
106 s = s.Substring(1);
107 }
108 HashSet<Card> newCards = new HashSet<Card>();
109 if (!s.IsEmpty())
110 {
111 if (!encSearch && (EMono._zone.IsTown || EMono._zone.IsPCFaction || EMono._zone is Zone_Tent))
112 {
113 foreach (Chara chara in EMono._map.charas)
114 {
115 if (chara.IsNeutralOrAbove() && (chara.Name.ToLower().Contains(s) || chara.sourceCard.GetSearchName(jp: false).Contains(s)))
116 {
117 newCards.Add(chara);
118 }
119 }
120 }
122 {
123 foreach (Thing thing2 in EMono._map.things)
124 {
125 if (encSearch)
126 {
127 if (thing2.MatchEncSearch(s))
128 {
129 newCards.Add(thing2);
130 }
131 }
132 else if (thing2.Name.ToLower().Contains(s) || thing2.sourceCard.GetSearchName(jp: false).Contains(s))
133 {
134 newCards.Add(thing2);
135 }
136 }
137 foreach (Card item in EMono._map.props.stocked.all)
138 {
139 if (!(item.parent is Thing thing) || !thing.trait.CanSearchContent)
140 {
141 continue;
142 }
143 if (encSearch)
144 {
145 if (item.MatchEncSearch(s))
146 {
147 newCards.Add(item);
148 }
149 }
150 else if (item.Name.ToLower().Contains(s) || item.sourceCard.GetSearchName(jp: false).Contains(s))
151 {
152 newCards.Add(item);
153 }
154 }
155 }
156 for (int i = 0; i < 2; i++)
157 {
158 foreach (Chara chara2 in EMono._map.charas)
159 {
160 if ((i == 0 && chara2 == EMono.pc) || (i == 1 && chara2 != EMono.pc) || !chara2.IsPCFactionOrMinion)
161 {
162 continue;
163 }
164 chara2.things.Foreach(delegate(Thing t)
165 {
166 if (!((t.parent as Card)?.trait is TraitChestMerchant))
167 {
168 if (encSearch)
169 {
170 if (t.MatchEncSearch(s))
171 {
172 newCards.Add(t);
173 }
174 }
175 else if (t.Name.ToLower().Contains(s) || t.source.GetSearchName(jp: false).Contains(s))
176 {
177 newCards.Add(t);
178 }
179 }
180 });
181 }
182 }
183 }
184 if (!newCards.SetEquals(cards))
185 {
186 cards = newCards;
187 RefreshList();
188 }
189 cgResult.alpha = ((list.ItemCount > 0) ? 1f : 0f);
190 }
191
192 public void RefreshWords()
193 {
194 listWords.callbacks = new UIList.Callback<Word, UIItem>
195 {
196 onClick = delegate(Word a, UIItem b)
197 {
198 if (a.type == 1)
199 {
200 if (field.text.IsEmpty())
201 {
202 SE.BeepSmall();
203 }
204 else
205 {
206 SE.ClickOk();
207 extra.words.Add(new Word
208 {
209 text = field.text
210 });
211 listWords.List();
212 }
213 }
214 else
215 {
216 field.text = a.text;
217 SE.Tab();
218 }
219 },
220 onInstantiate = delegate(Word a, UIItem b)
221 {
223 b.button2.SetActive(a.type != 1);
224 b.button2.SetOnClick(delegate
225 {
226 extra.words.Remove(a);
227 SE.Trash();
228 listWords.List();
229 });
230 },
231 onList = delegate
232 {
233 foreach (Word word in extra.words)
234 {
235 listWords.Add(word);
236 }
237 if (extra.words.Count < 10)
238 {
239 listWords.Add(new Word
240 {
241 text = "add_search_word".lang(),
242 type = 1
243 });
244 }
245 }
246 };
247 listWords.List();
248 }
249
250 public override void RefreshList()
251 {
253 selected = null;
254 list.callbacks = new UIList.Callback<Card, ButtonGrid>
255 {
256 onClick = delegate(Card a, ButtonGrid b)
257 {
258 Card rootCard = a.GetRootCard();
259 if (rootCard == EMono.pc)
260 {
262 selected = a;
263 SE.Click();
264 }
265 else if (EMono.pc.ai.IsNoGoal)
266 {
267 if (a.isDestroyed || !rootCard.pos.IsValid)
268 {
269 SE.Beep();
270 Search(field.text);
271 }
272 else
273 {
274 SE.Click();
275 selected = null;
276 EMono.pc.SetAIImmediate(new AI_Goto(rootCard.pos.Copy(), 0));
278 Close();
279 }
280 }
281 else
282 {
283 SE.Beep();
284 }
285 },
286 onRedraw = delegate(Card a, ButtonGrid b, int i)
287 {
288 b.SetCard(a, ButtonGrid.Mode.Search);
289 },
290 onList = delegate
291 {
292 foreach (Card card in cards)
293 {
294 list.Add(card);
295 }
296 }
297 };
298 list.List();
299 list.dsv.OnResize();
300 }
301
302 public override void OnDeactivate()
303 {
304 base.OnDeactivate();
305 if (field.text.IsEmpty())
306 {
307 extra.lastSearch = "";
308 }
310 }
311}
if(item3.idFile==idFirstFile &&item3.id==idFirstTopic)
Definition: UIBook.cs:627
virtual bool IsNoGoal
Definition: AIAct.cs:74
void SetTurbo(int mtp=-1)
Definition: AM_Adv.cs:1040
bool IsFuncPressed(CoreConfig.GameFunc func)
Definition: ActionMode.cs:1071
static AM_Adv Adv
Definition: ActionMode.cs:15
void SetCard(Card c, Mode mode=Mode.Default, Action< UINote > onWriteNote=null)
Definition: ButtonGrid.cs:184
Definition: Card.cs:11
bool isDestroyed
Definition: Card.cs:71
bool IsPCFactionOrMinion
Definition: Card.cs:2132
string Name
Definition: Card.cs:2013
ICardParent parent
Definition: Card.cs:51
Point pos
Definition: Card.cs:55
ThingContainer things
Definition: Card.cs:34
Card GetRootCard()
Definition: Card.cs:3173
Definition: Chara.cs:10
AIAct ai
Definition: Chara.cs:187
bool IsNeutralOrAbove()
Definition: Chara.cs:5928
void SetAIImmediate(AIAct g)
Definition: Chara.cs:8077
override CardRow sourceCard
Definition: Chara.cs:435
Definition: EMono.cs:4
static Chara pc
Definition: EMono.cs:13
static Zone _zone
Definition: EMono.cs:19
static Scene scene
Definition: EMono.cs:27
static UI ui
Definition: EMono.cs:15
static Map _map
Definition: EMono.cs:17
Definition: Lang.cs:6
static string[] GetList(string id)
Definition: Lang.cs:114
static void SetDirtyAll(bool immediate=false)
List< Thing > things
Definition: Map.cs:49
PropsManager props
Definition: Map.cs:91
List< Chara > charas
Definition: Map.cs:81
Point Copy()
Definition: Point.cs:467
bool IsValid
Definition: Point.cs:88
PropsStocked stocked
Definition: PropsManager.cs:6
PropSet all
Definition: Props.cs:8
virtual string GetSearchName(bool jp)
Definition: RenderRow.cs:130
ActionMode actionMode
Definition: Scene.cs:77
void Foreach(Action< Thing > action, bool onlyAccessible=true)
Definition: Thing.cs:8
SourceThing.Row source
Definition: Thing.cs:11
override bool MatchEncSearch(string s)
Definition: Thing.cs:2009
override CardRow sourceCard
Definition: Thing.cs:47
UIText mainText
Definition: UIButton.cs:102
Definition: UIItem.cs:5
UIButton button1
Definition: UIItem.cs:18
UIButton button2
Definition: UIItem.cs:20
Definition: UIList.cs:9
override void Add(object item)
Definition: UIList.cs:302
override void List()
Definition: UIList.cs:717
void SetText(string s)
Definition: UIText.cs:159
InputField field
Definition: WidgetCodex.cs:13
string lastSearch
Definition: WidgetCodex.cs:21
UIButton buttonClear
Definition: WidgetCodex.cs:23
List< Word > words
Definition: WidgetSearch.cs:13
override void Search(string s)
Definition: WidgetSearch.cs:90
override SearchType type
Definition: WidgetSearch.cs:37
override void RefreshList()
static WidgetSearch Instance
Definition: WidgetSearch.cs:25
new void Update()
Definition: WidgetSearch.cs:78
static Card selected
Definition: WidgetSearch.cs:29
CanvasGroup cgResult
Definition: WidgetSearch.cs:31
void RefreshWords()
override object CreateExtra()
Definition: WidgetSearch.cs:39
HashSet< Card > cards
Definition: WidgetSearch.cs:27
override void OnActivate()
Definition: WidgetSearch.cs:44
UIList listWords
Definition: WidgetSearch.cs:33
override void OnDeactivate()
override bool CheckClose()
Definition: WidgetSearch.cs:69
virtual bool IsTown
Definition: Zone.cs:220
bool IsPCFaction
Definition: Zone.cs:464