IEnumerator animateClose( dfListbox popup ) { var runningTime = 0f; var startAlpha = 1f; var endAlpha = 0f; var startHeight = popup.Height; var endHeight = 20f; while( this.target == popup && runningTime < ANIMATION_LENGTH ) { runningTime = Mathf.Min( runningTime + Time.deltaTime, ANIMATION_LENGTH ); popup.Opacity = Mathf.Lerp( startAlpha, endAlpha, runningTime / ANIMATION_LENGTH ); var height = Mathf.Lerp( startHeight, endHeight, runningTime / ANIMATION_LENGTH ); popup.Height = height; yield return null; } this.target = null; Destroy( popup.gameObject ); }
IEnumerator animateOpen( dfListbox popup ) { var runningTime = 0f; var startAlpha = 0f; var endAlpha = 1f; var startHeight = 20f; var endHeight = popup.Height; while( this.target == popup && runningTime < ANIMATION_LENGTH ) { runningTime = Mathf.Min( runningTime + Time.deltaTime, ANIMATION_LENGTH ); popup.Opacity = Mathf.Lerp( startAlpha, endAlpha, runningTime / ANIMATION_LENGTH ); var height = Mathf.Lerp( startHeight, endHeight, runningTime / ANIMATION_LENGTH ); popup.Height = height; yield return null; } popup.Opacity = 1f; popup.Height = endHeight; yield return null; popup.Invalidate(); }
private void closePopup(bool allowOverride = true) { if (this.popup == null) { return; } this.popup.LostFocus -= new FocusEventHandler(this.popup_LostFocus); this.popup.SelectedIndexChanged -= new PropertyChangedEventHandler <int>(this.popup_SelectedIndexChanged); this.popup.ItemClicked -= new PropertyChangedEventHandler <int>(this.popup_ItemClicked); this.popup.KeyDown -= new KeyPressHandler(this.popup_KeyDown); if (!allowOverride) { UnityEngine.Object.Destroy(this.popup.gameObject); this.popup = null; return; } bool flag = false; if (this.DropdownClose != null) { this.DropdownClose(this, this.popup, ref flag); } if (!flag) { flag = base.Signal("OnDropdownClose", new object[] { this, this.popup }); } if (!flag) { UnityEngine.Object.Destroy(this.popup.gameObject); } this.popup = null; }
private void openPopup() { if ((this.popup == null) && (this.items.Length != 0)) { Vector2 vector = this.calculatePopupSize(); this.popup = base.GetManager().AddControl <dfListbox>(); this.popup.name = base.name + " - Dropdown List"; this.popup.gameObject.hideFlags = HideFlags.DontSave; this.popup.Atlas = base.Atlas; this.popup.Anchor = dfAnchorStyle.Left | dfAnchorStyle.Top; this.popup.Font = this.Font; this.popup.Pivot = dfPivotPoint.TopLeft; this.popup.Size = vector; this.popup.Font = this.Font; this.popup.ItemHeight = this.ItemHeight; this.popup.ItemHighlight = this.ItemHighlight; this.popup.ItemHover = this.ItemHover; this.popup.ItemPadding = this.TextFieldPadding; this.popup.ItemTextColor = this.TextColor; this.popup.ItemTextScale = this.TextScale; this.popup.Items = this.Items; this.popup.ListPadding = this.ListPadding; this.popup.BackgroundSprite = this.ListBackground; this.popup.Shadow = this.Shadow; this.popup.ShadowColor = this.ShadowColor; this.popup.ShadowOffset = this.ShadowOffset; this.popup.ZOrder = 0x7fffffff; if ((vector.y >= this.MaxListHeight) && (this.listScrollbar != null)) {
private void closePopup(bool allowOverride = true) { if (this.popup != null) { this.popup.LostFocus -= new FocusEventHandler(this.popup_LostFocus); this.popup.SelectedIndexChanged -= new PropertyChangedEventHandler <int>(this.popup_SelectedIndexChanged); this.popup.ItemClicked -= new PropertyChangedEventHandler <int>(this.popup_ItemClicked); this.popup.KeyDown -= new KeyPressHandler(this.popup_KeyDown); if (!allowOverride) { UnityEngine.Object.Destroy(this.popup.gameObject); this.popup = null; } else { bool overridden = false; if (this.DropdownClose != null) { this.DropdownClose(this, this.popup, ref overridden); } if (!overridden) { object[] args = new object[] { this, this.popup }; overridden = base.Signal("OnDropdownClose", args); } if (!overridden) { UnityEngine.Object.Destroy(this.popup.gameObject); } this.popup = null; } } }
IEnumerator animateOpen(dfListbox popup) { var runningTime = 0f; var startAlpha = 0f; var endAlpha = 1f; var startHeight = 20f; var endHeight = popup.Height; while (this.target == popup && runningTime < ANIMATION_LENGTH) { runningTime = Mathf.Min(runningTime + Time.deltaTime, ANIMATION_LENGTH); popup.Opacity = Mathf.Lerp(startAlpha, endAlpha, runningTime / ANIMATION_LENGTH); var height = Mathf.Lerp(startHeight, endHeight, runningTime / ANIMATION_LENGTH); popup.Height = height; yield return(null); } popup.Opacity = 1f; popup.Height = endHeight; yield return(null); popup.Invalidate(); }
void Awake() { mNetworkManager = (NetworkManager)GameObject.FindObjectOfType(typeof(NetworkManager)); mGamesList = (dfListbox)GameObject.FindObjectOfType(typeof(dfListbox)); mLoadingPanel = (LoadingPanel)GameObject.FindObjectOfType(typeof(LoadingPanel)); mErrorPanel = (ErrorPanel)GameObject.FindObjectOfType(typeof(ErrorPanel)); }
protected internal override void OnKeyDown(dfKeyEventArgs args) { switch (args.KeyCode) { case KeyCode.UpArrow: { this.SelectedIndex = Mathf.Max(0, this.selectedIndex - 1); base.OnKeyDown(args); return; } case KeyCode.DownArrow: { dfListbox selectedIndex = this; selectedIndex.SelectedIndex = selectedIndex.SelectedIndex + 1; base.OnKeyDown(args); return; } case KeyCode.RightArrow: case KeyCode.LeftArrow: case KeyCode.Insert: { base.OnKeyDown(args); return; } case KeyCode.Home: { this.SelectedIndex = 0; base.OnKeyDown(args); return; } case KeyCode.End: { this.SelectedIndex = (int)this.items.Length; base.OnKeyDown(args); return; } case KeyCode.PageUp: { int num = this.SelectedIndex - Mathf.FloorToInt((this.size.y - (float)this.listPadding.vertical) / (float)this.itemHeight); this.SelectedIndex = Mathf.Max(0, num); base.OnKeyDown(args); return; } case KeyCode.PageDown: { dfListbox _dfListbox = this; _dfListbox.SelectedIndex = _dfListbox.SelectedIndex + Mathf.FloorToInt((this.size.y - (float)this.listPadding.vertical) / (float)this.itemHeight); base.OnKeyDown(args); return; } default: { base.OnKeyDown(args); return; } } }
void Awake() { mNetworkManager = (NetworkManager)FindObjectOfType(typeof(NetworkManager)); mDialogueManager = (DialogueManager)FindObjectOfType(typeof(DialogueManager)); mCountdown = (Countdown)FindObjectOfType(typeof(Countdown)); mAvailablePropsList = (dfListbox)FindObjectOfType(typeof(dfListbox)); mMyProps = (MyProps)FindObjectOfType(typeof(MyProps)); mGame = (Game)FindObjectOfType(typeof(Game)); }
void Awake() { list = GetComponentInChildren<dfListbox>(); list.SelectedIndex = 0; SpellsLearned = SpellDefinition.AllSpells .OrderBy( x => x.Name ) .Select( x => x.Name ) .ToList(); }
void OnDropdownOpen( dfDropdown dropdown, dfListbox popup ) { if( this.target != null ) { StopCoroutine( "animateOpen" ); StopCoroutine( "animateClose" ); Destroy( this.target.gameObject ); } this.target = popup; StartCoroutine( animateOpen( popup ) ); }
void OnDropdownOpen(dfDropdown dropdown, dfListbox popup) { if (this.target != null) { StopCoroutine("animateOpen"); StopCoroutine("animateClose"); Destroy(this.target.gameObject); } this.target = popup; StartCoroutine(animateOpen(popup)); }
public void ClosePopup(bool allowOverride) { if (popup == null) { return; } if (dfGUIManager.GetModalControl() == popup) { dfGUIManager.PopModal(); } popup.LostFocus -= popup_LostFocus; popup.SelectedIndexChanged -= popup_SelectedIndexChanged; popup.ItemClicked -= popup_ItemClicked; popup.KeyDown -= popup_KeyDown; if (!allowOverride) { Destroy(popup.gameObject); popup = null; return; } bool overridden = false; if (DropdownClose != null) { DropdownClose(this, popup, ref overridden); } if (!overridden) { Signal("OnDropdownClose", this, popup); } if (!overridden) { Destroy(popup.gameObject); } popup = null; }
private static void EditOptions(dfListbox control) { GUILayout.BeginHorizontal(); { EditorGUILayout.LabelField("Options", "", GUILayout.Width(100)); EditorGUI.BeginChangeCheck(); var optionsString = string.Join("\n", control.Items); var optionsEdit = EditorGUILayout.TextArea(optionsString, GUILayout.Height(100f), GUILayout.MaxWidth(225)); if (EditorGUI.EndChangeCheck()) { dfEditorUtil.MarkUndo(control, "Change options"); var options = optionsEdit.Trim().Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries); control.Items = options; } } GUILayout.EndHorizontal(); dfEditorUtil.LabelWidth = 100f; }
IEnumerator animateClose(dfListbox popup) { var runningTime = 0f; var startAlpha = 1f; var endAlpha = 0f; var startHeight = popup.Height; var endHeight = 20f; while (this.target == popup && runningTime < ANIMATION_LENGTH) { runningTime = Mathf.Min(runningTime + Time.deltaTime, ANIMATION_LENGTH); popup.Opacity = Mathf.Lerp(startAlpha, endAlpha, runningTime / ANIMATION_LENGTH); var height = Mathf.Lerp(startHeight, endHeight, runningTime / ANIMATION_LENGTH); popup.Height = height; yield return(null); } this.target = null; Destroy(popup.gameObject); }
void OnDropdownClose( dfDropdown dropdown, dfListbox popup ) { StartCoroutine( animateClose( popup ) ); }
private void openPopup() { if (this.popup != null || (int)this.items.Length == 0) { return; } Vector2 vector2 = this.calculatePopupSize(); this.popup = base.GetManager().AddControl <dfListbox>(); this.popup.name = string.Concat(base.name, " - Dropdown List"); this.popup.gameObject.hideFlags = HideFlags.DontSave; this.popup.Atlas = base.Atlas; this.popup.Anchor = dfAnchorStyle.Top | dfAnchorStyle.Left; this.popup.Font = this.Font; this.popup.Pivot = dfPivotPoint.TopLeft; this.popup.Size = vector2; this.popup.Font = this.Font; this.popup.ItemHeight = this.ItemHeight; this.popup.ItemHighlight = this.ItemHighlight; this.popup.ItemHover = this.ItemHover; this.popup.ItemPadding = this.TextFieldPadding; this.popup.ItemTextColor = this.TextColor; this.popup.ItemTextScale = this.TextScale; this.popup.Items = this.Items; this.popup.ListPadding = this.ListPadding; this.popup.BackgroundSprite = this.ListBackground; this.popup.Shadow = this.Shadow; this.popup.ShadowColor = this.ShadowColor; this.popup.ShadowOffset = this.ShadowOffset; this.popup.ZOrder = 2147483647; if (vector2.y >= (float)this.MaxListHeight && this.listScrollbar != null) { GameObject gameObject = UnityEngine.Object.Instantiate(this.listScrollbar.gameObject) as GameObject; dfScrollbar component = gameObject.GetComponent <dfScrollbar>(); float units = base.PixelsToUnits(); Vector3 vector3 = this.popup.transform.TransformDirection(Vector3.right); Vector3 width = this.popup.transform.position + ((vector3 * (vector2.x - component.Width)) * units); component.transform.parent = this.popup.transform; component.transform.position = width; component.Anchor = dfAnchorStyle.Top | dfAnchorStyle.Bottom; component.Height = this.popup.Height; dfListbox _dfListbox = this.popup; _dfListbox.Width = _dfListbox.Width - component.Width; this.popup.Scrollbar = component; this.popup.SizeChanged += new PropertyChangedEventHandler <Vector2>((dfControl control, Vector2 size) => component.Height = control.Height); } Vector2 vector21 = this.popup.Size; Vector3 vector31 = this.calculatePopupPosition((int)vector21.y); this.popup.transform.position = vector31; this.popup.transform.rotation = base.transform.rotation; this.popup.SelectedIndexChanged += new PropertyChangedEventHandler <int>(this.popup_SelectedIndexChanged); this.popup.LostFocus += new FocusEventHandler(this.popup_LostFocus); this.popup.ItemClicked += new PropertyChangedEventHandler <int>(this.popup_ItemClicked); this.popup.KeyDown += new KeyPressHandler(this.popup_KeyDown); this.popup.SelectedIndex = Mathf.Max(0, this.SelectedIndex); this.popup.EnsureVisible(this.popup.SelectedIndex); this.popup.Focus(); if (this.DropdownOpen != null) { bool flag = false; this.DropdownOpen(this, this.popup, ref flag); } base.Signal("OnDropdownOpen", new object[] { this, this.popup }); }
private void openPopup() { if (this.popup != null || (int)this.items.Length == 0) { return; } Vector2 vector2 = this.calculatePopupSize(); this.popup = base.GetManager().AddControl<dfListbox>(); this.popup.name = string.Concat(base.name, " - Dropdown List"); this.popup.gameObject.hideFlags = HideFlags.DontSave; this.popup.Atlas = base.Atlas; this.popup.Anchor = dfAnchorStyle.Top | dfAnchorStyle.Left; this.popup.Font = this.Font; this.popup.Pivot = dfPivotPoint.TopLeft; this.popup.Size = vector2; this.popup.Font = this.Font; this.popup.ItemHeight = this.ItemHeight; this.popup.ItemHighlight = this.ItemHighlight; this.popup.ItemHover = this.ItemHover; this.popup.ItemPadding = this.TextFieldPadding; this.popup.ItemTextColor = this.TextColor; this.popup.ItemTextScale = this.TextScale; this.popup.Items = this.Items; this.popup.ListPadding = this.ListPadding; this.popup.BackgroundSprite = this.ListBackground; this.popup.Shadow = this.Shadow; this.popup.ShadowColor = this.ShadowColor; this.popup.ShadowOffset = this.ShadowOffset; this.popup.ZOrder = 2147483647; if (vector2.y >= (float)this.MaxListHeight && this.listScrollbar != null) { GameObject gameObject = UnityEngine.Object.Instantiate(this.listScrollbar.gameObject) as GameObject; dfScrollbar component = gameObject.GetComponent<dfScrollbar>(); float units = base.PixelsToUnits(); Vector3 vector3 = this.popup.transform.TransformDirection(Vector3.right); Vector3 width = this.popup.transform.position + ((vector3 * (vector2.x - component.Width)) * units); component.transform.parent = this.popup.transform; component.transform.position = width; component.Anchor = dfAnchorStyle.Top | dfAnchorStyle.Bottom; component.Height = this.popup.Height; dfListbox _dfListbox = this.popup; _dfListbox.Width = _dfListbox.Width - component.Width; this.popup.Scrollbar = component; this.popup.SizeChanged += new PropertyChangedEventHandler<Vector2>((dfControl control, Vector2 size) => component.Height = control.Height); } Vector2 vector21 = this.popup.Size; Vector3 vector31 = this.calculatePopupPosition((int)vector21.y); this.popup.transform.position = vector31; this.popup.transform.rotation = base.transform.rotation; this.popup.SelectedIndexChanged += new PropertyChangedEventHandler<int>(this.popup_SelectedIndexChanged); this.popup.LostFocus += new FocusEventHandler(this.popup_LostFocus); this.popup.ItemClicked += new PropertyChangedEventHandler<int>(this.popup_ItemClicked); this.popup.KeyDown += new KeyPressHandler(this.popup_KeyDown); this.popup.SelectedIndex = Mathf.Max(0, this.SelectedIndex); this.popup.EnsureVisible(this.popup.SelectedIndex); this.popup.Focus(); if (this.DropdownOpen != null) { bool flag = false; this.DropdownOpen(this, this.popup, ref flag); } base.Signal("OnDropdownOpen", new object[] { this, this.popup }); }
void Awake() { mNetworkManager = (NetworkManager) FindObjectOfType(typeof(NetworkManager)); mDialogueManager = (DialogueManager) FindObjectOfType(typeof(DialogueManager)); mCountdown = (Countdown) FindObjectOfType(typeof(Countdown)); mAvailablePropsList = (dfListbox) FindObjectOfType(typeof(dfListbox)); mMyProps = (MyProps) FindObjectOfType(typeof(MyProps)); mGame = (Game) FindObjectOfType(typeof(Game)); }
void OnDropdownClose(dfDropdown dropdown, dfListbox popup) { StartCoroutine(animateClose(popup)); }
private void closePopup( bool allowOverride = true ) { if( popup == null ) return; popup.LostFocus -= popup_LostFocus; popup.SelectedIndexChanged -= popup_SelectedIndexChanged; popup.ItemClicked -= popup_ItemClicked; popup.KeyDown -= popup_KeyDown; if( !allowOverride ) { Destroy( popup.gameObject ); popup = null; return; } bool overridden = false; if( DropdownClose != null ) { DropdownClose( this, popup, ref overridden ); } if( !overridden ) { overridden = Signal( "OnDropdownClose", this, popup ); } if( !overridden ) { Destroy( popup.gameObject ); } popup = null; }
private void openPopup() { if( popup != null || items.Length == 0 ) return; // Find the top-level parent of this control to attach the popup list to. // This is done under the assumption that the top-level control will either be // a panel that does not move or a window that does, and that if the parent // is moved, the dropdown list will remain in the proper position relative // to this control. var root = this.GetRootContainer(); var popupSize = calculatePopupSize(); // Create the popup list and set all necessary properties popup = root.AddControl<dfListbox>(); popup.name = this.name + " - Dropdown List"; popup.gameObject.hideFlags = HideFlags.DontSave; popup.Atlas = this.Atlas; popup.Anchor = dfAnchorStyle.None; popup.Font = this.Font; popup.Pivot = dfPivotPoint.TopLeft; popup.Size = popupSize; popup.Font = this.Font; popup.ItemHeight = this.ItemHeight; popup.ItemHighlight = this.ItemHighlight; popup.ItemHover = this.ItemHover; popup.ItemPadding = this.TextFieldPadding; popup.ItemTextColor = this.TextColor; popup.ItemTextScale = this.TextScale; popup.Items = this.Items; popup.ListPadding = this.ListPadding; popup.BackgroundSprite = this.ListBackground; popup.Shadow = this.Shadow; popup.ShadowColor = this.ShadowColor; popup.ShadowOffset = this.ShadowOffset; popup.ZOrder = int.MaxValue; // Make sure the popup list is the top control if( popupSize.y >= MaxListHeight && listScrollbar != null ) { var scrollGO = GameObject.Instantiate( listScrollbar.gameObject ) as GameObject; var activeScrollbar = scrollGO.GetComponent<dfScrollbar>(); var p2u = PixelsToUnits(); var right = popup.transform.TransformDirection( Vector3.right ); var scrollbarPosition = popup.transform.position + right * ( popupSize.x - activeScrollbar.Width ) * p2u; activeScrollbar.transform.parent = popup.transform; activeScrollbar.transform.position = scrollbarPosition; activeScrollbar.Anchor = dfAnchorStyle.Top | dfAnchorStyle.Bottom; activeScrollbar.Height = popup.Height; //popup.AddControl( activeScrollbar ); popup.Width -= activeScrollbar.Width; popup.Scrollbar = activeScrollbar; //popup.ResetLayout(); popup.SizeChanged += ( control, size ) => { activeScrollbar.Height = control.Height; }; } // Position the dropdown and set its rotation to the same world rotation // as this control var popupPosition = calculatePopupPosition( (int)popup.Size.y ); popup.transform.position = popupPosition; popup.transform.rotation = this.transform.rotation; // Attach important events popup.SelectedIndexChanged += popup_SelectedIndexChanged; popup.LostFocus += popup_LostFocus; popup.ItemClicked += popup_ItemClicked; popup.KeyDown += popup_KeyDown; // Make sure that the selected item is visible popup.SelectedIndex = Mathf.Max( 0, this.SelectedIndex ); popup.EnsureVisible( popup.SelectedIndex ); // Make sure that the popup has input focus popup.Focus(); // Notify any listeners that the popup has been displayed if( DropdownOpen != null ) { bool overridden = false; DropdownOpen( this, popup, ref overridden ); } Signal( "OnDropdownOpen", this, popup ); }
public void OpenPopup() { if( popup != null || items.Length == 0 ) return; var popupSize = calculatePopupSize(); // Create the popup list and set all necessary properties popup = GetManager().AddControl<dfListbox>(); popup.name = this.name + " - Dropdown List"; popup.gameObject.hideFlags = HideFlags.DontSave; popup.Atlas = this.Atlas; popup.Anchor = dfAnchorStyle.Left | dfAnchorStyle.Top; popup.Color = this.Color; popup.Font = this.Font; popup.Pivot = dfPivotPoint.TopLeft; popup.Size = popupSize; popup.Font = this.Font; popup.ItemHeight = this.ItemHeight; popup.ItemHighlight = this.ItemHighlight; popup.ItemHover = this.ItemHover; popup.ItemPadding = this.TextFieldPadding; popup.ItemTextColor = this.TextColor; popup.ItemTextScale = this.TextScale; popup.Items = this.Items; popup.ListPadding = this.ListPadding; popup.BackgroundSprite = this.ListBackground; popup.Shadow = this.Shadow; popup.ShadowColor = this.ShadowColor; popup.ShadowOffset = this.ShadowOffset; popup.BringToFront(); // If there is a modal control/window up that displays this dropdown, // need to ensure that it is able to receive input if( dfGUIManager.GetModalControl() != null ) { dfGUIManager.PushModal( popup ); } if( popupSize.y >= MaxListHeight && listScrollbar != null ) { var scrollGO = GameObject.Instantiate( listScrollbar.gameObject ) as GameObject; var activeScrollbar = scrollGO.GetComponent<dfScrollbar>(); var p2u = PixelsToUnits(); var right = popup.transform.TransformDirection( Vector3.right ); var scrollbarPosition = popup.transform.position + right * ( popupSize.x - activeScrollbar.Width ) * p2u; popup.AddControl( activeScrollbar ); popup.Width -= activeScrollbar.Width; popup.Scrollbar = activeScrollbar; popup.SizeChanged += ( control, size ) => { activeScrollbar.Height = control.Height; }; activeScrollbar.transform.parent = popup.transform; activeScrollbar.transform.position = scrollbarPosition; activeScrollbar.Anchor = dfAnchorStyle.Top | dfAnchorStyle.Bottom; activeScrollbar.Height = popup.Height; } // Position the dropdown and set its rotation to the same world rotation // as this control var popupPosition = calculatePopupPosition( (int)popup.Size.y ); popup.transform.position = popupPosition; popup.transform.rotation = this.transform.rotation; // Attach important events popup.SelectedIndexChanged += popup_SelectedIndexChanged; popup.LeaveFocus += popup_LostFocus; popup.ItemClicked += popup_ItemClicked; popup.KeyDown += popup_KeyDown; // Make sure that the selected item is visible popup.SelectedIndex = Mathf.Max( 0, this.SelectedIndex ); popup.EnsureVisible( popup.SelectedIndex ); // Make sure that the popup has input focus popup.Focus(); // Notify any listeners that the popup has been displayed if( DropdownOpen != null ) { bool overridden = false; DropdownOpen( this, popup, ref overridden ); } Signal( "OnDropdownOpen", this, popup ); }
public void OpenPopup() { if (popup != null || items.Length == 0) { return; } var popupSize = calculatePopupSize(); // Create the popup list and set all necessary properties popup = GetManager().AddControl <dfListbox>(); popup.name = this.name + " - Dropdown List"; popup.gameObject.hideFlags = HideFlags.DontSave; popup.Atlas = this.Atlas; popup.Anchor = dfAnchorStyle.Left | dfAnchorStyle.Top; popup.Color = this.Color; popup.Font = this.Font; popup.Pivot = dfPivotPoint.TopLeft; popup.Size = popupSize; popup.Font = this.Font; popup.ItemHeight = this.ItemHeight; popup.ItemHighlight = this.ItemHighlight; popup.ItemHover = this.ItemHover; popup.ItemPadding = this.TextFieldPadding; popup.ItemTextColor = this.TextColor; popup.ItemTextScale = this.TextScale; popup.Items = this.Items; popup.ListPadding = this.ListPadding; popup.BackgroundSprite = this.ListBackground; popup.Shadow = this.Shadow; popup.ShadowColor = this.ShadowColor; popup.ShadowOffset = this.ShadowOffset; popup.BringToFront(); // If there is a modal control/window up that displays this dropdown, // need to ensure that it is able to receive input if (dfGUIManager.GetModalControl() != null) { dfGUIManager.PushModal(popup); } if (popupSize.y >= MaxListHeight && listScrollbar != null) { var scrollGO = GameObject.Instantiate(listScrollbar.gameObject) as GameObject; var activeScrollbar = scrollGO.GetComponent <dfScrollbar>(); var p2u = PixelsToUnits(); var right = popup.transform.TransformDirection(Vector3.right); var scrollbarPosition = popup.transform.position + right * (popupSize.x - activeScrollbar.Width) * p2u; popup.AddControl(activeScrollbar); popup.Width -= activeScrollbar.Width; popup.Scrollbar = activeScrollbar; popup.SizeChanged += (control, size) => { activeScrollbar.Height = control.Height; }; activeScrollbar.transform.parent = popup.transform; activeScrollbar.transform.position = scrollbarPosition; activeScrollbar.Anchor = dfAnchorStyle.Top | dfAnchorStyle.Bottom; activeScrollbar.Height = popup.Height; } // Position the dropdown and set its rotation to the same world rotation // as this control var popupPosition = calculatePopupPosition((int)popup.Size.y); popup.transform.position = popupPosition; popup.transform.rotation = this.transform.rotation; // Attach important events popup.SelectedIndexChanged += popup_SelectedIndexChanged; popup.LeaveFocus += popup_LostFocus; popup.ItemClicked += popup_ItemClicked; popup.KeyDown += popup_KeyDown; // Make sure that the selected item is visible popup.SelectedIndex = Mathf.Max(0, this.SelectedIndex); popup.EnsureVisible(popup.SelectedIndex); // Make sure that the popup has input focus popup.Focus(); // Notify any listeners that the popup has been displayed if (DropdownOpen != null) { bool overridden = false; DropdownOpen(this, popup, ref overridden); } Signal("OnDropdownOpen", this, popup); }
public void ClosePopup( bool allowOverride ) { if( popup == null ) return; if( dfGUIManager.GetModalControl() == popup ) { dfGUIManager.PopModal(); } popup.LostFocus -= popup_LostFocus; popup.SelectedIndexChanged -= popup_SelectedIndexChanged; popup.ItemClicked -= popup_ItemClicked; popup.KeyDown -= popup_KeyDown; if( !allowOverride ) { Destroy( popup.gameObject ); popup = null; return; } bool overridden = false; if( DropdownClose != null ) { DropdownClose( this, popup, ref overridden ); } if( !overridden ) { Signal( "OnDropdownClose", this, popup ); } if( !overridden ) { Destroy( popup.gameObject ); } popup = null; }
private static void EditOptions( dfListbox control ) { GUILayout.BeginHorizontal(); { EditorGUILayout.LabelField( "Options", "", GUILayout.Width( 100 ) ); EditorGUI.BeginChangeCheck(); var optionsString = string.Join( "\n", control.Items ); var optionsEdit = EditorGUILayout.TextArea( optionsString, GUILayout.Height( 100f ), GUILayout.MaxWidth( 225 ) ); if( EditorGUI.EndChangeCheck() ) { dfEditorUtil.MarkUndo( control, "Change options" ); var options = optionsEdit.Trim().Split( new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries ); control.Items = options; } } GUILayout.EndHorizontal(); dfEditorUtil.LabelWidth = 100f; }
private void closePopup(bool allowOverride = true) { if (this.popup == null) { return; } this.popup.LostFocus -= new FocusEventHandler(this.popup_LostFocus); this.popup.SelectedIndexChanged -= new PropertyChangedEventHandler<int>(this.popup_SelectedIndexChanged); this.popup.ItemClicked -= new PropertyChangedEventHandler<int>(this.popup_ItemClicked); this.popup.KeyDown -= new KeyPressHandler(this.popup_KeyDown); if (!allowOverride) { UnityEngine.Object.Destroy(this.popup.gameObject); this.popup = null; return; } bool flag = false; if (this.DropdownClose != null) { this.DropdownClose(this, this.popup, ref flag); } if (!flag) { flag = base.Signal("OnDropdownClose", new object[] { this, this.popup }); } if (!flag) { UnityEngine.Object.Destroy(this.popup.gameObject); } this.popup = null; }