mirror of
https://github.com/D1GQ/BetterAmongUs.git
synced 2026-10-20 01:46:19 +00:00
178 lines
5.1 KiB
C#
178 lines
5.1 KiB
C#
using UnityEngine;
|
|
|
|
namespace BetterAmongUs;
|
|
|
|
public class BetterOptionIntItem : BetterOptionItem
|
|
{
|
|
public int CurrentValue;
|
|
public IntRange intRange = new(0, 180);
|
|
public int Increment = 1;
|
|
private NumberOption? ThisOption;
|
|
private string? PostFix;
|
|
private string? PreFix;
|
|
|
|
public BetterOptionItem Create(int id, GameOptionsMenu gameOptionsMenu, string name, int[] values, int DefaultValue, string preFix = "", string postFix = "", BetterOptionItem Parent = null)
|
|
{
|
|
Id = id;
|
|
intRange = new(values[0], values[1]);
|
|
Increment = values[2];
|
|
if (DefaultValue < intRange.min) DefaultValue = intRange.min;
|
|
if (DefaultValue > intRange.max) DefaultValue = intRange.max;
|
|
CurrentValue = DefaultValue;
|
|
|
|
if (gameOptionsMenu == null)
|
|
{
|
|
Load(DefaultValue);
|
|
return this;
|
|
}
|
|
|
|
if (values.Length is < 3 or > 3) return null;
|
|
|
|
NumberOption optionBehaviour = UnityEngine.Object.Instantiate<NumberOption>(gameOptionsMenu.numberOptionOrigin, 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));
|
|
SpacingNum += StaticSpacingNumPlus;
|
|
|
|
// Fix Game Crash
|
|
foreach (RulesCategory rulesCategory in GameManager.Instance.GameSettingsList.AllCategories)
|
|
{
|
|
optionBehaviour.data = rulesCategory.AllGameSettings.ToArray().FirstOrDefault(item => item.Type == OptionTypes.Number);
|
|
}
|
|
|
|
optionBehaviour.PlusBtn.OnClick.RemoveAllListeners();
|
|
optionBehaviour.MinusBtn.OnClick.RemoveAllListeners();
|
|
optionBehaviour.PlusBtn.OnClick.AddListener(new Action(() => Increase()));
|
|
optionBehaviour.MinusBtn.OnClick.AddListener(new Action(() => Decrease()));
|
|
|
|
// Set data
|
|
Tab = gameOptionsMenu;
|
|
Name = name;
|
|
TitleText = optionBehaviour.TitleText;
|
|
Option = optionBehaviour;
|
|
PostFix = postFix;
|
|
PreFix = preFix;
|
|
ThisOption = optionBehaviour;
|
|
|
|
Load(DefaultValue);
|
|
AdjustButtonsActiveState();
|
|
|
|
BetterOptionItems.Add(this);
|
|
return this;
|
|
}
|
|
|
|
private void AdjustButtonsActiveState()
|
|
{
|
|
if (ThisOption == null) return;
|
|
|
|
ThisOption.ValueText.text = PreFix + CurrentValue.ToString() + PostFix;
|
|
|
|
if (CurrentValue + Increment > intRange.max)
|
|
{
|
|
ThisOption.PlusBtn.SetInteractable(false);
|
|
ThisOption.MinusBtn.SetInteractable(true);
|
|
}
|
|
else if (CurrentValue - Increment < intRange.min)
|
|
{
|
|
ThisOption.PlusBtn.SetInteractable(true);
|
|
ThisOption.MinusBtn.SetInteractable(false);
|
|
}
|
|
else
|
|
{
|
|
ThisOption.PlusBtn.SetInteractable(true);
|
|
ThisOption.MinusBtn.SetInteractable(true);
|
|
}
|
|
|
|
BetterDataManager.SaveSetting(Id, CurrentValue.ToString());
|
|
}
|
|
|
|
public void Increase()
|
|
{
|
|
int times = 1;
|
|
if (Input.GetKey(KeyCode.LeftShift))
|
|
times = 5;
|
|
if (Input.GetKey(KeyCode.LeftControl))
|
|
times = 10;
|
|
|
|
if (CurrentValue + Increment * times <= intRange.max)
|
|
{
|
|
CurrentValue += Increment * times;
|
|
}
|
|
|
|
AdjustButtonsActiveState();
|
|
}
|
|
|
|
public void Decrease()
|
|
{
|
|
int times = 1;
|
|
if (Input.GetKey(KeyCode.LeftShift))
|
|
times = 5;
|
|
if (Input.GetKey(KeyCode.LeftControl))
|
|
times = 10;
|
|
|
|
if (CurrentValue - Increment * times >= intRange.min)
|
|
{
|
|
CurrentValue -= Increment * times;
|
|
}
|
|
|
|
AdjustButtonsActiveState();
|
|
}
|
|
|
|
public void Load(int DefaultValue)
|
|
{
|
|
if (BetterDataManager.CanLoadSetting(Id))
|
|
{
|
|
var Int = BetterDataManager.LoadIntSetting(Id);
|
|
|
|
if (Int > intRange.max || Int < intRange.min)
|
|
{
|
|
Int = DefaultValue;
|
|
BetterDataManager.SaveSetting(Id, DefaultValue.ToString());
|
|
}
|
|
|
|
CurrentValue = Int;
|
|
}
|
|
else
|
|
{
|
|
BetterDataManager.SaveSetting(Id, DefaultValue.ToString());
|
|
}
|
|
}
|
|
|
|
public override float GetFloat()
|
|
{
|
|
if (BetterDataManager.CanLoadSetting(Id))
|
|
{
|
|
return BetterDataManager.LoadIntSetting(Id);
|
|
}
|
|
else
|
|
{
|
|
return CurrentValue;
|
|
}
|
|
}
|
|
|
|
public override int GetInt()
|
|
{
|
|
if (BetterDataManager.CanLoadSetting(Id))
|
|
{
|
|
return BetterDataManager.LoadIntSetting(Id);
|
|
}
|
|
else
|
|
{
|
|
return CurrentValue;
|
|
}
|
|
}
|
|
|
|
public override void SetData(OptionBehaviour optionBehaviour)
|
|
{
|
|
optionBehaviour.data = new BaseGameSetting
|
|
{
|
|
Title = StringNames.None,
|
|
Type = OptionTypes.Float,
|
|
};
|
|
}
|
|
|
|
public override void ValueChanged(int id, OptionBehaviour optionBehaviour)
|
|
{
|
|
}
|
|
}
|