summaryrefslogtreecommitdiff
path: root/src/gui/setup_chat.cpp
blob: 4d9bc98765a29388fc371edccd9b7f857c671208 (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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/*
 *  The Mana World
 *  Copyright (C) 2009  The Mana World Development Team
 *  Copyright (C) 2009-2010  Andrei Karas
 *
 *  This file is part of The Mana World.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "gui/setup_chat.h"
#include "gui/editdialog.h"
#include "gui/chatwindow.h"

#include "gui/widgets/button.h"
#include "gui/widgets/checkbox.h"
#include "gui/widgets/label.h"
#include "gui/widgets/layouthelper.h"
#include "gui/widgets/inttextfield.h"
#include "gui/widgets/chattab.h"

#include "configuration.h"
#include "localplayer.h"
#include "log.h"

#include "utils/gettext.h"

#include "debug.h"

#define ACTION_REMOVE_COLORS "remove colors"
#define ACTION_MAGIC_IN_DEBUG "magic in debug"
#define ACTION_ALLOW_COMMANDS_IN_CHATTABS "allow commands"
#define ACTION_SERVER_MSG_IN_DEBUG "server in debug"
#define ACTION_SHOW_CHAT_COLORS "show chat colors"
#define ACTION_MAX_CHAR_LIMIT "char limit"
#define ACTION_EDIT_CHAR_LIMIT "edit char limit"
#define ACTION_EDIT_CHAR_OK "edit char ok"
#define ACTION_MAX_LINES_LIMIT "lines limit"
#define ACTION_EDIT_LINES_LIMIT "edit lines limit"
#define ACTION_EDIT_LINES_OK "edit lines ok"
#define ACTION_CHAT_LOGGER "chat logger"
#define ACTION_TRADE_TAB "trade tab"
#define ACTION_HIDE_SHOP_MESSAGES "hide shop messages"
#define ACTION_SHOW_CHAT_HISTORY "show chat history"
#define ACTION_ENABLE_BATTLE_TAB "show battle tab"
#define ACTION_SHOW_BATTLE_EVENTS "show battle events"
#define ACTION_RESIZE_CHAT "resize chat"

Setup_Chat::Setup_Chat() :
    mEditDialog(0)
{
    setName(_("Chat"));

    mRemoveColors = config.getBoolValue("removeColors");
    mRemoveColorsCheckBox = new CheckBox(
        _("Remove colors from received chat messages"),
        mRemoveColors, this, ACTION_REMOVE_COLORS);

    mMagicInDebug = config.getBoolValue("showMagicInDebug");
    mMagicInDebugCheckBox = new CheckBox(_("Log magic messages in debug tab"),
        mMagicInDebug, this, ACTION_MAGIC_IN_DEBUG);

    mAllowCommandsInChatTabs = config.getBoolValue(
        "allowCommandsInChatTabs");

    mAllowCommandsInChatTabsCheckBox = new CheckBox(
        _("Allow magic and GM commands in all chat tabs"),
        mAllowCommandsInChatTabs, this, ACTION_ALLOW_COMMANDS_IN_CHATTABS);

    mServerMsgInDebug = config.getBoolValue("serverMsgInDebug");
    mServerMsgInDebugCheckBox = new CheckBox(
        _("Show server messages in debug tab"),
        mServerMsgInDebug, this, ACTION_SERVER_MSG_IN_DEBUG);

    mEnableChatLogger = config.getBoolValue("enableChatLog");
    mEnableChatLoggerCheckBox = new CheckBox(_("Enable chat Log"),
        mEnableChatLogger, this, ACTION_CHAT_LOGGER);

    mEnableTradeTab = config.getBoolValue("enableTradeTab");
    mEnableTradeTabCheckBox = new CheckBox(_("Enable trade tab"),
        mEnableTradeTab, this, ACTION_TRADE_TAB);

    mHideShopMessages = config.getBoolValue("hideShopMessages");
    mHideShopMessagesCheckBox = new CheckBox(_("Hide shop messages"),
        mHideShopMessages, this, ACTION_HIDE_SHOP_MESSAGES);

    mShowChatHistory = config.getBoolValue("showChatHistory");
    mShowChatHistoryCheckBox = new CheckBox(_("Show chat history"),
        mShowChatHistory, this, ACTION_SHOW_CHAT_HISTORY);

    mEnableBattleTab = config.getBoolValue("enableBattleTab");
    mEnableBattleTabCheckBox = new CheckBox(_("Enable battle tab"),
        mEnableBattleTab, this, ACTION_ENABLE_BATTLE_TAB);

    mShowBattleEvents = config.getBoolValue("showBattleEvents");
    mShowBattleEventsCheckBox = new CheckBox(_("Show battle events"),
        mShowBattleEvents, this, ACTION_SHOW_BATTLE_EVENTS);

    mShowChatColors = config.getBoolValue("showChatColorsList");
    mShowChatColorsCheckBox = new CheckBox(_("Show chat colors list"),
        mShowChatColors, this, ACTION_SHOW_CHAT_COLORS);

    mMaxCharButton = new Button(_("Edit"), ACTION_EDIT_CHAR_LIMIT, this);
    int maxCharLimit = config.getIntValue("chatMaxCharLimit");
    mMaxChar = (maxCharLimit != 0);
    mMaxCharCheckBox = new CheckBox(_("Limit max chars in chat line"),
        mMaxChar, this, ACTION_MAX_CHAR_LIMIT);

    mMaxCharField = new IntTextField(maxCharLimit, 0, 500, mMaxChar, 20);

    mMaxLinesButton = new Button(_("Edit"), ACTION_EDIT_LINES_LIMIT, this);
    int maxLinesLimit = config.getIntValue("chatMaxLinesLimit");
    mMaxLines = (maxLinesLimit != 0);

    mMaxLinesCheckBox = new CheckBox(_("Limit max lines in chat"),
                                     mMaxLines,
                                     this, ACTION_MAX_LINES_LIMIT);

    mMaxLinesField = new IntTextField(maxLinesLimit, 0, 500, mMaxLines, 20);

    mHideChatInput = config.getBoolValue("hideChatInput");
    mHideChatInputCheckBox = new CheckBox(_("Resize chat tabs if need"),
        mHideChatInput, this, ACTION_RESIZE_CHAT);

    // Do the layout
    LayoutHelper h(this);
    ContainerPlacer place = h.getPlacer(0, 0);

    place(0, 0, mRemoveColorsCheckBox, 10);
    place(0, 1, mMagicInDebugCheckBox, 10);
    place(0, 2, mAllowCommandsInChatTabsCheckBox, 10);
    place(0, 3, mServerMsgInDebugCheckBox, 10);
    place(0, 4, mShowChatColorsCheckBox, 10);
    place(0, 5, mMaxCharCheckBox, 6);
    place(6, 5, mMaxCharField, 2);
    place(8, 5, mMaxCharButton, 2);
    place(0, 6, mEnableChatLoggerCheckBox, 10);
    place(0, 7, mMaxLinesCheckBox, 6);
    place(6, 7, mMaxLinesField, 2);
    place(8, 7, mMaxLinesButton, 2);
    place(0, 8, mEnableTradeTabCheckBox, 10);
    place(0, 9, mHideShopMessagesCheckBox, 10);
    place(0, 10, mShowChatHistoryCheckBox, 10);
    place(0, 11, mEnableBattleTabCheckBox, 10);
    place(0, 12, mShowBattleEventsCheckBox, 10);
    place(0, 13, mHideChatInputCheckBox, 10);

    place.getCell().matchColWidth(0, 0);
    place = h.getPlacer(0, 1);

    setDimension(gcn::Rectangle(0, 0, 500, 500));
}

void Setup_Chat::action(const gcn::ActionEvent &event)
{
    if (event.getId() == ACTION_REMOVE_COLORS)
    {
        mRemoveColors = mRemoveColorsCheckBox->isSelected();
    }
    else if (event.getId() == ACTION_MAGIC_IN_DEBUG)
    {
        mMagicInDebug = mMagicInDebugCheckBox->isSelected();
    }
    else if (event.getId() == ACTION_ALLOW_COMMANDS_IN_CHATTABS)
    {
        mAllowCommandsInChatTabs
            = mAllowCommandsInChatTabsCheckBox->isSelected();
    }
    else if (event.getId() == ACTION_SERVER_MSG_IN_DEBUG)
    {
        mServerMsgInDebug = mServerMsgInDebugCheckBox->isSelected();
    }
    else if (event.getId() == ACTION_SHOW_CHAT_COLORS)
    {
        mShowChatColors = mShowChatColorsCheckBox->isSelected();
    }
    else if (event.getId() == ACTION_MAX_CHAR_LIMIT)
    {
        mMaxChar = mMaxCharCheckBox->isSelected();
    }
    else if (event.getId() == ACTION_EDIT_CHAR_LIMIT)
    {
        mEditDialog =  new EditDialog("Limit max chars in chat line",
                                      toString(mMaxCharField->getValue()),
                                      ACTION_EDIT_CHAR_OK);
        mEditDialog->addActionListener(this);
    }
    else if (event.getId() == ACTION_EDIT_CHAR_OK)
    {
        mMaxCharField->setValue(atoi(mEditDialog->getMsg().c_str()));
    }
    else if (event.getId() == ACTION_MAX_LINES_LIMIT)
    {
        mMaxLines = mMaxLinesCheckBox->isSelected();
    }
    else if (event.getId() == ACTION_EDIT_LINES_LIMIT)
    {
        mEditDialog =  new EditDialog("Limit max lines in chat",
                                      toString(mMaxLinesField->getValue()),
                                      ACTION_EDIT_LINES_OK);
        mEditDialog->addActionListener(this);
    }
    else if (event.getId() == ACTION_EDIT_LINES_OK)
    {
        mMaxLinesField->setValue(atoi(mEditDialog->getMsg().c_str()));
    }
    else if (event.getId() == ACTION_CHAT_LOGGER)
    {
        mEnableChatLogger = mEnableChatLoggerCheckBox->isSelected();
    }
    else if (event.getId() == ACTION_TRADE_TAB)
    {
        mEnableTradeTab = mEnableTradeTabCheckBox->isSelected();
    }
    else if (event.getId() == ACTION_HIDE_SHOP_MESSAGES)
    {
        mHideShopMessages = mHideShopMessagesCheckBox->isSelected();
    }
    else if (event.getId() == ACTION_SHOW_CHAT_HISTORY)
    {
        mShowChatHistory = mShowChatHistoryCheckBox->isSelected();
    }
    else if (event.getId() == ACTION_ENABLE_BATTLE_TAB)
    {
        mEnableBattleTab = mEnableBattleTabCheckBox->isSelected();
    }
    else if (event.getId() == ACTION_SHOW_BATTLE_EVENTS)
    {
        mShowBattleEvents = mShowBattleEventsCheckBox->isSelected();
    }
    else if (event.getId() == ACTION_RESIZE_CHAT)
    {
        mHideChatInput = mHideChatInputCheckBox->isSelected();
    }
}

void Setup_Chat::cancel()
{
    mRemoveColors = config.getBoolValue("removeColors");
    mRemoveColorsCheckBox->setSelected(mRemoveColors);

    mMagicInDebug = config.getBoolValue("showMagicInDebug");
    mMagicInDebugCheckBox->setSelected(mMagicInDebug);

    mAllowCommandsInChatTabs
        = config.getBoolValue("allowCommandsInChatTabs");
    mAllowCommandsInChatTabsCheckBox->setSelected(mAllowCommandsInChatTabs);

    mServerMsgInDebug = config.getBoolValue("serverMsgInDebug");
    mServerMsgInDebugCheckBox->setSelected(mServerMsgInDebug);

    mShowChatColors = config.getBoolValue("showChatColorsList");
    mShowChatColorsCheckBox->setSelected(mShowChatColors);

    int maxCharLimit = config.getIntValue("chatMaxCharLimit");
    mMaxChar = (maxCharLimit != 0);
    mMaxCharCheckBox->setSelected(mMaxChar);
    mMaxCharField->setValue(maxCharLimit);
    mMaxCharField->setEnabled(mMaxChar);

    int maxLinesLimit = config.getIntValue("chatMaxLinesLimit");
    mMaxLines = (maxLinesLimit != 0);
    mMaxLinesCheckBox->setSelected(mMaxLines);
    mMaxLinesField->setValue(maxLinesLimit);
    mMaxLinesField->setEnabled(mMaxLines);

    mEnableChatLogger = config.getBoolValue("enableChatLog");
    mEnableChatLoggerCheckBox->setSelected(mEnableChatLogger);

    mEnableTradeTab = config.getBoolValue("enableTradeTab");
    mEnableTradeTabCheckBox->setSelected(mEnableTradeTab);

    mHideShopMessages = config.getBoolValue("hideShopMessages");
    mHideShopMessagesCheckBox->setSelected(mHideShopMessages);

    mShowChatHistory = config.getBoolValue("showChatHistory");
    mShowChatHistoryCheckBox->setSelected(mShowChatHistory);

    mEnableBattleTab = config.getBoolValue("enableBattleTab");
    mEnableBattleTabCheckBox->setSelected(mEnableBattleTab);

    mShowBattleEvents = config.getBoolValue("showBattleEvents");
    mShowBattleEventsCheckBox->setSelected(mShowBattleEvents);

    mHideChatInput = config.getBoolValue("hideChatInput");
    mHideChatInputCheckBox->setSelected(mHideChatInput);
}

void Setup_Chat::apply()
{
    config.setValue("removeColors", mRemoveColors);
    config.setValue("showMagicInDebug", mMagicInDebug);
    config.setValue("allowCommandsInChatTabs", mAllowCommandsInChatTabs);
    config.setValue("serverMsgInDebug", mServerMsgInDebug);
    config.setValue("showChatColorsList", mShowChatColors);
    if (mMaxChar)
        config.setValue("chatMaxCharLimit", mMaxCharField->getValue());
    else
        config.setValue("chatMaxCharLimit", 0);
    if (mMaxLines)
        config.setValue("chatMaxLinesLimit", mMaxLinesField->getValue());
    else
        config.setValue("chatMaxLinesLimit", 0);
    config.setValue("enableChatLog", mEnableChatLogger);
    config.setValue("enableTradeTab", mEnableTradeTab);
    config.setValue("hideShopMessages", mHideShopMessages);
    config.setValue("showChatHistory", mShowChatHistory);
    config.setValue("enableBattleTab", mEnableBattleTab);
    config.setValue("showBattleEvents", mShowBattleEvents);

    config.setValue("hideChatInput", mHideChatInput);
    if (chatWindow)
        chatWindow->adjustTabSize();
}