Skip to content

Commit 7940a42

Browse files
sapiersapier
sapier
authored and
sapier
committedAug 22, 2014
Fix chat messages capturing mouse interactions for menu/formspecs
1 parent 55c646c commit 7940a42

File tree

1 file changed

+61
-46
lines changed

1 file changed

+61
-46
lines changed
 

‎src/game.cpp

+61-46
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,52 @@ static void show_pause_menu(GUIFormSpecMenu** cur_formspec,
10631063
(*cur_formspec)->doPause = true;
10641064
}
10651065

1066+
/******************************************************************************/
1067+
static void updateChat(Client& client, f32 dtime, bool show_debug,
1068+
const v2u32& screensize, bool show_chat, u32 show_profiler,
1069+
ChatBackend& chat_backend, gui::IGUIStaticText* guitext_chat,
1070+
gui::IGUIFont* font)
1071+
{
1072+
// Add chat log output for errors to be shown in chat
1073+
static LogOutputBuffer chat_log_error_buf(LMT_ERROR);
1074+
1075+
// Get new messages from error log buffer
1076+
while(!chat_log_error_buf.empty()) {
1077+
chat_backend.addMessage(L"", narrow_to_wide(chat_log_error_buf.get()));
1078+
}
1079+
1080+
// Get new messages from client
1081+
std::wstring message;
1082+
while (client.getChatMessage(message)) {
1083+
chat_backend.addUnparsedMessage(message);
1084+
}
1085+
1086+
// Remove old messages
1087+
chat_backend.step(dtime);
1088+
1089+
// Display all messages in a static text element
1090+
unsigned int recent_chat_count = chat_backend.getRecentBuffer().getLineCount();
1091+
std::wstring recent_chat = chat_backend.getRecentChat();
1092+
1093+
// TODO replace by fontengine fcts
1094+
unsigned int line_height = font->getDimension(L"Ay").Height + font->getKerningHeight();
1095+
1096+
guitext_chat->setText(recent_chat.c_str());
1097+
1098+
// Update gui element size and position
1099+
s32 chat_y = 5 + line_height;
1100+
if (show_debug)
1101+
chat_y += line_height;
1102+
1103+
core::rect<s32> rect(10, chat_y, font->getDimension(recent_chat.c_str()).Width +10,
1104+
chat_y + (recent_chat_count * line_height));
1105+
1106+
guitext_chat->setRelativePosition(rect);
1107+
// Don't show chat if disabled or empty or profiler is enabled
1108+
guitext_chat->setVisible(
1109+
show_chat && recent_chat_count != 0 && !show_profiler);
1110+
}
1111+
10661112
/******************************************************************************/
10671113
void the_game(bool &kill, bool random_input, InputHandler *input,
10681114
IrrlichtDevice *device, gui::IGUIFont* font, std::string map_dir,
@@ -1133,9 +1179,6 @@ void the_game(bool &kill, bool random_input, InputHandler *input,
11331179
SoundMaker soundmaker(sound, nodedef);
11341180
soundmaker.registerReceiver(&eventmgr);
11351181

1136-
// Add chat log output for errors to be shown in chat
1137-
LogOutputBuffer chat_log_error_buf(LMT_ERROR);
1138-
11391182
// Create UI for modifying quicktune values
11401183
QuicktuneShortcutter quicktune;
11411184

@@ -1527,24 +1570,24 @@ void the_game(bool &kill, bool random_input, InputHandler *input,
15271570
gui::IGUIStaticText *guitext = guienv->addStaticText(
15281571
L"Minetest",
15291572
core::rect<s32>(0, 0, 0, 0),
1530-
false, false);
1573+
false, false, guiroot);
15311574
// Second line of debug text
15321575
gui::IGUIStaticText *guitext2 = guienv->addStaticText(
15331576
L"",
15341577
core::rect<s32>(0, 0, 0, 0),
1535-
false, false);
1578+
false, false, guiroot);
15361579
// At the middle of the screen
15371580
// Object infos are shown in this
15381581
gui::IGUIStaticText *guitext_info = guienv->addStaticText(
15391582
L"",
15401583
core::rect<s32>(0,0,400,text_height*5+5) + v2s32(100,200),
1541-
false, true);
1584+
false, true, guiroot);
15421585

15431586
// Status text (displays info when showing and hiding GUI stuff, etc.)
15441587
gui::IGUIStaticText *guitext_status = guienv->addStaticText(
15451588
L"<Status>",
15461589
core::rect<s32>(0,0,0,0),
1547-
false, false);
1590+
false, false, guiroot);
15481591
guitext_status->setVisible(false);
15491592

15501593
std::wstring statustext;
@@ -1555,7 +1598,7 @@ void the_game(bool &kill, bool random_input, InputHandler *input,
15551598
L"",
15561599
core::rect<s32>(0,0,0,0),
15571600
//false, false); // Disable word wrap as of now
1558-
false, true);
1601+
false, true, guiroot);
15591602
// Remove stale "recent" chat messages from previous connections
15601603
chat_backend.clearRecentChat();
15611604
// Chat backend and console
@@ -1565,7 +1608,7 @@ void the_game(bool &kill, bool random_input, InputHandler *input,
15651608
gui::IGUIStaticText *guitext_profiler = guienv->addStaticText(
15661609
L"<Profiler>",
15671610
core::rect<s32>(0,0,0,0),
1568-
false, false);
1611+
false, false, guiroot);
15691612
guitext_profiler->setBackgroundColor(video::SColor(120,0,0,0));
15701613
guitext_profiler->setVisible(false);
15711614
guitext_profiler->setWordWrap(true);
@@ -3311,43 +3354,8 @@ void the_game(bool &kill, bool random_input, InputHandler *input,
33113354
/*
33123355
Get chat messages from client
33133356
*/
3314-
{
3315-
// Get new messages from error log buffer
3316-
while(!chat_log_error_buf.empty())
3317-
{
3318-
chat_backend.addMessage(L"", narrow_to_wide(
3319-
chat_log_error_buf.get()));
3320-
}
3321-
// Get new messages from client
3322-
std::wstring message;
3323-
while(client.getChatMessage(message))
3324-
{
3325-
chat_backend.addUnparsedMessage(message);
3326-
}
3327-
// Remove old messages
3328-
chat_backend.step(dtime);
3329-
3330-
// Display all messages in a static text element
3331-
u32 recent_chat_count = chat_backend.getRecentBuffer().getLineCount();
3332-
std::wstring recent_chat = chat_backend.getRecentChat();
3333-
guitext_chat->setText(recent_chat.c_str());
3334-
3335-
// Update gui element size and position
3336-
s32 chat_y = 5+(text_height+5);
3337-
if(show_debug)
3338-
chat_y += (text_height+5);
3339-
core::rect<s32> rect(
3340-
10,
3341-
chat_y,
3342-
screensize.X - 10,
3343-
chat_y + guitext_chat->getTextHeight()
3344-
);
3345-
guitext_chat->setRelativePosition(rect);
3346-
3347-
// Don't show chat if disabled or empty or profiler is enabled
3348-
guitext_chat->setVisible(show_chat && recent_chat_count != 0
3349-
&& !show_profiler);
3350-
}
3357+
updateChat(client, dtime, show_debug, screensize, show_chat,
3358+
show_profiler, chat_backend, guitext_chat, font);
33513359

33523360
/*
33533361
Inventory
@@ -3388,6 +3396,13 @@ void the_game(bool &kill, bool random_input, InputHandler *input,
33883396
update_draw_list_last_cam_dir = camera_direction;
33893397
}
33903398

3399+
/*
3400+
make sure menu is on top
3401+
*/
3402+
if ((!noMenuActive()) && (current_formspec)) {
3403+
guiroot->bringToFront(current_formspec);
3404+
}
3405+
33913406
/*
33923407
Drawing begins
33933408
*/

0 commit comments

Comments
 (0)
Please sign in to comment.