|
9 | 9 | using System.Text.Json.Serialization; |
10 | 10 | using System.Threading; |
11 | 11 | using Dalamud.Logging; |
| 12 | +using Dalamud.Plugin.Services; |
12 | 13 |
|
13 | 14 | namespace DelvCD.UIElements |
14 | 15 | { |
@@ -189,46 +190,32 @@ public override void Draw(Vector2 pos, Vector2? parentSize = null, bool parentVi |
189 | 190 | const int segments = 100; |
190 | 191 | float startAngle = (float)(-Math.PI / 2f + style.StartAngle * (Math.PI / 180f)); |
191 | 192 | float endAngle = (float)(-Math.PI / 2f + style.EndAngle * (Math.PI / 180f)); |
192 | | - |
193 | | - if (style.Direction == CircleDirection.AntiClockwise) |
194 | | - { |
195 | | - startAngle *= -1; |
196 | | - endAngle *= -1; |
197 | | - } |
198 | | - |
199 | 193 |
|
200 | 194 | List<CircleData> circles; |
201 | | - if (!style.Chunked) |
202 | | - { |
203 | | - circles = new List<CircleData>() { CalculateCircle(startAngle, endAngle, progressValue, progressMaxValue, style.Direction) }; |
204 | | - } |
205 | | - else |
206 | | - { |
207 | | - int chunkCount = style.ChunkedStacksFromTrigger ? (int)progressMaxValue : style.ChunkCount; |
208 | | - circles = CalculateChunkedCircles(startAngle, endAngle, progressValue, progressMaxValue, chunkCount, style.ChunkPadding, style.Direction, style.IncompleteChunkColor); |
209 | | - } |
| 195 | + circles = new List<CircleData>() { CalculateCircle(startAngle, endAngle, progressValue, progressMaxValue, style.Direction) }; |
210 | 196 |
|
211 | 197 | foreach (CircleData circle in circles) |
212 | 198 | { |
213 | | - |
214 | | - //PluginLog.Information($"{startAngle}|{endAngle}|{circle.StartAngle}|{circle.EndAngle}"); |
215 | | - |
216 | 199 | // fill |
217 | 200 | ConfigColor fillColor = circle.FillColor ?? style.FillColor; |
218 | | - |
| 201 | + |
| 202 | + // Draw background arc first |
| 203 | + if (circle.EndAngle != startAngle) |
| 204 | + { |
| 205 | + drawList.PathArcTo(localPos, style.Radius, circle.StartAngle, endAngle, segments); |
| 206 | + drawList.PathStroke(ImGui.ColorConvertFloat4ToU32(style.BackgroundColor.Vector), ImDrawFlags.None, style.Thickness); |
| 207 | + } |
| 208 | + |
| 209 | + // Draw fill arc on top |
219 | 210 | drawList.PathArcTo(localPos, style.Radius, circle.StartAngle, circle.EndAngle, segments); |
220 | 211 | drawList.PathStroke(ImGui.ColorConvertFloat4ToU32(fillColor.Vector), ImDrawFlags.None, style.Thickness); |
221 | 212 |
|
222 | | - // anything that remains is background |
223 | | - drawList.PathArcTo(localPos, style.Radius, circle.EndAngle, endAngle, segments); |
224 | | - drawList.PathStroke(ImGui.ColorConvertFloat4ToU32(style.BackgroundColor.Vector), ImDrawFlags.None, style.Thickness); |
225 | 213 |
|
226 | | - /* |
227 | 214 | if (style.Glow) |
228 | 215 | { |
229 | | - DrawHelpers.DrawGlow(localPos, size, style.GlowThickness, style.GlowSegments, style.GlowSpeed, style.GlowColor, style.GlowColor2, drawList); |
| 216 | + DrawHelpers.DrawGlowCircle(localPos, style.Radius, style.Thickness, style.GlowPadding, style.GlowSegments, style.GlowSpeed, style.GlowColor, style.GlowColor2, drawList); |
230 | 217 | } |
231 | | - */ |
| 218 | + |
232 | 219 | } |
233 | 220 | if (style.ShowBorder) |
234 | 221 | { |
@@ -258,65 +245,37 @@ public override void Draw(Vector2 pos, Vector2? parentSize = null, bool parentVi |
258 | 245 | } |
259 | 246 | } |
260 | 247 | } |
261 | | - |
| 248 | + |
262 | 249 | private CircleData CalculateCircle(float startAngle, float endAngle, float progress, float max, CircleDirection direction) |
263 | 250 | { |
264 | 251 | CircleData circle = new(); |
265 | | - /* |
| 252 | + |
266 | 253 | float fillPercent = max == 0 ? 1f : Math.Clamp(progress / max, 0f, 1f); |
267 | | - float fillAngle = max == 0 ? endAngle : Math.Clamp(progress / max, startAngle, endAngle); |
268 | | - */ |
269 | | - float current = progress / max; |
270 | 254 | float angleRange = endAngle - startAngle; |
271 | | - float relativeAngle = startAngle + (angleRange * current); |
272 | | - |
273 | | - circle.StartAngle = startAngle; |
274 | | - circle.EndAngle = relativeAngle; |
275 | | - |
276 | | - return circle; |
277 | | - } |
278 | | - |
279 | | - private List<CircleData> CalculateChunkedCircles(float startAngle, float endAngle, float progress, float max, int count, int padding, CircleDirection direction, ConfigColor incompleteColor) |
280 | | - { |
281 | | - |
282 | | - return new List<CircleData>() { CalculateCircle(startAngle, endAngle, progress, 1, direction) }; |
283 | | - |
284 | | - /* |
285 | 255 |
|
286 | | - int paddingCount = count - 1; |
287 | | - int chunkLength = horizontal ? |
288 | | - (int)((size.X - (paddingCount * padding)) / count) : |
289 | | - (int)((size.Y - (paddingCount * padding)) / count); |
290 | | -
|
291 | | - Vector2 chunkSize = horizontal ? |
292 | | - new(chunkLength, size.Y) : |
293 | | - new(size.X, chunkLength); |
294 | | -
|
295 | | - float chunkProgressSize = max / count; |
296 | | -
|
297 | | - Vector2 pos = Vector2.Zero; |
298 | | - List<CircleData> bars = new(count); |
299 | | -
|
300 | | - for (int i = 0; i < count; i++) |
| 256 | + if (direction == CircleDirection.AntiClockwise) |
301 | 257 | { |
302 | | - int index = reversed ? count - i - 1 : i; |
303 | | - float chunkProgress = Math.Min(progress - (chunkProgressSize * index), chunkProgressSize); |
304 | | - CircleData bar = CalculateCircle(pos, chunkSize, chunkProgress, chunkProgressSize, direction); |
305 | | -
|
306 | | - pos = horizontal ? |
307 | | - new Vector2(pos.X + padding + chunkLength, pos.Y) : |
308 | | - new Vector2(pos.X, pos.Y + padding + chunkLength); |
| 258 | + // If anticlockwise, the angle range needs to be reversed |
| 259 | + angleRange = startAngle - endAngle; |
| 260 | + } |
309 | 261 |
|
310 | | - if (chunkProgress < chunkProgressSize) |
311 | | - { |
312 | | - circle.FillColor = incompleteColor; |
313 | | - } |
| 262 | + float fillAngle = angleRange * fillPercent; |
314 | 263 |
|
315 | | - circles.Add(circle); |
| 264 | + // Adjusting for direction |
| 265 | + float relativeAngle; |
| 266 | + if (direction == CircleDirection.Clockwise) |
| 267 | + { |
| 268 | + relativeAngle = startAngle + fillAngle; |
| 269 | + } |
| 270 | + else // Anticlockwise |
| 271 | + { |
| 272 | + relativeAngle = startAngle - fillAngle; |
316 | 273 | } |
317 | 274 |
|
318 | | - return circles; |
319 | | - */ |
| 275 | + circle.StartAngle = startAngle; |
| 276 | + circle.EndAngle = relativeAngle; |
| 277 | + |
| 278 | + return circle; |
320 | 279 | } |
321 | 280 |
|
322 | 281 | public void Resize(Vector2 size, bool conditions) |
|
0 commit comments