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
This commit is contained in:
hikerstk 2013-04-18 22:44:18 +00:00
parent 418b024d6d
commit a693eb7eb5
17 changed files with 109 additions and 25 deletions

View File

@ -175,6 +175,7 @@ when the border that intersect at this corner are enabled.
<element type="list_header" state="neutral" image="glass/table_header.png" />
<element type="list_header" state="down" image="glass/table_header_down.png" />
<element type="list_sort_up" state="neutral" image="glass/list_sort_up.png" />
<element type="list_sort_down" state="neutral" image="glass/list_sort_down.png" />
<!-- Stateless -->
<element type="section" image="glass/glass_section.png"

View File

@ -174,6 +174,7 @@ when the border that intersect at this corner are enabled.
<element type="list_header" state="neutral" image="ocean/table_header.png" />
<element type="list_sort_up" state="neutral" image="ocean/list_sort_up.png" />
<element type="list_sort_down" state="neutral" image="ocean/list_sort_down.png" />
<element type="list_header" state="down" image="ocean/table_header_down.png" />
<!-- Stateless -->

View File

@ -173,6 +173,7 @@ when the border that intersect at this corner are enabled.
<element type="list_header" state="neutral" image="peach/table_header.png" />
<element type="list_sort_up" state="neutral" image="peach/list_sort_up.png" />
<element type="list_sort_down" state="neutral" image="peach/list_sort_down.png" />
<element type="list_header" state="down" image="peach/table_header_down.png" />
<!-- Stateless -->

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

View File

@ -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

View File

@ -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()

View File

@ -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()));

View File

@ -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<m_header_elements.size(); n++)
{

View File

@ -67,6 +67,9 @@ namespace GUIEngine
ButtonWidget* m_selected_column;
/** \brief whether this list is sorted in descending order */
bool m_sort_desc;
struct Column
{
irr::core::stringw m_text;

View File

@ -821,7 +821,7 @@ std::string FileManager::checkAndCreateLinuxDir(const char *env_name,
const std::string &FileManager::getAddonsDir() const
{
return m_addons_dir;
} // getADdonsDir
} // getAddonsDir
//-----------------------------------------------------------------------------
/** Returns the full path of a file in the addons directory.

View File

@ -493,7 +493,14 @@ namespace computeGPRanksData
return ( (m_score > 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

View File

@ -93,6 +93,8 @@ void AddonsScreen::init()
m_reloading = false;
m_sort_desc = true;
getWidget<GUIEngine::RibbonWidget>("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<GUIEngine::ListWidget>("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

View File

@ -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.*/

View File

@ -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

View File

@ -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