From 8e61db6a12e2cc4399ecd62a4b2dbcf6183e7c01 Mon Sep 17 00:00:00 2001 From: march3 Date: Sat, 10 Jun 2023 17:26:28 +0800 Subject: [PATCH] =?UTF-8?q?Python=E8=B6=85=E4=BA=BA-=E5=AE=87=E5=AE=99?= =?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 --- sim_scenes/func.py | 5 ++++- .../solar_system/sun_future_evolution.py | 2 +- simulators/ursina/entities/timer.py | 4 +++- simulators/ursina_simulator.py | 20 +++++++++++++------ 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/sim_scenes/func.py b/sim_scenes/func.py index c43153c..8566f19 100644 --- a/sim_scenes/func.py +++ b/sim_scenes/func.py @@ -115,6 +115,7 @@ def ursina_run(bodies, show_trail=False, show_name=False, show_timer=False, + timer_enabled=False, save_as_json=None, view_closely=False): """ @@ -128,6 +129,7 @@ def ursina_run(bodies, @param show_trail: 是否显示拖尾 @param show_name: 是否显示天体名称 @param show_timer: 是否显示计时器 + @param timer_enabled: 计时器是否有效 @param save_as_json: 将所有天体的信息保存为 json 文件 @param view_closely: 是否近距离查看天体 @return: @@ -170,6 +172,7 @@ def ursina_run(bodies, cosmic_bg=cosmic_bg, show_grid=show_grid, show_timer=show_timer, + timer_enabled=timer_enabled, bg_music=bg_music, view_closely=view_closely) @@ -222,7 +225,7 @@ def create_solar_system_bodies(ignore_mass=False, init_velocity=None): Mercury(name="水星", size_scale=0.3e3), # 水星放大 300 倍,距离保持不变 Venus(name="金星", size_scale=0.3e3), # 金星放大 300 倍,距离保持不变 Earth(name="地球", size_scale=0.3e3), # 地球放大 300 倍,距离保持不变 - Moon(name="月球", init_position=[0, 0, 363104 + AU], + Moon(name="月球", init_position=[0, 0, 363104 + AU], size_scale=0.3e3), # 月球放大 300 倍,距离保持不变 Mars(name="火星", size_scale=0.3e3), # 火星放大 300 倍,距离保持不变 # Asteroids(name="小行星群", size_scale=3.2e2, diff --git a/sim_scenes/solar_system/sun_future_evolution.py b/sim_scenes/solar_system/sun_future_evolution.py index e9fbf6f..3bf4879 100644 --- a/sim_scenes/solar_system/sun_future_evolution.py +++ b/sim_scenes/solar_system/sun_future_evolution.py @@ -56,5 +56,5 @@ if __name__ == '__main__': # 常用快捷键: P:运行和暂停 O:重新开始 I:显示天体轨迹 # position = 左-右+、上+下-、前+后- ursina_run(bodies, SECONDS_PER_YEAR, position=(0, 10 * AU, -10 * AU), - show_timer=True, + timer_enabled=True, bg_music="sounds/interstellar.mp3") diff --git a/simulators/ursina/entities/timer.py b/simulators/ursina/entities/timer.py index 739026f..2031f26 100644 --- a/simulators/ursina/entities/timer.py +++ b/simulators/ursina/entities/timer.py @@ -16,12 +16,14 @@ from simulators.ursina.ursina_event import UrsinaEvent class Timer(Text): - def __init__(self): + def __init__(self, show=True): # 创建一个文本对象来显示计时器的时间 super().__init__(text=' ', position=(0.70, -0.465), origin=(-0.5, 0.5), font=UrsinaConfig.CN_FONT, background=True) UrsinaEvent.on_timer_changed_subscription(self.on_timer_changed) + if not show: + self.enabled = False def on_timer_changed(self, time_data: TimeData): self.text = time_data.time_text diff --git a/simulators/ursina_simulator.py b/simulators/ursina_simulator.py index f3e46d5..7fdc378 100644 --- a/simulators/ursina_simulator.py +++ b/simulators/ursina_simulator.py @@ -209,14 +209,14 @@ class UrsinaSimulator(Simulator): evolve_dt = evolve_dt * self.interval_fator super().evolve(evolve_dt) - if self.show_timer: + if self.show_timer or self.timer_enabled: timer = BodyTimer() timer.calc_time(evolve_dt) - def create_timer(self): + def create_timer(self, show=True): from simulators.ursina.entities.timer import Timer # 创建一个文本对象来显示计时器的时间 - self.timer = Timer() + self.timer = Timer(show) return self.timer def cosmic_background(self, texture='../textures/cosmic2.jpg'): @@ -262,6 +262,10 @@ class UrsinaSimulator(Simulator): if "show_timer" in kwargs: self.show_timer = kwargs["show_timer"] + self.timer_enabled = False + if "timer_enabled" in kwargs: + self.timer_enabled = kwargs["timer_enabled"] + if view_closely: # 近距离查看 if isinstance(view_closely, float): @@ -314,9 +318,13 @@ class UrsinaSimulator(Simulator): if cosmic_bg is not None and os.path.exists(cosmic_bg): self.cosmic_background(cosmic_bg) - if self.show_timer: - self.create_timer() + self.timer_enabled = True + # 创建和显示计时器 + self.create_timer(True) + elif self.timer_enabled: + # 创建计时器,但是不显示 + self.create_timer(False) # 防止打开中文输入法 # self.switch_to_english_input_method() @@ -346,7 +354,7 @@ class UrsinaSimulator(Simulator): EditorCamera(ignore_paused=True) - if self.show_timer: + if self.show_timer or self.timer_enabled: UrsinaEvent.on_reset() UrsinaEvent.on_ready() -- GitLab