Allow cloning trains directly from the template train list

See: #312
This commit is contained in:
Jonathan G Rennison
2021-08-22 14:59:33 +01:00
parent a4c73e71c3
commit a026d82c6b
7 changed files with 88 additions and 0 deletions

View File

@@ -447,6 +447,8 @@ public:
if (newindex == this->selected_template_index || newindex >= templates.size()) {
this->selected_template_index = -1;
} else if (newindex < templates.size()) {
const TemplateVehicle *tmp = this->templates[newindex];
if (tmp != nullptr && TemplateVehicleClicked(tmp)) return;
this->selected_template_index = newindex;
}
this->UpdateButtonState();
@@ -840,3 +842,19 @@ void ShowTemplateReplaceWindow()
new TemplateReplaceWindow(&_replace_rail_vehicle_desc);
}
}
/**
* Dispatch a "template vehicle selected" event if any window waits for it.
* @param v selected vehicle;
* @return did any window accept vehicle selection?
*/
bool TemplateVehicleClicked(const TemplateVehicle *v)
{
assert(v != nullptr);
if (!(_thd.place_mode & HT_VEHICLE)) return false;
v = v->First();
if (!v->IsPrimaryVehicle()) return false;
return _thd.GetCallbackWnd()->OnTemplateVehicleSelect(v);
}