fixed options, fixed save, new Screenshots, v.140
This commit is contained in:
@@ -27,7 +27,6 @@ public class AudioHandler : MonoBehaviour
|
||||
{
|
||||
cameraAudio = GameObject.Find("Main Camera").GetComponent<AudioSource>();
|
||||
playerAudio = GameObject.Find("Player").GetComponent<AudioSource>();
|
||||
loadAudioSettings();
|
||||
}
|
||||
|
||||
public void playButtonClick()
|
||||
@@ -114,15 +113,13 @@ public class AudioHandler : MonoBehaviour
|
||||
GameObject.Find("slideMusic").GetComponent<Slider>().value = cameraAudio.volume;
|
||||
}
|
||||
|
||||
public void loadAudioSettings()
|
||||
{
|
||||
FileHandler.loadAudio(filepath, cameraAudio, playerAudio);
|
||||
}
|
||||
|
||||
public void saveAudioSettings()
|
||||
public string saveAudioSettings()
|
||||
{
|
||||
string result = "";
|
||||
float music = GameObject.Find("slideMusic").GetComponent<Slider>().value;
|
||||
float effects = GameObject.Find("slideEffects").GetComponent<Slider>().value;
|
||||
FileHandler.saveAudio(filepath, music, effects);
|
||||
result = result + "Music:" + music + "\r\n";
|
||||
result = result + "Effects:" + effects;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ namespace Assets.Scripts
|
||||
|
||||
public void closeOptions()
|
||||
{
|
||||
audioHandler.loadAudioSettings();
|
||||
audioHandler.playButtonClick();
|
||||
uihandler.closeOptions();
|
||||
}
|
||||
@@ -83,9 +82,13 @@ namespace Assets.Scripts
|
||||
|
||||
public void saveOptions()
|
||||
{
|
||||
string saveText = "";
|
||||
audioHandler.playButtonClick();
|
||||
uihandler.adaptScreen();
|
||||
audioHandler.saveAudioSettings();
|
||||
saveText = saveText + uihandler.saveVideoSettings() + "\r\n";
|
||||
saveText = saveText + audioHandler.saveAudioSettings() + "\r\n";
|
||||
GameObject.Find("Main Camera").GetComponent<PlayerCamera>().speed = GameObject.Find("slideSensitivity").GetComponent<Slider>().value;
|
||||
saveText = saveText + "Sensitivity:"+GameObject.Find("slideSensitivity").GetComponent<Slider>().value;
|
||||
FileHandler.saveOptions(saveText);
|
||||
uihandler.closeOptions();
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ namespace Assets.Scripts
|
||||
public class FileHandler
|
||||
{
|
||||
static StreamWriter sw;
|
||||
static string settingsPath = "./settings.txt";
|
||||
public static void saveGame(string data, string path)
|
||||
{
|
||||
sw = new StreamWriter(path);
|
||||
@@ -40,31 +41,90 @@ namespace Assets.Scripts
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveAudio(string path, float music, float effects)
|
||||
{
|
||||
sw = new StreamWriter(path);
|
||||
sw.WriteLine("Music:" + music);
|
||||
sw.WriteLine("Effects:" + effects);
|
||||
public static void saveOptions(string saveText){
|
||||
sw = new StreamWriter(settingsPath);
|
||||
sw.Write(saveText);
|
||||
sw.Flush();
|
||||
sw.Close();
|
||||
}
|
||||
|
||||
public static void loadAudio(string path, AudioSource cameraAudio, AudioSource playerAudio)
|
||||
{
|
||||
if (File.Exists(path))
|
||||
public static void loadOptions(bool isIngame){
|
||||
if (!File.Exists(settingsPath))
|
||||
{
|
||||
string[] lines = File.ReadAllLines(path);
|
||||
cameraAudio.volume = float.Parse(lines[0].Split(':')[1]);
|
||||
playerAudio.volume = float.Parse(lines[1].Split(':')[1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
sw = File.CreateText(path);
|
||||
sw = File.CreateText(settingsPath);
|
||||
sw.WriteLine("Music:0.5");
|
||||
sw.WriteLine("Effects:0.5");
|
||||
sw.WriteLine("Resolution:0");
|
||||
sw.WriteLine("Mode:0");
|
||||
sw.WriteLine("Sensitivity:1");
|
||||
sw.Flush();
|
||||
sw.Close();
|
||||
}
|
||||
string[] lines = File.ReadAllLines(settingsPath);
|
||||
foreach(string line in lines){
|
||||
switch(line.Split(":")[0]){
|
||||
case "Music":
|
||||
GameObject.Find("Main Camera").GetComponent<AudioSource>().volume = float.Parse(line.Split(':')[1]);
|
||||
break;
|
||||
case "Effects":
|
||||
GameObject.Find("Player").GetComponent<AudioSource>().volume = float.Parse(line.Split(':')[1]);
|
||||
break;
|
||||
case "Resolution":
|
||||
switch(line.Split(":")[1].ToLower()){
|
||||
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;
|
||||
}
|
||||
break;
|
||||
case "Mode":
|
||||
switch(line.Split(":")[1].ToLower()){
|
||||
case "0":
|
||||
Screen.fullScreenMode = FullScreenMode.Windowed;
|
||||
break;
|
||||
case "1":
|
||||
Screen.fullScreenMode = FullScreenMode.ExclusiveFullScreen;
|
||||
break;
|
||||
case "2":
|
||||
Screen.fullScreenMode = FullScreenMode.FullScreenWindow;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "Sensitivity":
|
||||
if(isIngame){
|
||||
GameObject.Find("Main Camera").GetComponent<PlayerCamera>().speed = float.Parse(line.Split(':')[1]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void loadOptionDisplay(){
|
||||
string[] lines = File.ReadAllLines(settingsPath);
|
||||
foreach(string line in lines){
|
||||
switch(line.Split(":")[0]){
|
||||
case "Music":
|
||||
GameObject.Find("slideMusic").GetComponent<Slider>().value = float.Parse(line.Split(':')[1]);
|
||||
break;
|
||||
case "Effects":
|
||||
GameObject.Find("slideEffects").GetComponent<Slider>().value = float.Parse(line.Split(':')[1]);
|
||||
break;
|
||||
case "Resolution":
|
||||
GameObject.Find("dropResolution").GetComponent<Dropdown>().value = int.Parse(line.Split(':')[1]);
|
||||
break;
|
||||
case "Mode":
|
||||
GameObject.Find("dropMode").GetComponent<Dropdown>().value = int.Parse(line.Split(':')[1]);
|
||||
break;
|
||||
case "Sensitivity":
|
||||
GameObject.Find("slideSensitivity").GetComponent<Slider>().value = float.Parse(line.Split(':')[1]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static string generateJSON(string key, object value)
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Assets.Scripts
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
FileHandler.loadOptions(true);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
@@ -88,6 +88,15 @@ namespace Assets.Scripts
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool canPlayerRotate()
|
||||
{
|
||||
if (state == UIState.GAME)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool isPlayerInFight()
|
||||
{
|
||||
return state == UIState.FIGHT;
|
||||
@@ -116,7 +125,7 @@ namespace Assets.Scripts
|
||||
public void openOptions()
|
||||
{
|
||||
options.SetActive(true);
|
||||
GameObject.Find("AudioHandler").GetComponent<AudioHandler>().setSlider();
|
||||
FileHandler.loadOptionDisplay();
|
||||
hideOtherElements(options);
|
||||
state = UIState.PAUSEOPTIONS;
|
||||
GameObject.Find("ScrollbarOptions").GetComponent<Scrollbar>().value = 1f;
|
||||
@@ -243,21 +252,20 @@ namespace Assets.Scripts
|
||||
showHUD();
|
||||
}
|
||||
|
||||
public void adaptScreen()
|
||||
{
|
||||
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);
|
||||
Screen.SetResolution(800, 600, Screen.fullScreenMode);
|
||||
break;
|
||||
case 1:
|
||||
Screen.SetResolution(1280, 800, Screen.fullScreenMode);
|
||||
break;
|
||||
case 2:
|
||||
Screen.SetResolution(1920,1080, Screen.fullScreenMode);
|
||||
Screen.SetResolution(1920, 1080, Screen.fullScreenMode);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -282,6 +290,9 @@ namespace Assets.Scripts
|
||||
}
|
||||
break;
|
||||
}
|
||||
result = result + "Resolution:"+resolution.GetComponent<Dropdown>().value+"\r\n";
|
||||
result = result + "Mode:"+mode.GetComponent<Dropdown>().value;
|
||||
return result;
|
||||
}
|
||||
|
||||
public void openPauseMenu()
|
||||
@@ -442,29 +453,25 @@ namespace Assets.Scripts
|
||||
|
||||
private void updateHealthUI(int health, int maxHealth)
|
||||
{
|
||||
GameObject foreground = GameObject.Find("healthForegroundInformation");
|
||||
GameObject background = GameObject.Find("healthBackgroundInformation");
|
||||
GameObject fill = GameObject.Find("pnlHealthBar");
|
||||
GameObject text = GameObject.Find("healthTextInformation");
|
||||
|
||||
updateBar(foreground, background, text, maxHealth, health);
|
||||
updateFill(fill, text, maxHealth, health);
|
||||
}
|
||||
|
||||
private void updateSecondaryUI(int secondary, int maxSecondary)
|
||||
{
|
||||
GameObject foreground = GameObject.Find("secondaryForegroundInformation");
|
||||
GameObject background = GameObject.Find("secondaryBackgroundInformation");
|
||||
GameObject fill = GameObject.Find("pnlSecondaryBar");
|
||||
GameObject text = GameObject.Find("secondaryTextInformation");
|
||||
|
||||
updateBar(foreground, background, text, maxSecondary, secondary);
|
||||
updateFill(fill, text, maxSecondary, secondary);
|
||||
}
|
||||
|
||||
private void updateExperienceUI(int experience, int maxExperience)
|
||||
{
|
||||
GameObject foreground = GameObject.Find("experienceForeground");
|
||||
GameObject background = GameObject.Find("experienceBackground");
|
||||
GameObject text = GameObject.Find("experienceText");
|
||||
GameObject fill = GameObject.Find("pnlExperience");
|
||||
|
||||
updateBar(foreground, background, text, maxExperience, experience);
|
||||
updateFill(fill, null, maxExperience, experience);
|
||||
}
|
||||
|
||||
public void updateHUD(Player player)
|
||||
@@ -476,13 +483,11 @@ namespace Assets.Scripts
|
||||
GameObject information = GameObject.Find("txtInformationHUD");
|
||||
player.updateNameHUD(information.GetComponent<Text>());
|
||||
|
||||
GameObject foreground = GameObject.Find("healthForegroundHUD");
|
||||
GameObject background = GameObject.Find("healthBackgroundHUD");
|
||||
updateBar(foreground, background, null, playerStats[1] + equipment["HP"], playerStats[0]);
|
||||
GameObject fill = GameObject.Find("HUD_healthFill");
|
||||
updateFill(fill, null, playerStats[1] + equipment["HP"], playerStats[0]);
|
||||
|
||||
foreground = GameObject.Find("secondaryForegroundHUD");
|
||||
background = GameObject.Find("secondaryBackgroundHUD");
|
||||
updateBar(foreground, background, null, playerStats[3] + equipment["MP"], playerStats[2]);
|
||||
fill = GameObject.Find("HUD_secondaryFill");
|
||||
updateFill(fill, null, playerStats[3] + equipment["MP"], playerStats[2]);
|
||||
}
|
||||
|
||||
public void updateBar(GameObject bar, GameObject barBackground, GameObject textField, int maxValue, int minValue)
|
||||
@@ -503,6 +508,22 @@ namespace Assets.Scripts
|
||||
bar.GetComponent<RectTransform>().offsetMax = new Vector2(-change, bar.GetComponent<RectTransform>().offsetMax.y);
|
||||
}
|
||||
|
||||
public void updateFill(GameObject fill, GameObject textField, int maxValue, int minValue)
|
||||
{
|
||||
string text = minValue + "/" + maxValue;
|
||||
float percentage = 0;
|
||||
if (maxValue > 0)
|
||||
{
|
||||
percentage = (1 / (float)maxValue) * minValue;
|
||||
}
|
||||
|
||||
if (textField != null)
|
||||
{
|
||||
textField.GetComponent<Text>().text = text;
|
||||
}
|
||||
fill.GetComponent<Image>().fillAmount = percentage;
|
||||
}
|
||||
|
||||
public void openIntroduction()
|
||||
{
|
||||
GameObject.Find("AudioHandler").GetComponent<AudioHandler>().Start();
|
||||
|
||||
Reference in New Issue
Block a user