Esempio n. 1
0
 def draw_label(self):
     if not self.is_init:
         if self.player['die']:
             # 玩家死亡
             self.dialogue.draw()
             self.label['center'].document = decode_attributed(
                 '{color (255, 255, 255, 255)}{font_size 30}' +
                 lang['game.text.die'])
             self.label['actionbar'].document = decode_attributed(
                 '{color (0, 0, 0, 255)}{font_size 15}' +
                 self.player['die_reason'])
             self.label['center'].draw()
             self.label['actionbar'].draw()
         elif self.ext['position']:
             # 在屏幕左上角绘制标签
             x, y, z = self.player['position']
             self.label['top'].document = decode_attributed(
                 '{color (255, 255, 255, 255)}{background_color (0, 0, 0, 64)}'
                 + lang['game.text.position'] %
                 (x, y, z, pyglet.clock.get_fps()))
             self.label['top'].draw()
             self.dialogue.draw()
     else:
         # 初始化屏幕
         self.loading_image.blit(0, 0)
         self.label['center'].document = decode_attributed(
             '{color (255, 255, 255, 255)}{font_size 15}' +
             lang['game.text.loading'])
         self.label['center'].draw()
Esempio n. 2
0
 def update(self):
     self.info_layer.begin_update()
     if self.model is None:
         self.info_layer.document = text.decode_attributed('')
     else:
         self.info_layer.document = text.decode_attributed(self.display_model())
     self.info_layer.end_update()
Esempio n. 3
0
 def add_dialogue(self, text):
     log_info('dialogue add: %s' % text)
     try:
         decode_attributed(text)
     except:
         text = '{color (255, 0, 0, 255)}decode error'
     else:
         pass
     self.dialogue.append(text)
     self.last = time.time()
     if len(self.shown) < 10:
         self.shown.append(text)
     else:
         self.shown.pop(0)
         self.shown.append(text)
Esempio n. 4
0
 def draw(self):
     # 两个换行符表示真正的换行
     text = decode_attributed(
         '{color (255, 255, 255, 255)}{background_color (0, 0, 0, 64)}' +
         '\n\n'.join(self.shown))
     self.dialogue_label.document = text
     self.dialogue_label.draw()
Esempio n. 5
0
    def prepend_text(self, formatted_text):
        "Preprends formatted text to the document"
        formatted_text += "{}\n"
        document = text.decode_attributed(formatted_text)
        self.document.insert_text(0, document.text)

        for attribute, runlist in document._style_runs.iteritems():
            for start, stop, value in runlist:
                self.document.set_style(start, stop, {attribute:value})
Esempio n. 6
0
    def append_text(self, formatted_text):
        "Adds formatted text to the document"
        document = text.decode_attributed("\n" + formatted_text)
        insert_pos = len(self.document.text)
        self.document.insert_text(insert_pos, document.text)

        for attribute, runlist in document._style_runs.iteritems():
            for start, stop, value in runlist:
                self.document.set_style(start + insert_pos, stop + insert_pos, {attribute:value})

        if self.info_layer.height < self.info_layer.content_height:
            self.info_layer.view_y = self.info_layer.height - self.info_layer.content_height
Esempio n. 7
0
 def __init__(self, width, height):
     self.dialogue_label = pyglet.text.DocumentLabel(decode_attributed(''),
                                                     x=0,
                                                     y=height - 75,
                                                     width=width // 2,
                                                     multiline=True)
     # 全部聊天内容
     self.dialogue = []
     # 实际显示的聊天内容
     self.shown = []
     # 最后一条聊天发送的时间
     self.last = time.time()
Esempio n. 8
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.batch = graphics.Batch()
        self.document = text.decode_attributed(doctext)
        self.margin = 2
        self.layout = layout.IncrementalTextLayout(
            self.document, self.width - self.margin * 2, self.height - self.margin * 2, multiline=True, batch=self.batch
        )
        self.caret = caret.Caret(self.layout)
        self.push_handlers(self.caret)

        self.set_mouse_cursor(self.get_system_mouse_cursor("text"))
Esempio n. 9
0
    def __init__(self, *args, **kwargs):
        super(TestWindow, self).__init__(*args, **kwargs)

        self.batch = graphics.Batch()
        self.document = text.decode_attributed(doctext)
        self.margin = 2
        self.layout = layout.IncrementalTextLayout(self.document,
            self.width - self.margin * 2, self.height - self.margin * 2,
            multiline=True,
            batch=self.batch)
        self.caret = caret.Caret(self.layout)
        self.push_handlers(self.caret)

        self.set_mouse_cursor(self.get_system_mouse_cursor('text'))
Esempio n. 10
0
    def __init__(self, multiline, wrap_lines, msg, *args, **kwargs):
        super(TestWindow, self).__init__(*args, **kwargs)

        self.batch = graphics.Batch()
        self.document = text.decode_attributed(msg)
        self.margin = 2
        self.layout = layout.IncrementalTextLayout(self.document,
            (self.width - self.margin * 2), 
            self.height - self.margin * 2,
            multiline=multiline,
            wrap_lines=wrap_lines,
            batch=self.batch)
        self.caret = caret.Caret(self.layout)
        self.push_handlers(self.caret)

        self.wrap_lines = wrap_lines

        self.set_mouse_cursor(self.get_system_mouse_cursor('text'))
Esempio n. 11
0
    def __init__(self, multiline, wrap_lines, msg, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.batch = graphics.Batch()
        self.document = text.decode_attributed(msg)
        self.margin = 2
        self.layout = layout.IncrementalTextLayout(
            self.document, (self.width - self.margin * 2),
            self.height - self.margin * 2,
            multiline=multiline,
            wrap_lines=wrap_lines,
            batch=self.batch)
        self.caret = caret.Caret(self.layout)
        self.push_handlers(self.caret)

        self.wrap_lines = wrap_lines

        self.set_mouse_cursor(self.get_system_mouse_cursor('text'))
Esempio n. 12
0
 def __init__(self, *args, **kwargs):
     super(Window, self).__init__(*args, **kwargs)
     # 窗口是否捕获鼠标
     self.exclusive = False
     # 玩家状态: 是否潜行, 是否飞行...
     self.player = {}
     self.player['stealing'] = False
     self.player['flying'] = False
     self.player['running'] = False
     self.player['die'] = False
     self.player['in_hud'] = False
     self.player['press_e'] = False
     # Strafing is moving lateral to the direction you are facing,
     # e.g. moving to the left or right while continuing to face forward.
     #
     # First element is -1 when moving forward, 1 when moving back, and 0
     # otherwise. The second element is -1 when moving left, 1 when moving
     # right, and 0 otherwise.
     self.player['strafe'] = [0, 0]
     # 玩家在世界中的位置 (x, y, z)
     self.player['position'] = (0, 4, 0)
     self.player['respawn_position'] = (0, 4, 0)
     # 拓展功能
     self.ext = {}
     self.ext['debug'] = False
     self.ext['open'] = False
     self.ext['position'] = False
     self.ext['running'] = False
     # First element is rotation of the player in the x-z plane (ground
     # plane) measured from the z-axis down. The second is the rotation
     # angle from the ground plane up. Rotation is in degrees.
     #
     # The vertical plane rotation ranges from -90 (looking straight down) to
     # 90 (looking straight up). The horizontal rotation range is unbounded.
     self.rotation = (0, 0)
     # Which sector the player is currently in.
     self.sector = None
     # 这个十字在屏幕中央
     self.reticle = None
     # Velocity in the y (upward) direction.
     self.dy = 0
     # 玩家可以放置的方块, 使用数字键切换
     self.inventory = [
         'grass', 'dirt', 'sand', 'stone', 'log', 'leaf', 'brick', 'plank',
         'craft_table'
     ]
     # 玩家手持的方块
     self.block = self.inventory[0]
     # 数字键列表
     self.num_keys = [
         key._1, key._2, key._3, key._4, key._5, key._6, key._7, key._8,
         key._9, key._0
     ]
     # 这个标签在画布的上方显示
     self.label = {}
     self.label['top'] = pyglet.text.DocumentLabel(decode_attributed(''),
                                                   x=0,
                                                   y=self.height - 30,
                                                   anchor_x='left',
                                                   anchor_y='center')
     self.is_init = True
     # 这个标签在画布正中偏上显示
     self.label['center'] = pyglet.text.DocumentLabel(decode_attributed(''),
                                                      x=self.width // 2,
                                                      y=self.height // 2 +
                                                      50,
                                                      anchor_x='center',
                                                      anchor_y='center')
     # 这个标签在画布正中偏下显示
     self.label['actionbar'] = pyglet.text.DocumentLabel(
         decode_attributed(''),
         x=self.width // 2,
         y=self.height // 2 - 100,
         anchor_x='center',
         anchor_y='center')
     # 加载用图片
     self.loading_image = image.load(
         os.path.join(path['texture'], 'loading.png'))
     self.loading_image.height = self.height
     self.loading_image.width = self.width
     # 覆盖屏幕的矩形
     self.full_screen = Rectangle(0, 0, self.width, self.height)
     # 聊天区
     self.dialogue = Dialogue(self.width, self.height)
     # 将 self.upgrade() 方法每 1.0 / TICKS_PER_SEC 调用一次, 它是游戏的主事件循环
     pyglet.clock.schedule_interval(self.update, 1.0 / TICKS_PER_SEC)
     # 检测玩家是否应该死亡
     pyglet.clock.schedule_interval(self.check_die, 1.0 / TICKS_PER_SEC)
     # 每10秒更新一次方块数据
     pyglet.clock.schedule_interval(self.update_status, 10.0)
     # 每60秒保存一次进度
     pyglet.clock.schedule_interval(self.save, 30.0)
     log_info('welcome %s(id: %s)' % (player['name'], player['id']))
Esempio n. 13
0
 def display(self, txt):
     self.document = text.decode_attributed(txt)
     self.info_layer = text.layout.IncrementalTextLayout(self.document, width= self.info_w
                                                                 , height = self.info_h
                                                                 , multiline=True)
     self.info_layer.x, self.info_layer.y = PADDING, PADDING