Cleaned up window base code

This commit is contained in:
Pasha Bibko
2026-01-15 11:17:27 +00:00
parent da7cb58ec3
commit fd61dcb2f4
8 changed files with 32 additions and 40 deletions

View File

@@ -1,13 +1,17 @@
namespace InterfaceOff
using UnityEngine;
namespace InterfaceOff
{
public class BasicWindow : WindowBase
{
public override void OnWindowInstantiation()
{
Components.InfoText.text = "Close";
/* Adds a random advert to the display */
Components.WindowImage.sprite = AdvertRegistry.GetRandomAdvert();
Components.WindowImage.color = new Color(1, 1, 1, 1);
}
public override void OnWindowClicked()
public override void OnWindowCloseButtonClicked()
{
Destroy(gameObject);
}

View File

@@ -59,7 +59,7 @@ namespace InterfaceOff
}
}
public override void OnWindowClicked()
public override void OnWindowCloseButtonClicked()
{
if (m_TilesRotatedCorrectly == 4)
{

View File

@@ -4,28 +4,20 @@ namespace InterfaceOff
{
public class MovingWindow : WindowBase
{
private int m_Health = int.MaxValue;
public override void OnWindowInstantiation()
{
/* Creates a random health value */
m_Health = Random.Range(2, 6);
Components.InfoText.text = $"{m_Health}";
/* Adds a random advert to the display */
Components.WindowImage.sprite = AdvertRegistry.GetRandomAdvert();
Components.WindowImage.color = new Color(1, 1, 1, 1);
/* Calculates a random velocity direction */
float angle = Random.Range(0, Mathf.PI * 2);
Velocity = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle)) * 100;
}
public override void OnWindowClicked()
public override void OnWindowCloseButtonClicked()
{
/* Decreases health and destroys if at 0 */
m_Health--;
Components.InfoText.text = $"{m_Health}";
if (m_Health <= 0)
{
Destroy(gameObject);
}
Destroy(gameObject);
}
}
}

View File

@@ -26,20 +26,6 @@ namespace InterfaceOff
string json = File.ReadAllText(path);
Trivia = JsonUtility.FromJson<TriviaSet>(json);
string longest = "";
int length = 0;
foreach (TriviaQuestion question in Trivia.questions)
{
if (length < question.question.Length)
{
length = question.question.Length;
longest = question.question;
}
}
Debug.Log(longest);
}
public override void OnWindowInstantiation()

View File

@@ -5,25 +5,28 @@ namespace InterfaceOff
public class TrollWindow : WindowBase
{
private int m_Health = int.MaxValue;
private bool m_SpawnOnRight = true;
public override void OnWindowInstantiation()
{
/* Calculates a random health value */
m_Health = Random.Range(2, 6);
Components.InfoText.text = "TROLL";
}
public override void OnWindowClicked()
public override void OnWindowCloseButtonClicked()
{
/* Decreases health and destroys if at 0 */
m_Health--;
if (m_Health <= 0)
{
Destroy(gameObject);
DestroyWindow();
return;
}
/* If not at zero randomly moves the close button */
float randX = Random.Range(-80, 80);
float randX = m_SpawnOnRight ? Random.Range(0, 80) : Random.Range(-80, 0);
m_SpawnOnRight = !m_SpawnOnRight; // Makes sure the close button is semi far away
Components.CloseButtonRectTransform.anchoredPosition = new Vector2(randX, 0);
}
}