From d6bdd98a76ab6a5d4f04228dded73b4acae43fa9 Mon Sep 17 00:00:00 2001 From: shenjack <3695888@qq.com> Date: Thu, 19 Jan 2023 16:32:36 +0800 Subject: [PATCH] =?UTF-8?q?SR1=20=E6=B8=B2=E6=9F=93=E5=BA=94=E8=AF=A5?= =?UTF-8?q?=E5=AE=8C=E4=BA=8B=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Difficult_Rocket/__init__.py | 7 ++-- Difficult_Rocket/api/types/SR1/__init__.py | 5 ++- Difficult_Rocket/client/render/sr1_ship.py | 37 +++++++++++++++------- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/Difficult_Rocket/__init__.py b/Difficult_Rocket/__init__.py index ce638e0..c7fed62 100644 --- a/Difficult_Rocket/__init__.py +++ b/Difficult_Rocket/__init__.py @@ -10,8 +10,9 @@ mail: 3695888@qq.com github: @shenjackyuanjie gitee: @shenjackyuanjie """ -import ctypes +# import ctypes import logging +from typing import List, Dict, Union, Optional from Difficult_Rocket.api.types import Options @@ -53,7 +54,7 @@ class _DR_option(Options): crash_report_test: bool = True # window option - gui_scale: int = 1 # default 1 2 -> 2x 3 -> 3x + gui_scale: float = 1.0 # default 1 2 -> 2x 3 -> 3x class _DR_runtime(Options): @@ -61,7 +62,7 @@ class _DR_runtime(Options): DR 的运行时配置 """ name = 'DR Runtime' - # game statue + # game status DR_version: Version = game_version Build_version: Version = build_version DR_long_version: int = long_version diff --git a/Difficult_Rocket/api/types/SR1/__init__.py b/Difficult_Rocket/api/types/SR1/__init__.py index fe75c81..47ff09b 100644 --- a/Difficult_Rocket/api/types/SR1/__init__.py +++ b/Difficult_Rocket/api/types/SR1/__init__.py @@ -37,7 +37,10 @@ class SR1Textures(Options): super().__init__(**kwargs) self.flush_option() for image_name in self.cached_options: - setattr(self, image_name, load(f'textures/parts/{image_name}.png')) + img = load(f'textures/parts/{image_name}.png') + img.anchor_x = img.width // 2 + img.anchor_y = img.height // 2 + setattr(self, image_name, img) self.flush_option() def get_texture(self, name: str): diff --git a/Difficult_Rocket/client/render/sr1_ship.py b/Difficult_Rocket/client/render/sr1_ship.py index 0de25eb..f481474 100644 --- a/Difficult_Rocket/client/render/sr1_ship.py +++ b/Difficult_Rocket/client/render/sr1_ship.py @@ -4,8 +4,9 @@ # All rights reserved # ------------------------------- +import math from xml.etree import ElementTree -from typing import List, TYPE_CHECKING, Union +from typing import List, TYPE_CHECKING, Union, Dict # third party package from defusedxml.ElementTree import parse @@ -38,7 +39,7 @@ class SR1ShipRender(BaseScreen): self.part_batch = Batch() self.part_group = Group() self.part_data = {} - self.parts_sprite = {} + self.parts_sprite: Dict[int, Sprite] = {} def load_textures(self): self.textures = SR1Textures() @@ -80,18 +81,32 @@ class SR1ShipRender(BaseScreen): editor_angle=part_editor_angle, flip_x=part_flip_x, flip_y=part_flip_y, explode=part_explode, textures=part_textures) self.part_data[part_id] = part_data - self.parts_sprite[part_id] = Sprite(img=self.textures.get_texture(part_data.textures), - x=10, y=10, batch=self.part_batch, group=self.part_group) + # 下面就是调用 pyglet 去渲染的部分 + render_scale = DR_option.gui_scale # 这个是 DR 的缩放比例 可以调节的( + # 主要是 Windows 下有一个缩放系数嘛,我待会试试这玩意能不能获取(估计得 ctypes + # 在不缩放的情况下,XML的1个单位长度对应60个像素 + render_x = part_x * render_scale * 60 + self.window_pointer.width / 2 + render_y = part_y * render_scale * 60 + self.window_pointer.height / 2 + # 你就这里改吧 + cache_sprite = Sprite(img=self.textures.get_texture(part_data.textures), + x=render_x, y=render_y, + batch=self.part_batch, group=self.part_group) + # 你得帮我换算一下 XML 里的 x y 和这里的屏幕像素的关系(OK + # 旋转啥的不是大问题, 我找你要那个渲染代码就是要 x y 的换算逻辑 + if part_flip_x: + cache_sprite.scale_x = -cache_sprite.scale_x # 就是直接取反缩放,应该没问题····吧?(待会试试就知道了 + if part_flip_y: + cache_sprite.scale_y = -cache_sprite.scale_y + cache_sprite.x = cache_sprite.x - cache_sprite.scale_x / 2 + cache_sprite.y = cache_sprite.y - cache_sprite.scale_y / 2 + cache_sprite.rotation = part_data.angle / math.pi * 180 + if not part_render: # 如果不渲染(渲染有毛病) + self.parts_sprite[part_id].visible = False + + self.parts_sprite[part_id] = cache_sprite def on_draw(self): self.part_batch.draw() def on_file_drop(self, x: int, y: int, paths: List[str]): - self.scale = DR_option.gui_scale self.render_ship() - ... - - def on_command(self, command: CommandText): - if command.match('render'): - print('rua, render ship!') - self.render_ship()