def display(title, message=None): message_text = None message_rect = None title_text = textrect(title, ui.typography["title"], width, colors.GOLD) title_rect = title_text.get_rect() title_rect.x += padding[3] title_rect.y += padding[0] tooltip_rect = pygame.Rect(0, 0, title_rect.w + padding[1] + padding[3], title_rect.h + padding[0] + padding[2]) if message is not None: message_text = textrect(message, ui.typography["system"], width, colors.WHITE) message_rect = message_text.get_rect() message_rect.x += padding[3] message_rect.y += title_rect.h + title_rect.y + separator_padding tooltip_rect.h += message_rect.h + separator_padding tooltip = pygame.surface.Surface((tooltip_rect.w, tooltip_rect.h)) tooltip.blit(gradients.vertical((tooltip_rect.w, tooltip_rect.h), colors.OPAQUE_DARK_GRAY, colors.OPAQUE_BLACK), (0, 0)) pygame.draw.rect(tooltip, colors.GOLD, tooltip_rect, 1) tooltip.blit(title_text, title_rect) if message_text is not None: tooltip.blit(message_text, message_rect) game_rect = game.background.get_rect() tooltip_rect.x = game.resolution[0] - tooltip_rect.w - margin[3] tooltip_rect.y = game.resolution[1] - tooltip_rect.h - margin[0] game.screen.blit(tooltip, tooltip_rect)
def __init__(self, title, message, buttons={}): frame_title = "dialogue_{0}".format(title) self.frame = Frame(frame_title, x, y, width, height, z) self.frame.title = title self.buttons = buttons self.frame.closeable = True background = pygame.surface.Surface((width, height)) background.blit(gradients.vertical((width, height), colors.OPAQUE_GRAY, colors.OPAQUE_BLACK), (0, 0)) self.frame.background = background textbox = self.frame.background.subsurface(pygame.Rect(50, 40, text_width, text_height)) button_rect = pygame.Rect(25, 60 + text_height, button_width, 25) button_area = self.frame.background.subsurface(button_rect) textrect(message, ui.typography["title"], text_width, colors.WHITE, surface=textbox) created_buttons = [] for button_create in buttons: created_buttons.append(Button(button_create[0], button_create[1])) total = len(created_buttons) padding = (button_width - (total * button.width)) / (total + 1) button_index = 0 for btn in created_buttons: btn_offset = button_area.get_abs_offset() btn_rect = pygame.Rect((padding * (button_index + 1)) + (button.width * button_index), 0, button.width, button.height) button_area.blit(btn.image, (btn_rect.x, btn_rect.y)) btn_rect.x += btn_offset[0] + x btn_rect.y += btn_offset[1] + y game.addClickableFrame(btn_rect, self.frame, btn.action, 2) button_index += 1
def __init__(self, label, action): """""" self.label = label self.action = action self.image = pygame.surface.Surface((width, height)) self.image.blit(gradients.vertical((width, height), colors.OPAQUE_DARK_RED, colors.OPAQUE_RED), (0, 0)) textrect(label, ui.typography["subtitle"], width, colors.WHITE, surface=self.image, align=1)
def renderPhysical(): player = game.player label = "{0} / {1}".format(int(player.physical_health), int(player.physical_capacity)) width = int(player.percent_physical_health * bar_size[0]) physical_bar.fill(colors.DARK_GRAY) if width > 0: physical_bar.blit(gradients.horizontal((width, bar_size[1]), colors.OPAQUE_DARK_RED, colors.OPAQUE_RED), (0, 0)) textrect(label, ui.typography["system"], bar_size[0], colors.WHITE, align=1, surface=physical_bar)
def addTriggerCount(name, count, bg_color=colors.RED, text_color=colors.WHITE): if name in _hotspots: hotspot = _hotspots[name] rect = pygame.Rect( hotspot.x + hotspot.w - (count_radius / 2), hotspot.y + hotspot.h - (count_radius / 2), count_radius * 2, count_radius * 2, ) pygame.draw.circle(background, bg_color, (rect.x, rect.y), count_radius) rect.x += count_radius / 2 rect.y -= count_radius - count_padding label = str(int(count)) textrect(label, ui.typography["ui"], rect.w, text_color, align=rect, surface=background)
def renderRanks(): active_page = frame.getPage(frame.active_page) for spell_details in _spell_pages[frame.active_page]: spell_name, spell_rect = spell_details spell_rank = _spell_ranks[spell_name] spell_rank_rect = spell_rank.get_rect() spell_rank.fill(colors.BLACK) rank = str(game.player.learned_spells[spell_name]) text = textrect(rank, ui.typography["ui"], spell_rank_rect.w, colors.WHITE, align=1) spell_rank.blit(text, (0, 0)) pygame.draw.rect(spell_rank, colors.SILVER, spell_rank_rect, 1) active_page.blit(spell_rank, (spell_rect.x - 5, spell_rect.y + spell_rect.h - 5)) label = "Available skill points: {0}".format(game.player.skill_points) page_rect = active_page.get_rect() avail_text = textrect(label, ui.typography["subtitle"], page_rect.w - 5, colors.GOLD, colors.BLACK, align=2) text_rect = avail_text.get_rect() active_page.blit(avail_text, (0, page_rect.h - text_rect.h - 5))
def renderMental(): player = game.player label = "{0} / {1}".format(int(player.mental_strain), int(player.mental_capacity)) width = int(player.percent_mental_stability * bar_size[0]) mental_bar.fill(colors.DARK_GRAY) stability_width = player.mental_stability * bar_size[0] stability_rect = pygame.Rect(bar_size[0] - stability_width, 0, stability_width, bar_size[1]) stability = mental_bar.subsurface(stability_rect) stability.fill(colors.GRAY) if width > 0: mental_bar.blit(gradients.horizontal((width, bar_size[1]), colors.OPAQUE_DARK_BLUE, colors.OPAQUE_BLUE), (0, 0)) textrect(label, ui.typography["system"], bar_size[0], colors.WHITE, align=1, surface=mental_bar)