# HG changeset patch # User sbr # Date 1370378865 -7200 # Branch fs5567_02 # Node ID 2b13bc4f7b4cc549b467051740ee7eb57bbd05bb # Parent ce6908dcd23360516156f41e807eaa01e541d5d4 # Parent bd5df79472b43e79d9ce5e766c2d15e8ed179583 -Change: Introduce a SelectOtherClass() method that store the selected object class and setup the object matrix. diff --git a/src/object_gui.cpp b/src/object_gui.cpp --- a/src/object_gui.cpp +++ b/src/object_gui.cpp @@ -85,9 +85,9 @@ NWidgetMatrix *matrix = this->GetWidget(WID_BO_SELECT_MATRIX); matrix->SetScrollbar(this->GetScrollbar(WID_BO_SELECT_SCROLL)); - matrix->SetCount(ObjectClass::Get(_selected_object_class)->GetUISpecCount()); if (this->CanRestoreSelectedObject()) { + this->SelectOtherClass(_selected_object_class), this->SelectOtherObject(_selected_object_index); } else { this->SelectFirstAvailableObject(true); @@ -331,6 +331,16 @@ } /** + * Select the specified object class. + * @param object_class_index Object class index to select. + */ + void SelectOtherClass(ObjectClassID object_class_index) + { + _selected_object_class = object_class_index; + this->GetWidget(WID_BO_SELECT_MATRIX)->SetCount(ObjectClass::Get(_selected_object_class)->GetUISpecCount()); + } + + /** * Select the specified object in #_selected_object_class class. * @param object_index Object index to select, \c -1 means select nothing. */ @@ -376,8 +386,7 @@ int num_clicked = this->vscroll->GetPosition() + (pt.y - this->nested_array[widget]->pos_y) / this->line_height; if (num_clicked >= (int)ObjectClass::GetUIClassCount()) break; - _selected_object_class = ObjectClass::GetUIClass(num_clicked); - this->GetWidget(WID_BO_SELECT_MATRIX)->SetCount(ObjectClass::Get(_selected_object_class)->GetUISpecCount()); + this->SelectOtherClass(ObjectClass::GetUIClass(num_clicked)); this->SelectFirstAvailableObject(false); break; } @@ -424,8 +433,7 @@ for (uint i = 0; i < objclass->GetSpecCount(); i++) { const ObjectSpec *spec = objclass->GetSpec(i); if (spec->IsAvailable()) { - _selected_object_class = j; - this->GetWidget(WID_BO_SELECT_MATRIX)->SetCount(ObjectClass::Get(_selected_object_class)->GetUISpecCount()); + this->SelectOtherClass(j); this->SelectOtherObject(i); return; } @@ -437,7 +445,7 @@ /* ... but make sure that the class is not empty. */ for (ObjectClassID j = OBJECT_CLASS_BEGIN; j < OBJECT_CLASS_MAX; j++) { if (ObjectClass::Get(j)->GetUISpecCount() > 0) { - _selected_object_class = j; + this->SelectOtherClass(j); break; } }