Ejemplo n.º 1
0
    def __init__(self, filename, **kwargs):
        kwargs.update({
            'width': 500,
            'height': 500,
            'vsync': True,
            'resizable': True,
        })
        super(BoxWorldWindow, self).__init__(**kwargs)
        # create a pyglet window and set glOptions.
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        # needed so that graphs.egi knows where to draw.
        egi.InitWithPyglet(self)
        egi.text_color(name='BLACK')

        glClearColor(0.9, 0.9, 0.9, 1.0)
        # Grey.
        #create a world for graph searching.
        #filename = kwargs['filename'] #"boxworld2.txt.
        #filename = 'map2.txt'.
        self.world = BoxWorld.FromFile(filename, self.get_size())
        self.world.reset_navgraph()
        # prep the fps display and some labels.
        self.fps_display = None
        # clock.ClockDisplay().
        clBlack = (0, 0, 0, 255)
        self.labels = {
            'mouse': Label('', x=5, y=self.height - 20, color=clBlack),
            'search': Label('', x=120, y=self.height - 20, color=clBlack),
            'status': Label('', x=300, y=self.height - 20, color=clBlack),
        }
        self._update_label()
        # add the extra event handlers we need.
        self.add_handers()
        # search limit.
        self.limit = 0
Ejemplo n.º 2
0
def drawLabel(text, pos=(0, 0), center=True):
    _standard_label = Label(text='standard Label',
                            font_size=200,
                            bold=True,
                            color=(255, 255, 255, 75))
    _standard_label.anchor_x = 'left'
    _standard_label.anchor_y = 'bottom'
    _standard_label.x = 0
    _standard_label.y = 0
    _standard_label.text = text
    glPushMatrix()
    glTranslated(pos[0], pos[1], 0.0)
    glScaled(0.3, 0.3, 1)
    _standard_label.draw()
    glPopMatrix()
Ejemplo n.º 3
0
 def __init__(self, heading, buttons, left, right, bottom, top):
     super().__init__(left, right, bottom, top)
     self.heading = heading
     font_size = 50
     x = left
     y = bottom
     self.heading_label = Label(heading,
                                font_name='Courier New',
                                font_size=font_size,
                                x=left,
                                y=y + int(font_size / 2))
     self.buttons = buttons
     self.highlightables = list(buttons)
     self.x = x
     self.y = y
Ejemplo n.º 4
0
    def process_user_input(self, ilet):
        view = self.view
        self.inputlet = ilet

        self.confirmbtn = UIActionConfirmButtons(
            parent=self,
            x=259,
            y=4,
            width=165,
            height=24,
        )
        self.progress_bar = BigProgressBar(parent=self, x=0, y=0, width=250)
        self.label = Label(
            text=u"HEY SOMETHING'S WRONG",
            x=125,
            y=28,
            font_size=12,
            color=(255, 255, 160, 255),
            shadow=(2, 0, 0, 0, 179),
            anchor_x='center',
            anchor_y='bottom',
        )

        view.selection_change += self._on_selection_change

        g = Game.getgame()
        port = view.player2portrait(g.me)
        port.equipcard_area.clear_selection()

        # view.selection_change.notify()  # the clear_selection thing will trigger this

        @self.confirmbtn.event
        def on_confirm(is_ok, force=False):
            if is_ok:
                ilet.set_result(*self.get_result())

            elif not force and view.get_selected_skills():
                view.reset_selected_skills()
                return

            ilet.done()
            end_transaction(self.trans)

        self.progress_bar.value = LinearInterp(
            1.0,
            0.0,
            ilet.timeout,
            on_done=lambda *a: on_confirm(False, force=True))
    def on_key_press(self, symbol, modifiers):
        print(time(), symbol, sep="\t")
        if symbol == key.ESCAPE:  # [ESC]
            self.alive = 0
        elif symbol == key.C:
            print('Rendering cat')
            self.clear_sprites()
            self.sprites.append(CustomSprite('img/cat.png', x=10, y=10))
        elif symbol == key.D:
            print('Rendering dog')
            self.clear_sprites()
            self.sprites.append(CustomSprite('img/dog.png', x=10, y=10))
        elif symbol == key.R:
            print('Rendering hello')
            self.label = HTMLLabel(
                '''<font face="Times New Roman" size="42" color="white">
                       Hello, <i>world</i></font>''',
                x=self.width // 2,
                y=self.height // 2,
                anchor_x='center',
                anchor_y='center')
            self.label.draw()

        elif symbol == key.T:
            print('Rendering hello plain')
            self.clear_sprites()
            self.label = Label(
                'Hello, world',
                font_name='Times New Roman',
                font_size=42,
                x=self.width // 2,
                y=self.height // 2,
                anchor_x='center',
                anchor_y='center',
                color=(255, 0, 0, 255),
            )
        elif symbol == key.SPACE:
            print('Starting Game')
            images = gen_image()
            for i in images:
                sleep(5)
                print('Rendering Next Home')
                self.clear_sprites()
                self.clear_sprites()
                print(i)
                # i = i.split("/")[1]
                # image = pyglet.image.load(i)
                self.sprites.append(CustomSprite(i, x=10, y=10))
Ejemplo n.º 6
0
    def __init__(self, width, height):
        self.width = width
        self.height = height
        self.batch = Batch()
        self.load_sprites()

        self.booty_sprite = self.create_sprite('booty', self.width - 50, 15)
        self.booty = 0
        self.booty_score = Label('0',
                                 font_name=FONT_NAME,
                                 font_size=28,
                                 color=(205, 175, 2, 0xff),
                                 x=self.width - 60,
                                 y=20,
                                 anchor_x='right',
                                 batch=self.batch)
Ejemplo n.º 7
0
def GetLabel(text, pyglet_font):
    """ Returns a Pyglet Label object for the given text and font """
    key = (text, pyglet_font)
    if key not in GlobalTextCache:
        # Use anchor_y="bottom" because by default, pyglet sets the baseline to
        # the y coordinate given.  Unfortunately, it doesn't expose a per-Text
        # descent (only a per-Font descent), so it's impossible to know how to
        # offset the y value properly for a given string.
        label = Label(text,
                      font_name=pyglet_font.name,
                      font_size=pyglet_font.size,
                      anchor_y="bottom")
        GlobalTextCache[key] = label
    else:
        label = GlobalTextCache[key]
    return label
Ejemplo n.º 8
0
 def __init__(self, number: str, point1: Point, point2: Point, color):
     self.cords = [
         point1.x, point1.y,
         point2.x, point1.y,
         point2.x, point2.y,
         point1.x, point2.y
     ]
     self.color = deepcopy(color)
     self.label = Label(
         number,
         font_name='Arial',
         font_size=20,
         color=(0, 0, 0, 255),
         x=(point1.x + point2.x) // 2,
         y=(point1.y + point2.y) // 2,
         anchor_x='center', anchor_y='center')
Ejemplo n.º 9
0
 def _planet_stamp(self, planet, value):
     pos = self.game_to_screen(planet.x, planet.y)
     radius = (self.ratio * PLANET_MIN_R) + (
         (PLANET_FACTOR * self.ratio) * planet.growth_rate)
     view_radius = planet.vision_range() * self.ratio
     color = COLOR[planet.owner_id]
     label = Label(
         # Added some rounding here for visual clarity
         str(int(value)),
         color=COLOR_NAMES_255['BLACK'],
         x=pos[0],
         y=pos[1],
         anchor_x='center',
         anchor_y='center')
     return ScreenPlanet(pos, planet.owner_id, radius, view_radius, color,
                         label)
Ejemplo n.º 10
0
    def setup(self):
        MenuView.setup(self)
        width, height = self.controller.window.width, self.controller.window.height

        self.layout = VerticalLayout(0, 0)

        self.text_input = TextWidget(self.controller.window,
                                     G.IP_ADDRESS,
                                     0,
                                     0,
                                     width=160,
                                     height=20,
                                     font_name='Arial',
                                     batch=self.batch)
        self.controller.window.push_handlers(self.text_input)
        self.text_input.focus()

        def text_input_callback(symbol, modifier):
            G.IP_ADDRESS = self.text_input.text

        self.text_input.push_handlers(key_released=text_input_callback)

        button = self.Button(caption=G._("Connect to server"),
                             on_click=self.controller.start_multiplayer_game)
        self.layout.add(button)
        self.buttons.append(button)
        button = self.Button(caption=G._("Launch server"),
                             on_click=self.launch_server)
        self.layout.add(button)
        self.buttons.append(button)
        button = self.Button(caption=G._("Done"),
                             on_click=self.controller.main_menu)
        self.layout.add(button)
        self.buttons.append(button)

        self.label = Label('Play Multiplayer',
                           font_name='ChunkFive Roman',
                           font_size=25,
                           x=width // 2,
                           y=self.frame.y + self.frame.height,
                           anchor_x='center',
                           anchor_y='top',
                           color=(255, 255, 255, 255),
                           batch=self.batch,
                           group=self.labels_group)

        self.on_resize(width, height)
Ejemplo n.º 11
0
    def __init__(self, **kwargs):
        # rip out the game settings we want
        players = kwargs.pop('players')
        gamestate = kwargs.pop('gamestate')
        self.game = PlanetWars(gamestate)
        for p in players:
            self.game.add_player(p)
        self.max_tick = kwargs.pop('max_game_length')
        self.max_tick += self.max_tick / 2

        # set and use pyglet window settings
        kwargs.update({
            'width': 500,
            'height': 500,
            'vsync': True,
            'resizable': False,
        })
        super(PlanetWarsWindow, self).__init__(**kwargs)
        # create a pyglet window and set glOptions
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
        glClearColor(0., 0., 0., 1.0)  # Grey

        # current "pen" colour of lines
        self.pen_color = (1, 0, 0, 1.)
        self.stroke = 1.0  # - thickness default
        self.qobj = gluNewQuadric()
        # gluQuadricDrawStyle(self.qobj, GLU_FILL) #GLU_SILHOUETTE)

        # prep the fps display and some labels
        self.fps_display = clock.ClockDisplay()
        clWhite = (255, 255, 255, 255)
        self.step_label = Label('STEP', x=5, y=self.height - 20, color=clWhite)
        self.fps = 0
        self.set_fps(20)
        self.paused = True
        self.view_id = 0
        self.label_type = 'num_ships'

        # create adaptor to help with drawing
        self.adaptor = PlanetWarsScreenAdapter(self.game, self.circle)

        # prep the game (space!)
        self.reset_space()
        # add extra event handlers we need
        self.add_handlers()
Ejemplo n.º 12
0
    def _generate_text(self):
        real_cord = lambda x, y: (x + self.camera.offset_x, y + self.camera.
                                  offset_y)

        menu_texts = reversed(self.action_menu_items.keys())
        for label in self.action_menu_texts:
            label.delete()

        for i, text in enumerate(menu_texts):
            text_x, text_y = real_cord(40, 150 - 50 * i)
            self.action_menu_texts.append(
                Label(text,
                      font_name='Times New Roman',
                      font_size=36,
                      x=text_x,
                      y=text_y,
                      batch=self.text_batch))
Ejemplo n.º 13
0
	def _create(self, x, y):
		self._title = Label(
			"_______________ LOG _______________",
			x=x,
			y=y + self.height + 5,
			height=20,
			batch=self._log
		)
		self._doc = decode_text("\n")
		self._doc.set_style(0, 0, dict(color=(255, 255, 255, 255)))

		self._box = ScrollableTextLayout(
			self._doc, self.width, self.height,
			multiline=True, batch=self._log
		)
		self._box.x = x
		self._box.y = y
Ejemplo n.º 14
0
    def size(self, frame):
        if frame is None:
            return
        Widget.size(self, frame)
        self.active = True
        if self.label is None:
            self.group = self.parentFrame.fgGroup
            self.label = Label(self.text,
                               batch=self.parentFrame.batch,
                               group=self.parentFrame.fgGroup,
                               font_name=self.fontName,
                               font_size=self.fontSize,
                               color=self.color)

            font = self.label.document.get_font()
            self.width = self.label.content_width
            self.height = font.ascent - font.descent
Ejemplo n.º 15
0
    def setup(self):
        MenuView.setup(self)
        width, height = self.controller.window.width, self.controller.window.height

        self.layout = VerticalLayout(0, 0)

        textures_enabled = len(G.texture_pack_list.available_texture_packs) > 1

        self.text_input = TextWidget(self.controller.window, G.USERNAME, 0, 0, width=160, height=20, font_name='Arial', batch=self.batch)
        self.controller.window.push_handlers(self.text_input)
        self.text_input.focus()
        self.text_input.caret.mark = len(self.text_input.document.text)  # Don't select the whole text
        def text_input_callback(symbol, modifier):
            G.USERNAME = self.text_input.text
        self.text_input.push_handlers(key_released=text_input_callback)

        hl = HorizontalLayout(0, 0)
        sb = self.Scrollbar(x=0, y=0, width=300, height=40, sb_width=20, sb_height=40, caption="Music")
        hl.add(sb)

        def change_sound_volume(pos):
            print(G.EFFECT_VOLUME)
            G.EFFECT_VOLUME = float(float(pos) / 100)
        sb = self.Scrollbar(x=0, y=0, width=300, height=40, sb_width=20, sb_height=40, caption="Sound", pos=int(G.EFFECT_VOLUME * 100), on_pos_change=change_sound_volume)
        hl.add(sb)
        self.layout.add(hl)

        hl = HorizontalLayout(0, 0)
        button = self.Button(width=300, caption=G._("Controls..."), on_click=self.controller.controls)
        hl.add(button)
        self.buttons.append(button)
        button = self.Button(width=300, caption=G._("Textures"), on_click=self.controller.textures, enabled=textures_enabled)
        hl.add(button)
        self.buttons.append(button)
        self.layout.add(hl)

        button = self.Button(width=610, caption=G._("Done"), on_click=self.controller.main_menu)
        self.layout.add(button)
        self.buttons.append(button)

        self.label = Label('Options', font_name='ChunkFive Roman', font_size=25, x=width/2, y=self.frame.y + self.frame.height,
            anchor_x='center', anchor_y='top', color=(255, 255, 255, 255), batch=self.batch,
            group=self.labels_group)

        self.on_resize(width, height)
Ejemplo n.º 16
0
def drawLabel(text, pos=(0, 0), **kwargs):
    kwargs.setdefault('font_size', 16)
    kwargs.setdefault('center', False)
    if kwargs.get('center'):
        kwargs.setdefault('anchor_x', 'center')
        kwargs.setdefault('anchor_y', 'center')
    else:
        kwargs.setdefault('anchor_x', 'left')
        kwargs.setdefault('anchor_y', 'bottom')
    del kwargs['center']
    temp_label = Label(text, **kwargs)
    #temp_label.x, temp_label.y = pos
    glPushMatrix()
    #glTranslated(-pos[0]-8.5,-pos[1]-8,0)
    glScaled(0.02, 0.02, 0.02)
    temp_label.draw()
    glPopMatrix()
    return temp_label.content_width
Ejemplo n.º 17
0
 def create_verts(self, x, y):
     self.__del__()
     self._x = x
     self._y = y
     self._label = Label(self._name,
                         x=x + self._width + 8,
                         y=y,
                         batch=self.batch,
                         group=self.group,
                         align='center')
     verts, colors = button(x=x,
                            y=y,
                            width=self._width,
                            height=self._height,
                            pressed=self._value)
     self._vertex_list = self.batch.add(
         len(verts) // 2, GL_TRIANGLES, self.group, ('v2f', verts),
         ('c3B', colors))
Ejemplo n.º 18
0
 def create_verts(self, x, y):
     self.__del__()
     self._x = x
     self._y = y
     self._label = Label(self._name,
                         x=x + self._width + 8,
                         y=y + 2,
                         batch=self.batch,
                         group=self.group)
     verts, colors = checkbox(x=x,
                              y=y,
                              width=self._width,
                              height=self._height,
                              border=4,
                              checked=self._value)
     self._vertex_list = self.batch.add(
         len(verts) // 2, GL_TRIANGLES, self.group, ('v2f', verts),
         ('c3B', colors))
Ejemplo n.º 19
0
	def run(self):
		self.window.set_visible()
		self.window.set_mouse_visible(False)
		self.window.set_exclusive_mouse(True)

		clock = pyglet.clock.Clock()
		fps_display = Label(x=0, y=0, anchor_y="top", font_size=14)
		while not self.window.has_exit:
			self.window.dispatch_events()
			self.updateFrame()
			fps_display.text = f"FPS: {pyglet.clock.get_fps()}"
			fps_display.draw()
			self.draw()
			self.window.flip()
			
			dt = clock.tick()

		print("fps:  %d" % clock.get_fps())
Ejemplo n.º 20
0
    def __init__(self, width, height):
        self.message_labels = []
        self.batch = pyglet.graphics.Batch()

        self.width = width
        self.height = height

        self.money = Label(text=u'0€',
                           x=self.width - 10,
                           y=self.height - 30,
                           font_name=FONT_NAME,
                           font_size=20,
                           anchor_x='right',
                           anchor_y='baseline',
                           color=GOLD + (255, ),
                           batch=self.batch)

        self.countdown = None
Ejemplo n.º 21
0
 def __init__(self, overlay):
     self.overlay = overlay
     self.batch = self.overlay.batch
     self.counter = 0
     self.dots = ''
     self.saving_lbl = Label('',
                             font_name='Consolas',
                             font_size=20,
                             color=(
                                 0,
                                 0,
                                 0,
                                 255,
                             ),
                             batch=self.batch,
                             anchor_x='center',
                             anchor_y='center',
                             x=self.overlay.centerX,
                             y=self.overlay.height - 30)
Ejemplo n.º 22
0
 def __init__(self, overlay):
     self.overlay = overlay
     self.batch = self.overlay.batch
     self.debug_lbl = Label('',
                            font_name='Consolas',
                            font_size=12,
                            color=(
                                0,
                                0,
                                0,
                                255,
                            ),
                            batch=self.batch,
                            x=10,
                            y=self.overlay.height - 10,
                            anchor_x='left',
                            anchor_y='top')
     self.level = None
     self.setLevel(self.overlay.game.data.engine.core.debug_lvl)
Ejemplo n.º 23
0
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        self.world = World()
        self.exclusive = False

        self.rotation = (0, 0)
        self.position = (0, 0, -10)
        self.movement_direction = [0, 0]
        schedule_interval(self.update, 1.0 / TICKS_PER_SECOND)

        self.label = Label('',
                           font_name='Arial',
                           font_size=18,
                           x=10,
                           y=self.height - 10,
                           anchor_x='left',
                           anchor_y='top',
                           color=(0, 0, 0, 255))
Ejemplo n.º 24
0
 def __init__(self, x, y, width, height, text):
     self._size = win_width, win_height = get_size()
     super().__init__(x, win_height - y, width, height)
     self._width = width
     self._depressed_img = image.load(join(path['texture.ui'],
                                           'button.png'))
     self._pressed_img = image.load(
         join(path['texture.ui'], 'button_over.png'))
     self._sprite = Sprite(self._depressed_img, x, win_height - y)
     self._text = text
     self._label = Label(self._text,
                         align='center',
                         anchor_x='center',
                         anchor_y='center',
                         x=x + width / 2,
                         y=win_height - y + height / 2 - 2,
                         font_name='minecraftia')
     self._pressed = False
     self._enable = True
Ejemplo n.º 25
0
    def process_user_input(self, ilet):
        parent = self.parent
        self.confirmbtn = ConfirmButtons(parent=self,
                                         x=259,
                                         y=4,
                                         width=165,
                                         height=24,
                                         buttons=((u'确定', True), (u'结束',
                                                                  False)))
        self.progress_bar = BigProgressBar(parent=self, x=0, y=0, width=250)
        self.label = Label(
            text=u"HEY SOMETHING'S WRONG",
            x=125,
            y=28,
            font_size=12,
            color=(255, 255, 160, 255),
            shadow=(2, 0, 0, 0, 179),
            anchor_x='center',
            anchor_y='bottom',
        )

        def dispatch_selection_change():
            self.confirmbtn.buttons[0].state = Button.DISABLED
            self.on_selection_change()

        parent.push_handlers(on_selection_change=dispatch_selection_change)

        g = Game.getgame()
        port = parent.player2portrait(g.me)
        port.equipcard_area.clear_selection()

        #dispatch_selection_change() # the clear_selection thing will trigger this

        @self.confirmbtn.event
        def on_confirm(is_ok):
            is_ok and ilet.set_result(*self.get_result())
            ilet.done()
            end_transaction(self.trans)

        self.progress_bar.value = LinearInterp(
            1.0, 0.0, ilet.timeout, on_done=lambda *a: on_confirm(False))

        self.inputlet = ilet
Ejemplo n.º 26
0
    def process_user_input(self, ilet):
        try:
            ui_meta = ilet.initiator.ui_meta
            choose_option_buttons = ui_meta.choose_option_buttons
            choose_option_prompt = ui_meta.choose_option_prompt
            if callable(choose_option_prompt):
                choose_option_prompt = choose_option_prompt(ilet.initiator)

        except AttributeError:
            choose_option_buttons = ((u'确定', True), (u'结束', False))
            choose_option_prompt = u'UIChooseOption: %s missing ui_meta' % (
                ilet.initiator.__class__.__name__)

        self.confirmbtn = ConfirmButtons(parent=self,
                                         x=259,
                                         y=4,
                                         width=165,
                                         height=24,
                                         buttons=choose_option_buttons)
        self.progress_bar = b = BigProgressBar(parent=self,
                                               x=0,
                                               y=0,
                                               width=250)
        b.value = LinearInterp(1.0,
                               0.0,
                               ilet.timeout,
                               on_done=lambda *a: on_confirm(None))
        self.label = Label(
            text=choose_option_prompt,
            x=125,
            y=28,
            font_size=12,
            color=(255, 255, 160, 255),
            shadow=(2, 0, 0, 0, 179),
            anchor_x='center',
            anchor_y='bottom',
        )

        @self.confirmbtn.event
        def on_confirm(val):
            ilet.set_option(val)
            ilet.done()
            end_transaction(self.trans)
Ejemplo n.º 27
0
    def __init__(self, handler, index, x, y, name, count=0, framesize=50):
        self.handler, self.index, = handler, index,
        self.x, self.y, = x, y,

        self.frame = self.createFrame(framesize)
        self.label = Label('{}\n{}'.format(name, count),
                           anchor_x='center',
                           anchor_y='center',
                           align='center',
                           font_name='Impact',
                           font_size=16,
                           color=(255, 255, 255, 255),
                           bold=False,
                           multiline=True,
                           batch=self.handler.batch,
                           width=100,
                           height=100,
                           x=x,
                           y=100)
Ejemplo n.º 28
0
 def create_verts(self, x, y):
     self.__del__()
     self._x = x
     self._y = y
     self._knob_x = self._knob_x or x
     self._label = Label(self._name,
                         x=x + self._width + 8,
                         y=y + 2,
                         batch=self.batch,
                         group=self.group)
     verts, colors = slider(x=x,
                            y=y,
                            width=self._width,
                            height=self._height,
                            bar=4,
                            position=self._knob_x - self._knob_w)
     self._vertex_list = self.batch.add(
         len(verts) // 2, GL_TRIANGLES, self.group, ('v2f', verts),
         ('c3B', colors))
Ejemplo n.º 29
0
 def __init__(self, left, right, bottom, top, model: BaseModel):
     super().__init__(left, right, bottom, top)
     self._model = None
     self._view_scale = 1.
     self._view: BaseView = None
     self._position = MutableOffsets(0, 0, 0)
     self._rotation = MutableDegrees(0, 0, 0)
     padding = 20
     font_size = 12
     x = left + padding
     y = top - (font_size + padding)
     self._info_label = Label("N/A",
                              font_name='Courier New',
                              font_size=font_size,
                              x=x,
                              y=y,
                              multiline=True,
                              width=self.width - padding * 2)
     self.set_model(model)
Ejemplo n.º 30
0
 def draw(self):
     Rect(self.pos.x,
          self.pos.y,
          self.w,
          self.h,
          color=self.color,
          draw=True)
     self.label = Label(
         text=self.text,
         x=self.pos.x,
         y=self.pos.y,
         anchor_x=CENTER,
         # anchor_y=CENTER,
         width=self.w,
         height=-self.h,
         font_size=25,
         font_name="helvetica")
     self.label.draw()
     self.color = self.COLOR