summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoralberth <alberth@openttd.org>2013-05-24 19:11:30 +0000
committeralberth <alberth@openttd.org>2013-05-24 19:11:30 +0000
commit4bdf33a1df83e7dc832c407005bdc474dcd9c862 (patch)
tree7d61eb1d022d484a1dfccc1e6280f955a2c69818 /src
parentca5b64a433dc552eb80c4396aa09b18466bfb435 (diff)
downloadopenttd-4bdf33a1df83e7dc832c407005bdc474dcd9c862.tar.xz
(svn r25282) -Add: When opening the object-build window, try to restore the last selected object (sbr).
Diffstat (limited to 'src')
-rw-r--r--src/object_gui.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/object_gui.cpp b/src/object_gui.cpp
index 35c395891..429f7a40f 100644
--- a/src/object_gui.cpp
+++ b/src/object_gui.cpp
@@ -44,6 +44,20 @@ class BuildObjectWindow : public PickerWindowBase {
this->vscroll->ScrollTowards(pos);
}
+ /**
+ * Tests whether the previously selected object can be selected.
+ * @return \c true if the selected object is available, \c false otherwise.
+ */
+ bool CanRestoreSelectedObject()
+ {
+ if (_selected_object_index == -1) return false;
+
+ ObjectClass *sel_objclass = ObjectClass::Get(_selected_object_class);
+ if ((int)sel_objclass->GetSpecCount() <= _selected_object_index) return false;
+
+ return sel_objclass->GetSpec(_selected_object_index)->IsAvailable();
+ }
+
public:
BuildObjectWindow(const WindowDesc *desc, Window *w) : PickerWindowBase(w), info_height(1)
{
@@ -56,7 +70,11 @@ public:
this->FinishInitNested(desc, 0);
- this->SelectFirstAvailableObject(true);
+ if (this->CanRestoreSelectedObject()) {
+ this->SelectOtherObject(_selected_object_index);
+ } else {
+ this->SelectFirstAvailableObject(true);
+ }
assert(ObjectClass::Get(_selected_object_class)->GetUISpecCount() > 0); // object GUI should be disables elsewise
this->EnsureSelectedObjectClassIsVisible();
this->GetWidget<NWidgetMatrix>(WID_BO_OBJECT_MATRIX)->SetCount(4);