Accidently added this last night, I deleted the scene change because I thought this was gone bruh
This commit is contained in:
@@ -14,31 +14,28 @@ public class PlayMenu : MonoBehaviour
|
||||
[SerializeField] private Button customPlayButton;
|
||||
[SerializeField] private Button customNormalizeButton;
|
||||
|
||||
[SerializeField] private TMP_InputField normalBerryChance;
|
||||
[SerializeField] private TMP_InputField poisonBerryChance;
|
||||
[SerializeField] private TMP_InputField slowBerryChance;
|
||||
[SerializeField] private TMP_InputField ultraBerryChance;
|
||||
[SerializeField] private TMP_InputField speedyBerryChance;
|
||||
[SerializeField] private TMP_InputField randomBerryChance;
|
||||
[SerializeField] private TMP_InputField antiBerryChance;
|
||||
[SerializeField] private TMP_InputField nothingBerryChance;
|
||||
|
||||
[SerializeField] private TMP_Text validateTotalText;
|
||||
|
||||
private const float defaultNormalBerryChance = 47.5f;
|
||||
private const float defaultPoisonBerryChance = 12.5f;
|
||||
private const float defaultSlowBerryChance = 10f;
|
||||
private const float defaultUltraBerryChance = 10f;
|
||||
private const float defaultSpeedyBerryChance = 10f;
|
||||
private const float defaultRandomBerryChance = 5f;
|
||||
private const float defaultAntiBerryChance = 5f;
|
||||
private const float defaultNothingBerryChance = 0f;
|
||||
|
||||
private float normalBerryChance = defaultNormalBerryChance;
|
||||
private float poisonBerryChance = defaultPoisonBerryChance;
|
||||
private float slowBerryChance = defaultSlowBerryChance;
|
||||
private float ultraBerryChance = defaultUltraBerryChance;
|
||||
private float speedyBerryChance = defaultSpeedyBerryChance;
|
||||
private float randomBerryChance = defaultRandomBerryChance;
|
||||
private float antiBerryChance = defaultAntiBerryChance;
|
||||
private float nothingBerryChance = defaultNothingBerryChance;
|
||||
|
||||
[SerializeField] private TMP_Text modifyTip;
|
||||
private readonly float defaultNormalBerryChance = 47.5f;
|
||||
private readonly float defaultPoisonBerryChance = 12.5f;
|
||||
private readonly float defaultSlowBerryChance = 10f;
|
||||
private readonly float defaultUltraBerryChance = 10f;
|
||||
private readonly float defaultSpeedyBerryChance = 10f;
|
||||
private readonly float defaultRandomBerryChance = 5f;
|
||||
private readonly float defaultAntiBerryChance = 5f;
|
||||
private readonly float defaultNothingBerryChance = 0f;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
modifyTip.text = Application.isMobilePlatform ? "Tap a berry to modify it's spawn chances!" : "Click a berry to modify it's spawn chances!";
|
||||
customButton.onClick.AddListener(() =>
|
||||
{
|
||||
selectionMenu.SetActive(false);
|
||||
@@ -49,92 +46,110 @@ public class PlayMenu : MonoBehaviour
|
||||
customMenu.SetActive(false);
|
||||
selectionMenu.SetActive(true);
|
||||
|
||||
normalBerryChance = defaultNormalBerryChance;
|
||||
poisonBerryChance = defaultPoisonBerryChance;
|
||||
slowBerryChance = defaultSlowBerryChance;
|
||||
ultraBerryChance = defaultUltraBerryChance;
|
||||
speedyBerryChance = defaultSpeedyBerryChance;
|
||||
randomBerryChance = defaultRandomBerryChance;
|
||||
antiBerryChance = defaultAntiBerryChance;
|
||||
nothingBerryChance = defaultNothingBerryChance;
|
||||
normalBerryChance.text = defaultNormalBerryChance.ToString();
|
||||
poisonBerryChance.text = defaultPoisonBerryChance.ToString();
|
||||
slowBerryChance.text = defaultSlowBerryChance.ToString();
|
||||
ultraBerryChance.text = defaultUltraBerryChance.ToString();
|
||||
speedyBerryChance.text = defaultSpeedyBerryChance.ToString();
|
||||
randomBerryChance.text = defaultRandomBerryChance.ToString();
|
||||
antiBerryChance.text = defaultAntiBerryChance.ToString();
|
||||
nothingBerryChance.text = defaultNothingBerryChance.ToString();
|
||||
ValidateTotal();
|
||||
});
|
||||
customNormalizeButton.onClick.AddListener(() =>
|
||||
{
|
||||
float normalBerry = GetValueFrom(normalBerryChance);
|
||||
float poisonBerry = GetValueFrom(poisonBerryChance);
|
||||
float slowBerry = GetValueFrom(slowBerryChance);
|
||||
float ultraBerry = GetValueFrom(ultraBerryChance);
|
||||
float speedyBerry = GetValueFrom(speedyBerryChance);
|
||||
float randomBerry = GetValueFrom(randomBerryChance);
|
||||
float antiBerry = GetValueFrom(antiBerryChance);
|
||||
float nothingBerry = GetValueFrom(nothingBerryChance);
|
||||
|
||||
int divideBy = 0;
|
||||
|
||||
divideBy += normalBerryChance > 0 ? 1 : 0;
|
||||
divideBy += poisonBerryChance > 0 ? 1 : 0;
|
||||
divideBy += slowBerryChance > 0 ? 1 : 0;
|
||||
divideBy += ultraBerryChance > 0 ? 1 : 0;
|
||||
divideBy += speedyBerryChance > 0 ? 1 : 0;
|
||||
divideBy += randomBerryChance > 0 ? 1 : 0;
|
||||
divideBy += antiBerryChance > 0 ? 1 : 0;
|
||||
divideBy += nothingBerryChance > 0 ? 1 : 0;
|
||||
divideBy += normalBerry > 0 ? 1 : 0;
|
||||
divideBy += poisonBerry > 0 ? 1 : 0;
|
||||
divideBy += slowBerry > 0 ? 1 : 0;
|
||||
divideBy += ultraBerry > 0 ? 1 : 0;
|
||||
divideBy += speedyBerry > 0 ? 1 : 0;
|
||||
divideBy += randomBerry > 0 ? 1 : 0;
|
||||
divideBy += antiBerry > 0 ? 1 : 0;
|
||||
divideBy += nothingBerry > 0 ? 1 : 0;
|
||||
|
||||
float addedChances = normalBerryChance + poisonBerryChance + slowBerryChance + ultraBerryChance + speedyBerryChance + randomBerryChance + antiBerryChance + nothingBerryChance;
|
||||
float addedChances = normalBerry + poisonBerry + slowBerry + ultraBerry + speedyBerry + randomBerry + antiBerry + nothingBerry;
|
||||
float difference = addedChances - 100f;
|
||||
|
||||
if (normalBerryChance > 0) normalBerryChance -= difference / divideBy;
|
||||
if (poisonBerryChance > 0) poisonBerryChance -= difference / divideBy;
|
||||
if (slowBerryChance > 0) slowBerryChance -= difference / divideBy;
|
||||
if (ultraBerryChance > 0) ultraBerryChance -= difference / divideBy;
|
||||
if (speedyBerryChance > 0) speedyBerryChance -= difference / divideBy;
|
||||
if (randomBerryChance > 0) randomBerryChance -= difference / divideBy;
|
||||
if (antiBerryChance > 0) antiBerryChance -= difference / divideBy;
|
||||
if (nothingBerryChance > 0) nothingBerryChance -= difference / divideBy;
|
||||
if (normalBerry > 0) NormalizeOne(normalBerryChance, normalBerry, divideBy, difference);
|
||||
if (poisonBerry > 0) NormalizeOne(poisonBerryChance, poisonBerry, divideBy, difference);
|
||||
if (slowBerry > 0) NormalizeOne(slowBerryChance, slowBerry, divideBy, difference);
|
||||
if (ultraBerry > 0) NormalizeOne(ultraBerryChance, ultraBerry, divideBy, difference);
|
||||
if (speedyBerry > 0) NormalizeOne(speedyBerryChance, speedyBerry, divideBy, difference);
|
||||
if (randomBerry > 0) NormalizeOne(randomBerryChance, randomBerry, divideBy, difference);
|
||||
if (antiBerry > 0) NormalizeOne(antiBerryChance, antiBerry, divideBy, difference);
|
||||
if (nothingBerry > 0) NormalizeOne(nothingBerryChance, nothingBerry, divideBy, difference);
|
||||
|
||||
if (normalBerryChance > 0) normalBerryChance = (float)Math.Floor(normalBerryChance);
|
||||
if (poisonBerryChance > 0) poisonBerryChance = (float)Math.Floor(poisonBerryChance);
|
||||
if (slowBerryChance > 0) slowBerryChance = (float)Math.Floor(slowBerryChance);
|
||||
if (ultraBerryChance > 0) ultraBerryChance = (float)Math.Floor(ultraBerryChance);
|
||||
if (speedyBerryChance > 0) speedyBerryChance = (float)Math.Floor(speedyBerryChance);
|
||||
if (randomBerryChance > 0) randomBerryChance = (float)Math.Floor(randomBerryChance);
|
||||
if (antiBerryChance > 0) antiBerryChance = (float)Math.Floor(antiBerryChance);
|
||||
if (nothingBerryChance > 0) nothingBerryChance = (float)Math.Floor(nothingBerryChance);
|
||||
normalBerry = GetValueFrom(normalBerryChance);
|
||||
poisonBerry = GetValueFrom(poisonBerryChance);
|
||||
slowBerry = GetValueFrom(slowBerryChance);
|
||||
ultraBerry = GetValueFrom(ultraBerryChance);
|
||||
speedyBerry = GetValueFrom(speedyBerryChance);
|
||||
randomBerry = GetValueFrom(randomBerryChance);
|
||||
antiBerry = GetValueFrom(antiBerryChance);
|
||||
nothingBerry = GetValueFrom(nothingBerryChance);
|
||||
|
||||
float addedChances2 = normalBerryChance + poisonBerryChance + slowBerryChance + ultraBerryChance + speedyBerryChance + randomBerryChance + antiBerryChance + nothingBerryChance;
|
||||
if (normalBerry > 0) normalBerry = (float)Math.Floor(normalBerry);
|
||||
if (poisonBerry > 0) poisonBerry = (float)Math.Floor(poisonBerry);
|
||||
if (slowBerry > 0) slowBerry = (float)Math.Floor(slowBerry);
|
||||
if (ultraBerry > 0) ultraBerry = (float)Math.Floor(ultraBerry);
|
||||
if (speedyBerry > 0) speedyBerry = (float)Math.Floor(speedyBerry);
|
||||
if (randomBerry > 0) randomBerry = (float)Math.Floor(randomBerry);
|
||||
if (antiBerry > 0) antiBerry = (float)Math.Floor(antiBerry);
|
||||
if (nothingBerry > 0) nothingBerry = (float)Math.Floor(nothingBerry);
|
||||
|
||||
float addedChances2 = normalBerry + poisonBerry + slowBerry + ultraBerry + speedyBerry + randomBerry + antiBerry + nothingBerry;
|
||||
float difference2 = addedChances2 - 100f;
|
||||
bool fixedValues = false;
|
||||
|
||||
if (normalBerryChance > 0)
|
||||
if (normalBerry > 0)
|
||||
{
|
||||
normalBerryChance = !fixedValues ? (normalBerryChance - difference2) : normalBerryChance;
|
||||
NormalizeTwo(normalBerryChance, fixedValues, normalBerry, difference2);
|
||||
fixedValues = true;
|
||||
}
|
||||
if (poisonBerryChance > 0)
|
||||
if (poisonBerry > 0)
|
||||
{
|
||||
poisonBerryChance = !fixedValues ? (poisonBerryChance - difference2) : poisonBerryChance;
|
||||
NormalizeTwo(poisonBerryChance, fixedValues, poisonBerry, difference2);
|
||||
fixedValues = true;
|
||||
}
|
||||
if (slowBerryChance > 0)
|
||||
if (slowBerry > 0)
|
||||
{
|
||||
slowBerryChance = !fixedValues ? (slowBerryChance - difference2) : slowBerryChance;
|
||||
NormalizeTwo(slowBerryChance, fixedValues, slowBerry, difference2);
|
||||
fixedValues = true;
|
||||
}
|
||||
if (ultraBerryChance > 0)
|
||||
if (ultraBerry > 0)
|
||||
{
|
||||
ultraBerryChance = !fixedValues ? (ultraBerryChance - difference2) : ultraBerryChance;
|
||||
NormalizeTwo(ultraBerryChance, fixedValues, ultraBerry, difference2);
|
||||
fixedValues = true;
|
||||
}
|
||||
if (speedyBerryChance > 0)
|
||||
if (speedyBerry > 0)
|
||||
{
|
||||
speedyBerryChance = !fixedValues ? (speedyBerryChance - difference2) : speedyBerryChance;
|
||||
NormalizeTwo(speedyBerryChance, fixedValues, speedyBerry, difference2);
|
||||
fixedValues = true;
|
||||
}
|
||||
if (randomBerryChance > 0)
|
||||
if (randomBerry > 0)
|
||||
{
|
||||
randomBerryChance = !fixedValues ? (randomBerryChance - difference2) : randomBerryChance;
|
||||
NormalizeTwo(randomBerryChance, fixedValues, randomBerry, difference2);
|
||||
fixedValues = true;
|
||||
}
|
||||
if (antiBerryChance > 0)
|
||||
if (antiBerry > 0)
|
||||
{
|
||||
antiBerryChance = !fixedValues ? (antiBerryChance - difference2) : antiBerryChance;
|
||||
NormalizeTwo(antiBerryChance, fixedValues, antiBerry, difference2);
|
||||
fixedValues = true;
|
||||
}
|
||||
if (nothingBerryChance > 0)
|
||||
if (nothingBerry > 0)
|
||||
{
|
||||
nothingBerryChance = !fixedValues ? (nothingBerryChance - difference2) : nothingBerryChance;
|
||||
NormalizeTwo(nothingBerryChance, fixedValues, nothingBerry, difference2);
|
||||
fixedValues = true;
|
||||
}
|
||||
|
||||
@@ -145,16 +160,33 @@ public class PlayMenu : MonoBehaviour
|
||||
GameObject obj = new("CustomGameTempData");
|
||||
obj.AddComponent<CustomGameTempData>();
|
||||
CustomGameTempData customGameTempData = obj.GetComponent<CustomGameTempData>();
|
||||
customGameTempData.normalBerryChance = normalBerryChance;
|
||||
customGameTempData.poisonBerryChance = poisonBerryChance;
|
||||
customGameTempData.slowBerryChance = slowBerryChance;
|
||||
customGameTempData.ultraBerryChance = ultraBerryChance;
|
||||
customGameTempData.speedyBerryChance = speedyBerryChance;
|
||||
customGameTempData.randomBerryChance = randomBerryChance;
|
||||
customGameTempData.antiBerryChance = antiBerryChance;
|
||||
customGameTempData.nothingBerryChance = nothingBerryChance;
|
||||
customGameTempData.normalBerryChance = GetValueFrom(normalBerryChance);
|
||||
customGameTempData.poisonBerryChance = GetValueFrom(poisonBerryChance);
|
||||
customGameTempData.slowBerryChance = GetValueFrom(slowBerryChance);
|
||||
customGameTempData.ultraBerryChance = GetValueFrom(ultraBerryChance);
|
||||
customGameTempData.speedyBerryChance = GetValueFrom(speedyBerryChance);
|
||||
customGameTempData.randomBerryChance = GetValueFrom(randomBerryChance);
|
||||
customGameTempData.antiBerryChance = GetValueFrom(antiBerryChance);
|
||||
customGameTempData.nothingBerryChance = GetValueFrom(nothingBerryChance);
|
||||
await SceneManager.LoadSceneAsync("CustomGamePlayer");
|
||||
});
|
||||
|
||||
normalBerryChance.onSelect.AddListener((value) => OnSelect(value, normalBerryChance));
|
||||
normalBerryChance.onDeselect.AddListener((value) => OnDeselect(value, normalBerryChance));
|
||||
poisonBerryChance.onSelect.AddListener((value) => OnSelect(value, poisonBerryChance));
|
||||
poisonBerryChance.onDeselect.AddListener((value) => OnDeselect(value, poisonBerryChance));
|
||||
slowBerryChance.onSelect.AddListener((value) => OnSelect(value, slowBerryChance));
|
||||
slowBerryChance.onDeselect.AddListener((value) => OnDeselect(value, slowBerryChance));
|
||||
ultraBerryChance.onSelect.AddListener((value) => OnSelect(value, ultraBerryChance));
|
||||
ultraBerryChance.onDeselect.AddListener((value) => OnDeselect(value, ultraBerryChance));
|
||||
speedyBerryChance.onSelect.AddListener((value) => OnSelect(value, speedyBerryChance));
|
||||
speedyBerryChance.onDeselect.AddListener((value) => OnDeselect(value, speedyBerryChance));
|
||||
randomBerryChance.onSelect.AddListener((value) => OnSelect(value, randomBerryChance));
|
||||
randomBerryChance.onDeselect.AddListener((value) => OnDeselect(value, randomBerryChance));
|
||||
antiBerryChance.onSelect.AddListener((value) => OnSelect(value, antiBerryChance));
|
||||
antiBerryChance.onDeselect.AddListener((value) => OnDeselect(value, antiBerryChance));
|
||||
nothingBerryChance.onSelect.AddListener((value) => OnSelect(value, nothingBerryChance));
|
||||
nothingBerryChance.onDeselect.AddListener((value) => OnDeselect(value, nothingBerryChance));
|
||||
}
|
||||
|
||||
void ValidateTotal()
|
||||
@@ -163,14 +195,14 @@ public class PlayMenu : MonoBehaviour
|
||||
customPlayButton.interactable = false;
|
||||
customNormalizeButton.interactable = false;
|
||||
float total = 0f;
|
||||
total += normalBerryChance;
|
||||
total += poisonBerryChance;
|
||||
total += slowBerryChance;
|
||||
total += ultraBerryChance;
|
||||
total += speedyBerryChance;
|
||||
total += randomBerryChance;
|
||||
total += antiBerryChance;
|
||||
total += nothingBerryChance;
|
||||
total += GetValueFrom(normalBerryChance);
|
||||
total += GetValueFrom(poisonBerryChance);
|
||||
total += GetValueFrom(slowBerryChance);
|
||||
total += GetValueFrom(ultraBerryChance);
|
||||
total += GetValueFrom(speedyBerryChance);
|
||||
total += GetValueFrom(randomBerryChance);
|
||||
total += GetValueFrom(antiBerryChance);
|
||||
total += GetValueFrom(nothingBerryChance);
|
||||
if (total == 100f)
|
||||
{
|
||||
customBackButton.interactable = true;
|
||||
@@ -185,6 +217,63 @@ public class PlayMenu : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
private float GetValueFrom(TMP_InputField inputField)
|
||||
{
|
||||
return GetValueFroText(inputField.text);
|
||||
}
|
||||
|
||||
private float GetValueFroText(string text)
|
||||
{
|
||||
try
|
||||
{
|
||||
return float.Parse(text.Replace("%", "").Trim());
|
||||
}
|
||||
catch
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
}
|
||||
|
||||
void OnSelect(string value, TMP_InputField inputField)
|
||||
{
|
||||
validateTotalText.gameObject.SetActive(false);
|
||||
customBackButton.interactable = false;
|
||||
customPlayButton.interactable = false;
|
||||
customNormalizeButton.interactable = false;
|
||||
inputField.text = value.Replace("%", "");
|
||||
inputField.stringPosition = inputField.text.Length;
|
||||
}
|
||||
|
||||
void OnDeselect(string value, TMP_InputField inputField)
|
||||
{
|
||||
if (float.TryParse(value, out var value2) && value2 < 0f)
|
||||
{
|
||||
value = "0";
|
||||
}
|
||||
inputField.text = value + "%";
|
||||
ValidateTotal();
|
||||
}
|
||||
|
||||
void NormalizeOne(TMP_InputField inputField, float berryChance, int divideBy, float difference)
|
||||
{
|
||||
inputField.text = (berryChance - (difference / divideBy)).ToString() + "%";
|
||||
inputField.stringPosition = inputField.text.Length;
|
||||
}
|
||||
|
||||
void NormalizeTwo(TMP_InputField inputField, bool fixedValues, float berryChance, float difference2)
|
||||
{
|
||||
if (!fixedValues)
|
||||
{
|
||||
inputField.text = (berryChance - difference2).ToString() + "%";
|
||||
inputField.stringPosition = inputField.text.Length;
|
||||
}
|
||||
else
|
||||
{
|
||||
inputField.text = berryChance.ToString() + "%";
|
||||
inputField.stringPosition = inputField.text.Length;
|
||||
}
|
||||
}
|
||||
|
||||
async void Update()
|
||||
{
|
||||
if (Keyboard.current.escapeKey.wasPressedThisFrame)
|
||||
|
||||
Reference in New Issue
Block a user