def __init__(self, text, block_movement=True): self.text = text self.block_movement = block_movement Menu.__init__(self, g_cfg.screen_width - 2 * cfg.border_width, g_cfg.screen_height / 2 - 2 * cfg.border_width, cfg.border_width, g_cfg.screen_height / 2 + cfg.border_width, bg=TRANSPARENT, blocking=block_movement) panel = Panel(self.width, self.height) self.add_widget(panel, (0, 0)) font = self.theme.get_font(cfg.font_size) box_width = g_cfg.screen_width - 4 * cfg.border_width lines = build_lines(self.text, box_width, font) # Draw message y_acc = 0 for line in lines: label = Label(line[2]) panel.add_widget(label, (cfg.border_width, cfg.border_width + y_acc)) y_acc += line[1] + cfg.line_spacing
def __init__(self, text, block_movement=True): self.text = text self.block_movement = block_movement # Split into lines theme = menu_config.theme font = theme.get_font(cfg.font_size) box_width = g_cfg.screen_width - 4 * cfg.border_width lines = build_lines(self.text, box_width, font) # Calculate box size self.box_height = (sum([line[1] for line in lines]) + (len(lines) - 1) * cfg.line_spacing + 4 * cfg.border_width) assert self.box_height < g_cfg.screen_height,\ 'Too much text for one box.' Menu.__init__(self, g_cfg.screen_width - 2 * cfg.border_width, self.box_height - 2 * cfg.border_width, cfg.border_width, g_cfg.screen_height - self.box_height\ + cfg.border_width, bg=TRANSPARENT, blocking=block_movement) panel = Panel(self.width, self.height) self.add_widget(panel, (0, 0)) # Draw message y_acc = 0 for line in lines: label = Label(line[2]) panel.add_widget(label, (cfg.border_width, cfg.border_width + y_acc)) y_acc += line[0] + cfg.line_spacing
def __init__(self, item_menu, item, quantity, item_entry, width, height, x=0, y=0, theme=None, bg=TRANSPARENT, mouse_control=Menu.MOUSE_LOOSE): Menu.__init__(self, width, height, x, y, theme, bg, mouse_control) self.item_menu = item_menu self.item = item self.quantity = quantity self.panel = Panel(width, height) self.add_widget(self.panel, (0, 0)) if hasattr(item, 'use'): self.use_label = UseLabel(self.item, self.item_menu.inventory, self.item_menu.party, item_entry) else: self.use_label = TrashLabel(self.item, self.item_menu.inventory, item_entry) self.panel.add_widget(self.use_label, (20, 12)) self.close_label = CloseLabel() self.panel.add_widget(self.close_label, (20, 36)) cursor = Cursor() cursor.bind(self)
class ActionDialog(Menu): def __init__(self, item_menu, item, quantity, item_entry, width, height, x=0, y=0, theme=None, bg=TRANSPARENT, mouse_control=Menu.MOUSE_LOOSE): Menu.__init__(self, width, height, x, y, theme, bg, mouse_control) self.item_menu = item_menu self.item = item self.quantity = quantity self.panel = Panel(width, height) self.add_widget(self.panel, (0, 0)) if hasattr(item, 'use'): self.use_label = UseLabel(self.item, self.item_menu.inventory, self.item_menu.party, item_entry) else: self.use_label = TrashLabel(self.item, self.item_menu.inventory, item_entry) self.panel.add_widget(self.use_label, (20, 12)) self.close_label = CloseLabel() self.panel.add_widget(self.close_label, (20, 36)) cursor = Cursor() cursor.bind(self)
def __init__(self, text, block_movement=True): self.text = text self.block_movement = block_movement self.current_panel = None Menu.__init__(self, g_cfg.screen_width - 2 * cfg.border_width, g_cfg.screen_height / 2 - 2 * cfg.border_width, cfg.border_width, g_cfg.screen_height / 2 + cfg.border_width, bg=TRANSPARENT, blocking=block_movement) # Split into lines font = self.theme.get_font(cfg.font_size) box_width = g_cfg.screen_width - 4 * cfg.border_width lines = build_lines(self.text, box_width, font) # Split into boxes box_height = g_cfg.screen_height / 2 - 4 * cfg.border_width self.boxes = split_boxes(lines, box_height, cfg.line_spacing) self.panels = [] # Draw panels for box in self.boxes: panel = Panel(self.width, self.height) y_acc = 0 for line in box: label = Label(line[2]) panel.add_widget(label, (cfg.border_width, cfg.border_width + y_acc)) y_acc += line[1] + cfg.line_spacing self.panels.append(panel) self.advance_panel()
class ItemMenu(Menu): def __init__(self, inventory, party, width, height, x=0, y=0, theme=None, bg=None, mouse_control=Menu.MOUSE_LOOSE): self.inventory = inventory self.party = party Menu.__init__(self, width, height, x, y, theme, bg, mouse_control) self.close_label = CloseLabel() self.add_widget(self.close_label, (20, 12)) self.inventory_panel = Panel(self.width * 0.55, self.height - 50) self.add_widget(self.inventory_panel, (16, self.height - 16, LEFT, DOWN)) self.inventory_scroll = ItemScrollArea(self.inventory, self.inventory_panel.width - 10, self.inventory_panel.height - 10, graphics_config.item_icon_height + 12, (20, 10)) self.inventory_panel.add_widget(self.inventory_scroll, (5, 5)) self.info_panel = ItemInfoPanel(self.width * 0.35, self.height * 0.55) info_x = self.width - 16 info_y = self.height - 16 self.add_widget(self.info_panel, (info_x, info_y, RIGHT, DOWN)) cursor = Cursor() cursor.bind(self) self.config_action_dialog(100, 60, TRANSPARENT) def config_action_dialog(self, width=None, height=None, bg=None): if width is not None: self.action_dialog_width = width if height is not None: self.action_dialog_height = height self.action_dialog_bg = bg def create_action_dialog(self, item_entry): x = (self.inventory_scroll.get_menu_position()[0] + self.inventory_scroll.width + 12) y = self.menu.y + 12 dialog = ActionDialog(self, item_entry.item, item_entry.quantity, item_entry, self.action_dialog_width, self.action_dialog_height, x, y, theme=self.theme, bg=self.action_dialog_bg) return dialog def remove_line(self, item): for i in xrange(len(self.inventory_scroll)): if self.inventory_scroll[i].get_contents()[0].item == item: self.inventory_scroll.remove_line(i) break
def __init__(self, width, height): Panel.__init__(self, width, height) self.speed_labels = [] x = 20 SPACING = 40 for txt, speed in (('Stop', 0), ('Play', 3), ('Fast', 6), ('Very Fast', 30), ('Crazy', 120)): l = SpeedLabel(txt, speed) self.add_widget(l, (x, self.height/2, LEFT, CENTER)) self.speed_labels.append(l) x += SPACING + l.width
def __init__(self, inventory, party, width, height, x=0, y=0, theme=None, bg=None, mouse_control=Menu.MOUSE_LOOSE): self.inventory = inventory self.party = party Menu.__init__(self, width, height, x, y, theme, bg, mouse_control) self.close_label = CloseLabel() self.add_widget(self.close_label, (20, 12)) self.inventory_panel = Panel(self.width * 0.55, self.height - 50) self.add_widget(self.inventory_panel, (16, self.height - 16, LEFT, DOWN)) self.inventory_scroll = ItemScrollArea(self.inventory, self.inventory_panel.width - 10, self.inventory_panel.height - 10, graphics_config.item_icon_height + 12, (20, 10)) self.inventory_panel.add_widget(self.inventory_scroll, (5, 5)) self.info_panel = ItemInfoPanel(self.width * 0.35, self.height * 0.55) info_x = self.width - 16 info_y = self.height - 16 self.add_widget(self.info_panel, (info_x, info_y, RIGHT, DOWN)) cursor = Cursor() cursor.bind(self) self.config_action_dialog(100, 60, TRANSPARENT)
def __init__(self, ingame, width, height): Panel.__init__(self, width, height) self.ingame = ingame SPACING = 20 y = 25 x = SPACING self.time_label = Label('xx minutes', focusable=False, size=16) self.add_widget(self.time_label, (x, y, LEFT, CENTER)) x += self.time_label.width + SPACING self.score_label = Label('', focusable=False, size=20) self.add_widget(self.score_label, (x, y, LEFT, CENTER)) y += SPACING self.event_area = EventArea(width - 2 * SPACING, height - y - SPACING) self.add_widget(self.event_area, (SPACING, y))
def __init__(self, width, height): Panel.__init__(self, width, height, focusable=False) self.item_icon = ImageWidget(None, focusable=False) x = 10 y = 10 self.add_widget(self.item_icon, (x, y)) self.item_name = Label("", focusable=False) x = 10 + graphics_config.item_icon_width + 5 y = 10 + (graphics_config.item_icon_height - self.item_name.height) / 2 self.add_widget(self.item_name, (x, y)) self.item_description = Label("", self.width - 20, size=10, focusable=False) x = 10 y = (10 + max(self.item_name.height, graphics_config.item_icon_height) + 10) self.add_widget(self.item_description, (x, y))
def __init__(self, text, choices, user_data=None, completion_callback=None, block_movement=True): self.block_movement = block_movement self.text = text self.choices = choices self.completion_callback = completion_callback self.user_data = user_data Menu.__init__(self, g_cfg.screen_width - 2 * cfg.border_width, g_cfg.screen_height / 2 - 2 * cfg.border_width, cfg.border_width, g_cfg.screen_height / 2 + cfg.border_width, bg=TRANSPARENT, blocking=block_movement) panel = Panel(self.width, self.height) self.add_widget(panel, (0, 0)) # Build lines and choice lines font = self.theme.get_font(cfg.font_size) self.__build_lines(font) # Draw message y_acc = 0 for line in self.lines: label = Label(line[2], focusable=False) panel.add_widget(label, (cfg.border_width, cfg.border_width + y_acc)) y_acc += line[1] + cfg.line_spacing self.starting_option = None for index, line in enumerate(self.choice_lines): label = ChoiceLabel(line[2], index) panel.add_widget(label, (2 * cfg.border_width, cfg.border_width + y_acc)) y_acc += line[1] + cfg.choice_line_spacing if self.starting_option is None: self.starting_option = label Cursor(ArrowCursorTheme()).bind(self, self.starting_option)
def __init__(self): Menu.__init__(self, 400, 300) self.panel = Panel(200, 150) self.add_widget(self.panel, (40, 80)) self.add_widget(MenuLabel(), (90, 20)) self.add_widget(Label('NonFocusable', focusable=False), (150, 20)) first_panel_label = Label('Panel0') self.panel.add_widget(first_panel_label, (40, 20)) self.panel.add_widget(Label('Panel1'), (120, 20)) self.panel.add_widget(Label('Panel2'), (40, 60)) self.panel.add_widget(Label('Panel3'), (120, 60)) self.panel.add_widget(AdjustableBar(100, 14, filled=0.9), (50, 100)) side_panel = Panel(110, 220) self.add_widget(side_panel, (260, 40)) grid = AdjustableVerticalGrid(110, 72, 2, 6) side_panel.add_widget(grid, AlignTopLeft()) img = pygame.image.load(data_path('icon.png')) #img = pygame.image.load(data_path('test.png')) self.add_widget(ImageWidget(img), (8, 8)) group = WidgetGroup(148, 20) group.add_widget(Label('Group0'), (10, 0)) group.add_widget(Label('Group1'), (90, 0)) self.add_widget(group, (60, 240)) #self.crystallize() # Add cursor cursor = Cursor() cursor.bind(self, first_panel_label)
class TestMenu(Menu): def __init__(self): Menu.__init__(self, 400, 300) self.panel = Panel(200, 150) self.add_widget(self.panel, (40, 80)) self.add_widget(MenuLabel(), (90, 20)) self.add_widget(Label('NonFocusable', focusable=False), (150, 20)) first_panel_label = Label('Panel0') self.panel.add_widget(first_panel_label, (40, 20)) self.panel.add_widget(Label('Panel1'), (120, 20)) self.panel.add_widget(Label('Panel2'), (40, 60)) self.panel.add_widget(Label('Panel3'), (120, 60)) self.panel.add_widget(AdjustableBar(100, 14, filled=0.9), (50, 100)) side_panel = Panel(110, 220) self.add_widget(side_panel, (260, 40)) grid = AdjustableVerticalGrid(110, 72, 2, 6) side_panel.add_widget(grid, AlignTopLeft()) img = pygame.image.load(data_path('icon.png')) #img = pygame.image.load(data_path('test.png')) self.add_widget(ImageWidget(img), (8, 8)) group = WidgetGroup(148, 20) group.add_widget(Label('Group0'), (10, 0)) group.add_widget(Label('Group1'), (90, 0)) self.add_widget(group, (60, 240)) #self.crystallize() # Add cursor cursor = Cursor() cursor.bind(self, first_panel_label)
def __init__(self, inventory, party, width, height, x=0, y=0, theme=None, bg=None, mouse_control=Menu.MOUSE_LOOSE): self.inventory = inventory self.party = party Menu.__init__(self, width, height, x, y, theme, bg, mouse_control) self.close_label = CloseLabel() self.add_widget(self.close_label, (20, 12)) self.inventory_panel = Panel(self.width * 0.55, self.height - 50) self.add_widget(self.inventory_panel, (16, self.height - 16, LEFT, DOWN)) self.inventory_scroll = ItemScrollArea( self.inventory, self.inventory_panel.width - 10, self.inventory_panel.height - 10, graphics_config.item_icon_height + 12, (20, 10)) self.inventory_panel.add_widget(self.inventory_scroll, (5, 5)) self.info_panel = ItemInfoPanel(self.width * 0.35, self.height * 0.55) info_x = self.width - 16 info_y = self.height - 16 self.add_widget(self.info_panel, (info_x, info_y, RIGHT, DOWN)) cursor = Cursor() cursor.bind(self) self.config_action_dialog(100, 60, TRANSPARENT)
def __init__(self): Menu.__init__(self, 480, 320) tab_group = TabGroup(['Bars%d' % (i + 1) for i in xrange(self.TABS)], 480, 320, tab_height=30) self.add_widget(tab_group, AlignCenter()) # Bar tabs for k in xrange(4): grid = Grid(480, 290, 4, 10) for i in xrange(4): for j in xrange(10): grid[i, j].add_widget(Panel(120, 29), AlignCenter()) width = 10 + 10 * (i + 1) height = 1 + j bar = CrazyBar(width, height) grid[i, j].add_widget(bar, AlignCenter()) tab_group[k].add_widget(grid, AlignCenter()) # Animated image tab surfaces = [] for k in xrange(25): s = pygame.Surface((100, 100)) s.fill(((25 - k) * 10, 0, k * 10)) surfaces.append(s) for k in xrange(25): s = pygame.Surface((100, 100)) s.fill((0, k * 10, (25 - k) * 10)) surfaces.append(s) for k in xrange(25): s = pygame.Surface((100, 100)) s.fill((k * 10, (25 - k) * 10, 0)) surfaces.append(s) animation = AnimatedImage(surfaces, 1) a = AnimatedImageWidget(animation, False) tab_group[4].add_widget(a, AlignTop()) # Add cursor cursor = Cursor() cursor.bind(self)
def __init__(self, ingame, width, height): Panel.__init__(self, width, height, focusable=False) self.chalkboard = Chalkboard(ingame, 280, 400) self.add_widget(self.chalkboard, AlignCenter())
class ItemMenu(Menu): def __init__(self, inventory, party, width, height, x=0, y=0, theme=None, bg=None, mouse_control=Menu.MOUSE_LOOSE): self.inventory = inventory self.party = party Menu.__init__(self, width, height, x, y, theme, bg, mouse_control) self.close_label = CloseLabel() self.add_widget(self.close_label, (20, 12)) self.inventory_panel = Panel(self.width * 0.55, self.height - 50) self.add_widget(self.inventory_panel, (16, self.height - 16, LEFT, DOWN)) self.inventory_scroll = ItemScrollArea( self.inventory, self.inventory_panel.width - 10, self.inventory_panel.height - 10, graphics_config.item_icon_height + 12, (20, 10)) self.inventory_panel.add_widget(self.inventory_scroll, (5, 5)) self.info_panel = ItemInfoPanel(self.width * 0.35, self.height * 0.55) info_x = self.width - 16 info_y = self.height - 16 self.add_widget(self.info_panel, (info_x, info_y, RIGHT, DOWN)) cursor = Cursor() cursor.bind(self) self.config_action_dialog(100, 60, TRANSPARENT) def config_action_dialog(self, width=None, height=None, bg=None): if width is not None: self.action_dialog_width = width if height is not None: self.action_dialog_height = height self.action_dialog_bg = bg def create_action_dialog(self, item_entry): x = (self.inventory_scroll.get_menu_position()[0] + self.inventory_scroll.width + 12) y = self.menu.y + 12 dialog = ActionDialog(self, item_entry.item, item_entry.quantity, item_entry, self.action_dialog_width, self.action_dialog_height, x, y, theme=self.theme, bg=self.action_dialog_bg) return dialog def remove_line(self, item): for i in xrange(len(self.inventory_scroll)): if self.inventory_scroll[i].get_contents()[0].item == item: self.inventory_scroll.remove_line(i) break
def __init__(self, match_team, width, height): Panel.__init__(self, width, height) self.match_team = match_team self.refresh()