annotate src/console_gui.cpp @ 10276:a5286e772120 draft

(svn r14514) -Codechange: use 'size' instead of 'length' for querystring and textbuf, explicitly say it includes the terminating zero -Fix: one couldn't rename things with too long default/automatic name -Fix: buffer overflow in console when too long (1024 bytes) command was entered
author smatz <smatz@openttd.org>
date Wed, 22 Oct 2008 19:12:10 +0000
parents 12805d675e85
children 045c3016adfe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
1 /* $Id$ */
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
2
10238
12805d675e85 (svn r14466) -Doc: remove some obsolete parameters, fix a few parameter names in comments and add a little more doxygen documentation.
rubidium <rubidium@openttd.org>
parents: 10207
diff changeset
3 /** @file console_gui.cpp Handling the GUI of the in-game console. */
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
4
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
5 #include "stdafx.h"
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
6 #include "openttd.h"
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
7 #include "textbuf_gui.h"
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
8 #include "window_gui.h"
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
9 #include "console_gui.h"
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
10 #include <stdarg.h>
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
11 #include <string.h>
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
12 #include "console_internal.h"
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
13 #include "window_func.h"
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
14 #include "string_func.h"
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
15 #include "gfx_func.h"
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
16 #include "core/math_func.hpp"
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
17 #include "settings_type.h"
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
18 #include "rev.h"
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
19
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
20 #include "table/strings.h"
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
21
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
22 enum {
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
23 ICON_HISTORY_SIZE = 20,
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
24 ICON_LINE_HEIGHT = 12,
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
25 ICON_RIGHT_BORDERWIDTH = 10,
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
26 ICON_BOTTOM_BORDERWIDTH = 12,
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
27 };
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
28
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
29 /**
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
30 * Container for a single line of console output
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
31 */
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
32 struct IConsoleLine {
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
33 static IConsoleLine *front; ///< The front of the console backlog buffer
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
34 static int size; ///< The amount of items in the backlog
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
35
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
36 IConsoleLine *previous; ///< The previous console message.
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
37 char *buffer; ///< The data to store.
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
38 uint16 colour; ///< The colour of the line.
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
39 uint16 time; ///< The amount of time the line is in the backlog.
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
40
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
41 /**
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
42 * Initialize the console line.
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
43 * @param buffer the data to print.
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
44 * @param colour the colour of the line.
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
45 */
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
46 IConsoleLine(char *buffer, uint16 colour) :
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
47 previous(IConsoleLine::front),
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
48 buffer(buffer),
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
49 colour(colour),
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
50 time(0)
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
51 {
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
52 IConsoleLine::front = this;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
53 IConsoleLine::size++;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
54 }
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
55
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
56 /**
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
57 * Clear this console line and any further ones.
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
58 */
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
59 ~IConsoleLine()
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
60 {
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
61 IConsoleLine::size--;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
62 free(buffer);
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
63
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
64 delete previous;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
65 }
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
66
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
67 /**
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
68 * Get the index-ed item in the list.
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
69 */
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
70 static const IConsoleLine *Get(uint index)
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
71 {
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
72 const IConsoleLine *item = IConsoleLine::front;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
73 while (index != 0 && item != NULL) {
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
74 index--;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
75 item = item->previous;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
76 }
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
77
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
78 return item;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
79 }
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
80
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
81 /**
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
82 * Truncate the list removing everything older than/more than the amount
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
83 * as specified in the config file.
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
84 * As a side effect also increase the time the other lines have been in
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
85 * the list.
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
86 * @return true if and only if items got removed.
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
87 */
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
88 static bool Truncate()
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
89 {
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
90 IConsoleLine *cur = IConsoleLine::front;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
91 if (cur == NULL) return false;
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
92
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
93 int count = 1;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
94 for (IConsoleLine *item = cur->previous; item != NULL; count++, cur = item, item = item->previous) {
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
95 if (item->time > _settings_client.gui.console_backlog_timeout &&
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
96 count > _settings_client.gui.console_backlog_length) {
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
97 delete item;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
98 cur->previous = NULL;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
99 return true;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
100 }
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
101
9915
f0cea4aa2bf6 (svn r14068) -Fix (r14056): MSVC doesn't support typeof.
rubidium <rubidium@openttd.org>
parents: 9906
diff changeset
102 if (item->time != MAX_UVALUE(uint16)) item->time++;
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
103 }
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
104
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
105 return false;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
106 }
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
107
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
108 /**
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
109 * Reset the complete console line backlog.
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
110 */
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
111 static void Reset()
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
112 {
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
113 delete IConsoleLine::front;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
114 IConsoleLine::front = NULL;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
115 IConsoleLine::size = 0;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
116 }
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
117 };
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
118
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
119 /* static */ IConsoleLine *IConsoleLine::front = NULL;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
120 /* static */ int IConsoleLine::size = 0;
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
121
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
122
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
123 /* ** main console cmd buffer ** */
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
124 static Textbuf _iconsole_cmdline;
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
125 static char *_iconsole_history[ICON_HISTORY_SIZE];
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
126 static byte _iconsole_historypos;
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
127 IConsoleModes _iconsole_mode;
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
128
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
129 /* *************** *
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
130 * end of header *
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
131 * *************** */
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
132
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
133 static void IConsoleClearCommand()
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
134 {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
135 memset(_iconsole_cmdline.buf, 0, ICON_CMDLN_SIZE);
10276
a5286e772120 (svn r14514) -Codechange: use 'size' instead of 'length' for querystring and textbuf, explicitly say it includes the terminating zero
smatz <smatz@openttd.org>
parents: 10238
diff changeset
136 _iconsole_cmdline.size = 1; // only terminating zero
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
137 _iconsole_cmdline.width = 0;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
138 _iconsole_cmdline.caretpos = 0;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
139 _iconsole_cmdline.caretxoffs = 0;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
140 SetWindowDirty(FindWindowById(WC_CONSOLE, 0));
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
141 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
142
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
143 static inline void IConsoleResetHistoryPos() {_iconsole_historypos = ICON_HISTORY_SIZE - 1;}
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
144
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
145
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
146 static void IConsoleHistoryAdd(const char *cmd);
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
147 static void IConsoleHistoryNavigate(int direction);
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
148
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
149 struct IConsoleWindow : Window
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
150 {
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
151 static int scroll;
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
152
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
153 IConsoleWindow(const WindowDesc *desc) : Window(desc)
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
154 {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
155 _iconsole_mode = ICONSOLE_OPENED;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
156 SetBit(_no_scroll, SCROLL_CON); // override cursor arrows; the gamefield will not scroll
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
157
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
158 this->height = _screen.height / 3;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
159 this->width = _screen.width;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
160 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
161
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
162 ~IConsoleWindow()
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
163 {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
164 _iconsole_mode = ICONSOLE_CLOSED;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
165 ClrBit(_no_scroll, SCROLL_CON);
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
166 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
167
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
168 virtual void OnPaint()
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
169 {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
170 int max = (this->height / ICON_LINE_HEIGHT) - 1;
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
171 const IConsoleLine *print = IConsoleLine::Get(IConsoleWindow::scroll);
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
172 GfxFillRect(this->left, this->top, this->width, this->height - 1, 0);
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
173 for (int i = 0; i < max && print != NULL; i++, print = print->previous) {
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
174 DoDrawString(print->buffer, 5,
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
175 this->height - (2 + i) * ICON_LINE_HEIGHT, print->colour);
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
176 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
177 /* If the text is longer than the window, don't show the starting ']' */
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
178 int delta = this->width - 10 - _iconsole_cmdline.width - ICON_RIGHT_BORDERWIDTH;
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
179 if (delta > 0) {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
180 DoDrawString("]", 5, this->height - ICON_LINE_HEIGHT, CC_COMMAND);
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
181 delta = 0;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
182 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
183
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
184 DoDrawString(_iconsole_cmdline.buf, 10 + delta, this->height - ICON_LINE_HEIGHT, CC_COMMAND);
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
185
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
186 if (_iconsole_cmdline.caret) {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
187 DoDrawString("_", 10 + delta + _iconsole_cmdline.caretxoffs, this->height - ICON_LINE_HEIGHT, TC_WHITE);
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
188 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
189 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
190
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
191 virtual void OnHundredthTick()
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
192 {
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
193 if (IConsoleLine::Truncate() &&
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
194 (IConsoleWindow::scroll > IConsoleLine::size)) {
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
195 IConsoleWindow::scroll = max(0, IConsoleLine::size - (this->height / ICON_LINE_HEIGHT) + 1);
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
196 this->SetDirty();
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
197 }
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
198 }
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
199
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
200 virtual void OnMouseLoop()
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
201 {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
202 if (HandleCaret(&_iconsole_cmdline)) this->SetDirty();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
203 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
204
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
205 virtual EventState OnKeyPress(uint16 key, uint16 keycode)
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
206 {
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
207 const int scroll_height = (this->height / ICON_LINE_HEIGHT) - 1;
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
208 switch (keycode) {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
209 case WKC_UP:
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
210 IConsoleHistoryNavigate(+1);
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
211 this->SetDirty();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
212 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
213
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
214 case WKC_DOWN:
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
215 IConsoleHistoryNavigate(-1);
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
216 this->SetDirty();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
217 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
218
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
219 case WKC_SHIFT | WKC_PAGEDOWN:
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
220 if (IConsoleWindow::scroll - scroll_height < 0) {
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
221 IConsoleWindow::scroll = 0;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
222 } else {
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
223 IConsoleWindow::scroll -= scroll_height;
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
224 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
225 this->SetDirty();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
226 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
227
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
228 case WKC_SHIFT | WKC_PAGEUP:
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
229 if (IConsoleWindow::scroll + scroll_height > IConsoleLine::size - scroll_height) {
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
230 IConsoleWindow::scroll = IConsoleLine::size - scroll_height;
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
231 } else {
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
232 IConsoleWindow::scroll += scroll_height;
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
233 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
234 this->SetDirty();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
235 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
236
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
237 case WKC_SHIFT | WKC_DOWN:
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
238 if (IConsoleWindow::scroll <= 0) {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
239 IConsoleWindow::scroll = 0;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
240 } else {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
241 --IConsoleWindow::scroll;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
242 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
243 this->SetDirty();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
244 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
245
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
246 case WKC_SHIFT | WKC_UP:
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
247 if (IConsoleWindow::scroll >= IConsoleLine::size) {
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
248 IConsoleWindow::scroll = IConsoleLine::size;
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
249 } else {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
250 ++IConsoleWindow::scroll;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
251 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
252 this->SetDirty();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
253 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
254
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
255 case WKC_BACKQUOTE:
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
256 IConsoleSwitch();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
257 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
258
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
259 case WKC_RETURN: case WKC_NUM_ENTER:
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
260 IConsolePrintF(CC_COMMAND, "] %s", _iconsole_cmdline.buf);
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
261 IConsoleHistoryAdd(_iconsole_cmdline.buf);
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
262
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
263 IConsoleCmdExec(_iconsole_cmdline.buf);
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
264 IConsoleClearCommand();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
265 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
266
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
267 case WKC_CTRL | WKC_RETURN:
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
268 _iconsole_mode = (_iconsole_mode == ICONSOLE_FULL) ? ICONSOLE_OPENED : ICONSOLE_FULL;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
269 IConsoleResize(this);
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
270 MarkWholeScreenDirty();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
271 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
272
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
273 case (WKC_CTRL | 'V'):
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
274 if (InsertTextBufferClipboard(&_iconsole_cmdline)) {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
275 IConsoleResetHistoryPos();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
276 this->SetDirty();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
277 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
278 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
279
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
280 case (WKC_CTRL | 'L'):
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
281 IConsoleCmdExec("clear");
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
282 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
283
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
284 case (WKC_CTRL | 'U'):
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
285 DeleteTextBufferAll(&_iconsole_cmdline);
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
286 this->SetDirty();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
287 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
288
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
289 case WKC_BACKSPACE: case WKC_DELETE:
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
290 if (DeleteTextBufferChar(&_iconsole_cmdline, keycode)) {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
291 IConsoleResetHistoryPos();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
292 this->SetDirty();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
293 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
294 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
295
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
296 case WKC_LEFT: case WKC_RIGHT: case WKC_END: case WKC_HOME:
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
297 if (MoveTextBufferPos(&_iconsole_cmdline, keycode)) {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
298 IConsoleResetHistoryPos();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
299 this->SetDirty();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
300 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
301 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
302
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
303 default:
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
304 if (IsValidChar(key, CS_ALPHANUMERAL)) {
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
305 IConsoleWindow::scroll = 0;
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
306 InsertTextBufferChar(&_iconsole_cmdline, key);
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
307 IConsoleResetHistoryPos();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
308 this->SetDirty();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
309 } else {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
310 return ES_NOT_HANDLED;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
311 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
312 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
313 return ES_HANDLED;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
314 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
315 };
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
316
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
317 int IConsoleWindow::scroll = 0;
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
318
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
319 static const Widget _iconsole_window_widgets[] = {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
320 {WIDGETS_END}
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
321 };
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
322
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
323 static const WindowDesc _iconsole_window_desc = {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
324 0, 0, 2, 2, 2, 2,
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
325 WC_CONSOLE, WC_NONE,
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
326 WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
327 _iconsole_window_widgets,
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
328 };
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
329
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
330 void IConsoleGUIInit()
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
331 {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
332 _iconsole_historypos = ICON_HISTORY_SIZE - 1;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
333 _iconsole_mode = ICONSOLE_CLOSED;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
334
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
335 IConsoleLine::Reset();
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
336 memset(_iconsole_history, 0, sizeof(_iconsole_history));
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
337
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
338 _iconsole_cmdline.buf = CallocT<char>(ICON_CMDLN_SIZE); // create buffer and zero it
10276
a5286e772120 (svn r14514) -Codechange: use 'size' instead of 'length' for querystring and textbuf, explicitly say it includes the terminating zero
smatz <smatz@openttd.org>
parents: 10238
diff changeset
339 _iconsole_cmdline.maxsize = ICON_CMDLN_SIZE;
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
340
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
341 IConsolePrintF(CC_WARNING, "OpenTTD Game Console Revision 7 - %s", _openttd_revision);
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
342 IConsolePrint(CC_WHITE, "------------------------------------");
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
343 IConsolePrint(CC_WHITE, "use \"help\" for more information");
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
344 IConsolePrint(CC_WHITE, "");
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
345 IConsoleClearCommand();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
346 IConsoleHistoryAdd("");
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
347 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
348
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
349 void IConsoleClearBuffer()
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
350 {
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
351 IConsoleLine::Reset();
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
352 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
353
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
354 void IConsoleGUIFree()
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
355 {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
356 free(_iconsole_cmdline.buf);
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
357 IConsoleClearBuffer();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
358 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
359
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
360 void IConsoleResize(Window *w)
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
361 {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
362 switch (_iconsole_mode) {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
363 case ICONSOLE_OPENED:
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
364 w->height = _screen.height / 3;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
365 w->width = _screen.width;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
366 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
367 case ICONSOLE_FULL:
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
368 w->height = _screen.height - ICON_BOTTOM_BORDERWIDTH;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
369 w->width = _screen.width;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
370 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
371 default: return;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
372 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
373
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
374 MarkWholeScreenDirty();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
375 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
376
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
377 void IConsoleSwitch()
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
378 {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
379 switch (_iconsole_mode) {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
380 case ICONSOLE_CLOSED:
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
381 new IConsoleWindow(&_iconsole_window_desc);
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
382 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
383
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
384 case ICONSOLE_OPENED: case ICONSOLE_FULL:
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
385 DeleteWindowById(WC_CONSOLE, 0);
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
386 break;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
387 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
388
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
389 MarkWholeScreenDirty();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
390 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
391
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
392 void IConsoleClose() {if (_iconsole_mode == ICONSOLE_OPENED) IConsoleSwitch();}
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
393 void IConsoleOpen() {if (_iconsole_mode == ICONSOLE_CLOSED) IConsoleSwitch();}
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
394
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
395 /**
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
396 * Add the entered line into the history so you can look it back
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
397 * scroll, etc. Put it to the beginning as it is the latest text
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
398 * @param cmd Text to be entered into the 'history'
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
399 */
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
400 static void IConsoleHistoryAdd(const char *cmd)
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
401 {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
402 free(_iconsole_history[ICON_HISTORY_SIZE - 1]);
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
403
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
404 memmove(&_iconsole_history[1], &_iconsole_history[0], sizeof(_iconsole_history[0]) * (ICON_HISTORY_SIZE - 1));
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
405 _iconsole_history[0] = strdup(cmd);
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
406 IConsoleResetHistoryPos();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
407 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
408
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
409 /**
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
410 * Navigate Up/Down in the history of typed commands
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
411 * @param direction Go further back in history (+1), go to recently typed commands (-1)
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
412 */
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
413 static void IConsoleHistoryNavigate(int direction)
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
414 {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
415 int i = _iconsole_historypos + direction;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
416
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
417 /* watch out for overflows, just wrap around */
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
418 if (i < 0) i = ICON_HISTORY_SIZE - 1;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
419 if (i >= ICON_HISTORY_SIZE) i = 0;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
420
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
421 if (direction > 0) {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
422 if (_iconsole_history[i] == NULL) i = 0;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
423 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
424
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
425 if (direction < 0) {
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
426 while (i > 0 && _iconsole_history[i] == NULL) i--;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
427 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
428
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
429 _iconsole_historypos = i;
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
430 IConsoleClearCommand();
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
431 /* copy history to 'command prompt / bash' */
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
432 assert(_iconsole_history[i] != NULL && IsInsideMM(i, 0, ICON_HISTORY_SIZE));
10276
a5286e772120 (svn r14514) -Codechange: use 'size' instead of 'length' for querystring and textbuf, explicitly say it includes the terminating zero
smatz <smatz@openttd.org>
parents: 10238
diff changeset
433 ttd_strlcpy(_iconsole_cmdline.buf, _iconsole_history[i], _iconsole_cmdline.maxsize);
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
434 UpdateTextBufferSize(&_iconsole_cmdline);
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
435 }
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
436
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
437 /**
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
438 * Handle the printing of text entered into the console or redirected there
10207
c54d140df948 (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium <rubidium@openttd.org>
parents: 9915
diff changeset
439 * by any other means. Text can be redirected to other clients in a network game
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
440 * as well as to a logfile. If the network server is a dedicated server, all activities
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
441 * are also logged. All lines to print are added to a temporary buffer which can be
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
442 * used as a history to print them onscreen
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
443 * @param color_code the colour of the command. Red in case of errors, etc.
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
444 * @param string the message entered or output on the console (notice, error, etc.)
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
445 */
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
446 void IConsoleGUIPrint(ConsoleColour color_code, char *str)
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
447 {
9906
b5cdbf8eadf3 (svn r14056) -Fix [FS#2192]: the console backlog is too small for list_patches. Now it'll only remove backlog items when there are more than a threshold and when they are there longer than (another) threshold.
rubidium <rubidium@openttd.org>
parents: 9339
diff changeset
448 new IConsoleLine(str, color_code);
9339
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
449 SetWindowDirty(FindWindowById(WC_CONSOLE, 0));
030274da8619 (svn r13231) -Codechange: split the core console code and the console GUI.
rubidium <rubidium@openttd.org>
parents:
diff changeset
450 }