Skip to content

Commit

Permalink
Merge pull request #1141 from ZarothYe/save-textcolor-setting
Browse files Browse the repository at this point in the history
Save and load the user's /textcolor setting to persist it between game sessions
  • Loading branch information
Hoikas authored May 6, 2022
2 parents 4ad07c1 + 54fb86f commit 207029b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Scripts/Python/ki/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,7 @@ def SetupKI(self):
self.DetermineKILevel()
self.DetermineKIFlags()
self.DetermineGZ()
self.DetermineTextColor()

# Hide all dialogs first.
KIMicroBlackbar.dialog.hide()
Expand Down Expand Up @@ -1642,6 +1643,28 @@ def MessageHistory(self, control, set):
control.end()
control.refresh()

#~~~~~~~~~~~~~~~~~#
# KI Text Color #
#~~~~~~~~~~~~~~~~~#

## Sets the KI Text Color from the Chronicle.
def DetermineTextColor(self):

vault = ptVault()
entry = vault.findChronicleEntry(kChronicleKITextColor)
if entry is not None:
colorStr = entry.chronicleGetValue()
PtDebugPrint(f"xKI.DetermineTextColor(): KI Text Color is: \"{colorStr}\".", level=kWarningLevel)
args = colorStr.split(",")
try:
self.chatMgr.chatTextColor = ptColor(float(args[0]), float(args[1]), float(args[2]))
except (IndexError, ValueError):
# format is incorrect -- didn't have 3 values, or values weren't floats -- so log an error and destroy all evidence
PtDebugPrint(f"xKI.DetermineTextColor(): KI Text Color was not in the expected triplet format", level=kWarningLevel)
vault.addChronicleEntry(kChronicleKITextColor, kChronicleKITextColorType, "")



#~~~~~~~~~~#
# GZ Games #
#~~~~~~~~~~#
Expand Down
17 changes: 17 additions & 0 deletions Scripts/Python/ki/xKIChat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,18 @@ def ChangePassword(self, newPassword):
return
PtChangePassword(newPassword)

## Update the Chronicle's KI Text Color values.
# This uses an RGB triplet with parts separated by "," or an empty string for the default chat color.
def UpdateTextColorChronicle(self):

vault = ptVault()
newVal = ""
if isinstance(self.chatMgr.chatTextColor, ptColor):
newVal = f"{self.chatMgr.chatTextColor.getRed()},{self.chatMgr.chatTextColor.getGreen()},{self.chatMgr.chatTextColor.getBlue()}"

PtDebugPrint(f"xKIChat.UpdateTextColorChronicle(): Setting KI Text Color chronicle to: \"{newVal}\".", level=kWarningLevel)
vault.addChronicleEntry(kChronicleKITextColor, kChronicleKITextColorType, newVal)

## Overrides the chat area text colors to be a single user-selected color
def SetTextColor(self, arg1, arg2=None, arg3=None):

Expand All @@ -1250,6 +1262,7 @@ def SetTextColor(self, arg1, arg2=None, arg3=None):
colorBlue = clamp(colorBlue, 0, 255)
colorGreen = clamp(colorGreen, 0, 255)
self.chatMgr.chatTextColor = ptColor(colorRed / 255.0, colorBlue / 255.0, colorGreen / 255.0)
self.UpdateTextColorChronicle()
self.chatMgr.DisplayStatusMessage(PtGetLocalizedString("KI.Chat.TextColorSetValue", [f"({colorRed}, {colorBlue}, {colorGreen})"]))
return

Expand All @@ -1266,6 +1279,7 @@ def SetTextColor(self, arg1, arg2=None, arg3=None):
colorBlue = clamp(colorBlue, 0.0, 1.0)
colorGreen = clamp(colorGreen, 0.0, 1.0)
self.chatMgr.chatTextColor = ptColor(colorRed, colorBlue, colorGreen)
self.UpdateTextColorChronicle()
self.chatMgr.DisplayStatusMessage(PtGetLocalizedString("KI.Chat.TextColorSetValue", [f"({colorRed}, {colorBlue}, {colorGreen})"]))
return

Expand All @@ -1274,10 +1288,12 @@ def SetTextColor(self, arg1, arg2=None, arg3=None):
# newColor is a valid localized color name with a corresponding function on the ptColor class
colorFn = getattr(ptColor(), kColorNames[newColor])
self.chatMgr.chatTextColor = colorFn()
self.UpdateTextColorChronicle()
self.chatMgr.DisplayStatusMessage(PtGetLocalizedString("KI.Chat.TextColorSetValue", [newColor]))
elif newColor == PtGetLocalizedString("KI.Commands.ChatSetTextColorDefaultArg"):
# user requested resetting text colors to defaults
self.chatMgr.chatTextColor = None
self.UpdateTextColorChronicle()
self.chatMgr.DisplayStatusMessage(PtGetLocalizedString("KI.Chat.TextColorSetDefault"))
else:
hexColor = newColor.lstrip("#")
Expand All @@ -1296,6 +1312,7 @@ def SetTextColor(self, arg1, arg2=None, arg3=None):
return
else:
self.chatMgr.chatTextColor = ptColor(colorRed, colorBlue, colorGreen)
self.UpdateTextColorChronicle()
self.chatMgr.DisplayStatusMessage(PtGetLocalizedString("KI.Chat.TextColorSetValue", [f"#{hexColor}"]))
else:
# argument was not 3 or 6 characters long, so it cannot be a valid hexadecimal color
Expand Down
2 changes: 2 additions & 0 deletions Scripts/Python/plasma/PlasmaKITypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@
kChronicleGZMarkersAquiredType = 1
kChronicleCalGZMarkersAquired = "CalGZMarkers"
kChronicleCalGZMarkersAquiredType = 1
kChronicleKITextColor = "KITextColor"
kChronicleKITextColorType = 1


def PtDetermineKILevel():
Expand Down

0 comments on commit 207029b

Please sign in to comment.