diff --git a/data/gui/skins/Glass.stkskin b/data/gui/skins/Glass.stkskin index 418d94050..1e7926ed1 100644 --- a/data/gui/skins/Glass.stkskin +++ b/data/gui/skins/Glass.stkskin @@ -175,6 +175,7 @@ when the border that intersect at this corner are enabled. + + diff --git a/data/gui/skins/Peach.stkskin b/data/gui/skins/Peach.stkskin index 693be4222..cd0e733a8 100644 --- a/data/gui/skins/Peach.stkskin +++ b/data/gui/skins/Peach.stkskin @@ -173,6 +173,7 @@ when the border that intersect at this corner are enabled. + diff --git a/data/gui/skins/glass/list_sort_down.png b/data/gui/skins/glass/list_sort_down.png new file mode 100644 index 000000000..d091ab4d0 Binary files /dev/null and b/data/gui/skins/glass/list_sort_down.png differ diff --git a/data/gui/skins/ocean/list_sort_down.png b/data/gui/skins/ocean/list_sort_down.png new file mode 100644 index 000000000..d091ab4d0 Binary files /dev/null and b/data/gui/skins/ocean/list_sort_down.png differ diff --git a/data/gui/skins/peach/list_sort_down.png b/data/gui/skins/peach/list_sort_down.png new file mode 100644 index 000000000..d091ab4d0 Binary files /dev/null and b/data/gui/skins/peach/list_sort_down.png differ diff --git a/src/addons/addon.hpp b/src/addons/addon.hpp index 2514ad02e..69ca37953 100644 --- a/src/addons/addon.hpp +++ b/src/addons/addon.hpp @@ -273,11 +273,11 @@ public: { switch(m_sort_order) { - case SO_DEFAULT: - if(testStatus(AS_FEATURED) && - !a.testStatus(AS_FEATURED)) return true; - if(!testStatus(AS_FEATURED) && - a.testStatus(AS_FEATURED)) return false; + case SO_DEFAULT: + if(testStatus(AS_FEATURED) && + !a.testStatus(AS_FEATURED)) return true; + if(!testStatus(AS_FEATURED) && + a.testStatus(AS_FEATURED)) return false; // Otherwise fall through to name comparison! case SO_NAME: // m_id is the lower case name @@ -291,6 +291,33 @@ public: return true; } // operator< + // ------------------------------------------------------------------------ + /** Compares two addons according to the sort order currently defined. + * Comparison is done for sorting in descending order. + * \param a The addon to compare this addon to. + */ + bool operator>(const Addon &a) const + { + switch(m_sort_order) + { + case SO_DEFAULT: + if(testStatus(AS_FEATURED) && + !a.testStatus(AS_FEATURED)) return true; + if(!testStatus(AS_FEATURED) && + a.testStatus(AS_FEATURED)) return false; + // Otherwise fall through to name comparison! + case SO_NAME: + // m_id is the lower case name + return m_id > a.m_id; + break; + case SO_DATE: + return m_date < a.m_date; + break; + } // switch + // Fix compiler warning. + return true; + } // operator> + }; // Addon diff --git a/src/config/user_config.cpp b/src/config/user_config.cpp index 1afa19ea7..c8578da42 100644 --- a/src/config/user_config.cpp +++ b/src/config/user_config.cpp @@ -569,6 +569,13 @@ bool operator<(const PlayerProfile &a, const PlayerProfile &b) return a.getUseFrequency() > b.getUseFrequency(); } // operator< +// ----------------------------------------------------------------------------- +/** \brief Needed for toggling sort order **/ +bool operator>(const PlayerProfile &a, const PlayerProfile &b) +{ + return a.getUseFrequency() < b.getUseFrequency(); +} // operator> + // ----------------------------------------------------------------------------- /** Load configuration values from file. */ bool UserConfig::loadConfig() diff --git a/src/guiengine/skin.cpp b/src/guiengine/skin.cpp index 54a549e24..6552b3b75 100644 --- a/src/guiengine/skin.cpp +++ b/src/guiengine/skin.cpp @@ -1504,8 +1504,14 @@ void Skin::drawListHeader(const irr::core::rect< irr::s32 > &rect, if (isSelected) { - ITexture* img = - SkinConfig::m_render_params["list_sort_up::neutral"].getImage(); + /** \brief img sets the icon for the column according to sort order **/ + ITexture* img; + if (((ListWidget*)widget->m_event_handler)->m_sort_desc) + img = + SkinConfig::m_render_params["list_sort_down::neutral"].getImage(); + else + img = + SkinConfig::m_render_params["list_sort_up::neutral"].getImage(); core::recti destRect(rect.UpperLeftCorner, core::dimension2di(rect.getHeight(), rect.getHeight())); diff --git a/src/guiengine/widgets/list_widget.cpp b/src/guiengine/widgets/list_widget.cpp index f2438b838..8ce81905e 100644 --- a/src/guiengine/widgets/list_widget.cpp +++ b/src/guiengine/widgets/list_widget.cpp @@ -39,6 +39,7 @@ ListWidget::ListWidget() : Widget(WTYPE_LIST) m_icons = NULL; m_listener = NULL; m_selected_column = NULL; + m_sort_desc = true; } // ----------------------------------------------------------------------------- @@ -371,6 +372,9 @@ EventPropagation ListWidget::transmitEvent(Widget* w, int col = originator[ (m_properties[PROP_ID] + "_column_").size() ] - '0'; m_selected_column = m_header_elements.get(col); + + /** \brief Allows sort icon to change depending on sort order **/ + m_sort_desc = !m_sort_desc; /* for (int n=0; n a.m_score) || (m_score == a.m_score && m_race_time < a.m_race_time) ); } - + + // -------------------------------------------------------------------- + bool operator>(const SortData &a) + { + return ( (m_score < a.m_score) || + (m_score == a.m_score && m_race_time > a.m_race_time) ); + } + }; // SortData } // namespace diff --git a/src/states_screens/addons_screen.cpp b/src/states_screens/addons_screen.cpp index 2db1b65d5..d1db10399 100644 --- a/src/states_screens/addons_screen.cpp +++ b/src/states_screens/addons_screen.cpp @@ -93,6 +93,8 @@ void AddonsScreen::init() m_reloading = false; + m_sort_desc = true; + getWidget("category")->setDeactivated(); GUIEngine::getFont()->setTabStop(0.66f); @@ -163,7 +165,7 @@ void AddonsScreen::loadList() continue; sorted_list.push_back(&addon); } - sorted_list.insertionSort(/*start=*/0); + sorted_list.insertionSort(/*start=*/0, m_sort_desc); GUIEngine::ListWidget* w_list = getWidget("list_addons"); @@ -298,6 +300,8 @@ void AddonsScreen::onColumnClicked(int column_id) case 1: Addon::setSortOrder(Addon::SO_DATE); break; default: assert(0); } // switch + /** \brief Toggle the sort order after column click **/ + m_sort_desc = !m_sort_desc; loadList(); } // onColumnClicked diff --git a/src/states_screens/addons_screen.hpp b/src/states_screens/addons_screen.hpp index 2c485b2dd..5da45b6d2 100644 --- a/src/states_screens/addons_screen.hpp +++ b/src/states_screens/addons_screen.hpp @@ -67,6 +67,9 @@ private: bool m_reloading; + /** \brief To check (and set) if sort order is descending **/ + bool m_sort_desc; + public: /** Load the addons into the main list.*/ diff --git a/src/states_screens/state_manager.hpp b/src/states_screens/state_manager.hpp index ae460c136..e6fdfe8ae 100644 --- a/src/states_screens/state_manager.hpp +++ b/src/states_screens/state_manager.hpp @@ -62,7 +62,7 @@ public: /** * Represents a player that is currently playing. - * Ties toghether : + * Ties together : * - a player's identity (and thus his/her highscores) * - which input device is used by which player * (we're very flexible on this; ActivePlayer #1 diff --git a/src/utils/ptr_vector.hpp b/src/utils/ptr_vector.hpp index 566f0a56c..19cb8079e 100644 --- a/src/utils/ptr_vector.hpp +++ b/src/utils/ptr_vector.hpp @@ -249,24 +249,44 @@ public: } // erase // ------------------------------------------------------------------------ - void insertionSort(unsigned int start=0) + void insertionSort(unsigned int start=0, bool desc = false) { - // We should not used unsigned ints here, because if the vector is - // empty j needs to be compared against -1 - for(int j=(int)start; j<(int)m_contents_vector.size()-1; j++) + if (!desc) { - if(*(m_contents_vector[j])<*(m_contents_vector[j+1])) continue; - // Now search the proper place for m_contents_vector[j+1] - // in the sorted section contentsVectot[start:j] - TYPE* t=m_contents_vector[j+1]; - unsigned int i = j+1; - do + // We should not used unsigned ints here, because if the vector is + // empty j needs to be compared against -1 + for(int j=(int)start; j<(int)m_contents_vector.size()-1; j++) { - m_contents_vector[i] = m_contents_vector[i-1]; - i--; - } while (i>start && *t<*(m_contents_vector[i-1])); - m_contents_vector[i]=t; + if(*(m_contents_vector[j])<*(m_contents_vector[j+1])) continue; + // Now search the proper place for m_contents_vector[j+1] + // in the sorted section contentsVectot[start:j] + TYPE* t=m_contents_vector[j+1]; + unsigned int i = j+1; + do + { + m_contents_vector[i] = m_contents_vector[i-1]; + i--; + } while (i>start && *t<*(m_contents_vector[i-1])); + m_contents_vector[i]=t; + } } + else + { + for(int j=(int)start; j<(int)m_contents_vector.size()-1; j++) + { + if(*(m_contents_vector[j])>*(m_contents_vector[j+1])) continue; + // Now search the proper place for m_contents_vector[j+1] + // in the sorted section contentsVectot[start:j] + TYPE* t=m_contents_vector[j+1]; + unsigned int i = j+1; + do + { + m_contents_vector[i] = m_contents_vector[i-1]; + i--; + } while (i>start && *t>*(m_contents_vector[i-1])); + m_contents_vector[i]=t; + } + } } // insertionSort