Ejemplo n.º 1
0
        public override Job Tick()
        {
            SetFollowerModeValues();
            _currentTime = DateTime.UtcNow;

            if (Input.GetKeyState(Keys.Escape))
            {
                _followerCoroutine.Pause();
                _networkActivityCoroutine.Pause();
                _followerShouldWork         = false;
                _networkCoroutineShouldWork = false;
                if (_httpListener.IsListening)
                {
                    LogMessage($"****** Tick: stopping the listener ", 1);
                    _httpListener.Stop();
                }
            }

            ;

            if (Input.GetKeyState(Settings.NetworkActivityPropagateWorkingChangeKey.Value))
            {
                ChangeNetworkActivityPropagateWorking();
            }

            if (Input.GetKeyState(Settings.NetworkActivityPropagateAggressivenessModeChangeKey.Value))
            {
                ChangeAggressivenessModeToPropagate();
            }

            if (Input.GetKeyState(Settings.NetworkActivityPropagateEnterInstanceKey.Value))
            {
                EnterInstancePropagate();
            }

            if (Input.GetKeyState(Settings.NetworkActivityActivateKey.Value))
            {
                // LogMessage($"****** Tick: resuming _networkActivityCoroutine", 1);
                _networkCoroutineShouldWork = true;
                _networkActivityCoroutine.Resume();
            }

            if (Input.GetKeyState(Settings.FollowerActivateKey.Value))
            {
                if (_networkActivityCoroutine.Running)
                {
                    LogMessage(
                        $"****** You tried to start the follower activity when network activity is running. Stop network activity first",
                        1);
                    LogMessage($"****** Skipping starting the follower activity ", 1);
                    return(null);
                }

                _debugTimer.Restart();
                _followerCoroutine.Resume();
                _followerShouldWork = true;
            }

            return(null);
        }
Ejemplo n.º 2
0
        private IEnumerator FindItemToPick()
        {
            if (!GameController.Window.IsForeground())
            {
                yield break;
            }
            if (UpdateCacheList.Value == null)
            {
                yield break;
            }
            var window    = GameController.Window.GetWindowRectangleTimeCache;
            var rect      = new RectangleF(window.X, window.X, window.X + window.Width, window.Y + window.Height);
            var playerPos = GameController.Player.GridPos;

            GameController.Debug["PickIt"] = UpdateCacheList?.Value;
            var rectangleOfGameWindow = GameController.Window.GetWindowRectangleTimeCache;

            rectangleOfGameWindow.Inflate(-36, -36);
            var pickUpThisItem = UpdateCacheList?.Value.FirstOrDefault(x =>
                                                                       DoWePickThis(x) && x.Distance < Settings.PickupRange && x.GroundItem != null &&
                                                                       rectangleOfGameWindow.Intersects(new RectangleF(x.LabelOnGround.Label.GetClientRectCache.Center.X,
                                                                                                                       x.LabelOnGround.Label.GetClientRectCache.Center.Y, 3, 3)) && Misc.CanFitInventory(x));

            if (Input.GetKeyState(Settings.PickUpKey.Value) ||
                CanLazyLoot() && ShouldLazyLoot(pickUpThisItem))
            {
                yield return(TryToPickV2(pickUpThisItem));

                FullWork = true;
            }
        }
Ejemplo n.º 3
0
        public override Job Tick()
        {
            if (GameController.Game.IngameState.ServerData.PlayerInventories.Count == 0)
            {
                return(null);
            }

            InventoryItems = GameController.Game.IngameState.ServerData.PlayerInventories[0].Inventory;
            inventorySlots = Misc.GetContainer2DArray(InventoryItems);
            DrawIgnoredCellsSettings();
            if (Input.GetKeyState(Settings.LazyLootingPauseKey))
            {
                DisableLazyLootingTill = DateTime.Now.AddSeconds(2);
            }
            if (Input.GetKeyState(Keys.Escape))
            {
                pickItCoroutine.Pause();
            }

            if (Input.GetKeyState(Settings.PickUpKey.Value) ||
                CanLazyLoot())
            {
                DebugTimer.Restart();

                if (pickItCoroutine.IsDone)
                {
                    var firstOrDefault = Core.ParallelRunner.Coroutines.FirstOrDefault(x => x.OwnerName == nameof(PickIt));

                    if (firstOrDefault != null)
                    {
                        pickItCoroutine = firstOrDefault;
                    }
                }

                pickItCoroutine.Resume();
                FullWork = false;
            }
            else
            {
                if (FullWork)
                {
                    pickItCoroutine.Pause();
                    DebugTimer.Reset();
                }
            }

            if (DebugTimer.ElapsedMilliseconds > 300)
            {
                FullWork = true;
                //LogMessage("Error pick it stop after time limit 300 ms", 1);
                DebugTimer.Reset();
            }
            //Graphics.DrawText($@"PICKIT :: Debug Tick Timer ({DebugTimer.ElapsedMilliseconds}ms)", new Vector2(100, 100), FontAlign.Left);
            //DebugTimer.Reset();

            return(null);
        }
Ejemplo n.º 4
0
        private IEnumerator FindItemToPick()
        {
            if (!GameController.Window.IsForeground())
            {
                yield break;
            }
            var window    = GameController.Window.GetWindowRectangleTimeCache;
            var rect      = new RectangleF(window.X, window.X, window.X + window.Width, window.Y + window.Height);
            var playerPos = GameController.Player.GridPos;

            List <CustomItem> currentLabels;
            var morphPath = "Metadata/MiscellaneousObjects/Metamorphosis/MetamorphosisMonsterMarker";

            if (Settings.UseWeight)
            {
                currentLabels = GameController.Game.IngameState.IngameUi.ItemsOnGroundLabels
                                .Where(x => x.Address != 0 &&
                                       x.ItemOnGround?.Path != null &&
                                       x.IsVisible && x.Label.GetClientRectCache.Center.PointInRectangle(rect) &&
                                       x.CanPickUp && (x.MaxTimeForPickUp.TotalSeconds <= 0) || x.ItemOnGround?.Path == morphPath)
                                .Select(x => new CustomItem(x, GameController.Files,
                                                            x.ItemOnGround.DistancePlayer, _weightsRules, x.ItemOnGround?.Path == morphPath))
                                .OrderByDescending(x => x.Weight).ThenBy(x => x.Distance).ToList();
            }
            else
            {
                currentLabels = GameController.Game.IngameState.IngameUi.ItemsOnGroundLabels
                                .Where(x => x.Address != 0 &&
                                       x.ItemOnGround?.Path != null &&
                                       x.IsVisible && x.Label.GetClientRectCache.Center.PointInRectangle(rect) &&
                                       x.CanPickUp && (x.MaxTimeForPickUp.TotalSeconds <= 0) || x.ItemOnGround?.Path == morphPath)
                                .Select(x => new CustomItem(x, GameController.Files,
                                                            x.ItemOnGround.DistancePlayer, _weightsRules, x.ItemOnGround?.Path == morphPath))
                                .OrderBy(x => x.Distance).ToList();
            }

            GameController.Debug["PickIt"] = currentLabels;
            var rectangleOfGameWindow = GameController.Window.GetWindowRectangleTimeCache;

            rectangleOfGameWindow.Inflate(-36, -36);
            var pickUpThisItem = currentLabels.FirstOrDefault(x =>
                                                              DoWePickThis(x) && x.Distance < Settings.PickupRange && x.GroundItem != null &&
                                                              rectangleOfGameWindow.Intersects(new RectangleF(x.LabelOnGround.Label.GetClientRectCache.Center.X,
                                                                                                              x.LabelOnGround.Label.GetClientRectCache.Center.Y, 3, 3)) && Misc.CanFitInventory(x));

            if (Input.GetKeyState(Settings.PickUpKey.Value) ||
                CanLazyLoot() && ShouldLazyLoot(pickUpThisItem))
            {
                yield return(TryToPickV2(pickUpThisItem));

                FullWork = true;
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// LazyLoot item independent checks
        /// </summary>
        /// <returns></returns>
        private bool CanLazyLoot()
        {
            if (!Settings.LazyLooting)
            {
                return(false);
            }
            if (Settings.LazyLooting && !Input.GetKeyState(Settings.LazyLootingPauseKey))
            {
                return(true);
            }
            // if (DisableLazyLootingTill > DateTime.Now) return false;

            return(true);
        }
Ejemplo n.º 6
0
        private IEnumerator FindItemToPick()
        {
            if (!Input.GetKeyState(Settings.PickUpKey.Value) || !GameController.Window.IsForeground())
            {
                yield break;
            }
            var window    = GameController.Window.GetWindowRectangleTimeCache;
            var rect      = new RectangleF(window.X, window.X, window.X + window.Width, window.Y + window.Height);
            var playerPos = GameController.Player.GridPos;

            List <CustomItem> currentLabels;

            if (Settings.UseWeight)
            {
                currentLabels = GameController.Game.IngameState.IngameUi.ItemsOnGroundLabels
                                .Where(x => x.Address != 0 &&
                                       x.ItemOnGround?.GetComponent <WorldItem>()?.ItemEntity.Path != null &&
                                       x.IsVisible && x.Label.GetClientRectCache.Center.PointInRectangle(rect) &&
                                       (x.CanPickUp || x.MaxTimeForPickUp.TotalSeconds <= 0))
                                .Select(x => new CustomItem(x, GameController.Files,
                                                            x.ItemOnGround.GetComponent <Positioned>().GridPos
                                                            .Distance(playerPos), _weightsRules))
                                .OrderByDescending(x => x.Weight).ThenBy(x => x.Distance).ToList();
            }
            else
            {
                currentLabels = GameController.Game.IngameState.IngameUi.ItemsOnGroundLabels
                                .Where(x => x.Address != 0 &&
                                       x.ItemOnGround?.GetComponent <WorldItem>()?.ItemEntity.Path != null &&
                                       x.IsVisible &&
                                       (x.CanPickUp || x.MaxTimeForPickUp.TotalSeconds <= 0))
                                .Select(x => new CustomItem(x, GameController.Files,
                                                            x.ItemOnGround.GetComponent <Positioned>().GridPos
                                                            .Distance(playerPos), _weightsRules))
                                .OrderBy(x => x.Distance).ToList();
            }

            GameController.Debug["PickIt"] = currentLabels;
            var pickUpThisItem = currentLabels.FirstOrDefault(x => DoWePickThis(x) && x.Distance < Settings.PickupRange);

            if (pickUpThisItem?.GroundItem != null)
            {
                yield return(TryToPickV2(pickUpThisItem));
            }
            FullWork = true;
        }
Ejemplo n.º 7
0
        /*public override void DrawSettings()
         * {
         *  ImGui.BulletText($"v{PluginVersion}");
         *  ImGui.BulletText($"Last Updated: {buildDate}");
         *  Settings.PickUpKey = ImGuiExtension.HotkeySelector("Pickup Key", Settings.PickUpKey);
         *  Settings.LeftClickToggleNode.Value = ImGuiExtension.Checkbox("Mouse Button: " + (Settings.LeftClickToggleNode ? "Left" : "Right"), Settings.LeftClickToggleNode);
         *  Settings.LeftClickToggleNode.Value = ImGuiExtension.Checkbox("Return Mouse To Position Before Click", Settings.ReturnMouseToBeforeClickPosition);
         *  Settings.GroundChests.Value = ImGuiExtension.Checkbox("Click Chests If No Items Around", Settings.GroundChests);
         *  Settings.PickupRange.Value = ImGuiExtension.IntSlider("Pickup Radius", Settings.PickupRange);
         *  Settings.ChestRange.Value = ImGuiExtension.IntSlider("Chest Radius", Settings.ChestRange);
         *  Settings.ExtraDelay.Value = ImGuiExtension.IntSlider("Extra Click Delay", Settings.ExtraDelay);
         *  Settings.MouseSpeed.Value = ImGuiExtension.FloatSlider("Mouse speed", Settings.MouseSpeed);
         *  Settings.TimeBeforeNewClick.Value = ImGuiExtension.IntSlider("Time wait for new click", Settings.TimeBeforeNewClick);
         *  //Settings.OverrideItemPickup.Value = ImGuiExtension.Checkbox("Item Pickup Override", Settings.OverrideItemPickup); ImGui.SameLine();
         *  //ImGuiExtension.ToolTip("Override item.CanPickup\n\rDO NOT enable this unless you know what you're doing!");
         *
         *  var tempRef = false;
         *  if (ImGui.CollapsingHeader("Pickit Rules", TreeNodeFlags.Framed | TreeNodeFlags.DefaultOpen))
         *  {
         *      if (ImGui.Button("Reload All Files")) LoadRuleFiles();
         *      Settings.NormalRuleFile = ImGuiExtension.ComboBox("Normal Rules", Settings.NormalRuleFile, PickitFiles, out tempRef);
         *      if (tempRef) _normalRules = LoadPickit(Settings.NormalRuleFile);
         *      Settings.MagicRuleFile = ImGuiExtension.ComboBox("Magic Rules", Settings.MagicRuleFile, PickitFiles, out tempRef);
         *      if (tempRef) _magicRules = LoadPickit(Settings.MagicRuleFile);
         *      Settings.RareRuleFile = ImGuiExtension.ComboBox("Rare Rules", Settings.RareRuleFile, PickitFiles, out tempRef);
         *      if (tempRef) _rareRules = LoadPickit(Settings.RareRuleFile);
         *      Settings.UniqueRuleFile = ImGuiExtension.ComboBox("Unique Rules", Settings.UniqueRuleFile, PickitFiles, out tempRef);
         *      if (tempRef) _uniqueRules = LoadPickit(Settings.UniqueRuleFile);
         *  }
         *
         *  if (ImGui.CollapsingHeader("Item Logic", TreeNodeFlags.Framed | TreeNodeFlags.DefaultOpen))
         *  {
         *      Settings.ShaperItems.Value = ImGuiExtension.Checkbox("Pickup Shaper Items", Settings.ShaperItems);
         *      ImGui.SameLine();
         *      Settings.ElderItems.Value = ImGuiExtension.Checkbox("Pickup Elder Items", Settings.ElderItems);
         *      if (ImGui.TreeNode("Links/Sockets/RGB"))
         *      {
         *          Settings.RGB.Value = ImGuiExtension.Checkbox("RGB Items", Settings.RGB);
         *          Settings.TotalSockets.Value = ImGuiExtension.IntSlider("##Sockets", Settings.TotalSockets);
         *          ImGui.SameLine();
         *          Settings.Sockets.Value = ImGuiExtension.Checkbox("Sockets", Settings.Sockets);
         *          Settings.LargestLink.Value = ImGuiExtension.IntSlider("##Links", Settings.LargestLink);
         *          ImGui.SameLine();
         *          Settings.Links.Value = ImGuiExtension.Checkbox("Links", Settings.Links);
         *          ImGui.Separator();
         *          ImGui.TreePop();
         *      }
         *
         *      if (ImGui.TreeNode("Overrides"))
         *      {
         *          Settings.PickUpEverything.Value = ImGuiExtension.Checkbox("Pickup Everything", Settings.PickUpEverything);
         *          Settings.AllDivs.Value = ImGuiExtension.Checkbox("All Divination Cards", Settings.AllDivs);
         *          Settings.AllCurrency.Value = ImGuiExtension.Checkbox("All Currency", Settings.AllCurrency);
         *          Settings.AllUniques.Value = ImGuiExtension.Checkbox("All Uniques", Settings.AllUniques);
         *          Settings.QuestItems.Value = ImGuiExtension.Checkbox("Quest Items", Settings.QuestItems);
         *          Settings.Maps.Value = ImGuiExtension.Checkbox("##Maps", Settings.Maps);
         *          ImGui.SameLine();
         *          if (ImGui.TreeNode("Maps"))
         *          {
         *              Settings.MapTier.Value = ImGuiExtension.IntSlider("Lowest Tier", Settings.MapTier);
         *              Settings.UniqueMap.Value = ImGuiExtension.Checkbox("All Unique Maps", Settings.UniqueMap);
         *              Settings.MapFragments.Value = ImGuiExtension.Checkbox("Fragments", Settings.MapFragments);
         *              ImGui.Spacing();
         *              ImGui.TreePop();
         *          }
         *
         *          Settings.GemQuality.Value = ImGuiExtension.IntSlider("##Gems", "Lowest Quality", Settings.GemQuality);
         *          ImGui.SameLine();
         *          Settings.Gems.Value = ImGuiExtension.Checkbox("Gems", Settings.Gems);
         *          ImGui.Separator();
         *          ImGui.TreePop();
         *      }
         *
         *      Settings.Rares.Value = ImGuiExtension.Checkbox("##Rares", Settings.Rares);
         *      ImGui.SameLine();
         *      if (ImGui.TreeNode("Rares##asd"))
         *      {
         *          Settings.RareJewels.Value = ImGuiExtension.Checkbox("Jewels", Settings.RareJewels);
         *          Settings.RareRingsilvl.Value = ImGuiExtension.IntSlider("##RareRings", "Lowest iLvl", Settings.RareRingsilvl);
         *          ImGui.SameLine();
         *          Settings.RareRings.Value = ImGuiExtension.Checkbox("Rings", Settings.RareRings);
         *          Settings.RareAmuletsilvl.Value = ImGuiExtension.IntSlider("##RareAmulets", "Lowest iLvl", Settings.RareAmuletsilvl);
         *          ImGui.SameLine();
         *          Settings.RareAmulets.Value = ImGuiExtension.Checkbox("Amulets", Settings.RareAmulets);
         *          Settings.RareBeltsilvl.Value = ImGuiExtension.IntSlider("##RareBelts", "Lowest iLvl", Settings.RareBeltsilvl);
         *          ImGui.SameLine();
         *          Settings.RareBelts.Value = ImGuiExtension.Checkbox("Belts", Settings.RareBelts);
         *          Settings.RareGlovesilvl.Value = ImGuiExtension.IntSlider("##RareGloves", "Lowest iLvl", Settings.RareGlovesilvl);
         *          ImGui.SameLine();
         *          Settings.RareGloves.Value = ImGuiExtension.Checkbox("Gloves", Settings.RareGloves);
         *          Settings.RareBootsilvl.Value = ImGuiExtension.IntSlider("##RareBoots", "Lowest iLvl", Settings.RareBootsilvl);
         *          ImGui.SameLine();
         *          Settings.RareBoots.Value = ImGuiExtension.Checkbox("Boots", Settings.RareBoots);
         *          Settings.RareHelmetsilvl.Value = ImGuiExtension.IntSlider("##RareHelmets", "Lowest iLvl", Settings.RareHelmetsilvl);
         *          ImGui.SameLine();
         *          Settings.RareHelmets.Value = ImGuiExtension.Checkbox("Helmets", Settings.RareHelmets);
         *          Settings.RareArmourilvl.Value = ImGuiExtension.IntSlider("##RareArmours", "Lowest iLvl", Settings.RareArmourilvl);
         *          ImGui.SameLine();
         *          Settings.RareArmour.Value = ImGuiExtension.Checkbox("Armours", Settings.RareArmour);
         *          ImGui.Spacing();
         *          Settings.RareWeaponilvl.Value = ImGuiExtension.IntSlider("##RareWeapons", "Lowest iLvl", Settings.RareWeaponilvl);
         *          ImGui.SameLine();
         *          Settings.RareWeapon.Value = ImGuiExtension.Checkbox("Weapons", Settings.RareWeapon);
         *          Settings.RareShieldilvl.Value = ImGuiExtension.IntSlider("##Shields", "Lowest iLvl", Settings.RareWeaponilvl);
         *          ImGui.SameLine();
         *          Settings.RareShield.Value = ImGuiExtension.Checkbox("Shields", Settings.RareWeapon);
         *          Settings.RareWeaponWidth.Value = ImGuiExtension.IntSlider("Maximum Width##RareWeaponWidth", Settings.RareWeaponWidth);
         *          Settings.RareWeaponHeight.Value = ImGuiExtension.IntSlider("Maximum Height##RareWeaponHeight", Settings.RareWeaponHeight);
         *          Settings.ItemCells.Value = ImGuiExtension.IntSlider("Maximum Cells##RareWeaponCell", Settings.ItemCells);
         *          ImGui.TreePop();
         *      }
         *  }
         * }*/

        public override Job Tick()
        {
            if (Input.GetKeyState(Keys.Escape))
            {
                pickItCoroutine.Pause();
            }

            if (Input.GetKeyState(Settings.PickUpKey.Value))
            {
                DebugTimer.Restart();

                if (pickItCoroutine.IsDone)
                {
                    var firstOrDefault = Core.ParallelRunner.Coroutines.FirstOrDefault(x => x.OwnerName == nameof(PickIt));

                    if (firstOrDefault != null)
                    {
                        pickItCoroutine = firstOrDefault;
                    }
                }

                pickItCoroutine.Resume();
                FullWork = false;
            }
            else
            {
                if (FullWork)
                {
                    pickItCoroutine.Pause();
                    DebugTimer.Reset();
                }
            }

            if (DebugTimer.ElapsedMilliseconds > 2000)
            {
                FullWork = true;
                LogMessage("Error pick it stop after time limit 2000 ms", 1);
                DebugTimer.Reset();
            }

            return(null);
        }
Ejemplo n.º 8
0
        public override void Render()
        {
            base.Render();

            if (_UnstackCoroutine != null && _UnstackCoroutine.IsDone)
            {
                _UnstackCoroutine = null;
            }

            var requiredPanelsOpen = GameController.Game.IngameState.IngameUi.InventoryPanel.IsVisible;

            if (_UnstackCoroutine != null && _UnstackCoroutine.Running)
            {
                if (_DebugTimer.ElapsedMilliseconds > 15000)
                {
                    DebugWindow.LogError(
                        "Unstacking the current stacked deck has reached the time limit for an operation.");
                    StopCoroutine();
                }

                if (!requiredPanelsOpen || Input.GetKeyState(Keys.Escape))
                {
                    StopCoroutine();
                }

                return;
            }

            if (!Settings.UnstackHotkey.PressedOnce())
            {
                return;
            }
            if (!requiredPanelsOpen)
            {
                return;
            }

            _UnstackCoroutine = new Coroutine(UnstackTheDecks(), this, Name);

            Core.ParallelRunner.Run(_UnstackCoroutine);
        }
Ejemplo n.º 9
0
        public static void Parse(ISettings settings, List <ISettingsHolder> draws, int id = -1)
        {
            if (settings == null)
            {
                DebugWindow.LogError("Cant parse null settings.");
                return;
            }

            var props = settings.GetType().GetProperties();

            foreach (var property in props)
            {
                if (property.GetCustomAttribute <IgnoreMenuAttribute>() != null)
                {
                    continue;
                }
                var menuAttribute = property.GetCustomAttribute <MenuAttribute>();
                var isSettings    = property.PropertyType.GetInterfaces().ContainsF(typeof(ISettings));

                if (property.Name == "Enable" && menuAttribute == null)
                {
                    continue;
                }

                if (menuAttribute == null)
                {
                    menuAttribute = new MenuAttribute(Regex.Replace(property.Name, "(\\B[A-Z])", " $1"));
                }

                var holder = new SettingsHolder
                {
                    Name    = menuAttribute.MenuName,
                    Tooltip = menuAttribute.Tooltip,
                    ID      = menuAttribute.index == -1 ? MathHepler.Randomizer.Next(int.MaxValue) : menuAttribute.index
                };

                if (isSettings)
                {
                    var innerSettings = (ISettings)property.GetValue(settings);

                    if (menuAttribute.index != -1)
                    {
                        holder.Type = HolderChildType.Tab;
                        draws.Add(holder);
                        Parse(innerSettings, draws, menuAttribute.index);
                        var parent = GetAllDrawers(draws).Find(x => x.ID == menuAttribute.parentIndex);
                        parent?.Children.Add(holder);
                    }
                    else
                    {
                        Parse(innerSettings, draws);
                    }

                    continue;
                }

                var type = property.GetValue(settings);

                if (menuAttribute.parentIndex != -1)
                {
                    var parent = GetAllDrawers(draws).Find(x => x.ID == menuAttribute.parentIndex);
                    parent?.Children.Add(holder);
                }
                else if (id != -1)
                {
                    var parent = GetAllDrawers(draws).Find(x => x.ID == id);
                    parent?.Children.Add(holder);
                }
                else
                {
                    draws.Add(holder);
                }

                switch (type)
                {
                case ButtonNode n:
                    holder.DrawDelegate = () =>
                    {
                        if (ImGui.Button(holder.Unique))
                        {
                            n.OnPressed();
                        }
                    };

                    break;

                case EmptyNode n:

                    break;

                case HotkeyNode n:
                    holder.DrawDelegate = () =>
                    {
                        var holderName = $"{holder.Name} {n.Value}##{n.Value}";
                        var open       = true;

                        if (ImGui.Button(holderName))
                        {
                            ImGui.OpenPopup(holderName);
                            open = true;
                        }

                        if (ImGui.BeginPopupModal(holderName, ref open, (ImGuiWindowFlags)35))
                        {
                            if (Input.GetKeyState(Keys.Escape))
                            {
                                ImGui.CloseCurrentPopup();
                                ImGui.EndPopup();
                                return;
                            }

                            foreach (var key in Enum.GetValues(typeof(Keys)))
                            {
                                var keyState = Input.GetKeyState((Keys)key);

                                if (keyState)
                                {
                                    n.Value = (Keys)key;
                                    ImGui.CloseCurrentPopup();
                                    break;
                                }
                            }

                            ImGui.Text($" Press new key to change '{n.Value}' or Esc for exit.");

                            ImGui.EndPopup();
                        }
                    };

                    break;

                case ToggleNode n:
                    holder.DrawDelegate = () =>
                    {
                        var value = n.Value;
                        ImGui.Checkbox(holder.Unique, ref value);
                        n.Value = value;
                    };

                    break;

                case ColorNode n:
                    holder.DrawDelegate = () =>
                    {
                        var vector4 = n.Value.ToVector4().ToVector4Num();

                        if (ImGui.ColorEdit4(holder.Unique, ref vector4,
                                             ImGuiColorEditFlags.AlphaBar | ImGuiColorEditFlags.NoInputs |
                                             ImGuiColorEditFlags.AlphaPreviewHalf))
                        {
                            n.Value = vector4.ToSharpColor();
                        }
                    };

                    break;

                case ListNode n:
                    holder.DrawDelegate = () =>
                    {
                        if (ImGui.BeginCombo(holder.Unique, n.Value))
                        {
                            foreach (var t in n.Values)
                            {
                                if (ImGui.Selectable(t))
                                {
                                    n.Value = t;
                                    ImGui.EndCombo();
                                    return;
                                }
                            }

                            ImGui.EndCombo();
                        }
                    };

                    break;

                case FileNode n:
                    holder.DrawDelegate = () =>
                    {
                        if (ImGui.TreeNode(holder.Unique))
                        {
                            var selected = n.Value;

                            if (ImGui.BeginChildFrame(1, new Vector2(0, 300)))
                            {
                                var di = new DirectoryInfo("config");

                                if (di.Exists)
                                {
                                    foreach (var file in di.GetFiles())
                                    {
                                        if (ImGui.Selectable(file.Name, selected == file.FullName))
                                        {
                                            n.Value = file.FullName;
                                        }
                                    }
                                }

                                ImGui.EndChildFrame();
                            }

                            ImGui.TreePop();
                        }
                    };

                    break;

                case RangeNode <int> n:
                    holder.DrawDelegate = () =>
                    {
                        var r = n.Value;
                        ImGui.SliderInt(holder.Unique, ref r, n.Min, n.Max);
                        n.Value = r;
                    };

                    break;

                case RangeNode <float> n:

                    holder.DrawDelegate = () =>
                    {
                        var r = n.Value;
                        ImGui.SliderFloat(holder.Unique, ref r, n.Min, n.Max);
                        n.Value = r;
                    };

                    break;

                case RangeNode <long> n:
                    holder.DrawDelegate = () =>
                    {
                        var r = (int)n.Value;
                        ImGui.SliderInt(holder.Unique, ref r, (int)n.Min, (int)n.Max);
                        n.Value = r;
                    };

                    break;

                case RangeNode <Vector2> n:
                    holder.DrawDelegate = () =>
                    {
                        var vect = n.Value;
                        ImGui.SliderFloat2(holder.Unique, ref vect, n.Min.X, n.Max.X);
                        n.Value = vect;
                    };

                    break;

                default:
                    Core.Logger.Warning($"{type} not supported for menu now. Ask developers to add this type.");
                    break;
                }
            }
        }
Ejemplo n.º 10
0
        private static void HandleType(SettingsHolder holder, object type, string propertyInfo)
        {
            switch (type)
            {
            case ButtonNode buttonNode:
                holder.DrawDelegate = () =>
                {
                    if (ImGui.Button(holder.Unique))
                    {
                        buttonNode.OnPressed();
                    }
                };
                return;

            case null:
            case EmptyNode _:
                holder.DrawDelegate = () => { };
                return;

            case HotkeyNode hotkeyNode:
                holder.DrawDelegate = () =>
                {
                    var str         = $"{holder.Name} {hotkeyNode.Value}##{hotkeyNode.Value}";
                    var popupOpened = true;

                    if (ImGui.Button(str))
                    {
                        ImGui.OpenPopup(str);
                        popupOpened = true;
                    }

                    if (!ImGui.BeginPopupModal(str, ref popupOpened,
                                               ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse))
                    {
                        return;
                    }

                    if (Input.GetKeyState(Keys.Escape))
                    {
                        ImGui.CloseCurrentPopup();
                        ImGui.EndPopup();
                        return;
                    }

                    foreach (var key in Enum.GetValues(typeof(Keys)))
                    {
                        if (!Input.GetKeyState((Keys)key))
                        {
                            continue;
                        }
                        hotkeyNode.Value = (Keys)key;
                        ImGui.CloseCurrentPopup();
                        break;
                    }

                    ImGui.Text($"Press new key to change '{hotkeyNode.Value}' or Esc for exit.");
                    ImGui.EndPopup();
                };
                return;

            case ToggleNode toggleNode:
                holder.DrawDelegate = () =>
                {
                    var isChecked = toggleNode.Value;
                    ImGui.Checkbox(holder.Unique, ref isChecked);
                    toggleNode.Value = isChecked;
                };
                return;

            case ColorNode colorNode:
                holder.DrawDelegate = () =>
                {
                    var color = colorNode.Value.ToVector4().ToVector4Num();
                    if (ImGui.ColorEdit4(holder.Unique, ref color,
                                         ImGuiColorEditFlags.NoInputs | ImGuiColorEditFlags.AlphaBar |
                                         ImGuiColorEditFlags.AlphaPreviewHalf))
                    {
                        colorNode.Value = color.ToSharpColor();
                    }
                };
                return;

            case ListNode listNode:
                holder.DrawDelegate = () =>
                {
                    if (!ImGui.BeginCombo(holder.Unique, listNode.Value))
                    {
                        return;
                    }

                    foreach (var value in listNode.Values)
                    {
                        if (!ImGui.Selectable(value))
                        {
                            continue;
                        }
                        listNode.Value = value;
                        break;
                    }

                    ImGui.EndCombo();
                };
                return;

            case FileNode fileNode:
                holder.DrawDelegate = () =>
                {
                    if (!ImGui.TreeNode(holder.Unique))
                    {
                        return;
                    }

                    var value = fileNode.Value;
                    if (ImGui.BeginChildFrame(1, new Vector2(0f, 300f)))
                    {
                        var directoryInfo = new DirectoryInfo("config");
                        if (directoryInfo.Exists)
                        {
                            var files = directoryInfo.GetFiles();
                            foreach (var fileInfo in files)
                            {
                                if (ImGui.Selectable(fileInfo.Name, value == fileInfo.FullName))
                                {
                                    fileNode.Value = fileInfo.FullName;
                                }
                            }
                        }

                        ImGui.EndChildFrame();
                    }

                    ImGui.TreePop();
                };
                return;

            case RangeNode <int> iRangeNode:
                holder.DrawDelegate = () =>
                {
                    var value = iRangeNode.Value;
                    ImGui.SliderInt(holder.Unique, ref value, iRangeNode.Min, iRangeNode.Max);
                    iRangeNode.Value = value;
                };
                return;

            case RangeNode <float> fRangeNode:
                holder.DrawDelegate = () =>
                {
                    var value = fRangeNode.Value;
                    ImGui.SliderFloat(holder.Unique, ref value, fRangeNode.Min, fRangeNode.Max);
                    fRangeNode.Value = value;
                };
                return;

            case RangeNode <long> lRangeNode:
                holder.DrawDelegate = () =>
                {
                    var value = (int)lRangeNode.Value;
                    ImGui.SliderInt(holder.Unique, ref value, (int)lRangeNode.Min, (int)lRangeNode.Max);
                    lRangeNode.Value = value;
                };
                return;

            case RangeNode <Vector2> vRangeNode:
                holder.DrawDelegate = () =>
                {
                    var value = vRangeNode.Value;
                    ImGui.SliderFloat2(holder.Unique, ref value, vRangeNode.Min.X, vRangeNode.Max.X);
                    vRangeNode.Value = value;
                };
                return;

            case TextNode textNode:
                holder.DrawDelegate = () =>
                {
                    var value = textNode.Value;
                    ImGui.InputText(holder.Unique, ref value, 200);
                    textNode.Value = value;
                };
                return;
            }

            DebugWindow.LogDebug(
                $"SettingsParser => DrawDelegate not auto-generated for '{propertyInfo}'.");
        }
Ejemplo n.º 11
0
        private static void HandleType(SettingsHolder holder, object type, string propertyInfo)
        {
            switch (type)
            {
            case ButtonNode buttonNode:
                holder.DrawDelegate = () =>
                {
                    if (ImGui.Button(holder.Unique))
                    {
                        buttonNode.OnPressed();
                    }
                };
                return;

            case null:
            case EmptyNode _:
                holder.DrawDelegate = () => { };
                return;

            case HotkeyNode hotkeyNode:
                holder.DrawDelegate = () =>
                {
                    var str = $"{holder.Name} {hotkeyNode.Value}##{hotkeyNode.Value}";

                    if (ImGui.Button(str))
                    {
                        // Clear async buffer state
                        Input.ClearAsyncBuffer();

                        // Begin pop up
                        ImGui.OpenPopup(str);
                    }

                    // Create modal
                    var popupOpened = true;
                    if (ImGui.BeginPopupModal(str, ref popupOpened, ImGuiWindowFlags.NoTitleBar | ImGuiWindowFlags.NoResize | ImGuiWindowFlags.NoCollapse))
                    {
                        ButtonPopupVisible = true;
                    }
                    else
                    {
                        return;
                    }

                    // Close popup if escape was pressed
                    if (Input.GetKeyState(Keys.Escape))
                    {
                        ImGui.CloseCurrentPopup();
                        ImGui.EndPopup();
                        ButtonPopupVisible = false;
                        return;
                    }

                    // Get prssed keys
                    Keys key = Input.GetPressedKeys(true);

                    // If a key was pressed, set value and close popup
                    if ((key & Keys.KeyCode) != Keys.None)
                    {
                        // Set the node's value to the keys that were pressed and close the popup
                        hotkeyNode.Value = key;
                        ImGui.CloseCurrentPopup();
                        ButtonPopupVisible = false;
                    }

                    // End popup
                    ImGui.Text($"Press new key to change '{hotkeyNode.Value}' or Esc for exit.");
                    ImGui.EndPopup();
                };
                return;

            case ToggleNode toggleNode:
                holder.DrawDelegate = () =>
                {
                    var isChecked = toggleNode.Value;
                    ImGui.Checkbox(holder.Unique, ref isChecked);
                    toggleNode.Value = isChecked;
                };
                return;

            case ColorNode colorNode:
                holder.DrawDelegate = () =>
                {
                    var color = colorNode.Value.ToVector4().ToVector4Num();
                    if (ImGui.ColorEdit4(holder.Unique, ref color,
                                         ImGuiColorEditFlags.NoInputs | ImGuiColorEditFlags.AlphaBar |
                                         ImGuiColorEditFlags.AlphaPreviewHalf))
                    {
                        colorNode.Value = color.ToSharpColor();
                    }
                };
                return;

            case ListNode listNode:
                holder.DrawDelegate = () =>
                {
                    if (!ImGui.BeginCombo(holder.Unique, listNode.Value))
                    {
                        return;
                    }

                    foreach (var value in listNode.Values)
                    {
                        if (!ImGui.Selectable(value))
                        {
                            continue;
                        }
                        listNode.Value = value;
                        break;
                    }

                    ImGui.EndCombo();
                };
                return;

            case FileNode fileNode:
                holder.DrawDelegate = () =>
                {
                    if (!ImGui.TreeNode(holder.Unique))
                    {
                        return;
                    }

                    var value = fileNode.Value;
                    if (ImGui.BeginChildFrame(1, new Vector2(0f, 300f)))
                    {
                        var directoryInfo = new DirectoryInfo("config");
                        if (directoryInfo.Exists)
                        {
                            var files = directoryInfo.GetFiles();
                            foreach (var fileInfo in files)
                            {
                                if (ImGui.Selectable(fileInfo.Name, value == fileInfo.FullName))
                                {
                                    fileNode.Value = fileInfo.FullName;
                                }
                            }
                        }

                        ImGui.EndChildFrame();
                    }

                    ImGui.TreePop();
                };
                return;

            case RangeNode <int> iRangeNode:
                holder.DrawDelegate = () =>
                {
                    var value = iRangeNode.Value;
                    ImGui.SliderInt(holder.Unique, ref value, iRangeNode.Min, iRangeNode.Max);
                    iRangeNode.Value = value;
                };
                return;

            case RangeNode <float> fRangeNode:
                holder.DrawDelegate = () =>
                {
                    var value = fRangeNode.Value;
                    ImGui.SliderFloat(holder.Unique, ref value, fRangeNode.Min, fRangeNode.Max);
                    fRangeNode.Value = value;
                };
                return;

            case RangeNode <long> lRangeNode:
                holder.DrawDelegate = () =>
                {
                    var value = (int)lRangeNode.Value;
                    ImGui.SliderInt(holder.Unique, ref value, (int)lRangeNode.Min, (int)lRangeNode.Max);
                    lRangeNode.Value = value;
                };
                return;

            case RangeNode <Vector2> vRangeNode:
                holder.DrawDelegate = () =>
                {
                    var value = vRangeNode.Value;
                    ImGui.SliderFloat2(holder.Unique, ref value, vRangeNode.Min.X, vRangeNode.Max.X);
                    vRangeNode.Value = value;
                };
                return;

            case TextNode textNode:
                holder.DrawDelegate = () =>
                {
                    var value = textNode.Value;
                    ImGui.InputText(holder.Unique, ref value, 200);
                    textNode.Value = value;
                };
                return;
            }
        }
Ejemplo n.º 12
0
        private static void HandleType(MenuAttribute menuAttribute, SettingsHolder holder, object type)
        {
            switch (type)
            {
            case ButtonNode n:
                holder.DrawDelegate = () =>
                {
                    if (ImGui.Button(holder.Unique))
                    {
                        n.OnPressed();
                    }
                };

                break;

            case EmptyNode n:

                break;

            case HotkeyNode n:
                holder.DrawDelegate = () =>
                {
                    var holderName = $"{holder.Name} {n.Value}##{n.Value}";
                    var open       = true;

                    if (ImGui.Button(holderName))
                    {
                        ImGui.OpenPopup(holderName);
                        open = true;
                    }

                    if (ImGui.BeginPopupModal(holderName, ref open, (ImGuiWindowFlags)35))
                    {
                        if (Input.GetKeyState(Keys.Escape))
                        {
                            ImGui.CloseCurrentPopup();
                            ImGui.EndPopup();
                            return;
                        }

                        foreach (var key in Enum.GetValues(typeof(Keys)))
                        {
                            var keyState = Input.GetKeyState((Keys)key);

                            if (keyState)
                            {
                                n.Value = (Keys)key;
                                ImGui.CloseCurrentPopup();
                                break;
                            }
                        }

                        ImGui.Text($" Press new key to change '{n.Value}' or Esc for exit.");

                        ImGui.EndPopup();
                    }
                };

                break;

            case ToggleNode n:
                holder.DrawDelegate = () =>
                {
                    var value = n.Value;
                    ImGui.Checkbox(holder.Unique, ref value);
                    n.Value = value;
                };

                break;

            case ColorNode n:
                holder.DrawDelegate = () =>
                {
                    var vector4 = n.Value.ToVector4().ToVector4Num();

                    if (ImGui.ColorEdit4(holder.Unique, ref vector4,
                                         ImGuiColorEditFlags.AlphaBar | ImGuiColorEditFlags.NoInputs |
                                         ImGuiColorEditFlags.AlphaPreviewHalf))
                    {
                        n.Value = vector4.ToSharpColor();
                    }
                };

                break;

            case ListNode n:
                holder.DrawDelegate = () =>
                {
                    if (ImGui.BeginCombo(holder.Unique, n.Value))
                    {
                        foreach (var t in n.Values)
                        {
                            if (ImGui.Selectable(t))
                            {
                                n.Value = t;
                                ImGui.EndCombo();
                                return;
                            }
                        }

                        ImGui.EndCombo();
                    }
                };

                break;

            case FileNode n:
                holder.DrawDelegate = () =>
                {
                    if (ImGui.TreeNode(holder.Unique))
                    {
                        var selected = n.Value;

                        if (ImGui.BeginChildFrame(1, new Vector2(0, 300)))
                        {
                            var di = new DirectoryInfo("config");

                            if (di.Exists)
                            {
                                foreach (var file in di.GetFiles())
                                {
                                    if (ImGui.Selectable(file.Name, selected == file.FullName))
                                    {
                                        n.Value = file.FullName;
                                    }
                                }
                            }

                            ImGui.EndChildFrame();
                        }

                        ImGui.TreePop();
                    }
                };

                break;

            case RangeNode <int> n:
                holder.DrawDelegate = () =>
                {
                    var r = n.Value;
                    ImGui.SliderInt(holder.Unique, ref r, n.Min, n.Max);
                    n.Value = r;
                };

                break;

            case RangeNode <float> n:

                holder.DrawDelegate = () =>
                {
                    var r = n.Value;
                    ImGui.SliderFloat(holder.Unique, ref r, n.Min, n.Max);
                    n.Value = r;
                };

                break;

            case RangeNode <long> n:
                holder.DrawDelegate = () =>
                {
                    var r = (int)n.Value;
                    ImGui.SliderInt(holder.Unique, ref r, (int)n.Min, (int)n.Max);
                    n.Value = r;
                };

                break;

            case RangeNode <Vector2> n:
                holder.DrawDelegate = () =>
                {
                    var vect = n.Value;
                    ImGui.SliderFloat2(holder.Unique, ref vect, n.Min.X, n.Max.X);
                    n.Value = vect;
                };

                break;

            case TextNode n:
                holder.DrawDelegate = () =>
                {
                    var input = n.Value;
                    ImGui.InputText(holder.Unique, ref input, 200);
                    n.Value = input;
                };
                break;

            default:
                DebugWindow.LogDebug($"{type} not supported for menu now. Ask developers to add this type.");
                break;
            }
        }