Skip to content

Commit aaa52ba

Browse files
committed
[PR] Update to .net8
Update for patch 6.58, minor refactoring for new style rules, no functional changes.
1 parent 689245c commit aaa52ba

File tree

5 files changed

+85
-70
lines changed

5 files changed

+85
-70
lines changed

PositionalGuide/ConfigWindow.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class ConfigWindow: Window, IDisposable {
3939
public delegate void SettingsUpdate();
4040
public event SettingsUpdate? OnSettingsUpdate;
4141

42-
public ConfigWindow(Plugin core) : base(core.Name, flags) {
42+
public ConfigWindow(Plugin core) : base(Plugin.Name, flags) {
4343
this.RespectCloseHotkey = true;
4444
this.TitleBarButtons = new() {
4545
new() {

PositionalGuide/Plugin.cs

Lines changed: 70 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ private enum CircleTypes { Target, Outer };
3434

3535
private bool disposed;
3636

37-
public string Name { get; } = "Positional Assistant";
37+
public const string Name = "Positional Assistant";
3838
public const string DTRDisplayName = "Guidelines";
3939

4040
[PluginService] public static IGameGui Gui { get; private set; } = null!;
@@ -44,6 +44,7 @@ private enum CircleTypes { Target, Outer };
4444
[PluginService] public static IClientState Client { get; private set; } = null!;
4545
[PluginService] public static ITargetManager Targets { get; private set; } = null!;
4646
[PluginService] public static IPluginLog Log { get; private set; } = null!;
47+
[PluginService] public static INotificationManager Notifications { get; private set; } = null!;
4748

4849
public Configuration Config { get; private set; }
4950

@@ -56,38 +57,38 @@ public Plugin(IDtrBar dtrBar) {
5657
this.Config.Update();
5758

5859
this.configWindow = new(this);
59-
this.configWindow.OnSettingsUpdate += this.settingsUpdated;
60+
this.configWindow.OnSettingsUpdate += this.SettingsUpdated;
6061
this.windowSystem = new(this.GetType().Namespace!);
6162
this.windowSystem.AddWindow(this.configWindow);
6263

63-
Commands.AddHandler(Command, new(this.onPluginCommand) {
64-
HelpMessage = $"Open {this.Name}'s config window",
64+
Commands.AddHandler(Command, new(this.OnPluginCommand) {
65+
HelpMessage = $"Open {Name}'s config window",
6566
ShowInHelp = true,
6667
});
6768

68-
this.dtrEntry = dtrBar.Get(this.Name);
69-
this.setDtrText();
69+
this.dtrEntry = dtrBar.Get(Name);
70+
this.SetDtrText();
7071
this.dtrEntry.Tooltip = "Click to toggle all rendering";
71-
this.dtrEntry.OnClick = this.dtrClickHandler;
72+
this.dtrEntry.OnClick = this.DtrClickHandler;
7273

73-
Interface.UiBuilder.OpenConfigUi += this.toggleConfigUi;
74-
Interface.UiBuilder.Draw += this.draw;
75-
this.updateCircleColours();
74+
Interface.UiBuilder.OpenConfigUi += this.ToggleConfigUi;
75+
Interface.UiBuilder.Draw += this.Draw;
76+
this.UpdateCircleColours();
7677
}
7778

78-
private void settingsUpdated() {
79-
this.setDtrText();
80-
this.updateCircleColours();
79+
private void SettingsUpdated() {
80+
this.SetDtrText();
81+
this.UpdateCircleColours();
8182
}
8283

83-
private void dtrClickHandler() {
84+
private void DtrClickHandler() {
8485
this.Config.Enabled = !this.Config.Enabled;
85-
this.setDtrText();
86+
this.SetDtrText();
8687
}
8788

88-
private void setDtrText() => this.dtrEntry.Text = $"{DTRDisplayName}: {(this.Config.Enabled ? "On" : "Off")}";
89+
private void SetDtrText() => this.dtrEntry.Text = $"{DTRDisplayName}: {(this.Config.Enabled ? "On" : "Off")}";
8990

90-
private void updateCircleColours() {
91+
private void UpdateCircleColours() {
9192
// fill a list containing the index and angle of all active lines, for every circle segment look which line is closest to it in terms of angleDifference
9293
// and use the color of that line, only needs to be done once as long as settings stay the same
9394
List<(int index, float angle)> lineIndexesAndAngles = new();
@@ -101,12 +102,12 @@ private void updateCircleColours() {
101102
}
102103

103104
for (int i = 0; i < this.circleSegmentIdxToAngle.Length; ++i) {
104-
(int index, float angle) closest = lineIndexesAndAngles.OrderBy(item => angleDifference(this.circleSegmentIdxToAngle[i], item.angle)).First();
105-
this.circleSegmentIdxToColour[i] = this.Config.LineColours[closest.index];
105+
(int index, float angle) = lineIndexesAndAngles.OrderBy(item => AngleDifference(this.circleSegmentIdxToAngle[i], item.angle)).First();
106+
this.circleSegmentIdxToColour[i] = this.Config.LineColours[index];
106107
}
107108
}
108109

109-
internal void draw() {
110+
internal void Draw() {
110111
this.windowSystem.Draw();
111112

112113
// If positionals matter in PVP, I won't help you. If they don't, I won't distract you.
@@ -175,7 +176,7 @@ internal void draw() {
175176
continue;
176177
anyLineActive = true;
177178

178-
Vector3 rotated = rotatePoint(targetPos, guidelineBasePoint2, targetFacing + this.lineIndexToAngle[lineIndex]);
179+
Vector3 rotated = RotatePoint(targetPos, guidelineBasePoint2, targetFacing + this.lineIndexToAngle[lineIndex]);
179180
bool endpointOnScreen = Gui.WorldToScreen(rotated, out Vector2 coord);
180181
if (limitEither) {
181182
if (!targetOnScreen && !endpointOnScreen)
@@ -187,11 +188,11 @@ internal void draw() {
187188
}
188189

189190
if (this.Config.DrawCircle) {
190-
this.drawCircle(drawing, targetPos, circleBasePoint, targetFacing, anyLineActive, CircleTypes.Target);
191+
this.DrawCircle(drawing, targetPos, circleBasePoint, targetFacing, anyLineActive, CircleTypes.Target);
191192
}
192193

193194
if (this.Config.DrawOuterCircle) {
194-
this.drawCircle(drawing, targetPos, circleBasePoint, targetFacing, anyLineActive, CircleTypes.Outer);
195+
this.DrawCircle(drawing, targetPos, circleBasePoint, targetFacing, anyLineActive, CircleTypes.Outer);
195196

196197
}
197198

@@ -200,10 +201,10 @@ internal void draw() {
200201
if (this.Config.DrawTetherLine && target != player) {
201202

202203
// radians between DUE SOUTH (angle=0) and PLAYER POSITION using TARGET POSITION as the vertex
203-
double angleToPlayer = angleBetween(targetPos, targetPos + Vector3.UnitZ, playerPos);
204+
double angleToPlayer = AngleBetween(targetPos, targetPos + Vector3.UnitZ, playerPos);
204205

205206
// radians between DUE SOUTH (angle=0) and TARGET POSITION using PLAYER POSITION as the vertex
206-
double angleToTarget = angleBetween(playerPos, playerPos + Vector3.UnitZ, targetPos);
207+
double angleToTarget = AngleBetween(playerPos, playerPos + Vector3.UnitZ, targetPos);
207208

208209
// the scalar offset from the target position towards their target ring, in the direction DUE SOUTH (angle=0)
209210
// if set distance is -1, point is the centre of the target, so offset is 0
@@ -214,14 +215,14 @@ internal void draw() {
214215
// the world position for the tether's inner point, as the offset point rotated around the centre to face the player
215216
Vector3 tetherInner = offset == 0
216217
? targetPos
217-
: rotatePoint(targetPos, targetPos + new Vector3(0, 0, offset), angleToPlayer);
218+
: RotatePoint(targetPos, targetPos + new Vector3(0, 0, offset), angleToPlayer);
218219

219220
// the world position for the tether's outer point, extending the set distance from the target's ring in the direction of the player
220221
// or, if set distance is -1, to the player's centre; if -2, to the edge of the player's ring
221222
Vector3 tetherOuter = this.Config.TetherLengthOuter switch {
222-
-2 => rotatePoint(playerPos, playerPos + new Vector3(0, 0, player.HitboxRadius), angleToTarget),
223+
-2 => RotatePoint(playerPos, playerPos + new Vector3(0, 0, player.HitboxRadius), angleToTarget),
223224
-1 => playerPos,
224-
_ => rotatePoint(targetPos, targetPos + new Vector3(0, 0, target.HitboxRadius + this.Config.SoftOuterTetherLength), angleToPlayer).WithY(playerPos.Y),
225+
_ => RotatePoint(targetPos, targetPos + new Vector3(0, 0, target.HitboxRadius + this.Config.SoftOuterTetherLength), angleToPlayer).WithY(playerPos.Y),
225226
};
226227

227228
if (this.Config.FlattenTether)
@@ -250,8 +251,8 @@ internal void draw() {
250251
ImGui.End();
251252
}
252253

253-
private void drawCircle(ImDrawListPtr drawing, Vector3 targetPos, Vector3 basePoint, float targetFacing, bool anyLineActive, CircleTypes circleType) {
254-
Vector4 circleColour = new Vector4(1, 0, 0, 1);
254+
private void DrawCircle(ImDrawListPtr drawing, Vector3 targetPos, Vector3 basePoint, float targetFacing, bool anyLineActive, CircleTypes circleType) {
255+
Vector4 circleColour = new(1, 0, 0, 1);
255256
Vector3 circleBasePoint = basePoint;
256257
bool forceCircleColour = false;
257258

@@ -267,8 +268,8 @@ private void drawCircle(ImDrawListPtr drawing, Vector3 targetPos, Vector3 basePo
267268
break;
268269
}
269270

270-
Vector3 startPoint = rotatePoint(targetPos, circleBasePoint, targetFacing);
271-
Vector3[] points = circlePoints(targetPos, startPoint, this.circleSegmentIdxToAngle).ToArray();
271+
Vector3 startPoint = RotatePoint(targetPos, circleBasePoint, targetFacing);
272+
Vector3[] points = CirclePoints(targetPos, startPoint, this.circleSegmentIdxToAngle).ToArray();
272273

273274
(Vector2 point, bool render)[] screenPoints = new (Vector2 point, bool render)[points.Length];
274275
for (int i = 0; i < points.Length; ++i) {
@@ -278,17 +279,19 @@ private void drawCircle(ImDrawListPtr drawing, Vector3 targetPos, Vector3 basePo
278279

279280
for (int i = 0; i < screenPoints.Length; ++i) {
280281
int nextIndex = (i + 1) % screenPoints.Length;
281-
(Vector2 point, bool render) screenPoint1 = screenPoints[i];
282-
(Vector2 point, bool render) screenPoint2 = screenPoints[nextIndex];
282+
#pragma warning disable IDE0042 // Deconstruct variable declaration
283+
(Vector2 point, bool render) curPoint = screenPoints[i];
284+
(Vector2 point, bool render) nextPoint = screenPoints[nextIndex];
285+
#pragma warning restore IDE0042 // Deconstruct variable declaration
283286

284-
if (screenPoint1.render && screenPoint2.render) {
287+
if (curPoint.render && nextPoint.render) {
285288
Vector4 colour = forceCircleColour ? circleColour : this.circleSegmentIdxToColour[i];
286-
drawing.AddLine(screenPoint1.point, screenPoint2.point, ImGui.GetColorU32(colour), this.Config.LineThickness + 2);
289+
drawing.AddLine(curPoint.point, nextPoint.point, ImGui.GetColorU32(colour), this.Config.LineThickness + 2);
287290
}
288291
}
289292
}
290293

291-
private static Vector2 rotatePoint(Vector2 centre, Vector2 originalPoint, double angleRadians) {
294+
private static Vector2 RotatePoint(Vector2 centre, Vector2 originalPoint, double angleRadians) {
292295
// Adapted (read: shamelessly stolen) from https://github.com/PunishedPineapple/Distance
293296

294297
Vector2 translatedOriginPoint = originalPoint - centre;
@@ -300,23 +303,23 @@ private static Vector2 rotatePoint(Vector2 centre, Vector2 originalPoint, double
300303
((float)Math.Sin(translatedAngle + angleRadians) * distance) + centre.Y
301304
);
302305
}
303-
private static Vector3 rotatePoint(Vector3 centre, Vector3 originalPoint, double angleRadians) {
304-
Vector2 rotated = rotatePoint(new Vector2(centre.X, centre.Z), new Vector2(originalPoint.X, originalPoint.Z), angleRadians);
306+
private static Vector3 RotatePoint(Vector3 centre, Vector3 originalPoint, double angleRadians) {
307+
Vector2 rotated = RotatePoint(new Vector2(centre.X, centre.Z), new Vector2(originalPoint.X, originalPoint.Z), angleRadians);
305308
return new(rotated.X, centre.Y, rotated.Y);
306309
}
307310

308-
private static double angleBetween(Vector2 vertex, Vector2 a, Vector2 b) => Math.Atan2(b.Y - vertex.Y, b.X - vertex.X) - Math.Atan2(a.Y - vertex.Y, a.X - vertex.X);
309-
private static double angleBetween(Vector3 vertex, Vector3 a, Vector3 b) => angleBetween(new Vector2(vertex.X, vertex.Z), new Vector2(a.X, a.Z), new Vector2(b.X, b.Z));
310-
private static float angleDifference(float a, float b) => (float)(Math.Min(Math.Abs(a - b), Math.Abs(Math.Abs(a - b) - (2 * Math.PI))));
311+
private static double AngleBetween(Vector2 vertex, Vector2 a, Vector2 b) => Math.Atan2(b.Y - vertex.Y, b.X - vertex.X) - Math.Atan2(a.Y - vertex.Y, a.X - vertex.X);
312+
private static double AngleBetween(Vector3 vertex, Vector3 a, Vector3 b) => AngleBetween(new Vector2(vertex.X, vertex.Z), new Vector2(a.X, a.Z), new Vector2(b.X, b.Z));
313+
private static float AngleDifference(float a, float b) => (float)(Math.Min(Math.Abs(a - b), Math.Abs(Math.Abs(a - b) - (2 * Math.PI))));
311314

312-
private static IEnumerable<Vector2> circlePoints(Vector2 centre, Vector2 start, float[] angles) {
315+
private static IEnumerable<Vector2> CirclePoints(Vector2 centre, Vector2 start, float[] angles) {
313316
foreach (float angle in angles)
314-
yield return rotatePoint(centre, start, angle);
317+
yield return RotatePoint(centre, start, angle);
315318
}
316-
private static IEnumerable<Vector3> circlePoints(Vector3 centre, Vector3 start, float[] angles)
317-
=> circlePoints(new Vector2(centre.X, centre.Z), new Vector2(start.X, start.Z), angles).Select(v2 => new Vector3(v2.X, centre.Y, v2.Y));
319+
private static IEnumerable<Vector3> CirclePoints(Vector3 centre, Vector3 start, float[] angles)
320+
=> CirclePoints(new Vector2(centre.X, centre.Z), new Vector2(start.X, start.Z), angles).Select(v2 => new Vector3(v2.X, centre.Y, v2.Y));
318321

319-
internal void onPluginCommand(string command, string arguments) {
322+
internal void OnPluginCommand(string command, string arguments) {
320323
string[] args = arguments.Trim().Split();
321324

322325
string action = args.Length >= 1 ? args[0].ToLower() : "config";
@@ -337,7 +340,7 @@ internal void onPluginCommand(string command, string arguments) {
337340
state = null;
338341
break;
339342
case "config":
340-
this.toggleConfigUi();
343+
this.ToggleConfigUi();
341344
return;
342345
case "swap":
343346
target = "all";
@@ -437,22 +440,34 @@ internal void onPluginCommand(string command, string arguments) {
437440
break;
438441
case "tether":
439442
this.Config.DrawTetherLine = state ?? !this.Config.DrawTetherLine;
440-
Interface.UiBuilder.AddNotification($"Tether rendering {(this.Config.DrawTetherLine ? "enabled" : "disabled")}", this.Name, NotificationType.Info);
443+
Notifications.AddNotification(new() {
444+
Title = Name,
445+
Content = $"Tether rendering {(this.Config.DrawTetherLine ? "enabled" : "disabled")}",
446+
Type = NotificationType.Info,
447+
Minimized = true,
448+
MinimizedText = $"Tethers {(this.Config.DrawTetherLine ? "on" : "off")}",
449+
});
441450
break;
442451
case "render":
443452
this.Config.Enabled = state ?? !this.Config.Enabled;
444-
Interface.UiBuilder.AddNotification($"Guide rendering {(this.Config.Enabled ? "enabled" : "disabled")}", this.Name, NotificationType.Info);
453+
Notifications.AddNotification(new() {
454+
Title = Name,
455+
Content = $"Guide rendering {(this.Config.DrawTetherLine ? "enabled" : "disabled")}",
456+
Type = NotificationType.Info,
457+
Minimized = true,
458+
MinimizedText = $"Guides {(this.Config.DrawTetherLine ? "on" : "off")}",
459+
});
445460
break;
446461
default:
447462
Chat.PrintError($"Unknown target '{args[1]}'");
448463
return;
449464
}
450465

451-
this.settingsUpdated();
466+
this.SettingsUpdated();
452467
Interface.SavePluginConfig(this.Config);
453468
}
454469

455-
internal void toggleConfigUi() {
470+
internal void ToggleConfigUi() {
456471
if (this.configWindow is not null) {
457472
this.configWindow.IsOpen = !this.configWindow.IsOpen;
458473
}
@@ -468,9 +483,9 @@ protected virtual void Dispose(bool disposing) {
468483
this.disposed = true;
469484

470485
if (disposing) {
471-
Interface.UiBuilder.OpenConfigUi -= this.toggleConfigUi;
472-
Interface.UiBuilder.Draw -= this.draw;
473-
this.configWindow.OnSettingsUpdate -= this.settingsUpdated;
486+
Interface.UiBuilder.OpenConfigUi -= this.ToggleConfigUi;
487+
Interface.UiBuilder.Draw -= this.Draw;
488+
this.configWindow.OnSettingsUpdate -= this.SettingsUpdated;
474489

475490
Commands.RemoveHandler(Command);
476491

PositionalGuide/PositionalGuide.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
44
<Product>PositionalGuide</Product>
5-
<Version>4.5.0</Version>
5+
<Version>4.6.0</Version>
66
<Description>Provides drawn guidelines to see where you need to stand to hit enemies with positionals</Description>
77
<Copyright>Copyleft VariableVixen 2022</Copyright>
88
<PackageProjectUrl>https://github.com/PrincessRTFM/PositionalAssistant</PackageProjectUrl>

PositionalGuide/dalamud.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<PropertyGroup>
55
<Platforms>x64</Platforms>
66
<PlatformTarget>x64</PlatformTarget>
7-
<TargetFramework>net7-windows</TargetFramework>
7+
<TargetFramework>net8-windows</TargetFramework>
88
<OutputType>Library</OutputType>
99
<Deterministic>false</Deterministic>
1010
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

PositionalGuide/packages.lock.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{
2-
"version": 1,
3-
"dependencies": {
4-
"net7.0-windows7.0": {
5-
"DalamudPackager": {
6-
"type": "Direct",
7-
"requested": "[2.1.12, )",
8-
"resolved": "2.1.12",
9-
"contentHash": "Sc0PVxvgg4NQjcI8n10/VfUQBAS4O+Fw2pZrAqBdRMbthYGeogzu5+xmIGCGmsEZ/ukMOBuAqiNiB5qA3MRalg=="
10-
}
11-
}
12-
}
13-
}
2+
"version": 1,
3+
"dependencies": {
4+
"net8.0-windows7.0": {
5+
"DalamudPackager": {
6+
"type": "Direct",
7+
"requested": "[2.1.12, )",
8+
"resolved": "2.1.12",
9+
"contentHash": "Sc0PVxvgg4NQjcI8n10/VfUQBAS4O+Fw2pZrAqBdRMbthYGeogzu5+xmIGCGmsEZ/ukMOBuAqiNiB5qA3MRalg=="
10+
}
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)