Skip to content

Commit

Permalink
fixed bug with missclicks in the background
Browse files Browse the repository at this point in the history
  • Loading branch information
13on4rd committed Sep 28, 2024
1 parent 9d13acc commit 25422dd
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Assets/Scenes/HUD/Shop.unity

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 22 additions & 1 deletion Assets/Scripts/Global Scripts/QuestionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
using TMPro;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using UnityEngine.UIElements;

/// <summary>
/// Handles how when questions appear and evaluates the player's answer
/// </summary>
public class QuestionManager : MonoBehaviour
public class QuestionManager : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
[Header("Attributes")]
private List<QuestionData> questions;
Expand Down Expand Up @@ -142,6 +143,8 @@ public bool CheckAnswer()
public void CloseQuestionUI()
{
UIManager.Instance.SetHoveringState(false);
rightAnswer.SetActive(false);
wrongAnswer.SetActive(false);
ActivateCanvas(false);
}

Expand All @@ -162,4 +165,22 @@ private void Quit()
SceneManager.UnloadSceneAsync("Question");
UIManager.Instance.SetHoveringState(false);
}

/// <summary>
/// This function sets the setHoveringState function to true if the mouse is over the menu
/// </summary>
/// <param name="eventData"> The mouse</param>
public void OnPointerEnter(PointerEventData eventData)
{
UIManager.Instance.SetHoveringState(true);
}

/// <summary>
/// This function sets the setHoveringState function to false if the mouse is over the menu
/// </summary>
/// <param name="eventData"> The mouse</param>
public void OnPointerExit(PointerEventData eventData)
{
UIManager.Instance.SetHoveringState(false);
}
}
1 change: 0 additions & 1 deletion Assets/Scripts/HUD/PauseButton.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,5 @@ public void OnPointerExit(PointerEventData eventData)
{
mouseOver = false;
UIManager.Instance.SetHoveringState(false);

}
}
4 changes: 3 additions & 1 deletion Assets/Scripts/HUD/PauseMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
using TMPro;

/// <summary>
/// This class manages the pause menu including its resume and pause logic
/// </summary>
public class PauseMenu : MonoBehaviour
public class PauseMenu : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
{
private bool mouseOver = false;

Expand All @@ -20,6 +21,7 @@ public void Resume()
{
Time.timeScale = 1f;
SceneManager.UnloadSceneAsync("Pause");
UIManager.Instance.SetHoveringState(false);
}

/// <summary>
Expand Down
6 changes: 3 additions & 3 deletions Assets/Scripts/Map/Plots.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private void Start()
/// </summary>
private void OnMouseEnter()
{
if (tileSprite != null)
if (tileSprite != null && BuildManager.Instance.GetSelectedTowerIndex() != -1)
{
tileSprite.color = hoverColor;
}
Expand All @@ -40,7 +40,7 @@ private void OnMouseEnter()
/// </summary>
private void OnMouseExit()
{
if (tileSprite != null)
if (tileSprite != null && BuildManager.Instance.GetSelectedTowerIndex() != -1)
{
tileSprite.color = startColor;
}
Expand All @@ -59,7 +59,7 @@ private void OnMouseDown()

if (UIManager.Instance.IsHoveringUI()) return;

if (towerObject != null)
if (towerObject != null&& BuildManager.Instance.GetSelectedTowerIndex() != -1)
{
tower.OpenUpgradeUI();
return;
Expand Down
7 changes: 6 additions & 1 deletion Assets/Scripts/Tower/BuildManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class BuildManager : MonoBehaviour
[Header("References")]
[SerializeField] private Tower[] towers;

private int selectedTower = 0;
private int selectedTower = -1;

/// <summary>
/// This function manages the singleton instance, so it initializes the <c>instance</c> variable, if not set, or
Expand Down Expand Up @@ -47,4 +47,9 @@ public void SetSelectedTower(int selectedTower)
{
this.selectedTower = selectedTower;
}

public int GetSelectedTowerIndex()
{
return selectedTower;
}
}
7 changes: 3 additions & 4 deletions Assets/Scripts/Tower/TowerTypes/BaseTower.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ public void OpenUpgradeUI()
public void CloseUpgradeUI()
{
upgradeUI.SetActive(false);
UIManager.Instance.SetHoveringState(false);
}

/// <summary>
Expand All @@ -104,7 +103,8 @@ public void Answer(bool answer)
else
{
Debug.Log("wrong answer");
// punishmenet: player looses half the price of the upgrade in credits

// TODO: adjust punishment
LevelManager.Instance.SpendCurrency(CalculateCost() / 2);
}

Expand Down Expand Up @@ -155,6 +155,5 @@ private int CalculateCost()
{
return Mathf.RoundToInt(baseUpgradeCost * Mathf.Pow(level, CostExponent));
}



}
4 changes: 2 additions & 2 deletions Assets/Scripts/UIManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public class UIManager : MonoBehaviour
{
public static UIManager Instance { get; private set; }
private bool isHoveringUI;
private bool isHoveringUI = true;

/// <summary>
/// This function manages the singleton instance, so it initializes the <c>instance</c> variable, if not set, or
Expand All @@ -30,7 +30,7 @@ private void Awake()
/// <summary>
/// This function detects whether the mouse is currently hovering over an UI element
/// </summary>
/// <param name="state"> The state of where the mouse is at the moment</param>
/// <param name="state">The state whether the player hovers over an UI element</param>
public void SetHoveringState(bool state)
{
isHoveringUI = state;
Expand Down

0 comments on commit 25422dd

Please sign in to comment.