summaryrefslogtreecommitdiff
path: root/src/newgrf_gui.cpp
diff options
context:
space:
mode:
authoryexo <yexo@openttd.org>2010-01-29 15:45:53 +0000
committeryexo <yexo@openttd.org>2010-01-29 15:45:53 +0000
commit81882039e3fd650ce3530c72ee2f14be784490d0 (patch)
tree3f0ef1fcc75afa816362a6fddf7c095997a43462 /src/newgrf_gui.cpp
parenta668e801e406718e6e9295db0a0c60be11878afe (diff)
downloadopenttd-81882039e3fd650ce3530c72ee2f14be784490d0.tar.xz
(svn r18947) -Fix [FS#1510]: after clicking move up/move down in the newgrf/ai the selected item could be out of range
Diffstat (limited to 'src/newgrf_gui.cpp')
-rw-r--r--src/newgrf_gui.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/newgrf_gui.cpp b/src/newgrf_gui.cpp
index 23b08a854..c1357e69a 100644
--- a/src/newgrf_gui.cpp
+++ b/src/newgrf_gui.cpp
@@ -777,7 +777,8 @@ struct NewGRFWindow : public Window {
GRFConfig **pc, *c;
if (this->sel == NULL) break;
- for (pc = &this->list; (c = *pc) != NULL; pc = &c->next) {
+ int pos = 0;
+ for (pc = &this->list; (c = *pc) != NULL; pc = &c->next, pos++) {
if (c->next == this->sel) {
c->next = this->sel->next;
this->sel->next = c;
@@ -785,6 +786,7 @@ struct NewGRFWindow : public Window {
break;
}
}
+ this->vscroll.ScrollTowards(pos);
this->preset = -1;
this->InvalidateData();
break;
@@ -794,7 +796,8 @@ struct NewGRFWindow : public Window {
GRFConfig **pc, *c;
if (this->sel == NULL) break;
- for (pc = &this->list; (c = *pc) != NULL; pc = &c->next) {
+ int pos = 1; // Start at 1 as we swap the selected newgrf with the next one
+ for (pc = &this->list; (c = *pc) != NULL; pc = &c->next, pos++) {
if (c == this->sel) {
*pc = c->next;
c->next = c->next->next;
@@ -802,6 +805,7 @@ struct NewGRFWindow : public Window {
break;
}
}
+ this->vscroll.ScrollTowards(pos);
this->preset = -1;
this->InvalidateData();
break;