Skip to content

Commit

Permalink
Add restart & switch hotkey + bugfixes
Browse files Browse the repository at this point in the history
- Adds the ability to restart using "r"
- Adds the ability to switch between work and break timer using "ctrl + r"
  • Loading branch information
adrian-miasik committed Sep 27, 2021
1 parent f77b2de commit 408e02f
Showing 1 changed file with 45 additions and 15 deletions.
60 changes: 45 additions & 15 deletions UnityPomodoro/Assets/AdrianMiasik/Scripts/PomodoroTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ private void Initialize()

// Calculate time
_currentTime = ts.TotalSeconds;
_totalTime = (float)ts.TotalSeconds;

// Transition to setup state
SwitchState(States.SETUP);
Expand Down Expand Up @@ -295,9 +296,29 @@ private void Update()
// Play / pause the timer
if (Input.GetKeyDown(KeyCode.Space))
{
ClearSelection();
foreach (DoubleDigit digit in selectedDigits)
{
digit.Deselect();
digit.Lock();
}

rightButton.OnClick();
}


// Restart timer
if (Input.GetKeyDown(KeyCode.R))
{
if (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl))
{
breakSlider.OnPointerClick(null);
}
else
{
Restart(state == States.COMPLETE);
}
}

// Tab between digits
if (Input.GetKeyDown(KeyCode.Tab))
{
Expand Down Expand Up @@ -689,6 +710,10 @@ public void SelectAll()
{
digit.Highlight();
}

// Since we are highlighting (instead of selecting), we bypass the text state logic hence we
// invoke it again here.
CalculateTextState();
}

public void AddSelection(DoubleDigit digitToAddToSelection)
Expand All @@ -706,7 +731,23 @@ public void RemoveSelection(DoubleDigit digitToRemoveFromSelection)
selectedDigits.Remove(digitToRemoveFromSelection);
}
}


private void CalculateTextState()
{
// Hide/show state text
if (selectedDigits.Count <= 0)
{
if (state != States.COMPLETE)
{
text.gameObject.SetActive(true);
}
}
else
{
text.gameObject.SetActive(false);
}
}

/// <summary>
/// Sets the selection to a single double digit.
/// If you'd like to select multiple digits, See AddSelection()
Expand All @@ -728,19 +769,8 @@ public void SetSelection(DoubleDigit currentDigit)
{
selectedDigits.Add(currentDigit);
}

// Hide/show state text
if (selectedDigits == null)
{
if (state != States.COMPLETE)
{
text.gameObject.SetActive(true);
}
}
else
{
text.gameObject.SetActive(false);
}

CalculateTextState();
}

public void ClearSelection()
Expand Down

0 comments on commit 408e02f

Please sign in to comment.