forked from TuckMeIntoBread/AutoRetainerSort
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEditInventoryOptionsForm.cs
218 lines (181 loc) · 6.83 KB
/
EditInventoryOptionsForm.cs
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.Windows.Media;
using AutoRetainerSort.Classes;
using LlamaLibrary.Logging;
using static AutoRetainerSort.Classes.ItemSortInfo;
namespace AutoRetainerSort
{
public partial class EditInventoryOptionsForm : Form
{
private static readonly LLogger Log = new LLogger(Strings.LogPrefix, Colors.Orange);
public EditInventoryOptionsForm()
{
InitializeComponent();
}
public EditInventoryOptionsForm(InventorySortInfo sortInfo, int index)
{
InitializeComponent();
_sortInfo = sortInfo;
_index = index;
}
private readonly InventorySortInfo _sortInfo;
private readonly int _index = int.MinValue;
private void Form_Load(object sender, EventArgs e)
{
if (_sortInfo == null || _index == int.MinValue)
{
MessageBox.Show("Couldn't load the sorting info correctly?", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
Close();
return;
}
txtBoxName.Text = _sortInfo.Name;
_bsSortTypes = new BindingSource(_sortInfo.SortTypes, "");
_bsItems = new BindingSource(_sortInfo.SpecificItems, "");
listBoxSortTypes.DataSource = _bsSortTypes;
listBoxItems.DataSource = _bsItems;
comboBoxSortType.DataSource = Enum.GetValues(typeof(SortType));
if (Owner != null)
{
var ownerCenterX = Owner.Location.X + (Owner.Width / 2) - (Width / 2);
var ownerCenterY = Owner.Location.Y + (Owner.Height / 2) - (Width / 2);
Location = new Point(ownerCenterX, ownerCenterY);
}
}
private BindingSource _bsSortTypes;
private BindingSource _bsItems;
private SortType NewSortType => Enum.TryParse(comboBoxSortType.SelectedValue.ToString(), out SortType sortType) ? sortType : SortType.UNKNOWN;
private void Name_TextChanged(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(txtBoxName.Text))
{
return;
}
_sortInfo.Name = txtBoxName.Text;
}
private void AddNewSortType_Click(object sender, EventArgs e)
{
var selected = NewSortType;
if (_sortInfo.ContainsType(selected))
{
return;
}
foreach (var pair in AutoRetainerSortSettings.Instance.InventoryOptions)
{
if (pair.Key == _index)
{
continue;
}
if (!pair.Value.ContainsType(selected))
{
continue;
}
var dr = MessageBox.Show(
string.Format(Strings.AddNewItem_AlreadyExists_Warning, pair.Value.Name, selected.ToString(), pair.Value.Name, _sortInfo.Name),
Strings.WarningCaption,
MessageBoxButtons.YesNo,
MessageBoxIcon.Warning);
if (dr != DialogResult.Yes)
{
return;
}
pair.Value.RemoveType(selected);
break;
}
_bsSortTypes.Add(new SortTypeWithCount(selected));
AutoRetainerSortSettings.Instance.Save();
}
private void AddNewItem_Click(object sender, EventArgs e)
{
var toAddIds = new HashSet<uint>();
using (var newItemForm = new AddNewItemForm())
{
var dr = newItemForm.ShowDialog(this);
if (dr != DialogResult.OK)
{
return;
}
var selectedItem = newItemForm.SelectedSearchResult;
if (selectedItem == null || selectedItem.RawItemId == 0)
{
return;
}
if (newItemForm.ModifierNone)
{
toAddIds.Add(selectedItem.RawItemId);
}
else if (newItemForm.ModifierHQ)
{
toAddIds.Add(selectedItem.RawItemId + QualityOffset);
}
else if (newItemForm.ModifierCollectable)
{
toAddIds.Add(selectedItem.RawItemId + CollectableOffset);
}
else
{
return;
}
if (newItemForm.IncludeHQ)
{
toAddIds.Add(selectedItem.RawItemId + QualityOffset);
}
if (newItemForm.IncludeCollectable)
{
toAddIds.Add(selectedItem.RawItemId + CollectableOffset);
}
}
foreach (var toAddId in toAddIds)
{
var sortInfo = ItemSortStatus.GetSortInfo(toAddId);
var shouldAdd = true;
foreach (var indexInfoPair in AutoRetainerSortSettings.Instance.InventoryOptions)
{
if (indexInfoPair.Key == _index)
{
continue;
}
if (!indexInfoPair.Value.ContainsItem(sortInfo))
{
continue;
}
if (sortInfo.ItemInfo.Unique)
{
continue;
}
var dr = MessageBox.Show(
string.Format(Strings.AddNewItem_AlreadyExists_Warning, indexInfoPair.Value.Name, sortInfo.Name, indexInfoPair.Value.Name, _sortInfo.Name),
Strings.WarningCaption,
MessageBoxButtons.YesNo,
MessageBoxIcon.Warning);
if (dr == DialogResult.Yes)
{
indexInfoPair.Value.SpecificItems.Remove(sortInfo);
}
else
{
shouldAdd = false;
break;
}
}
if (!shouldAdd)
{
continue;
}
Log.Information($"Added {sortInfo.Name} to {_sortInfo.Name}!");
_bsItems.Add(sortInfo);
}
AutoRetainerSortSettings.Instance.Save();
}
private void DeleteSelectedSortType_Click(object sender, EventArgs e)
{
_bsSortTypes.Remove(listBoxSortTypes.SelectedItem);
}
private void DeleteSelectedItemId_Click(object sender, EventArgs e)
{
_bsItems.Remove(listBoxItems.SelectedItem);
}
}
}