2using System.Collections.Generic;
4using System.Reflection;
5using System.Diagnostics;
8using Microsoft.Xna.Framework;
9using Microsoft.Xna.Framework.Input;
10using Microsoft.Xna.Framework.Graphics;
16 public class CUIFocusResolver
18 private CUIComponent focusedCUIComponent;
19 public CUIComponent FocusedCUIComponent
21 get => focusedCUIComponent;
24 CUIComponent oldFocused = focusedCUIComponent;
25 CUIComponent newFocused = value;
27 if (oldFocused == newFocused)
return;
29 if (oldFocused !=
null)
31 oldFocused.Focused =
false;
32 oldFocused.InvokeOnFocusLost();
35 if (newFocused !=
null)
37 newFocused.Focused =
true;
38 newFocused.InvokeOnFocus();
41 if (oldFocused is IKeyboardSubscriber || newFocused is
null)
43 OnVanillaIKeyboardSubscriberSet(
null,
true);
46 if (newFocused is IKeyboardSubscriber)
48 OnVanillaIKeyboardSubscriberSet((IKeyboardSubscriber)newFocused,
true);
51 focusedCUIComponent = value;
55 public void OnVanillaIKeyboardSubscriberSet(IKeyboardSubscriber value,
bool callFromCUI =
false)
59 KeyboardDispatcher _ = GUI.KeyboardDispatcher;
61 IKeyboardSubscriber oldSubscriber = _._subscriber;
62 IKeyboardSubscriber newSubscriber = value;
64 if (newSubscriber == oldSubscriber) {
return; }
67 if (!callFromCUI && oldSubscriber is CUIComponent && newSubscriber is
null) {
return; }
71 if (oldSubscriber !=
null)
73 TextInput.StopTextInput();
74 oldSubscriber.Selected =
false;
77 if (oldSubscriber is CUIComponent component && newSubscriber is GUITextBox)
80 component.InvokeOnFocusLost();
81 component.Focused =
false;
82 focusedCUIComponent =
null;
85 if (newSubscriber !=
null)
87 if (newSubscriber is GUITextBox box)
89 TextInput.SetTextInputRect(box.MouseRect);
90 TextInput.StartTextInput();
91 TextInput.SetTextInputRect(box.MouseRect);
94 if (newSubscriber is CUIComponent)
96 TextInput.StartTextInput();
99 newSubscriber.Selected =
true;
102 _._subscriber = value;