Extra keybinds

This commit is contained in:
AbstractConcept 2022-10-08 21:15:28 -05:00
parent e210923733
commit c3c0a05ac0
139 changed files with 586 additions and 233 deletions

View file

@ -50,7 +50,7 @@ namespace RimWorldAnimationStudio
if (keyframe.atTick.HasValue)
{
if (keyframe.HasValidKeyframeID() == false)
{ keyframe.GenerateKeyframeID(); }
{ keyframe.GenerateKeyframeID(Workspace.animationDef.animationStages[Workspace.stageID].animationClips.IndexOf(this)); }
BodyAngle.Add((float)keyframe.atTick / (float)duration, keyframe.bodyAngle, true);
HeadAngle.Add((float)keyframe.atTick / (float)duration, keyframe.headAngle, true);

View file

@ -19,6 +19,7 @@ namespace RimWorldAnimationStudio
public float genitalAngle;
public bool? quiver;
[XmlIgnore] public int keyframeID;
[XmlIgnore] public int actorID = -1;
public bool ShouldSerializegenitalAngle() { return genitalAngle != 0; }
public bool ShouldSerializequiver() { return quiver != null; }
@ -28,13 +29,14 @@ namespace RimWorldAnimationStudio
soundEffect = Tags.soundDefs.Concat(CustomTags.soundDefs).Contains(soundEffect) ? soundEffect : null;
}
public void GenerateKeyframeID()
{
public void GenerateKeyframeID(int actorID)
{
this.actorID = actorID;
int _keyframeID = Random.Range(100000, 1000000);
if (Workspace.animationDef.animationStages.Any(x => x.animationClips.Any(y => y.keyframes.Any(z => z.keyframeID == _keyframeID))))
{
GenerateKeyframeID();
GenerateKeyframeID(actorID);
return;
}

View file

@ -32,7 +32,8 @@ namespace RimWorldAnimationStudio
else
{ bodyRenderer.color = Constants.ColorWhite; }
appendageRenderer.gameObject.SetActive(Workspace.animationDef.actors[actorID].requiredGenitals.Any(x => x == "Penis") || Workspace.animationDef.actors[actorID].isFucking);
//headRenderer.gameObject.SetActive(Workspace.animationDef.actors[actorID].GetAlienRaceDef().isHumanoid);
//appendageRenderer.gameObject.SetActive(Workspace.animationDef.actors[actorID].requiredGenitals.Any(x => x == "Penis") || Workspace.animationDef.actors[actorID].isFucking);
}
public void OnPointerClick(PointerEventData eventData)

View file

@ -43,5 +43,66 @@ namespace RimWorldAnimationStudio
Workspace.Instance.GetPawnAnimationClip(Workspace.actorID).BuildSimpleCurves();
Workspace.Instance.RecordEvent("Actor position / orientation");
}
public void AdjustActor(Vector2 deltaOffset)
{
float deltaAngle = -deltaOffset.x * 33.3333f + deltaOffset.y * 33.3333f;
int facing = deltaOffset.x < 0 ? 3 : deltaOffset.y < 0 ? 2 : deltaOffset.x > 0 ? 1 : 0;
switch (Workspace.actorManipulationMode)
{
case ActorManipulationMode.Pan: MoveActor(deltaOffset); break;
case ActorManipulationMode.Rotate: RotateActor(deltaAngle); break;
case ActorManipulationMode.Face: FaceActor(facing); break;
}
}
public void MoveActor(Vector2 deltaOffset)
{
PawnKeyframe keyframe = Workspace.Instance.GetCurrentPawnKeyframe(true);
if (Workspace.selectedBodyPart == null)
{
keyframe.bodyOffsetX += deltaOffset.x;
keyframe.bodyOffsetZ += deltaOffset.y;
}
else if (Workspace.selectedBodyPart.isHead)
{ keyframe.headBob += deltaOffset.y; }
Workspace.Instance.GetCurrentPawnAnimationClip().BuildSimpleCurves();
Workspace.Instance.RecordEvent("Actor position / orientation");
}
public void RotateActor(float deltaAngle)
{
PawnKeyframe keyframe = Workspace.Instance.GetCurrentPawnKeyframe(true);
if (Workspace.selectedBodyPart == null)
{ keyframe.bodyAngle += deltaAngle; }
else if (Workspace.selectedBodyPart.isHead)
{ keyframe.headAngle += deltaAngle; }
else
{ keyframe.genitalAngle -= deltaAngle; }
Workspace.Instance.GetCurrentPawnAnimationClip().BuildSimpleCurves();
Workspace.Instance.RecordEvent("Actor position / orientation");
}
public void FaceActor(int facing)
{
PawnKeyframe keyframe = Workspace.Instance.GetCurrentPawnKeyframe(true);
if (Workspace.selectedBodyPart == null)
{ keyframe.bodyFacing = facing; }
else if (Workspace.selectedBodyPart.isHead)
{ keyframe.headFacing = facing; }
Workspace.Instance.GetCurrentPawnAnimationClip().BuildSimpleCurves();
Workspace.Instance.RecordEvent("Actor position / orientation");
}
}
}

View file

@ -56,6 +56,7 @@ namespace RimWorldAnimationStudio
if (Workspace.animationDef == null) return;
Workspace.animationDef.actors[Workspace.actorID].SetAlienRaceDef(label.text);
Workspace.selectedBodyPart = null;
}
}
}

View file

@ -143,6 +143,7 @@ namespace RimWorldAnimationStudio
{ continue; }
bool quiver = isAnimating && Workspace.Instance.GetCurrentOrPreviousKeyframe(actorID).quiver == true;
bool requiresGenitals = actor.requiredGenitals.Any(x => x == "Penis") || Workspace.animationDef.actors[actorID].isFucking;
float clipPercent = (float)(stageTick % clip.duration) / clip.duration;
if (stageTick == clip.duration) clipPercent = 1f;
@ -184,7 +185,7 @@ namespace RimWorldAnimationStudio
actorBody.bodyRenderer.sprite = alienRaceDef.GetBodyTypeGraphic((CardinalDirection)bodyFacing, bodyType);
actorBody.headRenderer.sprite = alienRaceDef.isHumanoid ? alienRaceDef.GetHeadGraphic((CardinalDirection)headFacing) : null;
actorBody.appendageRenderer.sprite = alienRaceDef.isHumanoid && bodyFacing != 0 ? Resources.Load<Sprite>("Textures/Humanlike/Appendages/Appendage" + bodyFacing) : null;
actorBody.appendageRenderer.sprite = requiresGenitals && alienRaceDef.isHumanoid && bodyFacing != 0 ? Resources.Load<Sprite>("Textures/Humanlike/Appendages/Appendage" + bodyFacing) : null;
actorBody.bodyRenderer.gameObject.SetActive(actorBody.bodyRenderer.sprite != null);
actorBody.headRenderer.gameObject.SetActive(actorBody.headRenderer.sprite != null);
@ -352,7 +353,7 @@ namespace RimWorldAnimationStudio
{ Debug.LogWarning("Cannot clone pawn keyframe - a keyframe already exists at this tick"); return; }
PawnKeyframe cloneFrame = keyframe.Copy();
cloneFrame.GenerateKeyframeID();
cloneFrame.GenerateKeyframeID(clipID);
cloneFrame.atTick = stageTick;
PawnKeyframe nextKeyframe = clip.keyframes.FirstOrDefault(x => x.atTick > stageTick);
@ -371,6 +372,48 @@ namespace RimWorldAnimationStudio
Workspace.Instance.RecordEvent("Keyframe clone");
}
public void CopyPawnKeyframes()
{
Workspace.copiedKeyframes.Clear();
List<PawnKeyframe> keyframesToClone = Workspace.Instance.GetPawnKeyframes(Workspace.keyframeID);
foreach (PawnKeyframe keyframe in keyframesToClone)
{ Workspace.copiedKeyframes.Add(keyframe.Copy()); }
}
public void PastePawnKeyframes()
{
foreach (PawnKeyframe keyframe in Workspace.copiedKeyframes)
{
PawnAnimationClip clip = Workspace.animationDef.animationStages[Workspace.stageID].animationClips[keyframe.actorID];
if (Workspace.Instance.DoesPawnKeyframeExistAtTick(Workspace.stageID, keyframe.actorID, stageTick))
{
PawnKeyframe oldKeyframe = Workspace.animationDef.animationStages[Workspace.stageID].animationClips[keyframe.actorID].keyframes.First(x => x.atTick == stageTick);
RemovePawnKeyframe(keyframe.actorID, oldKeyframe.keyframeID, true);
}
keyframe.GenerateKeyframeID(keyframe.actorID);
keyframe.atTick = stageTick;
PawnKeyframe nextKeyframe = clip.keyframes.FirstOrDefault(x => x.atTick > stageTick);
if (nextKeyframe != null)
{ clip.keyframes.Insert(clip.keyframes.IndexOf(nextKeyframe), keyframe); }
else
{ clip.keyframes.Add(keyframe); }
clip.BuildSimpleCurves();
animationTimelines.GetComponentsInChildren<AnimationTimeline>()[keyframe.actorID].AddPawnKeyFrame(keyframe.keyframeID);
clip.BuildSimpleCurves();
}
}
public void RemovePawnKeyframe()
{
foreach (int keyframeID in Workspace.keyframeID)
@ -380,17 +423,17 @@ namespace RimWorldAnimationStudio
}
}
public void RemovePawnKeyframe(int actorID, int keyframeID)
public void RemovePawnKeyframe(int actorID, int keyframeID, bool force = false)
{
PawnKeyframe keyframe = Workspace.Instance.GetPawnKeyframe(actorID, keyframeID);
PawnAnimationClip clip = Workspace.animationDef.animationStages[Workspace.stageID].animationClips[actorID];
if (keyframe == null || clip == null) return;
if (keyframe.atTick == 1)
if (keyframe.atTick == 1 && force == false)
{ Debug.LogWarning("Cannot delete key frame - the first key frame of an animation clip cannot be deleted"); return; }
if (clip.keyframes.Count <= 2)
if (clip.keyframes.Count <= 2 && force == false)
{ Debug.LogWarning("Cannot delete key frame - an animation clip must have two or more keyframes"); return; }
animationTimelines.GetComponentsInChildren<AnimationTimeline>()[actorID].RemovePawnKeyFrame(keyframe.keyframeID);

View file

@ -9,34 +9,220 @@ namespace RimWorldAnimationStudio
{
public class InputManager : Singleton<InputManager>
{
private float lastUpdate = -1f;
private float timeBetweenUpdates = 0.15f;
private float largeStep = 0.1f;
private float smallStep = 0.03f;
public bool CanUpdate()
{
if (Time.unscaledTime > lastUpdate + timeBetweenUpdates)
{
lastUpdate = Time.unscaledTime;
return true;
}
return false;
}
public void Update()
{
if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.Z))
// Make new animation
if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.LeftCommand)) && Input.GetKeyDown(KeyCode.N))
{ ApplicationManager.Instance.TryToMakeNewAnimation(); }
// Save animation
else if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.LeftCommand)) && Input.GetKeyDown(KeyCode.S))
{ ApplicationManager.Instance.TryToSaveAnimation(); }
// Load animation
else if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.LeftCommand)) && Input.GetKeyDown(KeyCode.L))
{ ApplicationManager.Instance.TryToLoadAnimation(); }
// Exit if animationDef has not be loaded
if (Workspace.animationDef == null) return;
// Play / pause
if (Input.GetKeyDown(KeyCode.Space))
{ AnimationController.Instance.ToggleAnimation(); }
// Move / switch actors
else if (Input.GetKey(KeyCode.UpArrow) && CanUpdate())
{
if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.LeftCommand))
{
Workspace.selectedBodyPart = null;
Workspace.actorID = Mathf.Clamp(Workspace.actorID - 1, 0, Workspace.animationDef.actors.Count - 1);
}
else if (Input.GetKey(KeyCode.LeftShift))
{ ActorKeyframeCard.Instance.AdjustActor(Vector2.up * smallStep); }
else
{ ActorKeyframeCard.Instance.AdjustActor(Vector2.up * largeStep); }
}
else if (Input.GetKey(KeyCode.DownArrow) && CanUpdate())
{
if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.LeftCommand))
{
Workspace.selectedBodyPart = null;
Workspace.actorID = Mathf.Clamp(Workspace.actorID + 1, 0, Workspace.animationDef.actors.Count - 1);
}
else if (Input.GetKey(KeyCode.LeftShift))
{ ActorKeyframeCard.Instance.AdjustActor(Vector2.down * smallStep); }
else
{ ActorKeyframeCard.Instance.AdjustActor(Vector2.down * largeStep); }
}
else if (Input.GetKey(KeyCode.LeftArrow) && CanUpdate())
{
if (Input.GetKey(KeyCode.LeftShift))
{ ActorKeyframeCard.Instance.AdjustActor(Vector2.left * smallStep); }
else
{ ActorKeyframeCard.Instance.AdjustActor(Vector2.left * largeStep); }
}
else if (Input.GetKey(KeyCode.RightArrow) && CanUpdate())
{
if (Input.GetKey(KeyCode.LeftShift))
{ ActorKeyframeCard.Instance.AdjustActor(Vector2.right * smallStep); }
else
{ ActorKeyframeCard.Instance.AdjustActor(Vector2.right * largeStep); }
}
// Switch to actor panning
else if (Input.GetKeyDown(KeyCode.Q))
{ AnimationController.Instance.ToggleActorManipulationMode(0); }
// Switch to actor rotating
else if (Input.GetKeyDown(KeyCode.W))
{ AnimationController.Instance.ToggleActorManipulationMode(1); }
// SWitch to actor facing
else if (Input.GetKeyDown(KeyCode.E))
{ AnimationController.Instance.ToggleActorManipulationMode(2); }
// Switch between body parts
else if (Input.GetKeyDown(KeyCode.Tab))
{
ActorBody actorBody = AnimationController.Instance.actorBodies.GetChild(Workspace.actorID).GetComponent<ActorBody>();
List<ActorBodyPart> actorBodyParts = actorBody.GetComponentsInChildren<ActorBodyPart>().Where(x => x.gameObject.activeInHierarchy)?.ToList();
foreach(Transform c in actorBody.transform)
{
Debug.Log(c.gameObject + " " + c.gameObject.activeSelf);
}
if (actorBodyParts.NullOrEmpty()) return;
if (Workspace.selectedBodyPart == null)
{ actorBodyParts[0].Activate(); return; }
else
{
for (int i = 0; i < actorBodyParts.Count; i++)
{
ActorBodyPart part = actorBodyParts[i];
if (part == Workspace.selectedBodyPart)
{
if (i < actorBodyParts.Count - 1)
{ actorBodyParts[i + 1].Activate(); return; }
else
{ actorBody.Activate(); return; }
}
}
}
}
// Move along time lines
else if (Input.GetKey(KeyCode.PageUp) && CanUpdate())
{
if (Input.GetKey(KeyCode.LeftShift))
{
PawnKeyframe keyframe = Workspace.Instance.GetPreviousKeyframe(Workspace.actorID);
if (keyframe != null) AnimationController.Instance.stageTick = keyframe.atTick.Value;
}
else if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.LeftCommand))
{ AnimationController.Instance.stageTick = 1; }
else
{ AnimationController.Instance.stageTick = Mathf.Clamp(AnimationController.Instance.stageTick - 1, 1, Workspace.StageWindowSize); }
}
else if (Input.GetKey(KeyCode.PageDown) && CanUpdate())
{
if (Input.GetKey(KeyCode.LeftShift))
{
PawnKeyframe keyframe = Workspace.Instance.GetNextKeyframe(Workspace.actorID);
if (keyframe != null) AnimationController.Instance.stageTick = keyframe.atTick.Value;
}
else if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.LeftCommand))
{ AnimationController.Instance.stageTick = Workspace.StageWindowSize; }
else
{ AnimationController.Instance.stageTick = Mathf.Clamp(AnimationController.Instance.stageTick + 1, 1, Workspace.StageWindowSize); }
}
// Switch stages
else if (Input.GetKeyDown(KeyCode.Home))
{
int prevStageID = Workspace.stageID;
Workspace.stageID = Mathf.Clamp(Workspace.stageID - 1, 0, Workspace.animationDef.animationStages.Count - 1);
if (Workspace.stageID != prevStageID)
{ Workspace.Instance.RecordEvent("Stage selected"); }
}
else if (Input.GetKeyDown(KeyCode.End))
{
int prevStageID = Workspace.stageID;
Workspace.stageID = Mathf.Clamp(Workspace.stageID + 1, 0, Workspace.animationDef.animationStages.Count - 1);
if (Workspace.stageID != prevStageID)
{ Workspace.Instance.RecordEvent("Stage selected"); }
}
// Undo
else if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.Z))
{ Workspace.Instance.Undo(); }
else if (Input.GetKey(KeyCode.LeftCommand) && Input.GetKeyDown(KeyCode.Z))
{ Workspace.Instance.Undo(); }
// Redo
else if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.Y))
{ Workspace.Instance.Redo(); }
else if (Input.GetKey(KeyCode.LeftCommand) && Input.GetKey(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.Z))
{ Workspace.Instance.Redo(); }
else if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.LeftCommand)) && Input.GetKeyDown(KeyCode.C))
{ AnimationController.Instance.ClonePawnKeyframe(); }
// Copy keyframes
else if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.C))
{ AnimationController.Instance.CopyPawnKeyframes(); }
else if (Input.GetKey(KeyCode.LeftCommand) && Input.GetKeyDown(KeyCode.C))
{ AnimationController.Instance.CopyPawnKeyframes(); }
// Paste keyframes
else if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.V))
{ AnimationController.Instance.PastePawnKeyframes(); }
else if (Input.GetKey(KeyCode.LeftCommand) && Input.GetKeyDown(KeyCode.X))
{ AnimationController.Instance.PastePawnKeyframes(); }
// Delete keyframes
else if (Input.GetKey(KeyCode.Backspace) || Input.GetKey(KeyCode.Delete))
{ AnimationController.Instance.RemovePawnKeyframe(); }
else if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.LeftCommand)) && Input.GetKeyDown(KeyCode.N))
{ ApplicationManager.Instance.TryToMakeNewAnimation(); }
else if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.LeftCommand)) && Input.GetKeyDown(KeyCode.S))
{ ApplicationManager.Instance.TryToSaveAnimation(); }
else if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.LeftCommand)) && Input.GetKeyDown(KeyCode.L))
{ ApplicationManager.Instance.TryToLoadAnimation(); }
}
}
}

View file

@ -20,7 +20,9 @@ namespace RimWorldAnimationStudio
public static ActorManipulationMode actorManipulationMode = ActorManipulationMode.Pan;
public static ActorBodyPart selectedBodyPart;
static int _actorID = 0;
public static List<PawnKeyframe> copiedKeyframes = new List<PawnKeyframe>();
private static int _actorID = 0;
public static int actorID { get { return Mathf.Clamp(_actorID, 0, animationDef.actors.Count - 1); } set { _actorID = value; } }
public static int StageWindowSize
@ -109,6 +111,38 @@ namespace RimWorldAnimationStudio
return animationDef.animationStages[stageID].animationClips[actorID].keyframes.Any(x => x.atTick == atTick);
}
public PawnKeyframe GetNextKeyframe(int actorID)
{
PawnKeyframe pawnKeyframe = null;
PawnAnimationClip clip = GetPawnAnimationClip(actorID);
int stageTick = AnimationController.Instance.stageTick;
foreach (PawnKeyframe keyframe in clip.keyframes)
{
if (keyframe.atTick > stageTick)
{ pawnKeyframe = keyframe; break; }
}
return pawnKeyframe;
}
public PawnKeyframe GetPreviousKeyframe(int actorID)
{
PawnKeyframe pawnKeyframe = null;
PawnAnimationClip clip = GetPawnAnimationClip(actorID);
int stageTick = AnimationController.Instance.stageTick;
foreach (PawnKeyframe keyframe in clip.keyframes)
{
if (keyframe.atTick < stageTick)
{ pawnKeyframe = keyframe; }
}
return pawnKeyframe;
}
public PawnKeyframe GetCurrentOrPreviousKeyframe(int actorID)
{
PawnKeyframe pawnKeyframe = null;