parent
5e136419fe
commit
8a00276913
9 changed files with 90 additions and 14 deletions
|
@ -739,6 +739,7 @@
|
|||
<ClCompile Include="..\..\src\carryover.cpp" />
|
||||
<ClCompile Include="..\..\src\chat_command_handler.cpp" />
|
||||
<ClCompile Include="..\..\src\chat_events.cpp" />
|
||||
<ClCompile Include="..\..\src\chat_log.cpp" />
|
||||
<ClCompile Include="..\..\src\commandline_options.cpp" />
|
||||
<ClCompile Include="..\..\src\config_cache.cpp" />
|
||||
<ClCompile Include="..\..\src\controller_base.cpp" />
|
||||
|
@ -3563,6 +3564,7 @@
|
|||
<ClInclude Include="..\..\src\carryover.hpp" />
|
||||
<ClInclude Include="..\..\src\chat_command_handler.hpp" />
|
||||
<ClInclude Include="..\..\src\chat_events.hpp" />
|
||||
<ClInclude Include="..\..\src\chat_log.hpp" />
|
||||
<ClInclude Include="..\..\src\commandline_options.hpp" />
|
||||
<ClInclude Include="..\..\src\config.hpp" />
|
||||
<ClInclude Include="..\..\src\config_cache.hpp" />
|
||||
|
|
|
@ -1553,6 +1553,7 @@
|
|||
<Filter>Gui\Dialogs</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\src\deprecation.cpp" />
|
||||
<ClCompile Include="..\..\src\chat_log.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\src\addon\client.hpp">
|
||||
|
@ -3015,6 +3016,7 @@
|
|||
<ClInclude Include="..\..\src\gui\widgets\retval.hpp">
|
||||
<Filter>Gui\Widgets</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\chat_log.hpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="..\..\src\tests\test_sdl_utils.hpp">
|
||||
|
|
|
@ -62,6 +62,7 @@ build_info.cpp
|
|||
carryover.cpp
|
||||
chat_command_handler.cpp
|
||||
chat_events.cpp
|
||||
chat_log.cpp
|
||||
commandline_options.cpp
|
||||
config_cache.cpp
|
||||
controller_base.cpp
|
||||
|
|
16
src/chat_log.cpp
Normal file
16
src/chat_log.cpp
Normal file
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
Copyright (C) 2018 by Jyrki Vesterinen <sandgtx@gmail.com>
|
||||
|
||||
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
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#include "chat_log.hpp"
|
||||
|
||||
std::map<std::string, chatroom_log> default_chat_log;
|
25
src/chat_log.hpp
Normal file
25
src/chat_log.hpp
Normal file
|
@ -0,0 +1,25 @@
|
|||
/*
|
||||
Copyright (C) 2018 by Jyrki Vesterinen <sandgtx@gmail.com>
|
||||
|
||||
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
|
||||
(at your option) any later version.
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY.
|
||||
|
||||
See the COPYING file for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
struct chatroom_log
|
||||
{
|
||||
std::string log;
|
||||
bool whisper;
|
||||
};
|
||||
|
||||
extern std::map<std::string, chatroom_log> default_chat_log;
|
|
@ -41,6 +41,7 @@
|
|||
#include "gui/widgets/tree_view_node.hpp"
|
||||
|
||||
#include "addon/manager_ui.hpp"
|
||||
#include "chat_log.hpp"
|
||||
#include "formatter.hpp"
|
||||
#include "formula/string_utils.hpp"
|
||||
#include "preferences/game.hpp"
|
||||
|
@ -745,6 +746,7 @@ void mp_lobby::pre_show(window& window)
|
|||
chatbox_->set_lobby_info(lobby_info_);
|
||||
chatbox_->set_wesnothd_connection(network_connection_);
|
||||
chatbox_->set_active_window_changed_callback([this]() { player_list_dirty_ = true; });
|
||||
chatbox_->load_log(default_chat_log);
|
||||
|
||||
find_widget<button>(&window, "create", false).set_retval(CREATE);
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#include "gui/dialogs/multiplayer/mp_staging.hpp"
|
||||
|
||||
#include "chat_log.hpp"
|
||||
#include "font/text_formatting.hpp"
|
||||
#include "formatter.hpp"
|
||||
#include "game_config.hpp"
|
||||
|
@ -107,6 +108,7 @@ void mp_staging::pre_show(window& window)
|
|||
|
||||
chat.room_window_open("this game", true, false); // TODO: better title?
|
||||
chat.active_window_changed();
|
||||
chat.load_log(default_chat_log);
|
||||
|
||||
//
|
||||
// Set up player list
|
||||
|
|
|
@ -63,6 +63,7 @@ chatbox::chatbox(const implementation::builder_chatbox& builder)
|
|||
, active_window_changed_callback_()
|
||||
, lobby_info_(nullptr)
|
||||
, wesnothd_connection_(nullptr)
|
||||
, log_(nullptr)
|
||||
{
|
||||
// We only implement a RECEIVE_KEYBOARD_FOCUS handler; LOSE_KEYBOARD_FOCUS
|
||||
// isn't needed. This handler forwards focus to the input textbox, meaning
|
||||
|
@ -91,6 +92,15 @@ void chatbox::finalize_setup()
|
|||
std::bind(&chatbox::chat_input_keypress_callback, this, _5));
|
||||
}
|
||||
|
||||
void chatbox::load_log(std::map<std::string, chatroom_log>& log)
|
||||
{
|
||||
for(const auto& l : log) {
|
||||
find_or_create_window(l.first, l.second.whisper, true, true, l.second.log);
|
||||
}
|
||||
|
||||
log_ = &log;
|
||||
}
|
||||
|
||||
void chatbox::active_window_changed()
|
||||
{
|
||||
lobby_chat_window& t = open_windows_[active_window_];
|
||||
|
@ -208,6 +218,11 @@ void chatbox::append_to_chatbox(const std::string& text, size_t id, const bool f
|
|||
log.set_use_markup(true);
|
||||
log.set_label(new_text);
|
||||
|
||||
if(log_ != nullptr) {
|
||||
const std::string& room_name = open_windows_[id].name;
|
||||
log_->at(room_name).log = new_text;
|
||||
}
|
||||
|
||||
const unsigned chatbox_position = log.get_vertical_scrollbar_item_position();
|
||||
|
||||
if(chatbox_at_end || force_scroll) {
|
||||
|
@ -359,18 +374,22 @@ bool chatbox::room_window_active(const std::string& room)
|
|||
|
||||
lobby_chat_window* chatbox::room_window_open(const std::string& room, const bool open_new, const bool allow_close)
|
||||
{
|
||||
return find_or_create_window(room, false, open_new, allow_close);
|
||||
return find_or_create_window(room, false, open_new, allow_close,
|
||||
VGETTEXT("Room <i>“$name”</i> joined", { { "name", room } }));
|
||||
}
|
||||
|
||||
lobby_chat_window* chatbox::whisper_window_open(const std::string& name, bool open_new)
|
||||
{
|
||||
return find_or_create_window(name, true, open_new, true);
|
||||
return find_or_create_window(name, true, open_new, true,
|
||||
VGETTEXT("Whisper session with <i>“$name”</i> started. "
|
||||
"If you do not want to receive messages from this user, type <i>/ignore $name</i>\n", { { "name", name } }));
|
||||
}
|
||||
|
||||
lobby_chat_window* chatbox::find_or_create_window(const std::string& name,
|
||||
const bool whisper,
|
||||
const bool open_new,
|
||||
const bool allow_close)
|
||||
const bool allow_close,
|
||||
const std::string& initial_text)
|
||||
{
|
||||
for(auto& t : open_windows_) {
|
||||
if(t.name == name && t.whisper == whisper) {
|
||||
|
@ -387,22 +406,19 @@ lobby_chat_window* chatbox::find_or_create_window(const std::string& name,
|
|||
//
|
||||
// Add a new chat log page.
|
||||
//
|
||||
std::map<std::string, string_map> data;
|
||||
string_map item;
|
||||
|
||||
item["use_markup"] = "true";
|
||||
item["label"] = initial_text;
|
||||
std::map<std::string, string_map> data{{"log_text", item}};
|
||||
|
||||
if(whisper) {
|
||||
item["label"] = VGETTEXT("Whisper session with <i>“$name”</i> started. "
|
||||
"If you do not want to receive messages from this user, type <i>/ignore $name</i>\n", {{"name", name}});
|
||||
data.emplace("log_text", item);
|
||||
} else {
|
||||
item["label"] = VGETTEXT("Room <i>“$name”</i> joined", {{"name", name}});
|
||||
data.emplace("log_text", item);
|
||||
|
||||
if(!whisper) {
|
||||
lobby_info_->open_room(name);
|
||||
}
|
||||
|
||||
if(log_ != nullptr) {
|
||||
log_->emplace(name, chatroom_log{item["label"], whisper});
|
||||
}
|
||||
|
||||
chat_log_container_->add_page(data);
|
||||
|
||||
//
|
||||
|
@ -532,6 +548,10 @@ void chatbox::close_window(size_t idx)
|
|||
lobby_info_->close_room(t.name);
|
||||
}
|
||||
|
||||
if(log_ != nullptr) {
|
||||
log_->erase(t.name);
|
||||
}
|
||||
|
||||
open_windows_.erase(open_windows_.begin() + idx);
|
||||
|
||||
roomlistbox_->remove_row(idx);
|
||||
|
|
|
@ -14,10 +14,12 @@
|
|||
#pragma once
|
||||
|
||||
#include "chat_events.hpp"
|
||||
#include "chat_log.hpp"
|
||||
#include "game_initialization/lobby_data.hpp"
|
||||
#include "game_initialization/lobby_info.hpp"
|
||||
#include "gui/widgets/container_base.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
class config;
|
||||
|
@ -92,6 +94,8 @@ public:
|
|||
wesnothd_connection_ = &c;
|
||||
}
|
||||
|
||||
void load_log(std::map<std::string, chatroom_log>& log);
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Initializes the internal sub-widget pointers.
|
||||
|
@ -144,6 +148,8 @@ private:
|
|||
|
||||
wesnothd_connection* wesnothd_connection_;
|
||||
|
||||
std::map<std::string, chatroom_log>* log_;
|
||||
|
||||
/** Inherited from styled_widget, implemented by REGISTER_WIDGET. */
|
||||
virtual const std::string& get_control_type() const override;
|
||||
|
||||
|
@ -233,7 +239,7 @@ public:
|
|||
/**
|
||||
* Helper function to find and open a new window, used by *_window_open
|
||||
*/
|
||||
lobby_chat_window* find_or_create_window(const std::string& name, const bool whisper, const bool open_new, const bool allow_close);
|
||||
lobby_chat_window* find_or_create_window(const std::string& name, const bool whisper, const bool open_new, const bool allow_close, const std::string& initial_text);
|
||||
|
||||
void close_window_button_callback(std::string room_name, bool& handled, bool& halt);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue