继续更新一些好东西
This commit is contained in:
parent
fde79fd3e5
commit
bbabe5699e
@ -127,6 +127,10 @@ _DR_runtime.add_option('language', _DR_runtime.language)
|
|||||||
DR_option = _DR_option()
|
DR_option = _DR_option()
|
||||||
DR_runtime = _DR_runtime()
|
DR_runtime = _DR_runtime()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
print(DR_option.InputBox_use_TextEntry)
|
||||||
|
...
|
||||||
|
|
||||||
if DR_option.playing:
|
if DR_option.playing:
|
||||||
from Difficult_Rocket.utils import new_thread
|
from Difficult_Rocket.utils import new_thread
|
||||||
|
|
||||||
|
@ -129,7 +129,7 @@ class Options:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def init_option(options_class: 'Options'.__class__, init_value: Optional[dict] = None) -> 'Options':
|
def init_option(options_class: 'Options'.__class__, init_value: Optional[dict] = None) -> 'Options':
|
||||||
options_class_instance = options_class(**init_value)
|
options_class_instance = options_class(**init_value if init_value is not None else {})
|
||||||
return options_class_instance
|
return options_class_instance
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ if TYPE_CHECKING:
|
|||||||
from Difficult_Rocket.client import ClientWindow
|
from Difficult_Rocket.client import ClientWindow
|
||||||
|
|
||||||
|
|
||||||
def get_part_data_from_xml(part_xml: Element) -> Optional[SR1PartData]:
|
def get_sr1_part(part_xml: Element) -> Optional[SR1PartData]:
|
||||||
if part_xml.tag != 'Part':
|
if part_xml.tag != 'Part':
|
||||||
return None
|
return None
|
||||||
# print(f"tag: {part.tag} attrib: {part.attrib}")
|
# print(f"tag: {part.tag} attrib: {part.attrib}")
|
||||||
@ -59,11 +59,14 @@ def get_part_data_from_xml(part_xml: Element) -> Optional[SR1PartData]:
|
|||||||
return part_data
|
return part_data
|
||||||
|
|
||||||
|
|
||||||
@Options.init_option
|
class _SR1ShipRender_Option(Options):
|
||||||
class SR1ShipRender_Option(Options):
|
|
||||||
# debug option
|
# debug option
|
||||||
draw_delta_line: bool = True
|
draw_delta_line: bool = False
|
||||||
draw_mouse_line: bool = True
|
draw_mouse_line: bool = False
|
||||||
|
draw_mouse_delta_line: bool = False
|
||||||
|
|
||||||
|
|
||||||
|
SR1ShipRender_Option = _SR1ShipRender_Option()
|
||||||
|
|
||||||
|
|
||||||
class SR1ShipRender(BaseScreen):
|
class SR1ShipRender(BaseScreen):
|
||||||
@ -76,6 +79,7 @@ class SR1ShipRender(BaseScreen):
|
|||||||
self.rendered = False
|
self.rendered = False
|
||||||
self.scale = scale
|
self.scale = scale
|
||||||
self.focus = True
|
self.focus = True
|
||||||
|
self.need_draw = False
|
||||||
self.dx = 0
|
self.dx = 0
|
||||||
self.dy = 0
|
self.dy = 0
|
||||||
self.debug_line = Line(main_window.width / 2, main_window.height / 2,
|
self.debug_line = Line(main_window.width / 2, main_window.height / 2,
|
||||||
@ -84,8 +88,11 @@ class SR1ShipRender(BaseScreen):
|
|||||||
self.debug_mouse_line = Line(main_window.width / 2, main_window.height / 2,
|
self.debug_mouse_line = Line(main_window.width / 2, main_window.height / 2,
|
||||||
main_window.width / 2, main_window.height / 2,
|
main_window.width / 2, main_window.height / 2,
|
||||||
width=3, color=(10, 200, 200, 255))
|
width=3, color=(10, 200, 200, 255))
|
||||||
|
self.debug_mouse_delta_line = Line(main_window.width / 2, main_window.height / 2,
|
||||||
|
main_window.width / 2, main_window.height / 2,
|
||||||
|
width=2, color=(200, 200, 10, 255))
|
||||||
self.debug_label = Label('debug label NODATA', font_name=Fonts.微软等宽无线,
|
self.debug_label = Label('debug label NODATA', font_name=Fonts.微软等宽无线,
|
||||||
x=main_window.width / 2, y=main_window.height / 2,)
|
x=main_window.width / 2, y=main_window.height / 2)
|
||||||
self.debug_mouse_label = Label('debug mouse_label NODATA', font_name=Fonts.微软等宽无线,
|
self.debug_mouse_label = Label('debug mouse_label NODATA', font_name=Fonts.微软等宽无线,
|
||||||
x=main_window.width / 2, y=main_window.height / 2)
|
x=main_window.width / 2, y=main_window.height / 2)
|
||||||
self.textures: Union[SR1Textures, None] = None
|
self.textures: Union[SR1Textures, None] = None
|
||||||
@ -127,7 +134,7 @@ class SR1ShipRender(BaseScreen):
|
|||||||
continue # 如果不是部件,则跳过
|
continue # 如果不是部件,则跳过
|
||||||
# print(f"tag: {part.tag} attrib: {part.attrib}")
|
# print(f"tag: {part.tag} attrib: {part.attrib}")
|
||||||
part_render = True
|
part_render = True
|
||||||
part = get_part_data_from_xml(part_xml)
|
part = get_sr1_part(part_xml)
|
||||||
if part.id in self.part_data:
|
if part.id in self.part_data:
|
||||||
print(f'hey! warning! id{part.id}')
|
print(f'hey! warning! id{part.id}')
|
||||||
self.part_data[part.id] = part
|
self.part_data[part.id] = part
|
||||||
@ -154,6 +161,7 @@ class SR1ShipRender(BaseScreen):
|
|||||||
if not part_render: # 如果不渲染(渲染有毛病)
|
if not part_render: # 如果不渲染(渲染有毛病)
|
||||||
self.parts_sprite[part.id].visible = False
|
self.parts_sprite[part.id].visible = False
|
||||||
self.parts_sprite[part.id] = cache_sprite
|
self.parts_sprite[part.id] = cache_sprite
|
||||||
|
self.need_draw = False
|
||||||
self.rendered = True
|
self.rendered = True
|
||||||
|
|
||||||
def update_parts(self) -> bool:
|
def update_parts(self) -> bool:
|
||||||
@ -169,6 +177,8 @@ class SR1ShipRender(BaseScreen):
|
|||||||
self.parts_sprite[part_id].scale = self.scale * DR_option.gui_scale
|
self.parts_sprite[part_id].scale = self.scale * DR_option.gui_scale
|
||||||
|
|
||||||
def on_draw(self):
|
def on_draw(self):
|
||||||
|
if self.need_draw:
|
||||||
|
self.render_ship()
|
||||||
self.part_batch.draw()
|
self.part_batch.draw()
|
||||||
if SR1ShipRender_Option.draw_delta_line:
|
if SR1ShipRender_Option.draw_delta_line:
|
||||||
self.debug_line.draw()
|
self.debug_line.draw()
|
||||||
@ -176,16 +186,18 @@ class SR1ShipRender(BaseScreen):
|
|||||||
if SR1ShipRender_Option.draw_mouse_line:
|
if SR1ShipRender_Option.draw_mouse_line:
|
||||||
self.debug_mouse_line.draw()
|
self.debug_mouse_line.draw()
|
||||||
self.debug_mouse_label.draw()
|
self.debug_mouse_label.draw()
|
||||||
|
if SR1ShipRender_Option.draw_mouse_delta_line:
|
||||||
|
self.debug_mouse_delta_line.draw()
|
||||||
|
|
||||||
def on_resize(self, width: int, height: int):
|
def on_resize(self, width: int, height: int):
|
||||||
if not self.rendered:
|
if not self.rendered:
|
||||||
return
|
return
|
||||||
self.debug_line.x = width / 2
|
self.debug_line.x = width / 2
|
||||||
self.debug_line.y = height / 2
|
self.debug_line.y = height / 2
|
||||||
self.debug_line._update_vertices()
|
|
||||||
self.debug_mouse_line.x = width / 2
|
self.debug_mouse_line.x = width / 2
|
||||||
self.debug_mouse_line.y = height / 2
|
self.debug_mouse_line.y = height / 2
|
||||||
self.debug_mouse_line._update_vertices()
|
self.debug_mouse_delta_line.x = width / 2
|
||||||
|
self.debug_mouse_delta_line.y = height / 2
|
||||||
self.update_parts()
|
self.update_parts()
|
||||||
|
|
||||||
def on_mouse_scroll(self, x: int, y: int, scroll_x: int, scroll_y: int):
|
def on_mouse_scroll(self, x: int, y: int, scroll_x: int, scroll_y: int):
|
||||||
@ -194,19 +206,32 @@ class SR1ShipRender(BaseScreen):
|
|||||||
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
|
self.debug_mouse_line.x2, self.debug_mouse_line.y2 = x, y
|
||||||
|
if not self.scale * (0.5 ** scroll_y) >= 10:
|
||||||
if not (self.scale + scroll_y * 0.1 == 0.0):
|
self.scale = self.scale * (0.5 ** scroll_y)
|
||||||
self.scale += scroll_y * 0.1
|
self.dx += (mouse_dx - self.dx) * (1 - (0.5 ** scroll_y))
|
||||||
self.dx -= (scroll_x * 0.1) * (mouse_dx + self.dx)
|
self.dy += (mouse_dy - self.dy) * (1 - (0.5 ** scroll_y))
|
||||||
self.dy -= (scroll_y * 0.1) * (mouse_dy + self.dy)
|
else:
|
||||||
|
self.scale = 10
|
||||||
|
self.debug_mouse_delta_line.x2 = (mouse_dx - self.dx) * (1 - (0.5 ** scroll_y)) + (self.window_pointer.width / 2)
|
||||||
|
self.debug_mouse_delta_line.y2 = (mouse_dy - self.dy) * (1 - (0.5 ** scroll_y)) + (self.window_pointer.height / 2)
|
||||||
self.debug_mouse_label.text = f'x: {mouse_dx} y: {mouse_dy}'
|
self.debug_mouse_label.text = f'x: {mouse_dx} y: {mouse_dy}'
|
||||||
self.debug_mouse_label.position = x, y + 10, 0
|
self.debug_mouse_label.position = x, y + 10, 0
|
||||||
self.update_parts()
|
self.update_parts()
|
||||||
|
# print(f'{self.scale=} {self.dx=} {self.dy=} {x=} {y=} {scroll_x=} {scroll_y=} {1 - (0.5 ** scroll_y)=}')
|
||||||
|
|
||||||
def on_command(self, command: CommandText):
|
def on_command(self, command: CommandText):
|
||||||
if command.match('render'):
|
if command.match('render'):
|
||||||
# self.render_ship()
|
# self.render_ship()
|
||||||
|
self.need_draw = True
|
||||||
print('应该渲染飞船的')
|
print('应该渲染飞船的')
|
||||||
|
elif command.match('sr1'):
|
||||||
|
if command.match('delta'):
|
||||||
|
SR1ShipRender_Option.draw_delta_line = not SR1ShipRender_Option.draw_mouse_delta_line
|
||||||
|
elif command.match('mouse'):
|
||||||
|
if command.match('delta'):
|
||||||
|
SR1ShipRender_Option.draw_mouse_line = not SR1ShipRender_Option.draw_mouse_line
|
||||||
|
else:
|
||||||
|
SR1ShipRender_Option.draw_mouse_delta_line = not SR1ShipRender_Option.draw_mouse_delta_line
|
||||||
|
|
||||||
def on_mouse_drag(self, x: int, y: int, dx: int, dy: int, buttons: int, modifiers: int):
|
def on_mouse_drag(self, x: int, y: int, dx: int, dy: int, buttons: int, modifiers: int):
|
||||||
if not self.focus:
|
if not self.focus:
|
||||||
|
@ -32,23 +32,15 @@ class CommandText:
|
|||||||
self.text = text
|
self.text = text
|
||||||
self.error = False
|
self.error = False
|
||||||
self.value_dict = {}
|
self.value_dict = {}
|
||||||
self.value_list = []
|
|
||||||
self.command_tree = {}
|
|
||||||
tree_list = text.split(' ')
|
|
||||||
|
|
||||||
self.tree_node = tree_list
|
def counter(self, start: Optional[int] = 0) -> int:
|
||||||
|
assert isinstance(start, int)
|
||||||
# @staticmethod
|
i = start
|
||||||
# def parse_text(raw_text: str) -> str:
|
while True:
|
||||||
# q_mark_iter = re.finditer('\\"', raw_text)
|
yield i
|
||||||
# for q_mark in q_mark_iter:
|
if self.error:
|
||||||
# ...
|
break
|
||||||
|
i += 1
|
||||||
@staticmethod
|
|
||||||
def parse_command(raw_command: Union[str, "CommandText"]) -> Tuple[List[str], Union[CommandParseError, type(True)]]:
|
|
||||||
spilt_list = re.split(r'', raw_command)
|
|
||||||
done_list = [re.sub(r'\\"', '"', raw_text) for raw_text in spilt_list]
|
|
||||||
return done_list, True # 完事了
|
|
||||||
|
|
||||||
def find(self, text: str) -> Union[str, bool]:
|
def find(self, text: str) -> Union[str, bool]:
|
||||||
finding = re.match(text, self.text)
|
finding = re.match(text, self.text)
|
||||||
@ -74,6 +66,9 @@ class CommandText:
|
|||||||
else:
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def int_value(self, name: Optional[str]):
|
||||||
|
...
|
||||||
|
|
||||||
def value(self,
|
def value(self,
|
||||||
name: str = None,
|
name: str = None,
|
||||||
split: str = ' ',
|
split: str = ' ',
|
||||||
|
@ -8,8 +8,8 @@ fonts_folder = "libs/fonts"
|
|||||||
|
|
||||||
[window]
|
[window]
|
||||||
style = "None"
|
style = "None"
|
||||||
width = 1512
|
width = 1520
|
||||||
height = 944
|
height = 1133
|
||||||
visible = true
|
visible = true
|
||||||
gui_scale = 1
|
gui_scale = 1
|
||||||
caption = "Difficult Rocket {version}"
|
caption = "Difficult Rocket {version}"
|
||||||
|
Loading…
Reference in New Issue
Block a user