From f0903a58d112794912a2326c1e3b67ee62b869a2 Mon Sep 17 00:00:00 2001 From: Nicolas Gnyra Date: Thu, 19 Sep 2024 21:19:59 -0400 Subject: [PATCH] Switch all public fields to properties --- .../MonoBehaviourFieldSuppressor.cs | 73 ------------------ .../Animations/AnimationStateUpdater.cs | 17 ++-- .../Components/Backgroundable.cs | 39 ++++++---- .../Components/ButtonArtworkImage.cs | 17 ++-- .../Components/ButtonIconImage.cs | 46 ++++++++--- .../Components/CustomCellListTableData.cs | 77 +++++++++++++++---- .../Components/CustomListTableData.cs | 47 ++++++++--- .../Components/ExternalComponents.cs | 2 +- .../Components/Glowable.cs | 17 ++-- .../Components/ModalColorPicker.cs | 66 ++++++++++++---- .../Components/ModalKeyboard.cs | 22 ++++-- .../Components/ScrollViewContent.cs | 14 +++- .../Components/Settings/ColorSetting.cs | 36 ++++++--- .../Settings/DropDownListSetting.cs | 23 ++++-- .../Components/Settings/GenericSetting.cs | 11 ++- .../Settings/GenericSliderSetting.cs | 50 ++++++++---- .../Components/Settings/IncDecSetting.cs | 44 ++++++++--- .../Components/Settings/IncrementSetting.cs | 74 +++++++++++++----- .../Components/Settings/ListSliderSetting.cs | 6 +- .../Components/Settings/SliderSetting.cs | 34 +++++--- .../Components/Settings/StringSetting.cs | 43 ++++++++--- .../Components/Settings/ToggleSetting.cs | 36 ++++++--- .../Components/Strokable.cs | 27 ++++--- BeatSaberMarkupLanguage/Components/Tab.cs | 4 +- .../Components/TabSelector.cs | 63 +++++++++++---- .../Components/TextPageScrollViewRefresher.cs | 21 +++-- .../FloatingScreen/FloatingScreen.cs | 65 +++++++++------- .../Settings/UI/ModSettingsFlowCoordinator.cs | 46 +++++------ .../UI/SettingsMenuListViewController.cs | 6 +- .../LocalizationTestViewController.cs | 2 +- .../ViewControllers/TestViewController.cs | 12 +-- 31 files changed, 676 insertions(+), 364 deletions(-) delete mode 100644 BeatSaberMarkupLanguage.Analyzers/MonoBehaviourFieldSuppressor.cs diff --git a/BeatSaberMarkupLanguage.Analyzers/MonoBehaviourFieldSuppressor.cs b/BeatSaberMarkupLanguage.Analyzers/MonoBehaviourFieldSuppressor.cs deleted file mode 100644 index d0c8addf..00000000 --- a/BeatSaberMarkupLanguage.Analyzers/MonoBehaviourFieldSuppressor.cs +++ /dev/null @@ -1,73 +0,0 @@ -using System; -using System.Collections.Immutable; -using System.Linq; -using BeatSaberMarkupLanguage.Analyzers.Resources; -using BeatSaberMarkupLanguage.Analyzers.Utilities; -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using Microsoft.CodeAnalysis.Diagnostics; -using UnityEngine; - -namespace BeatSaberMarkupLanguage.Analyzers; - -/// -/// A for Harmony patch methods and associated parameters. -/// -// TODO: This really belongs in its own project/package. Nothing currently available on NuGet seems to do this, so I'm leaving it here for now. -[DiagnosticAnalyzer(LanguageNames.CSharp)] -public class MonoBehaviourFieldSuppressor : DiagnosticSuppressor -{ - private static readonly SuppressionDescriptor StyleCopParameterNamingRule = new( - id: "BSMLS0010", - suppressedDiagnosticId: "SA1401", - justification: Strings.StyleCopParameterNamingHarmonyPatchSuppressorJustification); - - /// - public override ImmutableArray SupportedSuppressions => ImmutableArray.Create(StyleCopParameterNamingRule); - - /// - public override void ReportSuppressions(SuppressionAnalysisContext context) - { - foreach (Diagnostic diagnostic in context.ReportedDiagnostics) - { - this.AnalyzeDiagnosticField(diagnostic, context); - } - } - - private static bool IsSuppressible(ISymbol symbol) - { - if (!symbol.ContainingType.Extends(typeof(MonoBehaviour))) - { - return false; - } - - return symbol is IFieldSymbol fieldSymbol && !fieldSymbol.IsReadOnly && !fieldSymbol.IsStatic; - } - - private void AnalyzeDiagnosticField(Diagnostic diagnostic, SuppressionAnalysisContext context) - { - SyntaxNode? fieldDeclarationSyntax = context.GetSuppressibleNode(diagnostic); - if (fieldDeclarationSyntax == null) - { - return; - } - - SyntaxTree? syntaxTree = diagnostic.Location.SourceTree; - if (syntaxTree == null) - { - return; - } - - SemanticModel model = context.GetSemanticModel(syntaxTree); - ISymbol? declaredSymbol = model.GetDeclaredSymbol(fieldDeclarationSyntax)!; - if (!IsSuppressible(declaredSymbol)) - { - return; - } - - foreach (SuppressionDescriptor descriptor in this.SupportedSuppressions.Where(d => d.SuppressedDiagnosticId == diagnostic.Id)) - { - context.ReportSuppression(Suppression.Create(descriptor, diagnostic)); - } - } -} diff --git a/BeatSaberMarkupLanguage/Animations/AnimationStateUpdater.cs b/BeatSaberMarkupLanguage/Animations/AnimationStateUpdater.cs index 91656cb8..95daf715 100644 --- a/BeatSaberMarkupLanguage/Animations/AnimationStateUpdater.cs +++ b/BeatSaberMarkupLanguage/Animations/AnimationStateUpdater.cs @@ -5,10 +5,17 @@ namespace BeatSaberMarkupLanguage.Animations { public class AnimationStateUpdater : MonoBehaviour { - public Image Image; + [SerializeField] + private Image image; private AnimationControllerData controllerData; + public Image Image + { + get => image; + set => image = value; + } + public AnimationControllerData ControllerData { get => controllerData; @@ -32,19 +39,19 @@ protected void OnEnable() { if (ControllerData != null) { - ControllerData.ActiveImages.Add(Image); - Image.sprite = ControllerData.Sprites[ControllerData.UvIndex]; + ControllerData.ActiveImages.Add(image); + image.sprite = ControllerData.Sprites[ControllerData.UvIndex]; } } protected void OnDisable() { - ControllerData?.ActiveImages.Remove(Image); + ControllerData?.ActiveImages.Remove(image); } protected void OnDestroy() { - ControllerData?.ActiveImages.Remove(Image); + ControllerData?.ActiveImages.Remove(image); } } } diff --git a/BeatSaberMarkupLanguage/Components/Backgroundable.cs b/BeatSaberMarkupLanguage/Components/Backgroundable.cs index 69c6b991..c4bf3361 100644 --- a/BeatSaberMarkupLanguage/Components/Backgroundable.cs +++ b/BeatSaberMarkupLanguage/Components/Backgroundable.cs @@ -7,10 +7,17 @@ namespace BeatSaberMarkupLanguage.Components { public class Backgroundable : MonoBehaviour { + private static readonly Dictionary BackgroundCache = new(); + // TODO: this should be an ImageView - public Image Background; + [SerializeField] + private Image background; - private static readonly Dictionary BackgroundCache = new(); + public Image Background + { + get => background; + set => background = value; + } private static Dictionary Backgrounds => new() { @@ -41,7 +48,7 @@ public class Backgroundable : MonoBehaviour public void ApplyBackground(string name) { - if (Background != null) + if (background != null) { throw new BSMLException("Cannot add multiple backgrounds"); } @@ -64,8 +71,8 @@ public void ApplyBackground(string name) BackgroundCache.Add(name, bgTemplate); } - Background = gameObject.AddComponent(bgTemplate); - Background.enabled = true; + background = gameObject.AddComponent(bgTemplate); + background.enabled = true; } catch { @@ -75,15 +82,15 @@ public void ApplyBackground(string name) public void ApplyColor(Color color) { - if (Background == null) + if (background == null) { throw new BSMLException("Can't set color on null background!"); } - color.a = Background.color.a; - Background.color = color; + color.a = background.color.a; + background.color = color; - if (Background is ImageView imageView) + if (background is ImageView imageView) { Color color0 = new(1, 1, 1, imageView.color0.a); Color color1 = new(1, 1, 1, imageView.color1.a); @@ -96,12 +103,12 @@ public void ApplyColor(Color color) public void ApplyGradient(Color color0, Color color1) { - if (Background is not ImageView imageView) + if (background is not ImageView imageView) { throw new BSMLException("Can't set gradient on null background!"); } - Color color = new(1, 1, 1, Background.color.a); + Color color = new(1, 1, 1, background.color.a); imageView.gradient = true; imageView.color = color; @@ -111,7 +118,7 @@ public void ApplyGradient(Color color0, Color color1) public void ApplyColor0(Color color0) { - if (Background is not ImageView imageView) + if (background is not ImageView imageView) { throw new BSMLException("Can't set gradient on null background!"); } @@ -121,7 +128,7 @@ public void ApplyColor0(Color color0) public void ApplyColor1(Color color1) { - if (Background is not ImageView imageView) + if (background is not ImageView imageView) { throw new BSMLException("Can't set gradient on null background!"); } @@ -131,14 +138,14 @@ public void ApplyColor1(Color color1) public void ApplyAlpha(float alpha) { - if (Background == null) + if (background == null) { throw new BSMLException("Can't set gradient on null background!"); } - Color color = Background.color; + Color color = background.color; color.a = alpha; - Background.color = color; + background.color = color; } private static ImageView FindTemplate(string name, string backgroundName) diff --git a/BeatSaberMarkupLanguage/Components/ButtonArtworkImage.cs b/BeatSaberMarkupLanguage/Components/ButtonArtworkImage.cs index f7c102b4..61ea1fcb 100644 --- a/BeatSaberMarkupLanguage/Components/ButtonArtworkImage.cs +++ b/BeatSaberMarkupLanguage/Components/ButtonArtworkImage.cs @@ -7,21 +7,28 @@ namespace BeatSaberMarkupLanguage.Components { public class ButtonArtworkImage : MonoBehaviour { - public Image Image; + [SerializeField] + private Image image; + + public Image Image + { + get => image; + set => image = value; + } public void SetArtwork(string path) { - if (Image == null) + if (image == null) { - Image = GetComponentsInChildren().Where(x => x.name == "BGArtwork").FirstOrDefault(); + image = GetComponentsInChildren().Where(x => x.name == "BGArtwork").FirstOrDefault(); } - if (Image == null) + if (image == null) { throw new BSMLException("Unable to find BG artwork image!"); } - Image.SetImageAsync(path).ContinueWith((task) => Logger.Log.Error($"Failed to load image\n{task.Exception}"), TaskContinuationOptions.OnlyOnFaulted); + image.SetImageAsync(path).ContinueWith((task) => Logger.Log.Error($"Failed to load image\n{task.Exception}"), TaskContinuationOptions.OnlyOnFaulted); } } } diff --git a/BeatSaberMarkupLanguage/Components/ButtonIconImage.cs b/BeatSaberMarkupLanguage/Components/ButtonIconImage.cs index 424d1138..4791f2f5 100644 --- a/BeatSaberMarkupLanguage/Components/ButtonIconImage.cs +++ b/BeatSaberMarkupLanguage/Components/ButtonIconImage.cs @@ -7,24 +7,46 @@ namespace BeatSaberMarkupLanguage.Components { public class ButtonIconImage : MonoBehaviour { - public Image Image; + [SerializeField] + private Image image; - internal NoTransitionsButton Button; - internal GameObject Underline; + [SerializeField] + private NoTransitionsButton button; + + [SerializeField] + private GameObject underline; + + public Image Image + { + get => image; + set => image = value; + } + + internal NoTransitionsButton Button + { + get => button; + set => button = value; + } + + internal GameObject Underline + { + get => underline; + set => underline = value; + } public void SetIcon(string path) { - if (Image == null) + if (image == null) { return; } - Image.SetImageAsync(path).ContinueWith((task) => Logger.Log.Error($"Failed to load image\n{task.Exception}"), TaskContinuationOptions.OnlyOnFaulted); + image.SetImageAsync(path).ContinueWith((task) => Logger.Log.Error($"Failed to load image\n{task.Exception}"), TaskContinuationOptions.OnlyOnFaulted); } internal void SetSkew(float value) { - if (Image is not ImageView imageView) + if (image is not ImageView imageView) { return; } @@ -35,27 +57,27 @@ internal void SetSkew(float value) internal void SetUnderlineActive(bool active) { - if (Underline != null) + if (underline != null) { - Underline.SetActive(active); + underline.SetActive(active); } } protected void OnEnable() { - Button.selectionStateDidChangeEvent += OnSelectionStateDidChange; + button.selectionStateDidChangeEvent += OnSelectionStateDidChange; } protected void OnDisable() { - Button.selectionStateDidChangeEvent -= OnSelectionStateDidChange; + button.selectionStateDidChangeEvent -= OnSelectionStateDidChange; } private void OnSelectionStateDidChange(NoTransitionsButton.SelectionState state) { - Color color = Image.color; + Color color = image.color; color.a = state is NoTransitionsButton.SelectionState.Disabled ? 0.25f : 1; - Image.color = color; + image.color = color; } } } diff --git a/BeatSaberMarkupLanguage/Components/CustomCellListTableData.cs b/BeatSaberMarkupLanguage/Components/CustomCellListTableData.cs index dac2df8d..fcb6a9b6 100644 --- a/BeatSaberMarkupLanguage/Components/CustomCellListTableData.cs +++ b/BeatSaberMarkupLanguage/Components/CustomCellListTableData.cs @@ -9,17 +9,48 @@ namespace BeatSaberMarkupLanguage.Components { public class CustomCellListTableData : MonoBehaviour, TableView.IDataSource { - public string CellTemplate; - public float CellSizeValue = 8.5f; - public TableView TableView; - public bool ClickableCells = true; + [SerializeField] + private string cellTemplate; + + [SerializeField] + private float cellSizeValue = 8.5f; + + [SerializeField] + private TableView tableView; + + [SerializeField] + private bool clickableCells = true; + + public string CellTemplate + { + get => cellTemplate; + set => cellTemplate = value; + } + + public float CellSizeValue + { + get => cellSizeValue; + set => cellSizeValue = value; + } + + public TableView TableView + { + get => tableView; + set => tableView = value; + } + + public bool ClickableCells + { + get => clickableCells; + set => clickableCells = value; + } public IList Data { get; set; } = Array.Empty(); public virtual TableCell CellForIdx(TableView tableView, int idx) { CustomCellTableCell tableCell = new GameObject().AddComponent(); - if (ClickableCells) + if (clickableCells) { tableCell.gameObject.AddComponent(); tableCell.interactable = true; @@ -27,14 +58,14 @@ public virtual TableCell CellForIdx(TableView tableView, int idx) tableCell.reuseIdentifier = "BSMLCustomCellListCell"; tableCell.name = "BSMLCustomTableCell"; - tableCell.ParserParams = BSMLParser.Instance.Parse(CellTemplate, tableCell.gameObject, Data[idx]); + tableCell.ParserParams = BSMLParser.Instance.Parse(cellTemplate, tableCell.gameObject, Data[idx]); tableCell.SetupPostParse(); return tableCell; } public float CellSize(int idx) { - return CellSizeValue; + return cellSizeValue; } public int NumberOfCells() @@ -45,24 +76,36 @@ public int NumberOfCells() public class CustomCellTableCell : TableCell { - public BSMLParserParams ParserParams; - public List SelectedTags; - public List HoveredTags; - public List NeitherTags; + [SerializeField] + private List selectedTags; + + [SerializeField] + private List hoveredTags; + + [SerializeField] + private List neitherTags; + + public BSMLParserParams ParserParams { get; internal set; } + + public IList SelectedTags => selectedTags; + + public IList HoveredTags => selectedTags; + + public IList NeitherTags => selectedTags; public virtual void RefreshVisuals() { - foreach (GameObject gameObject in SelectedTags) + foreach (GameObject gameObject in selectedTags) { gameObject.SetActive(selected); } - foreach (GameObject gameObject in HoveredTags) + foreach (GameObject gameObject in hoveredTags) { gameObject.SetActive(highlighted); } - foreach (GameObject gameObject in NeitherTags) + foreach (GameObject gameObject in neitherTags) { gameObject.SetActive(!(selected || highlighted)); } @@ -75,9 +118,9 @@ public virtual void RefreshVisuals() internal void SetupPostParse() { - SelectedTags = ParserParams.GetObjectsWithTag("selected"); - HoveredTags = ParserParams.GetObjectsWithTag("hovered"); - NeitherTags = ParserParams.GetObjectsWithTag("un-selected-un-hovered"); + selectedTags = ParserParams.GetObjectsWithTag("selected"); + hoveredTags = ParserParams.GetObjectsWithTag("hovered"); + neitherTags = ParserParams.GetObjectsWithTag("un-selected-un-hovered"); } protected override void SelectionDidChange(TransitionType transitionType) diff --git a/BeatSaberMarkupLanguage/Components/CustomListTableData.cs b/BeatSaberMarkupLanguage/Components/CustomListTableData.cs index d76f55ca..d8ccbaaf 100644 --- a/BeatSaberMarkupLanguage/Components/CustomListTableData.cs +++ b/BeatSaberMarkupLanguage/Components/CustomListTableData.cs @@ -8,11 +8,16 @@ namespace BeatSaberMarkupLanguage.Components { public class CustomListTableData : MonoBehaviour, TableView.IDataSource { - public float CellSizeValue = 8.5f; - public string ReuseIdentifier = "BSMLListTableCell"; - public TableView TableView; + private const string ReuseIdentifier = "BSMLListTableCell"; - public bool ExpandCell = false; + [SerializeField] + private float cellSizeValue = 8.5f; + + [SerializeField] + private TableView tableView; + + [SerializeField] + private bool expandCell = false; private LevelListTableCell songListTableCellPrefab; private LevelPackCell levelPackTableCellPrefab; @@ -26,6 +31,24 @@ public enum ListStyle Simple, } + public float CellSizeValue + { + get => cellSizeValue; + set => cellSizeValue = value; + } + + public TableView TableView + { + get => tableView; + set => tableView = value; + } + + public bool ExpandCell + { + get => expandCell; + set => expandCell = value; + } + public ListStyle Style { get => listStyle; @@ -35,13 +58,13 @@ public ListStyle Style switch (value) { case ListStyle.List: - CellSizeValue = 8.5f; + cellSizeValue = 8.5f; break; case ListStyle.Box: - CellSizeValue = TableView.tableType == TableView.TableType.Horizontal ? 30f : 35f; + cellSizeValue = tableView.tableType == TableView.TableType.Horizontal ? 30f : 35f; break; case ListStyle.Simple: - CellSizeValue = 8f; + cellSizeValue = 8f; break; } @@ -53,7 +76,7 @@ public ListStyle Style public LevelListTableCell GetTableCell() { - LevelListTableCell tableCell = (LevelListTableCell)TableView.DequeueReusableCellForIdentifier(ReuseIdentifier); + LevelListTableCell tableCell = (LevelListTableCell)tableView.DequeueReusableCellForIdentifier(ReuseIdentifier); if (!tableCell) { if (songListTableCellPrefab == null) @@ -72,7 +95,7 @@ public LevelListTableCell GetTableCell() public BSMLBoxTableCell GetBoxTableCell() { - BSMLBoxTableCell tableCell = (BSMLBoxTableCell)TableView.DequeueReusableCellForIdentifier(ReuseIdentifier); + BSMLBoxTableCell tableCell = (BSMLBoxTableCell)tableView.DequeueReusableCellForIdentifier(ReuseIdentifier); if (!tableCell) { if (levelPackTableCellPrefab == null) @@ -114,7 +137,7 @@ public BSMLBoxTableCell InstantiateBoxTableCell(LevelPackCell levelPackTableCell public SimpleTextTableCell GetSimpleTextTableCell() { - SimpleTextTableCell tableCell = (SimpleTextTableCell)TableView.DequeueReusableCellForIdentifier(ReuseIdentifier); + SimpleTextTableCell tableCell = (SimpleTextTableCell)tableView.DequeueReusableCellForIdentifier(ReuseIdentifier); if (!tableCell) { if (simpleTextTableCellPrefab == null) @@ -145,7 +168,7 @@ public virtual TableCell CellForIdx(TableView tableView, int idx) tableCell._updatedBadgeGo.SetActive(false); tableCell._favoritesBadgeImage.gameObject.SetActive(false); tableCell.transform.Find("BpmIcon").gameObject.SetActive(false); - if (ExpandCell) + if (expandCell) { nameText.rectTransform.anchorMax = new Vector3(2, 0.5f, 0); authorText.rectTransform.anchorMax = new Vector3(2, 0.5f, 0); @@ -175,7 +198,7 @@ public virtual TableCell CellForIdx(TableView tableView, int idx) public float CellSize(int idx) { - return CellSizeValue; + return cellSizeValue; } public int NumberOfCells() diff --git a/BeatSaberMarkupLanguage/Components/ExternalComponents.cs b/BeatSaberMarkupLanguage/Components/ExternalComponents.cs index 795c72ae..8081bdbe 100644 --- a/BeatSaberMarkupLanguage/Components/ExternalComponents.cs +++ b/BeatSaberMarkupLanguage/Components/ExternalComponents.cs @@ -5,7 +5,7 @@ namespace BeatSaberMarkupLanguage.Components { public class ExternalComponents : MonoBehaviour { - public List Components = new(); // Components added to this list will be handled as if they are part of this object while parsing even if they aren't + public List Components { get; } = new(); // Components added to this list will be handled as if they are part of this object while parsing even if they aren't public T Get() where T : Component diff --git a/BeatSaberMarkupLanguage/Components/Glowable.cs b/BeatSaberMarkupLanguage/Components/Glowable.cs index 6d13acd1..66bfc9d2 100644 --- a/BeatSaberMarkupLanguage/Components/Glowable.cs +++ b/BeatSaberMarkupLanguage/Components/Glowable.cs @@ -5,23 +5,30 @@ namespace BeatSaberMarkupLanguage.Components { public class Glowable : MonoBehaviour { - public Image Image; + [SerializeField] + private Image image; + + public Image Image + { + get => image; + set => image = value; + } public void SetGlow(string colorString) { - if (Image == null) + if (image == null) { return; } if (colorString != "none") { - Image.color = Parse.Color(colorString); - Image.gameObject.SetActive(true); + image.color = Parse.Color(colorString); + image.gameObject.SetActive(true); } else { - Image.gameObject.SetActive(false); + image.gameObject.SetActive(false); } } } diff --git a/BeatSaberMarkupLanguage/Components/ModalColorPicker.cs b/BeatSaberMarkupLanguage/Components/ModalColorPicker.cs index d8df9596..1b73d41f 100644 --- a/BeatSaberMarkupLanguage/Components/ModalColorPicker.cs +++ b/BeatSaberMarkupLanguage/Components/ModalColorPicker.cs @@ -9,15 +9,17 @@ namespace BeatSaberMarkupLanguage.Components { public class ModalColorPicker : MonoBehaviour { - public ModalView ModalView; - public RGBPanelController RgbPanel; - public HSVPanelController HsvPanel; - public Image ColorImage; + [SerializeField] + private ModalView modalView; - public BSMLValue AssociatedValue; - public BSMLAction OnCancel; - public BSMLAction OnDone; - public BSMLAction OnChange; + [SerializeField] + private RGBPanelController rgbPanel; + + [SerializeField] + private HSVPanelController hsvPanel; + + [SerializeField] + private Image colorImage; private Color currentColor; @@ -25,26 +27,58 @@ public class ModalColorPicker : MonoBehaviour public event Action CancelEvent; + public BSMLValue AssociatedValue { get; set; } + + public BSMLAction OnCancel { get; set; } + + public BSMLAction OnDone { get; set; } + + public BSMLAction OnChange { get; set; } + + public ModalView ModalView + { + get => modalView; + set => modalView = value; + } + + public RGBPanelController RgbPanel + { + get => rgbPanel; + set => rgbPanel = value; + } + + public HSVPanelController HsvPanel + { + get => hsvPanel; + set => hsvPanel = value; + } + + public Image ColorImage + { + get => colorImage; + set => colorImage = value; + } + public Color CurrentColor { get => currentColor; set { currentColor = value; - if (RgbPanel != null) + if (rgbPanel != null) { - RgbPanel.color = currentColor; + rgbPanel.color = currentColor; } // If you're wondering why we check this for HSV it's so that if color is one where changing hue has no effect it won't lock up the hue slider - if (HsvPanel != null && HsvPanel.color != currentColor) + if (hsvPanel != null && hsvPanel.color != currentColor) { - HsvPanel.color = currentColor; + hsvPanel.color = currentColor; } - if (ColorImage != null) + if (colorImage != null) { - ColorImage.color = currentColor; + colorImage.color = currentColor; } } } @@ -54,7 +88,7 @@ public void CancelPressed() { OnCancel?.Invoke(); CancelEvent?.Invoke(); - ModalView.Hide(true); + modalView.Hide(true); } [UIAction("done")] @@ -63,7 +97,7 @@ public void DonePressed() AssociatedValue?.SetValue(CurrentColor); OnDone?.Invoke(CurrentColor); DoneEvent?.Invoke(CurrentColor); - ModalView.Hide(true); + modalView.Hide(true); } public void OnValueChanged(Color color, ColorChangeUIEventType type) diff --git a/BeatSaberMarkupLanguage/Components/ModalKeyboard.cs b/BeatSaberMarkupLanguage/Components/ModalKeyboard.cs index db4ad8e5..529f0e82 100644 --- a/BeatSaberMarkupLanguage/Components/ModalKeyboard.cs +++ b/BeatSaberMarkupLanguage/Components/ModalKeyboard.cs @@ -12,18 +12,28 @@ namespace BeatSaberMarkupLanguage.Components { public class ModalKeyboard : MonoBehaviour { - public ModalView ModalView; - public KEYBOARD Keyboard; + [SerializeField] + private ModalView modalView; - public BSMLValue AssociatedValue; - public BSMLAction OnEnter; - public bool ClearOnOpen; + public ModalView ModalView + { + get => modalView; + set => modalView = value; + } + + public KEYBOARD Keyboard { get; set; } + + public BSMLValue AssociatedValue { get; set; } + + public BSMLAction OnEnter { get; set; } + + public bool ClearOnOpen { get; set; } public void OnEnterKeyPressed(string value) { AssociatedValue?.SetValue(value); OnEnter?.Invoke(value); - ModalView.Hide(true); + modalView.Hide(true); } public void SetText(string text) diff --git a/BeatSaberMarkupLanguage/Components/ScrollViewContent.cs b/BeatSaberMarkupLanguage/Components/ScrollViewContent.cs index bba8fc89..4483143f 100644 --- a/BeatSaberMarkupLanguage/Components/ScrollViewContent.cs +++ b/BeatSaberMarkupLanguage/Components/ScrollViewContent.cs @@ -7,9 +7,17 @@ namespace BeatSaberMarkupLanguage.Components { public class ScrollViewContent : MonoBehaviour { - public ScrollView ScrollView; + [SerializeField] + private ScrollView scrollView; + private bool dirty = false; + public ScrollView ScrollView + { + get => scrollView; + set => scrollView = value; + } + protected void Start() { LayoutRebuilder.ForceRebuildLayoutImmediate(transform as RectTransform); @@ -45,8 +53,8 @@ private IEnumerator SetupScrollView() private void UpdateScrollView() { - ScrollView.SetContentSize((transform.GetChild(0) as RectTransform).rect.height); - ScrollView.RefreshButtons(); + scrollView.SetContentSize((transform.GetChild(0) as RectTransform).rect.height); + scrollView.RefreshButtons(); } } } diff --git a/BeatSaberMarkupLanguage/Components/Settings/ColorSetting.cs b/BeatSaberMarkupLanguage/Components/Settings/ColorSetting.cs index 02fae5c6..8d518470 100644 --- a/BeatSaberMarkupLanguage/Components/Settings/ColorSetting.cs +++ b/BeatSaberMarkupLanguage/Components/Settings/ColorSetting.cs @@ -5,33 +5,49 @@ namespace BeatSaberMarkupLanguage.Components.Settings { public class ColorSetting : GenericInteractableSetting { - public Button EditButton; - public ModalColorPicker ModalColorPicker; - public Image ColorImage; + [SerializeField] + private Button editButton; + + [SerializeField] + private Image colorImage; private Color currentColor = Color.white; + public ModalColorPicker ModalColorPicker { get; set; } + + public Button EditButton + { + get => editButton; + set => editButton = value; + } + + public Image ColorImage + { + get => colorImage; + set => colorImage = value; + } + public Color CurrentColor { get => currentColor; set { currentColor = value; - if (ColorImage != null) + if (colorImage != null) { - ColorImage.color = currentColor; + colorImage.color = currentColor; } } } public override bool Interactable { - get => EditButton != null && EditButton.interactable; + get => editButton != null && editButton.interactable; set { - if (EditButton != null) + if (editButton != null) { - EditButton.interactable = value; + editButton.interactable = value; } } } @@ -79,12 +95,12 @@ public override void ReceiveValue() protected virtual void OnEnable() { - EditButton.onClick.AddListener(EditButtonPressed); + editButton.onClick.AddListener(EditButtonPressed); } protected void OnDisable() { - EditButton.onClick.RemoveListener(EditButtonPressed); + editButton.onClick.RemoveListener(EditButtonPressed); } } } diff --git a/BeatSaberMarkupLanguage/Components/Settings/DropDownListSetting.cs b/BeatSaberMarkupLanguage/Components/Settings/DropDownListSetting.cs index 0c760def..9dc92d9b 100644 --- a/BeatSaberMarkupLanguage/Components/Settings/DropDownListSetting.cs +++ b/BeatSaberMarkupLanguage/Components/Settings/DropDownListSetting.cs @@ -8,10 +8,17 @@ namespace BeatSaberMarkupLanguage.Components.Settings { public class DropDownListSetting : GenericInteractableSetting { - public SimpleTextDropdown Dropdown; + [SerializeField] + private SimpleTextDropdown dropdown; private int index; + public SimpleTextDropdown Dropdown + { + get => dropdown; + set => dropdown = value; + } + public IList Values { get; set; } = Array.Empty(); public object Value @@ -29,7 +36,7 @@ public object Value index = 0; } - Dropdown.SelectCellWithIdx(index); + dropdown.SelectCellWithIdx(index); UpdateState(); } @@ -37,13 +44,13 @@ public object Value public override bool Interactable { - get => Dropdown._button.interactable; - set => Dropdown._button.interactable = value; + get => dropdown._button.interactable; + set => dropdown._button.interactable = value; } public override void Setup() { - Dropdown.didSelectCellWithIdxEvent += OnSelectIndex; + dropdown.didSelectCellWithIdxEvent += OnSelectIndex; ReceiveValue(); UpdateChoices(); gameObject.SetActive(true); @@ -53,11 +60,11 @@ public void UpdateChoices() { if (Formatter != null) { - Dropdown.SetTexts(Values.Cast().Select(o => Formatter.Invoke(o) as string).ToList()); + dropdown.SetTexts(Values.Cast().Select(o => Formatter.Invoke(o) as string).ToList()); } else { - Dropdown.SetTexts(Values.Cast().Select(o => o.ToString()).ToList()); + dropdown.SetTexts(Values.Cast().Select(o => o.ToString()).ToList()); } } @@ -88,7 +95,7 @@ private void OnSelectIndex(DropdownWithTableView tableView, int index) private void UpdateState() { - Dropdown._text.text = Value != null ? (Formatter == null ? Value?.ToString() : (Formatter.Invoke(Value) as string)) : string.Empty; + dropdown._text.text = Value != null ? (Formatter == null ? Value?.ToString() : (Formatter.Invoke(Value) as string)) : string.Empty; } } } diff --git a/BeatSaberMarkupLanguage/Components/Settings/GenericSetting.cs b/BeatSaberMarkupLanguage/Components/Settings/GenericSetting.cs index 19e4b6ba..b27ee742 100644 --- a/BeatSaberMarkupLanguage/Components/Settings/GenericSetting.cs +++ b/BeatSaberMarkupLanguage/Components/Settings/GenericSetting.cs @@ -5,10 +5,13 @@ namespace BeatSaberMarkupLanguage.Components.Settings { public abstract class GenericSetting : MonoBehaviour { - public BSMLAction Formatter; - public BSMLAction OnChange; - public BSMLValue AssociatedValue; - public bool UpdateOnChange; + public BSMLAction Formatter { get; set; } + + public BSMLAction OnChange { get; set; } + + public BSMLValue AssociatedValue { get; set; } + + public bool UpdateOnChange { get; set; } public abstract void Setup(); diff --git a/BeatSaberMarkupLanguage/Components/Settings/GenericSliderSetting.cs b/BeatSaberMarkupLanguage/Components/Settings/GenericSliderSetting.cs index 60f2504d..e030b2b5 100644 --- a/BeatSaberMarkupLanguage/Components/Settings/GenericSliderSetting.cs +++ b/BeatSaberMarkupLanguage/Components/Settings/GenericSliderSetting.cs @@ -7,23 +7,39 @@ namespace BeatSaberMarkupLanguage.Components.Settings { public abstract class GenericSliderSetting : GenericInteractableSetting { - public RangeValuesTextSlider Slider; - public bool ShowButtons = false; + [SerializeField] + private RangeValuesTextSlider slider; - protected TextMeshProUGUI text; + [SerializeField] + private bool showButtons = false; + + [SerializeField] + private TextMeshProUGUI text; private Button incButton; private Button decButton; + public RangeValuesTextSlider Slider + { + get => slider; + set => slider = value; + } + + public bool ShowButtons + { + get => showButtons; + set => showButtons = value; + } + public override bool Interactable { - get => Slider != null && Slider.interactable; + get => slider != null && slider.interactable; set { - if (Slider != null) + if (slider != null) { - Slider.interactable = value; - if (ShowButtons) + slider.interactable = value; + if (showButtons) { incButton.interactable = value; decButton.interactable = value; @@ -32,19 +48,25 @@ public override bool Interactable } } + protected TextMeshProUGUI Text + { + get => text; + set => text = value; + } + public override void Setup() { - incButton = Slider._incButton; - decButton = Slider._decButton; + incButton = slider._incButton; + decButton = slider._decButton; - if (!ShowButtons) + if (!showButtons) { - Slider.image.sprite = Utilities.FindSpriteCached("RoundRect10"); + slider.image.sprite = Utilities.FindSpriteCached("RoundRect10"); Destroy(incButton.gameObject); Destroy(decButton.gameObject); - (Slider.transform.Find("BG") as RectTransform).sizeDelta = new Vector2(0, 6); - (Slider.transform as RectTransform).sizeDelta = new Vector2(38, 0); - (Slider.transform.Find("SlidingArea") as RectTransform).sizeDelta = new Vector2(-4, -4); + (slider.transform.Find("BG") as RectTransform).sizeDelta = new Vector2(0, 6); + (slider.transform as RectTransform).sizeDelta = new Vector2(38, 0); + (slider.transform.Find("SlidingArea") as RectTransform).sizeDelta = new Vector2(-4, -4); } } } diff --git a/BeatSaberMarkupLanguage/Components/Settings/IncDecSetting.cs b/BeatSaberMarkupLanguage/Components/Settings/IncDecSetting.cs index a5e7d54d..176bc240 100644 --- a/BeatSaberMarkupLanguage/Components/Settings/IncDecSetting.cs +++ b/BeatSaberMarkupLanguage/Components/Settings/IncDecSetting.cs @@ -1,18 +1,42 @@ using TMPro; +using UnityEngine; using UnityEngine.UI; namespace BeatSaberMarkupLanguage.Components.Settings { public abstract class IncDecSetting : GenericInteractableSetting { - public TextMeshProUGUI TextMesh; - public Button DecButton; - public Button IncButton; + [SerializeField] + private TextMeshProUGUI textMesh; + + [SerializeField] + private Button decButton; + + [SerializeField] + private Button incButton; private bool interactable = true; private bool decEnabled; private bool incEnabled; + public TextMeshProUGUI TextMesh + { + get => textMesh; + set => textMesh = value; + } + + public Button DecButton + { + get => decButton; + set => decButton = value; + } + + public Button IncButton + { + get => incButton; + set => incButton = value; + } + public override bool Interactable { get => interactable; @@ -34,7 +58,7 @@ public bool EnableDec set { decEnabled = value; - DecButton.interactable = value && Interactable; + decButton.interactable = value && Interactable; } } @@ -43,13 +67,13 @@ public bool EnableInc set { incEnabled = value; - IncButton.interactable = value && Interactable; + incButton.interactable = value && Interactable; } } public string Text { - set => TextMesh.text = value; + set => textMesh.text = value; } public abstract void IncButtonPressed(); @@ -58,14 +82,14 @@ public string Text protected virtual void OnEnable() { - IncButton.onClick.AddListener(IncButtonPressed); - DecButton.onClick.AddListener(DecButtonPressed); + incButton.onClick.AddListener(IncButtonPressed); + decButton.onClick.AddListener(DecButtonPressed); } protected void OnDisable() { - IncButton.onClick.RemoveListener(IncButtonPressed); - DecButton.onClick.RemoveListener(DecButtonPressed); + incButton.onClick.RemoveListener(IncButtonPressed); + decButton.onClick.RemoveListener(DecButtonPressed); } } } diff --git a/BeatSaberMarkupLanguage/Components/Settings/IncrementSetting.cs b/BeatSaberMarkupLanguage/Components/Settings/IncrementSetting.cs index af2e7135..a3d20bd5 100644 --- a/BeatSaberMarkupLanguage/Components/Settings/IncrementSetting.cs +++ b/BeatSaberMarkupLanguage/Components/Settings/IncrementSetting.cs @@ -1,16 +1,48 @@ using System; +using UnityEngine; namespace BeatSaberMarkupLanguage.Components.Settings { public class IncrementSetting : IncDecSetting { - public bool IsInt; - public float MinValue = float.MinValue; - public float MaxValue = float.MaxValue; - public float Increments = 1; + [SerializeField] + private bool isInt; + + [SerializeField] + private float minValue = float.MinValue; + + [SerializeField] + private float maxValue = float.MaxValue; + + [SerializeField] + private float increments = 1; private float currentValue; + public bool IsInt + { + get => isInt; + set => isInt = value; + } + + public float MinValue + { + get => minValue; + set => minValue = value; + } + + public float MaxValue + { + get => maxValue; + set => maxValue = value; + } + + public float Increments + { + get => increments; + set => increments = value; + } + public float Value { get @@ -21,7 +53,7 @@ public float Value set { - if (IsInt) + if (isInt) { currentValue = Convert.ToInt32(value); } @@ -38,23 +70,23 @@ public override void Setup() { ReceiveValue(); - if (IsInt) + if (isInt) { - MinValue = ConvertToInt(MinValue); - MaxValue = ConvertToInt(MaxValue); - Increments = ConvertToInt(Increments); + minValue = ConvertToInt(minValue); + maxValue = ConvertToInt(maxValue); + increments = ConvertToInt(increments); } } public override void DecButtonPressed() { - currentValue -= Increments; + currentValue -= increments; EitherPressed(); } public override void IncButtonPressed() { - currentValue += Increments; + currentValue += increments; EitherPressed(); } @@ -62,7 +94,7 @@ public override void ApplyValue() { if (AssociatedValue != null) { - if (IsInt) + if (isInt) { AssociatedValue.SetValue(Convert.ToInt32(Value)); } @@ -77,13 +109,13 @@ public override void ReceiveValue() { if (AssociatedValue != null) { - Value = IsInt ? Convert.ToInt32(AssociatedValue.GetValue()) : Convert.ToSingle(AssociatedValue.GetValue()); + Value = isInt ? Convert.ToInt32(AssociatedValue.GetValue()) : Convert.ToSingle(AssociatedValue.GetValue()); } } protected string TextForValue(float value) { - if (IsInt) + if (isInt) { return Formatter == null ? ConvertToInt(value).ToString() : (Formatter.Invoke(ConvertToInt(value)) as string); } @@ -96,7 +128,7 @@ protected string TextForValue(float value) private void EitherPressed() { UpdateState(); - if (IsInt) + if (isInt) { OnChange?.Invoke(Convert.ToInt32(Value)); } @@ -113,13 +145,13 @@ private void EitherPressed() private void ValidateRange() { - if (currentValue < MinValue) + if (currentValue < minValue) { - currentValue = MinValue; + currentValue = minValue; } - else if (currentValue > MaxValue) + else if (currentValue > maxValue) { - currentValue = MaxValue; + currentValue = maxValue; } } @@ -127,8 +159,8 @@ private void UpdateState() { ValidateRange(); - EnableDec = currentValue > MinValue; - EnableInc = currentValue < MaxValue; + EnableDec = currentValue > minValue; + EnableInc = currentValue < maxValue; Text = TextForValue(currentValue); } diff --git a/BeatSaberMarkupLanguage/Components/Settings/ListSliderSetting.cs b/BeatSaberMarkupLanguage/Components/Settings/ListSliderSetting.cs index aabb375d..9216854a 100644 --- a/BeatSaberMarkupLanguage/Components/Settings/ListSliderSetting.cs +++ b/BeatSaberMarkupLanguage/Components/Settings/ListSliderSetting.cs @@ -15,7 +15,7 @@ public object Value set { Slider.value = Values.IndexOf(value) * 1f; - text.text = TextForValue(Value); + Text.text = TextForValue(Value); } } @@ -24,7 +24,7 @@ public override void Setup() base.Setup(); Slider.minValue = 0; Slider.maxValue = Values.Count - 1; - text = Slider.GetComponentInChildren(); + Text = Slider.GetComponentInChildren(); Slider.numberOfSteps = Values.Count; Slider.valueDidChangeEvent += OnValueChanged; @@ -60,7 +60,7 @@ protected void Awake() private void OnValueChanged(TextSlider textSlider, float val) { - text.text = TextForValue(Value); + Text.text = TextForValue(Value); OnChange?.Invoke(Value); if (UpdateOnChange) { diff --git a/BeatSaberMarkupLanguage/Components/Settings/SliderSetting.cs b/BeatSaberMarkupLanguage/Components/Settings/SliderSetting.cs index 4f3036a8..1cdf1a2c 100644 --- a/BeatSaberMarkupLanguage/Components/Settings/SliderSetting.cs +++ b/BeatSaberMarkupLanguage/Components/Settings/SliderSetting.cs @@ -2,16 +2,32 @@ using BeatSaberMarkupLanguage.Harmony_Patches; using HMUI; using TMPro; +using UnityEngine; namespace BeatSaberMarkupLanguage.Components.Settings { public class SliderSetting : GenericSliderSetting { - public bool IsInt = false; - public float Increments; + [SerializeField] + private bool isInt = false; + + [SerializeField] + private float increments; private float lastValue = float.NegativeInfinity; + public bool IsInt + { + get => isInt; + set => isInt = value; + } + + public float Increments + { + get => increments; + set => increments = value; + } + public float Value { get => Slider.value; @@ -24,8 +40,8 @@ public override void Setup() ApplyCustomSliderTexts.Remappers.Add(Slider, this); - text = Slider.GetComponentInChildren(); - Slider.numberOfSteps = (int)Math.Round((Slider.maxValue - Slider.minValue) / Increments) + 1; + Text = Slider.GetComponentInChildren(); + Slider.numberOfSteps = (int)Math.Round((Slider.maxValue - Slider.minValue) / increments) + 1; Slider.valueDidChangeEvent += OnValueChanged; // TextSlider.UpdateVisuals doesn't work properly when disabled @@ -39,7 +55,7 @@ public override void ApplyValue() { if (AssociatedValue != null) { - if (IsInt) + if (isInt) { AssociatedValue.SetValue((int)Math.Round(Slider.value)); } @@ -54,13 +70,13 @@ public override void ReceiveValue() { if (AssociatedValue != null) { - Slider.value = IsInt ? (int)AssociatedValue.GetValue() : (float)AssociatedValue.GetValue(); + Slider.value = isInt ? (int)AssociatedValue.GetValue() : (float)AssociatedValue.GetValue(); } } internal string TextForValue(float value) { - if (IsInt) + if (isInt) { return Formatter == null ? ((int)Math.Round(value)).ToString() : (Formatter.Invoke((int)Math.Round(value)) as string); } @@ -77,7 +93,7 @@ protected void Awake() private void OnValueChanged(TextSlider textSlider, float val) { - if (IsInt) + if (isInt) { val = (int)Math.Round(val); } @@ -89,7 +105,7 @@ private void OnValueChanged(TextSlider textSlider, float val) lastValue = val; - if (IsInt) + if (isInt) { OnChange?.Invoke((int)val); } diff --git a/BeatSaberMarkupLanguage/Components/Settings/StringSetting.cs b/BeatSaberMarkupLanguage/Components/Settings/StringSetting.cs index 91e34803..7e21f0a7 100644 --- a/BeatSaberMarkupLanguage/Components/Settings/StringSetting.cs +++ b/BeatSaberMarkupLanguage/Components/Settings/StringSetting.cs @@ -6,22 +6,45 @@ namespace BeatSaberMarkupLanguage.Components.Settings { public class StringSetting : GenericInteractableSetting { - public TextMeshProUGUI TextMesh; - public Button EditButton; + [SerializeField] + private TextMeshProUGUI textMesh; - public RectTransform BoundingBox; - public ModalKeyboard ModalKeyboard; + [SerializeField] + private Button editButton; + + [SerializeField] + private RectTransform boundingBox; private string currentValue; + public TextMeshProUGUI TextMesh + { + get => textMesh; + set => textMesh = value; + } + + public Button EditButton + { + get => editButton; + set => editButton = value; + } + + public RectTransform BoundingBox + { + get => boundingBox; + set => boundingBox = value; + } + + public ModalKeyboard ModalKeyboard { get; set; } + public override bool Interactable { - get => EditButton != null && EditButton.interactable; + get => editButton != null && editButton.interactable; set { - if (EditButton != null) + if (editButton != null) { - EditButton.interactable = value; + editButton.interactable = value; } } } @@ -32,7 +55,7 @@ public string Text set { currentValue = value; - TextMesh.text = Formatter == null ? value : Formatter.Invoke(value) as string; + textMesh.text = Formatter == null ? value : Formatter.Invoke(value) as string; } } @@ -73,13 +96,13 @@ public override void ReceiveValue() protected virtual void OnEnable() { - EditButton.onClick.AddListener(EditButtonPressed); + editButton.onClick.AddListener(EditButtonPressed); ModalKeyboard.Keyboard.EnterPressed += EnterPressed; } protected void OnDisable() { - EditButton.onClick.RemoveListener(EditButtonPressed); + editButton.onClick.RemoveListener(EditButtonPressed); ModalKeyboard.Keyboard.EnterPressed -= EnterPressed; } } diff --git a/BeatSaberMarkupLanguage/Components/Settings/ToggleSetting.cs b/BeatSaberMarkupLanguage/Components/Settings/ToggleSetting.cs index 77d49fad..dd2dbbe3 100644 --- a/BeatSaberMarkupLanguage/Components/Settings/ToggleSetting.cs +++ b/BeatSaberMarkupLanguage/Components/Settings/ToggleSetting.cs @@ -1,35 +1,51 @@ using TMPro; +using UnityEngine; using UnityEngine.UI; namespace BeatSaberMarkupLanguage.Components.Settings { public class ToggleSetting : GenericInteractableSetting { - public Toggle Toggle; - public TextMeshProUGUI TextMesh; + [SerializeField] + private Toggle toggle; + + [SerializeField] + private TextMeshProUGUI textMesh; private bool currentValue; + public Toggle Toggle + { + get => toggle; + set => toggle = value; + } + + public TextMeshProUGUI TextMesh + { + get => textMesh; + set => textMesh = value; + } + public bool Value { get => currentValue; set { currentValue = value; - Toggle.isOn = value; + toggle.isOn = value; } } public string Text { - get => TextMesh.text; - set => TextMesh.text = value; + get => textMesh.text; + set => textMesh.text = value; } public override bool Interactable { - get => Toggle.interactable; - set => Toggle.interactable = value; + get => toggle.interactable; + set => toggle.interactable = value; } public override void Setup() @@ -52,13 +68,13 @@ public override void ReceiveValue() protected void OnEnable() { - Toggle.onValueChanged.AddListener(OnValueChanged); - Toggle.isOn = currentValue; + toggle.onValueChanged.AddListener(OnValueChanged); + toggle.isOn = currentValue; } protected void OnDisable() { - Toggle.onValueChanged.RemoveListener(OnValueChanged); + toggle.onValueChanged.RemoveListener(OnValueChanged); } private void OnValueChanged(bool value) diff --git a/BeatSaberMarkupLanguage/Components/Strokable.cs b/BeatSaberMarkupLanguage/Components/Strokable.cs index d117b5a6..43e3a1c8 100644 --- a/BeatSaberMarkupLanguage/Components/Strokable.cs +++ b/BeatSaberMarkupLanguage/Components/Strokable.cs @@ -5,7 +5,8 @@ namespace BeatSaberMarkupLanguage.Components { public class Strokable : MonoBehaviour { - public Image Image; + [SerializeField] + private Image image; public enum StrokeType { @@ -14,9 +15,15 @@ public enum StrokeType Regular, } + public Image Image + { + get => image; + set => image = value; + } + public void SetType(StrokeType strokeType) { - if (Image == null) + if (image == null) { return; } @@ -24,28 +31,28 @@ public void SetType(StrokeType strokeType) switch (strokeType) { case StrokeType.None: - Image.enabled = false; + image.enabled = false; break; case StrokeType.Clean: - Image.enabled = true; - Image.sprite = Utilities.FindSpriteCached("RoundRectSmallStroke"); + image.enabled = true; + image.sprite = Utilities.FindSpriteCached("RoundRectSmallStroke"); break; case StrokeType.Regular: - Image.enabled = true; - Image.sprite = Utilities.FindSpriteCached("RoundRectBigStroke"); + image.enabled = true; + image.sprite = Utilities.FindSpriteCached("RoundRectBigStroke"); break; } } public void SetColor(string strokeColor) { - if (Image == null) + if (image == null) { return; } - Image.color = Parse.Color(strokeColor); - Image.enabled = true; + image.color = Parse.Color(strokeColor); + image.enabled = true; } } } diff --git a/BeatSaberMarkupLanguage/Components/Tab.cs b/BeatSaberMarkupLanguage/Components/Tab.cs index 2c740aca..b37abd68 100644 --- a/BeatSaberMarkupLanguage/Components/Tab.cs +++ b/BeatSaberMarkupLanguage/Components/Tab.cs @@ -4,12 +4,12 @@ namespace BeatSaberMarkupLanguage.Components { public class Tab : MonoBehaviour { - public TabSelector Selector; - private string tabName; private string tabKey; private bool isVisible = true; + public TabSelector Selector { get; set; } + public string TabName { get => tabName; diff --git a/BeatSaberMarkupLanguage/Components/TabSelector.cs b/BeatSaberMarkupLanguage/Components/TabSelector.cs index 3ae8b6a0..a8fdc934 100644 --- a/BeatSaberMarkupLanguage/Components/TabSelector.cs +++ b/BeatSaberMarkupLanguage/Components/TabSelector.cs @@ -10,13 +10,20 @@ namespace BeatSaberMarkupLanguage.Components { public class TabSelector : MonoBehaviour { - public TextSegmentedControl TextSegmentedControl; - public BSMLParserParams ParserParams; - public string TabTag; - public string LeftButtonTag; - public string RightButtonTag; private readonly List tabs = new(); + [SerializeField] + private TextSegmentedControl textSegmentedControl; + + [SerializeField] + private string tabTag; + + [SerializeField] + private string leftButtonTag; + + [SerializeField] + private string rightButtonTag; + private int pageCount = -1; private int currentPage = 0; @@ -25,6 +32,32 @@ public class TabSelector : MonoBehaviour private bool shouldRefresh; + public BSMLParserParams ParserParams { get; internal set; } + + public TextSegmentedControl TextSegmentedControl + { + get => textSegmentedControl; + set => textSegmentedControl = value; + } + + public string TabTag + { + get => tabTag; + set => tabTag = value; + } + + public string LeftButtonTag + { + get => leftButtonTag; + set => leftButtonTag = value; + } + + public string RightButtonTag + { + get => rightButtonTag; + set => rightButtonTag = value; + } + public int PageCount { get => pageCount; @@ -41,16 +74,16 @@ public int PageCount public void Setup() { tabs.Clear(); - foreach (GameObject gameObject in ParserParams.GetObjectsWithTag(TabTag)) + foreach (GameObject gameObject in ParserParams.GetObjectsWithTag(tabTag)) { Tab tab = gameObject.GetComponent(); tabs.Add(tab); tab.Selector = this; } - if (LeftButtonTag != null) + if (leftButtonTag != null) { - leftButton = ParserParams.GetObjectsWithTag(LeftButtonTag).FirstOrDefault().GetComponent