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
/*
 *
 *	Adventure Creator
 *	by Chris Burton, 2013-2014
 *	
 *	"MenuCycle.cs"
 * 
 *	This MenuElement is like a label, only it's text cycles through an array when clicked on.
 * 
 */

using UnityEngine;
using AC;

#if UNITY_EDITOR
using UnityEditor;
#endif

public class MenuCycle : MenuElement
{

	public string label = "Element";
	public bool doOutline;
	public TextAnchor anchor;
	public int selected;
	public string[] optionsArray;
	public AC_CycleType cycleType;
	
	
	public override void Declare ()
	{
		label = "Cycle";
		selected = 0;
		isVisible = true;
		isClickable = true;
		numSlots = 1;
		SetSize (new Vector2 (15f, 5f));
		anchor = TextAnchor.MiddleLeft;
		cycleType = AC_CycleType.CustomScript;
		
		base.Declare ();
	}
	
	
	public void CopyCycle (MenuCycle _element)
	{
		label = _element.label;
		doOutline = _element.doOutline;
		anchor = _element.anchor;
		selected = _element.selected;
		optionsArray = _element.optionsArray;
		cycleType = _element.cycleType;
				
		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);
			cycleType = (AC_CycleType) EditorGUILayout.EnumPopup ("Cycle type:", cycleType);
			if (cycleType == AC_CycleType.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 (Application.isPlaying)
		{
			if (optionsArray.Length > selected && selected > -1)
			{
				toggleText += optionsArray [selected];
			}
			else
			{
				Debug.Log ("Could not gather options options for MenuCycle " + label);
				selected = 0;
			}
		}
		else
		{
			toggleText += "Default option";	
		}
		
		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 (optionsArray.Length > selected && selected > -1)
		{
			return TranslateLabel (label) + " : " + optionsArray [selected];
		}

		return TranslateLabel (label);
	}
	
	
	public void Cycle ()
	{
		selected ++;
		if (selected > optionsArray.Length-1)
		{
			selected = 0;
		}
		
		if (cycleType == AC_CycleType.Language)
		{
			if (GameObject.FindWithTag (Tags.persistentEngine) && GameObject.FindWithTag (Tags.persistentEngine).GetComponent <Options>())
			{
				Options options = GameObject.FindWithTag (Tags.persistentEngine).GetComponent <Options>();
				
				options.optionsData.language = selected;
				options.SavePrefs ();
			}
			else
			{
				Debug.LogWarning ("Could not find Options data!");
			}
		}
	}
	
	
	public override void RecalculateSize ()
	{
		if (Application.isPlaying && cycleType == AC_CycleType.Language)
		{
			if (AdvGame.GetReferences () && AdvGame.GetReferences ().speechManager && GameObject.FindWithTag (Tags.persistentEngine) && GameObject.FindWithTag (Tags.persistentEngine).GetComponent <Options>())
			{	
				SpeechManager speechManager = AdvGame.GetReferences ().speechManager;
				Options options = GameObject.FindWithTag (Tags.persistentEngine).GetComponent <Options>();
				
				optionsArray = speechManager.languages.ToArray ();
				selected = options.optionsData.language;
			}
		}
		
		base.RecalculateSize ();
	}
	
	
	protected override void AutoSize ()
	{
		AutoSize (new GUIContent (TranslateLabel (label) + " : Default option"));
	}
	
}

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

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