void UpdateResourceAlertVariables() { ResourceAlert currentAlert = DangerAlertList.Instance.ResourceAlertList[resourceIndex]; resourceName = currentAlert.ResourceString; resourceEnabled = currentAlert.Enabled; resourcePercentage = currentAlert.Percentage.ToString(); }
void ShowResourceGUI() { buttonStyle = new GUIStyle(GUI.skin.button); toggleStyle = new GUIStyle(GUI.skin.toggle); textFieldStyle = new GUIStyle(GUI.skin.textField); toDel = null; textFieldStyle.normal.textColor = Color.green; GUILayout.BeginHorizontal(GUILayout.Width(WIDTH)); GUILayout.Label("Descent Warning: "); GUILayout.Label(DangerAlertCore.normalAlert, textFieldStyle, GUILayout.Width(120)); if (GUILayout.Button("<", GUILayout.Width(20))) { int x = dirEntriesList.FindIndex(s => s == DangerAlertCore.normalAlert); if (x == 0) { x = dirEntriesList.Count - 1; } else { x--; } DangerAlertCore.normalAlert = dirEntriesList[x]; } if (GUILayout.Button(">", GUILayout.Width(20))) { int x = dirEntriesList.FindIndex(s => s == DangerAlertCore.normalAlert); if (x == dirEntriesList.Count - 1) { x = 0; } else { x++; } DangerAlertCore.normalAlert = dirEntriesList[x]; } GUILayout.FlexibleSpace(); if (!DangerAlertCore.Instance.soundplayer.SoundPlaying()) //If the sound isn't playing, play the sound. { if (GUILayout.Button("Preview", GUILayout.Width(60))) { DangerAlertCore.Instance.soundplayer.LoadNewSound(DangerAlertCore.SOUND_DIR + DangerAlertCore.normalAlert, true); DangerAlertCore.Instance.soundplayer.PlaySound(true); //Plays sound } } else { if (GUILayout.Button("Stop", GUILayout.Width(60))) { DangerAlertCore.Instance.soundplayer.StopSound(); } } GUILayout.EndHorizontal(); GUILayout.Space(10); GUILayout.BeginHorizontal(GUILayout.Width(WIDTH)); if (GUILayout.Button("Add Resource")) { DangerAlertList.Instance.AddAlert(new ResourceAlert("ElectricCharge", 20, DangerAlertCore.defaultAlert)); resourceIndex = DangerAlertList.Instance.ResourceAlertList.Count - 1; //sets index to last one } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Space(5); GUILayout.Label("Resource", GUILayout.Width(120)); GUILayout.Space(75); GUILayout.Label("Alarm Sound", GUILayout.Width(150)); GUILayout.Space(5 + 120); GUILayout.Label("%", GUILayout.Width(35)); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); scrollPos = GUILayout.BeginScrollView(scrollPos); for (int i = 0; i < DangerAlertList.Instance.ResourceAlertList.Count; i++) { GUILayout.BeginHorizontal(); resourceAlert = DangerAlertList.Instance.ResourceAlertList[i]; if (resourceAlert.Enabled) { buttonStyle.normal.textColor = Color.green; toggleStyle.normal.textColor = Color.green; textFieldStyle.normal.textColor = Color.green; } else { buttonStyle.normal.textColor = Color.red; toggleStyle.normal.textColor = Color.red; textFieldStyle.normal.textColor = Color.red; } GUILayout.Label(resourceAlert.ResourceString, textFieldStyle, GUILayout.Width(120)); if (GUILayout.Button("<", GUILayout.Width(20))) { int x = resourceList.FindIndex(s => s == resourceAlert.ResourceString); if (x == 0) { x = resourceList.Count - 1; } else { x--; } resourceAlert.ResourceString = resourceList[x]; } if (GUILayout.Button(">", GUILayout.Width(20))) { int x = resourceList.FindIndex(s => s == resourceAlert.ResourceString); if (x == resourceList.Count - 1) { x = 0; } else { x++; } resourceAlert.ResourceString = resourceList[x]; } GUILayout.FlexibleSpace(); GUILayout.Label(resourceAlert.alertSound, textFieldStyle, GUILayout.Width(120)); if (GUILayout.Button("<", GUILayout.Width(20))) { int x = dirEntriesList.FindIndex(s => s == resourceAlert.alertSound); if (x == 0) { x = dirEntriesList.Count - 1; } else { x--; } resourceAlert.alertSound = dirEntriesList[x]; } if (GUILayout.Button(">", GUILayout.Width(20))) { int x = dirEntriesList.FindIndex(s => s == resourceAlert.alertSound); if (x == dirEntriesList.Count - 1) { x = 0; } else { x++; } resourceAlert.alertSound = dirEntriesList[x]; } GUILayout.FlexibleSpace(); float f = resourceAlert.Percentage; GUILayout.Label(f.ToString() + "%", GUILayout.Width(35)); f = GUILayout.HorizontalSlider(f, 0f, 99f, GUILayout.Width(100)); resourceAlert.Percentage = (int)f; resourceAlert.Enabled = GUILayout.Toggle(resourceAlert.Enabled, "", toggleStyle); GUILayout.Space(5); if (GUILayout.Button("X", GUILayout.Width(20))) { toDel = resourceAlert; } GUILayout.Space(5); if (!DangerAlertCore.Instance.soundplayer.SoundPlaying()) //If the sound isn't playing, play the sound. { if (GUILayout.Button("Preview", GUILayout.Width(60))) { DangerAlertCore.Instance.soundplayer.LoadNewSound(DangerAlertCore.SOUND_DIR + resourceAlert.alertSound, true); DangerAlertCore.Instance.soundplayer.PlaySound(true); //Plays sound } } else { if (GUILayout.Button("Stop", GUILayout.Width(60))) { DangerAlertCore.Instance.soundplayer.StopSound(); } } GUILayout.EndHorizontal(); } GUILayout.EndScrollView(); if (toDel != null) { DangerAlertList.Instance.ResourceAlertList.Remove(toDel); } GUILayout.BeginHorizontal(); if (GUILayout.Button("Save and Close")) { DangerAlertCore.Instance.soundplayer.LoadNewSound(DangerAlertCore.SOUND_DIR + DangerAlertCore.normalAlert, false); SaveSettings(); GuiOff(); } GUILayout.EndHorizontal(); }