Projet-IA-Madelaine/Scripts/MainMenuUI/MenuController.cs
2024-06-12 21:03:42 +02:00

257 lines
8.4 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using TMPro;
using Unity.VisualScripting;
public class MenuController : MonoBehaviour
{
[Header("Play Button")]
[SerializeField] Button playerButton;
[Header("Player Selection Settings")]
[SerializeField] Toggle omnicientBotToggler = null;
[SerializeField] Toggle observerBotToggler = null;
[SerializeField] Toggle iteratorBotToggler = null;
[SerializeField] Toggle humanPlayerToggler = null;
[Header("Level Settings")]
[SerializeField] Toggle laserToggler = null;
[SerializeField] Toggle missileToggler = null;
[SerializeField] Toggle coinToggler = null;
[SerializeField] Toggle badCoinToggler = null;
[SerializeField] Toggle surviveScoreToggler = null;
[Header("Seed Settings")]
[SerializeField] Toggle changeSeedToggler = null;
[SerializeField] Toggle useDefaultSeedToggler = null;
[SerializeField] TMP_InputField defaultSeedInputField = null;
[SerializeField] TMP_InputField customSeedInputField = null;
[Header("Session Settings")]
[SerializeField] Slider maxSpeedSlider = null;
[SerializeField] Slider startSpeedSlider = null;
[SerializeField] Slider difficultyMultiplyerSlider = null;
[SerializeField] Toggle rushModeToggler = null;
[SerializeField] TMP_InputField maxTryInputField = null;
[SerializeField] TMP_InputField maxTimeInputField = null;
[SerializeField] TMP_InputField maxDistanceInputField = null;
[Header("Menu Controller")]
public string _statsScene;
public string _playScene;
private void Start()
{
Time.timeScale = 1;
SetMaxSpeed();
SetStartSpeed();
SetDifficultyMultiplyer();
SetRushModeToggle();
SetMaxTry();
SetMaxTime();
SetMaxDistance();
SetChangeSeed();
SetUseDefaultSeed();
SetDefaultSeedValue();
SetCustomSeedValue();
SetLaserToggle();
SetMissileToggle();
SetCoinToggle();
SetBadCoinToggle();
SetSurviveScoreToggle();
SetOmnicientBotSelected();
SetObserverBotSelected();
SetIteratorBotSelected();
SetHumanPlayerSelected();
}
public void StatsButtonClicked()
{
Debug.Log("=============================================");
SceneManager.LoadScene(_statsScene);
}
public void PlayButtonClicked()
{
Debug.Log("=============================================");
SceneManager.LoadScene(_playScene);
}
void OnPlayerSelectionChanged()
{
bool omnicient = omnicientBotToggler.isOn;
bool observer = observerBotToggler.isOn;
bool iterator = iteratorBotToggler.isOn;
bool human = humanPlayerToggler.isOn;
playerButton.interactable = (omnicient || observer || iterator || human);
}
public void QuitButtonClicked()
{
Debug.Log("Game quitting");
Application.Quit();
}
// Session Rules
public void SetMaxSpeed()
{
float speed = maxSpeedSlider.value;
PlayerPrefs.SetFloat(Settings.MaxSpeedSettingValue, speed);
Debug.Log($"Game's max speed is set to {speed}");
}
public void SetStartSpeed()
{
float speed = startSpeedSlider.value;
PlayerPrefs.SetFloat(Settings.StartSpeedSettingValue, speed);
Debug.Log($"Game's starting speed is set to {speed}");
}
public void SetDifficultyMultiplyer()
{
float value = difficultyMultiplyerSlider.value;
PlayerPrefs.SetFloat(Settings.DifficultyMultiplierSettingValue, value);
Debug.Log($"Game's difficulty multiplyer is set to {value}");
}
public void SetRushModeToggle()
{
bool toggle = rushModeToggler.isOn;
PlayerPrefs.SetString(Settings.RushModeSettingToggle, toggle.ToString());
Debug.Log($"Rush Mode has been toggeled to {toggle}");
}
public void SetMaxTry()
{
int value = 0;
string text = maxTryInputField.text;
if (text != "")
{
value = int.Parse(text);
}
PlayerPrefs.SetInt(Settings.MaxTrySettingValue, value);
Debug.Log($"Game's maximum try count is set to {value}");
}
public void SetMaxTime()
{
int seconds = 0;
string text = maxTimeInputField.text;
if (text != "")
{
seconds = int.Parse(text);
}
PlayerPrefs.SetInt(Settings.MaxTimeSettingValue, seconds);
Debug.Log($"Game's session maximum time is set to {seconds} seconds");
}
public void SetMaxDistance()
{
int distance = 0;
string text = maxDistanceInputField.text;
if (text != "")
{
distance = int.Parse(text);
}
PlayerPrefs.SetFloat(Settings.MaxDistanceSettingValue, distance);
Debug.Log($"Level's max distance is set to {distance} units");
}
// Seed Rules
public void SetChangeSeed()
{
bool toggle = changeSeedToggler.isOn;
PlayerPrefs.SetString(Settings.ChangeSeedSetting, toggle.ToString());
Debug.Log($"Changing seed for each level is set to {toggle}");
}
public void SetUseDefaultSeed()
{
bool toggle = useDefaultSeedToggler.isOn;
PlayerPrefs.SetString(Settings.UseDefaultSeedSetting, toggle.ToString());
Debug.Log($"Usign default seed is set to {toggle}");
}
public void SetDefaultSeedValue()
{
int value = 0;
string text = defaultSeedInputField.text;
if(text != "")
{
value = int.Parse(text);
}
PlayerPrefs.SetInt(Settings.DefaultSeedSettingValue, value);
Debug.Log($"Default seed has been set to {value}");
}
public void SetCustomSeedValue()
{
int value = 0;
string text = customSeedInputField.text;
if (text != "")
{
value = int.Parse(text);
}
PlayerPrefs.SetInt(Settings.CustomSeedSettingValue, value);
Debug.Log($"Custom seed has been set to {value}");
}
// Level Rules
public void SetLaserToggle()
{
bool toggle = laserToggler.isOn;
PlayerPrefs.SetString(Settings.LaserSettingToggle, toggle.ToString());
Debug.Log($"Laser have been toggeled to {toggle}");
}
public void SetMissileToggle()
{
bool toggle = missileToggler.isOn;
PlayerPrefs.SetString(Settings.MissileSettingToggle, toggle.ToString());
Debug.Log($"Missiles have been toggeled to {toggle}");
}
public void SetCoinToggle()
{
bool toggle = coinToggler.isOn;
PlayerPrefs.SetString(Settings.CoinSettingToggle, toggle.ToString());
Debug.Log($"Coins have been toggeled to {toggle}");
}
public void SetBadCoinToggle()
{
bool toggle = badCoinToggler.isOn;
PlayerPrefs.SetString(Settings.BadCoinSettingToggle, toggle.ToString());
Debug.Log($"Bad Coins have been toggeled to {toggle}");
}
public void SetSurviveScoreToggle()
{
bool toggle = surviveScoreToggler.isOn;
PlayerPrefs.SetString(Settings.SurviveScoreSettingToggle, toggle.ToString());
Debug.Log($"Increasing score with surviving time has been toggeled to {toggle}");
}
// Player Selection
public void SetOmnicientBotSelected()
{
bool toggle = omnicientBotToggler.isOn;
PlayerPrefs.SetString(Settings.OmnicientBotSelected, toggle.ToString());
OnPlayerSelectionChanged();
Debug.Log($"Omnicient bot selected has been set to {toggle}");
}
public void SetObserverBotSelected()
{
bool toggle = observerBotToggler.isOn;
PlayerPrefs.SetString(Settings.ObserverBotSelected, toggle.ToString());
OnPlayerSelectionChanged();
Debug.Log($"Observer bot selected has been set to {toggle}");
}
public void SetIteratorBotSelected()
{
bool toggle = iteratorBotToggler.isOn;
PlayerPrefs.SetString(Settings.IteratorBotSelected, toggle.ToString());
OnPlayerSelectionChanged();
Debug.Log($"Iterator bot selected has been set to {toggle}");
}
public void SetHumanPlayerSelected()
{
bool toggle = humanPlayerToggler.isOn;
PlayerPrefs.SetString(Settings.HumanPlayerSelected, toggle.ToString());
OnPlayerSelectionChanged();
Debug.Log($"Human player selected has been set to {toggle}");
}
}