Mercurial > hg > openttd
changeset 17785:cbd020284e09 draft
(svn r22570) -Codechange: Store the GrfID of the caller when opening a parent window in the NewGRF debug GUI.
author | terkhen <terkhen@openttd.org> |
---|---|
date | Sun, 12 Jun 2011 20:51:38 +0000 |
parents | ebbbd5ad03d2 |
children | 9c79dc561eaa |
files | src/newgrf_debug.h src/newgrf_debug_gui.cpp src/table/newgrf_debug_data.h |
diffstat | 3 files changed, 38 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/newgrf_debug.h +++ b/src/newgrf_debug.h @@ -35,7 +35,7 @@ extern NewGrfDebugSpritePicker _newgrf_debug_sprite_picker; bool IsNewGRFInspectable(GrfSpecFeature feature, uint index); -void ShowNewGRFInspectWindow(GrfSpecFeature feature, uint index); +void ShowNewGRFInspectWindow(GrfSpecFeature feature, uint index, const uint32 grfid = 0); void DeleteNewGRFInspectWindow(GrfSpecFeature feature, uint index); GrfSpecFeature GetGrfSpecFeature(TileIndex tile);
--- a/src/newgrf_debug_gui.cpp +++ b/src/newgrf_debug_gui.cpp @@ -141,6 +141,13 @@ virtual void SetStringParameters(uint index) const = 0; /** + * Get the GRFID of the file that includes this item. + * @param index index to check. + * @return GRFID of the item. 0 means that the item is not inspectable. + */ + virtual uint32 GetGRFID(uint index) const = 0; + + /** * Resolve (action2) variable for a given index. * @param index The (instance) index to resolve the variable for. * @param var The variable to actually resolve. @@ -277,6 +284,9 @@ /** The value for the variable 60 parameters. */ static byte var60params[GSF_FAKE_END][0x20]; + /** GRFID of the caller of this window, 0 if it has no caller. */ + uint32 caller_grfid; + /** The currently editted parameter, to update the right one. */ byte current_edit_param; @@ -292,6 +302,16 @@ return IsInsideBS(variable, 0x60, 0x20); } + /** + * Set the GRFID of the item opening this window. + * @param grfid GRFID of the item opening this window, or 0 if not opened by other window. + */ + void SetCallerGRFID(uint32 grfid) + { + this->caller_grfid = grfid; + this->SetDirty(); + } + NewGRFInspectWindow(const WindowDesc *desc, WindowNumber wno) : Window() { this->CreateNestedTree(desc); @@ -442,8 +462,9 @@ { switch (widget) { case NIW_PARENT: { - uint index = GetFeatureHelper(this->window_number)->GetParent(GetFeatureIndex(this->window_number)); - ::ShowNewGRFInspectWindow((GrfSpecFeature)GB(index, 24, 8), GetFeatureIndex(index)); + const NIHelper *nih = GetFeatureHelper(this->window_number); + uint index = nih->GetParent(GetFeatureIndex(this->window_number)); + ::ShowNewGRFInspectWindow((GrfSpecFeature)GB(index, 24, 8), GetFeatureIndex(index), nih->GetGRFID(GetFeatureIndex(this->window_number))); break; } @@ -516,13 +537,16 @@ * we want to inspect. * @param feature The feature we want to inspect. * @param index The index/identifier of the feature to inspect. + * @param grfid GRFID of the item opening this window, or 0 if not opened by other window. */ -void ShowNewGRFInspectWindow(GrfSpecFeature feature, uint index) +void ShowNewGRFInspectWindow(GrfSpecFeature feature, uint index, const uint32 grfid) { if (!IsNewGRFInspectable(feature, index)) return; WindowNumber wno = GetInspectWindowNumber(feature, index); - AllocateWindowDescFront<NewGRFInspectWindow>(&_newgrf_inspect_desc, wno); + NewGRFInspectWindow *w = AllocateWindowDescFront<NewGRFInspectWindow>(&_newgrf_inspect_desc, wno); + if (w == NULL) w = (NewGRFInspectWindow *)FindWindowById(WC_NEWGRF_INSPECT, wno); + w->SetCallerGRFID(grfid); } /**
--- a/src/table/newgrf_debug_data.h +++ b/src/table/newgrf_debug_data.h @@ -66,6 +66,7 @@ const void *GetInstance(uint index)const { return Vehicle::Get(index); } const void *GetSpec(uint index) const { return Engine::Get(Vehicle::Get(index)->engine_type); } void SetStringParameters(uint index) const { this->SetSimpleStringParameters(STR_VEHICLE_NAME, index); } + uint32 GetGRFID(uint index) const { return (this->IsInspectable(index)) ? Engine::Get(Vehicle::Get(index)->engine_type)->grf_prop.grffile->grfid : 0; } void Resolve(ResolverObject *ro, uint32 index) const { extern void GetVehicleResolver(ResolverObject *ro, uint index); GetVehicleResolver(ro, index); } }; @@ -122,6 +123,7 @@ const void *GetInstance(uint index)const { return NULL; } const void *GetSpec(uint index) const { return GetStationSpec(index); } void SetStringParameters(uint index) const { this->SetObjectAtStringParameters(STR_STATION_NAME, GetStationIndex(index), index); } + uint32 GetGRFID(uint index) const { return (this->IsInspectable(index)) ? GetStationSpec(index)->grf_prop.grffile->grfid : 0; } void Resolve(ResolverObject *ro, uint32 index) const { extern void GetStationResolver(ResolverObject *ro, uint index); GetStationResolver(ro, index); } }; @@ -181,6 +183,7 @@ const void *GetInstance(uint index)const { return NULL; } const void *GetSpec(uint index) const { return HouseSpec::Get(GetHouseType(index)); } void SetStringParameters(uint index) const { this->SetObjectAtStringParameters(STR_TOWN_NAME, GetTownIndex(index), index); } + uint32 GetGRFID(uint index) const { return (this->IsInspectable(index)) ? HouseSpec::Get(GetHouseType(index))->grf_prop.grffile->grfid : 0; } void Resolve(ResolverObject *ro, uint32 index) const { extern void GetHouseResolver(ResolverObject *ro, uint index); GetHouseResolver(ro, index); } }; @@ -225,6 +228,7 @@ const void *GetInstance(uint index)const { return NULL; } const void *GetSpec(uint index) const { return GetIndustryTileSpec(GetIndustryGfx(index)); } void SetStringParameters(uint index) const { this->SetObjectAtStringParameters(STR_INDUSTRY_NAME, GetIndustryIndex(index), index); } + uint32 GetGRFID(uint index) const { return (this->IsInspectable(index)) ? GetIndustryTileSpec(GetIndustryGfx(index))->grf_prop.grffile->grfid : 0; } void Resolve(ResolverObject *ro, uint32 index) const { extern void GetIndustryTileResolver(ResolverObject *ro, uint index); GetIndustryTileResolver(ro, index); } }; @@ -290,6 +294,7 @@ const void *GetInstance(uint index)const { return Industry::Get(index); } const void *GetSpec(uint index) const { return GetIndustrySpec(Industry::Get(index)->type); } void SetStringParameters(uint index) const { this->SetSimpleStringParameters(STR_INDUSTRY_NAME, index); } + uint32 GetGRFID(uint index) const { return (this->IsInspectable(index)) ? GetIndustrySpec(Industry::Get(index)->type)->grf_prop.grffile->grfid : 0; } void Resolve(ResolverObject *ro, uint32 index) const { extern void GetIndustryResolver(ResolverObject *ro, uint index); GetIndustryResolver(ro, index); } uint GetPSASize(uint index, uint32 grfid) const { return cpp_lengthof(PersistentStorage, storage); } @@ -347,6 +352,7 @@ const void *GetInstance(uint index)const { return Object::GetByTile(index); } const void *GetSpec(uint index) const { return ObjectSpec::GetByTile(index); } void SetStringParameters(uint index) const { this->SetObjectAtStringParameters(STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_OBJECT, INVALID_STRING_ID, index); } + uint32 GetGRFID(uint index) const { return (this->IsInspectable(index)) ? ObjectSpec::GetByTile(index)->grf_prop.grffile->grfid : 0; } void Resolve(ResolverObject *ro, uint32 index) const { extern void GetObjectResolver(ResolverObject *ro, uint index); GetObjectResolver(ro, index); } }; @@ -373,6 +379,7 @@ const void *GetInstance(uint index)const { return NULL; } const void *GetSpec(uint index) const { return NULL; } void SetStringParameters(uint index) const { this->SetObjectAtStringParameters(STR_NEWGRF_INSPECT_CAPTION_OBJECT_AT_RAIL_TYPE, INVALID_STRING_ID, index); } + uint32 GetGRFID(uint index) const { return 0; } void Resolve(ResolverObject *ro, uint32 index) const { extern void GetRailTypeResolver(ResolverObject *ro, uint index); GetRailTypeResolver(ro, index); } }; @@ -401,6 +408,7 @@ const void *GetInstance(uint index)const { return NULL; } const void *GetSpec(uint index) const { return AirportTileSpec::Get(GetAirportGfx(index)); } void SetStringParameters(uint index) const { this->SetObjectAtStringParameters(STR_STATION_NAME, GetStationIndex(index), index); } + uint32 GetGRFID(uint index) const { return (this->IsInspectable(index)) ? AirportTileSpec::Get(GetAirportGfx(index))->grf_prop.grffile->grfid : 0; } void Resolve(ResolverObject *ro, uint32 index) const { extern void GetAirportTileTypeResolver(ResolverObject *ro, uint index); GetAirportTileTypeResolver(ro, index); } }; @@ -433,6 +441,7 @@ const void *GetInstance(uint index)const { return Town::Get(index); } const void *GetSpec(uint index) const { return NULL; } void SetStringParameters(uint index) const { this->SetSimpleStringParameters(STR_TOWN_NAME, index); } + uint32 GetGRFID(uint index) const { return 0; } uint Resolve(uint index, uint var, uint param, bool *avail) const { return TownGetVariable(var, param, avail, Town::Get(index), NULL); } };