forked from phorcys/Taiwu_mods
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNewWarehouse.cs
276 lines (252 loc) · 10.7 KB
/
NewWarehouse.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using GuiBaseUI;
using System.Linq;
namespace GuiWarehouse
{
public class NewWarehouse:MonoBehaviour
{
private bool actor;
private int typ;
BigDataScroll bigDataScroll;
public ScrollRect scrollRect;
private int[] m_data;
public int[] data
{
set
{
m_data = value;
SetData();
}
get
{
return m_data;
}
}
public bool setClick = false;
public bool isInit = false;
public void Init(bool actor,int typ)
{
Main.Logger.Log("NewWarehouse Init " + actor.ToString());
this.actor = actor;
this.typ = typ;
InitUI();
}
private void InitUI()
{
isInit = true;;
Vector2 size = new Vector2(650, 650);
Vector2 leftPos = actor ? new Vector2(-size.x * 0f, 0) : new Vector2(size.x * 0f, 0);
GameObject scrollView = CreateUI.NewScrollView(size, BarType.Vertical, ContentType.VerticalLayout);
scrollRect = scrollView.GetComponent<ScrollRect>();
scrollRect.verticalNormalizedPosition = 1;
Image imgScrollView = scrollView.GetComponentInChildren<Image>();
imgScrollView.color = new Color(0.5f, 0.5f, 0.5f, 0.005f);
imgScrollView.raycastTarget = false;
RectTransform rScrollView = ((RectTransform)scrollView.transform);
rScrollView.SetParent(gameObject.transform, false);
rScrollView.anchoredPosition = leftPos;
//scrollView.GetComponentInChildren<Mask>().enabled = false;
GameObject image = new GameObject("line", new System.Type[] { typeof(RectTransform) });
RectTransform rItemCell = image.GetComponent<RectTransform>();
rItemCell.SetParent(transform, false);
rItemCell.anchoredPosition = new Vector2(10000, 10000);
GameObject prefab = Warehouse.instance.warehouseItemIcon;
for (int i = 0; i < Main.settings.numberOfColumns; i++)
{
GameObject go = UnityEngine.Object.Instantiate(prefab);
go.transform.SetParent(rItemCell, false);
}
rItemCell.sizeDelta = new Vector2(size.x, size.x / Main.settings.numberOfColumns);
GridLayoutGroup gridLayoutGroup = image.AddComponent<GridLayoutGroup>();
gridLayoutGroup.cellSize = size / Main.settings.numberOfColumns * 0.9f;
gridLayoutGroup.spacing = 0.05f * size / Main.settings.numberOfColumns;
gridLayoutGroup.padding.left = (int)(size.x / Main.settings.numberOfColumns * 0.05f);
gridLayoutGroup.padding.top = (int)(size.x / Main.settings.numberOfColumns * 0.05f);
WarehouseItem itemCell = image.AddComponent<WarehouseItem>();
bigDataScroll = gameObject.AddComponent<BigDataScroll>();
bigDataScroll.Init(scrollRect, itemCell, SetCell);
bigDataScroll.cellHeight = size.x / Main.settings.numberOfColumns;
Transform parent = transform.parent;
ScrollRect scroll = parent.GetComponent<ScrollRect>();
if (scroll != null)
{
if (scroll.verticalScrollbar != null)
{
Image other = scroll.verticalScrollbar.GetComponent<Image>();
if (other != null)
{
RectTransform rect = (RectTransform)rScrollView.Find("ScrollbarVertical");
//rect.sizeDelta = new Vector2(10, 0);
Image my = rect.GetComponent<Image>();
//my.color = new Color(10.9490196f, 0.509803951f, 0.203921571f);
my.sprite = other.sprite;
my.type = Image.Type.Sliced;
}
else
{
Main.Logger.Log("没找到 ScrollbarVertical Image");
}
if (scroll.verticalScrollbar.targetGraphic != null)
{
Image other2 = scroll.verticalScrollbar.targetGraphic.GetComponent<Image>();
if (other != null)
{
RectTransform rect = (RectTransform)rScrollView.Find("ScrollbarVertical/SlidingArea/Handle");
//rect.sizeDelta = new Vector2(10, 10);
Image my = rect.GetComponent<Image>();
//my.color = new Color(0.3882353f, 0.807843149f, 0.8156863f);
my.sprite = other2.sprite;
my.type = Image.Type.Sliced;
}
else
{
Main.Logger.Log("没找到 Handle Image");
}
}
else
{
Main.Logger.Log("没找到 Handle");
}
}
}
else
{
Main.Logger.Log("没找到 ScrollbarVertical");
}
SetData();
}
private void SetData()
{
if (bigDataScroll != null&& m_data!=null&& isInit)
{
int count = m_data.Length / Main.settings.numberOfColumns + 1;
bigDataScroll.cellCount = count;
if (!Main.OnChangeItem)
{
scrollRect.verticalNormalizedPosition = 1;
}
}
}
private void SetCell(ItemCell itemCell, int index)
{
if (actor)
{
int num2 = DateFile.instance.MianActorID();
bool flag = !Main.settings.remoteWarehouse;
if (flag)
{
flag = HomeSystem.instance.homeMapPartId != DateFile.instance.mianPartId || HomeSystem.instance.homeMapPlaceId != DateFile.instance.mianPlaceId;
}
WarehouseItem item = itemCell as WarehouseItem;
if (item == null)
{
Main.Logger.Log("WarehouseItem出错。。。");
return;
}
ChildData[] childDatas = item.childDatas;
for (int i = 0; i < Main.settings.numberOfColumns; i++)
{
int idx = (index - 1) * Main.settings.numberOfColumns + i;
if (i < childDatas.Length)
{
ChildData childData = childDatas[i];
if (idx < m_data.Length)
{
int num3 = m_data[idx];
GameObject go = childData.gameObject;
if (!go.activeSelf)
{
go.SetActive(true);
}
go.name = "ActorItem," + num3;
//childData.setItem.SetWarehouseItemIcon(num2, num3, int.Parse(DateFile.instance.GetItemDate(num3, 3, true)) != 1 || flag);
childData.setItem.SetWarehouseItemIcon(num2, num3, (DateFile.instance.ParseInt(
DateFile.instance.GetItemDate(num3, 3)) != 1
|| DateFile.instance.ParseInt(DateFile.instance.GetItemDate(num3, 5)) == 42) | flag, Warehouse.instance.warehouseItemDes, 201);
}
else
{
GameObject go = childData.gameObject;
if (go.activeSelf)
{
go.SetActive(false);
}
}
}
else
{
Main.Logger.Log("数据出错。。。");
}
}
}
else
{
int num4 = -999;
bool cantTake = !Main.settings.remoteWarehouse;
if (cantTake)
{
cantTake = HomeSystem.instance.homeMapPartId != DateFile.instance.mianPartId || HomeSystem.instance.homeMapPlaceId != DateFile.instance.mianPlaceId;
}
WarehouseItem item = itemCell as WarehouseItem;
if (item == null)
{
Main.Logger.Log("WarehouseItem出错。。。");
return;
}
ChildData[] childDatas = item.childDatas;
for (int i = 0; i < Main.settings.numberOfColumns; i++)
{
int idx = (index - 1) * Main.settings.numberOfColumns + i;
if (i < childDatas.Length)
{
ChildData childData = childDatas[i];
if (idx < m_data.Length)
{
int num5 = m_data[idx];
GameObject go = childData.gameObject;
if (!go.activeSelf)
{
go.SetActive(true);
}
go.name = "WarehouseItem," + num5;
childData.setItem.SetWarehouseItemIcon(num4, num5, cantTake);
}
else
{
GameObject go = childData.gameObject;
if (go.activeSelf)
{
go.SetActive(false);
}
}
}
else
{
Main.Logger.Log("数据出错。。。");
}
}
}
}
private void Update()
{
if (!gameObject.activeInHierarchy | m_data == null | scrollRect == null)
{
return;
}
var mousePosition = Input.mousePosition;
var mouseOnPackage = mousePosition.x > Screen.width / 2;
var v = Input.GetAxis("Mouse ScrollWheel");
if (v != 0)
{
if (mouseOnPackage == actor)
{
float count = m_data.Length / Main.settings.numberOfColumns + 1;
scrollRect.verticalNormalizedPosition += v / count * Main.settings.scrollSpeed;
}
}
}
}
}