# HG changeset patch # User sbr # Date 1368872440 0 # Branch fs5503_02 # Node ID dee2f3668f2f3f03dae990b8971673e5495859a0 # Parent 4e6445a2fa93dd7311e05bfe579c166ce1b75e0a # Parent ce685d9034ee641a2cf7c2194a8d89e0a5e56048 When opening the BuildObjectWindow, ensure the selected object class is visible in the class selector. diff --git a/src/object_gui.cpp b/src/object_gui.cpp --- a/src/object_gui.cpp +++ b/src/object_gui.cpp @@ -34,6 +34,19 @@ int info_height; ///< The height of the info box. Scrollbar *vscroll; ///< The scrollbar. + /** + * Scrolls \c WID_BO_CLASS_LIST so that the selected object class is visible + */ + void EnsureSelectedObjectClassIsVisible() + { + uint pos = 0; + for (int i = 0; i < _selected_object_class; i++) { + if (ObjectClass::Get((ObjectClassID) i)->GetUISpecCount() == 0) continue; + pos++; + } + this->vscroll->ScrollTowards(pos); + } + public: BuildObjectWindow(const WindowDesc *desc, Window *w) : PickerWindowBase(w), info_height(1) { @@ -48,6 +61,7 @@ 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); NWidgetMatrix *matrix = this->GetWidget(WID_BO_SELECT_MATRIX);