mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
fake stable sort on card list
This commit is contained in:
@@ -481,7 +481,23 @@ bool CardListBase::compareItems(void* a, void* b) const {
|
|||||||
// compare sort keys
|
// compare sort keys
|
||||||
int cmp = smart_compare( va->getSortKey(), vb->getSortKey() );
|
int cmp = smart_compare( va->getSortKey(), vb->getSortKey() );
|
||||||
if (cmp != 0) return cmp < 0;
|
if (cmp != 0) return cmp < 0;
|
||||||
// equal values, compare alternate sort key
|
// equal values, compare alternate sort keys
|
||||||
|
if (sort_by_column2 != sort_by_column && sort_by_column2 >= 0) {
|
||||||
|
FieldP sort_field2 = column_fields[sort_by_column2];
|
||||||
|
ValueP va2 = reinterpret_cast<Card*>(a)->data[sort_field2];
|
||||||
|
ValueP vb2 = reinterpret_cast<Card*>(b)->data[sort_field2];
|
||||||
|
assert(va2 && vb2);
|
||||||
|
int cmp = smart_compare( va2->getSortKey(), vb2->getSortKey() );
|
||||||
|
if (cmp != 0) return cmp < 0;
|
||||||
|
if (sort_by_column3 != sort_by_column && sort_by_column3 != sort_by_column2 && sort_by_column3 >= 0) {
|
||||||
|
FieldP sort_field3 = column_fields[sort_by_column3];
|
||||||
|
ValueP va3 = reinterpret_cast<Card*>(a)->data[sort_field3];
|
||||||
|
ValueP vb3 = reinterpret_cast<Card*>(b)->data[sort_field3];
|
||||||
|
assert(va3 && vb3);
|
||||||
|
int cmp = smart_compare( va3->getSortKey(), vb3->getSortKey() );
|
||||||
|
if (cmp != 0) return cmp < 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
if (alternate_sort_field) {
|
if (alternate_sort_field) {
|
||||||
ValueP va = reinterpret_cast<Card*>(a)->data[alternate_sort_field];
|
ValueP va = reinterpret_cast<Card*>(a)->data[alternate_sort_field];
|
||||||
ValueP vb = reinterpret_cast<Card*>(b)->data[alternate_sort_field];
|
ValueP vb = reinterpret_cast<Card*>(b)->data[alternate_sort_field];
|
||||||
@@ -521,6 +537,8 @@ void CardListBase::rebuild() {
|
|||||||
GameSettings& gs = settings.gameSettingsFor(*set->game);
|
GameSettings& gs = settings.gameSettingsFor(*set->game);
|
||||||
sort_ascending = gs.sort_cards_ascending;
|
sort_ascending = gs.sort_cards_ascending;
|
||||||
sort_by_column = -1;
|
sort_by_column = -1;
|
||||||
|
sort_by_column2 = -1;
|
||||||
|
sort_by_column3 = -1;
|
||||||
long i = 0;
|
long i = 0;
|
||||||
FOR_EACH(f, column_fields) {
|
FOR_EACH(f, column_fields) {
|
||||||
if (f->name == gs.sort_cards_by) {
|
if (f->name == gs.sort_cards_by) {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
ItemList::ItemList(Window* parent, int id, long additional_style, bool multi_sel)
|
ItemList::ItemList(Window* parent, int id, long additional_style, bool multi_sel)
|
||||||
: wxListView(parent, id, wxDefaultPosition, wxDefaultSize, additional_style | wxLC_REPORT | wxLC_VIRTUAL | (multi_sel ? 0 : wxLC_SINGLE_SEL))
|
: wxListView(parent, id, wxDefaultPosition, wxDefaultSize, additional_style | wxLC_REPORT | wxLC_VIRTUAL | (multi_sel ? 0 : wxLC_SINGLE_SEL))
|
||||||
, selected_item_pos(-1)
|
, selected_item_pos(-1)
|
||||||
, sort_by_column(-1), sort_ascending(true)
|
, sort_by_column(-1), sort_by_column2(-1), sort_by_column3(-1), sort_ascending(true)
|
||||||
{
|
{
|
||||||
// create image list
|
// create image list
|
||||||
wxImageList* il = new wxImageList(18,14);
|
wxImageList* il = new wxImageList(18,14);
|
||||||
@@ -263,6 +263,8 @@ void ItemList::onColumnClick(wxListEvent& ev) {
|
|||||||
new_sort_by_column = -1; // 3rd click on same column -> don't sort
|
new_sort_by_column = -1; // 3rd click on same column -> don't sort
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
sort_by_column3 = sort_by_column2;
|
||||||
|
sort_by_column2 = sort_by_column;
|
||||||
sort_ascending = true;
|
sort_ascending = true;
|
||||||
}
|
}
|
||||||
sortBy(new_sort_by_column, sort_ascending);
|
sortBy(new_sort_by_column, sort_ascending);
|
||||||
|
|||||||
@@ -107,6 +107,8 @@ protected:
|
|||||||
VoidP selected_item; ///< The currently selected item
|
VoidP selected_item; ///< The currently selected item
|
||||||
long selected_item_pos; ///< Position of the selected item in the sorted_list, or -1 if no card is selected
|
long selected_item_pos; ///< Position of the selected item in the sorted_list, or -1 if no card is selected
|
||||||
long sort_by_column; ///< Column to use for sorting, or -1 if not sorted
|
long sort_by_column; ///< Column to use for sorting, or -1 if not sorted
|
||||||
|
long sort_by_column2; ///< Previous column used for sorting, or -1 if not sorted
|
||||||
|
long sort_by_column3; ///< Previous previous column used for sorting, or -1 if not sorted (stable sort aint workin so we doing this I guess)
|
||||||
bool sort_ascending; ///< Sort order
|
bool sort_ascending; ///< Sort order
|
||||||
vector<VoidP> sorted_list; ///< Sorted list of items, can be considered a map: pos->item
|
vector<VoidP> sorted_list; ///< Sorted list of items, can be considered a map: pos->item
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user