SR1 渲染应该完事了
This commit is contained in:
parent
21cdb03aef
commit
d6bdd98a76
@ -10,8 +10,9 @@ mail: 3695888@qq.com
|
|||||||
github: @shenjackyuanjie
|
github: @shenjackyuanjie
|
||||||
gitee: @shenjackyuanjie
|
gitee: @shenjackyuanjie
|
||||||
"""
|
"""
|
||||||
import ctypes
|
# import ctypes
|
||||||
import logging
|
import logging
|
||||||
|
from typing import List, Dict, Union, Optional
|
||||||
|
|
||||||
from Difficult_Rocket.api.types import Options
|
from Difficult_Rocket.api.types import Options
|
||||||
|
|
||||||
@ -53,7 +54,7 @@ class _DR_option(Options):
|
|||||||
crash_report_test: bool = True
|
crash_report_test: bool = True
|
||||||
|
|
||||||
# window option
|
# 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):
|
class _DR_runtime(Options):
|
||||||
@ -61,7 +62,7 @@ class _DR_runtime(Options):
|
|||||||
DR 的运行时配置
|
DR 的运行时配置
|
||||||
"""
|
"""
|
||||||
name = 'DR Runtime'
|
name = 'DR Runtime'
|
||||||
# game statue
|
# game status
|
||||||
DR_version: Version = game_version
|
DR_version: Version = game_version
|
||||||
Build_version: Version = build_version
|
Build_version: Version = build_version
|
||||||
DR_long_version: int = long_version
|
DR_long_version: int = long_version
|
||||||
|
@ -37,7 +37,10 @@ class SR1Textures(Options):
|
|||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.flush_option()
|
self.flush_option()
|
||||||
for image_name in self.cached_options:
|
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()
|
self.flush_option()
|
||||||
|
|
||||||
def get_texture(self, name: str):
|
def get_texture(self, name: str):
|
||||||
|
@ -4,8 +4,9 @@
|
|||||||
# All rights reserved
|
# All rights reserved
|
||||||
# -------------------------------
|
# -------------------------------
|
||||||
|
|
||||||
|
import math
|
||||||
from xml.etree import ElementTree
|
from xml.etree import ElementTree
|
||||||
from typing import List, TYPE_CHECKING, Union
|
from typing import List, TYPE_CHECKING, Union, Dict
|
||||||
|
|
||||||
# third party package
|
# third party package
|
||||||
from defusedxml.ElementTree import parse
|
from defusedxml.ElementTree import parse
|
||||||
@ -38,7 +39,7 @@ class SR1ShipRender(BaseScreen):
|
|||||||
self.part_batch = Batch()
|
self.part_batch = Batch()
|
||||||
self.part_group = Group()
|
self.part_group = Group()
|
||||||
self.part_data = {}
|
self.part_data = {}
|
||||||
self.parts_sprite = {}
|
self.parts_sprite: Dict[int, Sprite] = {}
|
||||||
|
|
||||||
def load_textures(self):
|
def load_textures(self):
|
||||||
self.textures = SR1Textures()
|
self.textures = SR1Textures()
|
||||||
@ -80,18 +81,32 @@ class SR1ShipRender(BaseScreen):
|
|||||||
editor_angle=part_editor_angle, flip_x=part_flip_x,
|
editor_angle=part_editor_angle, flip_x=part_flip_x,
|
||||||
flip_y=part_flip_y, explode=part_explode, textures=part_textures)
|
flip_y=part_flip_y, explode=part_explode, textures=part_textures)
|
||||||
self.part_data[part_id] = part_data
|
self.part_data[part_id] = part_data
|
||||||
self.parts_sprite[part_id] = Sprite(img=self.textures.get_texture(part_data.textures),
|
# 下面就是调用 pyglet 去渲染的部分
|
||||||
x=10, y=10, batch=self.part_batch, group=self.part_group)
|
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):
|
def on_draw(self):
|
||||||
self.part_batch.draw()
|
self.part_batch.draw()
|
||||||
|
|
||||||
def on_file_drop(self, x: int, y: int, paths: List[str]):
|
def on_file_drop(self, x: int, y: int, paths: List[str]):
|
||||||
self.scale = DR_option.gui_scale
|
|
||||||
self.render_ship()
|
self.render_ship()
|
||||||
...
|
|
||||||
|
|
||||||
def on_command(self, command: CommandText):
|
|
||||||
if command.match('render'):
|
|
||||||
print('rua, render ship!')
|
|
||||||
self.render_ship()
|
|
||||||
|
Loading…
Reference in New Issue
Block a user