/// <summary> /// Removes a popup from popup stage /// </summary> /// <param name="popup">A popup to remove</param> public void RemovePopup(DisplayObject popup) { #if TRIAL /* HACK CHECK */ Acme acme = (Acme)Framework.GetComponent <Acme>(true); if (null == acme || !acme.gameObject.activeInHierarchy /*active*/ || !acme.enabled) { return; } #endif #if DEBUG if (DebugMode) { Debug.Log("RemovePopup"); } #endif if (!_descriptors.ContainsKey(popup)) { return; } var descriptor = _descriptors[popup]; //if (popup.HasFocus) // FocusManager.Instance.Blur(); if (HasEventListener(CLOSING)) { Event e = new Event(CLOSING, popup, false, true); // cancelable DispatchEvent(e); if (e.Canceled) { return; } } if (IsDefaultPrevented(CLOSING)) { return; } var stage = descriptor.Stage; //Debug.Log(string.Format(@"Removing {0} from {1}", descriptor.PopupRoot, stage)); // removing children //descriptor.PopupRoot.Parent.RemoveChild(descriptor.PopupRoot); stage.RemoveChild(descriptor.PopupRoot); //Debug.Log("Descriptors remove"); _descriptors.Remove(popup); //FocusManager.Instance.Blur(); // TEMP disabled 2.1.2012. _popups.Remove(popup); if (descriptor.FocusPreviousOnHide) { if (_popups.Count > 0) // we have more opened popups { DisplayObject lastPopup = _popups[_popups.Count - 1]; //Debug.Log("_popups.Count: " + _popups.Count); if (lastPopup is InteractiveComponent) { ((InteractiveComponent)lastPopup).SetFocus(); /*lastPopup.Defer(delegate * { * ((InteractiveComponent)lastPopup).SetFocus(); * }, 1);*/ //FocusManager.Instance.SetFocus((InteractiveComponent)lastPopup); } // TEMP disabled on 2.1.2012. because the overlay popup constantly // appears and dissapears and takes focus // and raises "ArgumentException: You can only call GUI functions from inside OnGUI." // should enable back when overlay will be in it's top stage, non run by popup manager } else // this was the only popup { if (popup is Dialog) { Dialog dlg = (Dialog)popup; if (null != dlg.Owner) { // if owner is defined, focus the owner InteractiveComponent ic = dlg.Owner as InteractiveComponent; /*if (null != ic) * ic.SetFocus();*/ if (null != ic) { //((InteractiveComponent)lastPopup).SetFocus(); /*ic.Defer(delegate * { * //ic.SetFocus(); * FocusManager.Instance.SetFocus(ic); * }, 1);*/ //FocusManager.Instance.SetFocus(ic); ic.SetFocus(); } } //else // FocusManager.Instance.Blur(); // else blur everything // commented 20130331 - because after closing th eallert, the SetFocus te TextField (via the callback) didn't work } } } // disconnect if (_descriptors.Count == 0) { SystemManager.Instance.ResizeSignal.Disconnect(ResizeSlot); SystemManager.Instance.MouseDownSignal.Disconnect(MouseDownSlot); SystemManager.Instance.MouseWheelSignal.Disconnect(MouseWheelSlot); stage.RemoveEventListener(MouseEvent.MOUSE_DOWN, MouseDownHandler); } //Debug.Log("_descriptors.Count: " + _descriptors.Count); //_stage.ValidateNow(); if (HasEventListener(CLOSE)) { DispatchEvent(new Event(CLOSE, popup)); } if (descriptor.Popup != descriptor.PopupRoot) { // this is a modal popup // the removed effect won't play on popup, because PopupRoot is being removed, not the popup // we have to handle this case and play the effect here Component component = popup as Component; if (null != component && component.HasStyle("removedEffect")) { ITweenFactory removeEffect = (ITweenFactory)component.GetStyle("removedEffect"); removeEffect.Play(popup); } } }
private void OnMouseMove(Event e) { #if DEBUG if (DebugMode) { Debug.Log("MouseEventDispatcher.OnMouseMove"); } #endif _mouseEvent = (MouseEvent)e; _pos = _mouseEvent.GlobalPosition; _size = SystemManager.Instance.ScreenSize; if (_pos.X < 0 || _pos.Y < 0 || _pos.X > _size.X || _pos.Y > _size.Y) { if (!_isMouseLeave) { /** * 1) InvalidateDrawingList the event * */ _mouseLeaveEvent = new MouseEvent(MouseEvent.MOUSE_LEAVE) { Target = this, GlobalPosition = _pos }; } _isMouseLeave = true; } else { _isMouseLeave = false; } //Debug.Log("..... will recalculate ..... "); /** * 1) Find (any) component under under mouse * */ RecalculateMouseTarget(); //RecalculateMouseWheelTargets(); //Debug.Log("InspectMode: " + InspectMode); /** * 2) Handle inspector target under mouse * */ if (PlayModeInspect || InspectMode) { RecalculateInspectorTarget(); } if (null != MouseTarget) { #if DEBUG if (DebugMode) { Debug.Log("OnMouseMove component: " + MouseTarget); } #endif MouseEventHelper.BuildAndDispatchMouseEvent(this, MouseTarget, MouseEvent.MOUSE_MOVE, _mouseEvent.GlobalPosition, _mouseEvent.CurrentEvent); } if (MouseTarget != _previousMouseOveredComponent || _isMouseLeave) { if (null != _previousMouseOveredComponent) { MouseEventHelper.BuildAndDispatchMouseEvent(this, _previousMouseOveredComponent, MouseEvent.MOUSE_OUT, _mouseEvent.GlobalPosition, _mouseEvent.CurrentEvent); //Debug.Log("MOUSE_OUT: " + _previousMouseOveredComponent); _hasBeenMouseOut = true; string cursorStyle = (string)_previousMouseOveredComponent.GetStyle("cursor"); if (!string.IsNullOrEmpty(cursorStyle)) { CursorManager.Instance.RemoveCursor(_currentCursorId); } } if (MouseTarget != null) { /** * MOUSE OVER * */ if (!_hasBeenMouseDown && 0 != MouseTarget.HotControlId) { //GUIUtility.hotControl = MouseTarget.HotControlId; //Debug.Log("GUIUtility.hotControl: " + GUIUtility.hotControl); } MouseEventHelper.BuildAndDispatchMouseEvent(this, MouseTarget, MouseEvent.MOUSE_OVER, _mouseEvent.GlobalPosition, _mouseEvent.CurrentEvent); string cursorStyle = (string)MouseTarget.GetStyle("cursor"); if (!string.IsNullOrEmpty(cursorStyle)) { _currentCursorId = CursorManager.Instance.SetCursor(cursorStyle, CursorPriority.Low); } //Debug.Log("_previousMouseOveredComponent: " + _previousMouseOveredComponent); //Debug.Log("_rollOveredComponents.Count: " + _rollOveredComponents.Count); foreach (Component comp in _rollOveredComponents.Keys) { // this is the component subscribed to rollover events _shouldDispatchRollOver = false; _shouldDispatchRollOut = false; /** * 1) Both components are the child of this parent * From parent's point of view, there has been no rollover nor rollout * */ if (comp.Contains(MouseTarget, true) && null != _previousMouseOveredComponent && comp.Contains(_previousMouseOveredComponent, true)) { // do nothing continue; } /** * 2) Component child has been mouseovered. * The component has not been in rollovered state. * Dispatch ROLL_OVER. * */ if (comp.Contains(MouseTarget, true) && !_rollOveredComponents[comp]) { _shouldDispatchRollOver = true; _rollOveredComponentsToChangeState.Add(comp); } /** * 3) Component child has been mouseouted. * New mouseovered component is not a child of this component, and component has been in rollovered state. * Dispatch ROLL_OUT. * */ else if (null != _previousMouseOveredComponent && comp.Contains(_previousMouseOveredComponent, true) && _rollOveredComponents[comp]) { _shouldDispatchRollOut = true; _rollOveredComponentsToChangeState.Add(comp); } // rethink once again // check if there has been a mouse out and no mouse in (blank Stage example) //else if (_hasBeenMouseOut)// && !_shouldDispatchRollOut) //{ // Debug.Log("_hasBeenMouseOut"); // _shouldDispatchRollOut = true; // _rollOveredComponentsToChangeState.Add(comp); //} if (_shouldDispatchRollOut) { #if DEBUG if (DebugMode) { Debug.Log("Dispatching ROLL_OUT: " + comp); } #endif MouseEventHelper.BuildAndDispatchMouseEvent(this, comp, MouseEvent.ROLL_OUT, _mouseEvent.GlobalPosition, _mouseEvent.CurrentEvent); } else if (_shouldDispatchRollOver) { #if DEBUG if (DebugMode) { Debug.Log("Dispatching ROLL_OVER: " + comp); } #endif MouseEventHelper.BuildAndDispatchMouseEvent(this, comp, MouseEvent.ROLL_OVER, _mouseEvent.GlobalPosition, _mouseEvent.CurrentEvent); } } } // new mouse target is null else if (_hasBeenMouseOut || _isMouseLeave) { foreach (Component comp in _rollOveredComponents.Keys) { /** * * */ if (null != _previousMouseOveredComponent && comp.Contains(_previousMouseOveredComponent, true) && _rollOveredComponents[comp]) { #if DEBUG if (DebugMode) { Debug.Log("Dispatching ROLL_OUT (special): " + comp); } #endif _rollOveredComponentsToChangeState.Add(comp); MouseEventHelper.BuildAndDispatchMouseEvent(this, comp, MouseEvent.ROLL_OUT, _mouseEvent.GlobalPosition, _mouseEvent.CurrentEvent); } } } } _rollOveredComponentsToChangeState.ForEach(delegate(Component changing) { _rollOveredComponents[changing] = !_rollOveredComponents[changing]; }); _rollOveredComponentsToChangeState.Clear(); _previousMouseOveredComponent = MouseTarget; _hasBeenMouseOut = false; if (null != _mouseLeaveEvent) { /** * 2) Dispatch from manager * */ DispatchEvent(_mouseLeaveEvent); } }