Debug: Add vehicle index and flag dump to NewGRF debug window

This commit is contained in:
Jonathan G Rennison
2018-06-05 19:09:03 +01:00
parent 943f4fdabb
commit a8cfc9fe90
2 changed files with 31 additions and 0 deletions

View File

@@ -11,6 +11,7 @@
#include "stdafx.h" #include "stdafx.h"
#include <stdarg.h> #include <stdarg.h>
#include <functional>
#include "window_gui.h" #include "window_gui.h"
#include "window_func.h" #include "window_func.h"
#include "fileio_func.h" #include "fileio_func.h"
@@ -199,6 +200,8 @@ public:
return NULL; return NULL;
} }
virtual void ExtraInfo(uint index, std::function<void(const char *)> print) const {}
protected: protected:
/** /**
* Helper to make setting the strings easier. * Helper to make setting the strings easier.
@@ -292,6 +295,8 @@ struct NewGRFInspectWindow : Window {
Scrollbar *vscroll; Scrollbar *vscroll;
int first_variable_line_index = 0;
/** /**
* Check whether the given variable has a parameter. * Check whether the given variable has a parameter.
* @param variable the variable to check. * @param variable the variable to check.
@@ -459,6 +464,17 @@ struct NewGRFInspectWindow : Window {
const void *base_spec = nih->GetSpec(index); const void *base_spec = nih->GetSpec(index);
uint i = 0; uint i = 0;
nih->ExtraInfo(index, [&](const char *buf) {
int offset = i++;
offset -= this->vscroll->GetPosition();
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);
});
const_cast<NewGRFInspectWindow*>(this)->first_variable_line_index = i;
if (nif->variables != NULL) { if (nif->variables != NULL) {
this->DrawString(r, i++, "Variables:"); this->DrawString(r, i++, "Variables:");
for (const NIVariable *niv = nif->variables; niv->name != NULL; niv++) { for (const NIVariable *niv = nif->variables; niv->name != NULL; niv++) {
@@ -586,6 +602,8 @@ struct NewGRFInspectWindow : Window {
/* Get the line, make sure it's within the boundaries. */ /* Get the line, make sure it's within the boundaries. */
int line = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NGRFI_MAINPANEL, TOP_OFFSET); int line = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_NGRFI_MAINPANEL, TOP_OFFSET);
if (line == INT_MAX) return; if (line == INT_MAX) return;
if (line < this->first_variable_line_index) return;
line -= this->first_variable_line_index;
/* Find the variable related to the line */ /* Find the variable related to the line */
for (const NIVariable *niv = nif->variables; niv->name != NULL; niv++, line--) { for (const NIVariable *niv = nif->variables; niv->name != NULL; niv++, line--) {

View File

@@ -82,6 +82,19 @@ class NIHVehicle : public NIHelper {
VehicleResolverObject ro(v->engine_type, v, VehicleResolverObject::WO_CACHED); VehicleResolverObject ro(v->engine_type, v, VehicleResolverObject::WO_CACHED);
return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail); return ro.GetScope(VSG_SCOPE_SELF)->GetVariable(var, param, avail);
} }
/* virtual */ void ExtraInfo(uint index, std::function<void(const char *)> print) const
{
char buffer[1024];
Vehicle *v = Vehicle::Get(index);
print("Debug Info:");
seprintf(buffer, lastof(buffer), " Index: %u", index);
print(buffer);
char *b = buffer;
b += seprintf(b, lastof(buffer), " Flags: ");
b = v->DumpVehicleFlags(b, lastof(buffer));
print(buffer);
}
}; };
static const NIFeature _nif_vehicle = { static const NIFeature _nif_vehicle = {