summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorterkhen <terkhen@openttd.org>2011-06-12 20:51:38 +0000
committerterkhen <terkhen@openttd.org>2011-06-12 20:51:38 +0000
commit46d1a0621581a711aedeaa5d15628b4048fde43a (patch)
tree253ccf4e17d1d7cbd2d95b329811ec8320bf539a /src
parenta619ad37897c6ee985aa7bb0dadbd9bbc47c5a63 (diff)
downloadopenttd-46d1a0621581a711aedeaa5d15628b4048fde43a.tar.xz
(svn r22570) -Codechange: Store the GrfID of the caller when opening a parent window in the NewGRF debug GUI.
Diffstat (limited to 'src')
-rw-r--r--src/newgrf_debug.h2
-rw-r--r--src/newgrf_debug_gui.cpp32
-rw-r--r--src/table/newgrf_debug_data.h9
3 files changed, 38 insertions, 5 deletions
diff --git a/src/newgrf_debug.h b/src/newgrf_debug.h
index 4fd9d498f..89ede74eb 100644
--- a/src/newgrf_debug.h
+++ b/src/newgrf_debug.h
@@ -35,7 +35,7 @@ struct NewGrfDebugSpritePicker {
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);
diff --git a/src/newgrf_debug_gui.cpp b/src/newgrf_debug_gui.cpp
index 5cd3cd63a..6ba47e7ee 100644
--- a/src/newgrf_debug_gui.cpp
+++ b/src/newgrf_debug_gui.cpp
@@ -141,6 +141,13 @@ public:
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 @@ struct NewGRFInspectWindow : Window {
/** 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 @@ struct NewGRFInspectWindow : Window {
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 @@ struct NewGRFInspectWindow : Window {
{
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 @@ static const WindowDesc _newgrf_inspect_desc(
* 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);
}
/**
diff --git a/src/table/newgrf_debug_data.h b/src/table/newgrf_debug_data.h
index 0a5cfb9f0..94e030620 100644
--- a/src/table/newgrf_debug_data.h
+++ b/src/table/newgrf_debug_data.h
@@ -66,6 +66,7 @@ class NIHVehicle : public NIHelper {
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 @@ class NIHStation : public NIHelper {
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 @@ class NIHHouse : public NIHelper {
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 @@ class NIHIndustryTile : public NIHelper {
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 @@ class NIHIndustry : public NIHelper {
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 @@ class NIHObject : public NIHelper {
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 @@ class NIHRailType : public NIHelper {
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 @@ class NIHAirportTile : public NIHelper {
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 @@ class NIHTown : public NIHelper {
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); }
};