This commit is contained in:
Rowland 2026-01-22 11:13:01 +08:00
parent 99ef5c0253
commit 30a5669bc5
2 changed files with 4036 additions and 3995 deletions

10
demo.py
View File

@ -3973,6 +3973,9 @@ class MyWorld(CoreWorld):
if gui_element in self.gui_manager.gui_elements:
self.gui_manager.gui_elements.remove(gui_element)
# 获取节点名称(在删除之前)
node_name = node.getName() if not node.isEmpty() else '未命名节点'
# 删除节点本身
node.removeNode()
@ -3982,7 +3985,7 @@ class MyWorld(CoreWorld):
self.selection.clearSelection()
# 添加成功消息
self.add_success_message(f"已删除节点: {node.getName() or '未命名节点'}")
self.add_success_message(f"已删除节点: {node_name}")
def _copy_node(self, node):
"""复制节点"""
@ -4204,6 +4207,11 @@ class MyWorld(CoreWorld):
text_node.setAlign(TextNode.ACenter)
text_node.setTextColor(1, 1, 1, 1) # 白色
# 设置中文字体
chinese_font = self._get_chinese_font()
if chinese_font:
text_node.setFont(chinese_font)
# 创建节点路径并设置位置
text_np = NodePath(text_node)
text_np.reparentTo(self.render)

View File

@ -124,6 +124,36 @@ class GUIManager:
print("✓ GUI管理系统初始化完成")
def _get_chinese_font(self):
"""获取中文字体用于3D文本显示"""
try:
from panda3d.core import TextNode
from pathlib import Path
# 尝试不同的中文字体路径
font_paths = [
"/usr/share/fonts/truetype/wqy/wqy-microhei.ttc", # Linux 文泉驿
"/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc", # Linux Noto
"/System/Library/Fonts/PingFang.ttc", # macOS
"C:/Windows/Fonts/msyh.ttc", # Windows 微软雅黑
"C:/Windows/Fonts/simhei.ttf", # Windows 黑体
]
for font_path in font_paths:
if Path(font_path).exists():
font = TextNode.getFont(font_path)
if font:
print(f"✓ 为3D文本加载中文字体成功: {font_path}")
return font
# 如果都失败了,返回默认字体
print("⚠️ 无法加载中文字体,使用默认字体")
return None
except Exception as e:
print(f"⚠️ 加载中文字体失败: {e}")
return None
# ==================== GUI元素创建方法 ====================
def createGUIButton(self, pos=(0, 0, 0), text="按钮", size=(0.1,0.1,0.1)):
@ -727,8 +757,11 @@ class GUIManager:
textNode = TextNode(f'3d-text-{len(self.gui_elements)}')
textNode.setText(text)
textNode.setAlign(TextNode.ACenter)
if self.world.getChineseFont():
textNode.setFont(self.world.getChineseFont())
# 设置中文字体
chinese_font = self._get_chinese_font()
if chinese_font:
textNode.setFont(chinese_font)
# 挂载到选中的父节点
textNodePath = parent_node.attachNewNode(textNode)