--- a/src/town_gui.cpp Wed Mar 14 11:15:58 2007 +0000
+++ b/src/town_gui.cpp Fri Mar 16 12:03:49 2007 +0000
@@ -361,14 +361,16 @@
static const Widget _town_directory_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, 13, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
-{ WWT_CAPTION, RESIZE_NONE, 13, 11, 195, 0, 13, STR_2000_TOWNS, STR_018C_WINDOW_TITLE_DRAG_THIS},
-{ WWT_STICKYBOX, RESIZE_NONE, 13, 196, 207, 0, 13, 0x0, STR_STICKY_BUTTON},
-{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 0, 98, 14, 25, STR_SORT_BY_NAME, STR_SORT_ORDER_TIP},
-{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 99, 195, 14, 25, STR_SORT_BY_POPULATION, STR_SORT_ORDER_TIP},
-{ WWT_PANEL, RESIZE_BOTTOM, 13, 0, 195, 26, 189, 0x0, STR_200A_TOWN_NAMES_CLICK_ON_NAME},
-{ WWT_SCROLLBAR, RESIZE_BOTTOM, 13, 196, 207, 14, 189, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
-{ WWT_PANEL, RESIZE_TB, 13, 0, 195, 190, 201, 0x0, STR_NULL},
-{ WWT_RESIZEBOX, RESIZE_TB, 13, 196, 207, 190, 201, 0x0, STR_RESIZE_BUTTON},
+{ WWT_CAPTION, RESIZE_NONE, 13, 11, 300, 0, 13, STR_2000_TOWNS, STR_018C_WINDOW_TITLE_DRAG_THIS},
+{ WWT_STICKYBOX, RESIZE_NONE, 13, 301, 312, 0, 13, 0x0, STR_STICKY_BUTTON},
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 0, 74, 14, 25, STR_SORT_BY_NAME, STR_SORT_ORDER_TIP},
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 75, 149, 14, 25, STR_SORT_BY_POPULATION, STR_SORT_ORDER_TIP},
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 150, 224, 14, 25, STR_SORT_BY_GDP_CAPITA, STR_SORT_ORDER_TIP},
+{ WWT_PUSHTXTBTN, RESIZE_NONE, 13, 225, 300, 14, 25, STR_SORT_BY_GDP_TOTAL, STR_SORT_ORDER_TIP},
+{ WWT_PANEL, RESIZE_BOTTOM, 13, 0, 300, 26, 189, 0x0, STR_200A_TOWN_NAMES_CLICK_ON_NAME},
+{ WWT_SCROLLBAR, RESIZE_BOTTOM, 13, 301, 312, 14, 189, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
+{ WWT_PANEL, RESIZE_TB, 13, 0, 312, 190, 201, 0x0, STR_NULL},
+{ WWT_RESIZEBOX, RESIZE_TB, 13, 301, 312, 190, 201, 0x0, STR_RESIZE_BUTTON},
{ WIDGETS_END},
};
@@ -412,9 +414,30 @@
return r;
}
+static int CDECL TownGDPSorter(const void *a, const void *b)
+{
+ const Town* ta = *(const Town**)a;
+ const Town* tb = *(const Town**)b;
+ int r = (ta->GetActivity() * 100) - (tb->GetActivity() * 100);
+ if (_town_sort_order & 1) r = -r;
+ return r;
+}
+
+static int CDECL TownOutputSorter(const void *a, const void *b)
+{
+ const Town* ta = *(const Town**)a;
+ const Town* tb = *(const Town**)b;
+ int r = (ta->GetActivity() * 100 * ta->population) - (tb->GetActivity() * 100 * tb->population);
+ if (_town_sort_order & 1) r = -r;
+ return r;
+}
+
static void MakeSortedTownList(void)
{
const Town* t;
+ int (*townsortproc[])(const void *a, const void *b) = {
+ TownNameSorter, TownPopSorter, TownGDPSorter, TownOutputSorter
+ };
uint n = 0;
/* Create array for sorting */
@@ -426,7 +449,7 @@
_num_town_sort = n;
_last_town = NULL; // used for "cache"
- qsort((void*)_town_sort, n, sizeof(_town_sort[0]), _town_sort_order & 2 ? TownPopSorter : TownNameSorter);
+ qsort((void*)_town_sort, n, sizeof(_town_sort[0]), townsortproc[_town_sort_order / 2]);
DEBUG(misc, 3, "Resorting towns list");
}
@@ -444,7 +467,7 @@
SetVScrollCount(w, _num_town_sort);
DrawWindowWidgets(w);
- DoDrawString(_town_sort_order & 1 ? DOWNARROW : UPARROW, (_town_sort_order <= 1) ? 88 : 187, 15, 0x10);
+ DoDrawString(_town_sort_order & 1 ? DOWNARROW : UPARROW, 66 + (_town_sort_order / 2) * 75, 15, 0x10);
{
int n = 0;
@@ -458,6 +481,7 @@
SetDParam(0, t->index);
SetDParam(1, t->population);
+ SetDParam(2, t->GetActivity() * 100);
DrawString(2, y, STR_2057, 0);
y += 10;
@@ -471,19 +495,17 @@
case WE_CLICK:
switch (e->we.click.widget) {
- case 3: { /* Sort by Name ascending/descending */
- _town_sort_order = (_town_sort_order == 0) ? 1 : 0;
+ case 3: /* Sort by Name ascending/descending */
+ case 4: /* Sort by Population ascending/descending */
+ case 5: /* Sort by GDP per capita */
+ case 6: { /* Sort by economic output */
+ int sorter = e->we.click.widget - 3;
+ _town_sort_order = (_town_sort_order == 2 * sorter) ? 2 * sorter + 1 : 2 * sorter;
_town_sort_dirty = true;
SetWindowDirty(w);
} break;
- case 4: { /* Sort by Population ascending/descending */
- _town_sort_order = (_town_sort_order == 2) ? 3 : 2;
- _town_sort_dirty = true;
- SetWindowDirty(w);
- } break;
-
- case 5: { /* Click on Town Matrix */
+ case 7: { /* Click on Town Matrix */
const Town* t;
uint16 id_v = (e->we.click.pt.y - 28) / 10;
@@ -513,7 +535,7 @@
}
static const WindowDesc _town_directory_desc = {
- WDP_AUTO, WDP_AUTO, 208, 202,
+ WDP_AUTO, WDP_AUTO, 313, 202,
WC_TOWN_DIRECTORY, WC_NONE,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_STICKY_BUTTON | WDF_RESIZABLE,
_town_directory_widgets,
@@ -531,3 +553,5 @@
w->resize.height = w->height - 10 * 6; // minimum of 10 items in the list, each item 10 high
}
}
+
+