Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
StarRatingWidget.cs
浏览该文件的文档.
1using Engine;
3
4namespace Game {
5 public class StarRatingWidget : Widget {
7
8 public float m_rating;
9
10 public float StarSize { get; set; }
11
12 public Color ForeColor { get; set; }
13
14 public Color BackColor { get; set; }
15
16 public float Rating {
17 get => m_rating;
18 set => m_rating = Math.Clamp(value, 0f, 5f);
19 }
20
22 m_texture = ContentManager.Get<Texture2D>("Textures/Gui/RatingStar");
23 ForeColor = new Color(255, 192, 0);
24 BackColor = new Color(96, 96, 96);
25 StarSize = 64f;
26 }
27
28 public override void Update() {
29 if (Input.Press.HasValue
30 && HitTestGlobal(Input.Press.Value) == this) {
31 Vector2 vector = ScreenToWidget(Input.Press.Value);
32 Rating = (int)MathF.Floor(5f * vector.X / ActualSize.X + 1f);
33 }
34 }
35
36 public override void Draw(DrawContext dc) {
39 false,
40 0,
42 null,
43 null,
45 );
46 float x = 0f;
47 float x2 = ActualSize.X * Rating / 5f;
48 float x3 = ActualSize.X;
49 float y = 0f;
50 float y2 = ActualSize.Y;
51 int count = texturedBatch2D.TriangleVertices.Count;
52 texturedBatch2D.QueueQuad(
53 new Vector2(x, y),
54 new Vector2(x2, y2),
55 0f,
56 new Vector2(0f, 0f),
57 new Vector2(Rating, 1f),
59 );
60 texturedBatch2D.QueueQuad(
61 new Vector2(x2, y),
62 new Vector2(x3, y2),
63 0f,
64 new Vector2(Rating, 0f),
65 new Vector2(5f, 1f),
67 );
68 texturedBatch2D.TransformTriangles(GlobalTransform, count);
69 }
70
71 public override void MeasureOverride(Vector2 parentAvailableSize) {
72 IsDrawRequired = true;
74 }
75 }
76}
Engine.Color Color
void TransformTriangles(Matrix matrix, int start=0, int end=-1)
readonly DynamicArray< VertexPositionColorTexture > TriangleVertices
static readonly DepthStencilState None
TexturedBatch2D TexturedBatch(Texture2D texture, bool useAlphaTest=false, int layer=0, DepthStencilState depthStencilState=null, RasterizerState rasterizerState=null, BlendState blendState=null, SamplerState samplerState=null)
void QueueQuad(Vector2 corner1, Vector2 corner2, float depth, Vector2 texCoord1, Vector2 texCoord2, Color color)
static object Get(Type type, string name)
override void Draw(DrawContext dc)
override void MeasureOverride(Vector2 parentAvailableSize)
readonly PrimitivesRenderer2D PrimitivesRenderer2D
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