From 5d2f1f568a79599b855e3b763110ed204c21c48a Mon Sep 17 00:00:00 2001 From: march3 Date: Fri, 17 Mar 2023 16:45:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=AA=E9=98=B3=E7=B3=BB=E4=B8=89=E4=BD=93?= =?UTF-8?q?=E6=A8=A1=E6=8B=9F=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- simulators/ursina/ursina_ui.py | 30 ++++++++++++++++++++++++++++-- simulators/ursina_simulator.py | 16 ++++++++++++++-- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/simulators/ursina/ursina_ui.py b/simulators/ursina/ursina_ui.py index 61a54f5..5e1e79a 100644 --- a/simulators/ursina/ursina_ui.py +++ b/simulators/ursina/ursina_ui.py @@ -7,14 +7,14 @@ # python_version :3.8 # ============================================================================== from ursina import Ursina, window, Entity, Grid, Mesh, camera, Text, application, color, mouse, Vec2, Vec3, \ - load_texture, held_keys, Button, ButtonList, destroy, scene, distance + load_texture, held_keys, Button, ButtonList, destroy, scene, distance, Sequence, Wait, Func from ursina.prefabs.first_person_controller import FirstPersonController from common.consts import AU from simulators.ursina.ui_component import UiSlider, SwithButton, UiButton from simulators.ursina.ursina_config import UrsinaConfig from simulators.ursina.ursina_event import UrsinaEvent -from ursina import WindowPanel, InputField, Button, Slider, ButtonGroup, Panel +from ursina import WindowPanel, InputField, Button, Slider, ButtonGroup, Panel, invoke class UrsinaUI: @@ -121,6 +121,28 @@ class UrsinaUI: # slider_text = Text(text='自转速度', scale=1, position=(-0.6, 0.3)) # slider = Slider(scale=0.5, position=(-0.6, 0), min=0, max=10, step=1, text=slider_text) + def show_message(self, message, close_time=3): + """ + 创建消息框 + :param message: 消息内容 + :param close_time: 定义关闭时间 + :return: + """ + # 创建消息框 + message_box = Text(text=message, font=UrsinaConfig.CN_FONT, background=True, origin=(0, 0), y=.25) + + # 定义关闭函数 + def close_message(): + destroy(message_box) + + s = Sequence( + Wait(3), + Func(close_message) + ) + s.start() + # # 使用 time 模块来实现定时关闭 + # invoke(close_message, delay=close_time) + def on_off_trail_changed(self): if self.on_off_trail.value == self.trail_button_text: UrsinaConfig.show_trail = True @@ -154,6 +176,10 @@ class UrsinaUI: results = UrsinaEvent.on_searching_bodies() if len(results) > 0: sub_name, bodies = results[0] + if len(bodies) == 0: + self.show_message("天体都飞不见了,请重新运行。") + # button_dict = {"天体都飞不见了,请重新运行。": lambda: self.bodies_button_list_click(None)} + return # print(results[0]) button_dict = {"[关闭]": lambda: self.bodies_button_list_click(None)} camera = scene.camera diff --git a/simulators/ursina_simulator.py b/simulators/ursina_simulator.py index bea805d..59a2637 100644 --- a/simulators/ursina_simulator.py +++ b/simulators/ursina_simulator.py @@ -20,6 +20,7 @@ from common.system import System import time import datetime import math +import os from ursina import EditorCamera, PointLight, SpotLight, AmbientLight, DirectionalLight from scenes.func import ursina_run @@ -66,7 +67,6 @@ class UrsinaSimulator(Simulator): views.append(view) return views - def check_elapsed_time(self): """检查时间间隔是否已过""" now = datetime.datetime.now() @@ -154,6 +154,17 @@ class UrsinaSimulator(Simulator): return lights + def switch_to_english_input_method(self): + pass + # os.system("powershell -Command \"Set-WinUserLanguageList -LanguageList 'en-US', 'zh-CN' -Force\"") + + # if os.name == 'nt': # Windows 系统 + # os.system('powershell -Command "Set-WinUserLanguageList en-US -Force"') + # elif os.name == 'posix': # macOS 或 Linux 系统 + # os.system( + # 'defaults write ~/Library/Preferences/com.apple.HIToolbox.plist AppleSelectedInputSources -array-add \'{ "InputSourceKind" = "Keyboard Layout"; "KeyboardLayout ID" = 252; "KeyboardLayout Name" = "ABC"; }\'') + # os.system('killall cfprefsd') # 重启 CoreFoundation 进程使更改生效 + def run(self, dt, **kwargs): window.title = '宇宙模拟器' @@ -191,7 +202,8 @@ class UrsinaSimulator(Simulator): ui = UrsinaUI() EditorCamera(ignore_paused=True) - + # 防止打开中文输入法 + # self.switch_to_english_input_method() self.app.run() -- GitLab