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 customPlayButton;
|
||||||
[SerializeField] private Button customNormalizeButton;
|
[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;
|
[SerializeField] private TMP_Text validateTotalText;
|
||||||
|
|
||||||
private const float defaultNormalBerryChance = 47.5f;
|
private readonly float defaultNormalBerryChance = 47.5f;
|
||||||
private const float defaultPoisonBerryChance = 12.5f;
|
private readonly float defaultPoisonBerryChance = 12.5f;
|
||||||
private const float defaultSlowBerryChance = 10f;
|
private readonly float defaultSlowBerryChance = 10f;
|
||||||
private const float defaultUltraBerryChance = 10f;
|
private readonly float defaultUltraBerryChance = 10f;
|
||||||
private const float defaultSpeedyBerryChance = 10f;
|
private readonly float defaultSpeedyBerryChance = 10f;
|
||||||
private const float defaultRandomBerryChance = 5f;
|
private readonly float defaultRandomBerryChance = 5f;
|
||||||
private const float defaultAntiBerryChance = 5f;
|
private readonly float defaultAntiBerryChance = 5f;
|
||||||
private const float defaultNothingBerryChance = 0f;
|
private readonly 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;
|
|
||||||
|
|
||||||
void Awake()
|
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(() =>
|
customButton.onClick.AddListener(() =>
|
||||||
{
|
{
|
||||||
selectionMenu.SetActive(false);
|
selectionMenu.SetActive(false);
|
||||||
@@ -49,92 +46,110 @@ public class PlayMenu : MonoBehaviour
|
|||||||
customMenu.SetActive(false);
|
customMenu.SetActive(false);
|
||||||
selectionMenu.SetActive(true);
|
selectionMenu.SetActive(true);
|
||||||
|
|
||||||
normalBerryChance = defaultNormalBerryChance;
|
normalBerryChance.text = defaultNormalBerryChance.ToString();
|
||||||
poisonBerryChance = defaultPoisonBerryChance;
|
poisonBerryChance.text = defaultPoisonBerryChance.ToString();
|
||||||
slowBerryChance = defaultSlowBerryChance;
|
slowBerryChance.text = defaultSlowBerryChance.ToString();
|
||||||
ultraBerryChance = defaultUltraBerryChance;
|
ultraBerryChance.text = defaultUltraBerryChance.ToString();
|
||||||
speedyBerryChance = defaultSpeedyBerryChance;
|
speedyBerryChance.text = defaultSpeedyBerryChance.ToString();
|
||||||
randomBerryChance = defaultRandomBerryChance;
|
randomBerryChance.text = defaultRandomBerryChance.ToString();
|
||||||
antiBerryChance = defaultAntiBerryChance;
|
antiBerryChance.text = defaultAntiBerryChance.ToString();
|
||||||
nothingBerryChance = defaultNothingBerryChance;
|
nothingBerryChance.text = defaultNothingBerryChance.ToString();
|
||||||
ValidateTotal();
|
ValidateTotal();
|
||||||
});
|
});
|
||||||
customNormalizeButton.onClick.AddListener(() =>
|
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;
|
int divideBy = 0;
|
||||||
|
|
||||||
divideBy += normalBerryChance > 0 ? 1 : 0;
|
divideBy += normalBerry > 0 ? 1 : 0;
|
||||||
divideBy += poisonBerryChance > 0 ? 1 : 0;
|
divideBy += poisonBerry > 0 ? 1 : 0;
|
||||||
divideBy += slowBerryChance > 0 ? 1 : 0;
|
divideBy += slowBerry > 0 ? 1 : 0;
|
||||||
divideBy += ultraBerryChance > 0 ? 1 : 0;
|
divideBy += ultraBerry > 0 ? 1 : 0;
|
||||||
divideBy += speedyBerryChance > 0 ? 1 : 0;
|
divideBy += speedyBerry > 0 ? 1 : 0;
|
||||||
divideBy += randomBerryChance > 0 ? 1 : 0;
|
divideBy += randomBerry > 0 ? 1 : 0;
|
||||||
divideBy += antiBerryChance > 0 ? 1 : 0;
|
divideBy += antiBerry > 0 ? 1 : 0;
|
||||||
divideBy += nothingBerryChance > 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;
|
float difference = addedChances - 100f;
|
||||||
|
|
||||||
if (normalBerryChance > 0) normalBerryChance -= difference / divideBy;
|
if (normalBerry > 0) NormalizeOne(normalBerryChance, normalBerry, divideBy, difference);
|
||||||
if (poisonBerryChance > 0) poisonBerryChance -= difference / divideBy;
|
if (poisonBerry > 0) NormalizeOne(poisonBerryChance, poisonBerry, divideBy, difference);
|
||||||
if (slowBerryChance > 0) slowBerryChance -= difference / divideBy;
|
if (slowBerry > 0) NormalizeOne(slowBerryChance, slowBerry, divideBy, difference);
|
||||||
if (ultraBerryChance > 0) ultraBerryChance -= difference / divideBy;
|
if (ultraBerry > 0) NormalizeOne(ultraBerryChance, ultraBerry, divideBy, difference);
|
||||||
if (speedyBerryChance > 0) speedyBerryChance -= difference / divideBy;
|
if (speedyBerry > 0) NormalizeOne(speedyBerryChance, speedyBerry, divideBy, difference);
|
||||||
if (randomBerryChance > 0) randomBerryChance -= difference / divideBy;
|
if (randomBerry > 0) NormalizeOne(randomBerryChance, randomBerry, divideBy, difference);
|
||||||
if (antiBerryChance > 0) antiBerryChance -= difference / divideBy;
|
if (antiBerry > 0) NormalizeOne(antiBerryChance, antiBerry, divideBy, difference);
|
||||||
if (nothingBerryChance > 0) nothingBerryChance -= difference / divideBy;
|
if (nothingBerry > 0) NormalizeOne(nothingBerryChance, nothingBerry, divideBy, difference);
|
||||||
|
|
||||||
if (normalBerryChance > 0) normalBerryChance = (float)Math.Floor(normalBerryChance);
|
normalBerry = GetValueFrom(normalBerryChance);
|
||||||
if (poisonBerryChance > 0) poisonBerryChance = (float)Math.Floor(poisonBerryChance);
|
poisonBerry = GetValueFrom(poisonBerryChance);
|
||||||
if (slowBerryChance > 0) slowBerryChance = (float)Math.Floor(slowBerryChance);
|
slowBerry = GetValueFrom(slowBerryChance);
|
||||||
if (ultraBerryChance > 0) ultraBerryChance = (float)Math.Floor(ultraBerryChance);
|
ultraBerry = GetValueFrom(ultraBerryChance);
|
||||||
if (speedyBerryChance > 0) speedyBerryChance = (float)Math.Floor(speedyBerryChance);
|
speedyBerry = GetValueFrom(speedyBerryChance);
|
||||||
if (randomBerryChance > 0) randomBerryChance = (float)Math.Floor(randomBerryChance);
|
randomBerry = GetValueFrom(randomBerryChance);
|
||||||
if (antiBerryChance > 0) antiBerryChance = (float)Math.Floor(antiBerryChance);
|
antiBerry = GetValueFrom(antiBerryChance);
|
||||||
if (nothingBerryChance > 0) nothingBerryChance = (float)Math.Floor(nothingBerryChance);
|
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;
|
float difference2 = addedChances2 - 100f;
|
||||||
bool fixedValues = false;
|
bool fixedValues = false;
|
||||||
|
|
||||||
if (normalBerryChance > 0)
|
if (normalBerry > 0)
|
||||||
{
|
{
|
||||||
normalBerryChance = !fixedValues ? (normalBerryChance - difference2) : normalBerryChance;
|
NormalizeTwo(normalBerryChance, fixedValues, normalBerry, difference2);
|
||||||
fixedValues = true;
|
fixedValues = true;
|
||||||
}
|
}
|
||||||
if (poisonBerryChance > 0)
|
if (poisonBerry > 0)
|
||||||
{
|
{
|
||||||
poisonBerryChance = !fixedValues ? (poisonBerryChance - difference2) : poisonBerryChance;
|
NormalizeTwo(poisonBerryChance, fixedValues, poisonBerry, difference2);
|
||||||
fixedValues = true;
|
fixedValues = true;
|
||||||
}
|
}
|
||||||
if (slowBerryChance > 0)
|
if (slowBerry > 0)
|
||||||
{
|
{
|
||||||
slowBerryChance = !fixedValues ? (slowBerryChance - difference2) : slowBerryChance;
|
NormalizeTwo(slowBerryChance, fixedValues, slowBerry, difference2);
|
||||||
fixedValues = true;
|
fixedValues = true;
|
||||||
}
|
}
|
||||||
if (ultraBerryChance > 0)
|
if (ultraBerry > 0)
|
||||||
{
|
{
|
||||||
ultraBerryChance = !fixedValues ? (ultraBerryChance - difference2) : ultraBerryChance;
|
NormalizeTwo(ultraBerryChance, fixedValues, ultraBerry, difference2);
|
||||||
fixedValues = true;
|
fixedValues = true;
|
||||||
}
|
}
|
||||||
if (speedyBerryChance > 0)
|
if (speedyBerry > 0)
|
||||||
{
|
{
|
||||||
speedyBerryChance = !fixedValues ? (speedyBerryChance - difference2) : speedyBerryChance;
|
NormalizeTwo(speedyBerryChance, fixedValues, speedyBerry, difference2);
|
||||||
fixedValues = true;
|
fixedValues = true;
|
||||||
}
|
}
|
||||||
if (randomBerryChance > 0)
|
if (randomBerry > 0)
|
||||||
{
|
{
|
||||||
randomBerryChance = !fixedValues ? (randomBerryChance - difference2) : randomBerryChance;
|
NormalizeTwo(randomBerryChance, fixedValues, randomBerry, difference2);
|
||||||
fixedValues = true;
|
fixedValues = true;
|
||||||
}
|
}
|
||||||
if (antiBerryChance > 0)
|
if (antiBerry > 0)
|
||||||
{
|
{
|
||||||
antiBerryChance = !fixedValues ? (antiBerryChance - difference2) : antiBerryChance;
|
NormalizeTwo(antiBerryChance, fixedValues, antiBerry, difference2);
|
||||||
fixedValues = true;
|
fixedValues = true;
|
||||||
}
|
}
|
||||||
if (nothingBerryChance > 0)
|
if (nothingBerry > 0)
|
||||||
{
|
{
|
||||||
nothingBerryChance = !fixedValues ? (nothingBerryChance - difference2) : nothingBerryChance;
|
NormalizeTwo(nothingBerryChance, fixedValues, nothingBerry, difference2);
|
||||||
fixedValues = true;
|
fixedValues = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,16 +160,33 @@ public class PlayMenu : MonoBehaviour
|
|||||||
GameObject obj = new("CustomGameTempData");
|
GameObject obj = new("CustomGameTempData");
|
||||||
obj.AddComponent<CustomGameTempData>();
|
obj.AddComponent<CustomGameTempData>();
|
||||||
CustomGameTempData customGameTempData = obj.GetComponent<CustomGameTempData>();
|
CustomGameTempData customGameTempData = obj.GetComponent<CustomGameTempData>();
|
||||||
customGameTempData.normalBerryChance = normalBerryChance;
|
customGameTempData.normalBerryChance = GetValueFrom(normalBerryChance);
|
||||||
customGameTempData.poisonBerryChance = poisonBerryChance;
|
customGameTempData.poisonBerryChance = GetValueFrom(poisonBerryChance);
|
||||||
customGameTempData.slowBerryChance = slowBerryChance;
|
customGameTempData.slowBerryChance = GetValueFrom(slowBerryChance);
|
||||||
customGameTempData.ultraBerryChance = ultraBerryChance;
|
customGameTempData.ultraBerryChance = GetValueFrom(ultraBerryChance);
|
||||||
customGameTempData.speedyBerryChance = speedyBerryChance;
|
customGameTempData.speedyBerryChance = GetValueFrom(speedyBerryChance);
|
||||||
customGameTempData.randomBerryChance = randomBerryChance;
|
customGameTempData.randomBerryChance = GetValueFrom(randomBerryChance);
|
||||||
customGameTempData.antiBerryChance = antiBerryChance;
|
customGameTempData.antiBerryChance = GetValueFrom(antiBerryChance);
|
||||||
customGameTempData.nothingBerryChance = nothingBerryChance;
|
customGameTempData.nothingBerryChance = GetValueFrom(nothingBerryChance);
|
||||||
await SceneManager.LoadSceneAsync("CustomGamePlayer");
|
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()
|
void ValidateTotal()
|
||||||
@@ -163,14 +195,14 @@ public class PlayMenu : MonoBehaviour
|
|||||||
customPlayButton.interactable = false;
|
customPlayButton.interactable = false;
|
||||||
customNormalizeButton.interactable = false;
|
customNormalizeButton.interactable = false;
|
||||||
float total = 0f;
|
float total = 0f;
|
||||||
total += normalBerryChance;
|
total += GetValueFrom(normalBerryChance);
|
||||||
total += poisonBerryChance;
|
total += GetValueFrom(poisonBerryChance);
|
||||||
total += slowBerryChance;
|
total += GetValueFrom(slowBerryChance);
|
||||||
total += ultraBerryChance;
|
total += GetValueFrom(ultraBerryChance);
|
||||||
total += speedyBerryChance;
|
total += GetValueFrom(speedyBerryChance);
|
||||||
total += randomBerryChance;
|
total += GetValueFrom(randomBerryChance);
|
||||||
total += antiBerryChance;
|
total += GetValueFrom(antiBerryChance);
|
||||||
total += nothingBerryChance;
|
total += GetValueFrom(nothingBerryChance);
|
||||||
if (total == 100f)
|
if (total == 100f)
|
||||||
{
|
{
|
||||||
customBackButton.interactable = true;
|
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()
|
async void Update()
|
||||||
{
|
{
|
||||||
if (Keyboard.current.escapeKey.wasPressedThisFrame)
|
if (Keyboard.current.escapeKey.wasPressedThisFrame)
|
||||||
|
|||||||
Reference in New Issue
Block a user