summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2013-10-28 10:28:24 +0000
committerfrosch <frosch@openttd.org>2013-10-28 10:28:24 +0000
commit6872e8c63ce1d4cf56eeeb35fe659501334212e8 (patch)
tree1716f98e8dfa091b41729b5907e1465b27d22817 /src
parent2b8e66e3e3b4a6af06a56da7bd398c639d265ef4 (diff)
downloadopenttd-6872e8c63ce1d4cf56eeeb35fe659501334212e8.tar.xz
(svn r25919) -Change [FS#5734]: Preselect the current replacement in the right-side list of the autoreplace GUI, instead of selecting the first resp. previous item.
Diffstat (limited to 'src')
-rw-r--r--src/autoreplace_gui.cpp15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/autoreplace_gui.cpp b/src/autoreplace_gui.cpp
index b159376a0..dc1f5ed73 100644
--- a/src/autoreplace_gui.cpp
+++ b/src/autoreplace_gui.cpp
@@ -164,10 +164,21 @@ class ReplaceVehicleWindow : public Window {
this->engines[1].Clear();
this->sel_engine[1] = INVALID_ENGINE;
} else {
+ if (this->reset_sel_engine && this->sel_engine[0] != INVALID_ENGINE) {
+ /* Select the current replacement for sel_engine[0]. */
+ const Company *c = Company::Get(_local_company);
+ this->sel_engine[1] = EngineReplacementForCompany(c, this->sel_engine[0], this->sel_group);
+ }
+ /* Regenerate the list on the right. Note: This resets sel_engine[1] to INVALID_ENGINE, if it is no longer available. */
this->GenerateReplaceVehList(false);
this->vscroll[1]->SetCount(this->engines[1].Length());
- if (this->reset_sel_engine && this->sel_engine[1] == INVALID_ENGINE && this->engines[1].Length() != 0) {
- this->sel_engine[1] = this->engines[1][0];
+ if (this->reset_sel_engine && this->sel_engine[1] != INVALID_ENGINE) {
+ int position = 0;
+ for (EngineID *it = this->engines[1].Begin(); it != this->engines[1].End(); ++it) {
+ if (*it == this->sel_engine[1]) break;
+ ++position;
+ }
+ this->vscroll[1]->ScrollTowards(position);
}
}
}