Exemplo n.º 1
0
    def __init__(self,
                 window,
                 bus,
                 title='Welcome to tabulr',
                 draw_waves=False):
        """
        Initialize the Scene object.
        :param window: Pyglet window object. Must be same throughout application.
        :param bus: Event bus. Used for communicating scene changes to main application thread.
        """
        self.window = window
        self.window_title = title
        self.bus = bus
        self.batch = Batch()
        self.margin = 36
        self.sprites = {}
        self.inputs = []

        # Error message
        self.error_msg = Text('',
                              size=12,
                              bold=True,
                              batch=self.batch,
                              x=self.margin,
                              color=(236, 64, 122, 255))
        self.error_elapsed = 0
        self.error_opacity = 0

        # Waves background
        if draw_waves:
            waves_img = image('side-waves.png')
            waves_img.anchor_x = waves_img.width
            waves = Sprite(waves_img, x=window.width, y=0, batch=self.batch)
            waves.opacity = 160
            self.init_sprite('waves', waves, is_button=False)
Exemplo n.º 2
0
    def __init__(self, window, bus):
        super().__init__(window, bus)
        self.title = Text('Welcome to',
                          batch=self.batch,
                          x=self.margin,
                          y=(self.window.height // 2) + 100)
        self.title_bold = Text('tabulr',
                               bold=True,
                               batch=self.batch,
                               x=self.margin,
                               y=(self.window.height // 2) + 60)
        self.subtitle = Text(
            'Your schedule, from list to wallpaper. Like magic.',
            size=12,
            batch=self.batch,
            x=self.margin,
            y=self.window.height // 2)
        self.init_sprite(
            'next_button',
            Button('next',
                   self.window,
                   self.batch,
                   x=self.margin,
                   y=(self.window.height // 2) - 100))

        waves = Sprite(image('front-waves.png'), x=0, y=-30, batch=self.batch)
        waves.opacity = 140
        self.elapsed = 0
        self.init_sprite('waves', waves, is_button=False)
Exemplo n.º 3
0
 def draw(self, group):
     batch = Batch()
     ss = []
     for particle in group:
         s = Sprite(self.image, batch=batch)
         s.position = list(particle.position)[:2]
         s.color = [c * 255 for c in list(particle.color)[:3]]
         s.scale = particle.size[0] / 64.0
         s.rotation = particle.age * 720
         s.opacity = particle.color[3] * 255
         ss.append(s)
     batch.draw()
Exemplo n.º 4
0
    def addEntry(self, title="No title", action=None, top=False):
        h = self.but_h
        w = self.but_w
        x = self.w.width / 2
        y = (
            self.w.height / 2 - (h * len(self.entries)) +
            self.spacing
        )
        if title == "New Game":
            btn_texture = self.w.textures["button_green_jagged"]
        elif title == "Exit":
            btn_texture = self.w.textures["button_red"]
        else:
            btn_texture = self.w.textures["button_brown"]
        b_sprite = Sprite(
                        btn_texture,
                        x=x,
                        y=y,
                        batch=self.w.batches["mm_buttons"],
                        group=self.w.ui_group,
                    )
        b_sprite.opacity = 150
        # b_sprite.width, b_sprite.height = 3, 1
        b_sprite.rectangle = create_rectangle(x, y, w, h)
        b_sprite.action = action
        b_sprite.label = text.Label(
            title, font_name='Visitor TT1 BRK',
            font_size=self.font_size,
            color=self.font_clr,
            x=x, y=y,
            batch=self.w.batches["mm_labels"],
            anchor_x="center", anchor_y="center"
        )
        b_sprite.label.oldfontsize = b_sprite.label.font_size
        b_sprite.orig_size = self.but_w, self.but_h
        b_sprite.bw, b_sprite.bh = b_sprite.orig_size

        if top:
            self.entries.insert(0, b_sprite)
            self.updateOffset()
        else:
            self.entries.append(b_sprite)
            self.updateOffset()
Exemplo n.º 5
0
    def context_menu(self, obj, action="show"):
        self.wipe_context_menu()
        category = "context"
        texture = image.load(RES_PATH + 'ui/upgrade.png')
        texture = center_image(texture)
        offset =  (
            0.0 - texture.width // 2,
            obj.height // 2 + texture.height // 2
        )
        b_sprite = Sprite(
                texture,
                x=obj.x + offset[0],
                y=obj.y + offset[1],
                batch=self.w.batches["buttons"],
                group=self.w.ui_group
        )

        b_sprite.offset = offset
        b_sprite.active = True
        b_sprite.b_price = obj.price // 2
        if b_sprite.b_price > self.w.game.gold:
            b_sprite.opacity = 80
        b_sprite.b_type = "upgrade"
        b_sprite.category = category
        b_sprite.owner = obj
        self.context_sprites.append(b_sprite)

        size = 10
        offset = (
            0.0 - texture.width // 2 + 1,
            obj.height // 2 + texture.height // 2 + (size * 1.5) - 1
        )
        x = obj.x + offset[0]
        y = obj.y + offset[1]
        label = text.Label(
            str(obj.price // 2), font_name='Visitor TT1 BRK',
            font_size=size,
            x=x,
            y=y,
            batch=self.w.batches["buttons"],
            anchor_x="center", anchor_y="center",
            color=(32, 32, 32, 196)
        )
        label.offset = offset
        label.owner = obj
        label.b_type = "upgrade"
        label.category = category
        label.shadow = True
        self.context_sprites.append(label)

        offset = (
            0.0 - texture.width // 2,
            obj.height // 2 + texture.height // 2 + (size * 1.5)
        )
        x = obj.x + offset[0]
        y = obj.y + offset[1]
        label = text.Label(
            str(obj.price // 2), font_name='Visitor TT1 BRK',
            font_size=size,
            x=x,
            y=y,
            batch=self.w.batches["buttons"],
            anchor_x="center", anchor_y="center",
            color=(130, 255, 130, 255)
        )
        label.offset = offset
        label.owner = obj
        label.b_type = "upgrade"
        label.category = category
        label.shadow = False
        if obj.price // 2 > self.w.game.gold:
            label.color = (255, 140, 140, 225)
        self.context_sprites.append(label)

        texture = image.load(RES_PATH + 'ui/sell.png')
        texture = center_image(texture)
        offset =  (
            texture.width // 2,
            obj.height // 2 + texture.height // 2
        )
        b_sprite = Sprite(
                texture,
                x=obj.x + offset[0],
                y=obj.y + offset[1],
                batch=self.w.batches["buttons"],
                group=self.w.ui_group
        )
        b_sprite.offset = offset
        b_sprite.active = True
        b_sprite.b_price = obj.price
        b_sprite.b_type = "sell"
        b_sprite.category = category
        b_sprite.owner = obj
        self.context_sprites.append(b_sprite)
Exemplo n.º 6
0
    def showContextMenu(self, obj, action="show"):
        self.wipeContextMenu()
        category = "context"
        texture = self.w.textures['upgrade']
        offset =  (
            -texture.width,
            0
        )
        b_sprite = Sprite(
                texture,
                x=obj.x + offset[0],
                y=obj.y + offset[1],
                batch=self.w.batches["buttons"],
                group=self.w.ui_group
        )

        b_sprite.offset = offset
        b_sprite.active = True
        b_sprite.b_price = obj.price // 2
        if b_sprite.b_price > self.w.game.gold:
            b_sprite.opacity = 80
        b_sprite.b_type = "upgrade"
        b_sprite.category = category
        b_sprite.owner = obj
        self.context_sprites.append(b_sprite)

        size = 10
        offset = (
            -texture.width - 1,
            texture.width // 2 - 1
        )
        x = obj.x + offset[0]
        y = obj.y + offset[1]
        label = text.Label(
            str(obj.price // 2), font_name='Visitor TT1 BRK',
            font_size=size,
            x=x,
            y=y,
            batch=self.w.batches["buttons"],
            anchor_x="center", anchor_y="center",
            color=(32, 32, 32, 196)
        )
        label.offset = offset
        label.owner = obj
        label.b_type = "upgrade"
        label.category = category
        label.shadow = True
        self.context_sprites.append(label)

        size = 10
        offset = (
            0,
            obj.image.height
        )
        x = obj.x + offset[0]
        y = obj.y + offset[1]
        label = text.Label(
            str(int(obj.dmg)), font_name='Visitor TT1 BRK',
            font_size=size,
            x=x,
            y=y,
            batch=self.w.batches["buttons"],
            anchor_x="center", anchor_y="center",
            color=(32, 32, 32, 255)
        )
        label.offset = offset
        label.owner = obj
        label.b_type = "towerinfo"
        label.category = category
        label.shadow = False
        self.context_sprites.append(label)

        offset = (
            -texture.width,
            texture.width // 2
        )
        x = obj.x + offset[0]
        y = obj.y + offset[1]
        label = text.Label(
            str(obj.price // 2), font_name='Visitor TT1 BRK',
            font_size=size,
            x=x,
            y=y,
            batch=self.w.batches["buttons"],
            anchor_x="center", anchor_y="center",
            color=(130, 255, 130, 255)
        )
        label.offset = offset
        label.owner = obj
        label.b_type = "upgrade"
        label.category = category
        label.shadow = False
        if obj.price // 2 > self.w.game.gold:
            label.color = (255, 140, 140, 225)
        self.context_sprites.append(label)

        texture = self.w.textures["sell"]
        offset = (
            texture.width,
            0
        )
        b_sprite = Sprite(
                texture,
                x=obj.x + offset[0],
                y=obj.y + offset[1],
                batch=self.w.batches["buttons"],
                group=self.w.ui_group
        )
        b_sprite.offset = offset
        b_sprite.active = True
        b_sprite.b_price = obj.price
        b_sprite.b_type = "sell"
        b_sprite.category = category
        b_sprite.owner = obj
        self.context_sprites.append(b_sprite)
Exemplo n.º 7
0
    def __init__(self, parent_window, course_data, on_close):
        # Create window
        super().__init__(parent_window, on_close, caption='Confirm courses')

        # Window background
        gl.glClearColor(43 / 255, 65 / 255, 98 / 255, 1)
        waves = Sprite(image('front-waves.png'), x=0, y=0, batch=self.batch)
        waves.opacity = 160

        # The courses entered so far will be stored in self.course_data.
        # This is a dict, where each key is the course section
        # and the value is a tuple of the format (<title>, <venue>, <instructor>).
        self.course_data = course_data

        # UI text
        self.x_coords = [80, 250, 370,
                         480]  # section, title, venue, instructor
        self.heading_y = self.height - 90
        self.labels = [
            Text('Confirm your',
                 x=self.margin,
                 y=self.height - self.margin - 12,
                 size=20,
                 batch=self.batch),
            Text('courses',
                 x=self.margin + 170,
                 y=self.height - self.margin - 12,
                 size=20,
                 bold=True,
                 batch=self.batch),
            Text('Section',
                 x=self.x_coords[0],
                 y=self.heading_y,
                 size=12,
                 bold=True,
                 batch=self.batch),
            Text('Title',
                 x=self.x_coords[1],
                 y=self.heading_y,
                 size=12,
                 bold=True,
                 batch=self.batch),
            Text('Venue',
                 x=self.x_coords[2],
                 y=self.heading_y,
                 size=12,
                 bold=True,
                 batch=self.batch),
            Text('Instructor',
                 x=self.x_coords[3],
                 y=self.heading_y,
                 size=12,
                 bold=True,
                 batch=self.batch),
            Text('Page 1 of 1',
                 x=self.margin * 4,
                 y=self.margin + 8,
                 size=10,
                 batch=self.batch)
        ]

        # Next button
        next_button = Button('next', self, self.batch, y=self.margin)
        next_button.x = self.width - next_button.image.width - 24
        next_button.scale = 0.8
        self.ui_buttons = [next_button]

        # Table pagination
        self.page = 0
        self.pages = []
        self.paginate()
        self.ui_buttons.extend([
            Button('left', self, self.batch, x=self.margin, y=self.margin),
            Button('right', self, self.batch, x=self.margin * 2,
                   y=self.margin),
        ])

        # Rows
        self.delete_buttons = []
        self.course_rows = []
        self.generate_rows()