From a693eb7eb5082be764461fbb425b69cfbb3ddbd5 Mon Sep 17 00:00:00 2001 From: hikerstk Date: Thu, 18 Apr 2013 22:44:18 +0000 Subject: [PATCH] Added reverse-sorting of addons (#916). Thanks to ingridmorstrad for the patch. git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@12673 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- data/gui/skins/Glass.stkskin | 1 + data/gui/skins/Ocean.stkskin | 1 + data/gui/skins/Peach.stkskin | 1 + data/gui/skins/glass/list_sort_down.png | Bin 0 -> 3177 bytes data/gui/skins/ocean/list_sort_down.png | Bin 0 -> 3177 bytes data/gui/skins/peach/list_sort_down.png | Bin 0 -> 3177 bytes src/addons/addon.hpp | 37 +++++++++++++++--- src/config/user_config.cpp | 7 ++++ src/guiengine/skin.cpp | 10 ++++- src/guiengine/widgets/list_widget.cpp | 4 ++ src/guiengine/widgets/list_widget.hpp | 3 ++ src/io/file_manager.cpp | 2 +- src/race/race_manager.cpp | 9 ++++- src/states_screens/addons_screen.cpp | 6 ++- src/states_screens/addons_screen.hpp | 3 ++ src/states_screens/state_manager.hpp | 2 +- src/utils/ptr_vector.hpp | 48 +++++++++++++++++------- 17 files changed, 109 insertions(+), 25 deletions(-) create mode 100644 data/gui/skins/glass/list_sort_down.png create mode 100644 data/gui/skins/ocean/list_sort_down.png create mode 100644 data/gui/skins/peach/list_sort_down.png 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 0000000000000000000000000000000000000000..d091ab4d026b85788962e0788b5380c3b17f584f GIT binary patch literal 3177 zcmV-v43_hWP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGf6951U69E94oEQKA00v@9M??Vs0RI60 zpuMM)00007bV*G`2igS!0|OW*pQqjc001I%MObu0Z*6U5Zgc=ca%Ew3Wn>_CX>@2H zM@dakAa8CUVIWOmV~41BLjV8^t4TybRCr$PT3d4y$rT>kvccSO1z3`*gk>x2ODZqC zrKk#9Tcox^Ub3lV-}Afj3-&3gT-d;Z4fp~Zn_V#2mM^j;S(aqo?;6c5-#6AV?e+-d zi=c|Ns>agv%yjqp&Ue0Zy2plb^f^M{2!SI6ju7|}Bk-p${}B4In*Zm&+z$19cJnu( z(XmOp4MHEj3CO@ee}Dhb;Gn^VzCQka{o%Q^>A!iG-^Oq0RC!+SO9$WcJilrCo4=KF zxu)KyKO=ogyJ=aT>fqbY?(`F^+yc{VT27%C{#2M32=Pi2?A+YP$_(ry(3 zsI1X@3-V%{3>^m+13S;mzv8u8t$Hq-UCZYSqps)8qOF9(y-fxv01&^E{e6AEx_tTa zS64p1^7$|D357!ag0TAS_bfBq0(#dc$l##R+3Ee)ovGf}nV^zV!ch7qJEhIGZFdcy z)yV4oR4Vl~0Cr6p&(#`8SxsNPDYFI0|Nv895y%8&B@8h2a%QKuhZ$wJ!nA&bG10%AOQLx zenS_2GV;m!k&!QcdF|7`UcY|*(@U2=3b8ZGviw7gRgGku?s1;0-cZlgcD279%u+ZN z)VJP0Zx<)Q^F}I_w4ObC77j1W{jF3i{x_2?M4$sSz(#@%o)FpV>pgu6bgCw z)vH&VD=W*R^;+dWt(FxrTUG~y;_U2;v2v;K z53ALhfi2}?xw7qOI*I`7&SkhT7#d){EZJ7;d8t@j42m z1%wkM1Nbcmud`pZP5mv*Q5nQO)PvVJ7t=J2QmJIbVo`H`etxc8Dn76+>p3E^luT!7 z)2>e-0P&4Y(xl}$_PW(-PNh@H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Wv{#K&uM-&koGFj0Pw&U$@dhMkzE-J>0{9n9d8@IF zu2bHD(qPcTZNx=#zZ2Kn1MJIuxj*ViK`Yloje|tDF_BjUG6^+02Dkns=YOo z8wg(DGjW4R@(mjO2_wZDmlUGAQrMGxm!h_dT?^8>} zc+x+c&2V=olUR>GYS!zd{@Q+0-k~#KyF;XC)ZTg9GM}MTo`OgvAXYv#Wvw6p&`>d4 zjMj~pRUXq`rBX2^?(KU4&E;aX)3Z%D|#R?Pvb=#$pQk#01URlmpD;2*=R9}V=0A`EC`nowcKR1t*_bqCQ??C;{!%TVV{QQ5qz|l(v za0EnxSAr)gW{;N^mtG+~HfXH8Bjh*ZAMfuSsD2W=JCpvdE?0SYwcjn3_j;fF2TM-@ zXctHpV8}3!!?TYT!V7q7ld(yE*+r_9%Ut3Xqp|3;WtxvX$Kl2%py*Gi=Qvlk6 zC{?y~JpGp4&h^9BMS0 z7x7CJSwRxRIgZToxfF!eI!1p)9*LO=$laokqt8>VKx_6-#O@7P25C(dWko{hv3 zhqlV=mZ9$yfcB*De@br7v8-n;v;HsaEI&l5#Cp1SDet{z0ex_Id227x^D-!N!!SO^ zQn%gSt>X^uzW2cZgT}5z*9k&{p2vC5^L;18-U|RS83OUXJm2%Rz@c%p#~r;_2K3mr zuDU-0pevX@;G2#Z@BurwE7Oh`&=pJ{@J&Yy_<)_;m1#!|=nAF}_@@5@eO(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