Skip to content

Commit 7a44b84

Browse files
committed
Added BaseWrapperArrayNode.
1 parent dd87da2 commit 7a44b84

3 files changed

Lines changed: 158 additions & 1 deletion

File tree

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
using System;
2+
using System.Drawing;
3+
using ReClassNET.Extensions;
4+
using ReClassNET.UI;
5+
6+
namespace ReClassNET.Nodes
7+
{
8+
public class BaseWrapperArrayNode : BaseWrapperNode
9+
{
10+
public override int MemorySize => InnerNode.MemorySize * Count;
11+
12+
public int CurrentIndex { get; set; }
13+
public int Count { get; set; } = 1;
14+
public bool IsReadOnly { get; protected set; }
15+
16+
public override bool IsEmptyNodeAllowed => false;
17+
18+
public override bool PerformCycleCheck => true;
19+
20+
public override void GetUserInterfaceInfo(out string name, out Image icon)
21+
{
22+
name = "Array";
23+
icon = Properties.Resources.B16x16_Button_Array;
24+
}
25+
26+
public override void Intialize()
27+
{
28+
InnerNode = IntPtr.Size == 4 ? (BaseNode)new Hex32Node() : new Hex64Node();
29+
}
30+
31+
public override bool CanChangeInnerNodeTo(BaseNode node)
32+
{
33+
return node != null;
34+
}
35+
36+
public override Size Draw(ViewInfo view, int x, int y)
37+
{
38+
if (IsHidden && !IsWrapped)
39+
{
40+
return DrawHidden(view, x, y);
41+
}
42+
43+
DrawInvalidMemoryIndicator(view, y);
44+
45+
var origX = x;
46+
47+
AddSelection(view, x, y, view.Font.Height);
48+
49+
x = AddOpenClose(view, x, y);
50+
x = AddIcon(view, x, y, Icons.Array, -1, HotSpotType.None);
51+
52+
var tx = x;
53+
x = AddAddressOffset(view, x, y);
54+
55+
x = AddText(view, x, y, view.Settings.TypeColor, HotSpot.NoneId, "Array") + view.Font.Width;
56+
if (!IsWrapped)
57+
{
58+
x = AddText(view, x, y, view.Settings.NameColor, HotSpot.NameId, Name);
59+
}
60+
x = AddText(view, x, y, view.Settings.IndexColor, HotSpot.NoneId, "[");
61+
x = AddText(view, x, y, view.Settings.IndexColor, IsReadOnly ? HotSpot.NoneId : 0, Count.ToString());
62+
x = AddText(view, x, y, view.Settings.IndexColor, HotSpot.NoneId, "]");
63+
64+
x = AddIcon(view, x, y, Icons.LeftArrow, 2, HotSpotType.Click);
65+
x = AddText(view, x, y, view.Settings.IndexColor, HotSpot.NoneId, "(");
66+
x = AddText(view, x, y, view.Settings.IndexColor, 1, CurrentIndex.ToString());
67+
x = AddText(view, x, y, view.Settings.IndexColor, HotSpot.NoneId, ")");
68+
x = AddIcon(view, x, y, Icons.RightArrow, 3, HotSpotType.Click) + view.Font.Width;
69+
70+
x = AddText(view, x, y, view.Settings.ValueColor, HotSpot.NoneId, $"<Size={MemorySize}>") + view.Font.Width;
71+
x = AddIcon(view, x + 2, y, Icons.Change, 4, HotSpotType.ChangeWrappedType);
72+
73+
x += view.Font.Width;
74+
x = AddComment(view, x, y);
75+
76+
AddTypeDrop(view, y);
77+
AddDelete(view, y);
78+
79+
y += view.Font.Height;
80+
81+
var size = new Size(x - origX, view.Font.Height);
82+
83+
if (levelsOpen[view.Level])
84+
{
85+
var v = view.Clone();
86+
v.Address = view.Address.Add(Offset) + InnerNode.MemorySize * CurrentIndex;
87+
v.Memory = view.Memory.Clone();
88+
v.Memory.Offset += Offset.ToInt32() + InnerNode.MemorySize * CurrentIndex;
89+
90+
var childSize = InnerNode.Draw(v, tx, y);
91+
92+
size.Width = Math.Max(size.Width, childSize.Width + tx - origX);
93+
size.Height += childSize.Height;
94+
}
95+
96+
return size;
97+
}
98+
99+
public override int CalculateDrawnHeight(ViewInfo view)
100+
{
101+
if (IsHidden && !IsWrapped)
102+
{
103+
return HiddenHeight;
104+
}
105+
106+
var height = view.Font.Height;
107+
if (levelsOpen[view.Level])
108+
{
109+
height += InnerNode.CalculateDrawnHeight(view);
110+
}
111+
return height;
112+
}
113+
114+
public override void Update(HotSpot spot)
115+
{
116+
base.Update(spot);
117+
118+
if (spot.Id == 0 || spot.Id == 1)
119+
{
120+
if (int.TryParse(spot.Text, out var value))
121+
{
122+
if (spot.Id == 0 && !IsReadOnly)
123+
{
124+
if (value != 0)
125+
{
126+
Count = value;
127+
128+
ParentNode.ChildHasChanged(this);
129+
}
130+
}
131+
else
132+
{
133+
if (value < Count)
134+
{
135+
CurrentIndex = value;
136+
}
137+
}
138+
}
139+
}
140+
else if (spot.Id == 2)
141+
{
142+
if (CurrentIndex > 0)
143+
{
144+
--CurrentIndex;
145+
}
146+
}
147+
else if (spot.Id == 3)
148+
{
149+
if (CurrentIndex < Count - 1)
150+
{
151+
++CurrentIndex;
152+
}
153+
}
154+
}
155+
}
156+
}

‎ReClass.NET/ReClass.NET.csproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@
242242
<Compile Include="Native\NativeMethods.Unix.cs" />
243243
<Compile Include="Native\NativeMethods.Windows.cs" />
244244
<Compile Include="Nodes\BaseFunctionNode.cs" />
245+
<Compile Include="Nodes\BaseWrapperArrayNode.cs" />
245246
<Compile Include="Nodes\BaseWrapperNode.cs" />
246247
<Compile Include="Nodes\BoolNode.cs" />
247248
<Compile Include="Nodes\ClassUtil.cs" />

‎ReClass.NET/UI/NodeTypesBuilder.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static NodeTypesBuilder()
2525
defaultNodeTypeGroupList.Add(new[] { typeof(Vector4Node), typeof(Vector3Node), typeof(Vector2Node), typeof(Matrix4x4Node), typeof(Matrix3x4Node), typeof(Matrix3x3Node) });
2626
defaultNodeTypeGroupList.Add(new[] { typeof(Utf8TextNode), typeof(Utf8TextPtrNode), typeof(Utf16TextNode), typeof(Utf16TextPtrNode) });
2727
defaultNodeTypeGroupList.Add(new[] { typeof(ClassInstanceNode), typeof(ClassPtrNode) });
28-
defaultNodeTypeGroupList.Add(new[] { typeof(PointerNode), typeof(ClassInstanceArrayNode), typeof(ClassPtrArrayNode), typeof(VTableNode), typeof(FunctionNode), typeof(FunctionPtrNode) });
28+
defaultNodeTypeGroupList.Add(new[] { typeof(PointerNode), typeof(BaseWrapperArrayNode), typeof(ClassInstanceArrayNode), typeof(ClassPtrArrayNode), typeof(VTableNode), typeof(FunctionNode), typeof(FunctionPtrNode) });
2929
}
3030

3131
public static List<Type> RegisterPluginNodeGroup(Plugin plugin)

0 commit comments

Comments
 (0)