Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ComponentScreenOverlays.cs
浏览该文件的文档.
1using Engine;
3using Engine.Media;
6
7namespace Game {
10
12
14
16
18
20
22
23 public Random m_random = new(0);
24
26
28
29 public float? m_light;
30
32
33 public bool m_isUnderWater;
34
35 public static int[] m_drawOrders = [1101];
36
37 public float BlackoutFactor { get; set; }
38
39 public float RedoutFactor { get; set; }
40
41 public float GreenoutFactor { get; set; }
42
43 public string FloatingMessage { get; set; }
44
45 public float FloatingMessageFactor { get; set; }
46
47 public string Message { get; set; }
48
49 public float MessageFactor { get; set; }
50
51 public float IceFactor { get; set; }
52
54
55 public int[] DrawOrders => m_drawOrders;
56
57 public virtual void Update(float dt) {
58 bool flag = m_subsystemSky.ViewUnderWaterDepth > 0f;
59 if (flag != m_isUnderWater) {
60 m_isUnderWater = flag;
62 }
63 BlackoutFactor = 0f;
64 RedoutFactor = 0f;
65 GreenoutFactor = 0f;
66 IceFactor = 0f;
67 FloatingMessage = null;
69 Message = null;
70 MessageFactor = 0f;
71 }
72
73 public virtual void Draw(Camera camera, int drawOrder) {
74 if (m_componentPlayer.GameWidget != camera.GameWidget) {
75 return;
76 }
77 if (m_waterSurfaceCrossTime.HasValue) {
78 float num = (float)(m_subsystemTime.GameTime - m_waterSurfaceCrossTime.Value);
79 float num2 = 0.66f * MathUtils.Sqr(MathUtils.Saturate(1f - 0.75f * num));
80 if (num2 > 0.01f) {
81 Matrix matrix = default;
82 matrix.Translation = Vector3.Zero;
83 matrix.Forward = camera.ViewDirection;
84 matrix.Right = Vector3.Normalize(Vector3.Cross(camera.ViewUp, matrix.Forward));
85 matrix.Up = Vector3.Normalize(Vector3.Cross(matrix.Right, matrix.Forward));
86 Vector3 vector = matrix.ToYawPitchRoll();
87 Vector2 zero = Vector2.Zero;
88 zero.X -= 2f * vector.X / (float)Math.PI + 0.05f * MathF.Sin(5f * num);
89 zero.Y += 2f * vector.Y / (float)Math.PI + (m_isUnderWater ? 0.75f * num : -0.75f * num);
90 Texture2D texture = ContentManager.Get<Texture2D>("Textures/SplashOverlay");
91 DrawTexturedOverlay(camera, texture, new Color(156, 206, 210), num2, num2, zero);
92 }
93 }
94 if (IceFactor > 0f) {
96 }
97 if (RedoutFactor > 0.01f) {
98 DrawOverlay(camera, new Color(255, 64, 0), MathUtils.Saturate(2f * (RedoutFactor - 0.5f)), RedoutFactor);
99 }
100 if (BlackoutFactor > 0.01f) {
102 }
103 if (GreenoutFactor > 0.01f) {
104 DrawOverlay(camera, new Color(166, 175, 103), GreenoutFactor, MathUtils.Saturate(2f * GreenoutFactor));
105 }
106 if (!string.IsNullOrEmpty(FloatingMessage)
107 && FloatingMessageFactor > 0.01f) {
109 }
110 if (!string.IsNullOrEmpty(Message)
111 && MessageFactor > 0.01f) {
113 }
114 }
115
116 public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) {
117 m_subsystemTime = Project.FindSubsystem<SubsystemTime>(true);
118 m_subsystemTerrain = Project.FindSubsystem<SubsystemTerrain>(true);
119 m_subsystemSky = Project.FindSubsystem<SubsystemSky>(true);
120 m_componentGui = Entity.FindComponent<ComponentGui>(true);
121 m_componentPlayer = Entity.FindComponent<ComponentPlayer>(true);
122 }
123
124 public virtual void DrawOverlay(Camera camera, Color color, float innerFactor, float outerFactor) {
125 Vector2 viewportSize = camera.ViewportSize;
126 Vector2 vector = new(0f, 0f);
127 Vector2 vector2 = new(viewportSize.X, 0f);
128 Vector2 vector3 = new(viewportSize.X, viewportSize.Y);
129 Vector2 vector4 = new(0f, viewportSize.Y);
130 Vector2 p = new(viewportSize.X / 2f, viewportSize.Y / 2f);
131 Color color2 = color * outerFactor;
132 Color color3 = color * innerFactor;
134 int count = flatBatch2D.TriangleVertices.Count;
135 flatBatch2D.QueueTriangle(
136 vector,
137 vector2,
138 p,
139 0f,
140 color2,
141 color2,
142 color3
143 );
144 flatBatch2D.QueueTriangle(
145 vector2,
146 vector3,
147 p,
148 0f,
149 color2,
150 color2,
151 color3
152 );
153 flatBatch2D.QueueTriangle(
154 vector3,
155 vector4,
156 p,
157 0f,
158 color2,
159 color2,
160 color3
161 );
162 flatBatch2D.QueueTriangle(
163 vector4,
164 vector,
165 p,
166 0f,
167 color2,
168 color2,
169 color3
170 );
171 flatBatch2D.TransformTriangles(camera.ViewportMatrix, count);
172 flatBatch2D.Flush();
173 }
174
175 public virtual void DrawTexturedOverlay(Camera camera, Texture2D texture, Color color, float innerFactor, float outerFactor, Vector2 offset) {
176 Vector2 viewportSize = camera.ViewportSize;
177 float num = viewportSize.X / viewportSize.Y;
178 Vector2 vector = new(0f, 0f);
179 Vector2 vector2 = new(viewportSize.X, 0f);
180 Vector2 vector3 = new(viewportSize.X, viewportSize.Y);
181 Vector2 vector4 = new(0f, viewportSize.Y);
182 Vector2 p = new(viewportSize.X / 2f, viewportSize.Y / 2f);
183 offset.X = MathUtils.Remainder(offset.X, 1f);
184 offset.Y = MathUtils.Remainder(offset.Y, 1f);
185 Vector2 vector5 = new Vector2(0f, 0f) + offset;
186 Vector2 vector6 = new Vector2(num, 0f) + offset;
187 Vector2 vector7 = new Vector2(num, 1f) + offset;
188 Vector2 vector8 = new Vector2(0f, 1f) + offset;
189 Vector2 texCoord = new Vector2(num / 2f, 0.5f) + offset;
190 Color color2 = color * outerFactor;
191 Color color3 = color * innerFactor;
192 TexturedBatch2D texturedBatch2D = m_primitivesRenderer2D.TexturedBatch(
193 texture,
194 false,
195 0,
197 null,
200 );
201 int count = texturedBatch2D.TriangleVertices.Count;
202 texturedBatch2D.QueueTriangle(
203 vector,
204 vector2,
205 p,
206 0f,
207 vector5,
208 vector6,
209 texCoord,
210 color2,
211 color2,
212 color3
213 );
214 texturedBatch2D.QueueTriangle(
215 vector2,
216 vector3,
217 p,
218 0f,
219 vector6,
220 vector7,
221 texCoord,
222 color2,
223 color2,
224 color3
225 );
226 texturedBatch2D.QueueTriangle(
227 vector3,
228 vector4,
229 p,
230 0f,
231 vector7,
232 vector8,
233 texCoord,
234 color2,
235 color2,
236 color3
237 );
238 texturedBatch2D.QueueTriangle(
239 vector4,
240 vector,
241 p,
242 0f,
243 vector8,
244 vector5,
245 texCoord,
246 color2,
247 color2,
248 color3
249 );
250 texturedBatch2D.TransformTriangles(camera.ViewportMatrix, count);
251 texturedBatch2D.Flush();
252 }
253
254 public virtual void DrawIceOverlay(Camera camera, float factor) {
255 Vector2 viewportSize = camera.ViewportSize;
256 float s = 1f;
257 float num = factor;
258 Vector2 v = Vector2.One;
259 float num2 = v.Length();
260 Point2 point = new((int)MathF.Round(12f * viewportSize.X / viewportSize.Y), (int)MathF.Round(12f));
261 if (m_iceVertices == null
262 || m_cellsCount != point) {
263 m_cellsCount = point;
264 m_random.Seed(0);
265 m_iceVertices = new Vector2[(point.X + 1) * (point.Y + 1)];
266 for (int i = 0; i <= point.X; i++) {
267 for (int j = 0; j <= point.Y; j++) {
268 float num3 = i;
269 float num4 = j;
270 if (i != 0
271 && i != point.X) {
272 num3 += m_random.Float(-0.4f, 0.4f);
273 }
274 if (j != 0
275 && j != point.Y) {
276 num4 += m_random.Float(-0.4f, 0.4f);
277 }
278 float x = num3 / point.X;
279 float y = num4 / point.Y;
280 m_iceVertices[i + j * (point.X + 1)] = new Vector2(x, y);
281 }
282 }
283 }
284 Vector3 vector = Vector3.UnitX / camera.ProjectionMatrix.M11 * 2f * 0.2f * s;
285 Vector3 vector2 = Vector3.UnitY / camera.ProjectionMatrix.M22 * 2f * 0.2f * s;
286 Vector3 v2 = -0.2f * Vector3.UnitZ - 0.5f * (vector + vector2);
287 if (!m_light.HasValue
288 || Time.PeriodicEvent(0.05000000074505806, 0.0)) {
290 }
292 m_random.Seed(0);
293 Texture2D texture = ContentManager.Get<Texture2D>("Textures/IceOverlay");
294 TexturedBatch3D texturedBatch3D = m_primitivesRenderer3D.TexturedBatch(
295 texture,
296 false,
297 0,
302 );
303 Vector2 v3 = new(viewportSize.X / viewportSize.Y, 1f);
304 Vector2 vector3 = new(point.X - 1, point.Y - 1);
305 for (int k = 0; k < point.X; k++) {
306 for (int l = 0; l < point.Y; l++) {
307 float num5 = (new Vector2(2 * k / vector3.X - 1f, 2 * l / vector3.Y - 1f) * v).Length() / num2;
308 if (1f - num5 + m_random.Float(0f, 0.05f) < num) {
309 Vector2 v4 = m_iceVertices[k + l * (point.X + 1)];
310 Vector2 v5 = m_iceVertices[k + 1 + l * (point.X + 1)];
311 Vector2 v6 = m_iceVertices[k + 1 + (l + 1) * (point.X + 1)];
312 Vector2 v7 = m_iceVertices[k + (l + 1) * (point.X + 1)];
313 Vector3 vector4 = v2 + v4.X * vector + v4.Y * vector2;
314 Vector3 p = v2 + v5.X * vector + v5.Y * vector2;
315 Vector3 vector5 = v2 + v6.X * vector + v6.Y * vector2;
316 Vector3 p2 = v2 + v7.X * vector + v7.Y * vector2;
317 Vector2 vector6 = v4 * v3;
318 Vector2 texCoord = v5 * v3;
319 Vector2 vector7 = v6 * v3;
320 Vector2 texCoord2 = v7 * v3;
321 texturedBatch3D.QueueTriangle(
322 vector4,
323 p,
324 vector5,
325 vector6,
326 texCoord,
327 vector7,
328 color
329 );
330 texturedBatch3D.QueueTriangle(
331 vector5,
332 p2,
333 vector4,
334 vector7,
335 texCoord2,
336 vector6,
337 color
338 );
339 }
340 }
341 }
342 texturedBatch3D.Flush(camera.ProjectionMatrix);
343 }
344
345 public virtual void DrawFloatingMessage(Camera camera, string message, float factor) {
347 Vector2 position = camera.ViewportSize / 2f;
348 position.X += 0.07f * camera.ViewportSize.X * (float)Math.Sin(1.7300000190734863 * Time.FrameStartTime);
349 position.Y += 0.07f * camera.ViewportSize.Y * (float)Math.Cos(1.1200000047683716 * Time.FrameStartTime);
350 FontBatch2D fontBatch2D = m_primitivesRenderer2D.FontBatch(font, 1, DepthStencilState.None, null, BlendState.AlphaBlend);
351 int count = fontBatch2D.TriangleVertices.Count;
352 fontBatch2D.QueueText(
353 message,
354 position,
355 0f,
356 Color.White * factor,
357 TextAnchor.HorizontalCenter | TextAnchor.VerticalCenter,
360 );
361 fontBatch2D.TransformTriangles(camera.ViewportMatrix, count);
362 fontBatch2D.Flush();
363 }
364
365 public virtual void DrawMessage(Camera camera, string message, float factor) {
367 Vector2 position = new(camera.ViewportSize.X / 2f, camera.ViewportSize.Y - 25f);
368 FontBatch2D fontBatch2D = m_primitivesRenderer2D.FontBatch(font, 0, DepthStencilState.None, null, BlendState.AlphaBlend);
369 int count = fontBatch2D.TriangleVertices.Count;
370 fontBatch2D.QueueText(
371 message,
372 position,
373 0f,
374 Color.Gray * factor,
375 TextAnchor.HorizontalCenter | TextAnchor.Bottom,
378 );
379 fontBatch2D.TransformTriangles(camera.ViewportMatrix, count);
380 fontBatch2D.Flush();
381 }
382 }
383}
Engine.Color Color
readonly DynamicArray< VertexPositionColor > TriangleVertices
void TransformTriangles(Matrix matrix, int start=0, int end=-1)
void TransformTriangles(Matrix matrix, int start=0, int end=-1)
readonly DynamicArray< VertexPositionColorTexture > TriangleVertices
void TransformTriangles(Matrix matrix, int start=0, int end=-1)
readonly DynamicArray< VertexPositionColorTexture > TriangleVertices
static readonly BlendState Additive
static readonly BlendState AlphaBlend
static readonly DepthStencilState None
void Flush(bool clearAfterFlush=true)
void QueueTriangle(Vector2 p1, Vector2 p2, Vector2 p3, float depth, Color color)
void Flush(bool clearAfterFlush=true)
void QueueText(string text, Vector2 position, float depth, Color color, TextAnchor anchor=TextAnchor.Default)
static readonly RasterizerState CullNoneScissor
void QueueTriangle(Vector2 p1, Vector2 p2, Vector2 p3, float depth, Vector2 texCoord1, Vector2 texCoord2, Vector2 texCoord3, Color color)
void Flush(bool clearAfterFlush=true)
static float Remainder(float x, float y)
static float Saturate(float x)
static int Sqr(int x)
static bool PeriodicEvent(double period, double offset)
定义 Time.cs:63
static double FrameStartTime
定义 Time.cs:42
Vector3 ViewPosition
GameWidget GameWidget
Vector3 ViewUp
Matrix ViewportMatrix
Vector3 ViewDirection
Matrix ProjectionMatrix
Vector2 ViewportSize
virtual void DrawOverlay(Camera camera, Color color, float innerFactor, float outerFactor)
virtual void DrawTexturedOverlay(Camera camera, Texture2D texture, Color color, float innerFactor, float outerFactor, Vector2 offset)
virtual void DrawMessage(Camera camera, string message, float factor)
virtual void DrawFloatingMessage(Camera camera, string message, float factor)
virtual void DrawIceOverlay(Camera camera, float factor)
virtual void Draw(Camera camera, int drawOrder)
override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap)
static object Get(Type type, string name)
static BitmapFont BitmapFont
static ? float CalculateSmoothLight(SubsystemTerrain subsystemTerrain, Vector3 p)
float GlobalScale
ValuesDictionary ValuesDictionary
static Color White
static Color MultiplyColorOnly(Color c, float s)
static Color Gray
static Color Black
定义 Color.cs:7
Vector3 ToYawPitchRoll()
Vector3 Forward
static readonly Vector2 Zero
static readonly Vector2 One
static Vector3 Cross(Vector3 v1, Vector3 v2)
static Vector3 Normalize(Vector3 v)
static readonly Vector3 Zero