Mercurial > hg > openttd
changeset 14390:48685f9d7f68 draft
(svn r18947) -Fix [FS#1510]: after clicking move up/move down in the newgrf/ai the selected item could be out of range
author | yexo <yexo@openttd.org> |
---|---|
date | Fri, 29 Jan 2010 15:45:53 +0000 |
parents | b9f435980053 |
children | d412eb7ac21d |
files | src/ai/ai_gui.cpp src/newgrf_gui.cpp |
diffstat | 2 files changed, 8 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ai/ai_gui.cpp +++ b/src/ai/ai_gui.cpp @@ -604,6 +604,7 @@ if (this->selected_slot > 1) { Swap(_settings_newgame.ai_config[this->selected_slot], _settings_newgame.ai_config[this->selected_slot - 1]); this->selected_slot--; + this->vscroll.ScrollTowards(this->selected_slot); this->InvalidateData(); } break; @@ -612,6 +613,7 @@ if (this->selected_slot < _settings_newgame.difficulty.max_no_competitors) { Swap(_settings_newgame.ai_config[this->selected_slot], _settings_newgame.ai_config[this->selected_slot + 1]); this->selected_slot++; + this->vscroll.ScrollTowards(this->selected_slot); this->InvalidateData(); } break;
--- a/src/newgrf_gui.cpp +++ b/src/newgrf_gui.cpp @@ -777,7 +777,8 @@ 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 @@ break; } } + this->vscroll.ScrollTowards(pos); this->preset = -1; this->InvalidateData(); break; @@ -794,7 +796,8 @@ 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 @@ break; } } + this->vscroll.ScrollTowards(pos); this->preset = -1; this->InvalidateData(); break;