diff --git a/src/lang/english.txt b/src/lang/english.txt index 89a5d9d3d5..d9425a1745 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -4095,7 +4095,7 @@ STR_PLANS_DELETE :{BLACK}Delete STR_PLANS_DELETE_TOOLTIP :{BLACK}Delete the selected item in the list STR_PLANS_LIST_ITEM_PLAN :Plan #{NUM}: {NUM} line{P "" s} ({DATE_SHORT}) STR_PLANS_LIST_ITEM_LINE : -- Line #{NUM}: {NUM} segment{P "" s} -STR_PLANS_LIST_TOOLTIP :{BLACK}Double click any item in the list to (un)fold the related plan +STR_PLANS_LIST_TOOLTIP :{BLACK}Double click any item in the list to (un)fold the related plan.{}Ctrl+Click to scroll to. # Vehicle loading indicators STR_PERCENT_UP_SMALL :{TINY_FONT}{WHITE}{NUM}%{UP_ARROW} diff --git a/src/plans_base.h b/src/plans_base.h index ca31a5ca13..7dac2d45b4 100644 --- a/src/plans_base.h +++ b/src/plans_base.h @@ -131,6 +131,26 @@ struct PlanLine { this->tiles.push_back(FROM_LE32(*data)); } } + + void AddLineToCalculateCentreTile(uint64 &x, uint64 &y, uint32 &count) const + { + for (size_t i = 0; i < this->tiles.size(); i++) { + TileIndex t = this->tiles[i]; + x += TileX(t); + y += TileY(t); + count++; + } + } + + TileIndex CalculateCentreTile() const + { + uint64 x = 0; + uint64 y = 0; + uint32 count = 0; + this->AddLineToCalculateCentreTile(x, y, count); + if (count == 0) return INVALID_TILE; + return TileXY(x / count, y / count); + } }; struct Plan : PlanPool::PoolItem<&_plan_pool> { @@ -229,6 +249,18 @@ struct Plan : PlanPool::PoolItem<&_plan_pool> { if (_current_plan->owner == _local_company) DoCommandP(0, _current_plan->index, !this->visible_by_all, CMD_CHANGE_PLAN_VISIBILITY); return this->visible_by_all; } + + TileIndex CalculateCentreTile() const + { + uint64 x = 0; + uint64 y = 0; + uint32 count = 0; + for (PlanLineVector::const_iterator it = lines.begin(); it != lines.end(); it++) { + (*it)->AddLineToCalculateCentreTile(x, y, count); + } + if (count == 0) return INVALID_TILE; + return TileXY(x / count, y / count); + } }; #define FOR_ALL_PLANS_FROM(var, start) FOR_ALL_ITEMS_FROM(Plan, plan_index, var, start) diff --git a/src/plans_gui.cpp b/src/plans_gui.cpp index d079a605a0..544227484b 100644 --- a/src/plans_gui.cpp +++ b/src/plans_gui.cpp @@ -139,6 +139,18 @@ struct PlansWindow : Window { 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); }