diff --git a/src/lang/english.txt b/src/lang/english.txt index eafc23b189..841dc3d90f 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -3825,6 +3825,8 @@ STR_NEWGRF_INSPECT_REFRESH :{BLACK}R STR_NEWGRF_INSPECT_REFRESH_TOOLTIP :{BLACK}Toggle whether to refresh the contents every frame STR_NEWGRF_INSPECT_LOG_CONSOLE :{BLACK}L STR_NEWGRF_INSPECT_LOG_CONSOLE_TOOLTIP :{BLACK}Log text content of this window to the console +STR_NEWGRF_INSPECT_SPRITE_DUMP :{BLACK}S +STR_NEWGRF_INSPECT_SPRITE_DUMP_TOOLTIP :{BLACK}Display current sprite chain STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT :{STRING1} at {HEX} STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_OBJECT :Object diff --git a/src/newgrf_debug_gui.cpp b/src/newgrf_debug_gui.cpp index 0c8ae2b8d0..5adabe09a9 100644 --- a/src/newgrf_debug_gui.cpp +++ b/src/newgrf_debug_gui.cpp @@ -207,7 +207,9 @@ public: } virtual void ExtraInfo(uint index, std::function print) const {} + virtual void SpriteDump(uint index, std::function print) const {} virtual bool ShowExtraInfoOnly(uint index) const { return false; }; + virtual bool ShowSpriteDumpButton(uint index) const { return false; }; protected: /** @@ -306,6 +308,7 @@ struct NewGRFInspectWindow : Window { bool auto_refresh = false; bool log_console = false; + bool sprite_dump = false; /** * Check whether the given variable has a parameter. @@ -370,6 +373,7 @@ struct NewGRFInspectWindow : Window { { this->CreateNestedTree(); this->vscroll = this->GetScrollbar(WID_NGRFI_SCROLLBAR); + this->GetWidget(WID_NGRFI_SPRITE_DUMP_SEL)->SetDisplayedPlane(GetFeatureHelper(wno)->ShowSpriteDumpButton(::GetFeatureIndex(wno)) ? 0 : SZSP_NONE); this->FinishInitNested(wno); this->vscroll->SetCount(0); @@ -490,13 +494,16 @@ struct NewGRFInspectWindow : Window { DEBUG(misc, 0, "*** END ***"); } - /* Not nice and certainly a hack, but it beats duplicating - * this whole function just to count the actual number of - * elements. Especially because they need to be redrawn. */ - const_cast(this)->vscroll->SetCount(i); + uint count = std::min(UINT16_MAX, i); + if (vscroll->GetCount() != count) { + /* Not nice and certainly a hack, but it beats duplicating + * this whole function just to count the actual number of + * elements. Especially because they need to be redrawn. */ + const_cast(this)->vscroll->SetCount(count); + } }); - nih->ExtraInfo(index, [&](const char *buf) { + auto line_handler = [&](const char *buf) { if (this->log_console) DEBUG(misc, 0, " %s", buf); int offset = i++; @@ -504,7 +511,13 @@ struct NewGRFInspectWindow : Window { if (offset < 0 || offset >= this->vscroll->GetCapacity()) return; ::DrawString(r.left + LEFT_OFFSET, r.right - RIGHT_OFFSET, r.top + TOP_OFFSET + (offset * this->resize.step_height), buf, TC_BLACK); - }); + }; + if (this->sprite_dump) { + nih->SpriteDump(index, line_handler); + return; + } else { + nih->ExtraInfo(index, line_handler); + } if (nih->ShowExtraInfoOnly(index)) return; @@ -647,6 +660,7 @@ struct NewGRFInspectWindow : Window { break; case WID_NGRFI_MAINPANEL: { + if (this->sprite_dump) return; /* Does this feature have variables? */ const NIFeature *nif = GetFeature(this->window_number); if (nif->variables == nullptr) return; @@ -681,6 +695,15 @@ struct NewGRFInspectWindow : Window { this->SetWidgetDirty(WID_NGRFI_MAINPANEL); break; } + + case WID_NGRFI_SPRITE_DUMP: { + this->sprite_dump = !this->sprite_dump; + this->SetWidgetLoweredState(WID_NGRFI_SPRITE_DUMP, this->sprite_dump); + this->SetWidgetDirty(WID_NGRFI_SPRITE_DUMP); + this->SetWidgetDirty(WID_NGRFI_MAINPANEL); + this->SetWidgetDirty(WID_NGRFI_SCROLLBAR); + break; + } } } @@ -725,6 +748,9 @@ static const NWidgetPart _nested_newgrf_inspect_chain_widgets[] = { NWidget(NWID_HORIZONTAL), NWidget(WWT_CLOSEBOX, COLOUR_GREY), NWidget(WWT_CAPTION, COLOUR_GREY, WID_NGRFI_CAPTION), SetDataTip(STR_NEWGRF_INSPECT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS), + NWidget(NWID_SELECTION, INVALID_COLOUR, WID_NGRFI_SPRITE_DUMP_SEL), + NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_NGRFI_SPRITE_DUMP), SetDataTip(STR_NEWGRF_INSPECT_SPRITE_DUMP, STR_NEWGRF_INSPECT_SPRITE_DUMP_TOOLTIP), + EndContainer(), NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_NGRFI_LOG_CONSOLE), SetDataTip(STR_NEWGRF_INSPECT_LOG_CONSOLE, STR_NEWGRF_INSPECT_LOG_CONSOLE_TOOLTIP), NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_NGRFI_REFRESH), SetDataTip(STR_NEWGRF_INSPECT_REFRESH, STR_NEWGRF_INSPECT_REFRESH_TOOLTIP), NWidget(WWT_SHADEBOX, COLOUR_GREY), @@ -752,6 +778,9 @@ static const NWidgetPart _nested_newgrf_inspect_widgets[] = { NWidget(WWT_CLOSEBOX, COLOUR_GREY), NWidget(WWT_CAPTION, COLOUR_GREY, WID_NGRFI_CAPTION), SetDataTip(STR_NEWGRF_INSPECT_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS), NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_NGRFI_PARENT), SetDataTip(STR_NEWGRF_INSPECT_PARENT_BUTTON, STR_NEWGRF_INSPECT_PARENT_TOOLTIP), + NWidget(NWID_SELECTION, INVALID_COLOUR, WID_NGRFI_SPRITE_DUMP_SEL), + NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_NGRFI_SPRITE_DUMP), SetDataTip(STR_NEWGRF_INSPECT_SPRITE_DUMP, STR_NEWGRF_INSPECT_SPRITE_DUMP_TOOLTIP), + EndContainer(), NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_NGRFI_LOG_CONSOLE), SetDataTip(STR_NEWGRF_INSPECT_LOG_CONSOLE, STR_NEWGRF_INSPECT_LOG_CONSOLE_TOOLTIP), NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_NGRFI_REFRESH), SetDataTip(STR_NEWGRF_INSPECT_REFRESH, STR_NEWGRF_INSPECT_REFRESH_TOOLTIP), NWidget(WWT_SHADEBOX, COLOUR_GREY), diff --git a/src/table/newgrf_debug_data.h b/src/table/newgrf_debug_data.h index d352c3abe9..779761f666 100644 --- a/src/table/newgrf_debug_data.h +++ b/src/table/newgrf_debug_data.h @@ -76,6 +76,7 @@ static const NIVariable _niv_vehicles[] = { class NIHVehicle : public NIHelper { bool IsInspectable(uint index) const override { return true; } bool ShowExtraInfoOnly(uint index) const override { return Vehicle::Get(index)->GetGRF() == nullptr; } + bool ShowSpriteDumpButton(uint index) const override { return true; } uint GetParent(uint index) const override { const Vehicle *first = Vehicle::Get(index)->First(); return GetInspectWindowNumber(GetGrfSpecFeature(first->type), first->index); } const void *GetInstance(uint index)const override { return Vehicle::Get(index); } const void *GetSpec(uint index) const override { return Vehicle::Get(index)->GetEngine(); } @@ -329,6 +330,12 @@ class NIHVehicle : public NIHelper { seprintf(buffer, lastof(buffer), " Current image cacheable: %s", v->cur_image_valid_dir != INVALID_DIR ? "yes" : "no"); print(buffer); } + + /* virtual */ void SpriteDump(uint index, std::function print) const override + { + extern void DumpVehicleSpriteGroup(const Vehicle *v, std::function print); + DumpVehicleSpriteGroup(Vehicle::Get(index), std::move(print)); + } }; static const NIFeature _nif_vehicle = { diff --git a/src/widgets/newgrf_debug_widget.h b/src/widgets/newgrf_debug_widget.h index 3f898832a8..49b162269c 100644 --- a/src/widgets/newgrf_debug_widget.h +++ b/src/widgets/newgrf_debug_widget.h @@ -21,6 +21,8 @@ enum NewGRFInspectWidgets { WID_NGRFI_SCROLLBAR, ///< Scrollbar. WID_NGRFI_REFRESH, ///< Refresh toggle. WID_NGRFI_LOG_CONSOLE, ///< Log to console + WID_NGRFI_SPRITE_DUMP, ///< Dump current sprite group + WID_NGRFI_SPRITE_DUMP_SEL, ///< Selection widget for WID_NGRFI_SPRITE_DUMP }; /** Widgets of the #SpriteAlignerWindow class. */