/// <summary> /// Invoked when an unhandled Mouse.MouseMove attached event reaches an element in its route that is derived from this class. /// </summary> /// <param name="e">The MouseEventArgs that contains the event data.</param> protected override void OnMouseMove(MouseEventArgs e) { // Validate the parameters. if (e == null) { throw new ArgumentNullException("e"); } // This will highlight (and bring comletely into view) the element underneath the mouse. There is a verion of this in the WPF ComboBox that waits for a // MouseEnter event from the element and then tries to figure out if mouse movement caused the event. This is cumbersome because a MouseEnter event can // be caused by the mouse being moved over the element, or the element being scrolled underneath the mouse. An element being scrolled underneath a // mouse that hasn't moved can cause a false highlighting of the element, so a whole 'nuther set of logic was required to see if the mouse had actually // moved. Since this event assumes that the mouse has moved, it is simpler just to find out what element is under the mouse and change the highlight if // it wasn't the last thing highlighted. DependencyObject dependencyObject = this.InputHitTest(e.GetPosition(this)) as DependencyObject; HighlightElement highlightElement = VisualTreeExtensions.FindAncestor <HighlightElement>(dependencyObject); if (highlightElement != this.HighlightedElement) { highlightElement.BringIntoView(); this.HighlightedElement = highlightElement; } // Because an intermediate class in the inheritance might implement this method, we recommend that you call the base implementation in your // implementation. base.OnMouseMove(e); }
/// <summary> /// Moves the highlight by a line in the direction specified. /// </summary> /// <param name="focusNavigationDirection">The direction in which to move the highlight.</param> internal void MoveByLine(FocusNavigationDirection focusNavigationDirection) { // The highlight selector never gets the focus. Instead, it simulates the focus property with a 'highlighted' property that provides visual feedback to // the user of the item that would be selected if they hit the mouse button or enter key. This allows the edit control to get all the keystrokes with // the exception of the few that generate commands for the highlight selector. One of those commands is to move the selection and highlight by a single // line. This will use the 'PredictFocus' to find the next element in the direction of navigation. The next item will get the highlight instead of the // focus in this paradigm. UIElement navigationStart = this.HighlightedElement == null ? (UIElement)this : (UIElement)this.HighlightedElement; HighlightElement nextElement = navigationStart.PredictFocus(focusNavigationDirection) as HighlightElement; if (nextElement == null) { // Clearing the selection when wrapping is enabled will trigger that informs the listener that the selection has been cleared. The listening // object can elect what to do. For example, the listener could choose to move the navigation to the start of the window or clear out some other // control that is linked to this selection. When wrapping is not enabled, the selection will reach the end of the container and just stay there // no matter how many times the navigation arrows are pressed. if (this.SelectionWrapping == SelectionWrapping.Wrap) { this.HighlightedElement = null; this.OnSelectionWrapped(new RoutedEventArgs(HighlightSelector.SelectionWrappedEvent, this)); } } else { // This will bring the element into view, highlight it and select it. The selection will trigger an event that the owner window can watch for to // take some action, like fill in another control with the selected item. It is the selection and not the highlight that determine which object is // chosen by the user. So even though visually an item has a highlight, when they choose an action it is the selected item that provides a value // from this control. nextElement.BringIntoView(); this.HighlightedElement = nextElement; this.SelectedElement = nextElement; } }
private void PutInPool(HighlightElement element) { _activeHighlights.Remove(element); element.transform.SetParent(null); element.gameObject.SetActive(false); _highlightPool.Add(element); }
/// <summary> /// Called from the item to indicate that the mouse was released while over an item. /// </summary> /// <param name="highlightElement">The element that caused the event.</param> internal void NotifyHighlightItemSelect(HighlightElement highlightElement) { // Selecting an item with the mouse will close the highlight drop down and exit out of the editing mode. this.SelectedElement = highlightElement; // This will bubble the event up the element tree until someone cares enough to act on it. this.OnClicked(new RoutedEventArgs(HighlightSelector.ClickedEvent)); }
private void HighlightSpriteInternal(SpriteRenderer spriteRenderer, Params param) { if (spriteRenderer == null) { Log.Error($"{nameof(spriteRenderer)} is null."); return; } HighlightElement newHighlight = TakeFromPool(); Transform tr = newHighlight.transform; tr.SetParent(spriteRenderer.transform); tr.localPosition = Vector3.zero; tr.localRotation = Quaternion.identity; tr.localScale = Vector3.one; newHighlight.SetSprite(spriteRenderer.sprite, spriteRenderer.flipX, spriteRenderer.flipY); newHighlight.SetColor(param.Color); newHighlight.OnDestroyAction = OnHighlightDestroyed; newHighlight.OnCompleteAction = PutInPool; newHighlight.Target = spriteRenderer; float intensityValue; switch (param.Intensity) { default: case Intensity.Normal: intensityValue = _normalIntensity; break; case Intensity.High: intensityValue = _highIntensity; break; } float loopDuration; switch (param.FlickerSpeed) { default: case FlickerSpeed.Slow: loopDuration = _slowLoopDuration; break; case FlickerSpeed.Fast: loopDuration = _fastLoopDuration; break; } bool startMidway = param.AnimStart == AnimStart.MidHighlight; switch (param.Duration) { case Duration.Short: newHighlight.Play(intensityValue, loopDuration, _shortLoops, startMidway); break; case Duration.Long: newHighlight.Play(intensityValue, loopDuration, _longLoops, startMidway); break; case Duration.UntilManuallyStopped: newHighlight.Play(intensityValue, loopDuration, startMidway); break; } }
private void OnHighlightDestroyed(HighlightElement element) { _activeHighlights.Remove(element); _highlightPool.Remove(element); }
private DialogueElement CreateDialogueGUI(VisualElement root, ConversationRow conversation, DialogueRow dialogue, IList <ContentElement> contents, string language) { var dialogueElem = new DialogueElement(); var idElem = new IdElement { value = dialogue.Id }; dialogueElem.Header.Add(idElem); var defaultChoiceData = dialogue.GetChoice(0); if (defaultChoiceData != null) { CreateDefaultChoiceGUI(dialogueElem, conversation, defaultChoiceData, contents, language); } if (dialogue.Choices.Count > 1) { var choiceContainer = new ChoiceContainer(); choiceContainer.Add(new Label("Choices")); var first = true; foreach (var kv in dialogue.Choices) { if (kv.Value.Id == 0) { continue; } var choiceElem = CreateChoiceGUI(choiceContainer, conversation, kv.Value, contents, language); if (first) { first = false; choiceElem.style.marginTop = 0; } } dialogueElem.Add(choiceContainer); } if (!dialogue.IsEnd()) { var sb = new StringBuilder(); var delayElem = new DelayElement("Delay") { value = dialogue.Delay.ToString() }; dialogueElem.Add(delayElem); var speakerElem = new SpeakerElement("Speaker") { value = dialogue.Speaker }; dialogueElem.Add(speakerElem); if (HasActors(dialogue)) { CreateCharacterTableGUI(dialogueElem, out var columnContainerElem); CreateCharacterList <ActorColumnElement>(columnContainerElem, "Actor", dialogue.Actor1, dialogue.Actor2, dialogue.Actor3, dialogue.Actor4); CreateCharacterList <ActionColumnElement>(columnContainerElem, "Actions", dialogue.Actions1.BuildString(sb), dialogue.Actions2.BuildString(sb), dialogue.Actions3.BuildString(sb), dialogue.Actions4.BuildString(sb)); } var highlightElem = new HighlightElement("Highlight") { value = dialogue.Highlight.BuildString(sb) }; dialogueElem.Add(highlightElem); } if (dialogue.CommandsOnStart.Count > 0 || dialogue.CommandsOnEnd.Count > 0) { CreateCommandTableGUI(dialogueElem, dialogue.CommandsOnStart, dialogue.CommandsOnEnd); } root.Add(dialogueElem); return(dialogueElem); }