summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2012-04-22 16:28:37 +0000
committerfrosch <frosch@openttd.org>2012-04-22 16:28:37 +0000
commit971b3b5fa595f7c984f1092d6b01ed3ff60eeb01 (patch)
tree144a6b151ff0e566649c1c40ea7260738ad3e6da
parent00af887048a1b6d3d424dcf237843838ba31e2da (diff)
downloadopenttd-971b3b5fa595f7c984f1092d6b01ed3ff60eeb01.tar.xz
(svn r24171) -Fix [FS#4967, FS#5120]: Hide object specs/classes from the GUI, if they will never be available to the user.
-rw-r--r--src/object_gui.cpp38
-rw-r--r--src/terraform_gui.cpp4
2 files changed, 25 insertions, 17 deletions
diff --git a/src/object_gui.cpp b/src/object_gui.cpp
index 5fd9b1fcc..4b8f70447 100644
--- a/src/object_gui.cpp
+++ b/src/object_gui.cpp
@@ -42,7 +42,7 @@ public:
this->vscroll = this->GetScrollbar(WID_BO_SCROLLBAR);
this->vscroll->SetCapacity(5);
this->vscroll->SetPosition(0);
- this->vscroll->SetCount(ObjectClass::GetClassCount());
+ this->vscroll->SetCount(ObjectClass::GetUIClassCount());
this->FinishInitNested(desc, 0);
@@ -51,7 +51,7 @@ 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)->GetSpecCount());
+ matrix->SetCount(ObjectClass::Get(_selected_object_class)->GetUISpecCount());
}
virtual ~BuildObjectWindow()
@@ -78,7 +78,9 @@ public:
switch (widget) {
case WID_BO_CLASS_LIST: {
for (uint i = 0; i < ObjectClass::GetClassCount(); i++) {
- size->width = max(size->width, GetStringBoundingBox(ObjectClass::Get((ObjectClassID)i)->name).width);
+ ObjectClass *objclass = ObjectClass::Get((ObjectClassID)i);
+ if (objclass->GetUISpecCount() == 0) continue;
+ size->width = max(size->width, GetStringBoundingBox(objclass->name).width);
}
size->width += padding.width;
this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
@@ -106,7 +108,7 @@ public:
/* Get the height and view information. */
for (int i = 0; i < NUM_OBJECTS; i++) {
const ObjectSpec *spec = ObjectSpec::Get(i);
- if (!spec->enabled) continue;
+ if (!spec->IsEverAvailable()) continue;
two_wide |= spec->views >= 2;
height[spec->views / 4] = max<int>(ObjectSpec::Get(i)->height, height[spec->views / 4]);
}
@@ -155,8 +157,12 @@ public:
switch (GB(widget, 0, 16)) {
case WID_BO_CLASS_LIST: {
int y = r.top;
- for (uint i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < ObjectClass::GetClassCount(); i++) {
- SetDParam(0, ObjectClass::Get((ObjectClassID)i)->name);
+ uint pos = 0;
+ for (uint i = 0; i < ObjectClass::GetClassCount(); i++) {
+ ObjectClass *objclass = ObjectClass::Get((ObjectClassID)i);
+ if (objclass->GetUISpecCount() == 0) continue;
+ if (!this->vscroll->IsVisible(pos++)) continue;
+ SetDParam(0, objclass->name);
DrawString(r.left + WD_MATRIX_LEFT, r.right + WD_MATRIX_RIGHT, y + WD_MATRIX_TOP, STR_JUST_STRING,
((int)i == _selected_object_class) ? TC_WHITE : TC_BLACK);
y += this->line_height;
@@ -188,8 +194,10 @@ public:
case WID_BO_SELECT_IMAGE: {
if (_selected_object_index < 0) break;
- int obj_index = GB(widget, 16, 16);
- const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(obj_index);
+ ObjectClass *objclass = ObjectClass::Get(_selected_object_class);
+ int obj_index = objclass->GetIndexFromUI(GB(widget, 16, 16));
+ if (obj_index < 0) break;
+ const ObjectSpec *spec = objclass->GetSpec(obj_index);
if (spec == NULL) break;
if (!spec->IsAvailable()) {
@@ -261,7 +269,7 @@ public:
}
this->GetWidget<NWidgetMatrix>(WID_BO_OBJECT_MATRIX)->SetClicked(_selected_object_view);
- this->GetWidget<NWidgetMatrix>(WID_BO_SELECT_MATRIX)->SetClicked(_selected_object_index);
+ this->GetWidget<NWidgetMatrix>(WID_BO_SELECT_MATRIX)->SetClicked(_selected_object_index != -1 ? ObjectClass::Get(_selected_object_class)->GetUIFromIndex(_selected_object_index) : -1);
this->UpdateSelectSize();
this->SetDirty();
}
@@ -289,18 +297,18 @@ public:
switch (GB(widget, 0, 16)) {
case WID_BO_CLASS_LIST: {
int num_clicked = this->vscroll->GetPosition() + (pt.y - this->nested_array[widget]->pos_y) / this->line_height;
- if (num_clicked >= (int)ObjectClass::GetClassCount()) break;
+ if (num_clicked >= (int)ObjectClass::GetUIClassCount()) break;
- _selected_object_class = (ObjectClassID)num_clicked;
- this->GetWidget<NWidgetMatrix>(WID_BO_SELECT_MATRIX)->SetCount(ObjectClass::Get(_selected_object_class)->GetSpecCount());
+ _selected_object_class = ObjectClass::GetUIClass(num_clicked);
+ this->GetWidget<NWidgetMatrix>(WID_BO_SELECT_MATRIX)->SetCount(ObjectClass::Get(_selected_object_class)->GetUISpecCount());
this->SelectFirstAvailableObject(false);
break;
}
case WID_BO_SELECT_IMAGE: {
- int num_clicked = GB(widget, 16, 16);
- const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(num_clicked);
- if (spec->IsAvailable()) this->SelectOtherObject(num_clicked);
+ ObjectClass *objclass = ObjectClass::Get(_selected_object_class);
+ int num_clicked = objclass->GetIndexFromUI(GB(widget, 16, 16));
+ if (num_clicked >= 0 && objclass->GetSpec(num_clicked)->IsAvailable()) this->SelectOtherObject(num_clicked);
break;
}
diff --git a/src/terraform_gui.cpp b/src/terraform_gui.cpp
index 00d611e27..b288f383d 100644
--- a/src/terraform_gui.cpp
+++ b/src/terraform_gui.cpp
@@ -163,7 +163,7 @@ struct TerraformToolbarWindow : Window {
{
/* Don't show the place object button when there are no objects to place. */
NWidgetStacked *show_object = this->GetWidget<NWidgetStacked>(WID_TT_SHOW_PLACE_OBJECT);
- show_object->SetDisplayedPlane(ObjectClass::GetClassCount() != 0 ? 0 : SZSP_NONE);
+ show_object->SetDisplayedPlane(ObjectClass::GetUIClassCount() != 0 ? 0 : SZSP_NONE);
}
virtual void OnClick(Point pt, int widget, int click_count)
@@ -209,7 +209,7 @@ struct TerraformToolbarWindow : Window {
case WID_TT_PLACE_OBJECT: // Place object button
/* Don't show the place object button when there are no objects to place. */
- if (ObjectClass::GetClassCount() == 0) return;
+ if (ObjectClass::GetUIClassCount() == 0) return;
if (HandlePlacePushButton(this, WID_TT_PLACE_OBJECT, SPR_CURSOR_TRANSMITTER, HT_RECT)) {
ShowBuildObjectPicker(this);
this->last_user_action = widget;