Files
TalesOfNovariel/Assets/Scripts/Menu/UIHandlerMenu.cs
2026-01-25 12:49:13 +01:00

241 lines
9.5 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();
}
private void setPlayerInformation()
{
string name = GameObject.Find("inName").GetComponent<InputField>().text;
int role = GameObject.Find("dropClass").GetComponent<Dropdown>().value;
int race = GameObject.Find("dropRace").GetComponent<Dropdown>().value;
BasicRace playerRace = new BasicRace();
BasicClass playerClass = new ThiefClass();
switch (role)
{
case 0:
playerClass = new WarriorClass();
break;
case 1:
playerClass = new MageClass();
break;
case 2:
playerClass = new ThiefClass();
break;
}
switch (race)
{
case 0:
playerRace = new HumanRace();
break;
case 1:
playerRace = new ElvenRace();
break;
case 2:
playerRace = new DwarvenRace();
break;
case 3:
playerRace = new GoblinRace();
break;
case 4:
playerRace = new GiantRace();
break;
case 5:
playerRace = new NightelfRace();
break;
}
GameObject.Find("Player").GetComponent<PlayerGameObject>().generatePlayer(playerRace, playerClass, name, GameObject.Find("dropDifficulty").GetComponent<Dropdown>().value);
}
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();
EventSystem.current.SetSelectedGameObject(GameObject.Find("btnAudio"));
showOptionView("audio");
}
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 updateCreationInformation()
{
setPlayerInformation();
// health, maxHealth, secondary, maxSecondary, strength, dexterity, intelligence, level, experience, maxExperience, points
PlayerGameObject player = GameObject.Find("Player").GetComponent<PlayerGameObject>();
GameObject.Find("txtStrength_Creation").GetComponent<Text>().text = TextHandler.getText("strength") + " " + player.getPlayerStat("Strength").getAmount();
GameObject.Find("txtDexterity_Creation").GetComponent<Text>().text = TextHandler.getText("dexterity") + " " + player.getPlayerStat("Dexterity").getAmount();
GameObject.Find("txtIntelligence_Creation").GetComponent<Text>().text = TextHandler.getText("intelligence") + " " + player.getPlayerStat("Intelligence").getAmount();
GameObject.Find("txtHealth_Creation").GetComponent<Text>().text = TextHandler.getText("health") + " " + player.getPlayerStat("MaxHealth").getAmount();
GameObject.Find("txtSecondary_Creation").GetComponent<Text>().text = "Mana: " + player.getPlayerStat("MaxSecondary").getAmount();
}
public void loadGame(SceneHandler sceneHandler)
{
PlayerPrefs.SetInt("isLoad", 1);
sceneHandler.openGameScene();
}
public bool isCharacterCreation()
{
return characterCreation.activeSelf;
}
public void showOptionView(string key)
{
GameObject optionContent = GameObject.Find("pnlContent");
for (int i = 0; i < optionContent.transform.childCount; i++)
{
if (optionContent.transform.GetChild(i).name.ToLower().Contains(key))
{
optionContent.transform.GetChild(i).transform.localScale = new Vector3(1, 1, 1);
}
else
{
optionContent.transform.GetChild(i).transform.localScale = new Vector3(0, 0, 0);
}
}
}
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;
}
}
}
}