def main_menu(): global main_menu_item main_menu_item = menu = PrettyMenu() menu.add( ui.Label('version %s' % features.get('app.version'), color=(255, 0, 0, 150), font=ui.consolefont), (0, 0)) new_game_button = MenuButton('New\ngame', new_game_menu) menu.left.add(new_game_button) load_game_button = MenuButton('Load\ngame', save.load_dialog) menu.left.add(load_game_button) if features.get('app.multiplayer'): menu.left.add(MenuButton('Connect', save.connect_dialog)) menu.right.add(MenuButton('Feed\nback', feedback)) menu.right.add( MenuButton( '', options.show_options, image=ui.load_image('data/user/options.png').convert_alpha())) menu.right.add(MenuButton('Exit', ui.back)) menu.right.add(ui.Spacing(0, 0)) ui.replace(menu)
def main_menu(): global main_menu_item main_menu_item = menu = PrettyMenu() version = 'version %s' % features.get('app.version') if features.get('gold.status') != 'none': version += '+' + features.get('gold.status') if features.get('gold.session_warning'): version += ' WARNING! Login with Dropbox in options menu to save your purchases.' menu.add(ui.Label('civsync.com; ' + version + ' ' + get_renderer_label(), color=(255, 0, 0, 150), font=ui.consolefont), (0, 0)) new_game_button = MenuButton('New\ngame', new_game_menu) menu.left.add(new_game_button) load_game_button = MenuButton('Load\ngame', save.load_dialog) menu.left.add(load_game_button) if features.get('gold.enable'): gold_button = MenuButton(u'civsync\n Gold', gold.menu) gold_button.fg = (255, 215, 0) gold_button.bg = (255, 215, 0, 100) menu.left.add(gold_button) if features.get('app.multiplayer'): menu.left.add(MenuButton('Connect', save.connect_dialog)) menu.right.add(MenuButton('', options.show_options, image=ui.load_image('userdata/options.png'))) menu.right.add(MenuButton('Exit', ui.back)) menu.right.add(ui.Spacing(0, 0)) ui.replace(menu)
def main_menu(): global main_menu_item main_menu_item = menu = PrettyMenu() version = 'version %s' % features.get('app.version') if features.get('gold.status') != 'none': version += '+' + features.get('gold.status') if features.get('gold.session_warning'): version += ' WARNING! Login with Dropbox in options menu to save your purchases.' menu.add(ui.Label('civsync.com; ' + version, color=(255, 0, 0, 150), font=ui.consolefont), (0, 0)) new_game_button = MenuButton('New\ngame', new_game_menu) menu.left.add(new_game_button) load_game_button = MenuButton('Load\ngame', save.load_dialog) menu.left.add(load_game_button) if features.get('gold.enable'): gold_button = MenuButton(u'civsync\n Gold', gold.menu) gold_button.fg = (255, 215, 0) gold_button.bg = (255, 215, 0, 100) menu.left.add(gold_button) if features.get('app.multiplayer'): menu.left.add(MenuButton('Connect', save.connect_dialog)) menu.right.add(MenuButton('', options.show_options, image=ui.load_image('data/user/options.png'))) menu.right.add(MenuButton('Exit', ui.back)) menu.right.add(ui.Spacing(0, 0)) ui.replace(menu)
def load_background(self): img = ui.load_image('data/user/intro.jpg') img_size = img.get_size() surf_size = ui._fill_image.get_size() new_height = float(surf_size[0]) / img_size[0] * img_size[1] if new_height < surf_size[1]: new_height = surf_size[1] self.background_margin_top = (new_height - surf_size[1]) / -2.5 self.background = pygame.transform.smoothscale(img, (surf_size[0], int(new_height)))
def load_background(self): img = ui.load_image('userdata/intro.jpg') img_size = img.get_size() surf_size = graphics.get_window().get_size() new_height = float(surf_size[0]) / img_size[0] * img_size[1] if new_height < surf_size[1]: new_height = surf_size[1] self.background_margin_top = (new_height - surf_size[1]) / -2.5 self.background = img self.background_size = surf_size[0], int(new_height)
def load_background(self): img = ui.load_image('data/user/intro.jpg') img_size = img.get_size() surf_size = graphics.get_window().get_size() new_height = float(surf_size[0]) / img_size[0] * img_size[1] if new_height < surf_size[1]: new_height = surf_size[1] self.background_margin_top = (new_height - surf_size[1]) / -2.5 self.background = img self.background_size = surf_size[0], int(new_height)
def load_background(self): img = ui.load_image('data/user/intro.jpg') img_size = img.get_size() surf_size = ui._fill_image.get_size() new_height = float(surf_size[0]) / img_size[0] * img_size[1] if new_height < surf_size[1]: new_height = surf_size[1] self.background_margin_top = (new_height - surf_size[1]) / -2.5 self.background = pygame.transform.smoothscale( img, (surf_size[0], int(new_height)))
def main_menu(): global main_menu_item main_menu_item = menu = PrettyMenu() menu.add(ui.Label('version %s' % features.get('app.version'), color=(255, 0, 0, 150), font=ui.consolefont), (0, 0)) new_game_button = MenuButton('New\ngame', new_game_menu) menu.left.add(new_game_button) load_game_button = MenuButton('Load\ngame', save.load_dialog) menu.left.add(load_game_button) if features.get('app.multiplayer'): menu.left.add(MenuButton('Connect', save.connect_dialog)) menu.right.add(MenuButton('', options.show_options, image=ui.load_image('data/user/options.png'))) menu.right.add(MenuButton('Exit', ui.back)) menu.right.add(ui.Spacing(0, 0)) ui.replace(menu)
def __init__(self, event_handlers): """ Creates a new Tkinter instance :param event_handlers: Received by the controller. This contains hooks back to the controller for actions """ self.master = tkinter.Tk() # self.master.configure(bg='white') style = ThemedStyle(self.master) style.theme_use('arc') try: self.master.iconphoto(True, ui.load_image("ui/icons/EmpDat.gif")) except tkinter.TclError: pass self.event_handlers = event_handlers
def __init__(self, event_handlers): """Have a username, password, and submit button""" super().__init__(event_handlers) self.master.title("EmpDat Login") self.master.resizable(False, False) main = Frame(self.master) icon_image = ui.load_image("ui/icons/EmpDat.gif") icon = Label(main, image=icon_image) icon.image = icon_image icon.pack(padx=10, pady=10) self.title = Label(main, text="EmpDat") self.title.pack(pady=10) self.username = Label(main, text="Employee ID") self.entry = Entry(main, width=50) self.username.pack() self.entry.pack(padx=10) self.password = Label(main, text="Password") self.password_entry = Entry(main, width=50, show="•") self.password.pack() self.password_entry.pack(padx=10) self.submit_button = Button( main, text="Submit", command=lambda: event_handlers['submit'] (self.entry.get(), self.password_entry.get()), ) self.submit_button.pack(pady=10) main.pack() self.master.bind( '<Return>', lambda x: event_handlers['submit'] (self.entry.get(), self.password_entry.get()))
def __init__(self, *args, **kwargs): ui.Button.__init__(self, *args, **kwargs) self._image = ui.load_image('data/dropbox_logo.png')
def init_background(self): # the background of the igloo is indeed a part of the menu background image common.info("Init igloo background - start") (surface, dim) = ui.load_image(constants.main_menu_back) (surface_x_pc, surface_y_pc) = constants.igloo_pos surface_x = int((surface_x_pc * surface.get_width()) / 100) surface_y = int((surface_y_pc * surface.get_height()) / 100) (surface_width_pc, surface_height_pc) = constants.igloo_size surface_width = int((surface_width_pc * surface.get_width()) / 100) surface_height = int((surface_height_pc * surface.get_height()) / 100) self.surface_to_zoom_rect = Rect(surface_x, surface_y, surface_width, surface_height) surface_to_zoom = surface.subsurface(self.surface_to_zoom_rect) self.background = pygame.transform.scale( surface_to_zoom, (self.screen.get_width(), self.screen.get_height())) # now let's go back to screen dimensions : surface_x = int(self.x_pc2px(surface_x_pc)) surface_y = int(self.y_pc2px(surface_y_pc)) surface_width = int(self.x_pc2px(surface_width_pc)) surface_height = int(self.y_pc2px(surface_height_pc)) self.surface_to_zoom_rect = Rect(surface_x, surface_y, surface_width, surface_height) # adding the igloo self.igloo = ui.Image(self, (0, 0), (100, 100), constants.igloo_file, 255, 100, "TOPLEFT") self.append_back(self.igloo) # not clean, but same trick as used in ui.Page.draw_back() save_screen = self.screen self.screen = self.background self.igloo.draw() self.screen = save_screen (foo, initial_width, initial_height) = ui.get_image_info(constants.igloo_file) coord_convert_igloo = ui.Coordinates_converter( self, Rect((0, 0), (initial_width, initial_height)), self.igloo.rect) # not very clean: as the limit is the height # we assume width could be three times as big (for instance !) self.tux_size = coord_convert_igloo.get_coords_px2pc( (3 * constants.tux_height, constants.tux_height)) self.tux_initial_pos = coord_convert_igloo.get_coords_px2pc( constants.tux_initial_pos) (self.flag_mast_pos_x, self.flag_mast_pos_y) = coord_convert_igloo.get_coords_px2pc( (constants.flag_mast_pos_x_px, 0)) common.info("Init igloo background - before reducing") self.igloo_reduced_surface = pygame.transform.scale( self.background, self.surface_to_zoom_rect.size) common.info("Init igloo background - end")
def update(self) : ui.Page.update(self) if (cmp(self.transformation.text, "") == 0) : text = self.game.get_title(self.language) else : text = self.transformation.text # load the original image common.info("Loading original image "+ self.transformation.original_image_filename) self.original_image = ui.Image(self, self.game.image_pos, self.game.image_size, self.transformation.original_image_filename) self.unveil_width = ((self.original_image.rect.width) / self.transformation.pieces_amount_x) self.unveil_height = ((self.original_image.rect.height) / self.transformation.pieces_amount_y) self.rounded_width = int(round(self.unveil_width * self.transformation.pieces_amount_x)) self.rounded_height = int(round(self.unveil_height * self.transformation.pieces_amount_y)) self.original_image.cliprect_abs=((self.original_image.x, self.original_image.y), (self.rounded_width, self.rounded_height)) # in case the original_image has transparent alpha pixels original_image_surface_copy = copy.copy(self.original_image.surface) self.original_image.surface.blit(self.screen.subsurface(self.original_image.rect), (0,0) ) self.original_image.surface.blit(original_image_surface_copy, (0,0)) # add the "transformed" image common.info("Loading transformed image "+ self.transformation.transformed_image_filename) (resized_image, foo) = ui.load_image(self.transformation.transformed_image_filename, (self.original_image.rect.width, self.original_image.rect.height), "FILL") self.image = ui.Image_Absolute(self, (self.original_image.rect.left, self.original_image.rect.top), (self.original_image.rect.width, self.original_image.rect.height), resized_image) self.append(self.image) self.image.cliprect_abs=((self.image.rect.left, self.image.rect.top), (self.rounded_width, self.rounded_height)) # the "alpha" surfaces are transparent original images to make a smoother # transition between transformed and original image self.alpha_surfaces = [] alpha_step = 255 / (self.transformation.amount_alpha_surfaces + 2) alpha_value = alpha_step self.transformed_surface = copy.copy(self.image.surface) for i in range(self.transformation.amount_alpha_surfaces) : alpha_surface = copy.copy(self.original_image.surface) alpha_surface.set_alpha(alpha_value) alpha_value = alpha_value + alpha_step self.alpha_surfaces.append(alpha_surface) self.transformation.init_table()
def update(self) : ui.Page.update(self) (image_type, width, height) = ui.get_image_info(self.puzzle_file) self.game_area_width = self.screen.get_width() self.game_area_height = (self.screen.get_height()*self.height_percent_puzzle) // 100 self.start_posy_puzzle = (self.start_posy_puzzle_percent * self.screen.get_height()) // 100 max_width = self.game_area_width max_height = self.game_area_height if ((width < max_width) and (height < max_height)) : ratio = (height*1.0) / width width = max_width height = ratio * width amount_pieces = 0 while (amount_pieces < self.pieces_amount_x * self.pieces_amount_y) : max_width = max_width * 0.97 max_height = max_height * 0.98 if (width > max_width) : # we must keep proportions so we have to change the height... new_height = (height * max_width) // width new_width = max_width elif (height > max_height) : # we must keep proportions so we have to change the width... new_width = (width * max_height) // height new_height = max_height else : new_width = width new_height = height # puzzle looks like this : # # OOO PPPPP OOO # OOO PPPPP OOO # OOO PPPPP OOO # OOOOOOOOOOOOO # OOOOOOOOOOOOO # # O = a piece # P = the puzzle itself piece_space_x = (new_width * self.ratio_spacing_pieces_x) // self.pieces_amount_x piece_space_y = (new_height * self.ratio_spacing_pieces_y) // self.pieces_amount_y usable_x_top = (self.game_area_width - new_width)//2 amount_x_pieces_top = usable_x_top // piece_space_x #print "amount_x_pieces_top " + str(amount_x_pieces_top) usable_y_top = new_height amount_y_pieces_top = usable_y_top // piece_space_y #print "amount_y_pieces_top " + str(amount_y_pieces_top) usable_x_bottom = self.game_area_width amount_x_pieces_bottom = usable_x_bottom // piece_space_x #print "amount_x_pieces_bottom " + str(amount_x_pieces_bottom) usable_y_bottom = self.game_area_height - new_height amount_y_pieces_bottom = usable_y_bottom // piece_space_y #print "amount_y_pieces_bottom " + str(amount_y_pieces_bottom) amount_pieces = (2 * (amount_x_pieces_top * amount_y_pieces_top)) + (amount_x_pieces_bottom * amount_y_pieces_bottom) #print "amount_pieces " + str(amount_pieces) (resized_bitmap, foo) = ui.load_image(self.puzzle_file, (new_width, new_height)) new_width = resized_bitmap.get_width() new_height = resized_bitmap.get_height() if (amount_y_pieces_top == 0) : amount_x_pieces_top = 0 if (amount_x_pieces_top == 0) : amount_y_pieces_top = 0 self.puzzle_image = ui.Image_Absolute(self, ((self.screen.get_width()-new_width) // 2, self.start_posy_puzzle), (new_width, new_height), resized_bitmap) piece_size_x = new_width // self.pieces_amount_x piece_size_y = new_height // self.pieces_amount_y rel_x = -1 rel_y = 1 delta_x = (piece_space_x - piece_size_x) // 2 delta_y = (piece_space_y - piece_size_y) // 2 self.puzzle_pieces = [] self.tuxes = [] self.empty_locations = [] for x in range(self.pieces_amount_x) : x_pos = x * piece_size_x for y in range(self.pieces_amount_y) : y_pos = y * piece_size_y size_x = piece_size_x size_y = piece_size_y if ((x == self.pieces_amount_x - 1) and (x_pos + piece_size_x > self.puzzle_image.surface.get_width())) : size_x = self.puzzle_image.surface.get_width() - x_pos if ((y == self.pieces_amount_y - 1) and (y_pos + piece_size_y > self.puzzle_image.surface.get_height())) : size_y = self.puzzle_image.surface.get_height() - y_pos if (rel_y <= amount_y_pieces_top) : # we are in the top part, on the left and right of the finished puzzle if (rel_x < 0) : # on the left of the finished puzzle x_piece_pos = self.puzzle_image.rect.centerx + rel_x * piece_space_x - self.puzzle_image.surface.get_width() // 2 else : # on the right of the finished puzzle x_piece_pos = self.puzzle_image.rect.centerx + (rel_x - 1) * piece_space_x + self.puzzle_image.surface.get_width() // 2 y_piece_pos = self.puzzle_image.rect.bottom - (rel_y * piece_space_y) else : # we are below the finished puzzle if (rel_x < 0) : if (amount_x_pieces_bottom % 2 == 0) : x_piece_pos = self.puzzle_image.rect.centerx + (rel_x * piece_space_x) else : x_piece_pos = self.puzzle_image.rect.centerx + ((rel_x+0.5) * piece_space_x) else : if (amount_x_pieces_bottom % 2 == 0) : x_piece_pos = self.puzzle_image.rect.centerx + ((rel_x-1) * piece_space_x) else : x_piece_pos = self.puzzle_image.rect.centerx + ((rel_x-0.5) * piece_space_x) y_piece_pos = self.puzzle_image.rect.bottom + ((rel_y - 1 - amount_y_pieces_top) * piece_space_y) if (rel_x < 0) : rel_x = -rel_x if ((amount_x_pieces_bottom % 2 == 1) and (rel_x > amount_x_pieces_bottom // 2) and (rel_y > amount_y_pieces_top)) : rel_x = -1 rel_y = rel_y + 1 else : rel_x = - (rel_x + 1) if (((rel_y <= amount_y_pieces_top) and (rel_x < -amount_x_pieces_top)) or ((amount_x_pieces_bottom % 2 == 0) and (rel_x < -(amount_x_pieces_bottom // 2)) and (rel_y > amount_y_pieces_top))) : rel_y = rel_y + 1 rel_x = -1 empty_location = ui.Empty_Box_Absolute(self, (x_pos + self.puzzle_image.rect.left, y_pos + self.puzzle_image.rect.top), (size_x, size_y), constants.line_color, constants.line_alpha) self.append_back(empty_location) self.empty_locations.append(empty_location) ((tux_x_percent, tux_y_percent), (tux_width_percent, tux_height_percent)) = ( \ (self.x_px2pc(x_pos + self.puzzle_image.rect.left), self.y_px2pc(y_pos + self.puzzle_image.rect.top)), \ (self.x_px2pc(size_x), self.y_px2pc(size_y))) tux = ui.Image(self, (tux_x_percent, tux_y_percent), (tux_width_percent, tux_height_percent), self.game.goal_image_file, self.alpha_tux, self.tux_size_ratio_percent) self.append_back(tux) self.tuxes.append(tux) piece_image = ui.Image_Absolute(self, (x_piece_pos + delta_x, y_piece_pos + delta_y), (size_x, size_y), resized_bitmap.subsurface(Rect((x_pos, y_pos), (size_x, size_y)))) piece_image.set_associated_object(empty_location) self.append(piece_image) self.puzzle_pieces.append(piece_image) common.randomize_rects(self.puzzle_pieces) common.center_vert_absolute(self.puzzle_pieces + self.tuxes + self.empty_locations, self.start_posy_puzzle, self.game_area_height) if (cmp(self.puzzle.text, "") == 0) : text = self.puzzle.game.get_title(self.language) else : text = self.puzzle.text self.draw_back()
def init_background(self) : # the background of the igloo is indeed a part of the menu background image common.info("Init igloo background - start") (surface, dim) = ui.load_image(constants.main_menu_back) (surface_x_pc, surface_y_pc) = constants.igloo_pos surface_x = int((surface_x_pc * surface.get_width()) / 100) surface_y = int((surface_y_pc * surface.get_height()) / 100) (surface_width_pc, surface_height_pc) = constants.igloo_size surface_width = int((surface_width_pc * surface.get_width()) / 100) surface_height = int((surface_height_pc * surface.get_height()) / 100) self.surface_to_zoom_rect = Rect(surface_x, surface_y, surface_width, surface_height) surface_to_zoom = surface.subsurface(self.surface_to_zoom_rect) self.background = pygame.transform.scale(surface_to_zoom, (self.screen.get_width(), self.screen.get_height())) # now let's go back to screen dimensions : surface_x = int(self.x_pc2px(surface_x_pc)) surface_y = int(self.y_pc2px(surface_y_pc)) surface_width = int(self.x_pc2px(surface_width_pc)) surface_height = int(self.y_pc2px(surface_height_pc)) self.surface_to_zoom_rect = Rect(surface_x, surface_y, surface_width, surface_height) # adding the igloo self.igloo = ui.Image(self, (0,0), (100,100), constants.igloo_file, 255, 100, "TOPLEFT") self.append_back(self.igloo) # not clean, but same trick as used in ui.Page.draw_back() save_screen = self.screen self.screen = self.background self.igloo.draw() self.screen = save_screen (foo, initial_width, initial_height) = ui.get_image_info(constants.igloo_file) coord_convert_igloo = ui.Coordinates_converter(self, Rect((0,0), (initial_width, initial_height)), self.igloo.rect) # not very clean: as the limit is the height # we assume width could be three times as big (for instance !) self.tux_size = coord_convert_igloo.get_coords_px2pc((3 * constants.tux_height, constants.tux_height)) self.tux_initial_pos = coord_convert_igloo.get_coords_px2pc(constants.tux_initial_pos) (self.flag_mast_pos_x, self.flag_mast_pos_y) = coord_convert_igloo.get_coords_px2pc((constants.flag_mast_pos_x_px, 0)) common.info("Init igloo background - before reducing") self.igloo_reduced_surface = pygame.transform.scale(self.background, self.surface_to_zoom_rect.size) common.info("Init igloo background - end")