TalesOfNovariel/Assets/Scripts/Menu/UIHandlerMenu.cs
2023-04-14 20:25:54 +02:00

182 lines
6.6 KiB
C#

using Assets.Scripts.Classes;
using Assets.Scripts.Races;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
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()
{
options.SetActive(false);
characterCreation.SetActive(false);
mainMenu.SetActive(true);
SteamWorksHandler.getStandardAchievement("StartAchievement");
}
public void startGame(SceneHandler sceneHandler)
{
int cityAmount = 0;
switch (GameObject.Find("dropSize").GetComponent<Dropdown>().value)
{
case 0:
cityAmount = 5;
break;
case 1:
cityAmount = 10;
break;
case 2:
cityAmount = 20;
break;
case 3:
cityAmount = 40;
break;
}
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);
SteamWorksHandler.getStandardAchievement("CharAchievement");
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 BasicClass();
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;
}
GameObject.Find("Player").GetComponent<Player>().generatePlayer(playerRace, playerClass, name, GameObject.Find("dropDifficulty").GetComponent<Dropdown>().value);
}
public void openCharacterCreation()
{
characterCreation.SetActive(true);
mainMenu.SetActive(false);
}
public void closeCharacterCreation()
{
characterCreation.SetActive(false);
mainMenu.SetActive(true);
}
public void openOptions()
{
options.SetActive(true);
mainMenu.SetActive(false);
GameObject.Find("AudioHandler").GetComponent<AudioHandler>().setSlider();
GameObject.Find("ScrollbarOptions").GetComponent<Scrollbar>().value = 1f;
}
public void closeOptions()
{
options.SetActive(false);
mainMenu.SetActive(true);
}
public void adaptScreen()
{
GameObject resolution = GameObject.Find("dropResolution");
GameObject mode = GameObject.Find("dropMode");
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;
}
}
public void updateCreationInformation()
{
setPlayerInformation();
// health, maxHealth, secondary, maxSecondary, strength, dexterity, intelligence, level, experience, maxExperience, points
int[] playerstats = GameObject.Find("Player").GetComponent<Player>().getStats();
GameObject.Find("txtStrength_Creation").GetComponent<Text>().text = "Strength: " + playerstats[4];
GameObject.Find("txtDexterity_Creation").GetComponent<Text>().text = "Dexterity: " + playerstats[5];
GameObject.Find("txtIntelligence_Creation").GetComponent<Text>().text = "Intelligence: " + playerstats[6];
GameObject.Find("txtHealth_Creation").GetComponent<Text>().text = "Health: " + playerstats[1];
GameObject.Find("txtSecondary_Creation").GetComponent<Text>().text = "Mana: " + playerstats[3];
}
public void loadGame(SceneHandler sceneHandler)
{
PlayerPrefs.SetInt("isLoad", 1);
sceneHandler.openGameScene();
}
}
}