summaryrefslogtreecommitdiff
path: root/src/object_gui.cpp
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2013-06-30 14:37:50 +0000
committerfrosch <frosch@openttd.org>2013-06-30 14:37:50 +0000
commit83a0174ef20d054eaed7e06f4e41788e0866839d (patch)
treee6ee56ddcacf0511bf35a9525ddbe0383687e98a /src/object_gui.cpp
parentd798766f2e9d9ee0059768c2c18d9d39d57cc304 (diff)
downloadopenttd-83a0174ef20d054eaed7e06f4e41788e0866839d.tar.xz
(svn r25540) -Fix: Unify selecting a new object class in the object GUI. (sbr)
Diffstat (limited to 'src/object_gui.cpp')
-rw-r--r--src/object_gui.cpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/object_gui.cpp b/src/object_gui.cpp
index 4c1a47aa6..4efca0eaa 100644
--- a/src/object_gui.cpp
+++ b/src/object_gui.cpp
@@ -83,9 +83,9 @@ public:
NWidgetMatrix *matrix = this->GetWidget<NWidgetMatrix>(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);
@@ -329,6 +329,16 @@ public:
}
/**
+ * 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<NWidgetMatrix>(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.
*/
@@ -373,8 +383,7 @@ public:
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<NWidgetMatrix>(WID_BO_SELECT_MATRIX)->SetCount(ObjectClass::Get(_selected_object_class)->GetUISpecCount());
+ this->SelectOtherClass(ObjectClass::GetUIClass(num_clicked));
this->SelectFirstAvailableObject(false);
break;
}
@@ -421,8 +430,7 @@ public:
for (uint i = 0; i < objclass->GetSpecCount(); i++) {
const ObjectSpec *spec = objclass->GetSpec(i);
if (spec->IsAvailable()) {
- _selected_object_class = j;
- this->GetWidget<NWidgetMatrix>(WID_BO_SELECT_MATRIX)->SetCount(ObjectClass::Get(_selected_object_class)->GetUISpecCount());
+ this->SelectOtherClass(j);
this->SelectOtherObject(i);
return;
}
@@ -434,7 +442,7 @@ public:
/* ... 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;
}
}