summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-10-17 19:57:00 +0000
committertron <tron@openttd.org>2005-10-17 19:57:00 +0000
commit23ecc82ad31b29dbf2adc3dd0f6f7550b3ac3e69 (patch)
tree55174ff380184f8b141b398364301899461e7fb6
parentb85da4fef2897039e198da97f524f1ca9c6bf913 (diff)
downloadopenttd-23ecc82ad31b29dbf2adc3dd0f6f7550b3ac3e69.tar.xz
(svn r3055) Give the savegame/scenarion sort order flags symbolic names
-rw-r--r--misc_gui.c24
-rw-r--r--openttd.c2
-rw-r--r--openttd.h7
-rw-r--r--os2.c13
-rw-r--r--unix.c13
-rw-r--r--win32.c13
6 files changed, 47 insertions, 25 deletions
diff --git a/misc_gui.c b/misc_gui.c
index 2701ec4e9..e040c96ea 100644
--- a/misc_gui.c
+++ b/misc_gui.c
@@ -1246,7 +1246,11 @@ static void SaveLoadDlgWndProc(Window *w, WindowEvent *e)
}
GfxFillRect(w->widget[6].left + 1, w->widget[6].top + 1, w->widget[6].right, w->widget[6].bottom, 0xD7);
- DoDrawString(_savegame_sort_order & 1 ? DOWNARROW : UPARROW, _savegame_sort_order <= 1 ? w->widget[3].right - 9 : w->widget[2].right - 9, 15, 0x10);
+ DoDrawString(
+ _savegame_sort_order & SORT_DESCENDING ? DOWNARROW : UPARROW,
+ _savegame_sort_order & SORT_BY_NAME ? w->widget[2].right - 9 : w->widget[3].right - 9,
+ 15, 16
+ );
y = w->widget[6].top + 1;
pos = w->vscroll.pos;
@@ -1267,13 +1271,15 @@ static void SaveLoadDlgWndProc(Window *w, WindowEvent *e)
case WE_CLICK:
switch(e->click.widget) {
case 2: /* Sort save names by name */
- _savegame_sort_order = (_savegame_sort_order == 2) ? 3 : 2;
+ _savegame_sort_order = (_savegame_sort_order == SORT_BY_NAME) ?
+ SORT_BY_NAME | SORT_DESCENDING : SORT_BY_NAME;
_savegame_sort_dirty = true;
SetWindowDirty(w);
break;
case 3: /* Sort save names by date */
- _savegame_sort_order = (_savegame_sort_order == 0) ? 1 : 0;
+ _savegame_sort_order = (_savegame_sort_order == SORT_BY_DATE) ?
+ SORT_BY_DATE | SORT_DESCENDING : SORT_BY_DATE;
_savegame_sort_dirty = true;
SetWindowDirty(w);
break;
@@ -1489,7 +1495,11 @@ static void SelectScenarioWndProc(Window *w, WindowEvent *e) {
SetVScrollCount(w, _fios_num);
DrawWindowWidgets(w);
- DoDrawString(_savegame_sort_order & 1 ? DOWNARROW : UPARROW, _savegame_sort_order <= 1 ? w->widget[4].right - 9 : w->widget[3].right - 9, 15, 0x10);
+ DoDrawString(
+ _savegame_sort_order & SORT_DESCENDING ? DOWNARROW : UPARROW,
+ _savegame_sort_order & SORT_BY_NAME ? w->widget[3].right - 9 : w->widget[4].right - 9,
+ 15, 16
+ );
DrawString(4, 32, STR_4010_GENERATE_RANDOM_NEW_GAME, 9);
y = list_start;
@@ -1508,13 +1518,15 @@ static void SelectScenarioWndProc(Window *w, WindowEvent *e) {
case WE_CLICK:
switch(e->click.widget) {
case 3: /* Sort scenario names by name */
- _savegame_sort_order = (_savegame_sort_order == 2) ? 3 : 2;
+ _savegame_sort_order = (_savegame_sort_order == SORT_BY_NAME) ?
+ SORT_BY_NAME | SORT_DESCENDING : SORT_BY_NAME;
_savegame_sort_dirty = true;
SetWindowDirty(w);
break;
case 4: /* Sort scenario names by date */
- _savegame_sort_order = (_savegame_sort_order == 0) ? 1 : 0;
+ _savegame_sort_order = (_savegame_sort_order == SORT_BY_DATE) ?
+ SORT_BY_DATE | SORT_DESCENDING : SORT_BY_DATE;
_savegame_sort_dirty = true;
SetWindowDirty(w);
break;
diff --git a/openttd.c b/openttd.c
index 0e06fed7e..2ecd53a11 100644
--- a/openttd.c
+++ b/openttd.c
@@ -470,7 +470,7 @@ int ttd_main(int argc, char* argv[])
LoadDriver(SOUND_DRIVER, _ini_sounddriver);
LoadDriver(MUSIC_DRIVER, _ini_musicdriver);
LoadDriver(VIDEO_DRIVER, _ini_videodriver); // load video last, to prevent an empty window while sound and music loads
- _savegame_sort_order = 1; // default sorting of savegames is by date, newest first
+ _savegame_sort_order = SORT_BY_DATE | SORT_DESCENDING;
#ifdef ENABLE_NETWORK
// initialize network-core
diff --git a/openttd.h b/openttd.h
index 0796778db..26f45f219 100644
--- a/openttd.h
+++ b/openttd.h
@@ -523,6 +523,13 @@ enum SpecialStrings {
typedef void PlaceProc(TileIndex tile);
+enum {
+ SORT_ASCENDING = 0,
+ SORT_DESCENDING = 1,
+ SORT_BY_DATE = 0,
+ SORT_BY_NAME = 2
+};
+
VARDEF byte _savegame_sort_order;
#define INVALID_UINT_TILE (uint)0xFFFFFFFF
diff --git a/os2.c b/os2.c
index d4411bbb8..f414a4a1c 100644
--- a/os2.c
+++ b/os2.c
@@ -51,12 +51,13 @@ int compare_FiosItems(const void *a, const void *b)
const FiosItem *db = (const FiosItem *)b;
int r;
- if (_savegame_sort_order < 2) // sort by date
- r = da->mtime < db->mtime ? -1 : 1;
- else
+ if (_savegame_sort_order & SORT_BY_NAME) {
r = strcasecmp(da->title, db->title);
+ } else {
+ r = da->mtime < db->mtime ? -1 : 1;
+ }
- if (_savegame_sort_order & 1) r = -r;
+ if (_savegame_sort_order & SORT_DESCENDING) r = -r;
return r;
}
@@ -116,7 +117,7 @@ FiosItem *FiosGetSavegameList(int *num, int mode)
{
/* XXX ugly global variables ... */
byte order = _savegame_sort_order;
- _savegame_sort_order = 2; // sort ascending by name
+ _savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING;
qsort(_fios_items, _fios_count, sizeof(FiosItem), compare_FiosItems);
_savegame_sort_order = order;
}
@@ -243,7 +244,7 @@ FiosItem *FiosGetScenarioList(int *num, int mode)
{
/* XXX ugly global variables ... */
byte order = _savegame_sort_order;
- _savegame_sort_order = 2; // sort ascending by name
+ _savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING;
qsort(_fios_items, _fios_count, sizeof(FiosItem), compare_FiosItems);
_savegame_sort_order = order;
}
diff --git a/unix.c b/unix.c
index 3496a6452..3fb95569f 100644
--- a/unix.c
+++ b/unix.c
@@ -70,12 +70,13 @@ int compare_FiosItems(const void *a, const void *b)
const FiosItem *db = (const FiosItem *)b;
int r;
- if (_savegame_sort_order < 2) // sort by date
- r = da->mtime < db->mtime ? -1 : 1;
- else
+ if (_savegame_sort_order & SORT_BY_NAME) {
r = strcasecmp(da->title, db->title);
+ } else {
+ r = da->mtime < db->mtime ? -1 : 1;
+ }
- if (_savegame_sort_order & 1) r = -r;
+ if (_savegame_sort_order & SORT_DESCENDING) r = -r;
return r;
}
@@ -128,7 +129,7 @@ FiosItem *FiosGetSavegameList(int *num, int mode)
{
/* XXX ugly global variables ... */
byte order = _savegame_sort_order;
- _savegame_sort_order = 2; // sort ascending by name
+ _savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING;
qsort(_fios_items, _fios_count, sizeof(FiosItem), compare_FiosItems);
_savegame_sort_order = order;
}
@@ -229,7 +230,7 @@ FiosItem *FiosGetScenarioList(int *num, int mode)
{
/* XXX ugly global variables ... */
byte order = _savegame_sort_order;
- _savegame_sort_order = 2; // sort ascending by name
+ _savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING;
qsort(_fios_items, _fios_count, sizeof(FiosItem), compare_FiosItems);
_savegame_sort_order = order;
}
diff --git a/win32.c b/win32.c
index 20c3e1c80..5188065ea 100644
--- a/win32.c
+++ b/win32.c
@@ -644,12 +644,13 @@ int CDECL compare_FiosItems(const void *a, const void *b)
const FiosItem *db = (const FiosItem *)b;
int r;
- if (_savegame_sort_order < 2) // sort by date
- r = da->mtime < db->mtime ? -1 : 1;
- else
+ if (_savegame_sort_order & SORT_BY_NAME) {
r = strcasecmp(da->title, db->title);
+ } else {
+ r = da->mtime < db->mtime ? -1 : 1;
+ }
- if (_savegame_sort_order & 1) r = -r;
+ if (_savegame_sort_order & SORT_DESCENDING) r = -r;
return r;
}
@@ -698,7 +699,7 @@ FiosItem *FiosGetSavegameList(int *num, int mode)
{
/* XXX ugly global variables ... */
byte order = _savegame_sort_order;
- _savegame_sort_order = 2; // sort ascending by name
+ _savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING;
qsort(_fios_items, _fios_count, sizeof(FiosItem), compare_FiosItems);
_savegame_sort_order = order;
}
@@ -812,7 +813,7 @@ FiosItem *FiosGetScenarioList(int *num, int mode)
{
/* XXX ugly global variables ... */
byte order = _savegame_sort_order;
- _savegame_sort_order = 2; // sort ascending by name
+ _savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING;
qsort(_fios_items, _fios_count, sizeof(FiosItem), compare_FiosItems);
_savegame_sort_order = order;
}