Initial work to handle chat timestamps as time_points
This commit is contained in:
parent
6d4058d670
commit
3a74825e8d
7 changed files with 23 additions and 41 deletions
|
@ -146,7 +146,7 @@ void display_chat_manager::add_chat_message(const std::time_t& time, const std::
|
|||
|
||||
// Prepend message with timestamp.
|
||||
std::stringstream message_complete;
|
||||
message_complete << prefs::get().get_chat_timestamp(time) << str.str();
|
||||
message_complete << prefs::get().get_chat_timestamp(std::chrono::system_clock::from_time_t(time)) << str.str();
|
||||
|
||||
const SDL_Rect rect = my_disp_.map_outside_area();
|
||||
|
||||
|
|
|
@ -230,7 +230,7 @@ void chatbox::append_to_chatbox(const std::string& text, std::size_t id, const b
|
|||
|
||||
const std::string before_message = log.get_value().empty() ? "" : "\n";
|
||||
const std::string new_text = formatter()
|
||||
<< log.get_value() << before_message << markup::span_color("#bcb088", prefs::get().get_chat_timestamp(std::time(nullptr)), text);
|
||||
<< log.get_value() << before_message << markup::span_color("#bcb088", prefs::get().get_chat_timestamp(std::chrono::system_clock::now()), text);
|
||||
|
||||
log.set_use_markup(true);
|
||||
log.set_value(new_text);
|
||||
|
|
|
@ -70,6 +70,7 @@
|
|||
#include "replay_helper.hpp"
|
||||
#include "resources.hpp"
|
||||
#include "savegame.hpp"
|
||||
#include "serialization/chrono.hpp"
|
||||
#include "scripting/game_lua_kernel.hpp"
|
||||
#include "scripting/plugins/manager.hpp"
|
||||
#include "synced_context.hpp"
|
||||
|
@ -185,8 +186,6 @@ void menu_handler::show_chat_log()
|
|||
config c;
|
||||
c["name"] = "prototype of chat log";
|
||||
gui2::dialogs::chat_log::display(vconfig(c), *resources::recorder);
|
||||
// std::string text = resources::recorder->build_chat_log();
|
||||
// gui::show_dialog(*gui_,nullptr,_("Chat Log"),"",gui::CLOSE_ONLY,nullptr,nullptr,"",&text);
|
||||
}
|
||||
|
||||
void menu_handler::show_help()
|
||||
|
@ -1325,10 +1324,8 @@ void menu_handler::send_chat_message(const std::string& message, bool allies_onl
|
|||
config cfg;
|
||||
cfg["id"] = prefs::get().login();
|
||||
cfg["message"] = message;
|
||||
const std::time_t time = ::std::time(nullptr);
|
||||
std::stringstream ss;
|
||||
ss << time;
|
||||
cfg["time"] = ss.str();
|
||||
auto now = std::chrono::system_clock::now();
|
||||
cfg["time"] = chrono::serialize_timestamp(now);
|
||||
|
||||
const int side = board().is_observer() ? 0 : gui_->viewing_team().side();
|
||||
if(!board().is_observer()) {
|
||||
|
@ -1347,7 +1344,8 @@ void menu_handler::send_chat_message(const std::string& message, bool allies_onl
|
|||
|
||||
resources::recorder->speak(cfg);
|
||||
|
||||
add_chat_message(time, cfg["id"], side, message,
|
||||
auto as_time_t = std::chrono::system_clock::to_time_t(now); // FIXME: remove
|
||||
add_chat_message(as_time_t, cfg["id"], side, message,
|
||||
private_message ? events::chat_handler::MESSAGE_PRIVATE : events::chat_handler::MESSAGE_PUBLIC);
|
||||
}
|
||||
|
||||
|
|
|
@ -1752,14 +1752,13 @@ compression::format prefs::save_compression_format()
|
|||
return compression::format::gzip;
|
||||
}
|
||||
|
||||
std::string prefs::get_chat_timestamp(const std::time_t& t)
|
||||
std::string prefs::get_chat_timestamp(const std::chrono::system_clock::time_point& t)
|
||||
{
|
||||
if(chat_timestamp()) {
|
||||
auto temp = std::chrono::system_clock::from_time_t(t); // FIXME: remove
|
||||
if(use_twelve_hour_clock_format() == false) {
|
||||
return chrono::format_local_timestamp(temp, _("[%H:%M]")) + " ";
|
||||
return chrono::format_local_timestamp(t, _("[%H:%M]")) + " ";
|
||||
} else {
|
||||
return chrono::format_local_timestamp(temp, _("[%I:%M %p]")) + " ";
|
||||
return chrono::format_local_timestamp(t, _("[%I:%M %p]")) + " ";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -243,7 +243,7 @@ class prefs
|
|||
bool get_scroll_when_mouse_outside(bool def);
|
||||
bool auto_open_whisper_windows();
|
||||
bool show_combat();
|
||||
std::string get_chat_timestamp(const std::time_t& t);
|
||||
std::string get_chat_timestamp(const std::chrono::system_clock::time_point& t);
|
||||
compression::format save_compression_format();
|
||||
std::vector<std::string>* get_history(const std::string& id);
|
||||
std::vector<preferences::option>& get_advanced_preferences() {return advanced_prefs_;}
|
||||
|
|
|
@ -129,26 +129,21 @@ static void verify(const unit_map& units, const config& cfg) {
|
|||
LOG_REPLAY << "verification passed";
|
||||
}
|
||||
|
||||
static std::time_t get_time(const config &speak)
|
||||
static std::chrono::system_clock::time_point get_time(const config& speak)
|
||||
{
|
||||
std::time_t time;
|
||||
if (!speak["time"].empty())
|
||||
{
|
||||
std::stringstream ss(speak["time"].str());
|
||||
ss >> time;
|
||||
if(!speak["time"].empty()) {
|
||||
return chrono::parse_timestamp(speak["time"]);
|
||||
} else {
|
||||
// fallback in case sender uses wesnoth that doesn't send timestamps
|
||||
return std::chrono::system_clock::now();
|
||||
}
|
||||
else
|
||||
{
|
||||
//fallback in case sender uses wesnoth that doesn't send timestamps
|
||||
time = std::time(nullptr);
|
||||
}
|
||||
return time;
|
||||
}
|
||||
|
||||
chat_msg::chat_msg(const config &cfg)
|
||||
: color_()
|
||||
, nick_()
|
||||
, text_(cfg["message"].str())
|
||||
, time_(get_time(cfg))
|
||||
{
|
||||
if(cfg["team_name"].empty() && cfg["to_sides"].empty())
|
||||
{
|
||||
|
@ -163,17 +158,6 @@ chat_msg::chat_msg(const config &cfg)
|
|||
} else {
|
||||
color_ = team::get_side_highlight_pango(side);
|
||||
}
|
||||
time_ = get_time(cfg);
|
||||
/*
|
||||
} else if (side==1) {
|
||||
color_ = "red";
|
||||
} else if (side==2) {
|
||||
color_ = "blue";
|
||||
} else if (side==3) {
|
||||
color_ = "green";
|
||||
} else if (side==4) {
|
||||
color_ = "purple";
|
||||
}*/
|
||||
}
|
||||
|
||||
chat_msg::~chat_msg()
|
||||
|
@ -766,7 +750,8 @@ REPLAY_RETURN do_replay_handle(bool one_move)
|
|||
DBG_REPLAY << "tried to add a chat message twice.";
|
||||
if (!resources::controller->is_skipping_replay() || is_whisper) {
|
||||
int side = speak["side"].to_int();
|
||||
game_display::get_singleton()->get_chat_manager().add_chat_message(get_time(*speak), speaker_name, side, message,
|
||||
auto as_time_t = std::chrono::system_clock::to_time_t(get_time(*speak)); // FIXME: remove
|
||||
game_display::get_singleton()->get_chat_manager().add_chat_message(as_time_t, speaker_name, side, message,
|
||||
(team_name.empty() ? events::chat_handler::MESSAGE_PUBLIC
|
||||
: events::chat_handler::MESSAGE_PRIVATE),
|
||||
prefs::get().message_bell());
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
#include "map/location.hpp"
|
||||
|
||||
#include <ctime>
|
||||
#include <chrono>
|
||||
#include <iterator>
|
||||
class replay_recorder_base;
|
||||
class terrain_label;
|
||||
|
@ -33,14 +33,14 @@ public:
|
|||
const std::string &text() const { return text_; }
|
||||
const std::string &nick() const { return nick_; }
|
||||
const std::string &color() const { return color_; }
|
||||
const std::time_t &time() const { return time_; }
|
||||
const auto& time() const { return time_; }
|
||||
chat_msg(const config &cfg);
|
||||
virtual ~chat_msg();
|
||||
private:
|
||||
std::string color_;
|
||||
std::string nick_;
|
||||
std::string text_;
|
||||
std::time_t time_;
|
||||
std::chrono::system_clock::time_point time_;
|
||||
};
|
||||
|
||||
enum class REPLAY_ACTION_TYPE
|
||||
|
|
Loading…
Add table
Reference in a new issue