Last active
April 3, 2024 23:49
-
-
Save Schroedi/9b7cc4e545e19e95facf76c63a69d5b2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Automate the settings window for debugging | |
// e.a. automatically expand the Plugins section and select the plugin you are currently working on | |
public void Initialize() | |
{ | |
LokiPoe.OnGuiTick += OnGuiTickEvent; | |
} | |
private static void OnGuiTickEvent(object sender, GuiTickEventArgs e) | |
{ | |
if (!LokiPoe.IsBotFullyLoaded) | |
return; | |
var settingsWin = Application.Current.Windows.FirstOrDefault<Window>(w=> w.Title.ToLower() == "settings"); | |
if (settingsWin?.IsVisible == false) | |
return; | |
LokiPoe.OnGuiTick -= OnGuiTickEvent; | |
var found = false; | |
// we have to update the tree after each expansion | |
for (int i = 0; i < 3 && !found; i++) | |
{ | |
var settingsTree = Wpf.FindControlByName<ItemsControl>(settingsWin, "NewSettingsTreeView"); | |
ApplyTree(settingsTree, i => | |
{ | |
if (i.Header.ToString() == "Plugins") | |
i.IsExpanded = true; | |
if (i.Header.ToString() == "Routines") | |
i.IsExpanded = true; | |
// Select a plugin to show it's settings | |
// it only works reliably when we expand the section first | |
if (i.Header.ToString().Contains("Expeditor")) | |
{ | |
i.IsSelected = true; | |
found = true; | |
} | |
}); | |
// wait for tree to update | |
Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() => { })); | |
} | |
} | |
private static void ApplyTree(ItemsControl items, Action<TreeViewItem> f) | |
{ | |
foreach (var obj in items.Items) | |
{ | |
ItemsControl childControl = items.ItemContainerGenerator.ContainerFromItem(obj) as ItemsControl; | |
if (childControl != null) | |
{ | |
ApplyTree(childControl, f); | |
} | |
TreeViewItem item = childControl as TreeViewItem; | |
if (item != null) | |
f(item); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment