summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/message.h
blob: 624d5e00393ddc56f333ca7850911a6739d61239 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/**
 * @file
 * @brief Functions used to print messages.
**/

#ifndef MESSAGE_H
#define MESSAGE_H

#include <string>
#include <streambuf>
#include <iostream>

#include "enum.h"

// Write the message window contents out.
void display_message_window();
void clear_message_window();

void scroll_message_window(int n);

void clear_messages(bool force = false);

void flush_prev_message();

void more(bool user_forced = false);

void canned_msg(canned_message_type which_message);

class formatted_string;

void formatted_mpr(const formatted_string& fs,
                   msg_channel_type channel = MSGCH_PLAIN, int param = 0);

void formatted_message_history(const string &st,
                               msg_channel_type channel = MSGCH_PLAIN,
                               int param = 0,
                               int wrap_col = 0);

// mpr() an arbitrarily long list of strings
void mpr_comma_separated_list(const string &prefix,
                              const vector<string> &list,
                              const string &andc = ", and ",
                              const string &comma = ", ",
                              const msg_channel_type channel = MSGCH_PLAIN,
                              const int param = 0);

#include "cio.h"

// Sets whether messages that are printed through mpr are
// considered temporary.
void msgwin_set_temporary(bool temp);
// Clear the last set of temporary messages from both
// message window and history.
void msgwin_clear_temporary();

void msgwin_prompt(string prompt);
void msgwin_reply(string reply);

unsigned int msgwin_lines();
unsigned int msgwin_line_length();

// Tell the message window that previous messages may be considered
// read, e.g. after reading input from the player.
void msgwin_got_input();

int msgwin_get_line(string prompt,
                    char *buf, int len,
                    input_history *mh = NULL,
                    const string &fill = "");

// Do not use this templated function directly.  Use the macro below instead.
template<int> static int msgwin_get_line_autohist_temp(string prompt,
                                                       char *buf, int len,
                                                       const string &fill = "")
{
    static input_history hist(10);
    return msgwin_get_line(prompt, buf, len, &hist, fill);
}

// This version of mswgin_get_line will automatically retain its own
// input history, independent of other calls to msgwin_get_line.
#define msgwin_get_line_autohist(...) \
    msgwin_get_line_autohist_temp<__LINE__>(__VA_ARGS__)

// Tell the message window that the game is about to read a new
// command from the player.
void msgwin_new_cmd();
// Tell the message window that a new turn has started.
void msgwin_new_turn();

class no_messages
{
public:
    no_messages();
    ~no_messages();
private:
    bool msuppressed;
};

#ifdef USE_TILE_WEB
void webtiles_send_messages();
void webtiles_send_last_messages(int n = 20);
#endif

void save_messages(writer& outf);
void load_messages(reader& inf);
void clear_message_store();

// Have any messages been printed since the last clear?
bool any_messages();

void replay_messages();

void set_more_autoclear(bool on);

string get_last_messages(int mcount, bool full = false);
void get_recent_messages(vector<string> &messages,
                         vector<msg_channel_type> &channels);

int channel_to_colour(msg_channel_type channel, int param = 0);
bool strip_channel_prefix(string &text, msg_channel_type &channel,
                          bool silence = false);

namespace msg
{
    extern ostream stream;
    ostream& streams(msg_channel_type chan = MSGCH_PLAIN);

    struct setparam
    {
        setparam(int param);
        int m_param;
    };

    struct mute
    {
        mute(bool value = true);
        bool m_value;
    };

    class mpr_stream_buf : public streambuf
    {
    public:
        mpr_stream_buf(msg_channel_type chan);
        virtual ~mpr_stream_buf() {}
        void set_param(int p);
        void set_muted(bool m);
    protected:
        int overflow(int c);
    private:
        static const int INTERNAL_LENGTH = 500;
        char internal_buf[500]; // if your terminal is wider than this, too bad
        int internal_count;
        int param;
        bool muted;
        msg_channel_type channel;
    };

    void initialise_mpr_streams();
    void deinitialise_mpr_streams();
}

ostream& operator<<(ostream& os, const msg::setparam& sp);

void set_msg_dump_file(FILE* file);

#endif