Hey Gerodium,
I messed around with this and added texture rotation (but only for the circular mode), it uses Screen.DrawShape and some helper functions that
Marisa Kirisame wrote in this thread, feel free to merge it into your mod (and credit her for the helper functions). I probably did a half-ass job on it and you know your code better than I do. :)
The replacement for the circular Screen.DrawTexture call (the commented out was from your original code)
Code: Select all
//Screen.DrawTexture(texSelIcon, true, xpos, ypos,
// DTA_Alpha, (dataList[i].lifespan < 35) ? float(dataList[i].lifespan) / 35 : 1.0f,
// DTA_VirtualWidth, virtualW, DTA_VirtualHeight, virtualH, DTA_KeepRatio, true);
// make 2D shape
let shape = MakeSquare();
// get texture size and scale it
Vector2 size = TexMan.GetScaledSize(texSelIcon);
size.X *= scaling;
size.Y *= scaling;
// scale coordinates
// (some compensation for the Y coordinate to center the graphic properly)
Vector2 dpos = (xpos, ypos + ((size.Y / 2) / scaling));
dpos.X *= scaling;
dpos.Y *= scaling;
// calculate angle of texture rotation
Vector2 center = (Screen.GetWidth() / 2, Screen.GetHeight() / 2);
double ang = atan2(center.Y - dpos.Y, center.X - dpos.X) - 90;
// draw rotated texture
MoveSquare(shape, size, dpos, ang);
Screen.DrawShape(texSelIcon, true, shape,
DTA_Alpha, (dataList[i].lifespan < 35) ? float(dataList[i].lifespan) / 35 : 1.0f,
DTA_VirtualWidth, virtualW, DTA_VirtualHeight, virtualH, DTA_KeepRatio, true);
You're going to need MakeSquare() and MoveSquare(), feel free to stick it in wherever you feel is appropriate. The following code is MK's helper functions, just with cleaned up formatting and 1 tiny error fix:
Code: Select all
// create a square shape (not usable until calling MoveSquare)
static clearscope Shape2D MakeSquare()
{
// the shape that will be drawn
Shape2D square = new("Shape2D");
// texture coordinates of each corner
square.PushCoord((0, 0));
square.PushCoord((1, 0));
square.PushCoord((0, 1));
square.PushCoord((1, 1));
// two triangles make up the square
// the points have to be in counter-clockwise order
square.PushTriangle(0, 3, 1);
square.PushTriangle(0, 2, 3);
return square;
}
// set the positions of an existing square shape's vertices
static clearscope void MoveSquare(Shape2D shape, Vector2 size, Vector2 pos, double angle)
{
// clear any vertices already set
shape.Clear(Shape2D.C_Verts);
// corners of a square centered on 0,0
Vector2 points[4];
points[0] = (-0.5 * size.X, -0.5 * size.Y);
points[1] = (0.5 * size.X, -0.5 * size.Y);
points[2] = (-0.5 * size.X, 0.5 * size.Y);
points[3] = (0.5 * size.X, 0.5 * size.Y);
// apply a 2D rotation matrix:
//
// ┌ ┐ ┌ ┐
// │ cos θ -sin θ │ │ X │
// │ │ * │ │
// │ sin θ cos θ │ │ Y │
// └ ┘ └ ┘
//
// then move the points by the set offset
for (int i = 0; i < 4; i++)
{
Vector2 oldpos = points[i];
points[i].X = oldpos.X * cos(angle) - oldpos.Y * sin(angle) + pos.X;
points[i].Y = oldpos.X * sin(angle) + oldpos.Y * cos(angle) + pos.Y;
shape.PushVertex(points[i]);
}
}