From fd61dcb2f4ac3fa68af7da360ebded454a7293e5 Mon Sep 17 00:00:00 2001 From: Pasha Bibko <156938226+PashaBibko@users.noreply.github.com> Date: Thu, 15 Jan 2026 11:17:27 +0000 Subject: [PATCH] Cleaned up window base code --- Assets/Prefabs/SampleChild.prefab | 2 +- Assets/Scripts/WindowBase.cs | 9 ++++++++- Assets/Scripts/WindowInteractions.cs | 2 +- Assets/Scripts/Windows/BasicWindow.cs | 10 +++++++--- Assets/Scripts/Windows/ImageWindow.cs | 2 +- Assets/Scripts/Windows/MovingWindow.cs | 22 +++++++--------------- Assets/Scripts/Windows/TriviaWindow.cs | 14 -------------- Assets/Scripts/Windows/TrollWindow.cs | 11 +++++++---- 8 files changed, 32 insertions(+), 40 deletions(-) diff --git a/Assets/Prefabs/SampleChild.prefab b/Assets/Prefabs/SampleChild.prefab index aab1c99..44e195f 100644 --- a/Assets/Prefabs/SampleChild.prefab +++ b/Assets/Prefabs/SampleChild.prefab @@ -58,7 +58,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_Material: {fileID: 2100000, guid: 6412be81563725c40bfc6c75b1a58af8, type: 2} - m_Color: {r: 0, g: 1, b: 0.015290737, a: 1} + m_Color: {r: 0.24528301, g: 0.24528301, b: 0.24528301, a: 1} m_RaycastTarget: 1 m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} m_Maskable: 1 diff --git a/Assets/Scripts/WindowBase.cs b/Assets/Scripts/WindowBase.cs index 8322120..c743f3b 100644 --- a/Assets/Scripts/WindowBase.cs +++ b/Assets/Scripts/WindowBase.cs @@ -54,6 +54,13 @@ namespace InterfaceOff } public virtual void OnWindowInstantiation() { } - public virtual void OnWindowClicked() { } + + /* Default close button closes the window */ + public virtual void OnWindowCloseButtonClicked() => DestroyWindow(); + + protected void DestroyWindow() + { + Destroy(gameObject); + } } } diff --git a/Assets/Scripts/WindowInteractions.cs b/Assets/Scripts/WindowInteractions.cs index 7568ff2..fc7bb59 100644 --- a/Assets/Scripts/WindowInteractions.cs +++ b/Assets/Scripts/WindowInteractions.cs @@ -7,6 +7,6 @@ namespace InterfaceOff private WindowBase AttachedWindow { get; set; } public void SetAttachedTo(WindowBase window) => AttachedWindow = window; - public void WindowClicked() => AttachedWindow.OnWindowClicked(); + public void WindowClicked() => AttachedWindow.OnWindowCloseButtonClicked(); } } \ No newline at end of file diff --git a/Assets/Scripts/Windows/BasicWindow.cs b/Assets/Scripts/Windows/BasicWindow.cs index 8b4ea51..037bc32 100644 --- a/Assets/Scripts/Windows/BasicWindow.cs +++ b/Assets/Scripts/Windows/BasicWindow.cs @@ -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); } diff --git a/Assets/Scripts/Windows/ImageWindow.cs b/Assets/Scripts/Windows/ImageWindow.cs index e55f50f..51d2f58 100644 --- a/Assets/Scripts/Windows/ImageWindow.cs +++ b/Assets/Scripts/Windows/ImageWindow.cs @@ -59,7 +59,7 @@ namespace InterfaceOff } } - public override void OnWindowClicked() + public override void OnWindowCloseButtonClicked() { if (m_TilesRotatedCorrectly == 4) { diff --git a/Assets/Scripts/Windows/MovingWindow.cs b/Assets/Scripts/Windows/MovingWindow.cs index 139942d..dc0b996 100644 --- a/Assets/Scripts/Windows/MovingWindow.cs +++ b/Assets/Scripts/Windows/MovingWindow.cs @@ -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); } } } \ No newline at end of file diff --git a/Assets/Scripts/Windows/TriviaWindow.cs b/Assets/Scripts/Windows/TriviaWindow.cs index ab6472f..4eadef3 100644 --- a/Assets/Scripts/Windows/TriviaWindow.cs +++ b/Assets/Scripts/Windows/TriviaWindow.cs @@ -26,20 +26,6 @@ namespace InterfaceOff string json = File.ReadAllText(path); Trivia = JsonUtility.FromJson(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() diff --git a/Assets/Scripts/Windows/TrollWindow.cs b/Assets/Scripts/Windows/TrollWindow.cs index 79067d9..5688410 100644 --- a/Assets/Scripts/Windows/TrollWindow.cs +++ b/Assets/Scripts/Windows/TrollWindow.cs @@ -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); } }