This commit is contained in:
2025-05-08 23:57:22 +08:00
parent 24acc2a6f1
commit 7094a5886a
18 changed files with 442 additions and 583 deletions

View File

@@ -44,7 +44,7 @@ TOOL_WIDTH = config.TOOL_WIDTH
TOOL_HEIGHT = config.TOOL_HEIGHT
# Localization
from scripts.ui import localization
LANG = localization.LANG
TEXT = localization.TEXT
#========================================== FUNCTIONS ========================================
@@ -448,10 +448,10 @@ def update_raw_slider_value(value):
normalized_value = value / 100.0
# 获取UI实例并更新显示
from scripts.ui.behaviour import BehaviourUI
ui_instance = BehaviourUI.get_instance()
if ui_instance and hasattr(ui_instance, 'controls'):
ui_instance.controls["raw_slider_value"].setText(f"{normalized_value:.3f}")
from scripts.ui import behaviour
behaviour_ui = behaviour.BehaviourUI.get_instance()
if behaviour_ui and hasattr(behaviour_ui, 'controls'):
behaviour_ui.controls["raw_slider_value"].setText(f"{normalized_value:.3f}")
# 更新控制值
update_control_value(value)
@@ -472,10 +472,10 @@ def update_bs_slider_value(value):
normalized_value = value / 100.0
# 获取UI实例并更新显示
from scripts.ui.behaviour import BehaviourUI
ui_instance = BehaviourUI.get_instance()
if ui_instance and hasattr(ui_instance, 'controls'):
ui_instance.controls["bs_slider_value"].setText(f"{normalized_value:.3f}")
from scripts.ui import behaviour
behaviour_ui = behaviour.BehaviourUI.get_instance()
if behaviour_ui and hasattr(behaviour_ui, 'controls'):
behaviour_ui.controls["bs_slider_value"].setText(f"{normalized_value:.3f}")
# 更新BlendShape值
update_blendshape_value(value)
@@ -496,10 +496,10 @@ def update_bottom_slider_value(value):
normalized_value = value / 100.0
# 获取UI实例并更新显示
from scripts.ui.behaviour import BehaviourUI
ui_instance = BehaviourUI.get_instance()
if ui_instance and hasattr(ui_instance, 'controls'):
ui_instance.controls["bottom_slider_value"].setText(f"{normalized_value:.3f}")
from scripts.ui import behaviour
behaviour_ui = behaviour.BehaviourUI.get_instance()
if behaviour_ui and hasattr(behaviour_ui, 'controls'):
behaviour_ui.controls["bottom_slider_value"].setText(f"{normalized_value:.3f}")
# 更新主值
update_main_value(value)

View File

@@ -44,7 +44,7 @@ TOOL_WIDTH = config.TOOL_WIDTH
TOOL_HEIGHT = config.TOOL_HEIGHT
# Localization
from scripts.ui import localization
LANG = localization.LANG
TEXT = localization.TEXT
#========================================== FUNCTIONS ========================================
# 左侧面板功能

View File

@@ -44,7 +44,7 @@ TOOL_WIDTH = config.TOOL_WIDTH
TOOL_HEIGHT = config.TOOL_HEIGHT
# Localization
from scripts.ui import localization
LANG = localization.LANG
TEXT = localization.TEXT
#========================================== FUNCTIONS ========================================
# 左侧面板功能
@@ -439,15 +439,15 @@ def clean():
# 确认删除
result = cmds.confirmDialog(
title=LANG.get("confirm_delete", "确认删除"),
message=LANG.get("delete_lod_confirm", f"确定要删除{lod_name}吗?"),
button=[LANG.get("yes", ""), LANG.get("no", "")],
defaultButton=LANG.get("no", ""),
cancelButton=LANG.get("no", ""),
dismissString=LANG.get("no", "")
title=TEXT("confirm_delete", "确认删除"),
message=TEXT("delete_lod_confirm", f"确定要删除{lod_name}吗?"),
button=[TEXT("yes", ""), TEXT("no", "")],
defaultButton=TEXT("no", ""),
cancelButton=TEXT("no", ""),
dismissString=TEXT("no", "")
)
if result == LANG.get("yes", ""):
if result == TEXT("yes", ""):
# 删除与该LOD相关的所有模型
nodes_to_delete = cmds.ls(f"{lod_name}_*")
if nodes_to_delete:
@@ -548,7 +548,7 @@ def separate_model():
# 获取当前选中的模型
selected_models = cmds.ls(selection=True, type="transform")
if not selected_models:
cmds.warning(LANG.get("no_model_selected", "未选中模型"))
cmds.warning(TEXT("no_model_selected", "未选中模型"))
return False
# 对每个选中的模型进行分离
@@ -572,7 +572,7 @@ def fix_normals():
# 获取当前选中的模型
selected_models = cmds.ls(selection=True, type="transform")
if not selected_models:
cmds.warning(LANG.get("no_model_selected", "未选中模型"))
cmds.warning(TEXT("no_model_selected", "未选中模型"))
return False
# 对每个选中的模型修复法线
@@ -626,7 +626,7 @@ def modify_topology():
# 获取当前选中的模型
selected_models = cmds.ls(selection=True, type="transform")
if not selected_models:
cmds.warning(LANG.get("no_model_selected", "未选中模型"))
cmds.warning(TEXT("no_model_selected", "未选中模型"))
return False
# 切换到多边形编辑模式
@@ -649,7 +649,7 @@ def generate_face_components():
# 获取当前选中的模型
selected_models = cmds.ls(selection=True, type="transform")
if not selected_models:
cmds.warning(LANG.get("no_model_selected", "未选中模型"))
cmds.warning(TEXT("no_model_selected", "未选中模型"))
return False
# 生成眉毛
@@ -676,7 +676,7 @@ def generate_uvs():
# 获取当前选中的模型
selected_models = cmds.ls(selection=True, type="transform")
if not selected_models:
cmds.warning(LANG.get("no_model_selected", "未选中模型"))
cmds.warning(TEXT("no_model_selected", "未选中模型"))
return False
# 为每个选中的模型生成UV

View File

@@ -44,7 +44,7 @@ TOOL_WIDTH = config.TOOL_WIDTH
TOOL_HEIGHT = config.TOOL_HEIGHT
# Localization
from scripts.ui import localization
LANG = localization.LANG
TEXT = localization.TEXT
#========================================== GLOBALS ========================================
# 存储当前选中的关节和控制器信息

View File

@@ -39,10 +39,7 @@ TOOL_WIDTH = config.TOOL_WIDTH
TOOL_HEIGHT = config.TOOL_HEIGHT
# Localization
from scripts.ui import localization
LANG = localization.LANG
# 添加全局变量记录当前语言
current_language = "zh_CN" # 默认使用中文
TEXT = localization.TEXT
#========================================== FUNCTIONS ========================================
@@ -57,7 +54,7 @@ def save_dna():
fileFilter="DNA Files (*.dna);;All Files (*.*)",
dialogStyle=2,
fileMode=0,
caption=LANG.get("save_dna", "保存DNA文件")
caption=TEXT("save_dna", "保存DNA文件")
)
if file_path and len(file_path) > 0:
@@ -77,7 +74,7 @@ def open_dna():
fileFilter="DNA Files (*.dna);;All Files (*.*)",
dialogStyle=2,
fileMode=1,
caption=LANG.get("open_dna", "打开DNA文件")
caption=TEXT("open_dna", "打开DNA文件")
)
if file_path and len(file_path) > 0:
@@ -123,7 +120,7 @@ def import_skin():
fileFilter="Skin Files (*.skin);;XML Files (*.xml);;All Files (*.*)",
dialogStyle=2,
fileMode=1,
caption=LANG.get("import_skin", "导入蒙皮")
caption=TEXT("import_skin", "导入蒙皮")
)
if file_path and len(file_path) > 0:
@@ -143,7 +140,7 @@ def export_skin():
fileFilter="Skin Files (*.skin);;XML Files (*.xml);;All Files (*.*)",
dialogStyle=2,
fileMode=0,
caption=LANG.get("export_skin", "导出蒙皮")
caption=TEXT("export_skin", "导出蒙皮")
)
if file_path and len(file_path) > 0:
@@ -174,8 +171,8 @@ def show_help():
try:
# 打开帮助文档或显示帮助对话框
help_dialog = QtWidgets.QMessageBox()
help_dialog.setWindowTitle(LANG.get("help_title", "帮助"))
help_dialog.setText(LANG.get("help_message", "该插件是一个用于自定义MetaHuman的Maya插件。\n\n详细信息请参考文档。"))
help_dialog.setWindowTitle(TEXT("help_title", "帮助"))
help_dialog.setText(TEXT("help_message", "该插件是一个用于自定义MetaHuman的Maya插件。\n\n详细信息请参考文档。"))
help_dialog.setStandardButtons(QtWidgets.QMessageBox.Ok)
help_dialog.exec_()
except Exception as e:
@@ -302,10 +299,10 @@ def show_help():
webbrowser.open(config.TOOL_HELP_URL)
else:
cmds.confirmDialog(
title=LANG.get("help", "帮助"),
message=LANG.get("help_not_available", "帮助文档暂不可用"),
button=[LANG.get("ok", "确定")],
defaultButton=LANG.get("ok", "确定")
title=TEXT("help", "帮助"),
message=TEXT("help_not_available", "帮助文档暂不可用"),
button=[TEXT("ok", "确定")],
defaultButton=TEXT("ok", "确定")
)
except Exception as e:
print(f"显示帮助信息时出错: {e}")
@@ -360,15 +357,12 @@ def toggle_language():
"""
from scripts.ui import localization
import config
from ui.Qt import QtWidgets
from scripts.ui.Qt import QtWidgets
# 使用localization模块来切换语言
new_language = localization.switch_language()
# 更新配置
config.TOOL_LANG = new_language
# 尝试更新已有窗口的语言,而不重启窗口
try:
# 查找主窗口
main_window = None
@@ -376,37 +370,33 @@ def toggle_language():
if widget.objectName() == f"{config.TOOL_NAME}MainWindow" and isinstance(widget, QtWidgets.QWidget):
main_window = widget
break
if main_window:
# 更新主窗口标题
main_window.setWindowTitle(f"{config.TOOL_NAME} {config.TOOL_VERSION}")
# 获取各个UI实例并更新语言
from scripts.ui import geometry, rigging, behaviour, definition, toolbar
# 更新各个模块的UI
if hasattr(geometry, 'GeometryUI') and geometry.GeometryUI.get_instance():
geometry.GeometryUI.get_instance().update_language()
if hasattr(rigging, 'RiggingUI') and rigging.RiggingUI.get_instance():
rigging.RiggingUI.get_instance().update_language()
if hasattr(behaviour, 'BehaviourUI') and behaviour.BehaviourUI.get_instance():
behaviour.BehaviourUI.get_instance().update_language()
if hasattr(definition, 'DefinitionUI') and definition.DefinitionUI.get_instance():
definition.DefinitionUI.get_instance().update_language()
# 更新工具栏
if hasattr(toolbar, 'ToolbarUI') and hasattr(main_window, 'toolbar_ui'):
main_window.toolbar_ui.update_language()
# 遍历主窗口的所有子控件,批量动态更新语言
for child in main_window.findChildren(QtWidgets.QWidget):
# 只要有update_language方法就调用
if hasattr(child, 'update_language') and callable(child.update_language):
try:
child.update_language()
except Exception as e:
print(f"更新语言失败: {child}: {e}")
# 更新功能按钮文字
if hasattr(main_window, 'function_buttons'):
for key, button in main_window.function_buttons.items():
button.setText(localization.get_text(key))
button.setText(localization.TEXT(key))
print(f"语言已切换到: {new_language}")
# 切换语言后强制重载主窗口保证所有UI和控件100%刷新
from scripts.Main import main
for widget in QtWidgets.QApplication.allWidgets():
if widget.objectName() == f"{config.TOOL_NAME}MainWindow" and isinstance(widget, QtWidgets.QWidget):
widget.close()
main()
return
except Exception as e:
print(f"动态更新语言失败,将重启窗口: {e}")