Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
ViewWidget.cs
浏览该文件的文档.
1using Engine;
3
4namespace Game {
7
9
10 public static RenderTarget2D ScreenTexture = new(Window.Size.X, Window.Size.Y, 1, ColorFormat.Rgba8888, DepthFormat.Depth24Stencil8);
11
12 public GameWidget GameWidget { get; set; }
13
15 get {
16 if (m_scalingRenderTarget == null) {
17 return null;
18 }
19 return new Point2(m_scalingRenderTarget.Width, m_scalingRenderTarget.Height);
20 }
21 }
22
23 public override void ChangeParent(ContainerWidget parentWidget) {
24 if (parentWidget is GameWidget) {
25 GameWidget = (GameWidget)parentWidget;
26 m_subsystemDrawing = GameWidget.SubsystemGameWidgets.Project.FindSubsystem<SubsystemDrawing>(true);
27 base.ChangeParent(parentWidget);
28 return;
29 }
30 throw new InvalidOperationException("ViewWidget must be a child of GameWidget.");
31 }
32
33 public override void MeasureOverride(Vector2 parentAvailableSize) {
34 IsDrawRequired = true;
35 base.MeasureOverride(parentAvailableSize);
36 }
37
38 public override void Draw(DrawContext dc) {
39 if (GameWidget.PlayerData.ComponentPlayer != null
40 && GameWidget.PlayerData.IsReadyForPlaying) {
41 DrawToScreen(dc);
42 }
43 }
44
45 public override void Dispose() {
46 base.Dispose();
48 }
49
50 public virtual void DragOver(Widget dragWidget, object data) { }
51
52 public virtual void DragDrop(Widget dragWidget, object data) {
53 if (data is InventoryDragData inventoryDragData
54 && GameManager.Project != null) {
55 SubsystemPickables subsystemPickables = GameManager.Project.FindSubsystem<SubsystemPickables>(true);
56 ComponentPlayer componentPlayer = GameWidget.PlayerData.ComponentPlayer;
57 int slotValue = inventoryDragData.Inventory.GetSlotValue(inventoryDragData.SlotIndex);
58 int count = componentPlayer != null
59 && componentPlayer.ComponentInput.SplitSourceInventory == inventoryDragData.Inventory
60 && componentPlayer.ComponentInput.SplitSourceSlotIndex == inventoryDragData.SlotIndex ? 1 :
61 inventoryDragData.DragMode != DragMode.SingleItem ? inventoryDragData.Inventory.GetSlotCount(inventoryDragData.SlotIndex) :
62 MathUtils.Min(inventoryDragData.Inventory.GetSlotCount(inventoryDragData.SlotIndex), 1);
63 int num = inventoryDragData.Inventory.RemoveSlotItems(inventoryDragData.SlotIndex, count);
64 if (num > 0) {
65 Vector2 vector = dragWidget.WidgetToScreen(dragWidget.ActualSize / 2f);
67 GameWidget.ActiveCamera.ScreenToWorld(new Vector3(vector.X, vector.Y, 1f), Matrix.Identity)
68 - GameWidget.ActiveCamera.ViewPosition
69 )
70 * 12f;
71 subsystemPickables.AddPickable(slotValue, num, GameWidget.ActiveCamera.ViewPosition, value, null, componentPlayer.Entity);
72 }
73 }
74 }
75
76 public virtual void SetupScalingRenderTarget() {
78 float num2 = GlobalTransform.Right.Length();
79 float num3 = GlobalTransform.Up.Length();
80 Vector2 vector = new(ActualSize.X * num2, ActualSize.Y * num3);
81 Point2 point = default;
82 point.X = (int)MathF.Round(vector.X * num);
83 point.Y = (int)MathF.Round(vector.Y * num);
84 Point2 point2 = point;
85 if ((num < 1f || GlobalColorTransform != Color.White)
86 && point2.X > 0
87 && point2.Y > 0) {
88 if (m_scalingRenderTarget == null
89 || m_scalingRenderTarget.Width != point2.X
90 || m_scalingRenderTarget.Height != point2.Y) {
92 m_scalingRenderTarget = new RenderTarget2D(point2.X, point2.Y, 1, ColorFormat.Rgba8888, DepthFormat.Depth24Stencil8);
93 }
94 Display.RenderTarget = m_scalingRenderTarget;
95 Display.Clear(Color.Black, 1f, 0);
96 }
97 else {
99 }
100 }
101
102 public virtual void ApplyScalingRenderTarget(DrawContext dc) {
103 if (m_scalingRenderTarget != null) {
104 BlendState blendState = GlobalColorTransform.A < byte.MaxValue ? BlendState.AlphaBlend : BlendState.Opaque;
107 false,
108 0,
111 blendState,
113 );
114 int count = texturedBatch2D.TriangleVertices.Count;
116 texturedBatch2D.TransformTriangles(GlobalTransform, count);
118 }
119 }
120
121 public virtual void DrawToScreen(DrawContext dc) {
122 GameWidget.ActiveCamera.PrepareForDrawing();
123 RenderTarget2D renderTarget = Display.RenderTarget;
125 try {
126 m_subsystemDrawing.Draw(GameWidget.ActiveCamera);
127 }
128 finally {
129 Display.RenderTarget = renderTarget;
130 }
133 "DrawToScreen",
134 loader => {
135 loader.DrawToScreen(this, dc);
136 return false;
137 }
138 );
139 }
140 }
141}
void TransformTriangles(Matrix matrix, int start=0, int end=-1)
readonly DynamicArray< VertexPositionColorTexture > TriangleVertices
static readonly BlendState Opaque
static readonly BlendState AlphaBlend
static readonly DepthStencilState None
static void Clear(Vector4? color, float? depth=null, int? stencil=null)
static RenderTarget2D RenderTarget
TexturedBatch2D TexturedBatch(Texture2D texture, bool useAlphaTest=false, int layer=0, DepthStencilState depthStencilState=null, RasterizerState rasterizerState=null, BlendState blendState=null, SamplerState samplerState=null)
void Flush(bool clearAfterFlush=true, int maxLayer=int.MaxValue)
static readonly RasterizerState CullNoneScissor
void QueueQuad(Vector2 corner1, Vector2 corner2, float depth, Vector2 texCoord1, Vector2 texCoord2, Color color)
static int Min(int x1, int x2)
static Point2 Size
static Project Project
static ResolutionMode ResolutionMode
virtual Pickable AddPickable(Pickable pickable)
virtual void SetupScalingRenderTarget()
RenderTarget2D m_scalingRenderTarget
override void Dispose()
virtual void ApplyScalingRenderTarget(DrawContext dc)
override void Draw(DrawContext dc)
GameWidget GameWidget
virtual void DragOver(Widget dragWidget, object data)
override void MeasureOverride(Vector2 parentAvailableSize)
virtual void DragDrop(Widget dragWidget, object data)
override void ChangeParent(ContainerWidget parentWidget)
SubsystemDrawing m_subsystemDrawing
Point2? ScalingRenderTargetSize
static RenderTarget2D ScreenTexture
virtual void DrawToScreen(DrawContext dc)
readonly PrimitivesRenderer2D PrimitivesRenderer2D
Color GlobalColorTransform
virtual Vector2 WidgetToScreen(Vector2 p)
bool IsDrawRequired
Vector2 ActualSize
Matrix GlobalTransform
static void HookAction(string HookName, Func< ModLoader, bool > action)
执行Hook
static Color White
static Color Black
定义 Color.cs:7
static readonly Matrix Identity
static Point2 Round(Vector2 v)
static readonly Vector2 Zero
static readonly Vector2 One
static Vector3 Normalize(Vector3 v)