mirror of
https://github.com/D1GQ/BetterAmongUs.git
synced 2026-10-21 21:43:29 +00:00
107 lines
3.3 KiB
C#
107 lines
3.3 KiB
C#
using UnityEngine;
|
|
|
|
namespace BetterAmongUs;
|
|
|
|
public class BetterOptionCheckboxItem : BetterOptionItem
|
|
{
|
|
public BetterOptionItem? ThisParent;
|
|
private ToggleOption? ThisOption;
|
|
private bool? IsChecked;
|
|
|
|
public override bool ShowChildrenCondition() => IsChecked == true;
|
|
|
|
public BetterOptionItem Create(int id, GameOptionsMenu gameOptionsMenu, string name, bool DefaultValue = true, BetterOptionItem Parent = null)
|
|
{
|
|
Id = id;
|
|
Tab = gameOptionsMenu;
|
|
Name = name;
|
|
IsChecked = DefaultValue;
|
|
|
|
if (gameOptionsMenu == null)
|
|
{
|
|
Load(DefaultValue);
|
|
return this;
|
|
}
|
|
|
|
ToggleOption optionBehaviour = UnityEngine.Object.Instantiate<ToggleOption>(gameOptionsMenu.checkboxOrigin, Vector3.zero, Quaternion.identity, gameOptionsMenu.settingsContainer);
|
|
optionBehaviour.transform.localPosition = new Vector3(0.952f, 2f - StaticSpacingNum * SpacingNum, -2f);
|
|
SetUp(optionBehaviour);
|
|
optionBehaviour.OnValueChanged = new Action<OptionBehaviour>((option) => ValueChanged(id, option));
|
|
|
|
optionBehaviour.LabelBackground.transform.localScale = new Vector3(1.6f, 1f);
|
|
optionBehaviour.LabelBackground.transform.SetLocalX(-2.4f);
|
|
optionBehaviour.TitleText.enableAutoSizing = false;
|
|
optionBehaviour.TitleText.transform.SetLocalX(-1.5f);
|
|
optionBehaviour.TitleText.alignment = TMPro.TextAlignmentOptions.Right;
|
|
optionBehaviour.TitleText.enableWordWrapping = false;
|
|
optionBehaviour.TitleText.fontSize = 2.5f;
|
|
|
|
// Set data
|
|
optionBehaviour.CheckMark.GetComponent<SpriteRenderer>().enabled = DefaultValue;
|
|
TitleText = optionBehaviour.TitleText;
|
|
Option = optionBehaviour;
|
|
ThisOption = optionBehaviour;
|
|
|
|
Load(DefaultValue);
|
|
|
|
BetterOptionItems.Add(this);
|
|
|
|
if (Parent != null)
|
|
{
|
|
optionBehaviour.LabelBackground.GetComponent<SpriteRenderer>().color = new Color(0.85f, 0.85f, 0.85f, 1f);
|
|
optionBehaviour.LabelBackground.transform.SetLocalZ(1f);
|
|
ThisParent = Parent;
|
|
Parent.ChildrenList.Add(this);
|
|
}
|
|
else
|
|
{
|
|
SpacingNum += StaticSpacingNumPlus;
|
|
}
|
|
|
|
return this;
|
|
}
|
|
|
|
public void Load(bool DefaultValue)
|
|
{
|
|
if (BetterDataManager.CanLoadSetting(Id))
|
|
{
|
|
if (ThisOption == null) return;
|
|
|
|
var Bool = BetterDataManager.LoadBoolSetting(Id);
|
|
ThisOption.CheckMark.GetComponent<SpriteRenderer>().enabled = Bool;
|
|
IsChecked = Bool;
|
|
}
|
|
else
|
|
{
|
|
BetterDataManager.SaveSetting(Id, DefaultValue.ToString());
|
|
}
|
|
}
|
|
|
|
public override bool GetBool()
|
|
{
|
|
if (BetterDataManager.CanLoadSetting(Id))
|
|
{
|
|
return BetterDataManager.LoadBoolSetting(Id);
|
|
}
|
|
else
|
|
{
|
|
return IsChecked ??= false;
|
|
}
|
|
}
|
|
|
|
public override void SetData(OptionBehaviour optionBehaviour)
|
|
{
|
|
optionBehaviour.data = new BaseGameSetting
|
|
{
|
|
Title = StringNames.None,
|
|
Type = OptionTypes.Checkbox,
|
|
};
|
|
}
|
|
|
|
public override void ValueChanged(int id, OptionBehaviour optionBehaviour)
|
|
{
|
|
IsChecked = !IsChecked;
|
|
BetterDataManager.SaveSetting(Id, IsChecked.ToString());
|
|
}
|
|
}
|