Skip to content

Commit

Permalink
Fix : Handling Theme Bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
tunchasan committed Sep 9, 2022
1 parent 5c28e9e commit 69b00c5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
11 changes: 10 additions & 1 deletion Assets/Scripts/Game/Controller/DeckLayoutDynamicElement.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using ProjectCard.Game.Managers;
using UnityEngine;

namespace ProjectCard.Game.Controller
Expand All @@ -10,11 +11,14 @@ public class DeckLayoutDynamicElement : DeckLayoutElement, IMovable
public Action<DeckLayoutDynamicElement, float> OnElementDrag;
public Action<DeckLayoutDynamicElement, float> OnElementDrop;
private Vector3 _offset = Vector3.zero;
private bool _hasDrawn = false;

public DynamicElementAnimationBase AnimationController => animationController;

public void OnMouseDown()
{
if(ThemeManager.Instance.OnThemeChancing) return;
_hasDrawn = true;
_offset = transform.position - GetMouseAsWorldPoint();
OnElementSelect?.Invoke(this);
}
Expand All @@ -23,10 +27,12 @@ private Vector3 GetMouseAsWorldPoint()
{
var mousePoint = Input.mousePosition;
return Camera.ScreenToWorldPoint(mousePoint);

}

public void OnMouseDrag()
{
if(ThemeManager.Instance.OnThemeChancing || !_hasDrawn) return;

var targetTransform = transform;
var targetPosition = GetMouseAsWorldPoint() + _offset;

Expand All @@ -52,7 +58,10 @@ public void OnMouseDrag()

public void OnMouseUp()
{
if(ThemeManager.Instance.OnThemeChancing || !_hasDrawn) return;

OnElementDrop?.Invoke(this, transform.position.x);
_hasDrawn = false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected virtual IEnumerator AnimateLayoutTheme(ThemeData theme)
index = isReverse ? index - 1 : index + 1;
}

ThemeManager.OnChangeThemeComplete?.Invoke();
ThemeManager.Instance.CompleteChangeTheme();
}
}
}
11 changes: 10 additions & 1 deletion Assets/Scripts/Game/Managers/ThemeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ public class ThemeManager : Singleton<ThemeManager>
[SerializeField] private Camera playerCamera;

public const int Size = 2;
public float AnimationDuration { private set; get; } = 1.75F;
public float AnimationDuration { private set; get; } = 1.5F;
public ThemeData CurrentTheme { private set; get; } = null;
public bool OnThemeChancing { private set; get; } = false;

public static Action<ThemeData> OnChangeTheme;
public static Action OnChangeThemeComplete;
Expand All @@ -34,9 +35,16 @@ private void ChangeTheme()
AnimateTheme();
}

public void CompleteChangeTheme()
{
OnChangeThemeComplete?.Invoke();
OnThemeChancing = false;
}

private void AnimateTheme()
{
OnChangeTheme?.Invoke(CurrentTheme);
OnThemeChancing = true;

var initialColor = CurrentTheme.backgroundColor;
var targetColor = background.color;
Expand All @@ -51,6 +59,7 @@ private void AnimateTheme()
DOTween.To(() => background.color, x => background.color = x, initialColor, AnimationDuration / 2F);
});

}

private void OnEnable()
Expand Down

0 comments on commit 69b00c5

Please sign in to comment.