[Refactor] Improve overlay image creation logic for large logs and translations
This commit is contained in:
@@ -340,11 +340,25 @@ class Controller:
|
|||||||
model.logger.info(f"[SENT] {message}{translation}")
|
model.logger.info(f"[SENT] {message}{translation}")
|
||||||
|
|
||||||
if config.OVERLAY_LARGE_LOG is True and model.overlay.initialized is True:
|
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:
|
if config.OVERLAY_SHOW_ONLY_TRANSLATED_MESSAGES is True:
|
||||||
overlay_image = model.createOverlayImageLargeLog("send", translation[0], "")
|
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:
|
else:
|
||||||
overlay_image = model.createOverlayImageLargeLog("send", message, translation[0] if len(translation) > 0 else "")
|
overlay_image = model.createOverlayImageLargeLog(
|
||||||
model.updateOverlayLargeLog(overlay_image)
|
"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:
|
def speakerMessage(self, result:dict) -> None:
|
||||||
message = result["text"]
|
message = result["text"]
|
||||||
@@ -425,11 +439,24 @@ class Controller:
|
|||||||
model.updateOverlaySmallLog(overlay_image)
|
model.updateOverlaySmallLog(overlay_image)
|
||||||
|
|
||||||
if config.OVERLAY_LARGE_LOG is True and model.overlay.initialized is True:
|
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:
|
if config.OVERLAY_SHOW_ONLY_TRANSLATED_MESSAGES is True:
|
||||||
overlay_image = model.createOverlayImageLargeLog("receive", translation[0], "")
|
if len(translation) > 0:
|
||||||
|
overlay_image = model.createOverlayImageLargeLog(
|
||||||
|
"receive",
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
translation,
|
||||||
|
)
|
||||||
|
model.updateOverlayLargeLog(overlay_image)
|
||||||
else:
|
else:
|
||||||
overlay_image = model.createOverlayImageLargeLog("receive", message, translation[0] if len(translation) > 0 else "")
|
overlay_image = model.createOverlayImageLargeLog(
|
||||||
model.updateOverlayLargeLog(overlay_image)
|
"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:
|
if config.SEND_RECEIVED_MESSAGE_TO_VRC is True:
|
||||||
osc_message = self.messageFormatter("RECEIVED", translation, [message])
|
osc_message = self.messageFormatter("RECEIVED", translation, [message])
|
||||||
@@ -544,11 +571,25 @@ class Controller:
|
|||||||
model.oscSendMessage(osc_message)
|
model.oscSendMessage(osc_message)
|
||||||
|
|
||||||
if config.OVERLAY_LARGE_LOG is True:
|
if config.OVERLAY_LARGE_LOG is True:
|
||||||
if config.OVERLAY_SHOW_ONLY_TRANSLATED_MESSAGES is True and len(translation) > 0:
|
if config.OVERLAY_SHOW_ONLY_TRANSLATED_MESSAGES is True:
|
||||||
overlay_image = model.createOverlayImageLargeLog("send", translation[0], "")
|
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:
|
else:
|
||||||
overlay_image = model.createOverlayImageLargeLog("send", message, translation[0] if len(translation) > 0 else "")
|
overlay_image = model.createOverlayImageLargeLog(
|
||||||
model.updateOverlayLargeLog(overlay_image)
|
"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:
|
if model.checkWebSocketServerAlive() is True:
|
||||||
model.websocketSendMessage(
|
model.websocketSendMessage(
|
||||||
|
|||||||
@@ -769,10 +769,9 @@ class Model:
|
|||||||
if (self.overlay.settings[size]["ui_scaling"] != config.OVERLAY_SMALL_LOG_SETTINGS["ui_scaling"]):
|
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)
|
self.overlay.updateUiScaling(config.OVERLAY_SMALL_LOG_SETTINGS["ui_scaling"], size)
|
||||||
|
|
||||||
def createOverlayImageLargeLog(self, message_type:str, message:str, translation:str):
|
def createOverlayImageLargeLog(self, message_type:str, message:str, your_language:str, translation:list, target_languages:dict):
|
||||||
your_language = config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO]["1"]["language"]
|
target_languages = [data["language"] for data in target_languages.values() if data["enable"] is True]
|
||||||
target_language = config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO]["1"]["language"]
|
return self.overlay_image.createOverlayImageLargeLog(message_type, message, your_language, translation, target_languages)
|
||||||
return self.overlay_image.createOverlayImageLargeLog(message_type, message, your_language, translation, target_language)
|
|
||||||
|
|
||||||
def createOverlayImageLargeMessage(self, message):
|
def createOverlayImageLargeMessage(self, message):
|
||||||
ui_language = config.UI_LANGUAGE
|
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)
|
draw.text((text_x, text_y), text, text_color, anchor=anchor, stroke_width=0, font=font)
|
||||||
return img
|
return img
|
||||||
|
|
||||||
def createTextboxLargeLog(self, message_type:str, message:str, your_language:str, translation:str, target_language:str, date_time:str) -> Image:
|
def createTextboxLargeLog(self, message_type: str, message: str = None, your_language: str = None, translation: list = [], target_language: list = [], date_time: str = None) -> Image:
|
||||||
message_type_img = self.createTextImageMessageType(message_type, date_time)
|
# テキスト画像のリストを作成
|
||||||
if translation and target_language:
|
images = [self.createTextImageMessageType(message_type, date_time)]
|
||||||
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 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()
|
ui_color = self.getUiColorLargeLog()
|
||||||
background_color = ui_color["background_color"]
|
background_color = ui_color["background_color"]
|
||||||
background_outline_color = ui_color["background_outline_color"]
|
background_outline_color = ui_color["background_outline_color"]
|
||||||
|
|||||||
Reference in New Issue
Block a user