commit about v 0.5.3
release comming(no DEMO)
This commit is contained in:
parent
26506b6214
commit
12b914e407
@ -12,6 +12,7 @@ gitee: @shenjackyuanjie
|
||||
"""
|
||||
|
||||
from .api import *
|
||||
from .guis import *
|
||||
|
||||
__all__ = [
|
||||
'new_thread',
|
||||
|
@ -11,14 +11,21 @@ github: @shenjackyuanjie
|
||||
gitee: @shenjackyuanjie
|
||||
"""
|
||||
|
||||
from .tools import load_file
|
||||
# 单独导入的(或者就这一个有用的)
|
||||
from .translate import Lang
|
||||
from .delivery import Delivery
|
||||
from .new_thread import new_thread
|
||||
from .Exp import TexturesError, LanguageError
|
||||
|
||||
# lazy之后之前全部导入的(太多了写不动__all__了)
|
||||
from .Exp import *
|
||||
from .tools import *
|
||||
from .command import *
|
||||
from .calculation import *
|
||||
from .scientific_unit import *
|
||||
|
||||
__all__ = ['TexturesError',
|
||||
'LanguageError',
|
||||
'TestError',
|
||||
'new_thread',
|
||||
'Delivery',
|
||||
'load_file',
|
||||
|
149
Difficult_Rocket/api/command.py
Normal file
149
Difficult_Rocket/api/command.py
Normal file
@ -0,0 +1,149 @@
|
||||
# -------------------------------
|
||||
# Difficult Rocket
|
||||
# Copyright © 2021 by shenjackyuanjie
|
||||
# All rights reserved
|
||||
# -------------------------------
|
||||
|
||||
"""
|
||||
writen by shenjackyuanjie
|
||||
mail: 3695888@qq.com
|
||||
github: @shenjackyuanjie
|
||||
gitee: @shenjackyuanjie
|
||||
"""
|
||||
|
||||
from Difficult_Rocket.api import translate
|
||||
|
||||
# from libs.pyglet
|
||||
from libs import pyglet
|
||||
from libs.pyglet.text import Label
|
||||
from libs.pyglet.window import key
|
||||
from libs.pyglet.gui import widgets
|
||||
from libs.pyglet.graphics import Batch, Group
|
||||
from libs.pyglet.text.caret import Caret
|
||||
from libs.pyglet.text.layout import IncrementalTextLayout
|
||||
|
||||
|
||||
class CommandLine(widgets.WidgetBase):
|
||||
"""
|
||||
command line show
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
x: int,
|
||||
y: int,
|
||||
width: int,
|
||||
height: int,
|
||||
length: int,
|
||||
batch: Batch,
|
||||
group: Group = None,
|
||||
font_size: int = 20):
|
||||
super().__init__(x, y, width, height)
|
||||
# normal values
|
||||
self.length = length
|
||||
self._editing = False
|
||||
self.command_list = ['' for line in range(length)]
|
||||
bg_group = Group(order=0, parent=group)
|
||||
fg_group = Group(order=1, parent=group)
|
||||
# hidden value
|
||||
self._text = ''
|
||||
self._doc = pyglet.text.document.UnformattedDocument('')
|
||||
self._doc.set_style(0, len(self._doc.text), dict(color=(0, 0, 0, 255)))
|
||||
self._line = Label(x=x, y=y, batch=batch, text=self.text,
|
||||
color=(100, 255, 255, 200),
|
||||
anchor_x='left', anchor_y='center',
|
||||
font_size=font_size, group=fg_group)
|
||||
self._label = [Label(x=x, y=y + 20 + (line * 20), batch=batch, text='a',
|
||||
anchor_x='left', anchor_y='center',
|
||||
font_size=12, group=bg_group)
|
||||
for line in range(length)]
|
||||
# Rectangular outline with 2-pixel pad:
|
||||
color = (255, 255, 255, 255)
|
||||
self._pad = p = 2
|
||||
self._outline = pyglet.shapes.Rectangle(x-p, y-p, width+p+p, height+p+p, color[:3], batch, fg_group)
|
||||
self._outline.opacity = color[3]
|
||||
self._text_position = 0
|
||||
self._command_view = 0
|
||||
self._value = 0
|
||||
|
||||
def _update_position(self):
|
||||
self._line.position = self._x, self._y
|
||||
|
||||
@property
|
||||
def text(self):
|
||||
return self._text
|
||||
|
||||
@text.setter
|
||||
def text(self, value):
|
||||
assert type(value) is str, 'CommandLine\'s text must be string!'
|
||||
self._text = value
|
||||
self._line.text = value
|
||||
self._doc.text = value
|
||||
|
||||
@property
|
||||
def command_view(self):
|
||||
return self._command_view
|
||||
|
||||
@command_view.setter
|
||||
def command_view(self, value):
|
||||
"""
|
||||
value:
|
||||
-1 -> 将整个列表添加一个数据
|
||||
如果长度超过length就删掉多余的
|
||||
将视角移动到最下面,刷新显示列表
|
||||
0 ~ (self.length-1) -> 切换视角到对应的行数
|
||||
实际上还有一个限制
|
||||
"""
|
||||
assert type(value) is int, 'Command View must be integer'
|
||||
assert -2 < value < self.length, f'Command View must be bigger than -1 and smaller than {self.length}'
|
||||
if value == -1: # flush command list
|
||||
self._label.insert(0, self._label[-1])
|
||||
self._label.pop(-1)
|
||||
for line in range(self.length):
|
||||
self._label[line].y = self.y + 20 + (line * 20)
|
||||
self._label[0].text = self.text
|
||||
self.text = ''
|
||||
elif value == self._command_view: # not doing anything
|
||||
pass
|
||||
elif value > self._command_view: # move upwards
|
||||
pass
|
||||
else: # move downwards
|
||||
pass
|
||||
self._command_view = value
|
||||
|
||||
@property
|
||||
def editing(self):
|
||||
return self._editing
|
||||
|
||||
@editing.setter
|
||||
def editing(self, value):
|
||||
assert type(value) is bool, 'Command editing must be bool!'
|
||||
self._editing = value
|
||||
|
||||
def on_text(self, text):
|
||||
if self.editing:
|
||||
if text in ('\r', '\n'): # goto a new line
|
||||
self.command_view = -1
|
||||
self._editing = False
|
||||
else:
|
||||
self.text = f'{self.text[:self._text_position]}{text}{self.text[self._text_position:]}'
|
||||
# 插入字符(简单粗暴)
|
||||
self._text_position += 1
|
||||
# 光标位置+1
|
||||
elif text == 't': # open command line
|
||||
self._editing = not self.editing
|
||||
|
||||
def on_text_motion(self, motion):
|
||||
if self.editing:
|
||||
motion_string = key.motion_string(motion)
|
||||
if motion == key.MOTION_DOWN:
|
||||
# 刷新整个命令列表,向上刷新一遍
|
||||
self.command_list[-1].text = self.command_list[0].text # 把最上面一个显示替换成最新的
|
||||
last = self.command_list[-1] # 获取一遍现有的最后一个
|
||||
self.command_list.pop(-1) # 删除最后一个
|
||||
self.command_list.insert(1, last) # 把之前的最后一个插进第2个的位置(整体往后挪一个)
|
||||
for line in range(1, len(self.command_list)):
|
||||
self.command_list[line].y = 50 + (20 * line) # 挨个重设 y
|
||||
self.command_list.text = '' # 清除第一个的数据
|
||||
|
||||
def on_text_motion_select(self, motion):
|
||||
pass
|
@ -1,7 +1,6 @@
|
||||
import functools
|
||||
import inspect
|
||||
import threading
|
||||
import time
|
||||
from typing import Optional, Callable
|
||||
from Difficult_Rocket import crash
|
||||
|
||||
|
@ -31,6 +31,8 @@ class Lang:
|
||||
lang['language'] = 'abc' 或
|
||||
lang['lang'] = 'abc'
|
||||
的方式直接更改并刷新翻译
|
||||
用
|
||||
lang.lang(xxx, xxx)来获取翻译过的值
|
||||
"""
|
||||
|
||||
def __init__(self, language: str = 'zh-CN'):
|
||||
@ -82,6 +84,9 @@ class Lang:
|
||||
except KeyError:
|
||||
raise LanguageError(f'there\'s no key {args} in both {self.language} and zh-CN')
|
||||
|
||||
def 翻译(self, *args):
|
||||
self.lang(args)
|
||||
|
||||
|
||||
tr = Lang('zh-CN')
|
||||
|
||||
|
@ -25,6 +25,8 @@ if __name__ == '__main__': # been start will not run this
|
||||
sys.path.append('/bin')
|
||||
|
||||
# Difficult_Rocket function
|
||||
from Difficult_Rocket import guis
|
||||
from Difficult_Rocket.api import command
|
||||
from Difficult_Rocket.api.translate import tr
|
||||
from Difficult_Rocket.api import tools, new_thread, translate
|
||||
|
||||
@ -104,16 +106,16 @@ class ClientWindow(pyglet.window.Window):
|
||||
self.part_batch = pyglet.graphics.Batch()
|
||||
self.label_batch = pyglet.graphics.Batch()
|
||||
# frame
|
||||
self.frame = pyglet.gui.Frame(self)
|
||||
self.frame = pyglet.gui.Frame(self, order=20)
|
||||
self.M_frame = pyglet.gui.MovableFrame(self, modifier=key.LCTRL)
|
||||
# setup
|
||||
self.setup()
|
||||
# 命令显示
|
||||
self.command_label = [pyglet.text.Label(x=10, y=10 + 20 * line,
|
||||
anchor_x='left', anchor_y='center',
|
||||
font_name=translate.鸿蒙简体, font_size=12,
|
||||
batch=self.label_batch)
|
||||
for line in range(int(self.game_config['command']['show']) + 1)]
|
||||
self.command = command.CommandLine(x=10, y=30,
|
||||
width=20, height=20,
|
||||
length=int(self.game_config['command']['show']),
|
||||
batch=self.label_batch)
|
||||
self.push_handlers(self.command)
|
||||
# fps显示
|
||||
self.fps_label = pyglet.text.Label(x=10, y=self.height - 10,
|
||||
anchor_x='left', anchor_y='top',
|
||||
@ -194,6 +196,7 @@ class ClientWindow(pyglet.window.Window):
|
||||
self.part_batch.draw()
|
||||
self.label_batch.draw()
|
||||
|
||||
|
||||
"""
|
||||
keyboard and mouse input
|
||||
"""
|
||||
@ -223,11 +226,19 @@ class ClientWindow(pyglet.window.Window):
|
||||
self.logger.debug(tr.lang('window', 'key.release').format(key.symbol_string(symbol), key.modifiers_string(modifiers)))
|
||||
|
||||
def on_text(self, text):
|
||||
if text == '':
|
||||
if text == '\r':
|
||||
self.logger.debug(tr.lang('window', 'text.new_line'))
|
||||
else:
|
||||
self.logger.debug(tr.lang('window', 'text.input').format(text))
|
||||
|
||||
def on_text_motion(self, motion):
|
||||
motion_string = key.motion_string(motion)
|
||||
self.logger.debug(tr.lang('window', 'text.motion').format(motion_string))
|
||||
|
||||
def on_text_motion_select(self, motion):
|
||||
motion_string = key.motion_string(motion)
|
||||
self.logger.debug(tr.lang('window', 'text.motion_select').format(motion_string))
|
||||
|
||||
def on_close(self) -> None:
|
||||
self.run_input = False
|
||||
# self.input_line.join()
|
||||
|
@ -10,3 +10,7 @@ mail: 3695888@qq.com
|
||||
github: @shenjackyuanjie
|
||||
gitee: @shenjackyuanjie
|
||||
"""
|
||||
|
||||
from .widgets import *
|
||||
|
||||
__all__ = ['widgets']
|
@ -11,17 +11,22 @@ github: @shenjackyuanjie
|
||||
gitee: @shenjackyuanjie
|
||||
"""
|
||||
|
||||
from Difficult_Rocket.api import translate
|
||||
|
||||
from libs import pyglet
|
||||
from libs.pyglet.gui import widgets
|
||||
from libs.pyglet.sprite import Sprite
|
||||
from libs.pyglet.graphics import Batch
|
||||
from libs.pyglet.image import AbstractImage
|
||||
|
||||
__all__ = ['Parts']
|
||||
|
||||
|
||||
class Parts(widgets.WidgetBase):
|
||||
"""
|
||||
parts
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
x: int,
|
||||
y: int,
|
@ -35,8 +35,7 @@ class Game:
|
||||
self.on_python_v = sys.version.split(' ')[0]
|
||||
self.start_time = time.strftime('%Y-%m-%d %H-%M-%S', time.gmtime(time.time()))
|
||||
# lang_config
|
||||
self.language = tools.load_file('configs/sys_value/basic_config.json5')
|
||||
self.language = self.language['language']
|
||||
self.language = tools.load_file('configs/main.config', 'runtime')['language']
|
||||
tr.set_language(self.language)
|
||||
# logging config
|
||||
log_config = tools.load_file('configs/logger.json5')
|
||||
|
@ -4,13 +4,14 @@
|
||||
|
||||
[](https://Semver.org/)
|
||||
[](https://Python.org)
|
||||
[](https://pyglet.org)
|
||||
[](https://Python.org)
|
||||
|
||||
## Version
|
||||
|
||||
[](https://github.com/shenjackyuanjie/Difficult-Rocket/releases/v0.4.5)
|
||||
<br/>[](https://github.com/shenjackyuanjie/Difficult-Rocket/releases/v0.4.6)
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
## 中文README请移步 [这里](/docs/README-cn.md)
|
||||
|
||||
@ -47,7 +48,8 @@
|
||||
## Required python modules
|
||||
|
||||
- json5 (pre-installed V0.9.6 path:`./libs/json5`)
|
||||
- pyglet (pre-installed V2.0.dev9 path:`./libs/pyglet`)
|
||||
|
||||
[comment]: <> (- pyglet (pre-installed V2.0.dev9 path:`./libs/pyglet`))
|
||||
- pillow
|
||||
- semver
|
||||
|
||||
|
@ -30,10 +30,15 @@
|
||||
'mouse.RIGHT': 'right button',
|
||||
'mouse.LEFT': 'left button',
|
||||
'mouse.MIDDLE': 'middle button',
|
||||
'key.press': 'key {} {} been press',
|
||||
'key.release': 'key {} {} been release',
|
||||
'text.input': 'input text {}',
|
||||
'text.new_line': '换行'
|
||||
'key.press': 'key {} | {} been press',
|
||||
'key.release': 'key {} | {} been release',
|
||||
'text.input': 'input text "{}"',
|
||||
'text.new_line': 'new line',
|
||||
'text.motion': 'text move {}',
|
||||
'text.motion_select': 'text select {}',
|
||||
'libs.local': 'using local pyglet, version: {}',
|
||||
'libs.outer': 'using global pyglet, version: {}\n(may cause bug)',
|
||||
'fonts.found': 'found fonts in font lib: {}'
|
||||
},
|
||||
'server': {
|
||||
'setup.done': 'Server load complete ',
|
||||
|
@ -30,10 +30,12 @@
|
||||
'mouse.RIGHT': '右键',
|
||||
'mouse.LEFT': '左键',
|
||||
'mouse.MIDDLE': '中键',
|
||||
'key.press': '按键 {} {} 被按下',
|
||||
'key.release': '按键 {} {} 被释放',
|
||||
'text.input': '输入字符 {}',
|
||||
'key.press': '按键 {} | {} 被按下',
|
||||
'key.release': '按键 {} | {} 被释放',
|
||||
'text.input': '输入字符 "{}"',
|
||||
'text.new_line': '换行',
|
||||
'text.motion': '光标移动 {}',
|
||||
'text.motion_select': '光标选择 {}',
|
||||
'libs.local': '正在使用本地 pyglet 库 版本为: {}',
|
||||
'libs.outer': '正在使用全局 pyglet 库 版本为: {}\n(可能会造成bug,因为本地库版本为2.0dev9)',
|
||||
'fonts.found': '在字体列表中找到以下字体库: {}'
|
||||
|
@ -7,8 +7,8 @@ write_py_v = 3.8.10
|
||||
|
||||
[window]
|
||||
style = None
|
||||
width = 1024
|
||||
height = 768
|
||||
width = 1217
|
||||
height = 918
|
||||
visible = true
|
||||
caption = Difficult Rocket {version}
|
||||
resizable = true
|
||||
|
@ -4,14 +4,15 @@
|
||||
- [gitee](https://gitee.com/shenjackyuanjie/Difficult-Rocket)
|
||||
|
||||
[](https://Semver.org/)
|
||||
[](https://Python.org)
|
||||
[](https://Python.org)
|
||||
[](https://pyglet.org)
|
||||
[](https://Python.org)
|
||||
|
||||
## 版本
|
||||
|
||||
[](https://github.com/shenjackyuanjie/Difficult-Rocket/releases/v0.4.5)
|
||||
<br/>[](https://github.com/shenjackyuanjie/Difficult-Rocket/releases/v0.4.6)
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
### For an English version of readme, please move [here](https://github.com/shenjackyuanjie/Difficult-Rocket).
|
||||
|
||||
|
@ -26,6 +26,8 @@
|
||||
- handler of `on_key_press` and `on_key_release` and `on_text`
|
||||
- `game.config` config file
|
||||
- `lang/en-us.json5` now up to date with `lang/zh-CN.json5`
|
||||
- `graphics/frame/AllFrame`
|
||||
- `translate/Lang.翻译` same as `Lang.lang`
|
||||
|
||||
## 20210928 V 0.5.2
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user