Elin Decompiled Documentation EA 23.264 Nightly
Loading...
Searching...
No Matches
ContentGallery.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.IO;
3using System.Linq;
4using UnityEngine;
5using UnityEngine.UI;
6
7public class ContentGallery : EContent
8{
9 public class Page : UIBook.Page
10 {
11 public class Item
12 {
13 public int id;
14 }
15
16 public List<string> ids = new List<string>();
17
18 public override void BuildNote(UINote n, string idTopic)
19 {
20 foreach (string id in ids)
21 {
22 int idx = id.ToInt();
23 string path = GalleryFlattenAndRename.root + "/" + EClass.core.refs.dictSketches2[idx];
24 if (!File.Exists(path))
25 {
26 EClass.ui.Say("Full Image not found: " + path);
27 continue;
28 }
29 if (!File.Exists(path + "_t"))
30 {
31 EClass.ui.Say("Thumbnail not found: " + path);
32 continue;
33 }
34 UIItem uIItem = n.AddItem("ItemGallery");
35 Sprite sprite = sprites.TryGetValue(idx);
36 if (!sprite)
37 {
38 Texture2D texture2D = IO.LoadPNG(path + "_t");
39 sprite = Sprite.Create(texture2D, new Rect(0f, 0f, texture2D.width, texture2D.height), new Vector2(0.5f, 0.5f));
40 sprites[idx] = sprite;
41 }
42 uIItem.image1.sprite = sprite;
43 uIItem.text1.text = "#" + id;
44 uIItem.button1.SetOnClick(delegate
45 {
46 Debug.Log(path);
47 SE.Play("click_recipe");
48 Sprite sprite2 = spritesFull.TryGetValue(idx);
49 if (!sprite2)
50 {
51 Texture2D texture2D2 = IO.LoadPNG(path, FilterMode.Trilinear);
52 sprite2 = Sprite.Create(texture2D2, new Rect(0f, 0f, texture2D2.width, texture2D2.height), new Vector2(0.5f, 0.5f));
53 spritesFull[idx] = sprite2;
54 }
55 EClass.ui.AddLayer<LayerImage>().SetImage(sprite2);
56 });
57 }
58 }
59 }
60
61 public static int lastPage;
62
63 public static bool listMode;
64
65 public static Dictionary<int, Sprite> sprites = new Dictionary<int, Sprite>();
66
67 public static Dictionary<int, Sprite> spritesFull = new Dictionary<int, Sprite>();
68
69 public Transform transBig;
70
71 public Image imageBig;
72
73 public UIBook book;
74
76
77 public GridLayoutGroup[] grids;
78
79 public Vector2[] gridSize;
80
81 private bool first = true;
82
83 public override void OnSwitchContent(int idTab)
84 {
85 if (!first)
86 {
87 return;
88 }
90 {
91 EClass.player.sketches.Clear();
92 foreach (int key in EClass.core.refs.dictSketches2.Keys)
93 {
94 EClass.player.sketches.Add(key);
95 }
96 }
97 Refresh();
98 first = false;
99 }
100
101 public void Refresh()
102 {
103 book.pages.Clear();
104 GridLayoutGroup[] array = grids;
105 for (int i = 0; i < array.Length; i++)
106 {
107 array[i].cellSize = gridSize[listMode ? 1 : 0];
108 }
109 Page page = new Page();
110 List<int> list = EClass.player.sketches.ToList();
111 list.Sort((int a, int b) => a - b);
112 foreach (int item in list)
113 {
114 page.ids.Add(item.ToString() ?? "");
115 if (page.ids.Count >= (listMode ? 8 : 2))
116 {
117 book.AddPage(page);
118 page = new Page();
119 }
120 }
121 if (page.ids.Count > 0)
122 {
123 book.AddPage(page);
124 }
125 book.currentPage = lastPage;
126 book.Show();
127 textCollected.SetText("sketch_collected".lang((list.Count * 100 / EClass.core.refs.dictSketches2.Count()).ToString() ?? ""));
128 }
129
130 public void OnClickHelp()
131 {
132 LayerHelp.Toggle("other", "gallery");
133 }
134
135 public void ToggleMode()
136 {
138 lastPage = (listMode ? (book.currentPage / 4) : (book.currentPage * 4));
139 SE.Tab();
140 Refresh();
141 }
142
143 private void OnDestroy()
144 {
146 foreach (Sprite item in sprites.Values.Concat(spritesFull.Values))
147 {
148 Object.Destroy(item.texture);
149 Object.Destroy(item);
150 }
151 sprites.Clear();
152 spritesFull.Clear();
153 }
154}
List< string > ids
override void BuildNote(UINote n, string idTopic)
static bool listMode
Vector2[] gridSize
static int lastPage
Transform transBig
override void OnSwitchContent(int idTab)
static Dictionary< int, Sprite > sprites
static Dictionary< int, Sprite > spritesFull
GridLayoutGroup[] grids
UIText textCollected
bool allArt
Definition: CoreDebug.cs:197
UD_Int_String dictSketches2
Definition: CoreRef.cs:415
CoreRef refs
Definition: Core.cs:51
Definition: EClass.cs:6
static Core core
Definition: EClass.cs:7
static Player player
Definition: EClass.cs:13
static CoreDebug debug
Definition: EClass.cs:49
static UI ui
Definition: EClass.cs:17
static void Toggle(string idFile, string idTopic=null)
Definition: LayerHelp.cs:32
HashSet< int > sketches
Definition: Player.cs:1070
ICollection< TKey > Keys
Definition: UDictionary.cs:25
int idx
Definition: UIBook.cs:35
Definition: UIBook.cs:9
int currentPage
Definition: UIBook.cs:264
void AddPage(Page page)
Definition: UIBook.cs:538
void Show(string _idFile=null, string _idTopic=null, string title=null, BookList.Item _bookItem=null)
Definition: UIBook.cs:457
List< Page > pages
Definition: UIBook.cs:266
Definition: UIItem.cs:5
UIButton button1
Definition: UIItem.cs:18
Definition: UINote.cs:6
Definition: UIText.cs:6
void SetText(string s)
Definition: UIText.cs:159