[Refactor] Improve overlay image creation logic for large logs and translations
This commit is contained in:
@@ -340,10 +340,24 @@ class Controller:
|
||||
model.logger.info(f"[SENT] {message}{translation}")
|
||||
|
||||
if config.OVERLAY_LARGE_LOG is True and model.overlay.initialized is True:
|
||||
if config.OVERLAY_SHOW_ONLY_TRANSLATED_MESSAGES is True and len(translation) > 0:
|
||||
overlay_image = model.createOverlayImageLargeLog("send", translation[0], "")
|
||||
if config.OVERLAY_SHOW_ONLY_TRANSLATED_MESSAGES is True:
|
||||
if len(translation) > 0:
|
||||
overlay_image = model.createOverlayImageLargeLog(
|
||||
"send",
|
||||
None,
|
||||
None,
|
||||
translation,
|
||||
config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO]
|
||||
)
|
||||
model.updateOverlayLargeLog(overlay_image)
|
||||
else:
|
||||
overlay_image = model.createOverlayImageLargeLog("send", message, translation[0] if len(translation) > 0 else "")
|
||||
overlay_image = model.createOverlayImageLargeLog(
|
||||
"send",
|
||||
message,
|
||||
config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO]["1"]["language"],
|
||||
translation,
|
||||
config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO]
|
||||
)
|
||||
model.updateOverlayLargeLog(overlay_image)
|
||||
|
||||
def speakerMessage(self, result:dict) -> None:
|
||||
@@ -425,10 +439,23 @@ class Controller:
|
||||
model.updateOverlaySmallLog(overlay_image)
|
||||
|
||||
if config.OVERLAY_LARGE_LOG is True and model.overlay.initialized is True:
|
||||
if config.OVERLAY_SHOW_ONLY_TRANSLATED_MESSAGES is True and len(translation) > 0:
|
||||
overlay_image = model.createOverlayImageLargeLog("receive", translation[0], "")
|
||||
if config.OVERLAY_SHOW_ONLY_TRANSLATED_MESSAGES is True:
|
||||
if len(translation) > 0:
|
||||
overlay_image = model.createOverlayImageLargeLog(
|
||||
"receive",
|
||||
None,
|
||||
None,
|
||||
translation,
|
||||
)
|
||||
model.updateOverlayLargeLog(overlay_image)
|
||||
else:
|
||||
overlay_image = model.createOverlayImageLargeLog("receive", message, translation[0] if len(translation) > 0 else "")
|
||||
overlay_image = model.createOverlayImageLargeLog(
|
||||
"receive",
|
||||
message,
|
||||
language,
|
||||
translation,
|
||||
config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO]
|
||||
)
|
||||
model.updateOverlayLargeLog(overlay_image)
|
||||
|
||||
if config.SEND_RECEIVED_MESSAGE_TO_VRC is True:
|
||||
@@ -544,10 +571,24 @@ class Controller:
|
||||
model.oscSendMessage(osc_message)
|
||||
|
||||
if config.OVERLAY_LARGE_LOG is True:
|
||||
if config.OVERLAY_SHOW_ONLY_TRANSLATED_MESSAGES is True and len(translation) > 0:
|
||||
overlay_image = model.createOverlayImageLargeLog("send", translation[0], "")
|
||||
if config.OVERLAY_SHOW_ONLY_TRANSLATED_MESSAGES is True:
|
||||
if len(translation) > 0:
|
||||
overlay_image = model.createOverlayImageLargeLog(
|
||||
"send",
|
||||
None,
|
||||
None,
|
||||
translation,
|
||||
config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO],
|
||||
)
|
||||
model.updateOverlayLargeLog(overlay_image)
|
||||
else:
|
||||
overlay_image = model.createOverlayImageLargeLog("send", message, translation[0] if len(translation) > 0 else "")
|
||||
overlay_image = model.createOverlayImageLargeLog(
|
||||
"send",
|
||||
message,
|
||||
config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO]["1"]["language"],
|
||||
translation,
|
||||
config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO],
|
||||
)
|
||||
model.updateOverlayLargeLog(overlay_image)
|
||||
|
||||
if model.checkWebSocketServerAlive() is True:
|
||||
|
||||
@@ -769,10 +769,9 @@ class Model:
|
||||
if (self.overlay.settings[size]["ui_scaling"] != config.OVERLAY_SMALL_LOG_SETTINGS["ui_scaling"]):
|
||||
self.overlay.updateUiScaling(config.OVERLAY_SMALL_LOG_SETTINGS["ui_scaling"], size)
|
||||
|
||||
def createOverlayImageLargeLog(self, message_type:str, message:str, translation:str):
|
||||
your_language = config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO]["1"]["language"]
|
||||
target_language = config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO]["1"]["language"]
|
||||
return self.overlay_image.createOverlayImageLargeLog(message_type, message, your_language, translation, target_language)
|
||||
def createOverlayImageLargeLog(self, message_type:str, message:str, your_language:str, translation:list, target_languages:dict):
|
||||
target_languages = [data["language"] for data in target_languages.values() if data["enable"] is True]
|
||||
return self.overlay_image.createOverlayImageLargeLog(message_type, message, your_language, translation, target_languages)
|
||||
|
||||
def createOverlayImageLargeMessage(self, message):
|
||||
ui_language = config.UI_LANGUAGE
|
||||
|
||||
@@ -199,17 +199,37 @@ class OverlayImage:
|
||||
draw.text((text_x, text_y), text, text_color, anchor=anchor, stroke_width=0, font=font)
|
||||
return img
|
||||
|
||||
def createTextboxLargeLog(self, message_type:str, message:str, your_language:str, translation:str, target_language:str, date_time:str) -> Image:
|
||||
message_type_img = self.createTextImageMessageType(message_type, date_time)
|
||||
if translation and target_language:
|
||||
img = self.createTextImageLargeLog(message_type, "small", message, your_language)
|
||||
translation_img = self.createTextImageLargeLog(message_type, "large", translation, target_language)
|
||||
img = self.concatenateImagesVertically(img, translation_img)
|
||||
else:
|
||||
img = self.createTextImageLargeLog(message_type, "large", message, your_language)
|
||||
return self.concatenateImagesVertically(message_type_img, img)
|
||||
def createTextboxLargeLog(self, message_type: str, message: str = None, your_language: str = None, translation: list = [], target_language: list = [], date_time: str = None) -> Image:
|
||||
# テキスト画像のリストを作成
|
||||
images = [self.createTextImageMessageType(message_type, date_time)]
|
||||
|
||||
def createOverlayImageLargeLog(self, message_type:str, message:str, your_language:str, translation:str="", target_language:str=None) -> Image:
|
||||
# 翻訳がある場合
|
||||
if translation and target_language:
|
||||
# 元のメッセージがある場合は小さいサイズで追加
|
||||
if message is not None:
|
||||
images.append(
|
||||
self.createTextImageLargeLog(message_type, "small", message, your_language)
|
||||
)
|
||||
|
||||
# 翻訳をすべて大きいサイズで追加
|
||||
for trans, lang in zip(translation, target_language):
|
||||
images.append(
|
||||
self.createTextImageLargeLog(message_type, "large", trans, lang)
|
||||
)
|
||||
else:
|
||||
# 翻訳がない場合は元のメッセージのみ
|
||||
images.append(
|
||||
self.createTextImageLargeLog(message_type, "large", message, your_language)
|
||||
)
|
||||
|
||||
# すべてのテキスト画像を縦に結合
|
||||
combined_img = images[0]
|
||||
for img in images[1:]:
|
||||
combined_img = self.concatenateImagesVertically(combined_img, img)
|
||||
|
||||
return combined_img
|
||||
|
||||
def createOverlayImageLargeLog(self, message_type:str, message:str=None, your_language:str=None, translation:list=[], target_language:list=[]) -> Image:
|
||||
ui_color = self.getUiColorLargeLog()
|
||||
background_color = ui_color["background_color"]
|
||||
background_outline_color = ui_color["background_outline_color"]
|
||||
|
||||
Reference in New Issue
Block a user