好耶! 现在ok了 缩放! 0.7.1.0!

This commit is contained in:
shenjack 2023-02-19 21:02:14 +08:00
parent 0a95312c12
commit 00d41941dd
8 changed files with 74 additions and 27 deletions

View File

@ -22,7 +22,7 @@ from Difficult_Rocket.api.types import Options
from libs.MCDR.version import Version from libs.MCDR.version import Version
game_version = Version("0.7.0.3") # 游戏版本 game_version = Version("0.7.1.0") # 游戏版本
build_version = Version("1.1.0.0") # 编译文件版本(与游戏本体无关) build_version = Version("1.1.0.0") # 编译文件版本(与游戏本体无关)
DR_rust_version = Version("0.2.5.0") # DR 的 Rust 编写部分的版本 DR_rust_version = Version("0.2.5.0") # DR 的 Rust 编写部分的版本
__version__ = game_version __version__ = game_version

View File

@ -14,6 +14,7 @@ from typing import List, TYPE_CHECKING, Union, Dict, Optional, Callable, Generat
from defusedxml.ElementTree import parse from defusedxml.ElementTree import parse
# pyglet # pyglet
from pyglet.math import Vec4
from pyglet.text import Label from pyglet.text import Label
from pyglet.shapes import Line from pyglet.shapes import Line
from pyglet.sprite import Sprite from pyglet.sprite import Sprite
@ -82,7 +83,7 @@ class SR1ShipRender(BaseScreen):
self.focus = True self.focus = True
self.need_draw = False self.need_draw = False
self.drawing = False self.drawing = False
self.gen_draw: Optional[Callable] = None self.gen_draw: Optional[Generator] = None
self.need_update_parts = False self.need_update_parts = False
self.dx = 0 self.dx = 0
self.dy = 0 self.dy = 0
@ -117,7 +118,7 @@ class SR1ShipRender(BaseScreen):
self.parts_sprite: Dict[int, Sprite] = {} self.parts_sprite: Dict[int, Sprite] = {}
if DR_option.use_DR_rust: if DR_option.use_DR_rust:
self.camera_rs = Camera_rs(main_window, self.camera_rs = Camera_rs(main_window,
min_zoom=(1 / 2) ** 6, max_zoom=10) min_zoom=(1 / 2) ** 10, max_zoom=10)
self.rust_parts = None self.rust_parts = None
def load_xml(self, file_path: str) -> bool: def load_xml(self, file_path: str) -> bool:
@ -253,13 +254,50 @@ class SR1ShipRender(BaseScreen):
return return
mouse_dx = x - (self.window_pointer.width / 2) mouse_dx = x - (self.window_pointer.width / 2)
mouse_dy = y - (self.window_pointer.height / 2) mouse_dy = y - (self.window_pointer.height / 2)
self.debug_mouse_line.x2, self.debug_mouse_line.y2 = x, y # 鼠标缩放位置相对于屏幕中心的位置
if self.camera_rs.zoom * (0.5 ** scroll_y) < 10: mouse_dx_d = mouse_dx - self.camera_rs.dx
self.camera_rs.zoom = self.camera_rs.zoom * (0.5 ** scroll_y) mouse_dy_d = mouse_dy - self.camera_rs.dy
self.camera_rs.dx += (mouse_dx - self.camera_rs.dx) * (1 - (0.5 ** scroll_y)) # 鼠标相对偏移量的偏移量
self.camera_rs.dy += (mouse_dy - self.camera_rs.dy) * (1 - (0.5 ** scroll_y)) if scroll_y > 0:
zoom_d = ((2 ** scroll_y) - 1) * 0.5 + 1
elif scroll_y == 0:
zoom_d = 1
else: else:
zoom_d = ((2 ** scroll_y) - 1) * 0.5 + 1
print(f"1: {self.camera_rs.zoom=} {self.camera_rs.dx} {self.camera_rs.dy} {scroll_y=}")
# 缩放的变换量
print(f'{self.camera_rs.zoom * zoom_d=}')
if self.camera_rs.zoom == 10:
if scroll_y >= 0:
self.camera_rs.dx += mouse_dx_d * 0.5
self.camera_rs.dy += mouse_dy_d * 0.5
else:
self.camera_rs.zoom *= zoom_d
self.camera_rs.dx += mouse_dx_d
self.camera_rs.dy += mouse_dy_d
else:
mouse_dx_d *= (1 - zoom_d)
mouse_dy_d *= (1 - zoom_d)
self.camera_rs.zoom *= zoom_d
if self.camera_rs.zoom * zoom_d >= 10:
zoom_d = 10 / self.camera_rs.zoom
self.camera_rs.zoom = 10 self.camera_rs.zoom = 10
self.camera_rs.dx += mouse_dx_d
self.camera_rs.dy += mouse_dy_d
# if self.camera_rs.zoom / (0.5 ** (scroll_y * 0.5)) <= 10:
# self.camera_rs.zoom = self.camera_rs.zoom / zoom_d
# self.camera_rs.dx -= (mouse_dx - self.camera_rs.dx) * (1 - zoom_d)
# self.camera_rs.dy -= (mouse_dy - self.camera_rs.dy) * (1 - zoom_d)
# elif self.camera_rs.zoom == 10:
# self.camera_rs.dx -= mouse_dx * (0.1 ** scroll_y)
# self.camera_rs.dy -= mouse_dy * (0.1 ** scroll_y)
# else:
# self.camera_rs.zoom = 10
# self.camera_rs.dx -= (mouse_dx - self.camera_rs.dx) * zoom_d
# self.camera_rs.dy -= (mouse_dy - self.camera_rs.dy) * zoom_d
print(f"{self.camera_rs.zoom=} {self.camera_rs.dx} {self.camera_rs.dy} {scroll_y=}")
self.debug_mouse_line.x2, self.debug_mouse_line.y2 = x, y
self.debug_mouse_delta_line.x2 = (mouse_dx - self.camera_rs.dx) * (1 - (0.5 ** scroll_y)) + ( self.debug_mouse_delta_line.x2 = (mouse_dx - self.camera_rs.dx) * (1 - (0.5 ** scroll_y)) + (
self.window_pointer.width / 2) self.window_pointer.width / 2)
self.debug_mouse_delta_line.y2 = (mouse_dy - self.camera_rs.dy) * (1 - (0.5 ** scroll_y)) + ( self.debug_mouse_delta_line.y2 = (mouse_dy - self.camera_rs.dy) * (1 - (0.5 ** scroll_y)) + (
@ -275,6 +313,7 @@ class SR1ShipRender(BaseScreen):
self.camera_rs.zoom = 1 self.camera_rs.zoom = 1
self.camera_rs.dx = 0 self.camera_rs.dx = 0
self.camera_rs.dy = 0 self.camera_rs.dy = 0
self.window_pointer.view = Vec4()
else: else:
self.need_draw = True self.need_draw = True
print('应该渲染飞船的') print('应该渲染飞船的')
@ -299,7 +338,7 @@ class SR1ShipRender(BaseScreen):
def screenshot(window): def screenshot(window):
from libs.pyglet.gl import GLubyte, GLint, GL_RGBA, GL_UNSIGNED_BYTE, \ from libs.pyglet.gl import GLubyte, GLint, GL_RGBA, GL_UNSIGNED_BYTE, \
glReadPixels, glGetIntegerv glReadPixels
# from libs.pyglet.gl.gl_compat import GL_AUX_BUFFERS, GL_AUX0 # from libs.pyglet.gl.gl_compat import GL_AUX_BUFFERS, GL_AUX0
import pyglet import pyglet
width = window.width width = window.width

View File

@ -17,9 +17,9 @@
## 版本 ## 版本
[![Generic badge](https://img.shields.io/badge/Release-0.7.0.2-blue.svg)](https://github.com/shenjackyuanjie/Difficult-Rocket/releases) [![Generic badge](https://img.shields.io/badge/Release-0.7.1.0-blue.svg)](https://github.com/shenjackyuanjie/Difficult-Rocket/releases)
[![Generic badge](https://img.shields.io/badge/Pre_Release-0.7.0.2-blue.svg)](https://github.com/shenjackyuanjie/Difficult-Rocket/releases) [![Generic badge](https://img.shields.io/badge/Pre_Release-0.7.1.0-blue.svg)](https://github.com/shenjackyuanjie/Difficult-Rocket/releases)
[![Generic badge](https://img.shields.io/badge/Devloping-0.7.1-blue.svg)](https://github.com/shenjackyuanjie/Difficult-Rocket/releases) [![Generic badge](https://img.shields.io/badge/Devloping-0.7.2-blue.svg)](https://github.com/shenjackyuanjie/Difficult-Rocket/releases)
## English README please look [here](./docs/README-en.md) ## English README please look [here](./docs/README-en.md)

View File

@ -8,8 +8,8 @@ fonts_folder = "libs/fonts"
[window] [window]
style = "None" style = "None"
width = 1802 width = 1173
height = 1211 height = 830
visible = true visible = true
gui_scale = 1 gui_scale = 1
caption = "Difficult Rocket v{DR_version}|DR_rs v{DR_Rust_get_version}" caption = "Difficult Rocket v{DR_version}|DR_rs v{DR_Rust_get_version}"

View File

@ -17,9 +17,9 @@
## Version ## Version
[![Generic badge](https://img.shields.io/badge/Release-0.7.0.2-blue.svg)](https://github.com/shenjackyuanjie/Difficult-Rocket/releases) [![Generic badge](https://img.shields.io/badge/Release-0.7.1.0-blue.svg)](https://github.com/shenjackyuanjie/Difficult-Rocket/releases)
[![Generic badge](https://img.shields.io/badge/Pre_Release-0.7.0.2-blue.svg)](https://github.com/shenjackyuanjie/Difficult-Rocket/releases) [![Generic badge](https://img.shields.io/badge/Pre_Release-0.7.1.0-blue.svg)](https://github.com/shenjackyuanjie/Difficult-Rocket/releases)
[![Generic badge](https://img.shields.io/badge/Devloping-0.7.1-blue.svg)](https://github.com/shenjackyuanjie/Difficult-Rocket/releases) [![Generic badge](https://img.shields.io/badge/Devloping-0.7.2-blue.svg)](https://github.com/shenjackyuanjie/Difficult-Rocket/releases)
## 中文README请移步 [这里](../README.md) ## 中文README请移步 [这里](../README.md)

View File

@ -10,14 +10,14 @@
## Readme First! ## Readme First!
##### most badge can be clicked and jump ##### most badge can be clicked and jump
[![Generic badge](https://img.shields.io/badge/SemVer-2.0.0-blue.svg)](https://Semver.org/) [![Generic badge](https://img.shields.io/badge/SemVer-2.0.0-blue.svg)](https://Semver.org/)
![Generic badge](https://img.shields.io/badge/Version-0.7.0.2-yellow.svg) ![Generic badge](https://img.shields.io/badge/Version-0.7.1.0-yellow.svg)
- [![Readme-github](https://img.shields.io/badge/Readme-Github-blue.svg?style=flat-square&logo=Github)](https://github.com/shenjackyuanjie/Difficult-Rocket) - [![Readme-github](https://img.shields.io/badge/Readme-Github-blue.svg?style=flat-square&logo=Github)](https://github.com/shenjackyuanjie/Difficult-Rocket)
- [![Readme-gitee](https://img.shields.io/badge/Readme-Gitee-blue.svg?style=flat-square&logo=Gitee)](https://gitee.com/shenjackyuanjie/Difficult-Rocket) - [![Readme-gitee](https://img.shields.io/badge/Readme-Gitee-blue.svg?style=flat-square&logo=Gitee)](https://gitee.com/shenjackyuanjie/Difficult-Rocket)
- [![Readme-gitee](https://img.shields.io/badge/Readme-中文(点我!)-blue.svg?style=flat-square)](../../README.md) - [![Readme-gitee](https://img.shields.io/badge/Readme-中文(点我!)-blue.svg?style=flat-square)](../../README.md)
- Using [SemVer 2.0.0](https://semver.org/) to manage version - Using [SemVer 2.0.0](https://semver.org/) to manage version
## 2023 V 0.7.0.3 ## 20230219 V 0.7.1.0
### 命令 ### 命令
@ -28,6 +28,8 @@
- 更改了 `ClientWindow` 启动参数的设置, 实装 ClientOption 的使用 - 更改了 `ClientWindow` 启动参数的设置, 实装 ClientOption 的使用
- 将 `SR1PartData` 的字段 `type_` 重命名为 `p_type` - 将 `SR1PartData` 的字段 `type_` 重命名为 `p_type`
- 现在鼠标滚动更顺滑了
### `DR_Rs` ### `DR_Rs`

View File

@ -43,6 +43,12 @@ pub mod part_list {
Satellite Satellite
} }
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct Vertex {
pub x: f64,
pub y: f64
}
#[derive(Debug, Serialize, Deserialize, Clone)] #[derive(Debug, Serialize, Deserialize, Clone)]
pub struct PartType { pub struct PartType {
pub id: String, pub id: String,
@ -67,7 +73,9 @@ pub mod part_list {
pub sandbox_only: Option<bool>, pub sandbox_only: Option<bool>,
pub drag: Option<f64>, pub drag: Option<f64>,
pub hidden: Option<bool>, pub hidden: Option<bool>,
pub buoyancy: Option<f64> pub buoyancy: Option<f64>,
#[serde(rename = "@Shape")]
pub shapes: Option<Vec<Vertex>>
} }
#[inline] #[inline]
@ -87,12 +95,10 @@ pub mod part_list {
#[pyfunction] #[pyfunction]
#[pyo3(name = "part_list_read_test", signature = (file_name = "./configs/PartList.xml".to_string()))] #[pyo3(name = "part_list_read_test", signature = (file_name = "./configs/PartList.xml".to_string()))]
pub fn read_part_list_py(file_name: Option<String>) -> PyResult<()> { pub fn read_part_list_py(_py: Python, file_name: Option<String>) -> PyResult<()> {
let file_name = file_name.unwrap_or("./configs/PartList.xml".to_string()); let file_name = file_name.unwrap_or("./configs/PartList.xml".to_string());
let parts = read_part_list(file_name); // let parts = read_part_list(file_name);
if let Some(parts) = parts { read_part_list(file_name);
println!("{:?}", parts);
}
Ok(()) Ok(())
} }

View File

@ -6,7 +6,7 @@ build-backend = "pdm.pep517.api"
[project] [project]
name = "difficult-rocket" name = "difficult-rocket"
version = "0.7.0.2" version = "0.7.1.0"
description = "A rocket game" description = "A rocket game"
authors = [ authors = [
{name = "shenjackyuanjie", email = "3695888@qq.com"} {name = "shenjackyuanjie", email = "3695888@qq.com"}