Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
MoveRoseWidget.cs
浏览该文件的文档.
1using Engine;
3using Engine.Input;
4
5namespace Game {
6 public class MoveRoseWidget : Widget {
8
9 public bool m_jump;
10
11 public int? m_jumpTouchId;
12
14 get {
16 return m_direction;
17 }
18 return Vector3.Zero;
19 }
20 }
21
22 public bool Jump {
23 get {
25 return m_jump;
26 }
27 return false;
28 }
29 }
30
31 public override void Update() {
33 m_jump = false;
34 Vector2 v = ActualSize / 2f;
35 float num = ActualSize.X / 2f;
36 float num2 = num / 3.5f;
37 float num3 = MathUtils.DegToRad(35f);
38 foreach (TouchLocation touchLocation in Input.TouchLocations) {
39 if (HitTestGlobal(touchLocation.Position) == this) {
40 if (touchLocation.State == TouchLocationState.Pressed
41 && Vector2.Distance(ScreenToWidget(touchLocation.Position), v) <= num2) {
42 m_jump = true;
43 m_jumpTouchId = touchLocation.Id;
44 }
45 if (touchLocation.State == TouchLocationState.Released
46 && m_jumpTouchId.HasValue
47 && touchLocation.Id == m_jumpTouchId.Value) {
48 m_jumpTouchId = null;
49 }
50 if (touchLocation.State == TouchLocationState.Moved
51 || touchLocation.State == TouchLocationState.Pressed) {
52 Vector2 v2 = ScreenToWidget(touchLocation.Position);
53 float num4 = Vector2.Distance(v2, v);
54 if (num4 > num2
55 && num4 <= num) {
56 float num5 = Vector2.Angle(v2 - v, -Vector2.UnitY);
57 if (MathF.Abs(MathUtils.NormalizeAngle(num5 - 0f)) < num3) {
58 m_direction = m_jumpTouchId.HasValue ? new Vector3(0f, 1f, 0f) : new Vector3(0f, 0f, 1f);
59 }
60 else if (MathF.Abs(MathUtils.NormalizeAngle(num5 - (float)Math.PI / 2f)) < num3) {
61 m_direction = new Vector3(-1f, 0f, 0f);
62 }
63 else if (MathF.Abs(MathUtils.NormalizeAngle(num5 - (float)Math.PI)) < num3) {
64 m_direction = m_jumpTouchId.HasValue ? new Vector3(0f, -1f, 0f) : new Vector3(0f, 0f, -1f);
65 }
66 else if (MathF.Abs(MathUtils.NormalizeAngle(num5 - 4.712389f)) < num3) {
67 m_direction = new Vector3(1f, 0f, 0f);
68 }
69 }
70 }
71 }
72 }
73 }
74
75 public override void MeasureOverride(Vector2 parentAvailableSize) {
76 IsDrawRequired = true;
77 }
78
79 public override void Draw(DrawContext dc) {
80 Subtexture subtexture = ContentManager.Get<Subtexture>("Textures/Atlas/MoveRose");
81 Subtexture subtexture2 = ContentManager.Get<Subtexture>("Textures/Atlas/MoveRose_Pressed");
82 TexturedBatch2D texturedBatch2D = dc.PrimitivesRenderer2D.TexturedBatch(subtexture.Texture);
83 TexturedBatch2D texturedBatch2D2 = dc.PrimitivesRenderer2D.TexturedBatch(subtexture2.Texture);
84 int count = texturedBatch2D.TriangleVertices.Count;
85 int count2 = texturedBatch2D2.TriangleVertices.Count;
86 Vector2 p = ActualSize / 2f;
87 Vector2 vector = new(0f, 0f);
88 Vector2 vector2 = new(ActualSize.X, 0f);
89 Vector2 vector3 = new(ActualSize.X, ActualSize.Y);
90 Vector2 vector4 = new(0f, ActualSize.Y);
91 if (m_direction.Z > 0f) {
92 Vector2 subtextureCoords = GetSubtextureCoords(subtexture2, new Vector2(0f, 0f));
93 Vector2 subtextureCoords2 = GetSubtextureCoords(subtexture2, new Vector2(1f, 0f));
94 Vector2 subtextureCoords3 = GetSubtextureCoords(subtexture2, new Vector2(0.5f, 0.5f));
95 texturedBatch2D2.QueueTriangle(
96 vector,
97 vector2,
98 p,
99 0f,
100 subtextureCoords,
101 subtextureCoords2,
102 subtextureCoords3,
104 );
105 }
106 else {
107 Vector2 subtextureCoords4 = GetSubtextureCoords(subtexture, new Vector2(0f, 0f));
108 Vector2 subtextureCoords5 = GetSubtextureCoords(subtexture, new Vector2(1f, 0f));
109 Vector2 subtextureCoords6 = GetSubtextureCoords(subtexture, new Vector2(0.5f, 0.5f));
110 texturedBatch2D.QueueTriangle(
111 vector,
112 vector2,
113 p,
114 0f,
115 subtextureCoords4,
116 subtextureCoords5,
117 subtextureCoords6,
119 );
120 }
121 if (m_direction.X > 0f) {
122 Vector2 subtextureCoords7 = GetSubtextureCoords(subtexture2, new Vector2(1f, 0f));
123 Vector2 subtextureCoords8 = GetSubtextureCoords(subtexture2, new Vector2(1f, 1f));
124 Vector2 subtextureCoords9 = GetSubtextureCoords(subtexture2, new Vector2(0.5f, 0.5f));
125 texturedBatch2D2.QueueTriangle(
126 vector2,
127 vector3,
128 p,
129 0f,
130 subtextureCoords7,
131 subtextureCoords8,
132 subtextureCoords9,
134 );
135 }
136 else {
137 Vector2 subtextureCoords10 = GetSubtextureCoords(subtexture, new Vector2(1f, 0f));
138 Vector2 subtextureCoords11 = GetSubtextureCoords(subtexture, new Vector2(1f, 1f));
139 Vector2 subtextureCoords12 = GetSubtextureCoords(subtexture, new Vector2(0.5f, 0.5f));
140 texturedBatch2D.QueueTriangle(
141 vector2,
142 vector3,
143 p,
144 0f,
145 subtextureCoords10,
146 subtextureCoords11,
147 subtextureCoords12,
149 );
150 }
151 if (m_direction.Z < 0f) {
152 Vector2 subtextureCoords13 = GetSubtextureCoords(subtexture2, new Vector2(1f, 1f));
153 Vector2 subtextureCoords14 = GetSubtextureCoords(subtexture2, new Vector2(0f, 1f));
154 Vector2 subtextureCoords15 = GetSubtextureCoords(subtexture2, new Vector2(0.5f, 0.5f));
155 texturedBatch2D2.QueueTriangle(
156 vector3,
157 vector4,
158 p,
159 0f,
160 subtextureCoords13,
161 subtextureCoords14,
162 subtextureCoords15,
164 );
165 }
166 else {
167 Vector2 subtextureCoords16 = GetSubtextureCoords(subtexture, new Vector2(1f, 1f));
168 Vector2 subtextureCoords17 = GetSubtextureCoords(subtexture, new Vector2(0f, 1f));
169 Vector2 subtextureCoords18 = GetSubtextureCoords(subtexture, new Vector2(0.5f, 0.5f));
170 texturedBatch2D.QueueTriangle(
171 vector3,
172 vector4,
173 p,
174 0f,
175 subtextureCoords16,
176 subtextureCoords17,
177 subtextureCoords18,
179 );
180 }
181 if (m_direction.X < 0f) {
182 Vector2 subtextureCoords19 = GetSubtextureCoords(subtexture2, new Vector2(0f, 1f));
183 Vector2 subtextureCoords20 = GetSubtextureCoords(subtexture2, new Vector2(0f, 0f));
184 Vector2 subtextureCoords21 = GetSubtextureCoords(subtexture2, new Vector2(0.5f, 0.5f));
185 texturedBatch2D2.QueueTriangle(
186 vector4,
187 vector,
188 p,
189 0f,
190 subtextureCoords19,
191 subtextureCoords20,
192 subtextureCoords21,
194 );
195 }
196 else {
197 Vector2 subtextureCoords22 = GetSubtextureCoords(subtexture, new Vector2(0f, 1f));
198 Vector2 subtextureCoords23 = GetSubtextureCoords(subtexture, new Vector2(0f, 0f));
199 Vector2 subtextureCoords24 = GetSubtextureCoords(subtexture, new Vector2(0.5f, 0.5f));
200 texturedBatch2D.QueueTriangle(
201 vector4,
202 vector,
203 p,
204 0f,
205 subtextureCoords22,
206 subtextureCoords23,
207 subtextureCoords24,
209 );
210 }
211 if (texturedBatch2D == texturedBatch2D2) {
212 texturedBatch2D.TransformTriangles(GlobalTransform, count);
213 return;
214 }
215 texturedBatch2D.TransformTriangles(GlobalTransform, count);
216 texturedBatch2D2.TransformTriangles(GlobalTransform, count2);
217 }
218
219 public static Vector2 GetSubtextureCoords(Subtexture subtexture, Vector2 texCoords) => new(
220 MathUtils.Lerp(subtexture.TopLeft.X, subtexture.BottomRight.X, texCoords.X),
221 MathUtils.Lerp(subtexture.TopLeft.Y, subtexture.BottomRight.Y, texCoords.Y)
222 );
223 }
224}
Engine.Vector3 Vector3
void TransformTriangles(Matrix matrix, int start=0, int end=-1)
readonly DynamicArray< VertexPositionColorTexture > TriangleVertices
TexturedBatch2D TexturedBatch(Texture2D texture, bool useAlphaTest=false, int layer=0, DepthStencilState depthStencilState=null, RasterizerState rasterizerState=null, BlendState blendState=null, SamplerState samplerState=null)
void QueueTriangle(Vector2 p1, Vector2 p2, Vector2 p3, float depth, Vector2 texCoord1, Vector2 texCoord2, Vector2 texCoord3, Color color)
static float NormalizeAngle(float angle)
static float DegToRad(float degrees)
static float Lerp(float x1, float x2, float f)
static object Get(Type type, string name)
static Vector2 GetSubtextureCoords(Subtexture subtexture, Vector2 texCoords)
override void MeasureOverride(Vector2 parentAvailableSize)
override void Draw(DrawContext dc)
readonly Texture2D Texture
readonly Vector2 BottomRight
readonly Vector2 TopLeft
readonly PrimitivesRenderer2D PrimitivesRenderer2D
bool IsVisibleGlobal
virtual Widget HitTestGlobal(Vector2 point, Func< Widget, bool > predicate=null)
WidgetInput Input
Color GlobalColorTransform
bool IsDrawRequired
bool IsEnabledGlobal
Vector2 ActualSize
virtual Vector2 ScreenToWidget(Vector2 p)
Matrix GlobalTransform
static readonly Vector2 UnitY
static float Angle(Vector2 v1, Vector2 v2)
static float Distance(Vector2 v1, Vector2 v2)
static readonly Vector3 Zero