Elin Decompiled Documentation EA 23.167 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();
90 if (lastZone != EMono._zone || isDirty)
91 {
92 lastSearch = "";
93 Search(field.text);
94 isDirty = false;
95 }
96 }
97
98 public void RefreshSearch()
99 {
100 SE.Tab();
101 lastSearch = "";
102 Search(field.text);
103 }
104
105 public override void Search(string s)
106 {
107 if (!s.IsEmpty())
108 {
109 extra.lastSearch = s;
110 }
111 s = s.ToLower();
112 if (!buttonClear)
113 {
114 return;
115 }
116 buttonClear.SetActive(field.text != "");
117 buttonRefresh.SetActive(field.text != "");
118 if (s == lastSearch || s.Length == 0)
119 {
120 return;
121 }
122 lastSearch = s;
124 bool encSearch = s.Length >= 2 && (s[0] == '@' || s[0] == '@');
125 if (encSearch)
126 {
127 s = s.Substring(1);
128 }
129 HashSet<Card> newCards = new HashSet<Card>();
130 if (!s.IsEmpty())
131 {
132 if (!encSearch && (EMono._zone.IsTown || EMono._zone.HasLaw || EMono._zone.IsPCFaction || EMono._zone is Zone_Tent))
133 {
134 foreach (Chara chara in EMono._map.charas)
135 {
136 if (chara.IsNeutralOrAbove() && (chara.Name.ToLower().Contains(s) || chara.sourceCard.GetSearchName(jp: false).Contains(s)))
137 {
138 newCards.Add(chara);
139 }
140 }
141 }
143 {
144 foreach (Thing thing2 in EMono._map.things)
145 {
146 if (encSearch)
147 {
148 if (thing2.MatchEncSearch(s))
149 {
150 newCards.Add(thing2);
151 }
152 }
153 else if (thing2.Name.ToLower().Contains(s) || thing2.sourceCard.GetSearchName(jp: false).Contains(s))
154 {
155 newCards.Add(thing2);
156 }
157 }
158 foreach (Card item in EMono._map.props.stocked.all)
159 {
160 if (!(item.parent is Thing thing) || !thing.trait.CanSearchContent)
161 {
162 continue;
163 }
164 if (encSearch)
165 {
166 if (item.MatchEncSearch(s))
167 {
168 newCards.Add(item);
169 }
170 }
171 else if (item.Name.ToLower().Contains(s) || item.sourceCard.GetSearchName(jp: false).Contains(s))
172 {
173 newCards.Add(item);
174 }
175 }
176 }
177 for (int i = 0; i < 2; i++)
178 {
179 foreach (Chara chara2 in EMono._map.charas)
180 {
181 if ((i == 0 && chara2 == EMono.pc) || (i == 1 && chara2 != EMono.pc) || !chara2.IsPCFactionOrMinion)
182 {
183 continue;
184 }
185 chara2.things.Foreach(delegate(Thing t)
186 {
187 if (!((t.parent as Card)?.trait is TraitChestMerchant))
188 {
189 if (encSearch)
190 {
191 if (t.MatchEncSearch(s))
192 {
193 newCards.Add(t);
194 }
195 }
196 else if (t.Name.ToLower().Contains(s) || t.source.GetSearchName(jp: false).Contains(s))
197 {
198 newCards.Add(t);
199 }
200 }
201 });
202 }
203 }
204 }
205 if (!newCards.SetEquals(cards))
206 {
207 cards = newCards;
208 RefreshList();
209 }
210 cgResult.alpha = ((list.ItemCount > 0) ? 1f : 0f);
211 }
212
213 public void RefreshWords()
214 {
215 listWords.callbacks = new UIList.Callback<Word, UIItem>
216 {
217 onClick = delegate(Word a, UIItem b)
218 {
219 if (a.type == 1)
220 {
221 if (field.text.IsEmpty())
222 {
223 SE.BeepSmall();
224 }
225 else
226 {
227 SE.ClickOk();
228 extra.words.Add(new Word
229 {
230 text = field.text
231 });
232 listWords.List();
233 }
234 }
235 else
236 {
237 field.text = a.text;
238 SE.Tab();
239 }
240 },
241 onInstantiate = delegate(Word a, UIItem b)
242 {
244 b.button2.SetActive(a.type != 1);
245 b.button2.SetOnClick(delegate
246 {
247 extra.words.Remove(a);
248 SE.Trash();
249 listWords.List();
250 });
251 },
252 onList = delegate
253 {
254 foreach (Word word in extra.words)
255 {
256 listWords.Add(word);
257 }
258 if (extra.words.Count < 10)
259 {
260 listWords.Add(new Word
261 {
262 text = "add_search_word".lang(),
263 type = 1
264 });
265 }
266 }
267 };
268 listWords.List();
269 }
270
271 public override void RefreshList()
272 {
274 selected = null;
275 list.callbacks = new UIList.Callback<Card, ButtonGrid>
276 {
277 onClick = delegate(Card a, ButtonGrid b)
278 {
279 Card rootCard = a.GetRootCard();
280 if (rootCard == EMono.pc)
281 {
283 selected = a;
284 SE.Click();
285 }
286 else if (EMono.pc.ai.IsNoGoal)
287 {
288 if (a.isDestroyed || !rootCard.pos.IsValid)
289 {
290 SE.Beep();
291 Search(field.text);
292 }
293 else
294 {
295 SE.Click();
296 selected = null;
297 EMono.pc.SetAIImmediate(new AI_Goto(rootCard.pos.Copy(), 0));
299 }
300 }
301 else
302 {
303 SE.Beep();
304 }
305 },
306 onRedraw = delegate(Card a, ButtonGrid b, int i)
307 {
308 if (a.isDestroyed)
309 {
310 isDirty = true;
311 }
312 b.SetCard(a, ButtonGrid.Mode.Search);
313 },
314 onList = delegate
315 {
316 foreach (Card card in cards)
317 {
318 list.Add(card);
319 }
320 }
321 };
322 list.List();
323 list.dsv.OnResize();
324 }
325
326 public override void OnDeactivate()
327 {
328 base.OnDeactivate();
329 if (field.text.IsEmpty())
330 {
331 extra.lastSearch = "";
332 }
334 }
335}
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:2208
string Name
Definition: Card.cs:2073
ICardParent parent
Definition: Card.cs:51
Point pos
Definition: Card.cs:55
ThingContainer things
Definition: Card.cs:34
Card GetRootCard()
Definition: Card.cs:3287
Definition: Chara.cs:10
AIAct ai
Definition: Chara.cs:198
bool IsNeutralOrAbove()
Definition: Chara.cs:6085
void SetAIImmediate(AIAct g)
Definition: Chara.cs:8228
override CardRow sourceCard
Definition: Chara.cs:446
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:479
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:2037
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 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()
Definition: WidgetSearch.cs:98
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:226
virtual bool IsTown
Definition: Zone.cs:220
bool IsPCFaction
Definition: Zone.cs:466