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
 *	
 *	"MenuButton.cs"
 * 
 *	This MenuElement can be clicked on to perform a function defined in MenuSystem.
 * 
 */

using UnityEngine;
using System.Collections.Generic;
using AC;

#if UNITY_EDITOR
using UnityEditor;	
#endif

[System.Serializable]
public class MenuButton : MenuElement
{
	
	public string label = "Element";
	public TextAnchor anchor;
	public bool doOutline;
	public AC_ButtonClickType buttonClickType;
	public SimulateInputType simulateInput = SimulateInputType.Button;
	public float simulateValue = 1f;
	public bool doFade;
	public string switchMenuTitle;
	public string inventoryBoxTitle;
	public AC_ShiftInventory shiftInventory;
	public bool loopJournal = false;
	public MenuActionList actionList;
	public string inputAxis;

	
	public override void Declare ()
	{
		label = "Button";
		isVisible = true;
		isClickable = true;
		doOutline = false;
		buttonClickType = AC_ButtonClickType.CustomScript;
		simulateInput = SimulateInputType.Button;
		simulateValue = 1f;
		numSlots = 1;
		anchor = TextAnchor.MiddleCenter;
		SetSize (new Vector2 (10f, 5f));
		doFade = false;
		switchMenuTitle = "";
		inventoryBoxTitle = "";
		shiftInventory = AC_ShiftInventory.ShiftLeft;
		loopJournal = false;
		actionList = null;
		inputAxis = "";
		
		base.Declare ();
	}
	
	
	public void CopyButton (MenuButton _element)
	{
		label = _element.label;
		anchor = _element.anchor;
		doOutline = _element.doOutline;
		buttonClickType = _element.buttonClickType;
		simulateInput = _element.simulateInput;
		simulateValue = _element.simulateValue;
		doFade = _element.doFade;
		switchMenuTitle = _element.switchMenuTitle;
		inventoryBoxTitle = _element.inventoryBoxTitle;
		shiftInventory = _element.shiftInventory;
		loopJournal = _element.loopJournal;
		actionList = _element.actionList;
		inputAxis = _element.inputAxis;
				
		base.Copy (_element);
	}
	
	
	#if UNITY_EDITOR
	
	public override void ShowGUI ()
	{
		EditorGUILayout.BeginVertical ("Button");
			label = EditorGUILayout.TextField ("Button text:", label);
			anchor = (TextAnchor) EditorGUILayout.EnumPopup ("Text alignment:", anchor);
			doOutline = EditorGUILayout.Toggle ("Outline text?", doOutline);
			buttonClickType = (AC_ButtonClickType) EditorGUILayout.EnumPopup ("Click type:", buttonClickType);
		
			if (buttonClickType == AC_ButtonClickType.TurnOffMenu)
			{
				doFade = EditorGUILayout.Toggle ("Fade?", doFade);
			}
			else if (buttonClickType == AC_ButtonClickType.Crossfade)
			{
				switchMenuTitle = EditorGUILayout.TextField ("Menu to switch to:", switchMenuTitle);
			}
			else if (buttonClickType == AC_ButtonClickType.OffsetInventory)
			{
				inventoryBoxTitle = EditorGUILayout.TextField ("InventoryBox to affect:", inventoryBoxTitle);
				shiftInventory = (AC_ShiftInventory) EditorGUILayout.EnumPopup ("Offset type:", shiftInventory);
			}
			else if (buttonClickType == AC_ButtonClickType.OffsetJournal)
			{
				inventoryBoxTitle = EditorGUILayout.TextField ("Journal to affect:", inventoryBoxTitle);
				shiftInventory = (AC_ShiftInventory) EditorGUILayout.EnumPopup ("Offset type:", shiftInventory);
				loopJournal = EditorGUILayout.Toggle ("Cycle pages?", loopJournal);
			}
			else if (buttonClickType == AC_ButtonClickType.RunActionList)
			{
				actionList = (MenuActionList) EditorGUILayout.ObjectField ("ActionList to run:", actionList, typeof (MenuActionList), false);
			}
			else if (buttonClickType == AC_ButtonClickType.CustomScript)
			{
				ShowClipHelp ();
			}
			else if (buttonClickType == AC_ButtonClickType.SimulateInput)
			{
				simulateInput = (SimulateInputType) EditorGUILayout.EnumPopup ("Simulate:", simulateInput);
				inputAxis = EditorGUILayout.TextField ("Input axis:", inputAxis);
				if (simulateInput == SimulateInputType.Axis)
				{
					simulateValue = EditorGUILayout.FloatField ("Input value:", simulateValue);
				}
			}
		EditorGUILayout.EndVertical ();
		
		base.ShowGUI ();
	}
	
	#endif
	
	
	public override void Display (GUIStyle _style, int _slot, float 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);
		}

		base.Display (_style, _slot, zoom);
	}


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

	
	protected override void AutoSize ()
	{
		if (label == "" && backgroundTexture != null)
		{
			GUIContent content = new GUIContent (backgroundTexture);
			AutoSize (content);
		}
		else
		{
			GUIContent content = new GUIContent (TranslateLabel (label));
			AutoSize (content);
		}
	}
	
}

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

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