Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions src/ChatChannel.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

class ChatChannel {
string m_title;
BetterChat::IChatChannelSink@ m_sink;

array<ChatLine@> m_lines;

uint64 m_lastMessageTime = 0;

ChatChannel() {}

ChatChannel(const string&in title, BetterChat::IChatChannelSink@ sink) {
m_title = title;
@m_sink = sink;
}

void Clear()
{
m_lines.RemoveRange(0, m_lines.Length);
}

string GetTitle() {
return m_title;
}

void SendChatMessage(const string&in text) {
if (@m_sink !is null) {
m_sink.SendChatMessage(text);
}
}

void InsertLine(ChatLine@ line) {
m_lines.InsertLast(line);

if (m_lines.Length > uint(Setting_MaximumLines)) {
m_lines.RemoveRange(0, m_lines.Length - Setting_MaximumLines);
}

// Remember when the last message was received
m_lastMessageTime = Time::Now;
}
}

class ChatChannelHook: BetterChat::IChatChannelHook {
ChatChannel@ m_channel;

ChatChannelHook(ChatChannel@ channel) {
@m_channel = channel;
}

void Clear() override {
m_channel.Clear();
}

void AddChatEntry(BetterChat::ChatEntry entry) override {
g_window.AddChatLine(ChatLine(g_window.NextLineId(), Time::Stamp, entry), m_channel);
}
}
14 changes: 14 additions & 0 deletions src/ChatLine.as
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ class ChatLine
}
#endif

ChatLine(uint id, int64 time, BetterChat::ChatEntry entry) {
m_id = id;
m_time = time;
FromSharedEntry(entry);
}

vec4 GetHighlightColor(const vec4 &in def = vec4(0, 0, 0, 1))
{
vec3 ret(def.x, def.y, def.z);
Expand Down Expand Up @@ -90,6 +96,14 @@ class ChatLine
}
#endif

void FromSharedEntry(BetterChat::ChatEntry entry) {
// Trace the message to the log if needed by settings (and not in streamer mode)
if (Setting_TraceToLog && !Setting_StreamerMode) {
trace(entry.m_text);
}
FromChatLineInfo(ChatLineInfo(entry));
}

void FromChatLineInfo(const ChatLineInfo &in info)
{
string text = info.m_text;
Expand Down
30 changes: 30 additions & 0 deletions src/ChatLineInfo.as
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,36 @@ class ChatLineInfo

string m_text;

ChatLineInfo(BetterChat::ChatEntry entry) {
FromSharedEntry(entry);
}

void FromSharedEntry(BetterChat::ChatEntry entry) {
m_text = entry.m_text;
m_authorName = entry.m_authorName;
m_authorClubTag = entry.m_clubTag;
m_overrideClubTag = entry.m_clubTag != "";
m_linearHue = entry.m_linearHue;
m_teamNumber = entry.m_linearHue != 0. ? 1 : 0;
m_isSystem = entry.m_system;
m_scope = FromSharedScope(entry.m_scope);
}

ChatLineScope FromSharedScope(BetterChat::ChatEntryScope scope) {
switch (scope) {
case BetterChat::ChatEntryScope::Everyone:
return ChatLineScope::Everyone;
case BetterChat::ChatEntryScope::SpectatorCurrent:
return ChatLineScope::SpectatorCurrent;
case BetterChat::ChatEntryScope::SpectatorAll:
return ChatLineScope::SpectatorAll;
case BetterChat::ChatEntryScope::Team:
return ChatLineScope::Team;
default:
return ChatLineScope::YouOnly;
}
}

#if TMNEXT
ChatLineInfo(NGameScriptChat_SEntry@ entry)
{
Expand Down
Loading