|
|
|
@@ -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_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_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_RESIZEBOX, COLOUR_GREY),
|
|
|
|
|
EndContainer(),
|
|
|
|
@@ -73,19 +76,20 @@ struct PlansWindow : Window {
|
|
|
|
|
} ListItem;
|
|
|
|
|
|
|
|
|
|
Scrollbar *vscroll;
|
|
|
|
|
int text_offset;
|
|
|
|
|
NWidgetStacked *hide_all_sel;
|
|
|
|
|
std::vector<ListItem> list; ///< The translation table linking panel indices to their related PlanID.
|
|
|
|
|
int selected; ///< What item is currently selected in the panel.
|
|
|
|
|
uint vis_btn_left; ///< left offset of visibility button
|
|
|
|
|
Dimension company_icon_spr_dim; ///< dimensions of company icon
|
|
|
|
|
|
|
|
|
|
PlansWindow(WindowDesc *desc) : Window(desc)
|
|
|
|
|
{
|
|
|
|
|
this->CreateNestedTree();
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
|
|
Dimension spr_dim = GetSpriteSize(SPR_COMPANY_ICON);
|
|
|
|
|
this->text_offset = WD_FRAMETEXT_LEFT + spr_dim.width + 2 + SETTING_BUTTON_WIDTH;
|
|
|
|
|
|
|
|
|
|
this->selected = INT_MAX;
|
|
|
|
|
RebuildList();
|
|
|
|
|
}
|
|
|
|
@@ -122,28 +126,50 @@ struct PlansWindow : Window {
|
|
|
|
|
this->SetWidgetDirty(WID_PLN_LIST);
|
|
|
|
|
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:
|
|
|
|
|
if (_current_plan) _current_plan->ToggleVisibilityByAll();
|
|
|
|
|
break;
|
|
|
|
|
case WID_PLN_LIST: {
|
|
|
|
|
int new_selected = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_PLN_LIST, WD_FRAMERECT_TOP);
|
|
|
|
|
if (_ctrl_pressed) {
|
|
|
|
|
if (new_selected != INT_MAX) {
|
|
|
|
|
TileIndex t;
|
|
|
|
|
if (this->list[new_selected].is_plan) {
|
|
|
|
|
t = Plan::Get(this->list[new_selected].plan_id)->CalculateCentreTile();
|
|
|
|
|
} else {
|
|
|
|
|
t = Plan::Get(this->list[new_selected].plan_id)->lines[this->list[new_selected].line_id]->CalculateCentreTile();
|
|
|
|
|
}
|
|
|
|
|
if (t != INVALID_TILE) ScrollMainWindowToTile(t);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (this->selected != INT_MAX) {
|
|
|
|
|
_current_plan->SetFocus(false);
|
|
|
|
|
}
|
|
|
|
|
if (new_selected != INT_MAX) {
|
|
|
|
|
const int btn_left = this->vis_btn_left;
|
|
|
|
|
const int btn_right = btn_left + SETTING_BUTTON_WIDTH;
|
|
|
|
|
if (this->list[new_selected].is_plan) {
|
|
|
|
|
_current_plan = Plan::Get(this->list[new_selected].plan_id);
|
|
|
|
|
_current_plan->SetFocus(true);
|
|
|
|
|
if (pt.x >= 22 && pt.x < 41) _current_plan->ToggleVisibility();
|
|
|
|
|
if (pt.x >= btn_left && pt.x < btn_right) _current_plan->ToggleVisibility();
|
|
|
|
|
} else {
|
|
|
|
|
_current_plan = Plan::Get(this->list[new_selected].plan_id);
|
|
|
|
|
PlanLine *pl = _current_plan->lines[this->list[new_selected].line_id];
|
|
|
|
|
pl->SetFocus(true);
|
|
|
|
|
if (pt.x >= 22 && pt.x < 41) {
|
|
|
|
|
if (pt.x >= btn_left && pt.x < btn_right) {
|
|
|
|
|
if (pl->ToggleVisibility()) _current_plan->SetVisibility(true, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (click_count > 1 && (pt.x < 22 || pt.x >= 41)) {
|
|
|
|
|
if (click_count > 1 && (pt.x < btn_left || pt.x >= btn_right)) {
|
|
|
|
|
_current_plan->show_lines = !_current_plan->show_lines;
|
|
|
|
|
this->InvalidateData(INVALID_PLAN);
|
|
|
|
|
}
|
|
|
|
@@ -161,9 +187,20 @@ struct PlansWindow : Window {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AllPlansHidden() const
|
|
|
|
|
{
|
|
|
|
|
Plan *p;
|
|
|
|
|
FOR_ALL_PLANS(p) {
|
|
|
|
|
if (p->IsVisible()) return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void OnPaint()
|
|
|
|
|
{
|
|
|
|
|
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) {
|
|
|
|
|
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;
|
|
|
|
@@ -184,10 +221,11 @@ struct PlansWindow : Window {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool rtl = _current_text_dir == TD_RTL;
|
|
|
|
|
uint icon_left = 4 + (rtl ? r.right - this->text_offset : r.left);
|
|
|
|
|
uint btn_left = (rtl ? icon_left - SETTING_BUTTON_WIDTH + 4 : icon_left + SETTING_BUTTON_WIDTH - 4);
|
|
|
|
|
uint text_left = r.left + (rtl ? WD_FRAMERECT_LEFT : this->text_offset);
|
|
|
|
|
uint text_right = r.right - (rtl ? this->text_offset : WD_FRAMERECT_RIGHT);
|
|
|
|
|
uint icon_left = (rtl ? r.right - WD_FRAMERECT_RIGHT - this->company_icon_spr_dim.width : WD_FRAMETEXT_LEFT + r.left);
|
|
|
|
|
uint btn_left = (rtl ? icon_left - SETTING_BUTTON_WIDTH - 4 : icon_left + this->company_icon_spr_dim.width + 4);
|
|
|
|
|
uint text_left = (rtl ? r.left + WD_FRAMERECT_LEFT : btn_left + SETTING_BUTTON_WIDTH + 4);
|
|
|
|
|
uint text_right = (rtl ? btn_left - 4 : r.right - WD_FRAMERECT_RIGHT);
|
|
|
|
|
const_cast<PlansWindow*>(this)->vis_btn_left = btn_left;
|
|
|
|
|
|
|
|
|
|
for (uint16 i = this->vscroll->GetPosition(); this->vscroll->IsVisible(i) && i < this->vscroll->GetCount(); i++) {
|
|
|
|
|
Plan *p = Plan::Get(list[i].plan_id);
|
|
|
|
@@ -195,18 +233,18 @@ struct PlansWindow : Window {
|
|
|
|
|
if (i == this->selected) GfxFillRect(r.left + 1, y, r.right, y + this->resize.step_height, PC_DARK_GREY);
|
|
|
|
|
|
|
|
|
|
if (list[i].is_plan) {
|
|
|
|
|
DrawCompanyIcon(p->owner, icon_left, y + (FONT_HEIGHT_NORMAL - 10) / 2 + 1);
|
|
|
|
|
DrawBoolButton(btn_left, y + (FONT_HEIGHT_NORMAL - 10) / 2, p->visible, true);
|
|
|
|
|
DrawCompanyIcon(p->owner, icon_left, y + (this->resize.step_height - this->company_icon_spr_dim.height) / 2);
|
|
|
|
|
DrawBoolButton(btn_left, y + (this->resize.step_height - SETTING_BUTTON_HEIGHT) / 2, p->visible, true);
|
|
|
|
|
SetDParam(0, list[i].plan_id + 1);
|
|
|
|
|
SetDParam(1, p->lines.size());
|
|
|
|
|
SetDParam(2, p->creation_date);
|
|
|
|
|
DrawString(text_left, text_right, y, STR_PLANS_LIST_ITEM_PLAN, p->visible_by_all ? TC_LIGHT_BLUE : TC_YELLOW);
|
|
|
|
|
DrawString(text_left, text_right, y + (this->resize.step_height - FONT_HEIGHT_NORMAL) / 2, STR_PLANS_LIST_ITEM_PLAN, p->visible_by_all ? TC_LIGHT_BLUE : TC_YELLOW);
|
|
|
|
|
} else {
|
|
|
|
|
PlanLine *pl = p->lines[list[i].line_id];
|
|
|
|
|
DrawBoolButton(btn_left, y + (FONT_HEIGHT_NORMAL - 10) / 2, pl->visible, true);
|
|
|
|
|
DrawBoolButton(btn_left, y + (this->resize.step_height - SETTING_BUTTON_HEIGHT) / 2, pl->visible, true);
|
|
|
|
|
SetDParam(0, list[i].line_id + 1);
|
|
|
|
|
SetDParam(1, pl->tiles.size() - 1);
|
|
|
|
|
DrawString(text_left, text_right, y, STR_PLANS_LIST_ITEM_LINE, TC_WHITE);
|
|
|
|
|
DrawString(text_left, text_right, y + (this->resize.step_height - FONT_HEIGHT_NORMAL) / 2, STR_PLANS_LIST_ITEM_LINE, TC_WHITE);
|
|
|
|
|
}
|
|
|
|
|
y += this->resize.step_height;
|
|
|
|
|
}
|
|
|
|
@@ -224,7 +262,8 @@ struct PlansWindow : Window {
|
|
|
|
|
{
|
|
|
|
|
switch (widget) {
|
|
|
|
|
case WID_PLN_LIST:
|
|
|
|
|
resize->height = FONT_HEIGHT_NORMAL;
|
|
|
|
|
this->company_icon_spr_dim = GetSpriteSize(SPR_COMPANY_ICON);
|
|
|
|
|
resize->height = max<int>(FONT_HEIGHT_NORMAL, SETTING_BUTTON_HEIGHT);
|
|
|
|
|
size->height = resize->height * 5 + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|