From 46c6210764a4b447b72824d9233d220e1debb235 Mon Sep 17 00:00:00 2001 From: Nahuel Rocchetti Date: Sat, 24 Jun 2023 20:09:30 -0300 Subject: [PATCH] Add in-game main menu. --- .../OpenTS2/Content/NeighborhoodManager.cs | 2 ++ Assets/Scripts/OpenTS2/UI/Layouts/MainMenu.cs | 15 +++++++++------ .../Scripts/OpenTS2/UI/Layouts/NeighborhoodHUD.cs | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/Assets/Scripts/OpenTS2/Content/NeighborhoodManager.cs b/Assets/Scripts/OpenTS2/Content/NeighborhoodManager.cs index d748227..8de5ace 100644 --- a/Assets/Scripts/OpenTS2/Content/NeighborhoodManager.cs +++ b/Assets/Scripts/OpenTS2/Content/NeighborhoodManager.cs @@ -35,6 +35,8 @@ namespace OpenTS2.Content { CursorController.Cursor = CursorController.CursorType.Hourglass; ContentProvider.Get().Changes.SaveChanges(); + if (CurrentNeighborhood != null) + ContentLoading.UnloadNeighborhoodContentSync(); ContentLoading.LoadNeighborhoodContentSync(neighborhood); MusicController.FadeOutMusic(); CurrentNeighborhood = neighborhood; diff --git a/Assets/Scripts/OpenTS2/UI/Layouts/MainMenu.cs b/Assets/Scripts/OpenTS2/UI/Layouts/MainMenu.cs index f2e1004..68f100a 100644 --- a/Assets/Scripts/OpenTS2/UI/Layouts/MainMenu.cs +++ b/Assets/Scripts/OpenTS2/UI/Layouts/MainMenu.cs @@ -36,21 +36,24 @@ namespace OpenTS2.UI.Layouts private int _currentPage = 0; protected override ResourceKey UILayoutResourceKey => new ResourceKey(0x49001017, 0xA99D8A11, TypeIDs.UI); - public MainMenu() : this(MainCanvas) + public MainMenu(bool fromNeighborhood = false) : this(MainCanvas, fromNeighborhood) { } - public MainMenu(Transform canvas) : base(canvas) + public MainMenu(Transform canvas, bool fromNeighborhood = false) : base(canvas) { var root = Components[0]; root.SetAnchor(UIComponent.AnchorType.Center); root.transform.SetAsFirstSibling(); - var background = root.GetChildByID(BackgroundID); - background.gameObject.SetActive(true); - background.SetAnchor(UIComponent.AnchorType.Center); - background.transform.SetAsFirstSibling(); + if (!fromNeighborhood) + { + var background = root.GetChildByID(BackgroundID); + background.gameObject.SetActive(true); + background.SetAnchor(UIComponent.AnchorType.Center); + background.transform.SetAsFirstSibling(); + } var upperLeftSim = root.GetChildByID(UpperLeftSimBMPID); var lowerRightSim = root.GetChildByID(LowerRightSimBMPID); diff --git a/Assets/Scripts/OpenTS2/UI/Layouts/NeighborhoodHUD.cs b/Assets/Scripts/OpenTS2/UI/Layouts/NeighborhoodHUD.cs index 0b158d3..d7b4e07 100644 --- a/Assets/Scripts/OpenTS2/UI/Layouts/NeighborhoodHUD.cs +++ b/Assets/Scripts/OpenTS2/UI/Layouts/NeighborhoodHUD.cs @@ -19,8 +19,10 @@ namespace OpenTS2.UI.Layouts private const uint MediumCityNameTextID = 0xB3; private const uint SmallCityNameTextID = 0xA3; private const uint PrimaryOptionsID = 0x4BE6ED7E; + private const uint MainMenuID = 0x2; private const uint PuckID = 0x4BE6ED7D; protected override ResourceKey UILayoutResourceKey => new ResourceKey(0x49000000, 0xA99D8A11, TypeIDs.UI); + private MainMenu _mainMenu = null; public NeighborhoodHUD() : this(MainCanvas) { @@ -36,8 +38,20 @@ namespace OpenTS2.UI.Layouts var primaryOptions = root.GetChildByID(PrimaryOptionsID, false); + var mainMenu = root.GetChildByID(MainMenuID, false); + mainMenu.OnClick += OnMainMenu; + var largeCityName = primaryOptions.GetChildByID(LargeCityNameTextID); largeCityName.Text = NeighborhoodManager.CurrentNeighborhood.GetLocalizedName(); } + + void OnMainMenu() + { + CursorController.Cursor = CursorController.CursorType.Hourglass; + if (_mainMenu != null) + return; + _mainMenu = new MainMenu(true); + CursorController.Cursor = CursorController.CursorType.Default; + } } }