// TODO: maybe use endless interfaces so we can request something that is actually a ui thing, eh? public void AddKeyFocus(Trigger key, ZComponent focus, Action onSwitchAction, bool pressAgainToRevert) { RegisterListener(new InputListener(key, x => { onSwitchAction(); currentFocus = focus; focus.Focus(); var escapeListeners = new List <InputListener>(); var escapeTriggers = new List <Trigger>() { Trigger.Escape, Trigger.LeftMouseClick }; if (pressAgainToRevert) { escapeTriggers.Add(key); } foreach (var trigger in escapeTriggers) { var listener = new InputListener(trigger, y => { defaultFocus.Focus(); currentFocus = defaultFocus; foreach (var l in escapeListeners) { focus.UnregisterListener(l); } }); focus.RegisterListener(listener); escapeListeners.Add(listener); } })); }
public CompositionTemplate() { references = new ReferenceDataComponent(); var nameText = new BasicText(); nameText.position = new Vector2(5, 5); Register(references); var tracker = new PointCollectionTracker <Reference>(references, x => { return((TemplateManager.LOADED_TEMPLATES[x.name].GetBoundingBox().Min + TemplateManager.LOADED_TEMPLATES[x.name].GetBoundingBox().Max) / 2 + x.position); }); selector = new Selector <Reference>(new CameraSelectionProvider <Reference>(tracker), x => { referenceOutlines[x].boxColor = Color.Orange; nameText.text = GetSelectedText(selector.selected); }, x => { referenceOutlines[x].boxColor = Color.White; nameText.text = GetSelectedText(selector.selected); }); Register(selector, nameText); RegisterListener(new InputListener(Trigger.E, x => { if (selector.selected.Count != 1) { return; } editMode = true; editingItem = TemplateManager.LOADED_TEMPLATES[selector.selected.Single().name]; editingItem.Focus(); var listener = new InputListener(Trigger.Escape, y => { editingItem.UnregisterListener(y); this.Focus(); RecalculateBoundingBoxes(); editingItem = null; editMode = false; }); editingItem.RegisterListener(listener); })); }