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
|
public sealed override void DrawSelf(SpriteBatch spriteBatch)
{
spriteBatch.End();
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Additive, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone, null, Main.UIScaleMatrix);
foreach (var item in entitys) {
ReLogic.Graphics.DynamicSpriteFontExtensionMethods.DrawString(
spriteBatch,
FontAssets.MouseText.Value,
item?.ToString() ?? "",
GetItemPosition(item!),
Color.White,
0f,
Vector2.Zero,
1f,
SpriteEffects.None,
1f
);
}
spriteBatch.End();
spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.Opaque, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone, null, Main.UIScaleMatrix);
}
/// <summary>
/// 获取此实体需要绘制的位置
/// <code>
/// (index + 1) * ItemHeight + ItemVerticalSpacing
/// </code>
/// </summary>
private Vector2 GetItemPosition(Entity entity) => GetItemPosition(entitys.FindIndex(f => f.Equals(entity)));
/// <summary>
/// 获取此索引对应实体绘制的位置
/// <code>
/// (index + 1) * ItemHeight + ItemVerticalSpacing
/// </code>
/// </summary>
/// <returns></returns>
private Vector2 GetItemPosition(int index)
{
//1. 先计算此元素在列表中的索引 然后根据索引计算其左上角位置
_ = Main.UIScaleMatrix;
//数量 * 元素高度 + 元素间距
var itemOffset = new Vector2(0, index * ItemHeight + ItemVerticalSpacing); //TODO 现在X是没变的
var origOffset = new Vector2(LeftPadding, TopPadding);
return origOffset + itemOffset ;//origOffset + itemOffset;
}
|