Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animation #135

Merged
merged 5 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 59 additions & 6 deletions Splatoon/Gui/Layouts/Elements/LayoutDrawElement.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using Dalamud;
using Dalamud.Game;
using Dalamud.Game;
using Dalamud.Interface.Components;
using Dalamud.Interface.Utility.Raii;
using ECommons.GameFunctions;
using ECommons.ImGuiMethods;
using ECommons.LanguageHelpers;
using Lumina.Excel.GeneratedSheets;
using Newtonsoft.Json;
using Splatoon.RenderEngines;
using Splatoon.Serializables;
using Splatoon.Utility;
using System;

namespace Splatoon;

Expand Down Expand Up @@ -862,7 +860,62 @@ internal void LayoutDrawElement(Layout l, Element el, bool forceEnable = false)
{
el.SetDisplayStyle(style);
}
using (ImRaii.Disabled(!el.Filled))
{
if (el.type.EqualsAny(1, 3, 4) && el.Filled)
{
bool canSetCastAnimation = el.refActorRequireCast && el.ConfiguredRenderEngineKind() == RenderEngineKind.DirectX11;
using (ImRaii.Disabled(!canSetCastAnimation))
{
ImGuiUtils.SizedText("Cast Animation:".Loc(), WidthElement);
ImGui.SameLine();
}
ImGuiEx.HelpMarker("Choose a cast animation for this element. Requires 'While Casting' checked.\nUnsupported in ImGui Legacy renderer");
ImGui.SameLine();
using (ImRaii.Disabled(!canSetCastAnimation))
{
ImGui.SetNextItemWidth(WidthElement);
ImGuiUtils.EnumCombo("##castanimation" + i + k, ref el.castAnimation, CastAnimations.Names, CastAnimations.Tooltips);
using (ImRaii.Disabled(el.castAnimation is CastAnimationKind.Unspecified))
{
ImGui.SameLine();
ImGuiEx.Text("Color:".Loc());
ImGui.SameLine();
var v4 = ImGui.ColorConvertU32ToFloat4(el.animationColor);
if (ImGui.ColorEdit4("##animationcolorbutton" + i + k, ref v4, ImGuiColorEditFlags.NoInputs))
{
el.animationColor = ImGui.ColorConvertFloat4ToU32(v4);
}
ImGui.SameLine();
if (ImGui.Button("Copy".Loc() + "##copyfromstroke" + i + k))
{
el.animationColor = style.strokeColor;
}
if (ImGui.IsItemHovered())
{
ImGui.SetTooltip("Copy Stroke Color".Loc());
}
if (el.castAnimation is CastAnimationKind.Pulse)
{
ImGuiUtils.SizedText("Pulse:".Loc(), WidthElement);
ImGui.SameLine();

ImGuiEx.Text("Size:".Loc());
ImGui.SameLine();
ImGui.SetNextItemWidth(60f);
el.pulseSize = MathF.Min(el.pulseSize, el.EffectiveLength());
ImGui.DragFloat("##animationsize" + i + k, ref el.pulseSize, 0.01f, 0.1f, el.EffectiveLength());
ImGui.SameLine();

ImGuiEx.Text("Frequency (s):".Loc());
ImGui.SameLine();
ImGui.SetNextItemWidth(60f);
ImGui.DragFloat("##animationfreq" + i + k, ref el.pulseFrequency, 0.01f, 1, 10);
}
}
}
}
}
if ((el.type != 3) || el.includeRotation)
{
if (!(el.type == 3 && !el.includeRotation))
Expand Down Expand Up @@ -1028,7 +1081,7 @@ internal void LayoutDrawElement(Layout l, Element el, bool forceEnable = false)
ImGuiEx.HelpMarker("Choose a mechanic type that best represents this element.\n" +
"This is used for automatically setting default colors.\nOnly for DirectX11 renderer.");
ImGui.SameLine();
ImGui.SetNextItemWidth(WidthCombo);
ImGui.SetNextItemWidth(WidthElement);
ImGuiUtils.EnumCombo("##mechtype" + i + k, ref el.mechanicType, MechanicTypes.Names, MechanicTypes.Tooltips);

if ((el.type.EqualsAny(0, 1) && el.Donut > 0) || el.type == 4 || (el.type.EqualsAny(2, 3) && (el.radius > 0 || el.includeHitbox || el.includeOwnHitbox)))
Expand Down
16 changes: 11 additions & 5 deletions Splatoon/RenderEngines/DirectX11/DirectX11DisplayObjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ public DisplayObjectLine(float ax, float ay, float az, float bx, float by, float
this.startStyle = startStyle;
this.endStyle = endStyle;
}

public float Length
{
get
{
return (stop - start).Length();
}
}
public Vector3 Direction
{
get
Expand Down Expand Up @@ -107,10 +113,10 @@ public Vector2[] Bounds
{
return [
(start - PerpendicularRadius).ToVector2(),
(start + PerpendicularRadius).ToVector2(),
(stop - PerpendicularRadius).ToVector2(),
(stop + PerpendicularRadius).ToVector2(),
];
(start + PerpendicularRadius).ToVector2(),
(stop - PerpendicularRadius).ToVector2(),
(stop + PerpendicularRadius).ToVector2(),
];
}
}
}
Expand Down
29 changes: 15 additions & 14 deletions Splatoon/RenderEngines/DirectX11/DirectX11Renderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,11 @@ internal void DrawCircle(Element e, float x, float y, float z, float r, float an
{
if (e.Donut > 0)
{
DisplayObjects.Add(new DisplayObjectDonut(new(cx, z + e.offZ, cy), r, e.Donut, e.GetDisplayStyleWithOverride()));
DisplayObjects.Add(new DisplayObjectDonut(new(cx, z + e.offZ, cy), r, e.Donut, e.GetDisplayStyleWithOverride(go)));
}
else
{
var style = e.GetDisplayStyleWithOverride();
DisplayObjects.Add(new DisplayObjectCircle(new(cx, z + e.offZ, cy), r, style));
DisplayObjects.Add(new DisplayObjectCircle(new(cx, z + e.offZ, cy), r, e.GetDisplayStyleWithOverride(go)));
}
}
else
Expand All @@ -88,7 +87,7 @@ void DrawText(Element e, IGameObject go, float cx, float cy, float z)
}
}

internal void DrawCone(Element e, Vector3 origin, float? radius = null, float baseAngle = 0f)
internal void DrawCone(Element e, Vector3 origin, float? radius = null, float baseAngle = 0f, IGameObject go = null)
{
if (e.coneAngleMax > e.coneAngleMin)
{
Expand Down Expand Up @@ -119,12 +118,13 @@ internal void DrawCone(Element e, Vector3 origin, float? radius = null, float ba
}
DisplayObjects.Add(new DisplayObjectLine(center, end, 0, e.GetDisplayStyleWithOverride(), e.LineEndA, e.LineEndB));
}

DisplayObjects.Add(new DisplayObjectFan(center, innerRadius, outerRadius, angleMin, angleMax, e.GetDisplayStyleWithOverride()));
DrawText(e, null, center.X, center.Z, center.Y);
}
}

internal void AddRotatedLine(Vector3 tPos, float angle, Element e, float aradius, float hitboxRadius)
internal void AddRotatedLine(Vector3 tPos, float angle, Element e, float aradius, float hitboxRadius, IGameObject go = null)
{
if (e.includeRotation)
{
Expand All @@ -150,6 +150,7 @@ internal void AddRotatedLine(Vector3 tPos, float angle, Element e, float aradius
tPos.Y + e.offY,
tPos.Z + e.offZ));


if(!LayoutUtils.ShouldDraw(start.X, Utils.GetPlayerPositionXZY().X, start.Y, Utils.GetPlayerPositionXZY().Y)
&& !LayoutUtils.ShouldDraw(stop.X, Utils.GetPlayerPositionXZY().X, stop.Y, Utils.GetPlayerPositionXZY().Y)) return;

Expand Down Expand Up @@ -189,15 +190,15 @@ internal override void ProcessElement(Element e, Layout i = null, bool forceEnab
{
var pointPos = Utils.GetPlayerPositionXZY();
DrawCircle(e, pointPos.X, pointPos.Y, pointPos.Z, radius, e.includeRotation ? Svc.ClientState.LocalPlayer.Rotation : 0f,
e.overlayPlaceholders ? Svc.ClientState.LocalPlayer : null);
Svc.ClientState.LocalPlayer);
}
else if (e.type == 3)
{
AddRotatedLine(Utils.GetPlayerPositionXZY(), Svc.ClientState.LocalPlayer.Rotation, e, radius, 0f);
AddRotatedLine(Utils.GetPlayerPositionXZY(), Svc.ClientState.LocalPlayer.Rotation, e, radius, 0f, Svc.ClientState.LocalPlayer);
}
else if (e.type == 4)
{
DrawCone(e, Utils.GetPlayerPositionXZY(), radius, Svc.ClientState.LocalPlayer.Rotation);
DrawCone(e, Utils.GetPlayerPositionXZY(), radius, Svc.ClientState.LocalPlayer.Rotation, Svc.ClientState.LocalPlayer);
}
}
else if (e.refActorType == 2 && Svc.Targets.Target != null
Expand All @@ -210,19 +211,19 @@ internal override void ProcessElement(Element e, Layout i = null, bool forceEnab
{
DrawCircle(e, Svc.Targets.Target.GetPositionXZY().X, Svc.Targets.Target.GetPositionXZY().Y,
Svc.Targets.Target.GetPositionXZY().Z, radius, e.includeRotation ? Svc.Targets.Target.Rotation : 0f,
e.overlayPlaceholders ? Svc.Targets.Target : null);
Svc.Targets.Target);
}
else if (e.type == 3)
{
var angle = e.FaceMe ?
(180 - (MathHelper.GetRelativeAngle(Svc.Targets.Target.Position.ToVector2(), Marking.GetPlayer(e.faceplayer).Position.ToVector2()))).DegreesToRadians()
: Svc.Targets.Target.Rotation;
AddRotatedLine(Svc.Targets.Target.GetPositionXZY(), angle, e, radius, Svc.Targets.Target.HitboxRadius);
AddRotatedLine(Svc.Targets.Target.GetPositionXZY(), angle, e, radius, Svc.Targets.Target.HitboxRadius, Svc.Targets.Target);
}
else if (e.type == 4)
{
var baseAngle = e.FaceMe ? (180 - (MathHelper.GetRelativeAngle(Svc.Targets.Target.Position.ToVector2(), Marking.GetPlayer(e.faceplayer).Position.ToVector2()))).DegreesToRadians() : Svc.Targets.Target.Rotation;
DrawCone(e, Svc.Targets.Target.GetPositionXZY(), radius, baseAngle);
DrawCone(e, Svc.Targets.Target.GetPositionXZY(), radius, baseAngle, Svc.Targets.Target);
}
}
}
Expand All @@ -242,21 +243,21 @@ internal override void ProcessElement(Element e, Layout i = null, bool forceEnab
{
DrawCircle(e, a.GetPositionXZY().X, a.GetPositionXZY().Y, a.GetPositionXZY().Z, aradius,
e.includeRotation ? a.Rotation : 0f,
e.overlayPlaceholders ? a : null);
a);
}
else if (e.type == 3)
{
var angle = e.FaceMe ?
(180 - (MathHelper.GetRelativeAngle(a.Position.ToVector2(), Marking.GetPlayer(e.faceplayer).Position.ToVector2()))).DegreesToRadians()
: a.Rotation;
AddRotatedLine(a.GetPositionXZY(), angle, e, aradius, a.HitboxRadius);
AddRotatedLine(a.GetPositionXZY(), angle, e, aradius, a.HitboxRadius, a);
}
else if (e.type == 4)
{
var baseAngle = e.FaceMe ?
(180 - (MathHelper.GetRelativeAngle(a.Position.ToVector2(), Marking.GetPlayer(e.faceplayer).Position.ToVector2()))).DegreesToRadians()
: (a.Rotation);
DrawCone(e, a.GetPositionXZY(), aradius, baseAngle);
DrawCone(e, a.GetPositionXZY(), aradius, baseAngle, a);
}
}
}
Expand Down
129 changes: 78 additions & 51 deletions Splatoon/RenderEngines/DirectX11/DirectX11Scene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,24 +120,7 @@ void Draw(PctTexture? texture)
{
if (element is DisplayObjectFan elementFan)
{
if (elementFan.style.filled)
drawList.AddFanFilled(
elementFan.origin,
elementFan.innerRadius,
elementFan.outerRadius,
elementFan.angleMin,
elementFan.angleMax,
elementFan.style.originFillColor,
elementFan.style.endFillColor);
if (elementFan.style.IsStrokeVisible())
drawList.AddFan(
elementFan.origin,
elementFan.innerRadius,
elementFan.outerRadius,
elementFan.angleMin,
elementFan.angleMax,
elementFan.style.strokeColor,
thickness: elementFan.style.strokeThickness);
DrawFan(elementFan, drawList);
}
else if (element is DisplayObjectLine elementLine)
{
Expand Down Expand Up @@ -169,51 +152,95 @@ void Draw(PctTexture? texture)
return texture;
}

public void DrawLine(DisplayObjectLine line, PctDrawList drawList)
public void DrawFan(DisplayObjectFan fan, PctDrawList drawList)
{
if (line.radius == 0)
if (fan.style.filled)
drawList.AddFanFilled(
fan.origin,
fan.innerRadius,
fan.outerRadius,
fan.angleMin,
fan.angleMax,
fan.style.originFillColor,
fan.style.endFillColor);
if (fan.style.IsStrokeVisible())
drawList.AddFan(
fan.origin,
fan.innerRadius,
fan.outerRadius,
fan.angleMin,
fan.angleMax,
fan.style.strokeColor,
thickness: fan.style.strokeThickness);
if (fan.style.castFraction > 0)
{
drawList.PathLineTo(line.start);
drawList.PathLineTo(line.stop);
drawList.PathStroke(line.style.strokeColor, PctStrokeFlags.None, line.style.strokeThickness);

float arrowScale = MathF.Max(1, line.style.strokeThickness / 7f);
if (line.startStyle == LineEnd.Arrow)
if (fan.style.animation.kind is Serializables.CastAnimationKind.Pulse)
{
var arrowStart = line.start + arrowScale * 0.4f * line.Direction;
var offset = arrowScale * 0.3f * line.Perpendicular;
drawList.PathLineTo(arrowStart + offset);
drawList.PathLineTo(line.start);
drawList.PathLineTo(arrowStart - offset);
drawList.PathStroke(line.style.strokeColor, PctStrokeFlags.None, line.style.strokeThickness);
var size = fan.style.animation.size + fan.outerRadius - fan.innerRadius;
var pulsePosition = size * (float)((DateTime.Now - DateTime.MinValue).TotalMilliseconds / 1000f % fan.style.animation.frequency) / fan.style.animation.frequency;
drawList.AddFanFilled(
fan.origin,
MathF.Max(fan.innerRadius, fan.innerRadius + pulsePosition - fan.style.animation.size),
MathF.Min(fan.outerRadius, fan.innerRadius + pulsePosition),
fan.angleMin,
fan.angleMax,
fan.style.animation.color & 0x00FFFFFF,
fan.style.animation.color);
}

if (line.endStyle == LineEnd.Arrow)
else if (fan.style.animation.kind is Serializables.CastAnimationKind.Fill)
{
var arrowStart = line.stop - arrowScale * 0.4f * line.Direction;
var offset = arrowScale * 0.3f * line.Perpendicular;
drawList.PathLineTo(arrowStart + offset);
drawList.PathLineTo(line.stop);
drawList.PathLineTo(arrowStart - offset);
drawList.PathStroke(line.style.strokeColor, PctStrokeFlags.None, line.style.strokeThickness);
var size = fan.outerRadius - fan.innerRadius;
var castRadius = size * fan.style.castFraction;
drawList.AddFanFilled(
fan.origin,
fan.innerRadius,
fan.innerRadius + castRadius,
fan.angleMin,
fan.angleMax,
fan.style.animation.color,
fan.style.animation.color);
}
}
else
}

public void DrawLine(DisplayObjectLine line, PctDrawList drawList)
{
if (line.style.filled)
drawList.AddLineFilled(
line.start,
line.stop,
line.radius,
line.style.originFillColor,
line.style.endFillColor);
if (line.style.IsStrokeVisible())
drawList.AddLine(
line.start,
line.stop,
line.radius,
line.style.strokeColor);
if (line.style.castFraction > 0)
{
if (line.style.filled)
if (line.style.animation.kind is Serializables.CastAnimationKind.Pulse)
{
var length = line.style.animation.size + line.Length;
var pulsePosition = length * (float)((DateTime.Now - DateTime.MinValue).TotalMilliseconds / 1000f % line.style.animation.frequency) / line.style.animation.frequency;
drawList.AddLineFilled(
line.start,
line.stop,
line.start + line.Direction * MathF.Max(0, pulsePosition - line.style.animation.size),
line.start + line.Direction * MathF.Min(pulsePosition, line.Length),
line.radius,
line.style.originFillColor,
line.style.endFillColor);
if (line.style.IsStrokeVisible())
drawList.AddLine(
line.style.animation.color & 0x00FFFFFF,
line.style.animation.color);
}
else if (line.style.animation.kind is Serializables.CastAnimationKind.Fill)
{
var castLength = line.style.castFraction * line.Length;
drawList.AddLineFilled(
line.start,
line.stop,
line.start + line.Direction * castLength,
line.radius,
line.style.strokeColor,
thickness: line.style.strokeThickness);
line.style.animation.color,
line.style.animation.color);
}
}
}

Expand Down
Loading
Loading