diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 5f772f541e..039ef8a1c4 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -1887,6 +1887,7 @@ static const NWidgetPart _nested_industry_cargoes_widgets[] = { NWidget(NWID_HORIZONTAL), NWidget(WWT_CLOSEBOX, COLOUR_BROWN), NWidget(WWT_CAPTION, COLOUR_BROWN, WID_IC_CAPTION), SetDataTip(STR_INDUSTRY_CARGOES_INDUSTRY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS), + NWidget(WWT_DEBUGBOX, COLOUR_BROWN, WID_IC_DEBUG), NWidget(WWT_SHADEBOX, COLOUR_BROWN), NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN), NWidget(WWT_STICKYBOX, COLOUR_BROWN), @@ -2856,6 +2857,7 @@ struct IndustryCargoesWindow : public Window { this->vscroll->SetCount(num_indrows); this->SetDirty(); this->NotifySmallmap(); + this->SetWidgetDisabledState(WID_IC_DEBUG, false); } /** @@ -2927,6 +2929,7 @@ struct IndustryCargoesWindow : public Window { this->vscroll->SetCount(num_indrows); this->SetDirty(); this->NotifySmallmap(); + this->SetWidgetDisabledState(WID_IC_DEBUG, true); } /** @@ -3195,6 +3198,18 @@ struct IndustryCargoesWindow : public Window { { this->vscroll->SetCapacityFromWidget(this, WID_IC_PANEL, WD_FRAMERECT_TOP + CargoesField::small_height); } + + bool IsNewGRFInspectable() const override + { + return true; + } + + void ShowNewGRFInspectWindow() const override + { + if (this->ind_cargo < NUM_INDUSTRYTYPES) { + ::ShowNewGRFInspectWindow(GSF_INDUSTRIES, this->ind_cargo | (1 << 26)); + } + } }; const int IndustryCargoesWindow::HOR_TEXT_PADDING = 5; ///< Horizontal padding around the industry type text. diff --git a/src/newgrf_debug_gui.cpp b/src/newgrf_debug_gui.cpp index 1524c48b75..69b1d2d1fe 100644 --- a/src/newgrf_debug_gui.cpp +++ b/src/newgrf_debug_gui.cpp @@ -216,6 +216,7 @@ public: virtual void ExtraInfo(uint index, NIExtraInfoOutput &output) const {} virtual void SpriteDump(uint index, DumpSpriteGroupPrinter print) const {} virtual bool ShowExtraInfoOnly(uint index) const { return false; }; + virtual bool ShowExtraInfoIncludingGRFIDOnly(uint index) const { return false; }; virtual bool ShowSpriteDumpButton(uint index) const { return false; }; protected: @@ -618,6 +619,8 @@ struct NewGRFInspectWindow : Window { } } + if (nih->ShowExtraInfoIncludingGRFIDOnly(index)) return; + const_cast(this)->first_variable_line_index = i; if (nif->variables != nullptr) { diff --git a/src/table/newgrf_debug_data.h b/src/table/newgrf_debug_data.h index 428d11db56..21ea5bb18e 100644 --- a/src/table/newgrf_debug_data.h +++ b/src/table/newgrf_debug_data.h @@ -781,13 +781,40 @@ static const NIVariable _niv_industries[] = { class NIHIndustry : public NIHelper { bool IsInspectable(uint index) const override { return true; } - bool ShowExtraInfoOnly(uint index) const override { return GetIndustrySpec(Industry::Get(index)->type)->grf_prop.grffile == nullptr; } bool ShowSpriteDumpButton(uint index) const override { return true; } - uint GetParent(uint index) const override { return GetInspectWindowNumber(GSF_FAKE_TOWNS, Industry::Get(index)->town->index); } - const void *GetInstance(uint index)const override { return Industry::Get(index); } - const void *GetSpec(uint index) const override { return GetIndustrySpec(Industry::Get(index)->type); } - void SetStringParameters(uint index) const override { this->SetSimpleStringParameters(STR_INDUSTRY_NAME, index); } - uint32 GetGRFID(uint index) const override { return (!this->ShowExtraInfoOnly(index)) ? GetIndustrySpec(Industry::Get(index)->type)->grf_prop.grffile->grfid : 0; } + uint GetParent(uint index) const override { return HasBit(index, 26) ? UINT32_MAX : GetInspectWindowNumber(GSF_FAKE_TOWNS, Industry::Get(index)->town->index); } + const void *GetInstance(uint index)const override { return HasBit(index, 26) ? nullptr : Industry::Get(index); } + uint32 GetGRFID(uint index) const override { return (!this->ShowExtraInfoOnly(index)) ? ((const IndustrySpec *)this->GetSpec(index))->grf_prop.grffile->grfid : 0; } + + bool ShowExtraInfoOnly(uint index) const override + { + const IndustrySpec *spec = (const IndustrySpec *)this->GetSpec(index); + return spec == nullptr || spec->grf_prop.grffile == nullptr; + } + + bool ShowExtraInfoIncludingGRFIDOnly(uint index) const override + { + return HasBit(index, 26); + } + + const void *GetSpec(uint index) const override + { + if (HasBit(index, 26)) { + return GetIndustrySpec(GB(index, 0, 16)); + } else { + Industry *i = Industry::Get(index); + return i != nullptr ? GetIndustrySpec(i->type) : nullptr; + } + } + + void SetStringParameters(uint index) const override + { + if (HasBit(index, 26)) { + SetDParam(0, GetIndustrySpec(GB(index, 0, 16))->name); + } else { + this->SetSimpleStringParameters(STR_INDUSTRY_NAME, index); + } + } uint Resolve(uint index, uint var, uint param, GetVariableExtra *extra) const override { @@ -814,47 +841,52 @@ class NIHIndustry : public NIHelper { { char buffer[1024]; output.print("Debug Info:"); - seprintf(buffer, lastof(buffer), " Index: %u", index); - output.print(buffer); - const Industry *ind = Industry::GetIfValid(index); - if (ind) { - seprintf(buffer, lastof(buffer), " Location: %ux%u (%X), w: %u, h: %u", TileX(ind->location.tile), TileY(ind->location.tile), ind->location.tile, ind->location.w, ind->location.h); - output.print(buffer); - if (ind->neutral_station) { - seprintf(buffer, lastof(buffer), " Neutral station: %u: %s", ind->neutral_station->index, ind->neutral_station->GetCachedName()); - output.print(buffer); - } - seprintf(buffer, lastof(buffer), " Nearby stations: %u", (uint) ind->stations_near.size()); - output.print(buffer); - for (const Station *st : ind->stations_near) { - seprintf(buffer, lastof(buffer), " %u: %s", st->index, st->GetCachedName()); - output.print(buffer); - } - output.print(" Produces:"); - for (uint i = 0; i < lengthof(ind->produced_cargo); i++) { - if (ind->produced_cargo[i] != CT_INVALID) { - seprintf(buffer, lastof(buffer), " %s: waiting: %u, rate: %u, this month: production: %u, transported: %u, last month: production: %u, transported: %u, (%u/255)", - GetStringPtr(CargoSpec::Get(ind->produced_cargo[i])->name), ind->produced_cargo_waiting[i], ind->production_rate[i], ind->this_month_production[i], - ind->this_month_transported[i], ind->last_month_production[i], ind->last_month_transported[i], ind->last_month_pct_transported[i]); - output.print(buffer); - } - } - output.print(" Accepts:"); - for (uint i = 0; i < lengthof(ind->accepts_cargo); i++) { - if (ind->accepts_cargo[i] != CT_INVALID) { - seprintf(buffer, lastof(buffer), " %s: waiting: %u", - GetStringPtr(CargoSpec::Get(ind->accepts_cargo[i])->name), ind->incoming_cargo_waiting[i]); - output.print(buffer); - } - } - const IndustrySpec *indsp = GetIndustrySpec(ind->type); + if (!HasBit(index, 26)) { + seprintf(buffer, lastof(buffer), " Index: %u", index); + output.print(buffer); + const Industry *ind = Industry::GetIfValid(index); + if (ind) { + seprintf(buffer, lastof(buffer), " Location: %ux%u (%X), w: %u, h: %u", TileX(ind->location.tile), TileY(ind->location.tile), ind->location.tile, ind->location.w, ind->location.h); + output.print(buffer); + if (ind->neutral_station) { + seprintf(buffer, lastof(buffer), " Neutral station: %u: %s", ind->neutral_station->index, ind->neutral_station->GetCachedName()); + output.print(buffer); + } + seprintf(buffer, lastof(buffer), " Nearby stations: %u", (uint) ind->stations_near.size()); + output.print(buffer); + for (const Station *st : ind->stations_near) { + seprintf(buffer, lastof(buffer), " %u: %s", st->index, st->GetCachedName()); + output.print(buffer); + } + output.print(" Produces:"); + for (uint i = 0; i < lengthof(ind->produced_cargo); i++) { + if (ind->produced_cargo[i] != CT_INVALID) { + seprintf(buffer, lastof(buffer), " %s: waiting: %u, rate: %u, this month: production: %u, transported: %u, last month: production: %u, transported: %u, (%u/255)", + GetStringPtr(CargoSpec::Get(ind->produced_cargo[i])->name), ind->produced_cargo_waiting[i], ind->production_rate[i], ind->this_month_production[i], + ind->this_month_transported[i], ind->last_month_production[i], ind->last_month_transported[i], ind->last_month_pct_transported[i]); + output.print(buffer); + } + } + output.print(" Accepts:"); + for (uint i = 0; i < lengthof(ind->accepts_cargo); i++) { + if (ind->accepts_cargo[i] != CT_INVALID) { + seprintf(buffer, lastof(buffer), " %s: waiting: %u", + GetStringPtr(CargoSpec::Get(ind->accepts_cargo[i])->name), ind->incoming_cargo_waiting[i]); + output.print(buffer); + } + } + seprintf(buffer, lastof(buffer), " Counter: %u", ind->counter); + output.print(buffer); + } + } + + const IndustrySpec *indsp = (const IndustrySpec *)this->GetSpec(index); + if (indsp) { seprintf(buffer, lastof(buffer), " CBM_IND_PRODUCTION_CARGO_ARRIVAL: %s", HasBit(indsp->callback_mask, CBM_IND_PRODUCTION_CARGO_ARRIVAL) ? "yes" : "no"); output.print(buffer); seprintf(buffer, lastof(buffer), " CBM_IND_PRODUCTION_256_TICKS: %s", HasBit(indsp->callback_mask, CBM_IND_PRODUCTION_256_TICKS) ? "yes" : "no"); output.print(buffer); - seprintf(buffer, lastof(buffer), " Counter: %u", ind->counter); - output.print(buffer); if ((_settings_game.economy.industry_cargo_scale_factor != 0) && HasBit(indsp->callback_mask, CBM_IND_PRODUCTION_256_TICKS)) { seprintf(buffer, lastof(buffer), " Counter production interval: %u", ScaleQuantity(INDUSTRY_PRODUCE_TICKS, -_settings_game.economy.industry_cargo_scale_factor)); output.print(buffer); @@ -870,10 +902,10 @@ class NIHIndustry : public NIHelper { /* virtual */ void SpriteDump(uint index, DumpSpriteGroupPrinter print) const override { - const Industry *ind = Industry::GetIfValid(index); - if (ind) { + const IndustrySpec *spec = (const IndustrySpec *)this->GetSpec(index); + if (spec) { extern void DumpIndustrySpriteGroup(const IndustrySpec *spec, DumpSpriteGroupPrinter print); - DumpIndustrySpriteGroup(GetIndustrySpec(ind->type), std::move(print)); + DumpIndustrySpriteGroup(spec, std::move(print)); } } }; diff --git a/src/widgets/industry_widget.h b/src/widgets/industry_widget.h index 5e3a656c1f..5a5c5e935e 100644 --- a/src/widgets/industry_widget.h +++ b/src/widgets/industry_widget.h @@ -49,6 +49,7 @@ enum IndustryCargoesWidgets { WID_IC_SCROLLBAR, ///< Scrollbar of the panel. WID_IC_CARGO_DROPDOWN, ///< Select cargo dropdown. WID_IC_IND_DROPDOWN, ///< Select industry dropdown. + WID_IC_DEBUG, ///< Debug button }; #endif /* WIDGETS_INDUSTRY_WIDGET_H */