# HG changeset patch # User sbr # Date 1368872458 0 # Branch fs5503_02 # Node ID d837e223c99d7c6e83c87b8ba6708394058a458f # Parent dee2f3668f2f3f03dae990b8971673e5495859a0 # Parent 0b57a2a2a00b43d093d65e0bfccca1ef881c5a67 Try to not reset the previously selected object between BuildObjectWindow invocations. diff --git a/src/object_gui.cpp b/src/object_gui.cpp --- a/src/object_gui.cpp +++ b/src/object_gui.cpp @@ -47,6 +47,20 @@ this->vscroll->ScrollTowards(pos); } + /** + * Tests if 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) { @@ -59,7 +73,11 @@ 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(WID_BO_OBJECT_MATRIX)->SetCount(4);