Files
TalesOfNovariel/Assets/Scripts/Menu/UIHandlerMenu.cs

165 lines
6.0 KiB
C#

using Assets.Scripts.Classes;
using Assets.Scripts.Player;
using Assets.Scripts.Races;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Localization.Settings;
using UnityEngine.UI;
namespace Assets.Scripts.Menu
{
public class UIHandlerMenu : MonoBehaviour
{
public GameObject mainMenu;
public GameObject options;
public GameObject characterCreation;
// Start is called before the first frame update
void Start()
{
FileHandler.loadOptions(false);
options.transform.localScale = new Vector3(0, 0, 0);
characterCreation.transform.localScale = new Vector3(0, 0, 0);
SteamWorksHandler.getFirstPlayAchievement();
EventSystem.current.SetSelectedGameObject(GameObject.Find("btnStart"));
}
public void startGame(SceneHandler sceneHandler)
{
int cityAmount = GameObject.Find("dropSize").GetComponent<Dropdown>().value * 5 + 5;
PlayerPrefs.SetInt("cityAmount", cityAmount);
PlayerPrefs.SetInt("class", GameObject.Find("dropClass").GetComponent<Dropdown>().value);
PlayerPrefs.SetInt("race", GameObject.Find("dropRace").GetComponent<Dropdown>().value);
PlayerPrefs.SetString("playername", GameObject.Find("inName").GetComponent<InputField>().text);
PlayerPrefs.SetInt("difficulty", GameObject.Find("dropDifficulty").GetComponent<Dropdown>().value);
PlayerPrefs.SetInt("isLoad", 0);
sceneHandler.openGameScene();
}
public void openCharacterCreation()
{
options.transform.localScale = new Vector3(0, 0, 0);
characterCreation.transform.localScale = new Vector3(1, 1, 1);
EventSystem.current.SetSelectedGameObject(GameObject.Find("inName"));
}
public void closeCharacterCreation()
{
options.transform.localScale = new Vector3(0, 0, 0);
characterCreation.transform.localScale = new Vector3(0, 0, 0);
EventSystem.current.SetSelectedGameObject(GameObject.Find("btnStart"));
}
public void openOptions()
{
options.transform.localScale = new Vector3(1, 1, 1);
characterCreation.transform.localScale = new Vector3(0, 0, 0);
FileHandler.loadOptionDisplay();
}
public void closeOptions()
{
options.transform.localScale = new Vector3(0, 0, 0);
characterCreation.transform.localScale = new Vector3(0, 0, 0);
EventSystem.current.SetSelectedGameObject(GameObject.Find("btnStart"));
}
public string saveVideoSettings()
{
GameObject resolution = GameObject.Find("dropResolution");
GameObject mode = GameObject.Find("dropMode");
string result = "";
switch (resolution.GetComponent<Dropdown>().value)
{
case 0:
Screen.SetResolution(800, 600, Screen.fullScreenMode);
break;
case 1:
Screen.SetResolution(1280, 800, Screen.fullScreenMode);
break;
case 2:
Screen.SetResolution(1920, 1080, Screen.fullScreenMode);
break;
}
switch (mode.GetComponent<Dropdown>().value)
{
case 0:
if (Screen.fullScreenMode != FullScreenMode.Windowed)
{
Screen.fullScreenMode = FullScreenMode.Windowed;
}
break;
case 1:
if (Screen.fullScreenMode != FullScreenMode.ExclusiveFullScreen)
{
Screen.fullScreenMode = FullScreenMode.ExclusiveFullScreen;
}
break;
case 2:
if (Screen.fullScreenMode != FullScreenMode.FullScreenWindow)
{
Screen.fullScreenMode = FullScreenMode.FullScreenWindow;
}
break;
}
result = result + "Resolution:" + resolution.GetComponent<Dropdown>().value + "\r\n";
result = result + "Mode:" + mode.GetComponent<Dropdown>().value;
return result;
}
public string saveLanguage()
{
GameObject language = GameObject.Find("dropLanguage");
string result = "";
switch (language.GetComponent<Dropdown>().value)
{
case 0:
result = "de";
break;
case 1:
result = "en";
break;
}
result = "Language:" + result;
return result;
}
public string saveAudioSettings()
{
string result = "";
float music = GameObject.Find("slideMusic").GetComponent<Slider>().value;
float effects = GameObject.Find("slideEffects").GetComponent<Slider>().value;
result = result + "Music:" + music + "\r\n";
result = result + "Effects:" + effects;
return result;
}
public void loadGame(SceneHandler sceneHandler)
{
PlayerPrefs.SetInt("isLoad", 1);
sceneHandler.openGameScene();
}
public bool isCharacterCreation()
{
return characterCreation.activeSelf;
}
public void switchLanguage()
{
GameObject language = GameObject.Find("dropLanguage");
switch (language.GetComponent<Dropdown>().value)
{
case 0:
LocalizationSettings.SelectedLocale = LocalizationSettings.AvailableLocales.GetLocale("de");
break;
case 1:
LocalizationSettings.SelectedLocale = LocalizationSettings.AvailableLocales.GetLocale("en");
break;
}
}
}
}