context: using UnityEngine;
  using System.Collections;
  using Frontiers;
  using System.Collections.Generic;
  using System;
  
  namespace Frontiers.GUI
  {
  	//TODO figure out how to get lock cursor working correctly on linux
  	public class GUICursor : InterfaceActionFilter
  	{
  		public static GUICursor Get;
  		public static bool gUseMouseLock = true;
  
  		public int LastSelectedWidgetFlag {
  			get {
  				return CurrentSearch.Widget.Flag;
  			}
  		}
  
  		public MeshRenderer SoftwareCursorSprite;
  		public Texture2D CursorTexture;
  		public Texture2D StackSplitTexture;
  		public Texture2D StackQuickAddTexture;
  		public float TargetOpacity = 1.0f;
  		public float FadeTime = 1.0f;
  		public float Alpha = 0.0f;
  		public bool MoveCursorOnSelectGUIElements = false;
  		public bool HideSoftwareCursorSprite = false;
  		public InterfaceActionFilter InterfaceActions;
  		public FrontiersInterface CurrentActiveInterface;
  		public Camera SearchCamera;
  		public Vector3 ScreenSearchOrigin;
  		public Vector3 ScreenSearchDirection;
  		public Vector3 WorldSearchOrigin;
  		public List <FrontiersInterface.Widget> CurrentObjects = new List <FrontiersInterface.Widget> ();
  		public List <WidgetSearch> CurrentSearches = new List<WidgetSearch> ();
  
  		public bool FollowCurrentWidget {
  			get {
  				return mFollowSearch.Equals (CurrentSearch);
  			}
  			set {
  				mFollowSearch.Widget.IsEmpty = true;
  			}
  		}
  
  		public bool TryToFollowCurrentWidget (int flag)
  		{
  			if (CurrentSearch.Widget.Flag == flag) {
  				mFollowSearch = CurrentSearch;
  				return true;
  			}
  			return false;
  		}
  
  		public void StopFollowingCurrentWidget (int flag)
  		{
  			if (mFollowSearch.Widget.Flag == flag) {
  				mFollowSearch.Widget.IsEmpty = true;
  			}
  		}
  
  		public Bounds CurrentWidgetBounds {
  			get {
  				return CurrentSearch.ScreenBounds;
  			}
  		}
  
  		public Bounds PreviousSearchBounds {
  			get {
  				return PreviousSearch.ScreenBounds;
  			}
  		}
  
  		public bool WidgetSelectedRecently {
  			get {
  				return mLastFrameSelection == 1;
  			}
  			set {
  				mLastFrameSelection = 2;
  			}
  		}
  
  		public WidgetSearch CurrentSearch;
  		public WidgetSearch PreviousSearch;
  		public SearchDirection LastDirection;
  		public Vector3 LastSearchDirection;
  		public Vector3 LastMouseCursorResult;
  		public Bounds LastBrowserBounds;
  
  		public bool ReadyForNextPress {
  			get {
  				if (mPressedThisFrame) {
  					return false;
  				} else {
  					mPressedThisFrame = true;
  				}
  
  				double timeSinceLastInput = WorldClock.RealTime - mLastInput;
  				if (timeSinceLastInput > mPressInterval * 1.1f) {
  					mHolding = false;
  					mStartHold = -1f;
  				} else {
  					//see if we've held long enough
  					if (mStartHold > 0) {
  						if (WorldClock.RealTime > mStartHold + mHoldInterval) {
  							mHolding = true;
  						}
  					} else {
  						mStartHold = WorldClock.RealTime;
  					}
  				}
  				//if we've been holding it for a while return quick interval, otherwise normal interval
  				if (mHolding) {
  					return WorldClock.RealTime > mLastInput + mPressIntervalShort;
  				} else {
  					return WorldClock.RealTime > mLastInput + mPressInterval;
  				}
  			}
  			set {
  				mStartHold = -1f;
  			}
  		}
  
  		public void Start ()
  		{
  			Subscribe (InterfaceActionType.SelectionRight, SelectionRight);
  			Subscribe (InterfaceActionType.SelectionLeft, SelectionLeft);
  			Subscribe (InterfaceActionType.SelectionUp, SelectionUp);
  			Subscribe (InterfaceActionType.SelectionDown, SelectionDown);
  			Behavior = PassThroughBehavior.PassThrough;
  
  			SetCursorTexture ("Default");
  		}
  
  		public override void WakeUp ()
  		{
  			Screen.showCursor = false;
  			Get = this;
  			base.WakeUp ();
  		}
  
  		public bool SelectionRight (double timeStamp)
  		{
  			//Debug.Log ("Selection right");
  			if (UIInput.current != null && UIInput.current.isActiveAndEnabled) {
  				UIInput.current.Ping ();
  				return true;
  			}
  			FollowCurrentWidget = false;
  
  			if (ReadyForNextPress) {
  				mLastInput = WorldClock.RealTime;
  				if (FindSearchOriginAndCamera (true)) {
  					ScreenSearchDirection = SearchCamera.transform.right;
  					FindNextObject (SearchDirection.Right);
  					MasterAudio.PlaySound (MasterAudio.SoundType.PlayerInterface, "ButtonMouseNavigate");
  				} else {
  					ReadyForNextPress = false;
  				}
  			}
  			return true;
  		}
  
  		public bool SelectionLeft (double timeStamp)
  		{
  			//Debug.Log ("Selection left");
  			if (UIInput.current != null && UIInput.current.isActiveAndEnabled) {
  				UIInput.current.Ping ();
  				return true;
  			}
  			FollowCurrentWidget = false;
  
  			if (ReadyForNextPress) {
  				mLastInput = WorldClock.RealTime;
  				if (FindSearchOriginAndCamera (true)) {
  					ScreenSearchDirection = -SearchCamera.transform.right;
  					FindNextObject (SearchDirection.Left);
  					MasterAudio.PlaySound (MasterAudio.SoundType.PlayerInterface, "ButtonMouseNavigate");
  				} else {
  					ReadyForNextPress = false;
  				}
  			}
  			return true;
  		}
  
  		public bool SelectionUp (double timeStamp)
  		{
  			//Debug.Log ("Selection up");
  			if (UIInput.current != null && UIInput.current.isActiveAndEnabled) {
  				UIInput.current.Ping ();
  				return true;
  			}
  			FollowCurrentWidget = false;
  
  			if (ReadyForNextPress) {
  				mLastInput = WorldClock.RealTime;
  				if (FindSearchOriginAndCamera (true)) {
  					if (Profile.Get.HasCurrentProfile && Profile.Get.CurrentPreferences.Controls.InvertRawInterfaceAxis) {
  						ScreenSearchDirection = -SearchCamera.transform.up;
  						FindNextObject (SearchDirection.Down);
  					} else {
  						ScreenSearchDirection = SearchCamera.transform.up;
  						FindNextObject (SearchDirection.Up);
  					}
  					MasterAudio.PlaySound (MasterAudio.SoundType.PlayerInterface, "ButtonMouseNavigate");
  				} else {
  					ReadyForNextPress = false;
  				}
  			}
  			return true;
  		}
  
  		public bool SelectionDown (double timeStamp)
  		{
  			//Debug.Log ("Selection down");
  			if (UIInput.current != null && UIInput.current.isActiveAndEnabled) {
  				UIInput.current.Ping ();
  				return true;
  			}
  			FollowCurrentWidget = false;
  
  			if (ReadyForNextPress) {
  				mLastInput = WorldClock.RealTime;
  				if (FindSearchOriginAndCamera (true)) {
  					if (Profile.Get.HasCurrentProfile && Profile.Get.CurrentPreferences.Controls.InvertRawInterfaceAxis) {
  						ScreenSearchDirection = SearchCamera.transform.up;
  						FindNextObject (SearchDirection.Up);
  					} else {
  
gt: 						ScreenSearchDirection = -SearchCamera.transform.up;