Skip to content
This repository was archived by the owner on May 9, 2023. It is now read-only.

Commit 42156e1

Browse files
committed
1.5.2
* Added page view to GameObject Children/Component lists * Made a generic Page Handler helper class, replaced all page view implementations with the helper (no real change for users but should make things easier to maintain in the future, and they were basically all copy+pastes).
1 parent e7208d0 commit 42156e1

File tree

8 files changed

+282
-182
lines changed

8 files changed

+282
-182
lines changed

src/CachedObjects/CacheList.cs

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ namespace Explorer
1111
public class CacheList : CacheObjectBase
1212
{
1313
public bool IsExpanded { get; set; }
14-
public int ArrayOffset { get; set; }
15-
public int ArrayLimit { get; set; } = 20;
14+
public PageHelper Pages = new PageHelper();
1615

1716
public float WhiteSpace = 215f;
1817
public float ButtonWidthOffset = 290f;
@@ -230,18 +229,6 @@ public override void UpdateValue()
230229
{
231230
list.Add(null);
232231
}
233-
234-
//var type = ReflectionHelpers.GetActualType(obj);
235-
236-
//if (obj is Il2CppSystem.Object iObj)
237-
//{
238-
// obj = iObj.Il2CppCast(type);
239-
//}
240-
241-
//var cached = GetCacheObject(obj, null, null, type);
242-
//cached.UpdateValue();
243-
244-
//list.Add(cached);
245232
}
246233

247234
m_cachedEntries = list.ToArray();
@@ -286,51 +273,51 @@ public override void DrawValue(Rect window, float width)
286273

287274
if (IsExpanded)
288275
{
289-
float whitespace = WhiteSpace;
290-
276+
float whitespace = WhiteSpace;
291277
if (whitespace > 0)
292278
{
293279
ClampLabelWidth(window, ref whitespace);
294280
}
295281

296-
if (count > ArrayLimit)
282+
Pages.Count = count;
283+
284+
if (count > Pages.PageLimit)
297285
{
298286
GUILayout.EndHorizontal();
299287
GUILayout.BeginHorizontal(null);
300288

301289
GUILayout.Space(whitespace);
302290

303-
int maxOffset = (int)Mathf.Ceil((float)(count / (decimal)ArrayLimit)) - 1;
304-
GUILayout.Label($"Page {ArrayOffset + 1}/{maxOffset + 1}", new GUILayoutOption[] { GUILayout.Width(80) });
291+
//int maxOffset = (int)Mathf.Ceil((float)(count / (decimal)ArrayLimit)) - 1;
292+
Pages.CalculateMaxOffset();
293+
294+
//GUILayout.Label($"Page {PH.ArrayOffset + 1}/{maxOffset + 1}", new GUILayoutOption[] { GUILayout.Width(80) });
295+
Pages.CurrentPageLabel();
296+
305297
// prev/next page buttons
306298
if (GUILayout.Button("< Prev", new GUILayoutOption[] { GUILayout.Width(60) }))
307299
{
308-
if (ArrayOffset > 0) ArrayOffset--;
300+
Pages.TurnPage(Turn.Left);
309301
}
310302
if (GUILayout.Button("Next >", new GUILayoutOption[] { GUILayout.Width(60) }))
311303
{
312-
if (ArrayOffset < maxOffset) ArrayOffset++;
313-
}
314-
GUILayout.Label("Limit: ", new GUILayoutOption[] { GUILayout.Width(50) });
315-
var limit = this.ArrayLimit.ToString();
316-
limit = GUILayout.TextField(limit, new GUILayoutOption[] { GUILayout.Width(50) });
317-
if (limit != ArrayLimit.ToString() && int.TryParse(limit, out int i))
318-
{
319-
ArrayLimit = i;
304+
Pages.TurnPage(Turn.Right);
320305
}
321306

307+
Pages.DrawLimitInputArea();
308+
322309
GUILayout.Space(5);
323310
}
324311

325-
int offset = ArrayOffset * ArrayLimit;
326-
327-
if (offset >= count)
328-
{
329-
offset = 0;
330-
ArrayOffset = 0;
331-
}
312+
//int offset = ArrayOffset * ArrayLimit;
313+
//if (offset >= count)
314+
//{
315+
// offset = 0;
316+
// ArrayOffset = 0;
317+
//}
318+
int offset = Pages.CalculateOffsetIndex();
332319

333-
for (int i = offset; i < offset + ArrayLimit && i < count; i++)
320+
for (int i = offset; i < offset + Pages.PageLimit && i < count; i++)
334321
{
335322
var entry = m_cachedEntries[i];
336323

src/CppExplorer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Explorer
1212
public class CppExplorer : MelonMod
1313
{
1414
public const string GUID = "com.sinai.cppexplorer";
15-
public const string VERSION = "1.5.1";
15+
public const string VERSION = "1.5.2";
1616
public const string AUTHOR = "Sinai";
1717

1818
public const string NAME = "CppExplorer"

src/CppExplorer.csproj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@
6060
<HintPath>..\..\..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\UnhollowerBaseLib.dll</HintPath>
6161
<Private>False</Private>
6262
</Reference>
63-
6463
<!-- Unity 2019 build (InputLegacyModule.dll) -->
65-
6664
<Reference Include="UnityEngine" Condition="'$(Configuration)'=='Debug'">
6765
<HintPath>..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\UnityEngine.dll</HintPath>
6866
<Private>False</Private>
@@ -91,9 +89,7 @@
9189
<HintPath>..\..\..\Steam\steamapps\common\Hellpoint\MelonLoader\Managed\UnityEngine.UI.dll</HintPath>
9290
<Private>False</Private>
9391
</Reference>
94-
9592
<!-- Unity 2018 build (InputModule.dll) -->
96-
9793
<Reference Include="UnityEngine" Condition="'$(Configuration)'=='Release_Unity2018'">
9894
<HintPath>..\..\..\Steam\steamapps\common\VRChat\MelonLoader\Managed\UnityEngine.dll</HintPath>
9995
<Private>False</Private>
@@ -122,7 +118,6 @@
122118
<HintPath>..\..\..\Steam\steamapps\common\VRChat\MelonLoader\Managed\UnityEngine.UI.dll</HintPath>
123119
<Private>False</Private>
124120
</Reference>
125-
126121
</ItemGroup>
127122
<ItemGroup>
128123
<Compile Include="CachedObjects\CacheDictionary.cs" />
@@ -135,6 +130,7 @@
135130
<Compile Include="CppExplorer.cs" />
136131
<Compile Include="Extensions\ReflectionExtensions.cs" />
137132
<Compile Include="Extensions\UnityExtensions.cs" />
133+
<Compile Include="Helpers\PageHelper.cs" />
138134
<Compile Include="Helpers\ReflectionHelpers.cs" />
139135
<Compile Include="Helpers\UIHelpers.cs" />
140136
<Compile Include="Helpers\UnityHelpers.cs" />

src/Helpers/PageHelper.cs

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
using UnityEngine;
7+
8+
namespace Explorer
9+
{
10+
public enum Turn
11+
{
12+
Left,
13+
Right
14+
}
15+
16+
public class PageHelper
17+
{
18+
public int PageOffset { get; set; }
19+
public int PageLimit { get; set; } = 20;
20+
public int Count { get; set; }
21+
public int MaxOffset { get; set; } = -1;
22+
23+
public int CalculateMaxOffset()
24+
{
25+
return MaxOffset = (int)Mathf.Ceil((float)(Count / (decimal)PageLimit)) - 1;
26+
}
27+
28+
public void CurrentPageLabel()
29+
{
30+
var orig = GUI.skin.label.alignment;
31+
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
32+
33+
GUILayout.Label($"Page {PageOffset + 1}/{MaxOffset + 1}", new GUILayoutOption[] { GUILayout.Width(80) });
34+
35+
GUI.skin.label.alignment = orig;
36+
}
37+
38+
public void TurnPage(Turn direction)
39+
{
40+
var _ = Vector2.zero;
41+
TurnPage(direction, ref _);
42+
}
43+
44+
public void TurnPage(Turn direction, ref Vector2 scroll)
45+
{
46+
if (direction == Turn.Left)
47+
{
48+
if (PageOffset > 0)
49+
{
50+
PageOffset--;
51+
scroll = Vector2.zero;
52+
}
53+
}
54+
else
55+
{
56+
if (PageOffset < MaxOffset)
57+
{
58+
PageOffset++;
59+
scroll = Vector2.zero;
60+
}
61+
}
62+
}
63+
64+
public int CalculateOffsetIndex()
65+
{
66+
int offset = PageOffset * PageLimit;
67+
68+
if (offset >= Count)
69+
{
70+
offset = 0;
71+
PageOffset = 0;
72+
}
73+
74+
return offset;
75+
}
76+
77+
public void DrawLimitInputArea()
78+
{
79+
GUILayout.Label("Limit: ", new GUILayoutOption[] { GUILayout.Width(50) });
80+
var limit = this.PageLimit.ToString();
81+
limit = GUILayout.TextField(limit, new GUILayoutOption[] { GUILayout.Width(50) });
82+
if (limit != PageLimit.ToString() && int.TryParse(limit, out int i))
83+
{
84+
PageLimit = i;
85+
}
86+
}
87+
}
88+
}

src/MainMenu/Pages/ScenePage.cs

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@ public class ScenePage : WindowPage
1414

1515
public override string Name { get => "Scene Explorer"; set => base.Name = value; }
1616

17-
private int m_pageOffset = 0;
18-
private int m_limit = 20;
19-
private int m_currentTotalCount = 0;
17+
public PageHelper Pages = new PageHelper();
2018

2119
private float m_timeOfLastUpdate = -1f;
2220

@@ -46,14 +44,14 @@ public void OnSceneChange()
4644
SetTransformTarget(null);
4745
}
4846

49-
public void CheckOffset(ref int offset, int childCount)
50-
{
51-
if (offset >= childCount)
52-
{
53-
offset = 0;
54-
m_pageOffset = 0;
55-
}
56-
}
47+
//public void CheckOffset(ref int offset, int childCount)
48+
//{
49+
// if (offset >= childCount)
50+
// {
51+
// offset = 0;
52+
// m_pageOffset = 0;
53+
// }
54+
//}
5755

5856
public override void Update()
5957
{
@@ -63,7 +61,6 @@ public override void Update()
6361
m_timeOfLastUpdate = Time.time;
6462

6563
m_objectList = new List<GameObjectCache>();
66-
int offset = m_pageOffset * m_limit;
6764

6865
var allTransforms = new List<Transform>();
6966

@@ -86,15 +83,14 @@ public override void Update()
8683
}
8784
}
8885

89-
m_currentTotalCount = allTransforms.Count;
86+
Pages.Count = allTransforms.Count;
9087

91-
// make sure offset doesn't exceed count
92-
CheckOffset(ref offset, m_currentTotalCount);
88+
int offset = Pages.CalculateOffsetIndex();
9389

9490
// sort by childcount
9591
allTransforms.Sort((a, b) => b.childCount.CompareTo(a.childCount));
9692

97-
for (int i = offset; i < offset + m_limit && i < m_currentTotalCount; i++)
93+
for (int i = offset; i < offset + Pages.PageLimit && i < Pages.Count; i++)
9894
{
9995
var child = allTransforms[i];
10096
m_objectList.Add(new GameObjectCache(child.gameObject));
@@ -128,7 +124,7 @@ public void Search()
128124
{
129125
m_searchResults = SearchSceneObjects(m_searchInput);
130126
m_searching = true;
131-
m_currentTotalCount = m_searchResults.Count;
127+
Pages.Count = m_searchResults.Count;
132128
}
133129

134130
public void CancelSearch()
@@ -242,33 +238,21 @@ private void DrawPageButtons()
242238
{
243239
GUILayout.BeginHorizontal(null);
244240

245-
GUILayout.Label("Limit per page: ", new GUILayoutOption[] { GUILayout.Width(100) });
246-
var limit = m_limit.ToString();
247-
limit = GUILayout.TextField(limit, new GUILayoutOption[] { GUILayout.Width(30) });
248-
if (int.TryParse(limit, out int lim))
249-
{
250-
m_limit = lim;
251-
}
241+
Pages.DrawLimitInputArea();
252242

253-
// prev/next page buttons
254-
if (m_currentTotalCount > m_limit)
243+
if (Pages.Count > Pages.PageLimit)
255244
{
256-
int count = m_currentTotalCount;
257-
int maxOffset = (int)Mathf.Ceil((float)(count / (decimal)m_limit)) - 1;
258-
if (GUILayout.Button("< Prev", null))
245+
if (GUILayout.Button("< Prev", new GUILayoutOption[] { GUILayout.Width(80) }))
259246
{
260-
if (m_pageOffset > 0) m_pageOffset--;
261-
m_timeOfLastUpdate = -1f;
247+
Pages.TurnPage(Turn.Left, ref this.scroll);
262248
Update();
263249
}
264250

265-
GUI.skin.label.alignment = TextAnchor.MiddleCenter;
266-
GUILayout.Label($"Page {m_pageOffset + 1}/{maxOffset + 1}", new GUILayoutOption[] { GUILayout.Width(80) });
251+
Pages.CurrentPageLabel();
267252

268-
if (GUILayout.Button("Next >", null))
253+
if (GUILayout.Button("Next >", new GUILayoutOption[] { GUILayout.Width(80) }))
269254
{
270-
if (m_pageOffset < maxOffset) m_pageOffset++;
271-
m_timeOfLastUpdate = -1f;
255+
Pages.TurnPage(Turn.Right, ref this.scroll);
272256
Update();
273257
}
274258
}
@@ -342,15 +326,9 @@ private void DrawSearchResultsList()
342326

343327
if (m_searchResults.Count > 0)
344328
{
345-
int offset = m_pageOffset * m_limit;
346-
347-
if (offset >= m_searchResults.Count)
348-
{
349-
offset = 0;
350-
m_pageOffset = 0;
351-
}
329+
int offset = Pages.CalculateOffsetIndex();
352330

353-
for (int i = offset; i < offset + m_limit && i < m_searchResults.Count; i++)
331+
for (int i = offset; i < offset + Pages.PageLimit && i < m_searchResults.Count; i++)
354332
{
355333
var obj = m_searchResults[i];
356334

0 commit comments

Comments
 (0)