mirror of https://github.com/OpenTTD/OpenTTD
Cleanup: Don't mix switches and early returns in widget selection
parent
066ae6f3fb
commit
0bf6f82305
|
@ -406,10 +406,12 @@ struct NewGRFInspectWindow : Window {
|
||||||
::DrawString(r.Shrink(WidgetDimensions::scaled.frametext).Shrink(0, offset * this->resize.step_height, 0, 0), buf, TC_BLACK);
|
::DrawString(r.Shrink(WidgetDimensions::scaled.frametext).Shrink(0, offset * this->resize.step_height, 0, 0), buf, TC_BLACK);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DrawWidget(const Rect &r, int widget) const override
|
/**
|
||||||
|
* Helper function to draw the vehicle chain widget.
|
||||||
|
* @param r The rectangle to draw within.
|
||||||
|
*/
|
||||||
|
void DrawVehicleChainWidget(const Rect& r) const
|
||||||
{
|
{
|
||||||
switch (widget) {
|
|
||||||
case WID_NGRFI_VEH_CHAIN: {
|
|
||||||
const Vehicle *v = Vehicle::Get(this->GetFeatureIndex());
|
const Vehicle *v = Vehicle::Get(this->GetFeatureIndex());
|
||||||
int total_width = 0;
|
int total_width = 0;
|
||||||
int sel_start = 0;
|
int sel_start = 0;
|
||||||
|
@ -417,7 +419,7 @@ struct NewGRFInspectWindow : Window {
|
||||||
for (const Vehicle *u = v->First(); u != nullptr; u = u->Next()) {
|
for (const Vehicle *u = v->First(); u != nullptr; u = u->Next()) {
|
||||||
if (u == v) sel_start = total_width;
|
if (u == v) sel_start = total_width;
|
||||||
switch (u->type) {
|
switch (u->type) {
|
||||||
case VEH_TRAIN: total_width += Train ::From(u)->GetDisplayImageWidth(); break;
|
case VEH_TRAIN: total_width += Train::From(u)->GetDisplayImageWidth(); break;
|
||||||
case VEH_ROAD: total_width += RoadVehicle::From(u)->GetDisplayImageWidth(); break;
|
case VEH_ROAD: total_width += RoadVehicle::From(u)->GetDisplayImageWidth(); break;
|
||||||
default: NOT_REACHED();
|
default: NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
@ -443,12 +445,14 @@ struct NewGRFInspectWindow : Window {
|
||||||
} else {
|
} else {
|
||||||
DrawFrameRect(r.left + sel_start - skip, y, r.left + sel_end - skip, y + h, COLOUR_WHITE, FR_BORDERONLY);
|
DrawFrameRect(r.left + sel_start - skip, y, r.left + sel_end - skip, y + h, COLOUR_WHITE, FR_BORDERONLY);
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (widget != WID_NGRFI_MAINPANEL) return;
|
/**
|
||||||
|
* Helper function to draw the main panel widget.
|
||||||
|
* @param r The rectangle to draw within.
|
||||||
|
*/
|
||||||
|
void DrawMainPanelWidget(const Rect& r) const
|
||||||
|
{
|
||||||
uint index = this->GetFeatureIndex();
|
uint index = this->GetFeatureIndex();
|
||||||
const NIFeature *nif = GetFeature(this->window_number);
|
const NIFeature *nif = GetFeature(this->window_number);
|
||||||
const NIHelper *nih = nif->helper;
|
const NIHelper *nih = nif->helper;
|
||||||
|
@ -547,6 +551,19 @@ struct NewGRFInspectWindow : Window {
|
||||||
const_cast<NewGRFInspectWindow*>(this)->vscroll->SetCount(i);
|
const_cast<NewGRFInspectWindow*>(this)->vscroll->SetCount(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DrawWidget(const Rect &r, int widget) const override
|
||||||
|
{
|
||||||
|
switch (widget) {
|
||||||
|
case WID_NGRFI_VEH_CHAIN:
|
||||||
|
this->DrawVehicleChainWidget(r);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case WID_NGRFI_MAINPANEL:
|
||||||
|
this->DrawMainPanelWidget(r);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void OnClick(Point pt, int widget, int click_count) override
|
void OnClick(Point pt, int widget, int click_count) override
|
||||||
{
|
{
|
||||||
switch (widget) {
|
switch (widget) {
|
||||||
|
|
Loading…
Reference in New Issue