Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
FurnitureDesignWidget.cs
浏览该文件的文档.
1using Engine;
3
4namespace Game {
6 public enum ViewMode {
11 }
12
13 public static string fName = "FurnitureDesignWidget";
14
16
18
20
22
24
25 public static bool DrawDebugFurniture;
26
27 public Vector2 Size { get; set; }
28
29 public ViewMode Mode { get; set; }
30
31 public FurnitureDesign Design { get; set; }
32
34 ClampToBounds = true;
35 Size = new Vector2(float.PositiveInfinity);
36 Mode = ViewMode.Perspective;
37 m_direction = Vector3.Normalize(new Vector3(1f, -0.5f, -1f));
38 m_rotationSpeed = new Vector2(2f, 0.5f);
39 }
40
41 public override void Draw(DrawContext dc) {
42 if (Design == null) {
43 return;
44 }
45 Matrix matrix;
46 if (Mode == ViewMode.Perspective) {
47 Viewport viewport = Display.Viewport;
48 Vector3 vector = new(0.5f, 0.5f, 0.5f);
49 Matrix m = Matrix.CreateLookAt(2.65f * m_direction + vector, vector, Vector3.UnitY);
53 * MatrixUtils.CreateScaleTranslation(2f / viewport.Width, -2f / viewport.Height, -1f, 1f);
54 matrix = m * m2 * m3;
56 for (int i = 0; i <= Design.Resolution; i++) {
57 float num = i / (float)Design.Resolution;
58 Color color = i % 2 == 0 ? new Color(56, 56, 56, 56) : new Color(28, 28, 28, 28);
59 color *= GlobalColorTransform;
60 flatBatch3D.QueueLine(new Vector3(num, 0f, 0f), new Vector3(num, 0f, 1f), color);
61 flatBatch3D.QueueLine(new Vector3(0f, 0f, num), new Vector3(1f, 0f, num), color);
62 flatBatch3D.QueueLine(new Vector3(0f, num, 0f), new Vector3(0f, num, 1f), color);
63 flatBatch3D.QueueLine(new Vector3(0f, 0f, num), new Vector3(0f, 1f, num), color);
64 flatBatch3D.QueueLine(new Vector3(0f, num, 1f), new Vector3(1f, num, 1f), color);
65 flatBatch3D.QueueLine(new Vector3(num, 0f, 1f), new Vector3(num, 1f, 1f), color);
66 }
67 Color color2 = new Color(64, 64, 64, 255) * GlobalColorTransform;
68 FontBatch3D fontBatch3D = m_primitivesRenderer3d.FontBatch(LabelWidget.BitmapFont, 1);
69 fontBatch3D.QueueText(
71 new Vector3(0.5f, 0f, 0f),
72 0.004f * new Vector3(-1f, 0f, 0f),
73 0.004f * new Vector3(0f, 0f, -1f),
74 color2,
75 TextAnchor.HorizontalCenter
76 );
77 fontBatch3D.QueueText(
79 new Vector3(1f, 0f, 0.5f),
80 0.004f * new Vector3(0f, 0f, -1f),
81 0.004f * new Vector3(1f, 0f, 0f),
82 color2,
83 TextAnchor.HorizontalCenter
84 );
86 DebugDraw();
87 }
88 }
89 else {
90 Vector3 position;
91 Vector3 up;
92 if (Mode == ViewMode.Side) {
93 position = new Vector3(1f, 0f, 0f);
94 up = new Vector3(0f, 1f, 0f);
95 }
96 else if (Mode != ViewMode.Top) {
97 position = new Vector3(0f, 0f, -10f);
98 up = new Vector3(0f, 1f, 0f);
99 }
100 else {
101 position = new Vector3(0f, 1f, 0f);
102 up = new Vector3(0f, 0f, 1f);
103 }
104 Viewport viewport2 = Display.Viewport;
105 float num2 = MathUtils.Min(ActualSize.X, ActualSize.Y);
106 Matrix m4 = Matrix.CreateLookAt(position, new Vector3(0f, 0f, 0f), up);
107 Matrix m5 = Matrix.CreateOrthographic(2f, 2f, -10f, 10f);
108 Matrix m6 = MatrixUtils.CreateScaleTranslation(num2, 0f - num2, ActualSize.X / 2f, ActualSize.Y / 2f)
110 * MatrixUtils.CreateScaleTranslation(2f / viewport2.Width, -2f / viewport2.Height, -1f, 1f);
111 matrix = Matrix.CreateTranslation(-0.5f, -0.5f, -0.5f) * m4 * m5 * m6;
112 FlatBatch2D flatBatch2D = m_primitivesRenderer2d.FlatBatch();
114 for (int j = 1; j < Design.Resolution; j++) {
115 float num3 = j / (float)Design.Resolution;
116 Vector2 v = new(ActualSize.X * num3, 0f);
117 Vector2 v2 = new(ActualSize.X * num3, ActualSize.Y);
118 Vector2 v3 = new(0f, ActualSize.Y * num3);
119 Vector2 v4 = new(ActualSize.X, ActualSize.Y * num3);
120 Vector2.Transform(ref v, ref m7, out v);
121 Vector2.Transform(ref v2, ref m7, out v2);
122 Vector2.Transform(ref v3, ref m7, out v3);
123 Vector2.Transform(ref v4, ref m7, out v4);
124 Color color3 = j % 2 == 0 ? new Color(0, 0, 0, 56) : new Color(0, 0, 0, 28);
125 Color color4 = j % 2 == 0 ? new Color(56, 56, 56, 56) : new Color(28, 28, 28, 28);
126 color3 *= GlobalColorTransform;
127 color4 *= GlobalColorTransform;
128 flatBatch2D.QueueLine(v, v2, 0f, j % 2 == 0 ? color3 : color3 * 0.75f);
129 flatBatch2D.QueueLine(v + new Vector2(1f, 0f), v2 + new Vector2(1f, 0f), 0f, color4);
130 flatBatch2D.QueueLine(v3, v4, 0f, color3);
131 flatBatch2D.QueueLine(v3 + new Vector2(0f, 1f), v4 + new Vector2(0f, 1f), 0f, color4);
132 }
133 }
134 Matrix matrix2 = Matrix.Identity;
135 FurnitureGeometry geometry = Design.Geometry;
136 for (int k = 0; k < 6; k++) {
137 Color globalColorTransform = GlobalColorTransform;
138 if (Mode == ViewMode.Perspective) {
140 globalColorTransform *= new Color(num4, num4, num4);
141 }
142 if (geometry.SubsetOpaqueByFace[k] != null) {
143 BlocksManager.DrawMeshBlock(m_primitivesRenderer3d, geometry.SubsetOpaqueByFace[k], globalColorTransform, 1f, ref matrix2, null);
144 }
145 if (geometry.SubsetAlphaTestByFace[k] != null) {
148 geometry.SubsetAlphaTestByFace[k],
149 globalColorTransform,
150 1f,
151 ref matrix2,
152 null
153 );
154 }
155 }
156 m_primitivesRenderer3d.Flush(matrix);
158 }
159
160 public override void Update() {
161 if (Mode != ViewMode.Perspective) {
162 return;
163 }
164 if (Input.Tap.HasValue
165 && HitTestGlobal(Input.Tap.Value) == this) {
167 }
168 if (Input.Press.HasValue) {
169 if (m_dragStartPoint.HasValue) {
170 Vector2 vector = ScreenToWidget(Input.Press.Value) - ScreenToWidget(m_dragStartPoint.Value);
171 Vector2 vector2 = default;
172 vector2.Y = -0.01f * vector.X;
173 vector2.X = 0.01f * vector.Y;
174 if (Time.FrameDuration > 0f) {
176 }
177 Rotate(vector2);
178 m_dragStartPoint = Input.Press;
179 }
180 }
181 else {
182 m_dragStartPoint = null;
184 m_rotationSpeed *= MathF.Pow(0.1f, Time.FrameDuration);
185 }
186 }
187
188 public override void MeasureOverride(Vector2 parentAvailableSize) {
189 IsDrawRequired = Design != null;
191 }
192
193 public void Rotate(Vector2 angles) {
194 float num = MathUtils.DegToRad(1f);
197 float num2 = MathF.Acos(Vector3.Dot(m_direction, Vector3.UnitY));
198 float num3 = MathF.Acos(Vector3.Dot(m_direction, -Vector3.UnitY));
199 angles.X = MathF.Min(angles.X, num2 - num);
200 angles.X = MathF.Max(angles.X, 0f - (num3 - num));
203 }
204
205 public void DebugDraw() { }
206 }
207}
Engine.Color Color
Engine.Vector3 Vector3
static readonly DepthStencilState DepthRead
static Viewport Viewport
void QueueLine(Vector2 p1, Vector2 p2, float depth, Color color)
void QueueLine(Vector3 p1, Vector3 p2, Color color)
void QueueText(string text, Vector3 position, Vector3 right, Vector3 down, Color color, TextAnchor anchor=TextAnchor.Default)
static int Min(int x1, int x2)
static float DegToRad(float degrees)
static float FrameDuration
定义 Time.cs:46
static void DrawMeshBlock(PrimitivesRenderer3D primitivesRenderer, BlockMesh blockMesh, float size, ref Matrix matrix, DrawBlockEnvironmentData environmentData)
override void Draw(DrawContext dc)
override void MeasureOverride(Vector2 parentAvailableSize)
static BitmapFont BitmapFont
static string Get(string className, int key)
获取在当前语言类名键对应的字符串
static readonly float[] LightIntensityByLightValueAndFace
static Matrix CreateScaleTranslation(float sx, float sy, float tx, float ty)
virtual Widget HitTestGlobal(Vector2 point, Func< Widget, bool > predicate=null)
WidgetInput Input
Color GlobalColorTransform
Vector2 DesiredSize
bool IsDrawRequired
Vector2 ActualSize
virtual Vector2 ScreenToWidget(Vector2 p)
Matrix GlobalTransform
static Matrix CreateTranslation(float x, float y, float z)
static Matrix CreatePerspectiveFieldOfView(float fieldOfViewY, float aspectRatio, float nearPlane, float farPlane)
static readonly Matrix Identity
static Matrix CreateLookAt(Vector3 position, Vector3 target, Vector3 up)
static Matrix CreateFromAxisAngle(Vector3 axis, float angle)
static Matrix CreateRotationY(float radians)
static Matrix CreateOrthographic(float width, float height, float nearPlane, float farPlane)
static Vector2 Transform(Vector2 v, Matrix m)
static Vector3 TransformNormal(Vector3 v, Matrix m)
static Vector3 Cross(Vector3 v1, Vector3 v2)
static Vector3 Normalize(Vector3 v)
static Vector3 Max(Vector3 v, float f)
static Vector3 Min(Vector3 v, float f)
static readonly Vector3 UnitY
static float Dot(Vector3 v1, Vector3 v2)
static int OppositeFace(int face)