Skip to content

Commit 1eb6f0f

Browse files
committed
[Loot Editor] Loot can be sorted by pressing the column
1 parent 8c8e7ee commit 1eb6f0f

File tree

4 files changed

+56
-5
lines changed

4 files changed

+56
-5
lines changed

Modules/WDE.LootEditor/Editor/ViewModels/LootEditorViewModel.cs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,12 +1121,51 @@ private bool VerifyDuplicateKeys()
11211121

11221122
public ISolutionItem SolutionItem => ((ISolutionItem?)perDbSolutionItem ?? perEntitySolutionItem)!;
11231123

1124-
public void SortElements()
1124+
public void SortElements(int sortByCellIndex, bool ascending)
11251125
{
11261126
using var bulk = HistoryHandler.WithinBulk("Sort loot");
11271127
foreach (var group in Loots)
11281128
{
1129-
var copy = group.LootItems.OrderBy(x => x.GroupId.Value)
1129+
var source = group.LootItems;
1130+
if (source.Count == 0)
1131+
continue;
1132+
1133+
var firstRow = source[0];
1134+
IOrderedEnumerable<LootItemViewModel> ordered;
1135+
if (firstRow.CellsList[sortByCellIndex] is LootItemParameterCellLong)
1136+
{
1137+
if (ascending)
1138+
ordered = source.OrderBy(x => ((LootItemParameterCellLong)x.CellsList[sortByCellIndex]).Value);
1139+
else
1140+
ordered = source.OrderByDescending(x => ((LootItemParameterCellLong)x.CellsList[sortByCellIndex]).Value);
1141+
}
1142+
else if (firstRow.CellsList[sortByCellIndex] is ItemNameStringCell)
1143+
{
1144+
if (ascending)
1145+
ordered = source.OrderBy(x => ((ItemNameStringCell)x.CellsList[sortByCellIndex]).StringValue);
1146+
else
1147+
ordered = source.OrderByDescending(x => ((ItemNameStringCell)x.CellsList[sortByCellIndex]).StringValue);
1148+
}
1149+
else if (firstRow.CellsList[sortByCellIndex] is LootItemParameterCell<float>)
1150+
{
1151+
if (ascending)
1152+
ordered = source.OrderBy(x => ((LootItemParameterCell<float>)x.CellsList[sortByCellIndex]).Value);
1153+
else
1154+
ordered = source.OrderByDescending(x => ((LootItemParameterCell<float>)x.CellsList[sortByCellIndex]).Value);
1155+
}
1156+
else if (firstRow.CellsList[sortByCellIndex] is ActionCell)
1157+
{
1158+
continue;
1159+
}
1160+
else
1161+
{
1162+
messageBoxService.SimpleDialog("Error", "Non critical error - can't sort by this column",
1163+
"This is an internal error, please report it. Can't sort the loot, because " +
1164+
LootColumns[sortByCellIndex].Header + " is not sortable");
1165+
continue;
1166+
}
1167+
1168+
var copy = ordered
11301169
.ThenBy(x => x.ItemOrCurrencyId.Value)
11311170
.ToList();
11321171
group.LootItems.RemoveAll();

Modules/WDE.LootEditor/Editor/Views/LootEditorView.axaml.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,23 @@ private void VeryFastTableView_OnValueUpdateRequest(string text)
2222
(DataContext as LootEditorViewModel)!.UpdateSelectedCells(text);
2323
}
2424

25+
private int lastSortByColumnIndex = -1;
26+
private bool lastAscending = true;
27+
2528
private void VeryFastTableView_OnColumnPressed(object? sender, ColumnPressedEventArgs e)
2629
{
2730
if (DataContext is LootEditorViewModel vm)
2831
{
29-
vm.SortElements();
32+
if (lastSortByColumnIndex != e.ColumnIndex)
33+
{
34+
lastSortByColumnIndex = e.ColumnIndex;
35+
lastAscending = true;
36+
}
37+
else
38+
{
39+
lastAscending = !lastAscending;
40+
}
41+
vm.SortElements(e.ColumnIndex, lastAscending);
3042
}
3143
}
3244
}

WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Models/MySqlAreaTriggerTemplate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class MySqlAreaTriggerTemplate : IAreaTriggerTemplate
1111
public uint Id { get; set; }
1212

1313
[PrimaryKey]
14-
[Column(Name = "IsServerSide")]
14+
[Column(Name = "IsCustom")]
1515
public bool IsServerSide { get; set; }
1616

1717
public string? Name => null;

WoWDatabaseEditor.Common/WDE.TrinityMySqlDatabase/Models/MySqlCreatureTemplateWrath.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public class MySqlCreatureTemplateMaster : ICreatureTemplate
225225
[Column(Name = "RequiredExpansion")]
226226
public short RequiredExpansion { get; set; }
227227

228-
[Column(Name = "rank")]
228+
[Column(Name = "Classification")]
229229
public byte Rank { get; set; }
230230

231231
[Column(Name = "unit_class")]

0 commit comments

Comments
 (0)