Elin Decompiled Documentation EA 23.300 Nightly
Loading...
Searching...
No Matches
LayerPickPCC.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text.RegularExpressions;
5using UnityEngine;
6using UnityEngine.UI;
7
8public class LayerPickPCC : ELayer
9{
11
12 public LayoutGroup layoutParts;
13
14 private UIItemPCC _uiItemPcc;
15
16 private UIPCC _uiPcc;
17
18 private List<UIItemPCCPart> _items = new List<UIItemPCCPart>();
19
20 private List<Outline> _outlines = new List<Outline>();
21
22 private static readonly Dictionary<PCC.Part, BaseModPackage> _cached = new Dictionary<PCC.Part, BaseModPackage>();
23
24 private static readonly Regex _idRegex = new Regex("(\\d+)|(\\D+)", RegexOptions.Compiled);
25
26 public void Activate(UIPCC uiPcc, UIItemPCC uiItemPcc)
27 {
28 _uiPcc = uiPcc;
29 _uiItemPcc = uiItemPcc;
31 }
32
33 private void Update()
34 {
35 SpriteProvider provider = _uiPcc.actor.provider;
36 int frame = (provider.currentFrame + 2) % 4;
37 foreach (UIItemPCCPart item in _items)
38 {
39 item.SetSpriteIndex(provider.currentDir, frame);
40 }
41 }
42
43 public void PopulateButtons()
44 {
45 List<PCC.Part> list = _uiItemPcc.parts.ToList();
46 list.Sort(PartSorter);
47 foreach (PCC.Part part in list)
48 {
49 UIItemPCCPart item = Util.Instantiate(mold, layoutParts);
50 if (part == _uiItemPcc.part)
51 {
52 SetOutline(item.outline);
53 }
54 if (part == null)
55 {
56 item.button.onClick.AddListener(delegate
57 {
58 _uiItemPcc.slider.value = 0f;
59 SetOutline(item.outline);
60 });
61 item.button.tooltip.lang = "empty";
62 }
63 else
64 {
65 ModItem<Texture2D> modItem = part.modTextures.TryGetValue("walk");
66 if (modItem == null)
67 {
68 UnityEngine.Object.Destroy(item.gameObject);
69 continue;
70 }
71 item.button.tooltip.lang = GetPartProviderString(part);
72 item.button.onClick.AddListener(delegate
73 {
74 _uiItemPcc.slider.value = _uiItemPcc.parts.IndexOf(part);
75 SetOutline(item.outline);
76 });
77 item.SetSprites(IO.LoadPNG(modItem.fileInfo.FullName));
78 Color color = _uiPcc.pcc.data.GetColor(_uiItemPcc.idPartSet);
79 item.button.icon.color = _uiPcc.pccm.ApplyColorMod(color);
80 }
81 _items.Add(item);
82 }
83 void SetOutline(Outline outline)
84 {
85 _outlines.Add(outline);
86 foreach (Outline outline in _outlines)
87 {
88 outline.enabled = false;
89 }
90 outline.enabled = true;
91 }
92 }
93
94 public static string GetPartProviderString(PCC.Part part)
95 {
96 return "ID: " + part.id + "\n<i>" + GetPartProvider(part).title.TagColor(Color.cyan) + "</i>\n" + part.dir.ShortPath();
97 }
98
99 public static BaseModPackage GetPartProvider(PCC.Part part)
100 {
101 if (part == null)
102 {
103 return null;
104 }
105 if (_cached.TryGetValue(part, out var value))
106 {
107 return value;
108 }
109 string dir = part.dir;
110 value = BaseModManager.Instance.packages.FirstOrDefault((BaseModPackage p) => dir.StartsWith(p.dirInfo.FullName)) ?? new BaseModPackage
111 {
112 title = "unknownAuthor".lang()
113 };
114 return _cached[part] = value;
115 }
116
117 public static int PartSorter(PCC.Part lhs, PCC.Part rhs)
118 {
119 if (lhs == null)
120 {
121 if (rhs != null)
122 {
123 return -1;
124 }
125 return 0;
126 }
127 if (rhs == null)
128 {
129 return 1;
130 }
131 int num = GetPartSortOrder(lhs);
132 int num2 = GetPartSortOrder(rhs);
133 if (num != num2)
134 {
135 return num - num2;
136 }
137 string id = lhs.id;
138 string id2 = rhs.id;
139 if (id == id2)
140 {
141 return 0;
142 }
143 int result;
144 bool flag = int.TryParse(id, out result);
145 int result2;
146 bool flag2 = int.TryParse(id2, out result2);
147 if (flag && flag2)
148 {
149 return result.CompareTo(result2);
150 }
151 if (flag)
152 {
153 return -1;
154 }
155 if (flag2)
156 {
157 return 1;
158 }
159 MatchCollection matchCollection = _idRegex.Matches(id);
160 MatchCollection matchCollection2 = _idRegex.Matches(id2);
161 int num3 = Math.Min(matchCollection.Count, matchCollection2.Count);
162 for (int i = 0; i < num3; i++)
163 {
164 string value = matchCollection[i].Value;
165 string value2 = matchCollection2[i].Value;
166 int result3;
167 bool num4 = int.TryParse(value, out result3);
168 int result4;
169 bool flag3 = int.TryParse(value2, out result4);
170 int num5 = ((!(num4 && flag3)) ? string.Compare(value, value2, StringComparison.OrdinalIgnoreCase) : result3.CompareTo(result4));
171 if (num5 != 0)
172 {
173 return num5;
174 }
175 }
176 return matchCollection.Count - matchCollection2.Count;
177 static int GetPartSortOrder(PCC.Part part)
178 {
179 int num6 = BaseModManager.Instance.packages.IndexOf(GetPartProvider(part));
180 if (num6 < 0)
181 {
182 return int.MaxValue;
183 }
184 return num6;
185 }
186 }
187}
item3. title
Definition: UIBook.cs:640
List< BaseModPackage > packages
static BaseModManager Instance
DirectoryInfo dirInfo
Definition: ELayer.cs:4
void Activate(UIPCC uiPcc, UIItemPCC uiItemPcc)
Definition: LayerPickPCC.cs:26
static readonly Dictionary< PCC.Part, BaseModPackage > _cached
Definition: LayerPickPCC.cs:22
void Update()
Definition: LayerPickPCC.cs:33
LayoutGroup layoutParts
Definition: LayerPickPCC.cs:12
List< Outline > _outlines
Definition: LayerPickPCC.cs:20
UIItemPCCPart mold
Definition: LayerPickPCC.cs:10
static string GetPartProviderString(PCC.Part part)
Definition: LayerPickPCC.cs:94
static BaseModPackage GetPartProvider(PCC.Part part)
Definition: LayerPickPCC.cs:99
UIItemPCC _uiItemPcc
Definition: LayerPickPCC.cs:14
void PopulateButtons()
Definition: LayerPickPCC.cs:43
static int PartSorter(PCC.Part lhs, PCC.Part rhs)
List< UIItemPCCPart > _items
Definition: LayerPickPCC.cs:18
static readonly Regex _idRegex
Definition: LayerPickPCC.cs:24
FileInfo fileInfo
Definition: ModItem.cs:18