mirror of
https://gitgud.io/AbstractConcept/rimworld-animation-studio.git
synced 2024-08-15 00:43:27 +00:00
UI 2.0
This commit is contained in:
parent
c3c0a05ac0
commit
3d859555ad
324 changed files with 13886 additions and 7446 deletions
|
@ -9,12 +9,14 @@ namespace RimWorldAnimationStudio
|
|||
{
|
||||
public class InputManager : Singleton<InputManager>
|
||||
{
|
||||
public Transform dialogBoxes;
|
||||
|
||||
private float lastUpdate = -1f;
|
||||
private float timeBetweenUpdates = 0.15f;
|
||||
private float largeStep = 0.1f;
|
||||
private float smallStep = 0.03f;
|
||||
|
||||
public bool CanUpdate()
|
||||
public bool CanRepeatThisUpdate()
|
||||
{
|
||||
if (Time.unscaledTime > lastUpdate + timeBetweenUpdates)
|
||||
{
|
||||
|
@ -25,204 +27,290 @@ namespace RimWorldAnimationStudio
|
|||
return false;
|
||||
}
|
||||
|
||||
public bool IsModifierKeyHeld()
|
||||
{
|
||||
if (Input.GetKey(KeyCode.LeftShift)) return true;
|
||||
if (Input.GetKey(KeyCode.LeftControl)) return true;
|
||||
if (Input.GetKey(KeyCode.LeftAlt)) return true;
|
||||
if (Input.GetKey(KeyCode.LeftCommand)) return true;
|
||||
if (Input.GetKey(KeyCode.RightShift)) return true;
|
||||
if (Input.GetKey(KeyCode.RightControl)) return true;
|
||||
if (Input.GetKey(KeyCode.RightAlt)) return true;
|
||||
if (Input.GetKey(KeyCode.RightCommand)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsDialogBoxIsActive()
|
||||
{
|
||||
foreach (Transform child in dialogBoxes)
|
||||
{ if (child.gameObject.activeSelf) return true; }
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
// Make new animation
|
||||
if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.LeftCommand)) && Input.GetKeyDown(KeyCode.N))
|
||||
{ ApplicationManager.Instance.TryToMakeNewAnimation(); }
|
||||
if (IsDialogBoxIsActive()) return;
|
||||
|
||||
// Save animation
|
||||
else if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.LeftCommand)) && Input.GetKeyDown(KeyCode.S))
|
||||
{ ApplicationManager.Instance.TryToSaveAnimation(); }
|
||||
bool canRepeatThisUpdate = CanRepeatThisUpdate();
|
||||
|
||||
// Load animation
|
||||
else if ((Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.LeftCommand)) && Input.GetKeyDown(KeyCode.L))
|
||||
{ ApplicationManager.Instance.TryToLoadAnimation(); }
|
||||
foreach (Keybind keybind in KeybindConfig.Instance.GetAllKeybinds())
|
||||
{
|
||||
if (IsModifierKeyHeld() && keybind.keyModifiers.NullOrEmpty()) goto nextKeybind;
|
||||
|
||||
// Exit if animationDef has not be loaded
|
||||
foreach (KeyCode modKeyCode in keybind.keyModifiers)
|
||||
{ if (Input.GetKey(modKeyCode) == false) goto nextKeybind; }
|
||||
|
||||
if (keybind.repeatable && canRepeatThisUpdate)
|
||||
{ if (Input.GetKey(keybind.keyCode) == false) goto nextKeybind; }
|
||||
|
||||
else
|
||||
{ if (Input.GetKeyDown(keybind.keyCode) == false) goto nextKeybind; }
|
||||
|
||||
//Debug.Log(keybind.command);
|
||||
Invoke(keybind.command, 0f); return;
|
||||
|
||||
nextKeybind:;
|
||||
}
|
||||
}
|
||||
|
||||
public void QuitApplication()
|
||||
{
|
||||
ApplicationManager.Instance.TryToCloseApplication();
|
||||
}
|
||||
|
||||
public void NewAnimation()
|
||||
{
|
||||
ApplicationManager.Instance.TryToMakeNewAnimation();
|
||||
}
|
||||
|
||||
public void SaveAnimation()
|
||||
{
|
||||
ApplicationManager.Instance.TryToSaveAnimation();
|
||||
}
|
||||
|
||||
public void SaveAnimationAs()
|
||||
{
|
||||
ApplicationManager.Instance.TryToSaveAnimationAs();
|
||||
}
|
||||
|
||||
public void LoadAnimation()
|
||||
{
|
||||
ApplicationManager.Instance.TryToLoadAnimation();
|
||||
}
|
||||
|
||||
public void UndoAction()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
Workspace.Instance.Undo();
|
||||
}
|
||||
|
||||
public void RedoAction()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
Workspace.Instance.Redo();
|
||||
}
|
||||
|
||||
public void ToggleAnimationPreview()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
AnimationController.Instance.ToggleAnimation();
|
||||
}
|
||||
|
||||
public void CopyKeyframes()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
AnimationController.Instance.CopyPawnKeyframes();
|
||||
}
|
||||
|
||||
public void PasteKeyframes()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
AnimationController.Instance.PastePawnKeyframes();
|
||||
}
|
||||
|
||||
public void DeleteKeyframes()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
AnimationController.Instance.RemovePawnKeyframe();
|
||||
}
|
||||
|
||||
public void ActorMovementMode()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
AnimationController.Instance.ToggleActorManipulationMode(0);
|
||||
}
|
||||
|
||||
public void ActorRotateMode()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
AnimationController.Instance.ToggleActorManipulationMode(1);
|
||||
}
|
||||
|
||||
public void ActorFacingMode()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
AnimationController.Instance.ToggleActorManipulationMode(2);
|
||||
}
|
||||
|
||||
public void AdjustActorUpward()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
ActorKeyframeCard.Instance.AdjustActor(Vector2.up * largeStep);
|
||||
}
|
||||
|
||||
public void AdjustActorDownward()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
ActorKeyframeCard.Instance.AdjustActor(Vector2.down * largeStep);
|
||||
}
|
||||
|
||||
public void AdjustActorLeftward()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
ActorKeyframeCard.Instance.AdjustActor(Vector2.left * largeStep);
|
||||
}
|
||||
|
||||
public void AdjustActorRightward()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
ActorKeyframeCard.Instance.AdjustActor(Vector2.right * largeStep);
|
||||
}
|
||||
|
||||
public void AdjustActorUpwardSmall()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
ActorKeyframeCard.Instance.AdjustActor(Vector2.up * smallStep);
|
||||
}
|
||||
|
||||
public void AdjustActorDownwardSmall()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
ActorKeyframeCard.Instance.AdjustActor(Vector2.down * smallStep);
|
||||
}
|
||||
|
||||
public void AdjustActorLeftwardSmall()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
ActorKeyframeCard.Instance.AdjustActor(Vector2.left * smallStep);
|
||||
}
|
||||
|
||||
public void AdjustActorRightwardSmall()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
ActorKeyframeCard.Instance.AdjustActor(Vector2.right * smallStep);
|
||||
}
|
||||
|
||||
public void CycleActorBodyPartSelecion()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
|
||||
// Play / pause
|
||||
if (Input.GetKeyDown(KeyCode.Space))
|
||||
{ AnimationController.Instance.ToggleAnimation(); }
|
||||
ActorBody actorBody = AnimationController.Instance.actorBodies.GetChild(Workspace.actorID).GetComponent<ActorBody>();
|
||||
List<ActorBodyPart> actorBodyParts = actorBody.GetComponentsInChildren<ActorBodyPart>().Where(x => x.gameObject.activeInHierarchy)?.ToList();
|
||||
|
||||
// Move / switch actors
|
||||
else if (Input.GetKey(KeyCode.UpArrow) && CanUpdate())
|
||||
if (actorBodyParts.NullOrEmpty()) return;
|
||||
|
||||
if (Workspace.selectedBodyPart == null)
|
||||
{ actorBodyParts[0].Activate(); return; }
|
||||
|
||||
else
|
||||
{
|
||||
if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.LeftCommand))
|
||||
for (int i = 0; i < actorBodyParts.Count; i++)
|
||||
{
|
||||
Workspace.selectedBodyPart = null;
|
||||
Workspace.actorID = Mathf.Clamp(Workspace.actorID - 1, 0, Workspace.animationDef.actors.Count - 1);
|
||||
}
|
||||
ActorBodyPart part = actorBodyParts[i];
|
||||
|
||||
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++)
|
||||
if (part == Workspace.selectedBodyPart)
|
||||
{
|
||||
ActorBodyPart part = actorBodyParts[i];
|
||||
if (i < actorBodyParts.Count - 1)
|
||||
{ actorBodyParts[i + 1].Activate(); return; }
|
||||
|
||||
if (part == Workspace.selectedBodyPart)
|
||||
{
|
||||
if (i < actorBodyParts.Count - 1)
|
||||
{ actorBodyParts[i + 1].Activate(); return; }
|
||||
|
||||
else
|
||||
{ actorBody.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;
|
||||
}
|
||||
public void ToPreviousActor()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
|
||||
else if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.LeftCommand))
|
||||
{ AnimationController.Instance.stageTick = 1; }
|
||||
Workspace.selectedBodyPart = null;
|
||||
Workspace.actorID = Mathf.Clamp(Workspace.actorID - 1, 0, Workspace.animationDef.actors.Count - 1);
|
||||
}
|
||||
|
||||
else
|
||||
{ AnimationController.Instance.stageTick = Mathf.Clamp(AnimationController.Instance.stageTick - 1, 1, Workspace.StageWindowSize); }
|
||||
}
|
||||
public void ToNextActor()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
|
||||
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;
|
||||
}
|
||||
Workspace.selectedBodyPart = null;
|
||||
Workspace.actorID = Mathf.Clamp(Workspace.actorID + 1, 0, Workspace.animationDef.actors.Count - 1);
|
||||
}
|
||||
|
||||
else if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.LeftCommand))
|
||||
{ AnimationController.Instance.stageTick = Workspace.StageWindowSize; }
|
||||
public void ToPreviousTick()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
AnimationController.Instance.stageTick = Mathf.Clamp(AnimationController.Instance.stageTick - 1, 1, Workspace.StageWindowSize);
|
||||
}
|
||||
|
||||
else
|
||||
{ AnimationController.Instance.stageTick = Mathf.Clamp(AnimationController.Instance.stageTick + 1, 1, Workspace.StageWindowSize); }
|
||||
}
|
||||
public void ToNextTick()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
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);
|
||||
public void ToFirstTick()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
AnimationController.Instance.stageTick = 1;
|
||||
}
|
||||
|
||||
if (Workspace.stageID != prevStageID)
|
||||
{ Workspace.Instance.RecordEvent("Stage selected"); }
|
||||
}
|
||||
public void ToLastTick()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
AnimationController.Instance.stageTick = Workspace.StageWindowSize;
|
||||
}
|
||||
|
||||
else if (Input.GetKeyDown(KeyCode.End))
|
||||
{
|
||||
|
||||
int prevStageID = Workspace.stageID;
|
||||
Workspace.stageID = Mathf.Clamp(Workspace.stageID + 1, 0, Workspace.animationDef.animationStages.Count - 1);
|
||||
public void ToPreviousKey()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
PawnKeyframe keyframe = Workspace.Instance.GetPreviousKeyframe(Workspace.actorID);
|
||||
if (keyframe != null) AnimationController.Instance.stageTick = keyframe.atTick.Value;
|
||||
}
|
||||
|
||||
if (Workspace.stageID != prevStageID)
|
||||
{ Workspace.Instance.RecordEvent("Stage selected"); }
|
||||
}
|
||||
public void ToNextKey()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
PawnKeyframe keyframe = Workspace.Instance.GetNextKeyframe(Workspace.actorID);
|
||||
if (keyframe != null) AnimationController.Instance.stageTick = keyframe.atTick.Value;
|
||||
}
|
||||
|
||||
// Undo
|
||||
else if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.Z))
|
||||
{ Workspace.Instance.Undo(); }
|
||||
public void ToPreviousStage()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
|
||||
else if (Input.GetKey(KeyCode.LeftCommand) && Input.GetKeyDown(KeyCode.Z))
|
||||
{ Workspace.Instance.Undo(); }
|
||||
int prevStageID = Workspace.stageID;
|
||||
Workspace.stageID = Mathf.Clamp(Workspace.stageID - 1, 0, Workspace.animationDef.animationStages.Count - 1);
|
||||
|
||||
// Redo
|
||||
else if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.Y))
|
||||
{ Workspace.Instance.Redo(); }
|
||||
if (Workspace.stageID != prevStageID)
|
||||
{ Workspace.Instance.RecordEvent("Stage selected"); }
|
||||
}
|
||||
|
||||
else if (Input.GetKey(KeyCode.LeftCommand) && Input.GetKey(KeyCode.LeftShift) && Input.GetKeyDown(KeyCode.Z))
|
||||
{ Workspace.Instance.Redo(); }
|
||||
public void ToNextStage()
|
||||
{
|
||||
if (Workspace.animationDef == null) return;
|
||||
|
||||
// Copy keyframes
|
||||
else if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.C))
|
||||
{ AnimationController.Instance.CopyPawnKeyframes(); }
|
||||
int prevStageID = Workspace.stageID;
|
||||
Workspace.stageID = Mathf.Clamp(Workspace.stageID + 1, 0, Workspace.animationDef.animationStages.Count - 1);
|
||||
|
||||
else if (Input.GetKey(KeyCode.LeftCommand) && Input.GetKeyDown(KeyCode.C))
|
||||
{ AnimationController.Instance.CopyPawnKeyframes(); }
|
||||
if (Workspace.stageID != prevStageID)
|
||||
{ Workspace.Instance.RecordEvent("Stage selected"); }
|
||||
}
|
||||
|
||||
// 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(); }
|
||||
public void CenterView()
|
||||
{
|
||||
Camera.main.GetComponent<CameraController>().ResetCamera();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue