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