-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathNPCInvWithLinqSettings.cs
More file actions
133 lines (108 loc) · 4.32 KB
/
NPCInvWithLinqSettings.cs
File metadata and controls
133 lines (108 loc) · 4.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
using ExileCore2.Shared.Attributes;
using ExileCore2.Shared.Interfaces;
using ExileCore2.Shared.Nodes;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text.Json.Serialization;
using System.Numerics;
using ImGuiNET;
namespace NPCInvWithLinq;
public class NPCInvWithLinqSettings : ISettings
{
public NPCInvWithLinqSettings()
{
RuleConfig = new RuleRenderer(this);
}
public ToggleNode Enable { get; set; } = new ToggleNode(false);
public ToggleNode DrawOnTabLabels { get; set; } = new ToggleNode(true);
public ColorNode TabFrameColor { get; set; } = new ColorNode(Color.Red);
public RangeNode<int> FrameThickness { get; set; } = new RangeNode<int>(1, 1, 20);
[JsonIgnore]
public TextNode FilterTest { get; set; } = new TextNode();
[JsonIgnore]
[Menu("Reload/Apply filters")]
public ButtonNode ReloadFilters { get; set; } = new ButtonNode();
[Menu("Use a Custom \"\\config\\custom_folder\" folder ")]
public TextNode CustomConfigDir { get; set; } = new TextNode();
public List<NPCInvRule> NPCInvRules { get; set; } = new List<NPCInvRule>();
[JsonIgnore]
public RuleRenderer RuleConfig { get; set; }
[Submenu(RenderMethod = nameof(Render))]
public class RuleRenderer
{
private readonly NPCInvWithLinqSettings _parent;
public RuleRenderer(NPCInvWithLinqSettings parent)
{
_parent = parent;
}
public void Render(NPCInvWithLinq plugin)
{
if (ImGui.Button("Open rule folder"))
{
var configDir = plugin.ConfigDirectory;
var customConfigFileDirectory = !string.IsNullOrEmpty(_parent.CustomConfigDir)
? Path.Combine(Path.GetDirectoryName(plugin.ConfigDirectory), _parent.CustomConfigDir)
: null;
var directoryToOpen = Directory.Exists(customConfigFileDirectory)
? customConfigFileDirectory
: configDir;
Process.Start("explorer.exe", directoryToOpen);
}
ImGui.Separator();
ImGui.BulletText("Select Rules To Load");
ImGui.BulletText("Ordering rule sets so general items will match first rather than last will improve performance");
var tempNpcInvRules = new List<NPCInvRule>(_parent.NPCInvRules); // Create a copy
var reloadRequired = false;
for (int i = 0; i < tempNpcInvRules.Count; i++)
{
if (ImGui.ArrowButton($"##upButton{i}", ImGuiDir.Up) && i > 0)
{
(tempNpcInvRules[i - 1], tempNpcInvRules[i]) = (tempNpcInvRules[i], tempNpcInvRules[i - 1]);
reloadRequired = true;
}
ImGui.SameLine();
ImGui.Text(" ");
ImGui.SameLine();
if (ImGui.ArrowButton($"##downButton{i}", ImGuiDir.Down) && i < tempNpcInvRules.Count - 1)
{
(tempNpcInvRules[i + 1], tempNpcInvRules[i]) = (tempNpcInvRules[i], tempNpcInvRules[i + 1]);
reloadRequired = true;
}
ImGui.SameLine();
ImGui.Text(" - ");
ImGui.SameLine();
var refToggle = tempNpcInvRules[i].Enabled;
if (ImGui.Checkbox($"{tempNpcInvRules[i].Name}##checkbox{i}", ref refToggle))
{
tempNpcInvRules[i].Enabled = refToggle;
reloadRequired = true;
}
ImGui.SameLine();
if (tempNpcInvRules[i].Color.DrawPicker($"##color{i}"))
{
plugin.LoadRuleFiles();
}
}
_parent.NPCInvRules = tempNpcInvRules;
if (reloadRequired)
{
plugin.LoadRuleFiles();
}
}
}
}
public class NPCInvRule
{
public string Name { get; set; } = "";
public string Location { get; set; } = "";
public bool Enabled { get; set; } = false;
public ColorNode Color { get; set; } = new ColorNode(System.Drawing.Color.Red);
public NPCInvRule(string name, string location, bool enabled)
{
Name = name;
Location = location;
Enabled = enabled;
}
}