TBTR: Add train tooltips (right click and hover) in template edit window
This commit is contained in:
@@ -78,7 +78,7 @@ static const NWidgetPart _widgets[] = {
|
||||
EndContainer(),
|
||||
NWidget(NWID_HORIZONTAL),
|
||||
NWidget(NWID_VERTICAL),
|
||||
NWidget(WWT_PANEL, COLOUR_GREY, TCW_NEW_TMPL_PANEL), SetMinimalSize(250, 30), SetResize(1, 0), SetScrollbar(TCW_SCROLLBAR_H_NEW_TMPL), EndContainer(),
|
||||
NWidget(WWT_PANEL, COLOUR_GREY, TCW_NEW_TMPL_PANEL), SetMinimalSize(250, 30), SetResize(1, 0), SetScrollbar(TCW_SCROLLBAR_H_NEW_TMPL), SetDataTip(STR_NULL, STR_DEPOT_TRAIN_LIST_TOOLTIP), EndContainer(),
|
||||
NWidget(WWT_PANEL, COLOUR_GREY, TCW_INFO_PANEL), SetMinimalSize(250, 100), SetResize(1, 1), SetScrollbar(TCW_SCROLLBAR_V_NEW_TMPL), EndContainer(),
|
||||
NWidget(NWID_HSCROLLBAR, COLOUR_GREY, TCW_SCROLLBAR_H_NEW_TMPL),
|
||||
EndContainer(),
|
||||
@@ -388,6 +388,61 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool OnRightClick(Point pt, int widget) override
|
||||
{
|
||||
if (widget != TCW_NEW_TMPL_PANEL) return false;
|
||||
|
||||
GetDepotVehiclePtData gdvp = { nullptr, nullptr };
|
||||
const Vehicle *v = nullptr;
|
||||
NWidgetBase *nwi = this->GetWidget<NWidgetBase>(TCW_NEW_TMPL_PANEL);
|
||||
DepotGUIAction mode = this->GetVehicleFromDepotWndPt(pt.x - nwi->pos_x, pt.y - nwi->pos_y, &v, &gdvp);
|
||||
v = gdvp.wagon;
|
||||
|
||||
if (v == nullptr || mode != MODE_DRAG_VEHICLE) return false;
|
||||
|
||||
CargoArray capacity, loaded;
|
||||
|
||||
/* Display info for single (articulated) vehicle, or for whole chain starting with selected vehicle */
|
||||
bool whole_chain = _ctrl_pressed;
|
||||
|
||||
/* loop through vehicle chain and collect cargoes */
|
||||
uint num = 0;
|
||||
for (const Vehicle *w = v; w != nullptr; w = w->Next()) {
|
||||
if (w->cargo_cap > 0 && w->cargo_type < NUM_CARGO) {
|
||||
capacity[w->cargo_type] += w->cargo_cap;
|
||||
loaded [w->cargo_type] += w->cargo.StoredCount();
|
||||
}
|
||||
|
||||
if (w->type == VEH_TRAIN && !w->HasArticulatedPart()) {
|
||||
num++;
|
||||
if (!whole_chain) break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Build tooltipstring */
|
||||
static char details[1024];
|
||||
details[0] = '\0';
|
||||
char *pos = details;
|
||||
|
||||
for (CargoID cargo_type = 0; cargo_type < NUM_CARGO; cargo_type++) {
|
||||
if (capacity[cargo_type] == 0) continue;
|
||||
|
||||
SetDParam(0, cargo_type); // {CARGO} #1
|
||||
SetDParam(1, loaded[cargo_type]); // {CARGO} #2
|
||||
SetDParam(2, cargo_type); // {SHORTCARGO} #1
|
||||
SetDParam(3, capacity[cargo_type]); // {SHORTCARGO} #2
|
||||
pos = GetString(pos, STR_DEPOT_VEHICLE_TOOLTIP_CARGO, lastof(details));
|
||||
}
|
||||
|
||||
/* Show tooltip window */
|
||||
uint64 args[2];
|
||||
args[0] = (whole_chain ? num : v->engine_type);
|
||||
args[1] = (uint64)(size_t)details;
|
||||
GuiShowTooltips(this, whole_chain ? STR_DEPOT_VEHICLE_TOOLTIP_CHAIN : STR_DEPOT_VEHICLE_TOOLTIP, 2, args, TCC_RIGHT_CLICK);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual void OnDragDrop(Point pt, int widget) override
|
||||
{
|
||||
switch (widget) {
|
||||
|
Reference in New Issue
Block a user