feat(chat): add colored system messages for player join/exit

This commit is contained in:
2026-07-20 18:09:24 +08:00
parent 7e6f48ff07
commit 4d2b87bfcb
8 changed files with 67 additions and 8 deletions

View File

@@ -1,11 +1,15 @@
#pragma once
#include "Cubed/ui/color.hpp"
#include <cstdint>
#include <string>
namespace Cubed {
struct ChatMessage {
std::string player;
std::string text;
Color color;
bool system_msg = false;
uint64_t time = 0;
};
} // namespace Cubed

View File

@@ -11,6 +11,7 @@
#include "Cubed/tools/priority_thread_pool.hpp"
#include "Cubed/tools/recent_queue.hpp"
#include "Cubed/tools/thread_pool.hpp"
#include "Cubed/ui/color.hpp"
#include "world/block_change.pb.h"
#include <absl/container/flat_hash_set.h>
@@ -192,6 +193,7 @@ private:
int threads);
void send_server_stop();
void boardcast_message(const std::string& name, const std::string& message);
void boardcast_message(const std::string& name, const std::string& message,
Color color = Color::WHITE, bool system_msg = false);
};
} // namespace Cubed

View File

@@ -6,7 +6,7 @@
namespace Cubed {
enum class Color {
BLACK,
BLACK = 0,
WHITE,
RED,
GREEN,
@@ -21,6 +21,39 @@ enum class Color {
BROWN
};
inline constexpr Color color_from_int(int i) {
switch (i) {
case std::to_underlying(Color::BLACK):
return Color::BLACK;
case std::to_underlying(Color::WHITE):
return Color::WHITE;
case std::to_underlying(Color::RED):
return Color::RED;
case std::to_underlying(Color::GREEN):
return Color::GREEN;
case std::to_underlying(Color::BLUE):
return Color::BLUE;
case std::to_underlying(Color::YELLOW):
return Color::YELLOW;
case std::to_underlying(Color::CYAN):
return Color::CYAN;
case std::to_underlying(Color::MAGENTA):
return Color::MAGENTA;
case std::to_underlying(Color::GRAY):
return Color::GRAY;
case std::to_underlying(Color::ORANGE):
return Color::ORANGE;
case std::to_underlying(Color::PURPLE):
return Color::PURPLE;
case std::to_underlying(Color::PINK):
return Color::PINK;
case std::to_underlying(Color::BROWN):
return Color::BROWN;
default:
return Color::WHITE;
}
}
inline constexpr glm::vec4 color_value(Color color) {
using glm::vec4;