|
@@ -333,105 +333,105 @@ static const WindowDesc _town_view_scen_
|
|
|
_town_view_scen_widgets,
|
|
|
TownViewWndProc
|
|
|
};
|
|
|
|
|
|
void ShowTownViewWindow(TownID town)
|
|
|
{
|
|
|
Window *w;
|
|
|
|
|
|
if (_game_mode != GM_EDITOR) {
|
|
|
w = AllocateWindowDescFront(&_town_view_desc, town);
|
|
|
} else {
|
|
|
w = AllocateWindowDescFront(&_town_view_scen_desc, town);
|
|
|
}
|
|
|
|
|
|
if (w != NULL) {
|
|
|
w->flags4 |= WF_DISABLE_VP_SCROLL;
|
|
|
AssignWindowViewport(w, 3, 17, 0xFE, 0x56, GetTown(town)->xy, 1);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
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_IMGBTN, 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},
|
|
|
{ WIDGETS_END},
|
|
|
};
|
|
|
|
|
|
|
|
|
// used to get a sorted list of the towns
|
|
|
static uint _num_town_sort;
|
|
|
|
|
|
static char _bufcache[64];
|
|
|
static const Town* _last_town;
|
|
|
|
|
|
static int CDECL TownNameSorter(const void *a, const void *b)
|
|
|
{
|
|
|
const Town* ta = *(const Town**)a;
|
|
|
const Town* tb = *(const Town**)b;
|
|
|
char buf1[64];
|
|
|
int r;
|
|
|
|
|
|
SetDParam(0, ta->index);
|
|
|
GetString(buf1, STR_TOWN);
|
|
|
GetString(buf1, STR_TOWN, lastof(buf1));
|
|
|
|
|
|
/* If 'b' is the same town as in the last round, use the cached value
|
|
|
* We do this to speed stuff up ('b' is called with the same value a lot of
|
|
|
* times after eachother) */
|
|
|
if (tb != _last_town) {
|
|
|
_last_town = tb;
|
|
|
SetDParam(0, tb->index);
|
|
|
GetString(_bufcache, STR_TOWN);
|
|
|
GetString(_bufcache, STR_TOWN, lastof(_bufcache));
|
|
|
}
|
|
|
|
|
|
r = strcmp(buf1, _bufcache);
|
|
|
if (_town_sort_order & 1) r = -r;
|
|
|
return r;
|
|
|
}
|
|
|
|
|
|
static int CDECL TownPopSorter(const void *a, const void *b)
|
|
|
{
|
|
|
const Town* ta = *(const Town**)a;
|
|
|
const Town* tb = *(const Town**)b;
|
|
|
int r = ta->population - tb->population;
|
|
|
if (_town_sort_order & 1) r = -r;
|
|
|
return r;
|
|
|
}
|
|
|
|
|
|
static void MakeSortedTownList(void)
|
|
|
{
|
|
|
const Town* t;
|
|
|
uint n = 0;
|
|
|
|
|
|
/* Create array for sorting */
|
|
|
_town_sort = realloc((void*)_town_sort, GetTownArraySize() * sizeof(_town_sort[0]));
|
|
|
if (_town_sort == NULL)
|
|
|
error("Could not allocate memory for the town-sorting-list");
|
|
|
|
|
|
FOR_ALL_TOWNS(t) _town_sort[n++] = t;
|
|
|
|
|
|
_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);
|
|
|
|
|
|
DEBUG(misc, 1) ("Resorting Towns list...");
|
|
|
}
|
|
|
|
|
|
|
|
|
static void TownDirectoryWndProc(Window *w, WindowEvent *e)
|
|
|
{
|
|
|
switch (e->event) {
|
|
|
case WE_PAINT: {
|
|
|
if (_town_sort_dirty) {
|
|
|
_town_sort_dirty = false;
|
|
|
MakeSortedTownList();
|
|
|
}
|
|
|
|
|
|
SetVScrollCount(w, _num_town_sort);
|
|
|
|