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
/*
 *
 *	Adventure Creator
 *	by Chris Burton, 2013-2014
 *	
 *	"MenuToggle.cs"
 * 
 *	This MenuElement toggles between On and Off when clicked on.
 *	It can be used for changing boolean options.
 * 
 */

using UnityEngine;
using AC;

#if UNITY_EDITOR
using UnityEditor;
#endif

public class MenuToggle : MenuElement
{

	public string label;
	public bool isOn;
	public bool doOutline;
	public TextAnchor anchor;
	public AC_ToggleType toggleType;
	
	
	public override void Declare ()
	{
		label = "Toggle";
		isOn = false;
		isVisible = true;
		isClickable = true;
		toggleType = AC_ToggleType.CustomScript;
		numSlots = 1;
		SetSize (new Vector2 (15f, 5f));
		anchor = TextAnchor.MiddleLeft;
		
		base.Declare ();
	}
	
	
	public void CopyToggle (MenuToggle _element)
	{
		label = _element.label;
		isOn = _element.isOn;
		doOutline = _element.doOutline;
		anchor = _element.anchor;
		toggleType = _element.toggleType;
		
		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);
			isOn = EditorGUILayout.Toggle ("Is on?", isOn);
		
			toggleType = (AC_ToggleType) EditorGUILayout.EnumPopup ("Toggle type:", toggleType);
			if (toggleType == AC_ToggleType.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);
		}
		
		string toggleText = TranslateLabel (label) + " : ";
		if (isOn)
		{
			toggleText += "On";
		}
		else
		{
			toggleText += "Off";
		}
		
		if (doOutline)
		{
			AdvGame.DrawTextOutline (ZoomRect (relativeRect, zoom), toggleText, _style, Color.black, _style.normal.textColor, 2);
		}
		else
		{
			GUI.Label (ZoomRect (relativeRect, zoom), toggleText, _style);
		}
	}


	public override string GetLabel (int slot)
	{
		if (isOn)
		{
			return TranslateLabel (label) + " : " + "On";
		}
		
		return TranslateLabel (label) + " : " + "Off";
	}

	
	public void Toggle ()
	{
		if (isOn)
		{
			isOn = false;
		}
		else
		{
			isOn = true;
		}
		
		if (toggleType == AC_ToggleType.Subtitles)
		{
			if (GameObject.FindWithTag (Tags.persistentEngine) && GameObject.FindWithTag (Tags.persistentEngine).GetComponent <Options>())
			{
				Options options = GameObject.FindWithTag (Tags.persistentEngine).GetComponent <Options>();
				
				options.optionsData.showSubtitles = isOn;
				options.SavePrefs ();
			}
		}
	}
	
	
	public override void RecalculateSize ()
	{
		if (Application.isPlaying && toggleType == AC_ToggleType.Subtitles)
		{
			if (GameObject.FindWithTag (Tags.persistentEngine) && GameObject.FindWithTag (Tags.persistentEngine).GetComponent <Options>())
			{	
				isOn = GameObject.FindWithTag (Tags.persistentEngine).GetComponent <Options>().optionsData.showSubtitles;
			}
		}
		
		base.RecalculateSize ();
	}
	
	
	protected override void AutoSize ()
	{
		AutoSize (new GUIContent (TranslateLabel (label) + " : Off"));
	}

}

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

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