Subversion Repository Public Repository

Nextrek

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
 *
 *	Adventure Creator
 *	by Chris Burton, 2013-2014
 *	
 *	"MenuSlider.cs"
 * 
 *	This MenuElement creates a slider for eg. volume control.
 * 
 */

using UnityEngine;
using AC;

#if UNITY_EDITOR
using UnityEditor;
#endif

public class MenuSlider : MenuElement
{
	
	public string label;
	public bool doOutline;
	public int amount;
	public TextAnchor anchor;
	public Texture2D sliderTexture;
	public AC_SliderType sliderType;

	
	public override void Declare ()
	{
		label = "Slider";
		doOutline = false;
		isVisible = true;
		isClickable = true;
		numSlots = 1;
		amount = 10;
		anchor = TextAnchor.MiddleLeft;
		sliderType = AC_SliderType.CustomScript;
		
		base.Declare ();
	}
	
	
	public void CopySlider (MenuSlider _element)
	{
		label = _element.label;
		doOutline = _element.doOutline;
		amount = _element.amount;
		anchor = _element.anchor;
		sliderTexture = _element.sliderTexture;
		sliderType = _element.sliderType;

		base.Copy (_element);
	}
	
	
	#if UNITY_EDITOR
	
	public override void ShowGUI ()
	{
		EditorGUILayout.BeginVertical ("Button");
			label = EditorGUILayout.TextField ("Label text:", label);
			anchor = (TextAnchor) EditorGUILayout.EnumPopup ("Text alignment:", anchor);
			doOutline = EditorGUILayout.Toggle ("Outline text?", doOutline);
			amount = EditorGUILayout.IntSlider ("Slider value:", amount, 0, 10);
		
			EditorGUILayout.BeginHorizontal ();
				EditorGUILayout.LabelField ("Slider texture:", GUILayout.Width (145f));
				sliderTexture = (Texture2D) EditorGUILayout.ObjectField (sliderTexture, typeof (Texture2D), false, GUILayout.Width (70f), GUILayout.Height (30f));
			EditorGUILayout.EndHorizontal ();
		
			sliderType = (AC_SliderType) EditorGUILayout.EnumPopup ("Slider type:", sliderType);
			if (sliderType == AC_SliderType.CustomScript)
			{
				ShowClipHelp ();
			}
		EditorGUILayout.EndVertical ();
		
		base.ShowGUI ();
	}
	
	#endif
	
	
	public override void Display (GUIStyle _style, int _slot, float zoom)
	{
		base.Display (_style, _slot, zoom);
		
		_style.alignment = anchor;
		if (zoom < 1f)
		{
			_style.fontSize = (int) ((float) _style.fontSize * zoom);
		}
		
		if (doOutline)
		{
			AdvGame.DrawTextOutline (ZoomRect (relativeRect, zoom), TranslateLabel (label), _style, Color.black, _style.normal.textColor, 2);
		}
		else
		{
			GUI.Label (ZoomRect (relativeRect, zoom), TranslateLabel (label), _style);
		}
		
		if (sliderTexture)
		{
			Rect sliderRect = relativeRect;
			sliderRect.x = relativeRect.x + (relativeRect.width / 2);
			sliderRect.width = slotSize.x / 100 * AdvGame.GetMainGameViewSize ().x * (float) amount / 10 * 0.5f;
			GUI.DrawTexture (ZoomRect (sliderRect, zoom), sliderTexture, ScaleMode.StretchToFill, true, 0f);
		}
	}


	public override string GetLabel (int slot)
	{
		return TranslateLabel (label);
	}
	
	
	public void Change ()
	{
		amount ++; 
		
		if (amount > 10)
		{
			amount = 0;
		}
		
		if (sliderType != AC_SliderType.CustomScript)
		{
			if (GameObject.FindWithTag (Tags.persistentEngine) && GameObject.FindWithTag (Tags.persistentEngine).GetComponent <Options>())
			{
				Options options = GameObject.FindWithTag (Tags.persistentEngine).GetComponent <Options>();
				
				if (sliderType == AC_SliderType.Speech)
				{
					options.optionsData.speechVolume = amount;
				}
				else if (sliderType == AC_SliderType.Music)
				{
					options.optionsData.musicVolume = amount;
					options.SetVolume (SoundType.Music);
				}
				else if (sliderType == AC_SliderType.SFX)
				{
					options.optionsData.sfxVolume = amount;
					options.SetVolume (SoundType.SFX);
				}		
				
				options.SavePrefs ();
			}
			else
			{
				Debug.LogWarning ("Could not find Options data!");
			}
		}
	}
	
	
	public override void RecalculateSize ()
	{
		if (Application.isPlaying && sliderType != AC_SliderType.CustomScript)
		{
			if (GameObject.FindWithTag (Tags.persistentEngine) && GameObject.FindWithTag (Tags.persistentEngine).GetComponent <Options>())
			{	
				Options options = GameObject.FindWithTag (Tags.persistentEngine).GetComponent <Options>();
				
				if (sliderType == AC_SliderType.Speech)
				{
					amount = options.optionsData.speechVolume;
				}
				else if (sliderType == AC_SliderType.Music)
				{
					amount = options.optionsData.musicVolume;
				}
				else if (sliderType == AC_SliderType.SFX)
				{
					amount = options.optionsData.sfxVolume;
				}
			}
		}
		
		base.RecalculateSize ();
	}
	
	
	protected override void AutoSize ()
	{
		AutoSize (new GUIContent (TranslateLabel (label)));
	}

}

Commits for Nextrek/SpaceCrew/SpaceCrew/Assets/AdventureCreator/Scripts/Menu/Menu classes/MenuSlider.cs

Diff revisions: vs.
Revision Author Commited Message
83 FMMortaroli picture FMMortaroli Tue 13 May, 2014 11:32:51 +0000