Elin Decompiled Documentation EA 23.102 Nightly
Loading...
Searching...
No Matches
LayerNewspaper.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using UnityEngine;
5using UnityEngine.UI;
6
7public class LayerNewspaper : ELayer
8{
10
12
14
16
18
20
22
24
25 public Image imageHeadline;
26
27 public Image imageAdRight;
28
29 public Image moldAdBottom;
30
31 public List<Sprite> spritesAd;
32
33 public List<Sprite> spritesSmallAd;
34
35 public List<Sprite> spritesHeadline;
36
37 public LayoutGroup layoutAdBottom;
38
39 public LayoutGroup layoutPortrait;
40
42
43 public List<string> desiredNews;
44
46
47 public GameObject goTop;
48
49 public GameObject goBack;
50
51 public Sprite spriteComicBig;
52
53 public bool topPage;
54
55 private int seed;
56
58
59 public override void OnInit()
60 {
62 {
63 NewsList.dict = null;
65 }
66 seed = (ELayer.debug.enable ? (-1) : ELayer.world.dayData.seed);
67 Rand.UseSeed(seed, delegate
68 {
69 imageAdRight.sprite = spritesAd.RandomItem();
70 imageAdRight.SetNativeSize();
71 });
72 textDate.text = "news_date".lang(Lang.GetList("monthEng")[ELayer.world.date.month - 1], ELayer.world.date.day.ToString() ?? "", ELayer.world.date.year.ToString() ?? "");
73 int luck = (int)ELayer.world.dayData.luck;
74 textFortune.text = "news_tellLuck".lang(Lang.GetList("dayLuck")[luck], Lang.GetList("dayLuck2")[luck]);
75 RefreshAD();
81 }
82
83 public void OnClickPage()
84 {
86 buttonPage.mainText.SetText((topPage ? "news_firstPage" : "news_secondPage").lang());
87 SE.Play("click_scroll");
89 }
90
91 public void RefreshPage()
92 {
93 goTop.SetActive(topPage);
94 goBack.SetActive(!topPage);
95 }
96
97 public void OnClickComic()
98 {
99 SE.Play("click_recipe");
100 ELayer.ui.AddLayer<LayerImage>().SetImage(spriteComicBig);
101 }
102
103 public async void RefreshNews()
104 {
105 moldPortrait = layoutPortrait.CreateMold<Portrait>();
106 List<NewsList.Item> list = NewsList.GetNews(seed);
107 if (desiredNews.Count > 0)
108 {
109 for (int i = 0; i < desiredNews.Count; i++)
110 {
111 foreach (NewsList.Item item2 in NewsList.listAll)
112 {
113 if (item2.title.Contains(desiredNews[i]))
114 {
115 list[i] = item2;
116 break;
117 }
118 }
119 }
120 }
121 listNews.callbacks = new UIList.Callback<NewsList.Item, UIItem>
122 {
123 onInstantiate = delegate(NewsList.Item a, UIItem b)
124 {
125 b.text1.text = a.title;
126 b.text2.SetText(a.content);
127 },
128 onList = delegate
129 {
130 foreach (NewsList.Item item3 in list)
131 {
132 listNews.Add(item3);
133 }
134 }
135 };
136 listNews.List();
137 Rand.UseSeed(seed, delegate
138 {
139 imageHeadline.sprite = spritesHeadline.RandomItem();
140 });
141 foreach (NewsList.Item item4 in list)
142 {
143 List<string> listImageId = item4.listImageId;
144 if (listImageId.Count == 0)
145 {
146 continue;
147 }
148 Sprite sprite = Resources.Load<Sprite>("UI/Layer/LayerNewspaper/Headline/headline_" + listImageId[0]);
149 if (!sprite)
150 {
151 continue;
152 }
153 imageHeadline.sprite = sprite;
154 if (listImageId.Count <= 1)
155 {
156 break;
157 }
158 for (int j = 1; j < listImageId.Count; j++)
159 {
160 ModItem<Sprite> item = Portrait.modPortraits.GetItem(listImageId[j], returnNull: true);
161 if (item != null)
162 {
163 Util.Instantiate(moldPortrait, layoutPortrait).SetPortrait(item.id);
164 }
165 }
166 layoutPortrait.RebuildLayout();
167 break;
168 }
169 }
170
171 public void RefreshAD()
172 {
174 moldAdBottom = layoutAdBottom.CreateMold<Image>();
175 float num = layoutAdBottom.Rect().sizeDelta.x - 20f;
176 IList<Sprite> list = spritesSmallAd.Copy().Shuffle();
177 for (int i = 0; i < list.Count; i++)
178 {
179 Sprite sprite = list[i];
180 if (num > sprite.textureRect.width)
181 {
182 Image image = Util.Instantiate(moldAdBottom, layoutAdBottom);
183 num = num - sprite.textureRect.width - 5f;
184 image.sprite = sprite;
185 image.SetNativeSize();
186 }
187 }
188 layoutAdBottom.RebuildLayout();
189 Rand.SetSeed();
190 }
191
192 public async void RefreshChat()
193 {
194 List<Net.ChatLog> logs = await Net.GetChat(ChatCategory.Test, Lang.langCode);
195 if (isDestroyed || logs.Count == 0)
196 {
197 return;
198 }
199 listChat.callbacks = new UIList.Callback<Net.ChatLog, UIItem>
200 {
201 onInstantiate = delegate(Net.ChatLog a, UIItem b)
202 {
203 b.text1.SetText(a.msg);
204 },
205 onList = delegate
206 {
207 foreach (Net.ChatLog item in logs)
208 {
210 }
211 }
212 };
213 listChat.List();
214 }
215
216 public async void RefreshVote()
217 {
218 List<Net.VoteLog> logs = await Net.GetVote(Lang.langCode);
219 if (isDestroyed || logs.Count == 0)
220 {
221 return;
222 }
223 textVote.SetText(logs[0].name.StripBrackets());
224 int num = (int)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
225 int num2 = (logs[0].time - num) / 60 / 60 / 24;
226 textVoteRemaining.SetText("news_voteLeft".lang(num2.ToString() ?? ""));
227 logs.RemoveAt(0);
228 logs.Sort((Net.VoteLog a, Net.VoteLog b) => b.count - a.count);
229 listVote.callbacks = new UIList.Callback<Net.VoteLog, UIItem>
230 {
231 onInstantiate = delegate(Net.VoteLog a, UIItem b)
232 {
233 b.text1.SetText(a.name);
234 b.text2.SetText(a.count.ToString() ?? "");
235 b.button1.SetOnClick(delegate
236 {
237 SE.Click();
238 Net.SendVote(a.index, Lang.langCode);
239 a.count++;
240 b.text2.SetText(a.count.ToString() ?? "");
241 foreach (UIList.ButtonPair button in listVote.buttons)
242 {
243 (button.component as UIItem).button1.SetActive(enable: false);
244 }
245 });
246 },
247 onList = delegate
248 {
249 foreach (Net.VoteLog item in logs)
250 {
252 }
253 }
254 };
255 listVote.List();
256 }
257
258 public void RefreshWeather()
259 {
261 listWeather.callbacks = new UIList.Callback<Weather.WeatherForecast, UIItem>
262 {
263 onInstantiate = delegate(Weather.WeatherForecast a, UIItem b)
264 {
265 string text = a.date.month + "/" + a.date.day;
266 foreach (KeyValuePair<Weather.Condition, int> item in a.cons.OrderByDescending((KeyValuePair<Weather.Condition, int> a) => a.Value))
267 {
268 if (b.image1.sprite == null)
269 {
270 b.image1.sprite = ELayer.core.refs.icons.weather[item.Key];
271 }
272 else if (b.image2.sprite == null)
273 {
274 b.image2.sprite = ELayer.core.refs.icons.weather[item.Key];
275 b.image2.SetActive(enable: true);
276 }
277 }
278 b.text1.text = text;
279 },
280 onList = delegate
281 {
282 for (int i = 0; i < 7; i++)
283 {
284 if (list.Count > i && list[i].cons.Count > 0)
285 {
286 listWeather.Add(list[i]);
287 }
288 }
289 }
290 };
292 }
293}
ChatCategory
Definition: ChatCategory.cs:2
bool enable
Definition: CoreDebug.cs:285
UDIconWeather weather
Definition: CoreRef.cs:134
Icons icons
Definition: CoreRef.cs:339
CoreRef refs
Definition: Core.cs:51
int day
Definition: Date.cs:62
int year
Definition: Date.cs:38
Luck luck
Definition: DayData.cs:15
int seed
Definition: DayData.cs:17
Definition: ELayer.cs:4
static World world
Definition: ELayer.cs:39
static Core core
Definition: ELayer.cs:7
static CoreDebug debug
Definition: ELayer.cs:43
static UI ui
Definition: ELayer.cs:21
Definition: Lang.cs:6
static string langCode
Definition: Lang.cs:28
static string[] GetList(string id)
Definition: Lang.cs:114
List< Sprite > spritesHeadline
List< string > desiredNews
async void RefreshVote()
UIText textVoteRemaining
List< Sprite > spritesAd
LayoutGroup layoutAdBottom
UIButton buttonPage
List< Sprite > spritesSmallAd
async void RefreshChat()
Portrait moldPortrait
Sprite spriteComicBig
GameObject goBack
LayoutGroup layoutPortrait
async void RefreshNews()
GameObject goTop
override void OnInit()
bool isDestroyed
Definition: Layer.cs:98
ModItem< T > GetItem(string id, bool returnNull=false)
Definition: ModItemList.cs:61
Definition: Net.cs:11
static async UniTask< List< VoteLog > > GetVote(string idLang)
Definition: Net.cs:255
static async UniTask< List< ChatLog > > GetChat(ChatCategory cat, string idLang)
Definition: Net.cs:350
static async UniTask< bool > SendVote(int id, string idLang)
Definition: Net.cs:227
static List< Item > GetNews(int seed)
Definition: NewsList.cs:80
static List< Item > listAll
Definition: NewsList.cs:17
static ModItemList< Sprite > modPortraits
Definition: Portrait.cs:12
Definition: Rand.cs:4
static void UseSeed(int seed, Action action)
Definition: Rand.cs:22
static void SetSeed(int a=-1)
Definition: Rand.cs:37
UIText mainText
Definition: UIButton.cs:102
Definition: UIItem.cs:5
Image image2
Definition: UIItem.cs:16
UIButton button1
Definition: UIItem.cs:18
Image image1
Definition: UIItem.cs:14
UIText text2
Definition: UIItem.cs:8
UIText text1
Definition: UIItem.cs:6
Definition: UIList.cs:9
List< ButtonPair > buttons
Definition: UIList.cs:244
override void Add(object item)
Definition: UIList.cs:302
override void List()
Definition: UIList.cs:717
Definition: UIText.cs:6
string lang
Definition: UIText.cs:9
void SetText(string s)
Definition: UIText.cs:159
List< WeatherForecast > GetWeatherForecast()
Definition: Weather.cs:215
void CreateDayData()
Definition: World.cs:43
GameDate date
Definition: World.cs:6
DayData dayData
Definition: World.cs:18
Weather weather
Definition: World.cs:12