(svn r24171) -Fix [FS#4967, FS#5120]: Hide object specs/classes from the GUI, if they will never be available to the user.

This commit is contained in:
frosch 2012-04-22 16:28:37 +00:00
parent 14bd0dad91
commit 6e471388e4
2 changed files with 25 additions and 17 deletions

View File

@ -42,7 +42,7 @@ public:
this->vscroll = this->GetScrollbar(WID_BO_SCROLLBAR); this->vscroll = this->GetScrollbar(WID_BO_SCROLLBAR);
this->vscroll->SetCapacity(5); this->vscroll->SetCapacity(5);
this->vscroll->SetPosition(0); this->vscroll->SetPosition(0);
this->vscroll->SetCount(ObjectClass::GetClassCount()); this->vscroll->SetCount(ObjectClass::GetUIClassCount());
this->FinishInitNested(desc, 0); this->FinishInitNested(desc, 0);
@ -51,7 +51,7 @@ public:
NWidgetMatrix *matrix = this->GetWidget<NWidgetMatrix>(WID_BO_SELECT_MATRIX); NWidgetMatrix *matrix = this->GetWidget<NWidgetMatrix>(WID_BO_SELECT_MATRIX);
matrix->SetScrollbar(this->GetScrollbar(WID_BO_SELECT_SCROLL)); 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() virtual ~BuildObjectWindow()
@ -78,7 +78,9 @@ public:
switch (widget) { switch (widget) {
case WID_BO_CLASS_LIST: { case WID_BO_CLASS_LIST: {
for (uint i = 0; i < ObjectClass::GetClassCount(); i++) { 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; size->width += padding.width;
this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM; this->line_height = FONT_HEIGHT_NORMAL + WD_MATRIX_TOP + WD_MATRIX_BOTTOM;
@ -106,7 +108,7 @@ public:
/* Get the height and view information. */ /* Get the height and view information. */
for (int i = 0; i < NUM_OBJECTS; i++) { for (int i = 0; i < NUM_OBJECTS; i++) {
const ObjectSpec *spec = ObjectSpec::Get(i); const ObjectSpec *spec = ObjectSpec::Get(i);
if (!spec->enabled) continue; if (!spec->IsEverAvailable()) continue;
two_wide |= spec->views >= 2; two_wide |= spec->views >= 2;
height[spec->views / 4] = max<int>(ObjectSpec::Get(i)->height, height[spec->views / 4]); height[spec->views / 4] = max<int>(ObjectSpec::Get(i)->height, height[spec->views / 4]);
} }
@ -155,8 +157,12 @@ public:
switch (GB(widget, 0, 16)) { switch (GB(widget, 0, 16)) {
case WID_BO_CLASS_LIST: { case WID_BO_CLASS_LIST: {
int y = r.top; int y = r.top;
for (uint i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < ObjectClass::GetClassCount(); i++) { uint pos = 0;
SetDParam(0, ObjectClass::Get((ObjectClassID)i)->name); 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, 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); ((int)i == _selected_object_class) ? TC_WHITE : TC_BLACK);
y += this->line_height; y += this->line_height;
@ -188,8 +194,10 @@ public:
case WID_BO_SELECT_IMAGE: { case WID_BO_SELECT_IMAGE: {
if (_selected_object_index < 0) break; if (_selected_object_index < 0) break;
int obj_index = GB(widget, 16, 16); ObjectClass *objclass = ObjectClass::Get(_selected_object_class);
const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(obj_index); 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 == NULL) break;
if (!spec->IsAvailable()) { if (!spec->IsAvailable()) {
@ -261,7 +269,7 @@ public:
} }
this->GetWidget<NWidgetMatrix>(WID_BO_OBJECT_MATRIX)->SetClicked(_selected_object_view); 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->UpdateSelectSize();
this->SetDirty(); this->SetDirty();
} }
@ -289,18 +297,18 @@ public:
switch (GB(widget, 0, 16)) { switch (GB(widget, 0, 16)) {
case WID_BO_CLASS_LIST: { case WID_BO_CLASS_LIST: {
int num_clicked = this->vscroll->GetPosition() + (pt.y - this->nested_array[widget]->pos_y) / this->line_height; 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; _selected_object_class = ObjectClass::GetUIClass(num_clicked);
this->GetWidget<NWidgetMatrix>(WID_BO_SELECT_MATRIX)->SetCount(ObjectClass::Get(_selected_object_class)->GetSpecCount()); this->GetWidget<NWidgetMatrix>(WID_BO_SELECT_MATRIX)->SetCount(ObjectClass::Get(_selected_object_class)->GetUISpecCount());
this->SelectFirstAvailableObject(false); this->SelectFirstAvailableObject(false);
break; break;
} }
case WID_BO_SELECT_IMAGE: { case WID_BO_SELECT_IMAGE: {
int num_clicked = GB(widget, 16, 16); ObjectClass *objclass = ObjectClass::Get(_selected_object_class);
const ObjectSpec *spec = ObjectClass::Get(_selected_object_class)->GetSpec(num_clicked); int num_clicked = objclass->GetIndexFromUI(GB(widget, 16, 16));
if (spec->IsAvailable()) this->SelectOtherObject(num_clicked); if (num_clicked >= 0 && objclass->GetSpec(num_clicked)->IsAvailable()) this->SelectOtherObject(num_clicked);
break; break;
} }

View File

@ -163,7 +163,7 @@ struct TerraformToolbarWindow : Window {
{ {
/* Don't show the place object button when there are no objects to place. */ /* 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); 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) 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 case WID_TT_PLACE_OBJECT: // Place object button
/* Don't show the place object button when there are no objects to place. */ /* 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)) { if (HandlePlacePushButton(this, WID_TT_PLACE_OBJECT, SPR_CURSOR_TRANSMITTER, HT_RECT)) {
ShowBuildObjectPicker(this); ShowBuildObjectPicker(this);
this->last_user_action = widget; this->last_user_action = widget;