def __init__(self, x, y, title, width=400, height=200, colour=BROWN): self.colour = colour self.background = pygame.Surface((width, height)) self.width = width self.height = height self.title = ClickableAsset( self._BORDER_PIXELS, self._BORDER_PIXELS, width - 2 * self._BORDER_PIXELS, self._TITLE_HEIGHT_PIXELS - self._BORDER_PIXELS, '') # HAX, f**k it, make go now self.title_background = ScaledImageAsset(0, 0, width, self._TITLE_HEIGHT_PIXELS, TITLE_BACKGROUND) self.title_text = CentredTextAsset(0, 2, width, self._TITLE_HEIGHT_PIXELS, "== %s ==" % title, size=16, bold=True) self.body = ScaledImageAsset(0, self._TITLE_HEIGHT_PIXELS, width, height - self._TITLE_HEIGHT_PIXELS, BODY_BACKGROUND) self.title.offset_x = x self.title.offset_y = y self.assets = [] PicassoAsset.__init__(self, None, x, y)
def build_hint_asset(hint): return CentredTextAsset(graphics.INFO_PANEL_X, graphics.INFO_PANEL_Y, graphics.INFO_PANEL_WIDTH, graphics.INFO_PANEL_HEIGHT, hint, size=16, bold=True)
def __init__(self, x, y, title, width=400, height=200, colour=BROWN): self.colour = colour self.background = pygame.Surface((width, height)) self.width = width self.height = height self.title = ClickableAsset( self._BORDER_PIXELS, self._BORDER_PIXELS, width - 2 * self._BORDER_PIXELS, self._TITLE_HEIGHT_PIXELS - self._BORDER_PIXELS, '' ) # HAX, f**k it, make go now self.title_background = ScaledImageAsset(0, 0, width, self._TITLE_HEIGHT_PIXELS, TITLE_BACKGROUND) self.title_text = CentredTextAsset(0, 2, width, self._TITLE_HEIGHT_PIXELS, "== %s ==" % title, size=16, bold=True) self.body = ScaledImageAsset( 0, self._TITLE_HEIGHT_PIXELS, width, height - self._TITLE_HEIGHT_PIXELS, BODY_BACKGROUND) self.title.offset_x = x self.title.offset_y = y self.assets = [] PicassoAsset.__init__(self, None, x, y)
class DialogAsset(PicassoAsset): _BORDER_PIXELS = 5 _TITLE_HEIGHT_PIXELS = 25 def __init__(self, x, y, title, width=400, height=200, colour=BROWN): self.colour = colour self.background = pygame.Surface((width, height)) self.width = width self.height = height self.title = ClickableAsset( self._BORDER_PIXELS, self._BORDER_PIXELS, width - 2 * self._BORDER_PIXELS, self._TITLE_HEIGHT_PIXELS - self._BORDER_PIXELS, '') # HAX, f**k it, make go now self.title_background = ScaledImageAsset(0, 0, width, self._TITLE_HEIGHT_PIXELS, TITLE_BACKGROUND) self.title_text = CentredTextAsset(0, 2, width, self._TITLE_HEIGHT_PIXELS, "== %s ==" % title, size=16, bold=True) self.body = ScaledImageAsset(0, self._TITLE_HEIGHT_PIXELS, width, height - self._TITLE_HEIGHT_PIXELS, BODY_BACKGROUND) self.title.offset_x = x self.title.offset_y = y self.assets = [] PicassoAsset.__init__(self, None, x, y) def draw(self): self.background.fill(BLACK) # pygame.draw.rect(self.background, self.colour, pygame.Rect( # self._BORDER_PIXELS, self._BORDER_PIXELS, # self.width - 2 * self._BORDER_PIXELS, # self.height - 2 * self._BORDER_PIXELS, # )) # pygame.draw.line(self.background, BLACK, # (0, self._TITLE_HEIGHT_PIXELS), # (self.width, self._TITLE_HEIGHT_PIXELS), # self._BORDER_PIXELS, # ) self.background.blit(self.title.draw(), self.title.get_coordinate()) self.background.blit(self.title_background.draw(), self.title_background.get_coordinate()) self.background.blit(self.title_text.draw(), self.title_text.get_coordinate()) self.background.blit(self.body.draw(), self.body.get_coordinate()) assets = list(self.assets) for asset in assets: self.background.blit( asset.draw(), (asset.x, self._TITLE_HEIGHT_PIXELS + asset.y)) return self.background def dialog_height(self): return self.height - self._TITLE_HEIGHT_PIXELS def add_text(self, rel_x, rel_y, text, size=18): new_asset = TextAsset(0, 0, text, size=size) if rel_x == None: rel_x = (self.width - new_asset.get_width()) / 2 if rel_y == None: rel_y = (self.height - self._TITLE_HEIGHT_PIXELS - new_asset.get_height()) / 2 new_asset.x = rel_x new_asset.y = rel_y self.assets.append(new_asset) return new_asset def being_dragged(self, pos=None): return self.title.mouse_hovering(pos) def move_to(self, x, y): self.x = x self.y = y self.title.offset_x = x self.title.offset_y = y for asset in self.assets: asset.offset_x = x asset.offset_y = y def finished(self): return True def drag_dialog(self): # pygame doesn't properly set relative position on first call for some # reason... pygame.mouse.get_rel() self.title.force_highlight = True while pygame.mouse.get_pressed()[0]: mouse_delta = pygame.mouse.get_rel() new_x = max(self.x + mouse_delta[0], 0) new_x = min(new_x, get_picasso().get_width() - self.width) new_y = max(self.y + mouse_delta[1], 0) new_y = min(new_y, get_picasso().get_height() - self.height) self.move_to(new_x, new_y) time.sleep(0) pump() self.title.force_highlight = False
class DialogAsset(PicassoAsset): _BORDER_PIXELS = 5 _TITLE_HEIGHT_PIXELS = 25 def __init__(self, x, y, title, width=400, height=200, colour=BROWN): self.colour = colour self.background = pygame.Surface((width, height)) self.width = width self.height = height self.title = ClickableAsset( self._BORDER_PIXELS, self._BORDER_PIXELS, width - 2 * self._BORDER_PIXELS, self._TITLE_HEIGHT_PIXELS - self._BORDER_PIXELS, '' ) # HAX, f**k it, make go now self.title_background = ScaledImageAsset(0, 0, width, self._TITLE_HEIGHT_PIXELS, TITLE_BACKGROUND) self.title_text = CentredTextAsset(0, 2, width, self._TITLE_HEIGHT_PIXELS, "== %s ==" % title, size=16, bold=True) self.body = ScaledImageAsset( 0, self._TITLE_HEIGHT_PIXELS, width, height - self._TITLE_HEIGHT_PIXELS, BODY_BACKGROUND) self.title.offset_x = x self.title.offset_y = y self.assets = [] PicassoAsset.__init__(self, None, x, y) def draw(self): self.background.fill(BLACK) #pygame.draw.rect(self.background, self.colour, pygame.Rect( # self._BORDER_PIXELS, self._BORDER_PIXELS, # self.width - 2 * self._BORDER_PIXELS, # self.height - 2 * self._BORDER_PIXELS, #)) #pygame.draw.line(self.background, BLACK, # (0, self._TITLE_HEIGHT_PIXELS), # (self.width, self._TITLE_HEIGHT_PIXELS), # self._BORDER_PIXELS, #) self.background.blit(self.title.draw(), self.title.get_coordinate()) self.background.blit(self.title_background.draw(), self.title_background.get_coordinate()) self.background.blit(self.title_text.draw(), self.title_text.get_coordinate()) self.background.blit(self.body.draw(), self.body.get_coordinate()) assets = list(self.assets) for asset in assets: self.background.blit(asset.draw(), (asset.x, self._TITLE_HEIGHT_PIXELS + asset.y )) return self.background def dialog_height(self): return self.height - self._TITLE_HEIGHT_PIXELS def add_text(self, rel_x, rel_y, text, size=18): new_asset = TextAsset(0, 0, text, size=size) if rel_x == None: rel_x = (self.width - new_asset.get_width()) / 2 if rel_y == None: rel_y = (self.height - self._TITLE_HEIGHT_PIXELS - \ new_asset.get_height()) / 2 new_asset.x = rel_x new_asset.y = rel_y self.assets.append(new_asset) return new_asset def being_dragged(self, pos=None): return self.title.mouse_hovering(pos) def move_to(self, x, y): self.x = x self.y = y self.title.offset_x = x self.title.offset_y = y for asset in self.assets: asset.offset_x = x asset.offset_y = y def finished(self): return True def drag_dialog(self): # pygame doesn't properly set relative position on first call for some # reason... pygame.mouse.get_rel() self.title.force_highlight = True while pygame.mouse.get_pressed()[0]: mouse_delta = pygame.mouse.get_rel() new_x = max(self.x + mouse_delta[0], 0) new_x = min(new_x, get_picasso().get_width() - self.width) new_y = max(self.y + mouse_delta[1], 0) new_y = min(new_y, get_picasso().get_height() - self.height) self.move_to(new_x, new_y) time.sleep(0) pump() self.title.force_highlight = False