mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Chat console, including a number of rebases and modifications.
Defaults modified from original: alpha=200, key=F10
This commit is contained in:
parent
0053651814
commit
967f25461b
17 changed files with 1941 additions and 146 deletions
149
src/game.cpp
149
src/game.cpp
|
@ -32,6 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "guiTextInputMenu.h"
|
||||
#include "guiDeathScreen.h"
|
||||
#include "tool.h"
|
||||
#include "guiChatConsole.h"
|
||||
#include "config.h"
|
||||
#include "clouds.h"
|
||||
#include "camera.h"
|
||||
|
@ -62,22 +63,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#define FIELD_OF_VIEW_TEST 0
|
||||
|
||||
|
||||
// Chat data
|
||||
struct ChatLine
|
||||
{
|
||||
ChatLine():
|
||||
age(0.0)
|
||||
{
|
||||
}
|
||||
ChatLine(const std::wstring &a_text):
|
||||
age(0.0),
|
||||
text(a_text)
|
||||
{
|
||||
}
|
||||
float age;
|
||||
std::wstring text;
|
||||
};
|
||||
|
||||
/*
|
||||
Text input system
|
||||
*/
|
||||
|
@ -90,14 +75,7 @@ struct TextDestChat : public TextDest
|
|||
}
|
||||
void gotText(std::wstring text)
|
||||
{
|
||||
// Discard empty line
|
||||
if(text == L"")
|
||||
return;
|
||||
|
||||
// Send to others
|
||||
m_client->sendChatMessage(text);
|
||||
// Show locally
|
||||
m_client->addChatMessage(text);
|
||||
m_client->typeChatMessage(text);
|
||||
}
|
||||
|
||||
Client *m_client;
|
||||
|
@ -676,7 +654,8 @@ void the_game(
|
|||
std::string address,
|
||||
u16 port,
|
||||
std::wstring &error_message,
|
||||
std::string configpath
|
||||
std::string configpath,
|
||||
ChatBackend &chat_backend
|
||||
)
|
||||
{
|
||||
video::IVideoDriver* driver = device->getVideoDriver();
|
||||
|
@ -978,8 +957,10 @@ void the_game(
|
|||
core::rect<s32>(0,0,0,0),
|
||||
//false, false); // Disable word wrap as of now
|
||||
false, true);
|
||||
//guitext_chat->setBackgroundColor(video::SColor(96,0,0,0));
|
||||
core::list<ChatLine> chat_lines;
|
||||
// Remove stale "recent" chat messages from previous connections
|
||||
chat_backend.clearRecentChat();
|
||||
// Chat backend and console
|
||||
GUIChatConsole *gui_chat_console = new GUIChatConsole(guienv, guienv->getRootGUIElement(), -1, &chat_backend, &client);
|
||||
|
||||
// Profiler text (size is updated when text is updated)
|
||||
gui::IGUIStaticText *guitext_profiler = guienv->addStaticText(
|
||||
|
@ -1299,7 +1280,9 @@ void the_game(
|
|||
*/
|
||||
|
||||
// Reset input if window not active or some menu is active
|
||||
if(device->isWindowActive() == false || noMenuActive() == false)
|
||||
if(device->isWindowActive() == false
|
||||
|| noMenuActive() == false
|
||||
|| guienv->hasFocus(gui_chat_console))
|
||||
{
|
||||
input->clear();
|
||||
}
|
||||
|
@ -1375,6 +1358,15 @@ void the_game(
|
|||
&g_menumgr, dest,
|
||||
L"/"))->drop();
|
||||
}
|
||||
else if(input->wasKeyDown(getKeySetting("keymap_console")))
|
||||
{
|
||||
if (!gui_chat_console->isOpenInhibited())
|
||||
{
|
||||
// Open up to over half of the screen
|
||||
gui_chat_console->openConsole(0.6);
|
||||
guienv->setFocus(gui_chat_console);
|
||||
}
|
||||
}
|
||||
else if(input->wasKeyDown(getKeySetting("keymap_freemove")))
|
||||
{
|
||||
if(g_settings->getBool("free_move"))
|
||||
|
@ -1655,23 +1647,6 @@ void the_game(
|
|||
/*
|
||||
Player speed control
|
||||
*/
|
||||
|
||||
if(!noMenuActive() || !device->isWindowActive())
|
||||
{
|
||||
PlayerControl control(
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
camera_pitch,
|
||||
camera_yaw
|
||||
);
|
||||
client.setPlayerControl(control);
|
||||
}
|
||||
else
|
||||
{
|
||||
/*bool a_up,
|
||||
bool a_down,
|
||||
|
@ -1758,6 +1733,8 @@ void the_game(
|
|||
&g_menumgr, respawner);
|
||||
menu->drop();
|
||||
|
||||
chat_backend.addMessage(L"", L"You died.");
|
||||
|
||||
/* Handle visualization */
|
||||
|
||||
damage_flash_timer = 0;
|
||||
|
@ -2357,83 +2334,38 @@ void the_game(
|
|||
// Get new messages from error log buffer
|
||||
while(!chat_log_error_buf.empty())
|
||||
{
|
||||
chat_lines.push_back(ChatLine(narrow_to_wide(
|
||||
chat_log_error_buf.get())));
|
||||
chat_backend.addMessage(L"", narrow_to_wide(
|
||||
chat_log_error_buf.get()));
|
||||
}
|
||||
// Get new messages from client
|
||||
std::wstring message;
|
||||
while(client.getChatMessage(message))
|
||||
{
|
||||
chat_lines.push_back(ChatLine(message));
|
||||
/*if(chat_lines.size() > 6)
|
||||
{
|
||||
core::list<ChatLine>::Iterator
|
||||
i = chat_lines.begin();
|
||||
chat_lines.erase(i);
|
||||
}*/
|
||||
chat_backend.addUnparsedMessage(message);
|
||||
}
|
||||
// Append them to form the whole static text and throw
|
||||
// it to the gui element
|
||||
std::wstring whole;
|
||||
// This will correspond to the line number counted from
|
||||
// top to bottom, from size-1 to 0
|
||||
s16 line_number = chat_lines.size();
|
||||
// Count of messages to be removed from the top
|
||||
u16 to_be_removed_count = 0;
|
||||
for(core::list<ChatLine>::Iterator
|
||||
i = chat_lines.begin();
|
||||
i != chat_lines.end(); i++)
|
||||
{
|
||||
// After this, line number is valid for this loop
|
||||
line_number--;
|
||||
// Increment age
|
||||
(*i).age += dtime;
|
||||
/*
|
||||
This results in a maximum age of 60*6 to the
|
||||
lowermost line and a maximum of 6 lines
|
||||
*/
|
||||
float allowed_age = (6-line_number) * 60.0;
|
||||
// Remove old messages
|
||||
chat_backend.step(dtime);
|
||||
|
||||
if((*i).age > allowed_age)
|
||||
{
|
||||
to_be_removed_count++;
|
||||
continue;
|
||||
}
|
||||
whole += (*i).text + L'\n';
|
||||
}
|
||||
for(u16 i=0; i<to_be_removed_count; i++)
|
||||
{
|
||||
core::list<ChatLine>::Iterator
|
||||
it = chat_lines.begin();
|
||||
chat_lines.erase(it);
|
||||
}
|
||||
guitext_chat->setText(whole.c_str());
|
||||
// Display all messages in a static text element
|
||||
u32 recent_chat_count = chat_backend.getRecentBuffer().getLineCount();
|
||||
std::wstring recent_chat = chat_backend.getRecentChat();
|
||||
guitext_chat->setText(recent_chat.c_str());
|
||||
|
||||
// Update gui element size and position
|
||||
|
||||
/*core::rect<s32> rect(
|
||||
10,
|
||||
screensize.Y - guitext_chat_pad_bottom
|
||||
- text_height*chat_lines.size(),
|
||||
screensize.X - 10,
|
||||
screensize.Y - guitext_chat_pad_bottom
|
||||
);*/
|
||||
|
||||
s32 chat_y = 5+(text_height+5);
|
||||
if(show_debug)
|
||||
chat_y += (text_height+5);
|
||||
core::rect<s32> rect(
|
||||
10,
|
||||
chat_y,
|
||||
screensize.X - 10,
|
||||
chat_y + guitext_chat->getTextHeight()
|
||||
10,
|
||||
chat_y,
|
||||
screensize.X - 10,
|
||||
chat_y + guitext_chat->getTextHeight()
|
||||
);
|
||||
|
||||
guitext_chat->setRelativePosition(rect);
|
||||
|
||||
// Don't show chat if empty or profiler or debug is enabled
|
||||
guitext_chat->setVisible(chat_lines.size() != 0
|
||||
&& show_chat && show_profiler == 0);
|
||||
// Don't show chat if disabled or empty or profiler is enabled
|
||||
guitext_chat->setVisible(show_chat && recent_chat_count != 0
|
||||
&& !show_profiler);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -2634,6 +2566,8 @@ void the_game(
|
|||
*/
|
||||
if(clouds)
|
||||
clouds->drop();
|
||||
if(gui_chat_console)
|
||||
gui_chat_console->drop();
|
||||
|
||||
/*
|
||||
Draw a "shutting down" screen, which will be shown while the map
|
||||
|
@ -2648,6 +2582,9 @@ void the_game(
|
|||
gui_shuttingdowntext->remove();*/
|
||||
}
|
||||
|
||||
chat_backend.addMessage(L"", L"# Disconnected.");
|
||||
chat_backend.addMessage(L"", L"");
|
||||
|
||||
} // Client scope (must be destructed before destructing *def and tsrc
|
||||
|
||||
delete tsrc;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue