mirror of https://github.com/OpenTTD/OpenTTD
(svn r16091) -Change [FS#2778]: Reverse the order of the lines in the AI debug window
parent
713da56d9b
commit
3e2e5b097c
|
@ -629,6 +629,8 @@ enum AIDebugWindowWidgets {
|
||||||
struct AIDebugWindow : public Window {
|
struct AIDebugWindow : public Window {
|
||||||
static CompanyID ai_debug_company;
|
static CompanyID ai_debug_company;
|
||||||
int redraw_timer;
|
int redraw_timer;
|
||||||
|
int last_vscroll_pos;
|
||||||
|
bool autoscroll;
|
||||||
|
|
||||||
AIDebugWindow(const WindowDesc *desc, WindowNumber number) : Window(desc, number)
|
AIDebugWindow(const WindowDesc *desc, WindowNumber number) : Window(desc, number)
|
||||||
{
|
{
|
||||||
|
@ -641,6 +643,8 @@ struct AIDebugWindow : public Window {
|
||||||
this->vscroll.cap = 14;
|
this->vscroll.cap = 14;
|
||||||
this->vscroll.pos = 0;
|
this->vscroll.pos = 0;
|
||||||
this->resize.step_height = 12;
|
this->resize.step_height = 12;
|
||||||
|
this->last_vscroll_pos = 0;
|
||||||
|
this->autoscroll = true;
|
||||||
|
|
||||||
if (ai_debug_company != INVALID_COMPANY) this->LowerWidget(ai_debug_company + AID_WIDGET_COMPANY_BUTTON_START);
|
if (ai_debug_company != INVALID_COMPANY) this->LowerWidget(ai_debug_company + AID_WIDGET_COMPANY_BUTTON_START);
|
||||||
|
|
||||||
|
@ -722,9 +726,17 @@ struct AIDebugWindow : public Window {
|
||||||
this->InvalidateWidget(AID_WIDGET_SCROLLBAR);
|
this->InvalidateWidget(AID_WIDGET_SCROLLBAR);
|
||||||
if (log == NULL) return;
|
if (log == NULL) return;
|
||||||
|
|
||||||
|
/* Detect when the user scrolls the window. Enable autoscroll when the
|
||||||
|
* bottom-most line becomes visible. */
|
||||||
|
if (this->last_vscroll_pos != this->vscroll.pos) {
|
||||||
|
this->autoscroll = this->vscroll.pos >= log->used - this->vscroll.cap;
|
||||||
|
}
|
||||||
|
if (this->autoscroll) this->vscroll.pos = max(0, log->used - this->vscroll.cap);
|
||||||
|
last_vscroll_pos = this->vscroll.pos;
|
||||||
|
|
||||||
int y = 6;
|
int y = 6;
|
||||||
for (int i = this->vscroll.pos; i < (this->vscroll.cap + this->vscroll.pos); i++) {
|
for (int i = this->vscroll.pos; i < (this->vscroll.cap + this->vscroll.pos) && i < log->used; i++) {
|
||||||
uint pos = (log->count + log->pos - i) % log->count;
|
uint pos = (i + log->pos + 1 - log->used + log->count) % log->count;
|
||||||
if (log->lines[pos] == NULL) break;
|
if (log->lines[pos] == NULL) break;
|
||||||
|
|
||||||
TextColour colour;
|
TextColour colour;
|
||||||
|
@ -747,6 +759,8 @@ struct AIDebugWindow : public Window {
|
||||||
this->RaiseWidget(ai_debug_company + AID_WIDGET_COMPANY_BUTTON_START);
|
this->RaiseWidget(ai_debug_company + AID_WIDGET_COMPANY_BUTTON_START);
|
||||||
ai_debug_company = show_ai;
|
ai_debug_company = show_ai;
|
||||||
this->LowerWidget(ai_debug_company + AID_WIDGET_COMPANY_BUTTON_START);
|
this->LowerWidget(ai_debug_company + AID_WIDGET_COMPANY_BUTTON_START);
|
||||||
|
this->autoscroll = true;
|
||||||
|
this->last_vscroll_pos = this->vscroll.pos;
|
||||||
this->SetDirty();
|
this->SetDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
log->lines = CallocT<char *>(80);
|
log->lines = CallocT<char *>(80);
|
||||||
log->type = CallocT<AILog::AILogType>(80);
|
log->type = CallocT<AILog::AILogType>(80);
|
||||||
log->count = 80;
|
log->count = 80;
|
||||||
log->pos = log->count;
|
log->pos = log->count - 1;
|
||||||
log->used = 0;
|
log->used = 0;
|
||||||
}
|
}
|
||||||
LogData *log = (LogData *)AIObject::GetLogPointer();
|
LogData *log = (LogData *)AIObject::GetLogPointer();
|
||||||
|
|
Loading…
Reference in New Issue