forked from yanchunlei/SC-Chinese
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSubsystemSignBlockBehavior.cs
146 lines (144 loc) · 4.1 KB
/
SubsystemSignBlockBehavior.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
using Engine;
using Engine.Graphics;
using Game;
using System.Collections.Generic;
using System.Linq;
namespace ZHCN
{
public class SubsystemSignBlockBehavior : Game.SubsystemSignBlockBehavior, IUpdateable
{
public new void RenderText(FontBatch2D fontBatch, FlatBatch2D flatBatch, TextData textData)
{
if (textData.TextureLocation.HasValue)
{
var list = new List<string>();
var list2 = new List<Color>();
for (int i = 0; i < textData.Lines.Length; i++)
{
if (!string.IsNullOrEmpty(textData.Lines[i]))
{
list.Add(textData.Lines[i].Replace("\\", "").ToUpper());
list2.Add(textData.Colors[i]);
}
}
if (list.Count > 0)
{
float num = list.Max((string l) => l.Length) * 16;
float num2 = list.Count * 26;
float num3 = 4f;
float num4;
float num5;
if (num / num2 < num3)
{
num4 = num2 * num3;
num5 = num2;
}
else
{
num4 = num;
num5 = num / num3;
}
bool flag = !string.IsNullOrEmpty(textData.Url);
for (int j = 0; j < list.Count; j++)
{
var vector = new Vector2(num4 / 2f, j * 26 + textData.TextureLocation.Value * 32 + (num5 - num2) / 2f);
fontBatch.QueueText(list[j], vector, 0f, flag ? new Color(0, 0, 64) : list2[j], TextAnchor.HorizontalCenter);
if (flag)
{
flatBatch.QueueLine(new Vector2(vector.X - list[j].Length * 26 / 2, vector.Y + 26f), new Vector2(vector.X + list[j].Length * 26 / 2, vector.Y + 26f), 0f, new Color(0, 0, 64));
}
}
textData.UsedTextureWidth = num4;
textData.UsedTextureHeight = num5;
}
}
}
public new void Update(float dt)
{
bool flag = false;
foreach (View view in m_subsystemViews.Views)
{
bool flag2 = false;
foreach (Vector3 lastUpdatePosition in m_lastUpdatePositions)
{
if (Vector3.DistanceSquared(view.ActiveCamera.ViewPosition, lastUpdatePosition) < 4f)
{
flag2 = true;
break;
}
}
if (!flag2)
{
flag = true;
break;
}
}
if (!flag)
return;
m_lastUpdatePositions.Clear();
m_lastUpdatePositions.AddRange(m_subsystemViews.Views.Select(c._.UpdateRenderTarget_b__40_0));
m_nearTexts.Clear();
foreach (TextData value in m_textsByPoint.Values)
{
Point3 point = value.Point;
float num = m_subsystemViews.CalculateSquaredDistanceFromNearestView(new Vector3(point));
if (num <= 400f)
{
value.Distance = num;
m_nearTexts.Add(value);
}
}
m_nearTexts.Sort(c._.UpdateRenderTarget_b__40_1);
if (m_nearTexts.Count > 32)
m_nearTexts.RemoveRange(32, m_nearTexts.Count - 32);
foreach (TextData nearText in m_nearTexts)
{
nearText.ToBeRenderedFrame = Time.FrameIndex;
}
bool flag3 = false;
for (int i = 0; i < MathUtils.Min(m_nearTexts.Count, 32); i++)
{
TextData textData = m_nearTexts[i];
if (textData.TextureLocation.HasValue)
continue;
int num2 = m_textureLocations.FirstIndex(c._.UpdateRenderTarget_b__40_2);
if (num2 < 0)
num2 = m_textureLocations.FirstIndex(c._.UpdateRenderTarget_b__40_3);
if (num2 >= 0)
{
TextData textData2 = m_textureLocations[num2];
if (textData2 != null)
{
textData2.TextureLocation = null;
m_textureLocations[num2] = null;
}
m_textureLocations[num2] = textData;
textData.TextureLocation = num2;
flag3 = true;
}
}
if (flag3)
{
RenderTarget2D renderTarget = Display.RenderTarget;
Display.RenderTarget = m_renderTarget;
try
{
Display.Clear(new Vector4(Color.Transparent));
FlatBatch2D flatBatch = m_primitivesRenderer2D.FlatBatch(0, DepthStencilState.None, null, BlendState.Opaque);
FontBatch2D fontBatch = m_primitivesRenderer2D.FontBatch(m_font, 1, DepthStencilState.None, null, BlendState.Opaque, SamplerState.PointClamp);
for (int j = 0; j < m_textureLocations.Length; j++)
{
TextData textData3 = m_textureLocations[j];
if (textData3 != null)
RenderText(fontBatch, flatBatch, textData3);
}
m_primitivesRenderer2D.Flush();
}
finally
{
Display.RenderTarget = renderTarget;
}
}
}
}
}