Elin Decompiled Documentation EA 23.331 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 Zone lastZone;
36
37 private bool isDirty;
38
39 public Extra extra => base.config.extra as Extra;
40
41 public override SearchType type => SearchType.Search;
42
43 public override object CreateExtra()
44 {
45 return new Extra();
46 }
47
48 public override void OnActivate()
49 {
50 base.OnActivate();
51 Instance = this;
52 selected = null;
53 if (extra.words == null)
54 {
55 extra.words = new List<Word>();
56 string[] array = Lang.GetList("search_words");
57 foreach (string text in array)
58 {
59 extra.words.Add(new Word
60 {
61 text = text
62 });
63 }
64 }
67 if (!extra.lastSearch.IsEmpty())
68 {
69 field.text = extra.lastSearch;
70 }
71 }
72
73 public override bool CheckClose()
74 {
75 if (Input.GetKey(KeyCode.LeftControl))
76 {
77 return Input.GetKeyDown(KeyCode.F);
78 }
79 return false;
80 }
81
82 private new void Update()
83 {
85 {
86 EMono.ui.widgets.DeactivateWidget(this);
87 return;
88 }
89 base.Update();
91 {
92 selected = null;
93 isDirty = true;
94 }
95 if (lastZone != EMono._zone || isDirty)
96 {
97 lastSearch = "";
98 Search(field.text);
99 isDirty = false;
100 }
101 }
102
103 public void RefreshSearch()
104 {
105 SE.Tab();
106 lastSearch = "";
107 Search(field.text);
108 }
109
110 public override void Search(string s)
111 {
112 if (!s.IsEmpty())
113 {
114 extra.lastSearch = s;
115 }
116 s = s.ToLower();
117 if (!buttonClear)
118 {
119 return;
120 }
121 buttonClear.SetActive(field.text != "");
122 buttonRefresh.SetActive(field.text != "");
123 if (s == lastSearch || s.Length == 0)
124 {
125 return;
126 }
127 lastSearch = s;
129 bool encSearch = s.Length >= 2 && (s[0] == '@' || s[0] == '@');
130 if (encSearch)
131 {
132 s = s.Substring(1);
133 }
134 HashSet<Card> newCards = new HashSet<Card>();
135 if (!s.IsEmpty())
136 {
137 if (!encSearch && (EMono._zone.IsTown || EMono._zone.HasLaw || EMono._zone.IsPCFaction || EMono._zone is Zone_Tent))
138 {
139 foreach (Chara chara in EMono._map.charas)
140 {
141 if (chara.IsNeutralOrAbove() && (chara.mimicry == null || chara.IsPCFactionOrMinion || EMono.debug.showExtra) && (chara.Name.ToLower().Contains(s) || chara.sourceCard.GetSearchName(jp: false).Contains(s)))
142 {
143 newCards.Add(chara);
144 }
145 }
146 }
148 {
149 foreach (Thing thing2 in EMono._map.things)
150 {
151 if (encSearch)
152 {
153 if (thing2.MatchEncSearch(s))
154 {
155 newCards.Add(thing2);
156 }
157 }
158 else if (thing2.Name.ToLower().Contains(s) || thing2.sourceCard.GetSearchName(jp: false).Contains(s))
159 {
160 newCards.Add(thing2);
161 }
162 }
163 foreach (Card item in EMono._map.props.stocked.all)
164 {
165 if (!(item.parent is Thing thing) || !thing.trait.CanSearchContent)
166 {
167 continue;
168 }
169 if (encSearch)
170 {
171 if (item.MatchEncSearch(s))
172 {
173 newCards.Add(item);
174 }
175 }
176 else if (item.Name.ToLower().Contains(s) || item.sourceCard.GetSearchName(jp: false).Contains(s))
177 {
178 newCards.Add(item);
179 }
180 }
181 }
182 for (int i = 0; i < 2; i++)
183 {
184 foreach (Chara chara2 in EMono._map.charas)
185 {
186 if ((i == 0 && chara2 == EMono.pc) || (i == 1 && chara2 != EMono.pc) || !chara2.IsPCFactionOrMinion)
187 {
188 continue;
189 }
190 chara2.things.Foreach(delegate(Thing t)
191 {
192 if (!((t.parent as Card)?.trait is TraitChestMerchant))
193 {
194 if (encSearch)
195 {
196 if (t.MatchEncSearch(s))
197 {
198 newCards.Add(t);
199 }
200 }
201 else if (t.Name.ToLower().Contains(s) || t.source.GetSearchName(jp: false).Contains(s))
202 {
203 newCards.Add(t);
204 }
205 }
206 });
207 }
208 }
209 }
210 if (!newCards.SetEquals(cards))
211 {
212 cards = newCards;
213 RefreshList();
214 }
215 cgResult.alpha = ((list.ItemCount > 0) ? 1f : 0f);
216 }
217
218 public void RefreshWords()
219 {
220 listWords.callbacks = new UIList.Callback<Word, UIItem>
221 {
222 onClick = delegate(Word a, UIItem b)
223 {
224 if (a.type == 1)
225 {
226 if (field.text.IsEmpty())
227 {
228 SE.BeepSmall();
229 }
230 else
231 {
232 SE.ClickOk();
233 extra.words.Add(new Word
234 {
235 text = field.text
236 });
237 listWords.List();
238 }
239 }
240 else
241 {
242 field.text = a.text;
243 SE.Tab();
244 }
245 },
246 onInstantiate = delegate(Word a, UIItem b)
247 {
249 b.button2.SetActive(a.type != 1);
250 b.button2.SetOnClick(delegate
251 {
252 extra.words.Remove(a);
253 SE.Trash();
254 listWords.List();
255 });
256 },
257 onList = delegate
258 {
259 foreach (Word word in extra.words)
260 {
261 listWords.Add(word);
262 }
263 if (extra.words.Count < 10)
264 {
265 listWords.Add(new Word
266 {
267 text = "add_search_word".lang(),
268 type = 1
269 });
270 }
271 }
272 };
273 listWords.List();
274 }
275
276 public override void RefreshList()
277 {
279 selected = null;
280 list.callbacks = new UIList.Callback<Card, ButtonGrid>
281 {
282 onClick = delegate(Card a, ButtonGrid b)
283 {
284 Card rootCard = a.GetRootCard();
285 if (rootCard == EMono.pc)
286 {
288 selected = a;
289 SE.Click();
290 }
291 else if (EMono.pc.ai.IsNoGoal)
292 {
293 if (a.isDestroyed || !rootCard.pos.IsValid)
294 {
295 SE.Beep();
296 Search(field.text);
297 }
298 else
299 {
300 SE.Click();
301 selected = null;
302 EMono.pc.SetAIImmediate(new AI_Goto(rootCard.pos.Copy(), 0));
304 }
305 }
306 else
307 {
308 SE.Beep();
309 }
310 },
311 onRedraw = delegate(Card a, ButtonGrid b, int i)
312 {
313 if (a.isDestroyed)
314 {
315 isDirty = true;
316 }
317 b.SetCard(a, ButtonGrid.Mode.Search);
318 },
319 onList = delegate
320 {
321 foreach (Card card in cards)
322 {
323 list.Add(card);
324 }
325 }
326 };
327 list.List();
328 list.dsv.OnResize();
329 }
330
331 public override void OnDeactivate()
332 {
333 base.OnDeactivate();
334 if (field.text.IsEmpty())
335 {
336 extra.lastSearch = "";
337 }
339 }
340}
if(!match.Success)
virtual bool IsNoGoal
Definition: AIAct.cs:74
void SetTurbo(int mtp=-1)
Definition: AM_Adv.cs:1086
bool IsFuncPressed(CoreConfig.GameFunc func)
Definition: ActionMode.cs:1101
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:78
bool IsPCFactionOrMinion
Definition: Card.cs:2342
virtual Chara Chara
Definition: Card.cs:2122
string Name
Definition: Card.cs:2191
ICardParent parent
Definition: Card.cs:56
Point pos
Definition: Card.cs:60
ThingContainer things
Definition: Card.cs:39
virtual bool isChara
Definition: Card.cs:2135
Card GetRootCard()
Definition: Card.cs:3600
Definition: Chara.cs:10
override bool IsAliveInCurrentZone
Definition: Chara.cs:567
AIAct ai
Definition: Chara.cs:206
bool IsNeutralOrAbove()
Definition: Chara.cs:6901
void SetAIImmediate(AIAct g)
Definition: Chara.cs:9425
override CardRow sourceCard
Definition: Chara.cs:454
ConBaseTransmuteMimic mimicry
Definition: Chara.cs:106
bool showExtra
Definition: CoreDebug.cs:183
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
static CoreDebug debug
Definition: EMono.cs:45
Definition: Lang.cs:7
static string[] GetList(string id)
Definition: Lang.cs:113
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:491
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:79
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:2182
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:354
override void List()
Definition: UIList.cs:769
void SetText(string s)
Definition: UIText.cs:163
InputField field
Definition: WidgetCodex.cs:13
string lastSearch
Definition: WidgetCodex.cs:21
UIButton buttonRefresh
Definition: WidgetCodex.cs:25
UIButton buttonClear
Definition: WidgetCodex.cs:23
List< Word > words
Definition: WidgetSearch.cs:13
override void Search(string s)
override SearchType type
Definition: WidgetSearch.cs:41
void RefreshSearch()
override void RefreshList()
static WidgetSearch Instance
Definition: WidgetSearch.cs:25
new void Update()
Definition: WidgetSearch.cs:82
static Card selected
Definition: WidgetSearch.cs:29
CanvasGroup cgResult
Definition: WidgetSearch.cs:31
void RefreshWords()
override object CreateExtra()
Definition: WidgetSearch.cs:43
HashSet< Card > cards
Definition: WidgetSearch.cs:27
override void OnActivate()
Definition: WidgetSearch.cs:48
UIList listWords
Definition: WidgetSearch.cs:33
override void OnDeactivate()
override bool CheckClose()
Definition: WidgetSearch.cs:73
Definition: Zone.cs:12
virtual bool HasLaw
Definition: Zone.cs:233
virtual bool IsTown
Definition: Zone.cs:227
bool IsPCFaction
Definition: Zone.cs:477