Fix list sorting (#3368)
* Manage if the sort should be default, ascending or descending from the base widget * Update all list sorting to be in sync with the list widget sort buttons
This commit is contained in:
parent
c58ac1b111
commit
f5a308f94b
@ -479,7 +479,7 @@ EventPropagation ListWidget::transmitEvent(Widget* w,
|
||||
m_header_elements[col].getIrrlichtElement<IGUIButton>()->setPressed(true);
|
||||
*/
|
||||
|
||||
if (m_listener) m_listener->onColumnClicked(m_sort_col);
|
||||
if (m_listener) m_listener->onColumnClicked(m_sort_col, m_sort_desc, m_sort_default);
|
||||
|
||||
return EVENT_BLOCK;
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ namespace GUIEngine
|
||||
public:
|
||||
virtual ~IListWidgetHeaderListener(){}
|
||||
|
||||
virtual void onColumnClicked(int columnId) = 0;
|
||||
virtual void onColumnClicked(int column_id, bool sort_desc, bool sort_default) = 0;
|
||||
};
|
||||
|
||||
/** \brief A vertical list widget with text entries
|
||||
|
@ -162,10 +162,6 @@ void AddonsScreen::init()
|
||||
|
||||
m_reloading = false;
|
||||
|
||||
m_sort_desc = false;
|
||||
m_sort_default = true;
|
||||
m_sort_col = 0;
|
||||
|
||||
getWidget<GUIEngine::RibbonWidget>("category")->setActive(false);
|
||||
|
||||
if(UserConfigParams::logAddons())
|
||||
@ -232,7 +228,7 @@ void AddonsScreen::tearDown()
|
||||
* updated.
|
||||
* \param type Must be 'kart' or 'track'.
|
||||
*/
|
||||
void AddonsScreen::loadList()
|
||||
void AddonsScreen::loadList(bool sort_desc)
|
||||
{
|
||||
#ifndef SERVER_ONLY
|
||||
// Get the filter by words.
|
||||
@ -287,7 +283,7 @@ void AddonsScreen::loadList()
|
||||
|
||||
sorted_list.push_back(&addon);
|
||||
}
|
||||
sorted_list.insertionSort(/*start=*/0, m_sort_desc);
|
||||
sorted_list.insertionSort(/*start=*/0, sort_desc);
|
||||
|
||||
GUIEngine::ListWidget* w_list =
|
||||
getWidget<GUIEngine::ListWidget>("list_addons");
|
||||
@ -420,33 +416,20 @@ void AddonsScreen::loadList()
|
||||
} // loadList
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void AddonsScreen::onColumnClicked(int column_id)
|
||||
void AddonsScreen::onColumnClicked(int column_id, bool sort_desc, bool sort_default)
|
||||
{
|
||||
if (m_sort_col != column_id)
|
||||
{
|
||||
m_sort_desc = false;
|
||||
m_sort_default = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!m_sort_default) m_sort_desc = !m_sort_desc;
|
||||
m_sort_default = !m_sort_desc && !m_sort_default;
|
||||
}
|
||||
|
||||
m_sort_col = column_id;
|
||||
|
||||
switch(column_id)
|
||||
{
|
||||
case 0:
|
||||
Addon::setSortOrder(m_sort_default ? Addon::SO_DEFAULT : Addon::SO_NAME);
|
||||
Addon::setSortOrder(sort_default ? Addon::SO_DEFAULT : Addon::SO_NAME);
|
||||
break;
|
||||
case 1:
|
||||
Addon::setSortOrder(m_sort_default ? Addon::SO_DEFAULT : Addon::SO_DATE);
|
||||
Addon::setSortOrder(sort_default ? Addon::SO_DEFAULT : Addon::SO_DATE);
|
||||
break;
|
||||
default: assert(0); break;
|
||||
} // switch
|
||||
/** \brief Toggle the sort order after column click **/
|
||||
loadList();
|
||||
loadList(sort_desc && !sort_default);
|
||||
} // onColumnClicked
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -73,13 +73,6 @@ private:
|
||||
|
||||
bool m_reloading;
|
||||
|
||||
/** \brief To check (and set) if sort order is descending **/
|
||||
bool m_sort_desc;
|
||||
|
||||
bool m_sort_default;
|
||||
|
||||
int m_sort_col;
|
||||
|
||||
/** List of date filters **/
|
||||
std::vector<DateFilter> m_date_filters;
|
||||
|
||||
@ -88,7 +81,7 @@ private:
|
||||
public:
|
||||
|
||||
/** Load the addons into the main list.*/
|
||||
void loadList();
|
||||
void loadList(bool sort_desc = false);
|
||||
|
||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||
virtual void loadedFromFile() OVERRIDE;
|
||||
@ -102,7 +95,7 @@ public:
|
||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||
virtual void beforeAddingWidget() OVERRIDE;
|
||||
|
||||
virtual void onColumnClicked(int columnId) OVERRIDE;
|
||||
virtual void onColumnClicked(int column_id, bool sort_desc, bool sort_default) OVERRIDE;
|
||||
|
||||
virtual void init() OVERRIDE;
|
||||
virtual void tearDown() OVERRIDE;
|
||||
|
@ -32,7 +32,6 @@ using namespace GUIEngine;
|
||||
*/
|
||||
GhostReplaySelection::GhostReplaySelection() : Screen("ghost_replay_selection.stkgui")
|
||||
{
|
||||
m_sort_desc = true;
|
||||
m_is_comparing = false;
|
||||
m_replay_to_compare_uid = 0;
|
||||
} // GhostReplaySelection
|
||||
@ -424,11 +423,16 @@ void GhostReplaySelection::onConfirm()
|
||||
/** Change the sort order if a column was clicked.
|
||||
* \param column_id ID of the column that was clicked.
|
||||
*/
|
||||
void GhostReplaySelection::onColumnClicked(int column_id)
|
||||
void GhostReplaySelection::onColumnClicked(int column_id, bool sort_desc, bool sort_default)
|
||||
{
|
||||
// Begin by resorting the list to default
|
||||
defaultSort();
|
||||
|
||||
if (sort_default)
|
||||
{
|
||||
loadList();
|
||||
return;
|
||||
}
|
||||
|
||||
int diff_difficulty = m_same_difficulty ? 1 : 0;
|
||||
int diff_linear = m_active_mode_is_linear ? 0 : 1;
|
||||
@ -461,10 +465,7 @@ void GhostReplaySelection::onColumnClicked(int column_id)
|
||||
else
|
||||
assert(0);
|
||||
|
||||
/** \brief Toggle the sort order after column click **/
|
||||
m_sort_desc = !m_sort_desc;
|
||||
|
||||
ReplayPlay::get()->sortReplay(m_sort_desc);
|
||||
ReplayPlay::get()->sortReplay(sort_desc);
|
||||
|
||||
loadList();
|
||||
} // onColumnClicked
|
||||
|
@ -54,7 +54,6 @@ private:
|
||||
bool m_same_difficulty;
|
||||
bool m_same_version;
|
||||
bool m_best_times;
|
||||
bool m_sort_desc;
|
||||
bool m_is_comparing;
|
||||
bool m_active_mode_is_linear;
|
||||
RaceManager::MinorRaceModeType m_active_mode;
|
||||
@ -90,7 +89,7 @@ public:
|
||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||
virtual void beforeAddingWidget() OVERRIDE;
|
||||
|
||||
virtual void onColumnClicked(int columnId) OVERRIDE;
|
||||
virtual void onColumnClicked(int column_id, bool sort_desc, bool sort_default) OVERRIDE;
|
||||
|
||||
virtual void init() OVERRIDE;
|
||||
|
||||
|
@ -34,7 +34,8 @@ using namespace irr::gui;
|
||||
using namespace Online;
|
||||
|
||||
int OnlineProfileFriends::m_sort_column = 0;
|
||||
bool OnlineProfileFriends::m_sort_increasing = true;
|
||||
bool OnlineProfileFriends::m_sort_desc = false;
|
||||
bool OnlineProfileFriends::m_sort_default = true;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
/** Constructor for a display of all friends.
|
||||
@ -81,8 +82,6 @@ void OnlineProfileFriends::beforeAddingWidget()
|
||||
void OnlineProfileFriends::init()
|
||||
{
|
||||
OnlineProfileBase::init();
|
||||
m_sort_column = 0;
|
||||
m_sort_increasing = true;
|
||||
m_profile_tabs->select( m_friends_tab->m_properties[PROP_ID],
|
||||
PLAYER_ID_GAME_MASTER );
|
||||
m_profile_tabs->setFocusForPlayer(PLAYER_ID_GAME_MASTER);
|
||||
@ -120,15 +119,11 @@ void OnlineProfileFriends::eventCallback(Widget* widget,
|
||||
} // eventCallback
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
void OnlineProfileFriends::onColumnClicked(int column_id)
|
||||
void OnlineProfileFriends::onColumnClicked(int column_id, bool sort_desc, bool sort_default)
|
||||
{
|
||||
if (column_id == m_sort_column)
|
||||
m_sort_increasing = !m_sort_increasing;
|
||||
else
|
||||
{
|
||||
m_sort_increasing = true;
|
||||
}
|
||||
m_sort_column = column_id;
|
||||
m_sort_desc = sort_desc;
|
||||
m_sort_default = sort_default;
|
||||
displayResults();
|
||||
} // onColumnClicked
|
||||
|
||||
@ -140,20 +135,14 @@ bool OnlineProfileFriends::compareFriends(int f1, int f2)
|
||||
switch (m_sort_column)
|
||||
{
|
||||
case 0: // sort by name
|
||||
if (m_sort_increasing)
|
||||
return p1->getUserName().lower_ignore_case(p2->getUserName());
|
||||
else
|
||||
return p2->getUserName().lower_ignore_case(p1->getUserName());
|
||||
return p1->getUserName().lower_ignore_case(p2->getUserName());
|
||||
case 1: // sort by date
|
||||
{
|
||||
OnlineProfile::RelationInfo *r1 = p1->getRelationInfo();
|
||||
OnlineProfile::RelationInfo *r2 = p2->getRelationInfo();
|
||||
// While we are comparing dates that are strings, they are normalised
|
||||
// i.e. contain leading 0 etc, so a string compare works as expected.
|
||||
if (m_sort_increasing)
|
||||
return r1->getDate().lower_ignore_case(r2->getDate());
|
||||
else
|
||||
return r2->getDate().lower_ignore_case(r1->getDate());
|
||||
return r1->getDate().lower_ignore_case(r2->getDate());
|
||||
}
|
||||
case 2: // sort by online status
|
||||
{
|
||||
@ -162,16 +151,12 @@ bool OnlineProfileFriends::compareFriends(int f1, int f2)
|
||||
// In case of same online status, sort by name
|
||||
if (r1->isOnline() == r2->isOnline())
|
||||
{
|
||||
if (m_sort_increasing)
|
||||
return p1->getUserName().lower_ignore_case(p2->getUserName());
|
||||
else
|
||||
return p2->getUserName().lower_ignore_case(p1->getUserName());
|
||||
return p1->getUserName().lower_ignore_case(p2->getUserName());
|
||||
}
|
||||
else
|
||||
if (m_sort_increasing)
|
||||
return r1->isOnline() < r2->isOnline();
|
||||
else
|
||||
return r2->isOnline() < r1->isOnline();
|
||||
{
|
||||
return r1->isOnline() < r2->isOnline();
|
||||
}
|
||||
}
|
||||
default:
|
||||
break;
|
||||
@ -187,7 +172,8 @@ void OnlineProfileFriends::displayResults()
|
||||
{
|
||||
m_friends_list_widget->clear();
|
||||
OnlineProfile::IDList friends = m_visiting_profile->getFriends();
|
||||
std::sort(friends.begin(), friends.end(), compareFriends);
|
||||
(m_sort_desc && !m_sort_default) ? std::sort(friends.rbegin(), friends.rend(), compareFriends)
|
||||
: std::sort(friends.begin(), friends.end(), compareFriends);
|
||||
for (unsigned int i = 0; i < friends.size(); i++)
|
||||
{
|
||||
std::vector<ListWidget::ListCell> row;
|
||||
|
@ -48,11 +48,13 @@ private:
|
||||
GUIEngine::TextBoxWidget *m_search_box_widget;
|
||||
|
||||
bool m_waiting_for_friends;
|
||||
|
||||
/** Which column to use for sorting. */
|
||||
static int m_sort_column;
|
||||
|
||||
/** True is sorting should be increasing. */
|
||||
static bool m_sort_increasing;
|
||||
static bool m_sort_desc;
|
||||
|
||||
static bool m_sort_default;
|
||||
|
||||
void displayResults();
|
||||
static bool compareFriends(int f1, int f2);
|
||||
@ -72,7 +74,7 @@ public:
|
||||
|
||||
virtual void onUpdate(float delta) OVERRIDE;
|
||||
virtual void beforeAddingWidget() OVERRIDE;
|
||||
virtual void onColumnClicked(int columnId) OVERRIDE;
|
||||
virtual void onColumnClicked(int column_id, bool sort_desc, bool sort_default) OVERRIDE;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
/** Triggers a reload of the friend list next time this menu is shown. */
|
||||
|
@ -200,10 +200,18 @@ void ServerSelection::loadList(unsigned sort_case)
|
||||
/** Change the sort order if a column was clicked.
|
||||
* \param column_id ID of the column that was clicked.
|
||||
*/
|
||||
void ServerSelection::onColumnClicked(int column_id)
|
||||
void ServerSelection::onColumnClicked(int column_id, bool sort_desc, bool sort_default)
|
||||
{
|
||||
m_sort_desc = !m_sort_desc;
|
||||
loadList(column_id);
|
||||
if (sort_default)
|
||||
{
|
||||
m_sort_desc = false;
|
||||
loadList(/* distance */ 5);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_sort_desc = sort_desc;
|
||||
loadList(column_id);
|
||||
}
|
||||
} // onColumnClicked
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
@ -80,7 +80,7 @@ public:
|
||||
/** \brief implement callback from parent class GUIEngine::Screen */
|
||||
virtual void beforeAddingWidget() OVERRIDE;
|
||||
|
||||
virtual void onColumnClicked(int columnId) OVERRIDE;
|
||||
virtual void onColumnClicked(int column_id, bool sort_desc, bool sort_default) OVERRIDE;
|
||||
|
||||
virtual void init() OVERRIDE;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user