summaryrefslogtreecommitdiff
path: root/town_gui.c
diff options
context:
space:
mode:
authordarkvater <darkvater@openttd.org>2004-09-07 19:01:06 +0000
committerdarkvater <darkvater@openttd.org>2004-09-07 19:01:06 +0000
commitbf9c8068be695e95662a541eb76465d60af6c976 (patch)
tree29dca88c305d0bd459c03c65b6c285d4eb8eef5a /town_gui.c
parent51d928a478f5cc83285d4f87453fa5c2ce69f77b (diff)
downloadopenttd-bf9c8068be695e95662a541eb76465d60af6c976.tar.xz
(svn r175) -Fix: [1023771] inconsistent/missing stations in station list. Forgot to change owner-sort after changing function.
-Codechange: some more asserts to vehicle-sorts to quickly find any possible problems.
Diffstat (limited to 'town_gui.c')
-rw-r--r--town_gui.c72
1 files changed, 39 insertions, 33 deletions
diff --git a/town_gui.c b/town_gui.c
index 8d6cfbd5d..7d8ed4c3b 100644
--- a/town_gui.c
+++ b/town_gui.c
@@ -390,7 +390,7 @@ static void MakeSortedTownList()
FOR_ALL_TOWNS(t) if(t->xy) _town_sort[n++] = t->index;
_num_town_sort = n;
- _last_town_idx = 255; // used for "cache"
+ _last_town_idx = 0; // used for "cache"
qsort(_town_sort, n, sizeof(_town_sort[0]), _town_sort_order & 2 ? TownPopSorter : TownNameSorter);
DEBUG(misc, 1) ("Resorting Towns list...");
@@ -401,66 +401,72 @@ static void TownDirectoryWndProc(Window *w, WindowEvent *e)
{
switch(e->event) {
case WE_PAINT: {
- int n;
- uint p;
- Town *t;
if (_town_sort_dirty) {
_town_sort_dirty = false;
MakeSortedTownList();
}
- w->vscroll.count = _num_town_sort;
+ SetVScrollCount(w, _num_town_sort);
DrawWindowWidgets(w);
- DoDrawString(_town_sort_order & 1 ? "\xAA" : "\xA0", _town_sort_order <= 1 ? 88 : 187, 15, 0x10);
+ DoDrawString(_town_sort_order & 1 ? "\xAA" : "\xA0", (_town_sort_order <= 1) ? 88 : 187, 15, 0x10);
- p = w->vscroll.pos;
- n = 0;
-
- while (p < _num_town_sort) {
- t = DEREF_TOWN(_town_sort[p]);
- SET_DPARAM16(0, t->index);
- SET_DPARAM32(1, t->population);
- DrawString(2, 28+n*10, STR_2057, 0);
- p++;
- if (++n == 16)
- break;
+ {
+ Town *t;
+ int n = 0;
+ uint16 i = w->vscroll.pos;
+ int y = 28;
+
+ while (i < _num_town_sort) {
+ t = DEREF_TOWN(_town_sort[i]);
+
+ assert(t->xy);
+
+ SET_DPARAM16(0, t->index);
+ SET_DPARAM32(1, t->population);
+ DrawString(2, y, STR_2057, 0);
+
+ y += 10;
+ i++;
+ if (++n == w->vscroll.cap) { break;} // max number of towns in 1 window
+ }
}
} break;
case WE_CLICK:
switch(e->click.widget) {
- case 2: {
- _town_sort_order = _town_sort_order==0 ? 1 : 0;
+ case 2: { /* Sort by Name ascending/descending */
+ _town_sort_order = (_town_sort_order == 0) ? 1 : 0;
_town_sort_dirty = true;
SetWindowDirty(w);
} break;
- case 3: {
- _town_sort_order = _town_sort_order==2 ? 3 : 2;
+ case 3: { /* Sort by Population ascending/descending */
+ _town_sort_order = (_town_sort_order == 2) ? 3 : 2;
_town_sort_dirty = true;
SetWindowDirty(w);
} break;
- case 4: {
- int y = (e->click.pt.y - 28) / 10;
- byte p;
- Town *t;
+ case 4: { /* Click on Town Matrix */
+ uint16 id_v = (e->click.pt.y - 28) / 10;
- if (!IS_INT_INSIDE(y, 0, 16))
- return;
- p = y + w->vscroll.pos;
- if (p < _num_town_sort) {
- t = DEREF_TOWN(_town_sort[p]);
+ if (id_v >= w->vscroll.cap) { return;} // click out of bounds
+
+ id_v += w->vscroll.pos;
+
+ if (id_v >= _num_town_sort) { return;} // click out of town bounds
+
+ {
+ Town *t = DEREF_TOWN(_town_sort[id_v]);
+ assert(t->xy);
+
ScrollMainWindowToTile(t->xy);
}
- break;
- }
+ } break;
}
break;
-
case WE_4:
SetWindowDirty(w);
break;