feat: change name for some part

This commit is contained in:
shenjack 2023-01-01 11:25:12 +08:00
parent aaec129c83
commit 834d050276
4 changed files with 211 additions and 209 deletions

View File

@ -35,7 +35,7 @@ class _DR_option(Options):
""" """
name = 'DR Option' name = 'DR Option'
# runtime options # runtime options
InputBox_use_TextEntry: bool = False CommandBox_use_TextEntry: bool = False
record_threads: bool = True record_threads: bool = True
use_cProfile: bool = False use_cProfile: bool = False
use_local_logging: bool = False use_local_logging: bool = False

View File

@ -37,7 +37,7 @@ from Difficult_Rocket import DR_runtime, DR_option
from Difficult_Rocket.utils import tools, translate from Difficult_Rocket.utils import tools, translate
from Difficult_Rocket.utils.new_thread import new_thread from Difficult_Rocket.utils.new_thread import new_thread
from Difficult_Rocket.client.fps.fps_log import FpsLogger from Difficult_Rocket.client.fps.fps_log import FpsLogger
from Difficult_Rocket.client.guis.widgets import InputBox from Difficult_Rocket.client.guis.widgets import CommandBox
from Difficult_Rocket.exception.command import CommandError from Difficult_Rocket.exception.command import CommandError
from Difficult_Rocket.client.render.sr1_ship import SR1ShipRender from Difficult_Rocket.client.render.sr1_ship import SR1ShipRender
from Difficult_Rocket.client.screen import BaseScreen, DRScreen, DRDEBUGScreen from Difficult_Rocket.client.screen import BaseScreen, DRScreen, DRDEBUGScreen
@ -154,8 +154,8 @@ class ClientWindow(Window):
# 命令显示 # 命令显示
self.command_group = pyglet.graphics.Group(0) self.command_group = pyglet.graphics.Group(0)
self.command_tree = tree.CommandTree(tree.DR_command) self.command_tree = tree.CommandTree(tree.DR_command)
self.input_box = InputBox(x=50, y=30, width=300, height=20, self.input_box = CommandBox(x=50, y=30, width=300,
batch=self.label_batch) # 实例化 batch=self.label_batch, text='') # 实例化
self.input_box.push_handlers(self) self.input_box.push_handlers(self)
self.push_handlers(self.input_box) self.push_handlers(self.input_box)
self.input_box.enabled = True self.input_box.enabled = True

View File

@ -74,206 +74,208 @@ class TextButton(widgets.WidgetBase):
... ...
if not DR_option.InputBox_use_TextEntry: if not DR_option.CommandBox_use_TextEntry:
class InputBox(widgets.WidgetBase): class CommandBox(widgets.TextEntry):
""" ...
input box # class InputBox(widgets.WidgetBase):
""" # """
# input box
def __init__(self, # """
x: int, y: int, width: int, height: int, #
message: str = '', # def __init__(self,
font_name: str = translate.微软等宽, # x: int, y: int, width: int, height: int,
font_size: int = 15, # message: str = '',
font_bold: bool = False, # font_name: str = translate.微软等宽,
font_italic: bool = False, # font_size: int = 15,
font_stretch: bool = False, # font_bold: bool = False,
font_dpi: int = 100, # font_italic: bool = False,
text_color: [int, int, int] = (187, 187, 187, 255), # font_stretch: bool = False,
out_line_color: [int, int, int] = (37, 116, 176), # font_dpi: int = 100,
cursor_color: [int, int, int] = (187, 187, 187), # text_color: [int, int, int] = (187, 187, 187, 255),
select_color: [int, int, int] = (63, 115, 255), # out_line_color: [int, int, int] = (37, 116, 176),
out_line: int = 2, # cursor_color: [int, int, int] = (187, 187, 187),
batch: Batch = None, # select_color: [int, int, int] = (63, 115, 255),
group: Group = None): # out_line: int = 2,
if batch is None: # batch: Batch = None,
batch = Batch() # group: Group = None):
if group is None: # if batch is None:
group = Group() # batch = Batch()
super().__init__(x, y, width, height) # if group is None:
self.enabled = False # group = Group()
self._text = message # super().__init__(x, y, width, height)
self._cursor_poi = 0 # self.enabled = False
self.font = font.load(name=font_name, size=font_size, # self._text = message
bold=font_bold, italic=font_italic, stretch=font_stretch, # self._cursor_poi = 0
dpi=font_dpi) # self.font = font.load(name=font_name, size=font_size,
self.font_height = self.font.ascent - self.font.descent # bold=font_bold, italic=font_italic, stretch=font_stretch,
self.out_bound = out_line # dpi=font_dpi)
if DR_option.InputBox_use_TextEntry: # self.font_height = self.font.ascent - self.font.descent
# 基于IncrementalTextLayout的处理系统 # self.out_bound = out_line
self._doc = FormattedDocument(message) # if DR_option.InputBox_use_TextEntry:
# self._doc.set_style() # # 基于IncrementalTextLayout的处理系统
self._layout = IncrementalTextLayout(self._doc, self.font, width, height, # self._doc = FormattedDocument(message)
batch=batch, group=group) # # self._doc.set_style()
self._input_box = widgets.TextEntry(x, y, width, height, # self._layout = IncrementalTextLayout(self._doc, self.font, width, height,
self._doc, self._layout, # batch=batch, group=group)
batch=batch, group=group) # self._input_box = widgets.TextEntry(x, y, width, height,
else: # self._doc, self._layout,
# 基于Label的处理系统 # batch=batch, group=group)
self._input_box = Label(x=x + out_line, y=y + out_line, # else:
width=width, height=self.font_height + self.out_bound * 2, # # 基于Label的处理系统
color=text_color, # self._input_box = Label(x=x + out_line, y=y + out_line,
font_name=font_name, font_size=font_size, # width=width, height=self.font_height + self.out_bound * 2,
batch=batch, group=group, # color=text_color,
text=message) # font_name=font_name, font_size=font_size,
self._HTML_box = HTMLLabel(x=x + out_line, y=y + out_line + 30, # batch=batch, group=group,
width=width, height=self.font_height + self.out_bound * 2, # text=message)
batch=batch, group=group, # self._HTML_box = HTMLLabel(x=x + out_line, y=y + out_line + 30,
text=message) # width=width, height=self.font_height + self.out_bound * 2,
self._out_box = Rectangle(x=x - out_line, y=y - out_line, # batch=batch, group=group,
color=out_line_color, # text=message)
width=width + (out_line * 2), height=height + (out_line * 2), # self._out_box = Rectangle(x=x - out_line, y=y - out_line,
batch=batch, group=group) # color=out_line_color,
self._光标 = Rectangle(x=x + out_line, y=y + out_line, # width=width + (out_line * 2), height=height + (out_line * 2),
color=cursor_color, # batch=batch, group=group)
width=1, height=self.font_height, # self._光标 = Rectangle(x=x + out_line, y=y + out_line,
batch=batch, group=group) # color=cursor_color,
self._选择框 = Rectangle(x=x, y=y, width=0, height=self.font_height, # width=1, height=self.font_height,
color=select_color) # batch=batch, group=group)
self._选择的字 = Label(x=x, y=y, width=0, height=self.font_height, # self._选择框 = Rectangle(x=x, y=y, width=0, height=self.font_height,
color=text_color, # color=select_color)
font_name=font_name, font_size=font_size, # self._选择的字 = Label(x=x, y=y, width=0, height=self.font_height,
batch=batch, group=group, # color=text_color,
text='') # font_name=font_name, font_size=font_size,
# batch=batch, group=group,
""" # text='')
输入框的属性 #
""" # """
# 输入框的属性
# 本身属性 # """
@property #
def text(self) -> str: # 输入框的文本 # # 本身属性
return self._text # @property
# def text(self) -> str: # 输入框的文本
@text.setter # return self._text
def text(self, value) -> None: #
assert type(value) is str, 'Input Box\'s text must be string!' # @text.setter
self._text = value # def text(self, value) -> None:
self._input_box.text = value # assert type(value) is str, 'Input Box\'s text must be string!'
self._HTML_box.text = html.decode_text2HTML(value, show_style=True) # self._text = value
# self._input_box.text = value
@property # self._HTML_box.text = html.decode_text2HTML(value, show_style=True)
def cursor_poi(self) -> int: # 光标位置 #
return self._cursor_poi # @property
# def cursor_poi(self) -> int: # 光标位置
@cursor_poi.setter # return self._cursor_poi
def cursor_poi(self, value) -> None: #
assert type(value) is int, 'Input Box\'s cursor poi must be int!' # @cursor_poi.setter
self._cursor_poi = value # def cursor_poi(self, value) -> None:
self._光标.x = self.x + self.out_bound + self._input_box.content_width # assert type(value) is int, 'Input Box\'s cursor poi must be int!'
# self._cursor_poi = value
# 渲染时属性 # self._光标.x = self.x + self.out_bound + self._input_box.content_width
@property #
def opacity(self) -> int: # 透明度 # # 渲染时属性
return self._input_box.opacity # @property
# def opacity(self) -> int: # 透明度
@opacity.setter # return self._input_box.opacity
def opacity(self, value: int) -> None: #
assert type(value) is int, 'Input Box\'s opacity must be int!' # @opacity.setter
self._input_box.opacity = value # def opacity(self, value: int) -> None:
self._out_box.opacity = value # assert type(value) is int, 'Input Box\'s opacity must be int!'
self._选择的字.opacity = value # self._input_box.opacity = value
self._选择框.opacity = value # self._out_box.opacity = value
self._光标.opacity = value # self._选择的字.opacity = value
# self._选择框.opacity = value
@property # self._光标.opacity = value
def visible(self) -> bool: # 是否可见 #
return self._input_box.visible # @property
# def visible(self) -> bool: # 是否可见
@visible.setter # return self._input_box.visible
def visible(self, value: bool) -> None: #
assert type(value) is bool, 'Input Box\'s visible must be bool!' # @visible.setter
self._input_box.visible = value # def visible(self, value: bool) -> None:
self._out_box.visible = value # assert type(value) is bool, 'Input Box\'s visible must be bool!'
self._选择的字.visible = value # self._input_box.visible = value
self._选择框.visible = value # self._out_box.visible = value
self._光标.visible = value # self._选择的字.visible = value
# self._选择框.visible = value
@property # self._光标.visible = value
def value(self) -> str: #
return self._text # @property
# def value(self) -> str:
""" # return self._text
事件调用 #
""" # """
# 事件调用
def _update_position(self): # """
self._input_box.position = self._x + self.out_bound, self._y + self.out_bound #
self._out_box.position = self._x - self.out_bound, self._y - self.out_bound # def _update_position(self):
self._光标.position = self._x + self.out_bound, self._y + self.out_bound # self._input_box.position = self._x + self.out_bound, self._y + self.out_bound
# self._out_box.position = self._x - self.out_bound, self._y - self.out_bound
# 输入东西 # self._光标.position = self._x + self.out_bound, self._y + self.out_bound
def on_text(self, text: str): #
if self.enabled: # # 输入东西
if text in ('\r', '\n'): # def on_text(self, text: str):
if self.text: # if self.enabled:
self.dispatch_event('on_commit', self.text) # if text in ('\r', '\n'):
else: # if self.text:
self.text = f'{self.text[:self.cursor_poi]}{text}{self.text[self.cursor_poi:]}' # self.dispatch_event('on_commit', self.text)
self.cursor_poi += len(text) # else:
# self.text = f'{self.text[:self.cursor_poi]}{text}{self.text[self.cursor_poi:]}'
# 移动光标 # self.cursor_poi += len(text)
def on_text_motion(self, motion): #
if self.enabled: # # 移动光标
# 根据按键处理 # def on_text_motion(self, motion):
# 单格移动光标(上下左右) # if self.enabled:
if motion in (key.MOTION_UP, key.MOTION_LEFT): # 往上一个移动 # # 根据按键处理
self.cursor_poi = max(0, self._cursor_poi - 1) # # 单格移动光标(上下左右)
elif motion in (key.MOTION_DOWN, key.MOTION_RIGHT): # 往下一个移动 # if motion in (key.MOTION_UP, key.MOTION_LEFT): # 往上一个移动
self.cursor_poi = min(len(self.text), self._cursor_poi + 1) # self.cursor_poi = max(0, self._cursor_poi - 1)
# 大前后移动(开头或结尾) # elif motion in (key.MOTION_DOWN, key.MOTION_RIGHT): # 往下一个移动
elif motion in ( # self.cursor_poi = min(len(self.text), self._cursor_poi + 1)
key.MOTION_BEGINNING_OF_LINE, key.MOTION_BEGINNING_OF_FILE, key.MOTION_PREVIOUS_PAGE): # 开头 # # 大前后移动(开头或结尾)
self.cursor_poi = 0 # elif motion in (
elif motion in (key.MOTION_END_OF_LINE, key.MOTION_END_OF_FILE, key.MOTION_NEXT_PAGE): # 结尾 # key.MOTION_BEGINNING_OF_LINE, key.MOTION_BEGINNING_OF_FILE, key.MOTION_PREVIOUS_PAGE): # 开头
self.cursor_poi = len(self.text) # self.cursor_poi = 0
# 删除操作 # elif motion in (key.MOTION_END_OF_LINE, key.MOTION_END_OF_FILE, key.MOTION_NEXT_PAGE): # 结尾
elif motion == key.MOTION_BACKSPACE: # self.cursor_poi = len(self.text)
if self.text: # 如果有文字 # # 删除操作
self.text = f'{self.text[:self.cursor_poi - 1]}{self.text[self.cursor_poi:]}' # elif motion == key.MOTION_BACKSPACE:
self.cursor_poi = max(0, self._cursor_poi - 1) # if self.text: # 如果有文字
elif motion == key.MOTION_DELETE: # self.text = f'{self.text[:self.cursor_poi - 1]}{self.text[self.cursor_poi:]}'
if self.text and self.cursor_poi != len(self.text) - 1: # 如果有文字,并且光标不在最后 # self.cursor_poi = max(0, self._cursor_poi - 1)
self.text = f'{self.text[:self.cursor_poi]}{self.text[self.cursor_poi + 1:]}' # elif motion == key.MOTION_DELETE:
# 剪贴板操作 # if self.text and self.cursor_poi != len(self.text) - 1: # 如果有文字,并且光标不在最后
elif motion == key.MOTION_COPY: # self.text = f'{self.text[:self.cursor_poi]}{self.text[self.cursor_poi + 1:]}'
pass # # 剪贴板操作
elif motion == key.MOTION_PASTE: # elif motion == key.MOTION_COPY:
paste_text = paste() # pass
self.text = f'{self.text[:self.cursor_poi]}{paste_text}{self.text[self.cursor_poi:]}' # elif motion == key.MOTION_PASTE:
self.cursor_poi += len(paste_text) # paste_text = paste()
# self.text = f'{self.text[:self.cursor_poi]}{paste_text}{self.text[self.cursor_poi:]}'
def on_text_motion_select(self, motion): # self.cursor_poi += len(paste_text)
pass #
# def on_text_motion_select(self, motion):
def on_mouse_press(self, x, y, buttons, modifiers): # pass
if self._check_hit(x, y) and self._input_box.visible: #
self.enabled = True # def on_mouse_press(self, x, y, buttons, modifiers):
else: # if self._check_hit(x, y) and self._input_box.visible:
self.enabled = False # self.enabled = True
# else:
def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers): # self.enabled = False
pass #
# def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
def on_mouse_release(self, x, y, buttons, modifiers): # pass
pass #
# def on_mouse_release(self, x, y, buttons, modifiers):
def on_commit(self, text: str): # pass
pass #
# def on_commit(self, text: str):
# pass
InputBox.register_event_type('on_commit') #
#
# InputBox.register_event_type('on_commit')
else: else:
InputBox = widgets.TextEntry CommandBox = widgets.TextEntry
# class InputBox(widgets.TextEntry): # class InputBox(widgets.TextEntry):
# pass # pass

View File

@ -38,11 +38,11 @@ class CommandText:
self.tree_node = tree_list self.tree_node = tree_list
@staticmethod # @staticmethod
def parse_text(raw_text: str) -> str: # def parse_text(raw_text: str) -> str:
q_mark_iter = re.finditer('\\"', raw_text) # q_mark_iter = re.finditer('\\"', raw_text)
for q_mark in q_mark_iter: # for q_mark in q_mark_iter:
... # ...
@staticmethod @staticmethod
def parse_command(raw_command: Union[str, "CommandText"]) -> Tuple[List[str], Union[CommandParseError, type(True)]]: def parse_command(raw_command: Union[str, "CommandText"]) -> Tuple[List[str], Union[CommandParseError, type(True)]]: