private void AddAllowedStashTabNode(StashTabNode node) { var deleteTabButton = new ButtonNode(); var deleteTabButtonDrawer = new ButtonSettingDrawer(deleteTabButton, "Delete", GetUniqDrawerId()); AllowedStashTabsRoot.Children.Insert(AllowedStashTabsRoot.Children.Count - 1, deleteTabButtonDrawer); var buttonSameLineDrawer = new SameLineSettingDrawer("", GetUniqDrawerId());//Delete button and stash node should be on same line AllowedStashTabsRoot.Children.Insert(AllowedStashTabsRoot.Children.Count - 1, buttonSameLineDrawer); var stashNodeDrawer = new StashTabNodeSettingDrawer(node, "", GetUniqDrawerId()); AllowedStashTabsRoot.Children.Insert(AllowedStashTabsRoot.Children.Count - 1, stashNodeDrawer);//AllowedStashTabsRoot.Children.Count - 1, deleteTabButton.OnPressed += delegate { //Delete stash node related drawers AllowedStashTabsRoot.Children.Remove(deleteTabButtonDrawer); AllowedStashTabsRoot.Children.Remove(buttonSameLineDrawer); AllowedStashTabsRoot.Children.Remove(stashNodeDrawer); Settings.AllowedStashTabs.Remove(stashNodeDrawer.StashNode); StashTabController.UnregisterStashNode(stashNodeDrawer.StashNode);//No sence to update data in deleted stash node }; StashTabController.RegisterStashNode(node); }
public bool SwitchToTab(StashTabNode tabNode) { var stashPanel = _ingameState.ServerData.StashPanel; // We don't want to Switch to a tab that we are already on if (stashPanel.IndexVisibleStash == tabNode.VisibleIndex) { return(true); } if (!_playerHasDropdownMenu) { return(SwitchToTabViaArrowKeys(tabNode)); } var indexOfVisibleStash = stashPanel.IndexVisibleStash; var travelDistance = Math.Abs(tabNode.VisibleIndex - indexOfVisibleStash); if (tabNode.VisibleIndex > 30 && indexOfVisibleStash < 30) { SwitchToTab(new StashTabNode { VisibleIndex = 30 }); return(SwitchToTabViaArrowKeys(tabNode)); } if (travelDistance > 3) { return(SwitchToTabViaDropdownMenu(tabNode)); } return(SwitchToTabViaArrowKeys(tabNode)); }
public override void InitializeSettingsMenu() { base.InitializeSettingsMenu(); AllowedStashTabsRoot = new CheckboxSettingDrawer(Settings.OnlyAllowedStashTabs, "Allowed Stash Tabs", GetUniqDrawerId()); SettingsDrawers.Add(AllowedStashTabsRoot); //Adding checkbox to settings menu drawers var addTabButton = new ButtonNode(); var addTabButtonDrawer = new ButtonSettingDrawer(addTabButton, "Add Stash Tab", GetUniqDrawerId()); AllowedStashTabsRoot.Children.Add(addTabButtonDrawer); addTabButton.OnPressed += delegate { var newNode = new StashTabNode(); AddAllowedStashTabNode(newNode); Settings.AllowedStashTabs.Add(newNode); }; foreach (var node in Settings.AllowedStashTabs) { AddAllowedStashTabNode(node); } }
private bool SwitchToTabViaArrowKeys(StashTabNode tabNode) { var latency = (int)_ingameState.CurLatency; var indexOfCurrentVisibleTab = _ingameState.ServerData.StashPanel.IndexVisibleStash; var difference = tabNode.VisibleIndex - indexOfCurrentVisibleTab; var tabIsToTheLeft = difference < 0; for (var i = 0; i < Math.Abs(difference); i++) { Keyboard.KeyPress(tabIsToTheLeft ? Keys.Left : Keys.Right); Thread.Sleep(latency); } return(true); }
private void StashTabRenameRegistered(StashTabNode tab, string newName) { if (MainMenuWindow.Settings.DeveloperMode.Value) { DebugPlug.DebugPlugin.LogMsg($"StashTabRenameRegistered: Name: {tab.Name} {tab.Name} -> {newName}", 2); } SubscribedNodes.Where(x => x.Exist && x.Id == tab.Id).ToList().ForEach(x => x.Name = newName); try { OnStashTabRenameRegistered(tab, newName); } catch (Exception ex) { DebugPlug.DebugPlugin.LogMsg($"StashTabController: Error in OnStashTabRenameRegistered event: {ex.Message}", 5); } }
public static void RegisterStashNode(StashTabNode node) { if (node == null) { DebugPlug.DebugPlugin.LogMsg($"StashTabController: You are trying to register null StashTabNode", 4, Color.Yellow); return; } if (SubscribedNodes.Contains(node)) { DebugPlug.DebugPlugin.LogMsg($"StashTabController: StashTabNode is already registered (TabName: {node.Name}, VisibleIndex: {node.VisibleIndex})", 4, Color.Yellow); return; } SubscribedNodes.Add(node); UpdateRegisteredNode(node); }
private List <StashTabNode> StashTabNodes = new List <StashTabNode>(); //This is for hot reload, we will unload it private void GenerateStashieSettingsMenu() //Separate func cuz we can call it in anu moment to reload all menu { if (FiltersMenuRootMenu != null) { SettingsDrawers.Remove(FiltersMenuRootMenu); } if (RefillMenuRootMenu != null) { SettingsDrawers.Remove(RefillMenuRootMenu); } FiltersMenuRootMenu = new BaseSettingsDrawer("Filters", GetUniqDrawerId()); SettingsDrawers.Add(FiltersMenuRootMenu); var submenu = new Dictionary <string, BaseSettingsDrawer>(); foreach (var customFilter in _customFilters) { if (!Settings.FilterOptions.TryGetValue(customFilter.Name, out var tabNode)) { tabNode = new StashTabNode(); Settings.FilterOptions.Add(customFilter.Name, tabNode); } StashTabNodes.Add(tabNode); StashTabController.RegisterStashNode(tabNode); var filterParent = FiltersMenuRootMenu; if (!string.IsNullOrEmpty(customFilter.SubmenuName)) { if (!submenu.TryGetValue(customFilter.SubmenuName, out filterParent)) { filterParent = new BaseSettingsDrawer(customFilter.SubmenuName, GetUniqDrawerId()); FiltersMenuRootMenu.Children.Add(filterParent); submenu.Add(customFilter.SubmenuName, filterParent); } } filterParent.Children.Add(new StashTabNodeSettingDrawer(tabNode, customFilter.Name, GetUniqDrawerId())); customFilter.StashIndexNode = tabNode; } RefillMenuRootMenu = new CheckboxSettingDrawer(Settings.RefillCurrency, "Refill Currency", GetUniqDrawerId()); SettingsDrawers.Add(RefillMenuRootMenu); RefillMenuRootMenu.Children.Add(new StashTabNodeSettingDrawer(Settings.CurrencyStashTab, "Currency Tab", GetUniqDrawerId())); StashTabController.RegisterStashNode(Settings.CurrencyStashTab); RefillMenuRootMenu.Children.Add(new CheckboxSettingDrawer(Settings.AllowHaveMore, "Allow Have More", GetUniqDrawerId())); var refillRoot = new BaseSettingsDrawer("Refills:", GetUniqDrawerId()); RefillMenuRootMenu.Children.Add(refillRoot); var addTabButton = new ButtonNode(); var addTabButtonDrawer = new ButtonSettingDrawer(addTabButton, "Add Refill", GetUniqDrawerId()); RefillMenuRootMenu.Children.Add(addTabButtonDrawer); addTabButton.OnPressed += delegate { var newRefill = new RefillProcessor(); AddRefill(newRefill); Settings.Refills.Add(newRefill); }; foreach (var refill in Settings.Refills) { AddRefill(refill); } }
public bool SwitchToTabViaDropdownMenu(StashTabNode tabNode) { var latency = (int)_ingameState.CurLatency; var stashPanel = _ingameState.ServerData.StashPanel; var stashCount = 0; // We want to maximum wait 20 times the Current Latency before giving up in our while loops. var maxNumberOfTries = latency * 20 > 2000 ? latency * 20 / WHILE_DELAY : 2000 / WHILE_DELAY; try { var viewAllTabsButton = _ingameState.ServerData.StashPanel.ViewAllStashButton; if (stashPanel.IsVisible && !viewAllTabsButton.IsVisible) { return(SwitchToTabViaArrowKeys(tabNode)); } var dropdownMenu = _ingameState.ServerData.StashPanel.ViewAllStashPanel; if (!dropdownMenu.IsVisible) { var pos = viewAllTabsButton.GetClientRect(); Mouse.SetCursorPosAndLeftClick(pos.Center, Settings.ExtraDelay, _windowOffset); // Make sure that we are scrolled to the top in the menu. if (_ingameState.ServerData.StashPanel.TotalStashes > 30) { Thread.Sleep(WHILE_DELAY); Mouse.VerticalScroll(true, 10); Thread.Sleep(WHILE_DELAY); Mouse.VerticalScroll(true, 10); } } // Dropdown menu have the following children: 0, 1, 2. // Where: // 0 is the icon (fx. chaos orb). // 1 is the name of the tab. // 2 is the slider. var slider = dropdownMenu.Children[1].ChildCount == _ingameState.ServerData.StashPanel.TotalStashes; var noSlider = dropdownMenu.Children[2].ChildCount == _ingameState.ServerData.StashPanel.TotalStashes; RectangleF tabPos; if (slider) { tabPos = dropdownMenu.GetChildAtIndex(1).GetChildAtIndex(tabNode.VisibleIndex).GetClientRect(); } else if (noSlider) { tabPos = dropdownMenu.GetChildAtIndex(2).GetChildAtIndex(tabNode.VisibleIndex).GetClientRect(); } else { LogMessage("Couldn't detect steam/non-steam, contact administrator", 3); return(false); //tabPos = dropdownMenu.GetChildAtIndex(tabNode.VisibleIndex).GetChildAtIndex(1).GetClientRect(); } Mouse.SetCursorPosAndLeftClick(tabPos.Center, Settings.ExtraDelay, _windowOffset); Thread.Sleep(latency); } catch (Exception e) { LogError($"Error in GoToTab {tabNode.Name}: {e.Message}", 5); return(false); } Inventory stash; var counter = 0; do { Thread.Sleep(WHILE_DELAY); stash = stashPanel.VisibleStash; if (counter++ <= maxNumberOfTries) { continue; } LogMessage( $"2. Error opening stash : {tabNode.Name}. Inventory type is: {stash.InvType.ToString()}", 5); return(false); } while (stash?.VisibleInventoryItems == null); return(true); }
public bool SwitchToTabViaDropdownMenu(StashTabNode tabNode) { var latency = (int)_ingameState.CurLatency; var stashPanel = _ingameState.ServerData.StashPanel; // We want to maximum wait 20 times the Current Latency before giving up in our while loops. var maxNumberOfTries = latency * 20 > 2000 ? latency * 20 / WHILE_DELAY : 2000 / WHILE_DELAY; try { var viewAllTabsButton = _ingameState.ServerData.StashPanel.ViewAllStashButton; if (stashPanel.IsVisible && !viewAllTabsButton.IsVisible) { return(SwitchToTabViaArrowKeys(tabNode)); } var dropdownMenu = _ingameState.ServerData.StashPanel.ViewAllStashPanel; if (!dropdownMenu.IsVisible) { var pos = viewAllTabsButton.GetClientRect(); Mouse.SetCursorPosAndLeftClick(pos.Center, Settings.ExtraDelay, _windowOffset); var brCounter = 0; while (!dropdownMenu.IsVisible) { Thread.Sleep(WHILE_DELAY); if (brCounter++ <= maxNumberOfTries) { continue; } LogMessage($"Error in SwitchToTabViaDropdownMenu({tabNode.Name}).", 5); return(false); } // Make sure that we are scrolled to the top in the menu. if (_ingameState.ServerData.StashPanel.TotalStashes > 30) { Thread.Sleep(WHILE_DELAY); Mouse.VerticalScroll(true, 10); Thread.Sleep(WHILE_DELAY); Mouse.VerticalScroll(true, 10); } } var tabPos = dropdownMenu.Children[tabNode.VisibleIndex].GetClientRect(); Mouse.SetCursorPosAndLeftClick(tabPos.Center, Settings.ExtraDelay, _windowOffset); Thread.Sleep(latency); } catch (Exception e) { LogError($"Error in GoToTab {tabNode.Name}: {e.Message}", 5); return(false); } Inventory stash; var counter = 0; do { Thread.Sleep(WHILE_DELAY); stash = stashPanel.VisibleStash; if (counter++ <= maxNumberOfTries) { continue; } LogMessage( $"2. Error opening stash : {tabNode.Name}. Inventory type is: {stash.InvType.ToString( )}", 5); return(false); } while (stash?.VisibleInventoryItems == null); return(true); }
public FilterResult(StashTabNode stashNode, ItemData itemData) { StashNode = stashNode; ClickPos = itemData.GetClickPos(); }
private static void UpdateRegisteredNode(StashTabNode node) { StashTabNode foundNode = null; bool foundMulptiple = false; List <StashTabNode> searchResults = new List <StashTabNode>(); if (node.Name == StashTabNode.EMPTYNAME) { goto NotFound; } searchResults = CachedStashTabs.Where(x => x.Name == node.Name).ToList(); if (searchResults.Count > 1) { searchResults = searchResults.Where(x => !x.IsRemoveOnly).ToList();//For same names on standard } if (searchResults.Count == 0) { goto NotFound; } if (searchResults.Count == 1) { foundNode = searchResults[0]; goto Found; } foundMulptiple = true; var searchResults2 = searchResults.Where(x => x.VisibleIndex == node.VisibleIndex).ToList(); if (searchResults2.Count == 1) { foundNode = searchResults2[0]; goto Found; } searchResults2 = searchResults.Where(x => x.Id == node.Id).ToList();//will work on same league/account if (searchResults2.Count == 1) { foundNode = searchResults2[0]; goto Found; } else { goto NotFound; } Found: node.Id = foundNode.Id; node.VisibleIndex = foundNode.VisibleIndex; node.IsRemoveOnly = foundNode.IsRemoveOnly; node.Exist = true; return; NotFound: if (node.Name != StashTabNode.EMPTYNAME) { if (foundMulptiple) { DebugPlug.DebugPlugin.LogMsg($"StashTabController: Found multiple stash tabs ({searchResults.Count}) with name: {node.Name}. Can't select single one due to differend positions. It will be ignored in all plugins using this tab.", 5); } else { DebugPlug.DebugPlugin.LogMsg($"StashTabController: Can't find stash tab with name: {node.Name}. It will be ignored in all plugins using this tab.", 5); } } node.Id = -1; node.Exist = false; return; }
public static void UnregisterStashNode(StashTabNode node) { SubscribedNodes.Remove(node); }
public StashTabNodeSettingDrawer(StashTabNode stashNode, string settingName, int settingId) : base(settingName, settingId) => StashNode = stashNode;