Add a 'Show All' button to plans GUI.

This commit is contained in:
Jonathan G Rennison
2017-03-31 13:51:17 +01:00
parent b9e6ad1c6d
commit a3d21411e7
3 changed files with 30 additions and 1 deletions

View File

@@ -4086,6 +4086,8 @@ STR_PLANS_ADD_LINES :{BLACK}Add line
STR_PLANS_ADDING_LINES :{BLACK}Adding... STR_PLANS_ADDING_LINES :{BLACK}Adding...
STR_PLANS_HIDE_ALL :{BLACK}Hide all STR_PLANS_HIDE_ALL :{BLACK}Hide all
STR_PLANS_HIDE_ALL_TOOLTIP :{BLACK}Set the visibility of all the plans and all their lines to false STR_PLANS_HIDE_ALL_TOOLTIP :{BLACK}Set the visibility of all the plans and all their lines to false
STR_PLANS_SHOW_ALL :{BLACK}Show all
STR_PLANS_SHOW_ALL_TOOLTIP :{BLACK}Set the visibility of all the plans and all their lines to true
STR_PLANS_VISIBILITY_PRIVATE :{BLACK}Make private STR_PLANS_VISIBILITY_PRIVATE :{BLACK}Make private
STR_PLANS_VISIBILITY_PUBLIC :{BLACK}Make public STR_PLANS_VISIBILITY_PUBLIC :{BLACK}Make public
STR_PLANS_VISIBILITY_TOOLTIP :{BLACK}Toggle the visibility of a plan (private is yellow, public is blue). A public plan will be displayed in the plan window of the other companies but only its owner can add lines to it. STR_PLANS_VISIBILITY_TOOLTIP :{BLACK}Toggle the visibility of a plan (private is yellow, public is blue). A public plan will be displayed in the plan window of the other companies but only its owner can add lines to it.

View File

@@ -51,7 +51,10 @@ static const NWidgetPart _nested_plans_widgets[] = {
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_PLN_NEW), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_PLANS_NEW_PLAN, STR_NULL), NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_PLN_NEW), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_PLANS_NEW_PLAN, STR_NULL),
NWidget(WWT_TEXTBTN_2, COLOUR_GREY, WID_PLN_ADD_LINES), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_PLANS_ADD_LINES, STR_PLANS_ADDING_LINES), NWidget(WWT_TEXTBTN_2, COLOUR_GREY, WID_PLN_ADD_LINES), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_PLANS_ADD_LINES, STR_PLANS_ADDING_LINES),
NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_PLN_VISIBILITY), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_PLANS_VISIBILITY_PUBLIC, STR_PLANS_VISIBILITY_TOOLTIP), NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_PLN_VISIBILITY), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_PLANS_VISIBILITY_PUBLIC, STR_PLANS_VISIBILITY_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_PLN_HIDE_ALL), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_PLANS_HIDE_ALL, STR_NULL), NWidget(NWID_SELECTION, INVALID_COLOUR, WID_PLN_HIDE_ALL_SEL),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_PLN_HIDE_ALL), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_PLANS_HIDE_ALL, STR_PLANS_HIDE_ALL_TOOLTIP),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_PLN_SHOW_ALL), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_PLANS_SHOW_ALL, STR_PLANS_SHOW_ALL_TOOLTIP),
EndContainer(),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_PLN_DELETE), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_PLANS_DELETE, STR_PLANS_DELETE_TOOLTIP), NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_PLN_DELETE), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_PLANS_DELETE, STR_PLANS_DELETE_TOOLTIP),
NWidget(WWT_RESIZEBOX, COLOUR_GREY), NWidget(WWT_RESIZEBOX, COLOUR_GREY),
EndContainer(), EndContainer(),
@@ -73,6 +76,7 @@ struct PlansWindow : Window {
} ListItem; } ListItem;
Scrollbar *vscroll; Scrollbar *vscroll;
NWidgetStacked *hide_all_sel;
std::vector<ListItem> list; ///< The translation table linking panel indices to their related PlanID. std::vector<ListItem> list; ///< The translation table linking panel indices to their related PlanID.
int selected; ///< What item is currently selected in the panel. int selected; ///< What item is currently selected in the panel.
uint vis_btn_left; ///< left offset of visibility button uint vis_btn_left; ///< left offset of visibility button
@@ -82,6 +86,8 @@ struct PlansWindow : Window {
{ {
this->CreateNestedTree(); this->CreateNestedTree();
this->vscroll = this->GetScrollbar(WID_PLN_SCROLLBAR); this->vscroll = this->GetScrollbar(WID_PLN_SCROLLBAR);
this->hide_all_sel = this->GetWidget<NWidgetStacked>(WID_PLN_HIDE_ALL_SEL);
this->hide_all_sel->SetDisplayedPlane(0);
this->FinishInitNested(); this->FinishInitNested();
this->selected = INT_MAX; this->selected = INT_MAX;
@@ -120,6 +126,14 @@ struct PlansWindow : Window {
this->SetWidgetDirty(WID_PLN_LIST); this->SetWidgetDirty(WID_PLN_LIST);
break; break;
} }
case WID_PLN_SHOW_ALL: {
Plan *p;
FOR_ALL_PLANS(p) {
if (p->IsListable()) p->SetVisibility(true);
}
this->SetWidgetDirty(WID_PLN_LIST);
break;
}
case WID_PLN_VISIBILITY: case WID_PLN_VISIBILITY:
if (_current_plan) _current_plan->ToggleVisibilityByAll(); if (_current_plan) _current_plan->ToggleVisibilityByAll();
break; break;
@@ -161,9 +175,20 @@ struct PlansWindow : Window {
} }
} }
bool AllPlansHidden() const
{
Plan *p;
FOR_ALL_PLANS(p) {
if (p->IsVisible()) return false;
}
return true;
}
virtual void OnPaint() virtual void OnPaint()
{ {
this->SetWidgetDisabledState(WID_PLN_HIDE_ALL, this->vscroll->GetCount() == 0); this->SetWidgetDisabledState(WID_PLN_HIDE_ALL, this->vscroll->GetCount() == 0);
this->SetWidgetDisabledState(WID_PLN_SHOW_ALL, this->vscroll->GetCount() == 0);
this->hide_all_sel->SetDisplayedPlane(this->vscroll->GetCount() != 0 && this->AllPlansHidden() ? 1 : 0);
if (_current_plan) { if (_current_plan) {
this->SetWidgetsDisabledState(_current_plan->owner != _local_company, WID_PLN_ADD_LINES, WID_PLN_VISIBILITY, WID_PLN_DELETE, WIDGET_LIST_END); this->SetWidgetsDisabledState(_current_plan->owner != _local_company, WID_PLN_ADD_LINES, WID_PLN_VISIBILITY, WID_PLN_DELETE, WIDGET_LIST_END);
this->GetWidget<NWidgetCore>(WID_PLN_VISIBILITY)->widget_data = _current_plan->visible_by_all ? STR_PLANS_VISIBILITY_PRIVATE : STR_PLANS_VISIBILITY_PUBLIC; this->GetWidget<NWidgetCore>(WID_PLN_VISIBILITY)->widget_data = _current_plan->visible_by_all ? STR_PLANS_VISIBILITY_PRIVATE : STR_PLANS_VISIBILITY_PUBLIC;

View File

@@ -21,7 +21,9 @@ enum PlansWidgets {
WID_PLN_ADD_LINES, WID_PLN_ADD_LINES,
WID_PLN_VISIBILITY, WID_PLN_VISIBILITY,
WID_PLN_HIDE_ALL, WID_PLN_HIDE_ALL,
WID_PLN_SHOW_ALL,
WID_PLN_DELETE, WID_PLN_DELETE,
WID_PLN_HIDE_ALL_SEL,
}; };
#endif /* WIDGETS_PLANS_WIDGET_H */ #endif /* WIDGETS_PLANS_WIDGET_H */