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