def Special_Refresh(): extra.Tile_Texture( screen, "rivets.jpg", Rect(menu_margin, 0, menu_width, screen.get_rect().height)) edge = Rect(menu_margin, -10, menu_width + 10, screen.get_rect().height + 10) for r in [stats_rect, global_stats_rect, edge]: extra.Line_Edging(screen, r, False) r = picture.get_rect() r.center = picture_surf.get_rect().center extra.Line_Edging(picture_surf, r, False) picture_surf.blit(picture, r.topleft)
def __Draw(self, xxx_todo_changeme): (width_hint, height_hint) = xxx_todo_changeme surf = pygame.Surface((width_hint, height_hint)) bbox = Rect(0, 0, width_hint, height_hint) extra.Tile_Texture(surf, "006metal.jpg", surf.get_rect()) margin = 8 w = bbox.width - (margin * 2) th = None y = margin + bbox.top control_rects = [] max_width = 0 first_item = True for (num, name, hotkeys) in self.options: if (name == None): # a gap if (first_item): img = resource.Load_Image("header.jpg") img_r = img.get_rect() img_r.center = bbox.center img_r.top = y surf.blit(img, img_r.topleft) extra.Edge_Effect(surf, img_r) max_width = img_r.width + (margin * 2) y += img_r.height y += margin * 2 continue txt = render.Render(name, 18, (50, 200, 20), (200, 200, 0)) if (th == None): th = txt.get_rect().height + (margin * 2) tw = txt.get_rect().width + (margin * 2) if (tw > max_width): max_width = tw x = bbox.left + margin r = Rect(x, y, w, th) x += self.Justify(w, txt.get_rect().width) extra.Tile_Texture(surf, "greenrust.jpg", r) extra.Edge_Effect(surf, r) self.Enhancement_Interface(surf, num, r, margin) surf.blit(txt, (x, y + margin - 1)) y += th + margin control_rects.append((num, r)) first_item = False # Finalise drawing extra.Line_Edging(surf, bbox, True) return (surf, control_rects, (max_width, y))
def __Draw_H(self, title, text, height): width = self.width margin = 10 fs1 = 12 fs2 = 14 newline_gap = 12 surf = pygame.Surface((width, height)) bbox = surf.get_rect() extra.Tile_Texture(surf, "006metal.jpg", bbox) tsurf = stats.Get_Font(fs1).render(title, True, (250,250,200)) tsurf_r = tsurf.get_rect() tsurf_r.center = bbox.center tsurf_r.top = margin surf.blit(tsurf, tsurf_r.topleft) y = tsurf_r.bottom + margin # line edging for title extra.Line_Edging(surf, Rect(0,0,width,y), True) y += margin x = margin height = y while ( len(text) != 0 ): newline = False i = text.find(' ') j = text.find("\n") if (( j >= 0 ) and ( j < i )): i = j newline = True if ( i < 0 ): i = len(text) word = text[ : i ] + " " text = text[ i + 1 : ].lstrip() tsurf = stats.Get_Font(fs2).render(word, True, (250,200,250)) tsurf_r = tsurf.get_rect() tsurf_r.topleft = (x,y) if ( tsurf_r.right > ( width - 5 )): # Wrap. y += tsurf_r.height x = margin tsurf_r.topleft = (x,y) surf.blit(tsurf, tsurf_r.topleft) x = tsurf_r.right height = tsurf_r.bottom + margin if ( newline ): x = margin y = tsurf_r.bottom + newline_gap # line edging for rest of box extra.Line_Edging(surf, bbox, True) return (surf, height)
class Menu: def __init__(self, menu_options, force_width=0): self.options = menu_options self.control_rects = [] self.hover = None self.bbox = None self.selection = None self.update_required = True width_hint = height_hint = 10 if (force_width > 0): width_hint = force_width # Two attempts at drawing required. (discard1, discard2, (width_hint, height_hint)) = self.__Draw( (width_hint, height_hint)) if (width_hint < 150): width_hint = 150 if (force_width > 0): width_hint = force_width (self.surf_store, self.control_rects, (discard1, discard2)) = self.__Draw((width_hint, height_hint)) self.bbox = Rect(0, 0, width_hint, height_hint) def Get_Command(self): return self.selection def Select(self, snum): self.update_required = True self.selection = snum def Mouse_Move(self, spos): if ((spos == None) or (not self.bbox.collidepoint(spos))): self.hover = None return self.update_required = True (x, y) = spos old_sel = self.hover self.hover = None x -= self.bbox.left y -= self.bbox.top for (num, r) in self.control_rects: if (r.collidepoint(x, y)): self.hover = num if (old_sel != self.hover): sound.FX("click_s") return def Mouse_Down(self, spos): self.Mouse_Move(spos) if (self.hover != None): self.selection = self.hover sound.FX("click") def Key_Press(self, k): for (num, name, hotkeys) in self.options: if ((hotkeys != None) and (k in hotkeys)): self.selection = num self.update_required = True sound.FX("click") return def Draw(self, output, centre=None): if (self.update_required): self.update_required = False if (centre == None): self.bbox.center = output.get_rect().center else: self.bbox.center = centre self.bbox.clamp_ip(output.get_rect()) output.blit(self.surf_store, self.bbox.topleft) for (num, r) in self.control_rects: r = Rect(r) r.top += self.bbox.top r.left += self.bbox.left if (num == self.selection): pygame.draw.rect(output, (255, 255, 255), r, 1) elif (num == self.hover): pygame.draw.rect(output, (0, 180, 0), r, 1) def __Draw(self, (width_hint, height_hint)): surf = pygame.Surface((width_hint, height_hint)) bbox = Rect(0, 0, width_hint, height_hint) extra.Tile_Texture(surf, "006metal.jpg", surf.get_rect()) margin = 8 w = bbox.width - (margin * 2) th = None y = margin + bbox.top control_rects = [] max_width = 0 first_item = True for (num, name, hotkeys) in self.options: if (name == None): # a gap if (first_item): img = resource.Load_Image("header.jpg") img_r = img.get_rect() img_r.center = bbox.center img_r.top = y surf.blit(img, img_r.topleft) extra.Edge_Effect(surf, img_r) max_width = img_r.width + (margin * 2) y += img_r.height y += margin * 2 continue txt = render.Render(name, 18, (50, 200, 20), (200, 200, 0)) if (th == None): th = txt.get_rect().height + (margin * 2) tw = txt.get_rect().width + (margin * 2) if (tw > max_width): max_width = tw x = bbox.left + margin r = Rect(x, y, w, th) x += self.Justify(w, txt.get_rect().width) extra.Tile_Texture(surf, "greenrust.jpg", r) extra.Edge_Effect(surf, r) self.Enhancement_Interface(surf, num, r, margin) surf.blit(txt, (x, y + margin - 1)) y += th + margin control_rects.append((num, r)) first_item = False # Finalise drawing extra.Line_Edging(surf, bbox, True) return (surf, control_rects, (max_width, y))