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

pull/59/head
Jonathan G Rennison 6 years ago
parent 943f4fdabb
commit a8cfc9fe90

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

@ -82,6 +82,19 @@ class NIHVehicle : public NIHelper {
VehicleResolverObject ro(v->engine_type, v, VehicleResolverObject::WO_CACHED);
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 = {

Loading…
Cancel
Save