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
/*
 *
 *	Adventure Creator
 *	by Chris Burton, 2013-2014
 *	
 *	"MenuInput.cs"
 * 
 *	This MenuElement acts like a label, whose text can be changed with keyboard input.
 * 
 */

using UnityEngine;
using AC;

#if UNITY_EDITOR
using UnityEditor;
#endif

public class MenuInput : MenuElement
{
	
	public string label = "Element";
	public TextAnchor anchor;
	public bool doOutline;
	public AC_InputType inputType;
	public int characterLimit = 10;

	private float lastInputTime = 0f;

	
	public override void Declare ()
	{
		label = "Input";
		isVisible = true;
		isClickable = true;
		numSlots = 1;
		anchor = TextAnchor.MiddleCenter;
		SetSize (new Vector2 (10f, 5f));
		inputType = AC_InputType.AlphaNumeric;
		characterLimit = 10;
		lastInputTime = 0f;
		
		base.Declare ();
	}
	
	
	public void CopyInput (MenuInput _element)
	{
		label = _element.label;
		anchor = _element.anchor;
		doOutline = _element.doOutline;
		inputType = _element.inputType;
		characterLimit = _element.characterLimit;
		
		base.Copy (_element);
	}
	
	
	#if UNITY_EDITOR
	
	public override void ShowGUI ()
	{
		EditorGUILayout.BeginVertical ("Button");
		label = EditorGUILayout.TextField ("Default text:", label);
		inputType = (AC_InputType) EditorGUILayout.EnumPopup ("Input type:", inputType);
		characterLimit = EditorGUILayout.IntSlider ("Character limit:", characterLimit, 1, 50);
		anchor = (TextAnchor) EditorGUILayout.EnumPopup ("Text alignment:", anchor);
		doOutline = EditorGUILayout.Toggle ("Outline text?", doOutline);
		EditorGUILayout.EndVertical ();
		
		base.ShowGUI ();
	}
	
	#endif
	
	
	public override void Display (GUIStyle _style, int _slot, float zoom)
	{
		base.Display (_style, _slot, zoom);
		
		_style.wordWrap = true;
		_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);
		}
	}


	public override string GetLabel (int slot)
	{
		return TranslateLabel (label);
	}


	public void CheckForInput (string input)
	{
		if (Time.time > lastInputTime + 0.1f)
		{
			lastInputTime = Time.time;

			if (input == "Backspace")
			{
				label = label.Substring (0, label.Length - 1);
			}
			else if (input != "None")
			{
				if (input.Contains ("Alpha") || inputType == AC_InputType.AlphaNumeric)
				{
					input = input.Replace ("Alpha", "");
					if (characterLimit == 1)
					{
						label = input;
					}
					else if (label.Length < characterLimit)
					{
						label += input;
					}
				}
			}
		}
	}

	
	protected override void AutoSize ()
	{
		GUIContent content = new GUIContent (TranslateLabel (label));
		AutoSize (content);
	}
	
}

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

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