Skip to content

Commit

Permalink
Add prefix to chat logs all the time, plus to chat headers when /text…
Browse files Browse the repository at this point in the history
…color is enabled. Meh, I dunno.
  • Loading branch information
ZarothYe committed May 15, 2022
1 parent 88c13a4 commit 2b539e8
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions Scripts/Python/ki/xKIChat.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ def AddChatLine(self, player, message, cFlags, forceKI=True):
headerColor = kColors.ChatHeaderBroadcast
bodyColor = kColors.ChatMessage
mentionColor = kColors.ChatMessageMention
contextPrefix = ""
censorLevel = self.GetCensorLevel()
hasMention = False

Expand All @@ -443,6 +444,7 @@ def AddChatLine(self, player, message, cFlags, forceKI=True):
# Is it subtitles for current audio?
if cFlags.subtitle:
headerColor = kColors.AudioSubtitleHeader
contextPrefix = PtGetLocalizedString("KI.Chat.SubtitleContextPrefix")
if player is not None:
# add subtitle speaker's name if it was provided
# add leading space to match indent for broadcast player messages
Expand All @@ -459,14 +461,18 @@ def AddChatLine(self, player, message, cFlags, forceKI=True):
if cFlags.private:
if cFlags.admin:
headerColor = kColors.ChatHeaderError
contextPrefix = PtGetLocalizedString("KI.Chat.AdminContextPrefix")
else:
headerColor = kColors.ChatHeaderPrivate
contextPrefix = PtGetLocalizedString("KI.Chat.PrivateContextPrefix")
forceKI = True
else:
if cFlags.neighbors:
headerColor = kColors.ChatHeaderNeighbors
contextPrefix = PtGetLocalizedString("KI.Chat.NeighborsContextPrefix")
else:
headerColor = kColors.ChatHeaderBuddies
contextPrefix = PtGetLocalizedString("KI.Chat.BuddiesContextPrefix")

if cFlags.toSelf:
pretext = PtGetLocalizedString("KI.Chat.InterAgeSendTo")
Expand Down Expand Up @@ -508,6 +514,7 @@ def AddChatLine(self, player, message, cFlags, forceKI=True):
# Is it a ccr broadcast?
elif cFlags.ccrBcast:
headerColor = kColors.ChatHeaderAdmin
contextPrefix = PtGetLocalizedString("KI.Chat.CCRContextPrefix")
if cFlags.toSelf:
pretext = PtGetLocalizedString("KI.Chat.PrivateSendTo")
else:
Expand All @@ -519,6 +526,7 @@ def AddChatLine(self, player, message, cFlags, forceKI=True):
elif cFlags.admin:
if cFlags.private:
headerColor = kColors.ChatHeaderError
contextPrefix = PtGetLocalizedString("KI.Chat.AdminContextPrefix")
if cFlags.toSelf:
pretext = PtGetLocalizedString("KI.Chat.PrivateSendTo")
else:
Expand All @@ -531,6 +539,7 @@ def AddChatLine(self, player, message, cFlags, forceKI=True):
PtFlashWindow()
else:
headerColor = kColors.ChatHeaderAdmin
contextPrefix = PtGetLocalizedString("KI.Chat.AdminContextPrefix")
forceKI = True

# Is it a broadcast message?
Expand All @@ -553,11 +562,13 @@ def AddChatLine(self, player, message, cFlags, forceKI=True):
elif cFlags.private:
if cFlags.toSelf:
headerColor = kColors.ChatHeaderPrivate
contextPrefix = PtGetLocalizedString("KI.Chat.PrivateContextPrefix")
pretext = PtGetLocalizedString("KI.Chat.PrivateSendTo")
else:
if not self.CheckIfCanPM(player.getPlayerID()):
return
headerColor = kColors.ChatHeaderPrivate
contextPrefix = PtGetLocalizedString("KI.Chat.PrivateContextPrefix")
pretext = PtGetLocalizedString("KI.Chat.PrivateMsgRecvd")
forceKI = True

Expand All @@ -570,9 +581,11 @@ def AddChatLine(self, player, message, cFlags, forceKI=True):
else:
if cFlags == kChat.SystemMessage:
headerColor = kColors.ChatHeaderError
contextPrefix = PtGetLocalizedString("KI.Chat.ErrorContextPrefix")
pretext = PtGetLocalizedString("KI.Chat.ErrorMsgRecvd")
elif cFlags == kChat.AudioSubtitle:
headerColor = kColors.AudioSubtitleHeader
contextPrefix = PtGetLocalizedString("KI.Chat.SubtitleContextPrefix")
if player is not None:
# add subtitle speaker's name if it was provided
# add leading space to match indent for broadcast player messages
Expand Down Expand Up @@ -603,9 +616,10 @@ def AddChatLine(self, player, message, cFlags, forceKI=True):
chatMentions = []

# if we have an override chat color set, use it instead of the various default chat colors
headerColor = self.chatTextColor if self.chatTextColor is not None else headerColor
bodyColor = self.chatTextColor if self.chatTextColor is not None else bodyColor
mentionColor = self.chatTextColor if self.chatTextColor is not None else mentionColor
if self.chatTextColor:
headerColor = self.chatTextColor
bodyColor = self.chatTextColor
mentionColor = self.chatTextColor

for chatArea in (self.miniChatArea, self.microChatArea):
with PtBeginGUIUpdate(chatArea):
Expand All @@ -615,7 +629,7 @@ def AddChatLine(self, player, message, cFlags, forceKI=True):
chatArea.insertColor(headerColor)

# Added unicode support here.
chatArea.insertStringW("\n{}".format(chatHeaderFormatted))
chatArea.insertStringW(f"\n{contextPrefix if self.chatTextColor else ''}{chatHeaderFormatted}")
chatArea.insertColor(bodyColor)

lastInsert = 0
Expand All @@ -627,8 +641,9 @@ def AddChatLine(self, player, message, cFlags, forceKI=True):
chatArea.insertStringW(chatMessageFormatted[lastInsert:start], censorLevel=censorLevel)

lastInsert = end

chatArea.insertColor(mentionColor)
chatArea.insertStringW(mention, censorLevel=censorLevel, urlDetection=False)
chatArea.insertStringW(f"{'*' if self.chatTextColor else ''}{mention}{'*' if self.chatTextColor else ''}", censorLevel=censorLevel, urlDetection=False)
chatArea.insertColor(bodyColor)

# If there is remaining text to display after last mention, write it
Expand Down Expand Up @@ -657,7 +672,7 @@ def AddChatLine(self, player, message, cFlags, forceKI=True):

# Write to the log file.
if self.chatLogFile is not None and self.chatLogFile.isOpen():
self.chatLogFile.write(chatHeaderFormatted[0:] + chatMessageFormatted)
self.chatLogFile.write(f"{contextPrefix}{chatHeaderFormatted[0:]}{chatMessageFormatted}")

# Update the fading controls.
self.ResetFadeState()
Expand Down

0 comments on commit 2b539e8

Please sign in to comment.