btn1 = Button(position = (30, 30), title = "Hello", action = say_hello, style = 'default') btn2 = Button(x = 30, y = btn1.bottom + 30, width = 200, title = "Goodbye", just = 'centre', action = say_goodbye, enabled = 0) btn2.font = Font("Times", 1.2 * system_font.size, []) btn3 = Button(x = 30, y = btn2.bottom + 30, width = 200, font = Font("Times", 1.2 * system_font.size, ['italic']), action = simulate_hello, title = "Wrong", style = 'cancel') btn3.color = red btn3.just = 'right' btn3.title = "Gidday Mate" class TWindow(Window): def key_down(self, e): say(e) Window.key_down(self, e) win = TWindow(width = 260, height = btn3.bottom + 30, title = "Btns", resizable = 0, zoomable = 0) win.add(btn1) win.add(btn2) win.add(btn3) win.show()
"""btn2 = Button(x = 30, y = btn1.bottom + 30, width = 200, title = "Goodbye", just = 'centre', action = say_goodbye, enabled = 0) btn2.font = Font("Times", 1.2 * system_font.size, [])""" btn3 = Button(x=30, y=btn1.bottom + 30, width=200, font=Font("Times", 1.2 * system_font.size, ['italic']), action=stop_recording, title="Wrong", style='cancel') btn3.color = red btn3.just = 'right' btn3.title = "Gidday Mate" win.add(btn1) """win.add(btn2)""" """win.add(btn3)""" win.add(btn5) win.show() instructions = """ There should be 3 buttons arranged vertically: 1. Title "Hello", natural width, style 'default' 2. Title "Goodbye" in a serif font, width 200, initially disabled 3. Title "Gidday Mate" in red italic, width 200, style 'cancel', right aligned Pressing button 1 should print "Hello, world!" and enable button 2. Pressing button 2 should print "Goodbye, world!" and disable button 2. Pressing button 3 should simulate pressing button 1.
def open_formation_bio_window(window_x, window_y, formation, win_previous, file_name, current_list): # ========== Window ========== win_formation_bio = Window() win_formation_bio.title = formation_bio_win_title win_formation_bio.auto_position = False win_formation_bio.position = (window_x, window_y) win_formation_bio.size = (win_width, win_height) win_formation_bio.resizable = 0 win_formation_bio.name = formation_bio_title + " Window" win_formation_bio.show() # ========== Load Formation Spacing ========== # Get attribute lists with open(config_filename, 'r') as f: formation_spacing = json.load(f)['formation_coordinates'][formation['name']] f.close() labels_list = [] # ========== Field Ratio ========== y_to_x_ratio = 0.8 # Line specification line_color = white line_size = 2 # Field field_color = dark_green field_length = 600 field_width = field_length*y_to_x_ratio # Field positioning on screen field_x_offset = (win_formation_bio.width - field_width - button_width - 100) / 2 field_y_offset = top_border + title_height + title_border # Center circle center_spot_x = field_x_offset + field_width/2 center_spot_y = field_y_offset + field_length/2 circle_radius = int(field_length/10) # Goal box penalty_spot_height = int(field_length*12/100) eighteen_box_height = int(field_length*18/100) eighteen_box_width = int(field_length*44/100) six_box_height = int(field_length*6/100) six_box_width = int(field_length*20/100) # Corner semi circles corner_semi_circle_radius = int(field_length*2/100) # ========== Player Spacing Values ========== x_space = int(field_width/20) y_space = int(field_length/24) player_box_width = 80 player_box_height = 50 player_box_color = lighter link_size = 5 link_color = red # ========== Window Image View ========== image_pos = (field_x_offset, field_y_offset) src_rect = (0, 0, field_width, field_length) dst_rect = Geometry.offset_rect(src_rect, image_pos) class StartWindowImageView(View): def draw(self, c, r): c.backcolor = view_backcolor c.erase_rect(r) # Field and sidelines c.forecolor = field_color c.fill_rect((dst_rect[0]-5, dst_rect[1]-5, dst_rect[2]+5, dst_rect[3]+5)) c.forecolor = line_color c.fill_rect((dst_rect[0], dst_rect[1], dst_rect[2], dst_rect[3])) c.forecolor = field_color c.fill_rect((dst_rect[0]+line_size, dst_rect[1]+line_size, dst_rect[2]-line_size, dst_rect[3]-line_size)) # Center circle, center spot, and half-way line c.forecolor = line_color c.fill_oval((center_spot_x-circle_radius, center_spot_y-circle_radius, center_spot_x+circle_radius, center_spot_y+circle_radius)) c.forecolor = field_color c.fill_oval((center_spot_x-circle_radius+line_size, center_spot_y-circle_radius+line_size, center_spot_x+circle_radius-line_size, center_spot_y+circle_radius-line_size)) c.forecolor = line_color c.fill_rect((dst_rect[0], center_spot_y-line_size/2, dst_rect[2], center_spot_y+line_size/2)) c.fill_oval((center_spot_x-line_size*2, center_spot_y-line_size*2, center_spot_x+line_size*2, center_spot_y+line_size*2)) # Goal box semi circle c.forecolor = line_color c.fill_oval((center_spot_x-circle_radius, dst_rect[1]+penalty_spot_height-circle_radius, center_spot_x+circle_radius, dst_rect[1]+penalty_spot_height+circle_radius)) c.fill_oval((center_spot_x-circle_radius, dst_rect[3]-penalty_spot_height-circle_radius, center_spot_x+circle_radius, dst_rect[3]-penalty_spot_height+circle_radius)) c.forecolor = field_color c.fill_oval((center_spot_x-circle_radius+line_size, dst_rect[1]+penalty_spot_height-circle_radius+line_size, center_spot_x+circle_radius-line_size, dst_rect[1]+penalty_spot_height+circle_radius-line_size)) c.fill_oval((center_spot_x-circle_radius+line_size, dst_rect[3]-penalty_spot_height-circle_radius+line_size, center_spot_x+circle_radius-line_size, dst_rect[3]-penalty_spot_height+circle_radius-line_size)) # Eighteen yard box c.forecolor = line_color c.fill_rect((center_spot_x-eighteen_box_width/2, dst_rect[1], center_spot_x+eighteen_box_width/2, dst_rect[1]+eighteen_box_height)) c.fill_rect((center_spot_x-eighteen_box_width/2, dst_rect[3]-eighteen_box_height, center_spot_x+eighteen_box_width/2, dst_rect[3])) c.forecolor = field_color c.fill_rect((center_spot_x-eighteen_box_width/2+line_size, dst_rect[1]+line_size, center_spot_x+eighteen_box_width/2-line_size, dst_rect[1]+eighteen_box_height-line_size)) c.fill_rect((center_spot_x-eighteen_box_width/2+line_size, dst_rect[3]-eighteen_box_height+line_size, center_spot_x+eighteen_box_width/2-line_size, dst_rect[3]-line_size)) # Penalty spot c.forecolor = line_color c.fill_oval((center_spot_x-line_size*2, dst_rect[1]+six_box_height*2-line_size*2, center_spot_x+line_size*2, dst_rect[1]+six_box_height*2+line_size*2)) c.fill_oval((center_spot_x-line_size*2, dst_rect[3]-six_box_height*2-line_size*2, center_spot_x+line_size*2, dst_rect[3]-six_box_height*2+line_size*2)) # Six yard box c.forecolor = line_color c.fill_rect((center_spot_x-six_box_width/2, dst_rect[1], center_spot_x+six_box_width/2, dst_rect[1]+six_box_height)) c.fill_rect((center_spot_x-six_box_width/2, dst_rect[3]-six_box_height, center_spot_x+six_box_width/2, dst_rect[3])) c.forecolor = field_color c.fill_rect((center_spot_x-six_box_width/2+line_size, dst_rect[1]+line_size, center_spot_x+six_box_width/2-line_size, dst_rect[1]+six_box_height-line_size)) c.fill_rect((center_spot_x-six_box_width/2+line_size, dst_rect[3]-six_box_height+line_size, center_spot_x+six_box_width/2-line_size, dst_rect[3]-line_size)) # Corner circles c.forecolor = line_color c.stroke_arc((dst_rect[0]+1, dst_rect[1]), corner_semi_circle_radius, 0, 90) c.frame_arc((dst_rect[2], dst_rect[1]), corner_semi_circle_radius, 90, 180) c.stroke_arc((dst_rect[0]+1, dst_rect[3]-line_size), corner_semi_circle_radius, 270, 0) c.frame_arc((dst_rect[2], dst_rect[3]-line_size), corner_semi_circle_radius, 180, 270) # Links for sym, pos in formation['positions'].iteritems(): c.forecolor = link_color position_coordinates = formation_spacing[sym] for link in pos['links']: link_coordinates = formation_spacing[link] # Determine line direction to decide which points to use change_y = (link_coordinates[1]-position_coordinates[1])*y_space change_x = (link_coordinates[0]-position_coordinates[0])*x_space+0.0001 ratio = change_y/change_x # Horizontal width line if abs(ratio) >= 1: c.fill_poly([(int(dst_rect[0]+position_coordinates[0]*x_space)-link_size/2, int(dst_rect[1]+position_coordinates[1]*y_space)), (int(dst_rect[0]+position_coordinates[0]*x_space)+link_size/2, int(dst_rect[1]+position_coordinates[1]*y_space)), (int(dst_rect[0]+link_coordinates[0]*x_space+link_size/2), int(dst_rect[1]+link_coordinates[1]*y_space)), (int(dst_rect[0]+link_coordinates[0]*x_space-link_size/2), int(dst_rect[1]+link_coordinates[1]*y_space))]) # Vertical width line else: c.fill_poly([(int(dst_rect[0]+position_coordinates[0]*x_space), int(dst_rect[1]+position_coordinates[1]*y_space)-link_size/2), (int(dst_rect[0]+position_coordinates[0]*x_space), int(dst_rect[1]+position_coordinates[1]*y_space)+link_size/2), (int(dst_rect[0]+link_coordinates[0]*x_space), int(dst_rect[1]+link_coordinates[1]*y_space)+link_size/2), (int(dst_rect[0]+link_coordinates[0]*x_space), int(dst_rect[1]+link_coordinates[1]*y_space)-link_size/2)]) # Player Markers for sym in formation['positions'].iterkeys(): c.forecolor = player_box_color position_coordinates = formation_spacing[sym] c.fill_oval((dst_rect[0]+position_coordinates[0]*x_space-player_box_width/2, dst_rect[1]+position_coordinates[1]*y_space-player_box_height/2, dst_rect[0]+position_coordinates[0]*x_space+player_box_width/2, dst_rect[1]+position_coordinates[1]*y_space+player_box_height/2)) view = StartWindowImageView(size=win_formation_bio.size) # ========== Position Labels ========== label_width = player_box_width label_height = 35 pos_label_color = blue for symbol, position in formation['positions'].iteritems(): pos_coordinates = formation_spacing[symbol] label_x = int(dst_rect[0]+pos_coordinates[0]*x_space-label_width/2) label_y = int(dst_rect[1]+pos_coordinates[1]*y_space-label_height/2) pos_label = Label(text=position['symbol'],font=title_font_2, width=label_width, height=label_height, x=label_x, y=label_y, color=pos_label_color, just='center') labels_list.append(pos_label) # ========== Button Declarations ========== add_formation_btn = Button() back_btn = Button("Back") # ========== Button Functions ========== def add_formation_btn_func(): # Check if formation is already on selected formations list # Remove formation from list if formation in current_list.db: # Remove current_list.db.remove(formation) # Save current_list.sort(['name']) current_list.save(file_name, 'list', True) # Switch button title add_formation_btn.title = "Add Formation to List" # Add formation to the list else: # Add current_list.db.append(formation) # Save current_list.sort(['name']) current_list.save(file_name, 'list', True) # Switch button title add_formation_btn.title = "Remove Formation from List" win_formation_bio.become_target() def back_btn_func(): win_formation_bio.hide() win_previous.show() # ========== Buttons ========== button_x_offset = 50 add_formation_btn.x = win_formation_bio.width - button_width - button_x_offset add_formation_btn.y = top_border add_formation_btn.height = small_button_height add_formation_btn.width = button_width add_formation_btn.font = smaller_button_font add_formation_btn.action = add_formation_btn_func add_formation_btn.style = 'default' add_formation_btn.color = small_button_color # Check if formation is already on selected formations list if formation in current_list.db: add_formation_btn.title = "Remove Formation from List" else: add_formation_btn.title = "Add Formation to List" back_btn.x = add_formation_btn.left back_btn.y = add_formation_btn.bottom back_btn.height = small_button_height back_btn.width = button_width back_btn.font = small_button_font back_btn.action = back_btn_func back_btn.style = 'default' back_btn.color = small_button_color # ========== Name ========== formation_name_label = Label(text=formation['name'], font=title_font, width=title_width, height=title_height, x=(win_width - title_width)/2, y=top_border, color=title_color, just='center') # Shift title over the field formation_name_label.x = (win_formation_bio.width - title_width - button_width - 100) / 2 labels_list.append(formation_name_label) # ========== Formation Info Title Label ========== info_title = Label(text="Formation Info", font=title_font_2, width=title_width, height=title_height, x=add_formation_btn.right - button_width/2 - title_width/2, y=back_btn.bottom + top_border*3, color=title_color, just='center') labels_list.append(info_title) # ========== Formation Info Labels ========== info_width = 110 info_label_text = "Style:\n# Links:\n# Attackers:\n# Midfielders:\n# Defenders:" info_title_label = Label(text=info_label_text, font=std_tf_font_bold, width=info_width, height=std_tf_height*5, x=add_formation_btn.left - button_x_offset, y=info_title.bottom + title_border, color=title_color, just='right') labels_list.append(info_title_label) # ========== Formation Info ========== info_text = (formation['style'] + "\n" + str(formation['num_links']) + "\n" + str(formation['num_attackers']) + "\n" + str(formation['num_midfielders']) + "\n" + str(formation['num_defenders'])) info_label = Label(text=info_text, font=std_tf_font_bold, width=info_width, height=std_tf_height*5, x=info_title_label.right + 10, y=info_title_label.top, color=title_color, just='left') labels_list.append(info_label) # ========== Description Label ========== description_title_label = Label(text="Description:", font=std_tf_font_bold, width=small_button_width, height=std_tf_height, x=add_formation_btn.left, y=info_title_label.bottom + top_border, color=title_color, just='center') labels_list.append(description_title_label) # ========== Description ========== description = formation['description'] description_text = '' max_chars = 25 counter = 0 for word in description.split(): counter += len(word) + 1 description_text += ' ' + word if counter >= max_chars: description_text += '\n' counter = 0 description_label = Label(text=description_text, font=std_tf_font, width=small_button_width+100, height=std_tf_height*13, x=info_title_label.left, y=description_title_label.bottom + title_border, color=title_color, just='left') labels_list.append(description_label) # ========== Add buttons to window ========== view.add(add_formation_btn) view.add(back_btn) for label in labels_list: view.add(label) win_formation_bio.add(view) view.become_target() win_formation_bio.show()
def open_player_bio_window(window_x, window_y, player, win_previous, db_dict=None, file_name=None, current_list=None, roster=None, pos_symbol=None, input_formation=None, pick_formations_page=None): if current_list is None: current_list = PlayerDB.PlayerDB() # ========== Window ========== win_player_bio = Window() win_player_bio.title = player_bio_win_title win_player_bio.auto_position = False win_player_bio.position = (window_x, window_y) win_player_bio.size = (win_width, win_height) win_player_bio.resizable = 0 win_player_bio.name = player_bio_title + " Window" win_player_bio.show() # ========== Window Image View ========== class PlayerBioWindowImageView(View): def draw(self, c, r): c.backcolor = view_backcolor c.erase_rect(r) # Background image image_pos = ((player_name_label.left - player_background.width)/2, 5) src_rect = player_background.bounds dst_rect = Geometry.offset_rect(src_rect, image_pos) player_background.draw(c, src_rect, dst_rect) # Lines between summary stats c.forecolor = stat_line_color c.fill_rect((dst_rect[0]+22, dst_rect[1]+stat_line_y, dst_rect[2]-22, dst_rect[1]+stat_line_y+1)) c.fill_rect((dst_rect[0]+22, dst_rect[1]+stat_line_y+stat_line_spacing, dst_rect[2]-22, dst_rect[1]+stat_line_y+stat_line_spacing+1)) # Headshot image_pos = (image_pos[0]+player_headshot_pos[0], player_headshot_pos[1]) src_rect = player_headshot.bounds headshot_dst_rect = Geometry.offset_rect(src_rect, image_pos) player_headshot.draw(c, src_rect, headshot_dst_rect) # Club if 'normal' in player['club']['imageUrls']: image_url = player['club']['imageUrls']['normal']['large'] # FIFA 15 compatibility elif 'dark' in player['club']['imageUrls']: image_url = player['club']['imageUrls']['dark']['large'] ratio = 0.75 image_file_name = 'club_' + str(player['club']['id']) + '_' + str(ratio) image_file_name = save_small_image(image_url, image_file_name, ratio) club_image = Image(file=image_file_name) club_image_pos = club_pos club_rect = club_image.bounds club_dst_rect = Geometry.offset_rect(club_rect, club_image_pos) club_image.draw(c, club_rect, club_dst_rect) # Nation if 'imageUrls' in player['nation']: image_url = player['nation']['imageUrls']['large'] # FIFA 15 compatibility elif 'imageUrl' in player['nation']: image_url = player['nation']['imgUrl'] ratio = 0.75 image_file_name = 'nation_' + str(player['nation']['id']) + '_' + str(ratio) image_file_name = save_small_image(image_url, image_file_name, ratio) nation_image = Image(file=image_file_name) nation_image_pos = (club_image_pos[0], club_image_pos[1]+club_image.size[1]+nation_spacing) nation_rect = nation_image.bounds nation_dst_rect = Geometry.offset_rect(nation_rect, nation_image_pos) nation_image.draw(c, nation_rect, nation_dst_rect) # Coins symbol image_file_name = 'Images/coins.png' coins_image = Image(file=image_file_name) coins_image_pos = coins_pos coins_rect = coins_image.bounds coins_dst_rect = Geometry.offset_rect(coins_rect, coins_image_pos) coins_image.draw(c, coins_rect, coins_dst_rect) view = PlayerBioWindowImageView(size=win_player_bio.size) # ========== Player Headshot ========== image_url = player['headshotImgUrl'] image_file_name = player['id'] + '_full' # FIFA 15 compatibility if "130x130" in image_url: ratio = 120.0/130.0 image_file_name = save_small_image(image_url, image_file_name, ratio) elif "120x120" in image_url: image_file_name = save_image(image_url, image_file_name) player_headshot = Image(file=image_file_name) # ========== Player Background ========== # Assign player background card if player['color'] in ['award_winner', 'bronze', 'confederation_champions_motm', 'easports', 'fut_champions_bronze', 'fut_champions_gold', 'fut_champions_silver', 'gold', 'green', 'halloween', 'legend', 'motm', 'motm_2', 'movember', 'ones_to_watch', 'pink_gold', 'pink', 'purple', 'rare_bronze', 'rare_gold', 'rare_silver', 'red_blue', 'silver', 'sbc_base', 'squad_building_challenge', 'teal', 'tott', 'tots_bronze', 'tots_gold', 'tots_silver', 'totw_bronze', 'totw_gold', 'totw_silver', 'toty']: background_file = 'Images/Cards/' + player['color'] + '.png' else: background_file = 'Images/Cards/idk.png' player_background = Image(file=background_file) # Assign positioning for player card based on type if player['color'] in ['legend']: player_headshot_pos = (43, 15) club_pos = (51, 76) nation_spacing = 2 coins_pos = (155, 222) stat_line_y = 173 stat_line_spacing = 21 name_y = 138 rating_pos = (33, 35) stats_y = 159 card_rating_pos_color = black card_name_color = black card_stat_color = black stat_line_color = barely_darker coins_color = black elif player['color'] in ['green', 'movember', 'pink_gold']: player_headshot_pos = (43, 15) club_pos = (51, 76) nation_spacing = 1 coins_pos = (155, 222) stat_line_y = 173 stat_line_spacing = 21 name_y = 138 rating_pos = (33, 35) stats_y = 159 card_rating_pos_color = black card_name_color = black card_stat_color = white stat_line_color = barely_lighter coins_color = black elif player['color'] in ['tott']: player_headshot_pos = (43, 15) club_pos = (51, 76) nation_spacing = 1 coins_pos = (155, 222) stat_line_y = 173 stat_line_spacing = 21 name_y = 138 rating_pos = (33, 35) stats_y = 159 card_rating_pos_color = black card_name_color = white card_stat_color = black stat_line_color = barely_darker coins_color = black elif player['color'] in ['confederation_champions_motm', 'motm', 'motm_2', 'pink', 'purple', 'teal']: player_headshot_pos = (43, 15) club_pos = (51, 76) nation_spacing = 1 coins_pos = (155, 222) stat_line_y = 173 stat_line_spacing = 21 name_y = 138 rating_pos = (33, 35) stats_y = 159 card_rating_pos_color = black card_name_color = white card_stat_color = white stat_line_color = barely_lighter coins_color = white elif player['color'] in ['halloween', 'easports', 'ones_to_watch', 'sbc_base', 'toty']: player_headshot_pos = (43, 15) club_pos = (51, 76) nation_spacing = 1 coins_pos = (155, 222) stat_line_y = 173 stat_line_spacing = 21 name_y = 138 rating_pos = (33, 35) stats_y = 159 card_rating_pos_color = white card_name_color = white card_stat_color = white stat_line_color = barely_lighter coins_color = white elif player['color'] in ['award_winner', 'tots_gold', 'tots_silver', 'tots_bronze']: player_headshot_pos = (43, 15) club_pos = (51, 76) nation_spacing = 1 coins_pos = (155, 222) stat_line_y = 173 stat_line_spacing = 21 name_y = 138 rating_pos = (33, 35) stats_y = 159 card_rating_pos_color = white card_name_color = black card_stat_color = white stat_line_color = barely_lighter coins_color = black elif player['color'] in ['totw_gold', 'totw_silver', 'totw_bronze']: player_headshot_pos = (43, 15) club_pos = (51, 76) nation_spacing = 1 coins_pos = (155, 222) stat_line_y = 173 stat_line_spacing = 21 name_y = 138 rating_pos = (33, 35) stats_y = 159 card_rating_pos_color = black card_name_color = white card_stat_color = white stat_line_color = barely_lighter coins_color = white elif player['color'] in ['rare_gold', 'rare_silver', 'rare_bronze']: player_headshot_pos = (43, 15) club_pos = (51, 76) nation_spacing = 1 coins_pos = (155, 222) stat_line_y = 172 stat_line_spacing = 21 name_y = 138 rating_pos = (33, 35) stats_y = 158 card_rating_pos_color = black card_name_color = black card_stat_color = black stat_line_color = barely_darker coins_color = black elif player['color'] in ['gold', 'silver', 'bronze']: player_headshot_pos = (43, 15) club_pos = (51, 76) nation_spacing = 3 coins_pos = (155, 222) stat_line_y = 173 stat_line_spacing = 21 name_y = 138 rating_pos = (33, 35) stats_y = 159 card_rating_pos_color = black card_name_color = black card_stat_color = black stat_line_color = barely_darker coins_color = black else: player_headshot_pos = (43, 15) club_pos = (51, 76) nation_spacing = 1 coins_pos = (155, 222) stat_line_y = 173 stat_line_spacing = 21 name_y = 138 rating_pos = (33, 35) stats_y = 159 card_rating_pos_color = black card_name_color = black card_stat_color = black stat_line_color = barely_darker coins_color = black # ========== Button Declarations ========== add_player_btn = Button() back_btn = Button("Back") update_price_btn = Button("Update") # ========== Button Functions ========== def add_player_btn_func(): # Assign player to roster if that is the current process if roster is not None and pos_symbol is not None and input_formation is not None: roster[pos_symbol] = player win_player_bio.hide() AssignPlayers.open_assign_players_window(win_player_bio.x, win_player_bio.y, db_dict, input_formation, pick_formations_page, roster) # Check if player is already on selected players list # Remove player from list elif player in current_list.db: # Remove current_list.db.remove(player) # Save current_list.sort(['rating']) current_list.save(file_name, 'list', True) # Switch button title add_player_btn.title = "Add Player to List" # Add player to the list else: # Add current_list.db.append(player) # Save current_list.sort(['rating']) current_list.save(file_name, 'list', True) # Switch button title add_player_btn.title = "Remove Player from List" win_player_bio.become_target() def back_btn_func(): win_player_bio.hide() win_previous.show() def update_price_btn_func(): if db_dict is not None: # Get index in player list and player db if player in db_dict['player_list'][1].db: list_index = db_dict['player_list'][1].db.index(player) else: list_index = -1 if player in db_dict['player_db'][1].db: db_index = db_dict['player_db'][1].db.index(player) else: db_index = -1 # Load console type settings = {'console_type': ''} with open(config_filename, 'r') as f: settings["console_type"] = json.load(f)['console_type'] f.close() # Get updated price new_price = Player.Player(player).get_price(settings["console_type"]) # Update price displayed new_price_str = str(new_price) if new_price > 999999: new_price_str = new_price_str[:-6] + ',' + new_price_str[-6:-3] + ',' + new_price_str[-3:] elif new_price > 999: new_price_str = new_price_str[:-3] + ',' + new_price_str[-3:] elif new_price < 1: new_price_str = '?' price_label.text = str(new_price_str) # Assigned updated price if list_index > -1: updated_player = db_dict['player_list'][1].db[list_index] updated_player['price'] = new_price db_dict['player_list'][1].db[list_index] = updated_player if db_index > -1: updated_player = db_dict['player_db'][1].db[db_index] updated_player['price'] = new_price db_dict['player_db'][1].db[db_index] = updated_player player['price'] = new_price # Save if list_index > -1: db_dict['player_list'][1].sort(['rating']) db_dict['player_list'][1].save(db_dict['player_list'][0], 'list', True) if db_index > -1: db_dict['player_db'][1].sort(['rating']) db_dict['player_db'][1].save(db_dict['player_db'][0], 'db', True) win_player_bio.become_target() # ========== Buttons ========== button_x_offset = 85 add_player_btn.x = win_player_bio.width - button_width - button_x_offset add_player_btn.y = top_border add_player_btn.height = small_button_height add_player_btn.width = button_width add_player_btn.font = small_button_font add_player_btn.action = add_player_btn_func add_player_btn.style = 'default' add_player_btn.color = small_button_color # Disable button if no lists selected if file_name is None and roster is None: add_player_btn.enabled = 0 if roster is not None and pos_symbol is not None and input_formation is not None: add_player_btn.title = "Assign Player to Roster" # Get list of player base IDs base_ids = [] for player_value in roster.itervalues(): base_ids.append(player_value['baseId']) # Make sure any version player isn't already on team if player['baseId'] in base_ids: add_player_btn.title = "Player Already on Roster" add_player_btn.enabled = 0 # Check if player is already on selected players list elif player in current_list.db: add_player_btn.title = "Remove Player from List" else: add_player_btn.title = "Add Player to List" back_btn.x = add_player_btn.left back_btn.y = add_player_btn.bottom back_btn.height = small_button_height back_btn.width = button_width back_btn.font = small_button_font back_btn.action = back_btn_func back_btn.style = 'default' back_btn.color = small_button_color update_price_btn.x = add_player_btn.right update_price_btn.y = add_player_btn.top update_price_btn.height = small_button_height*2 update_price_btn.width = button_width/3 update_price_btn.font = small_button_font update_price_btn.action = update_price_btn_func update_price_btn.style = 'default' update_price_btn.color = small_button_color if db_dict is None: update_price_btn.enabled = 0 # ========== Player Info Labels ========== # Get attribute lists with open(config_filename, 'r') as f: attribute_lists = json.load(f)['player_attributes'] f.close() labels_list = [] name_width = 300 rating_big_width = 70 traits_offset_left = 25 traits_label_width = 100 traits_list_label_width = 500 - traits_label_width section_label_width = 115 # ========== Name ========== player_name_label = Label(font=title_font, width=name_width, height=title_height, x=(win_width - name_width)/2, y=top_border, color=title_color, just='center') labels_list.append(player_name_label) player_full_name_label = Label(font=title_tf_font, width=name_width, height=std_tf_height, x=(win_width - name_width)/2, y=player_name_label.bottom - title_border, color=title_color, just='center') labels_list.append(player_full_name_label) # ========== Name on Card ========== name_on_card_label = Label(font=std_tf_font_bold, width=player_background.width, height=std_tf_height, x=(player_name_label.left - player_background.width)/2, y=name_y, color=card_name_color, just='center') labels_list.append(name_on_card_label) # ========== Rating and Position ========== rating_big_label = Label(font=title_font_3, width=rating_big_width, height=title_height, x=rating_pos[0], y=rating_pos[1], color=card_rating_pos_color, just='center') labels_list.append(rating_big_label) position_big_label = Label(font=title_font_6, width=rating_big_width, height=title_height, x=rating_big_label.left, y=rating_big_label.bottom-27, color=card_rating_pos_color, just='center') labels_list.append(position_big_label) # ========== Traits and Specialities ========== traits_label = Label(font=std_tf_font_bold, width=traits_label_width, height=std_tf_height, x=player_full_name_label.left - traits_offset_left, y=player_full_name_label.bottom+title_border*2, color=title_color, just='right') labels_list.append(traits_label) traits_list_label = Label(font=small_tf_font, width=traits_list_label_width, height=std_tf_height, x=traits_label.right + small_button_spacing, y=traits_label.top+3, color=title_color, just='left') labels_list.append(traits_list_label) traits_list_label_2 = Label(font=small_tf_font, width=traits_list_label_width, height=std_tf_height, x=traits_label.right + small_button_spacing, y=traits_list_label.bottom, color=title_color, just='left') labels_list.append(traits_list_label_2) specialities_label = Label(font=std_tf_font_bold, width=traits_label_width, height=std_tf_height, x=traits_label.left, y=traits_list_label_2.bottom, color=title_color, just='right') labels_list.append(specialities_label) specialities_list_label = Label(font=small_tf_font, width=traits_list_label_width, height=std_tf_height, x=specialities_label.right + small_button_spacing, y=specialities_label.top+3, color=title_color, just='left') labels_list.append(specialities_list_label) specialities_list_label_2 = Label(font=small_tf_font, width=traits_list_label_width, height=std_tf_height, x=specialities_label.right + small_button_spacing, y=specialities_list_label.bottom, color=title_color, just='left') labels_list.append(specialities_list_label_2) # ========== Attributes Under Picture Section ========== attr_title_label_width = 35 attr_label_width = 20 attribute_x_offset = 30 label_x = (player_name_label.left - player_background.width)/2 + player_background.width/2 - attribute_x_offset - 10 label_y = stats_y for idx, attr in enumerate(player['attributes']): if idx == 3: label_x += 2*attribute_x_offset + 10 label_y = stats_y stat_label = Label(font=std_tf_font_bold, width=attr_label_width, height=std_tf_height, x=label_x-attr_label_width-2, y=label_y, color=card_stat_color, just='right') stat_label.text = str(attr['value']) labels_list.append(stat_label) stat_title_label = Label(font=std_tf_font, width=attr_title_label_width, height=std_tf_height, x=label_x+1, y=label_y, color=card_stat_color, just='left') stat_title_label.text = format_attr_name(attr['name'][-3:]) labels_list.append(stat_title_label) label_y += std_tf_height + 1 # ========== Price Section ========== price_width = 80 price = str(player['price']) if player['price'] > 999999: price = price[:-6] + ',' + price[-6:-3] + ',' + price[-3:] elif player['price'] > 999: price = price[:-3] + ',' + price[-3:] elif player['price'] < 1: price = '?' coins_pos = (coins_pos[0] - (9 - len(price)) * 3, coins_pos[1]) price_label = Label(text=price,font=std_tf_font_bold, width=price_width, height=std_tf_height, x=coins_pos[0] - price_width - 3, y=coins_pos[1], color=coins_color, just='right') labels_list.append(price_label) # ========== Database Info Section ========== db_info_label = Label(font=std_tf_font_bold, width=section_label_width, height=std_tf_height, x=win_player_bio.width * 5 / 50, y=specialities_list_label_2.bottom + int(7.3*title_border), color=title_color, just='center') db_info_label.text = "Database Info" labels_list.append(db_info_label) db_info_title_label_width = 80 db_info_label_width = 55 attribute_x_offset = 40 label_x = db_info_label.left + section_label_width/2 - attribute_x_offset label_y = db_info_label.bottom for idx, db_info in enumerate(attribute_lists['db']): if idx == 5: attribute_x_offset = 85 db_info_title_label_width = 60 db_info_label_width = 50 label_x = db_info_label.left + section_label_width/2 + attribute_x_offset label_y = db_info_label.bottom if db_info == 'modelName': db_info_label_width = 95 stat_title_label = Label(font=small_tf_font, width=db_info_title_label_width, height=std_tf_height, x=label_x-db_info_title_label_width, y=label_y, color=title_color, just='right') stat_title_label.text = format_attr_name(db_info) + ':' labels_list.append(stat_title_label) stat_label = Label(font=small_tf_font, width=db_info_label_width, height=std_tf_height, x=label_x, y=label_y, color=title_color, just='right') if db_info in ['clubId', 'leagueId', 'nationId']: stat_label.text = str(player[db_info[:-2]]['id']) else: stat_label.text = str(player[db_info]) labels_list.append(stat_label) label_y += std_tf_height # ========== Personal Section ========== personal_label = Label(font=std_tf_font_bold, width=section_label_width, height=std_tf_height, x=win_player_bio.width * 29 / 50, y=specialities_list_label_2.bottom + top_border, color=title_color, just='center') personal_label.text = "Personal" labels_list.append(personal_label) personal_title_stat_width = 100 personal_stat_width = 65 personal_stat_just = 'right' personal_x_offset = personal_stat_width + 60 label_x = personal_label.left + section_label_width/2 - personal_x_offset label_y = personal_label.bottom for idx, personal in enumerate(attribute_lists['personal']): if idx == 7: personal_title_stat_width = 75 personal_stat_width = 250 personal_stat_just = 'left' personal_x_offset = personal_title_stat_width - 55 label_x = personal_label.left + section_label_width/2 + personal_x_offset label_y = personal_label.bottom # Skip these since other labels use them if personal == 'positionFull': continue stat_title_label = Label(font=small_tf_font, width=personal_title_stat_width, height=std_tf_height, x=label_x-personal_title_stat_width, y=label_y, color=title_color, just='right') stat_title_label.text = format_attr_name(personal) + ':' labels_list.append(stat_title_label) color = white # Change color for rating and potential if personal in ['rating', 'potential']: color = attr_color(player[personal]) # Change color for quality and color elif personal in ['quality', 'color', 'playerType']: color = quality_color(player[personal]) stat_label = Label(font=small_tf_font, width=personal_stat_width, height=std_tf_height, x=label_x+5, y=label_y, color=color, just=personal_stat_just) if personal == 'height': centimeters = player[personal] converted_height = convert_height(centimeters, 'string') stat_label.text = '%s (%d cm)' % (converted_height, centimeters) elif personal == 'weight': kilograms = player[personal] pounds = convert_weight(kilograms) stat_label.text = '%.1f lb (%d kg)' % (pounds, kilograms) elif personal in ['club', 'nation']: stat_label.text = ascii_text(player[personal]['name']) elif personal in ['league']: stat_label.text = '%s (%s)' % (ascii_text(player[personal]['name']), ascii_text(player[personal]['abbrName'])) elif personal == 'birthdate': b_day = format_birthday(player['birthdate']) stat_label.text = b_day elif personal == 'position': stat_label.text = '%s (%s)' % (player['positionFull'], player[personal]) else: stat_label.text = str(player[personal]) labels_list.append(stat_label) label_y += std_tf_height # ========== Detailed Attribute Sections ========== attribute_group_list = ['characteristics', 'pace', 'shooting', 'passing', 'goalkeeping', 'dribbling', 'defending', 'physicality'] group_spacing = (win_player_bio.width - 4*section_label_width)/5 group_x = group_spacing group_y = personal_label.bottom + 175 for idx, group in enumerate(attribute_group_list): if idx == 4: group_x = group_spacing group_y += 150 stat_group_label = Label(font=std_tf_font_bold, width=section_label_width, height=std_tf_height, x=group_x, y=group_y, color=title_color, just='center') stat_group_label.text = group.capitalize() if idx in [1, 2, 3, 5, 6, 7] and not player['isGK']: stat_group_label.text += ':' labels_list.append(stat_group_label) if idx in [1, 2, 3, 5, 6, 7] and not player['isGK']: rating_offset = [0, 25, 12, 16, 0, 8, 6, 2] stat_group_rating_label = Label(font=std_tf_font_bold, width=20, height=std_tf_height, x=stat_group_label.right - rating_offset[idx], y=group_y, color=title_color, just='center') stat_group_rating_label.text = str(player['attributes'][idx - (1 + int(idx/4))]['value']) stat_group_rating_label.color = attr_color(player['attributes'][idx - (1 + int(idx/4))]['value']) labels_list.append(stat_group_rating_label) # ========== Detailed Attribute Stats Sections ========== stat_title_label_width = 110 stat_width = 25 label_y = stat_group_label.bottom label_x = stat_group_label.left + section_label_width/2 + 25 if group == 'characteristics': stat_width = 60 for attribute in attribute_lists[group]: stat_title_label = Label(font=small_tf_font, width=stat_title_label_width, height=std_tf_height, x=label_x-stat_title_label_width, y=label_y, color=title_color, just='right') stat_title_label.text = format_attr_name(attribute) + ':' labels_list.append(stat_title_label) color = white if type(player[attribute]) is int and attribute not in ['weakFoot', 'skillMoves']: color = attr_color(player[attribute]) elif attribute in ['weakFoot', 'skillMoves']: color = attr_color(40 + 10*player[attribute]) stat_label = Label(font=small_tf_font, width=stat_width, height=std_tf_height, x=label_x, y=label_y, color=color, just='right') if attribute in ['weakFoot', 'skillMoves']: stat_label.text = '* '*player[attribute] else: stat_label.text = str(player[attribute]) labels_list.append(stat_label) label_y += std_tf_height group_x += section_label_width + group_spacing # ========== Label Text ========== # Player's normal name player_name = ascii_text(player['name']) player_name_label.text = player_name name_on_card_label.text = player_name # Player's name player_full_name = ascii_text(player['firstName']) + ' ' + ascii_text(player['lastName']) player_full_name_label.text = player_full_name # Player's rating rating_big_label.text = str(player['rating']) # Player's position position_big_label.text = player['position'] # Player's traits traits_label.text = 'Traits:' traits_list = '' traits_list_2 = '' if player['traits'] is not None: index = 0 for trait in player['traits']: if len(traits_list + trait) < 70: traits_list += trait + ', ' index += 1 else: break for trait in player['traits'][index:]: traits_list_2 += trait + ', ' else: traits_list = 'No traits..' if len(traits_list_2) > 0: traits_list_label.text = traits_list[:-1] else: traits_list_label.text = traits_list[:-2] traits_list_label_2.text = traits_list_2[:-2] # Player's specialities specialities_label.text = 'Specialities:' specialities_list = '' specialities_list_2 = '' if player['specialities'] is not None: index = 0 for speciality in player['specialities']: if len(specialities_list + speciality) < 70: specialities_list += speciality + ', ' index += 1 else: break for speciality in player['specialities'][index:]: specialities_list_2 += speciality + ', ' else: specialities_list = 'No specialities..' if len(specialities_list_2) > 0: specialities_list_label.text = specialities_list[:-1] else: specialities_list_label.text = specialities_list[:-2] specialities_list_label_2.text = specialities_list_2[:-2] # ========== Add buttons to window ========== view.add(add_player_btn) view.add(back_btn) view.add(update_price_btn) for label in labels_list: view.add(label) win_player_bio.add(view) view.become_target() win_player_bio.show()
def open_create_ultimate_teams_window(window_x, window_y, db_dict, win_previous, player_judge_list=None, team_judge_list=None, file_name=None, roster=None, input_formation=None): display_items = [] # Get create ultimate team configuration values with open(config_filename, 'r') as f: settings = json.load(f)['ultimate_team_configs'] f.close() # Set the attributes lists if player_judge_list is not None: settings['player_sort_attributes'] = player_judge_list if team_judge_list is not None: settings['team_sort_attributes'] = team_judge_list if roster is None: roster = {} settings['roster'] = roster # Assign input formation, or lack thereof, to settings settings['input_formation'] = input_formation # ========== Window ========== win_ultimate_teams = Window() win_ultimate_teams.title = create_ultimate_teams_win_title win_ultimate_teams.auto_position = False win_ultimate_teams.position = (window_x, window_y) win_ultimate_teams.size = (win_width, win_height) win_ultimate_teams.resizable = 0 win_ultimate_teams.name = create_ultimate_teams_title + " Window" # ========== Window Image View ========== class CreateUltimateTeamsWindowImageView(View): def draw(self, c, r): c.backcolor = view_backcolor c.erase_rect(r) view = CreateUltimateTeamsWindowImageView(size=win_ultimate_teams.size) # ========== Title ========== title = Label(text=create_ultimate_teams_title) title.font = title_font title.width = title_width title.height = title_height title.x = (win_width - title_width) / 2 title.y = top_border title.color = title_color title.just = 'center' display_items.append(title) # ========== Settings ========== # ========== Current player list and formation list ========== file_name_width = 125 file_button_width = 200 # Functions for picking files def player_list_current_btn_func(): save_settings() settings['file_type'] = 'current_player_list' settings['file_changes'] = False settings['prev_window'] = 'team_creation' settings['prev_window_value'] = win_previous settings['create_team_name'] = team_list_name_tf.value PickFile.open_pick_file_window(win_ultimate_teams.x, win_ultimate_teams.y, db_dict, settings) win_ultimate_teams.hide() def player_db_current_btn_func(): save_settings() settings['file_type'] = 'current_player_db' settings['file_changes'] = False settings['prev_window'] = 'team_creation' settings['prev_window_value'] = win_previous settings['create_team_name'] = team_list_name_tf.value PickFile.open_pick_file_window(win_ultimate_teams.x, win_ultimate_teams.y, db_dict, settings) win_ultimate_teams.hide() def formation_list_current_btn_func(): save_settings() settings['file_type'] = 'current_formation_list' settings['file_changes'] = False settings['prev_window'] = 'team_creation' settings['prev_window_value'] = win_previous settings['create_team_name'] = team_list_name_tf.value PickFile.open_pick_file_window(win_ultimate_teams.x, win_ultimate_teams.y, db_dict, settings) win_ultimate_teams.hide() player_list_label = Label(text="Player List:", font=std_tf_font_bold, width=file_name_width, height=std_tf_height, x=(win_width-file_name_width-file_button_width-5)/2, y=title.bottom + title_border*3, color=title_color, just='right') display_items.append(player_list_label) player_list_button = Button(title=db_dict['player_list'][0], font=small_tf_font, width=file_button_width, height=std_tf_height, x=player_list_label.right + 5, y=player_list_label.top, color=title_color, just='center', action=player_list_current_btn_func) display_items.append(player_list_button) player_db_label = Label(text="Player DB:", font=std_tf_font_bold, width=file_name_width, height=std_tf_height, x=player_list_label.left, y=player_list_label.bottom + title_border, color=title_color, just='right') display_items.append(player_db_label) player_db_button = Button(title=db_dict['player_db'][0], font=small_tf_font, width=file_button_width, height=std_tf_height, x=player_list_label.right + 5, y=player_db_label.top, color=title_color, just='center', action=player_db_current_btn_func) display_items.append(player_db_button) formation_list_label = Label(text="Formation List:", font=std_tf_font_bold, width=file_name_width, height=std_tf_height, x=player_list_label.left, y=player_db_label.bottom + title_border, color=title_color, just='right') display_items.append(formation_list_label) formation_list_button = Button(title=db_dict['formation_list'][0], font=small_tf_font, width=file_button_width, height=std_tf_height, x=formation_list_label.right + 5, y=formation_list_label.top, color=title_color, just='center', action=formation_list_current_btn_func) display_items.append(formation_list_button) if input_formation is not None and input_formation['name'] != 'Generic': formation_list_button.enabled = 0 formation_list_button.title = input_formation['name'] settings_indent = 3*win_width/7 # ========== Team Name ========== tf_width = 235 team_name_label_width = 130 disabled_msg = "Disabled" team_list_name_label = Label(text="Team List Name: ", font=std_tf_font_bold, width=team_name_label_width, height=std_tf_height, x=settings_indent - team_name_label_width, y=formation_list_label.bottom + title_border*2, color=title_color, just='right') display_items.append(team_list_name_label) team_list_name_tf = TextField(font=std_tf_font, width=tf_width, height=std_tf_height + 5, x=team_list_name_label.right + small_button_spacing, y=team_list_name_label.top) display_items.append(team_list_name_tf) if file_name is not None: team_list_name_tf.value = file_name radio_btn_width = 75 radio_btn_space = 5 # ========== Process Type Label ========== process_type_label = Label(text="Processing Type: ", font=std_tf_font_bold, width=std_tf_width, height=std_tf_height, x=settings_indent - std_tf_width, y=team_list_name_label.bottom + title_border, color=title_color, just='right') display_items.append(process_type_label) def get_process_type_rg(): settings['process_type'] = process_type_radio_group.value win_ultimate_teams.become_target() process_type_radio_group = RadioGroup(action=get_process_type_rg) # Process Type Radio Buttons multi_process_radio_btn = RadioButton('Multi', width=radio_btn_width, x=process_type_label.right + radio_btn_space, y=process_type_label.top, group=process_type_radio_group, value='multi') display_items.append(multi_process_radio_btn) single_process_radio_btn = RadioButton('Single', width=radio_btn_width, x=multi_process_radio_btn.right + radio_btn_space, y=process_type_label.top, group=process_type_radio_group, value='single') display_items.append(single_process_radio_btn) process_type_radio_group.value = settings['process_type'] # If building a team based on one formation, there is no benefit to using multiple processes. if input_formation is not None: if input_formation['name'] != 'Generic': process_type_radio_group.value = 'single' settings['process_type'] = 'single' multi_process_radio_btn.enabled = 0 single_process_radio_btn.enabled = 0 # ========== Chemistry Matters Label ========== chemistry_matters_label = Label(text="Chemistry Matters: ", font=std_tf_font_bold, width=std_tf_width, height=std_tf_height, x=settings_indent - std_tf_width, y=process_type_label.bottom + title_border, color=title_color, just='right') display_items.append(chemistry_matters_label) def get_chemistry_matters_rg(): settings['chemistry_matters'] = chemistry_matters_radio_group.value win_ultimate_teams.become_target() chemistry_matters_radio_group = RadioGroup(action=get_chemistry_matters_rg) # Process Type Radio Buttons multi_process_radio_btn = RadioButton('Yes', width=radio_btn_width, x=chemistry_matters_label.right + radio_btn_space, y=chemistry_matters_label.top, group=chemistry_matters_radio_group, value=True) display_items.append(multi_process_radio_btn) single_process_radio_btn = RadioButton('No', width=radio_btn_width, x=multi_process_radio_btn.right + radio_btn_space, y=chemistry_matters_label.top, group=chemistry_matters_radio_group, value=False) display_items.append(single_process_radio_btn) chemistry_matters_radio_group.value = settings['chemistry_matters'] # ========== Judging Teams Label ========== judging_teams_label = Label(text="How to Judge Teams: ", font=std_tf_font_bold, width=std_tf_width, height=std_tf_height, x=settings_indent - std_tf_width, y=chemistry_matters_label.bottom + title_border, color=title_color, just='right') display_items.append(judging_teams_label) judging_teams_attributes = Label(font=std_tf_font, width=std_tf_width, height=std_tf_height, x=judging_teams_label.right + radio_btn_space, y=judging_teams_label.top, color=title_color, just='left') judging_teams_attributes_text = '' for attr in settings['team_sort_attributes']: judging_teams_attributes_text += format_attr_name(attr) + ', ' # Remove extra comma and space judging_teams_attributes_text = judging_teams_attributes_text[:-2] # Truncate if too long if len(judging_teams_attributes_text) > 26: judging_teams_attributes_text = judging_teams_attributes_text[:26] + '...' judging_teams_attributes.text = judging_teams_attributes_text display_items.append(judging_teams_attributes) # Judging Teams Edit Button def judging_teams_edit_btn_func(): save_settings() attr_dict = {} attr_list = settings['team_sort_attributes'] attr_type = 'team_sort' attribute_settings = {'window': 'ultimate_team_judging', 'file_name': team_list_name_tf.value, 'roster': roster, 'input_formation': input_formation, 'prev_window_value': win_previous} AddAttribute.open_attribute_window( win_ultimate_teams.x, win_ultimate_teams.y, db_dict, attr_dict, attr_list, attr_type, attribute_settings) win_ultimate_teams.hide() judging_edit_btn_width = 40 judging_teams_edit_btn = Button("Edit", #x=teams_to_return_tf.right - judging_edit_btn_width, x=judging_teams_attributes.right, y=judging_teams_label.top, height=small_button_height-7, width=judging_edit_btn_width, font=small_button_font, action=judging_teams_edit_btn_func, style = 'default', color=button_color, just='right') display_items.append(judging_teams_edit_btn) # ========== Judging Players Label ========== judging_players_label = Label(text="How to Judge Players: ", font=std_tf_font_bold, width=std_tf_width, height=std_tf_height, x=settings_indent - std_tf_width, y=judging_teams_label.bottom + title_border, color=title_color, just='right') display_items.append(judging_players_label) judging_players_attributes = Label(font=std_tf_font, width=std_tf_width, height=std_tf_height, x=judging_players_label.right + radio_btn_space, y=judging_players_label.top, color=title_color, just='left') judging_players_attributes_text = '' for attr in settings['player_sort_attributes']: judging_players_attributes_text += format_attr_name(attr) + ', ' # Remove extra comma and space judging_players_attributes_text = judging_players_attributes_text[:-2] # Truncate if too long if len(judging_players_attributes_text) > 26: judging_players_attributes_text = judging_players_attributes_text[:26] + '...' judging_players_attributes.text = judging_players_attributes_text display_items.append(judging_players_attributes) # Judging Teams Edit Button def judging_players_edit_btn_func(): save_settings() attr_dict = {} attr_list = settings['player_sort_attributes'] attr_type = 'player_sort' attribute_settings = {'window': 'ultimate_player_judging', 'file_name': team_list_name_tf.value, 'roster': roster, 'input_formation': input_formation, 'prev_window_value': win_previous} AddAttribute.open_attribute_window(win_ultimate_teams.x, win_ultimate_teams.y, db_dict, attr_dict, attr_list, attr_type, attribute_settings) win_ultimate_teams.hide() judging_edit_btn_width = 40 judging_players_edit_btn = Button("Edit", #x=teams_to_return_tf.right - judging_edit_btn_width, x=judging_players_attributes.right, y=judging_players_label.top, height=small_button_height-7, width=judging_edit_btn_width, font=small_button_font, action=judging_players_edit_btn_func, style = 'default', color=button_color, just='right') display_items.append(judging_players_edit_btn) # ========== New Player Budget ========== budget_tf = TextField(font=std_tf_font, width=tf_width, height=std_tf_height_plus) def budget_btn_func(): if not settings['budget'][0]: settings['budget'][0] = True budget_tf.value = str(settings['budget'][1]) budget_tf.enabled = 1 player_db_button.enabled = 1 else: # Get value from text field and assign to settings if str.isdigit(budget_tf.value): settings['budget'][1] = int(budget_tf.value) settings['budget'][0] = False budget_tf.value = disabled_msg budget_tf.enabled = 0 player_db_button.enabled = 0 win_ultimate_teams.become_target() budget_btn = Button(title="New Player Budget", font=std_tf_font_bold, width=std_tf_width, height=std_tf_height_plus, x=settings_indent - std_tf_width, y=judging_players_label.bottom + title_border*2, action=budget_btn_func, color=title_color, just='right') display_items.append(budget_btn) budget_tf.x = budget_btn.right + radio_btn_space budget_tf.y = budget_btn.top display_items.append(budget_tf) # Disable based on settings if not settings['budget'][0]: budget_tf.value = disabled_msg budget_tf.enabled = 0 player_db_button.enabled = 0 else: budget_tf.value = str(settings['budget'][1]) # ========== Limits Label ========== limits_label = Label(text="Limitations", font=title_font_3, width=std_tf_width, height=title_height-25, x=(win_ultimate_teams.width - std_tf_width)/2, y=budget_tf.bottom + title_border*2, color=title_color, just='center') display_items.append(limits_label) # ========== Players per Position Label ========== players_per_pos_tf = TextField(font=std_tf_font, width=tf_width, height=std_tf_height_plus) def players_per_pos_btn_func(): if not settings['players_per_position'][0]: settings['players_per_position'][0] = True players_per_pos_tf.value = str(settings['players_per_position'][1]) players_per_pos_tf.enabled = 1 else: # Get value from text field and assign to settings if str.isdigit(players_per_pos_tf.value): settings['players_per_position'][1] = int(players_per_pos_tf.value) settings['players_per_position'][0] = False players_per_pos_tf.value = disabled_msg players_per_pos_tf.enabled = 0 win_ultimate_teams.become_target() players_per_pos_btn = Button(title="Players per Position", font=std_tf_font_bold, width=std_tf_width, height=std_tf_height_plus, x=settings_indent - std_tf_width, y=limits_label.bottom + 5, action=players_per_pos_btn_func, color=title_color, just='right') display_items.append(players_per_pos_btn) players_per_pos_tf.x = players_per_pos_btn.right + radio_btn_space players_per_pos_tf.y = players_per_pos_btn.top display_items.append(players_per_pos_tf) # Disable based on settings if not settings['players_per_position'][0]: players_per_pos_tf.value = disabled_msg players_per_pos_tf.enabled = 0 else: players_per_pos_tf.value = str(settings['players_per_position'][1]) # ========== Max Teams per Formation Label ========== teams_per_formation_tf = TextField(font=std_tf_font, width=tf_width, height=std_tf_height_plus) def teams_per_formation_btn_func(): if not settings['teams_per_formation'][0]: settings['teams_per_formation'][0] = True teams_per_formation_tf.value = str(settings['teams_per_formation'][1]) teams_per_formation_tf.enabled = 1 else: # Get value from text field and assign to settings if str.isdigit(teams_per_formation_tf.value): settings['teams_per_formation'][1] = int(teams_per_formation_tf.value) settings['teams_per_formation'][0] = False teams_per_formation_tf.value = disabled_msg teams_per_formation_tf.enabled = 0 win_ultimate_teams.become_target() teams_per_formation_btn = Button(title="Max Teams per Formation", font=std_tf_font_bold, width=std_tf_width, height=std_tf_height_plus, x=settings_indent - std_tf_width, y=players_per_pos_btn.bottom + 5, action=teams_per_formation_btn_func, color=title_color, just='right') display_items.append(teams_per_formation_btn) teams_per_formation_tf.x = teams_per_formation_btn.right + radio_btn_space teams_per_formation_tf.y = teams_per_formation_btn.top display_items.append(teams_per_formation_tf) # Disable based on settings if not settings['teams_per_formation'][0]: teams_per_formation_tf.value = disabled_msg teams_per_formation_tf.enabled = 0 else: teams_per_formation_tf.value = str(settings['teams_per_formation'][1]) # ========== Max Teams to Return Label ========== teams_to_return_tf = TextField(font=std_tf_font, width=tf_width, height=std_tf_height_plus) def teams_to_return_btn_func(): if not settings['num_teams_returned'][0]: settings['num_teams_returned'][0] = True teams_to_return_tf.value = str(settings['num_teams_returned'][1]) teams_to_return_tf.enabled = 1 else: # Get value from text field and assign to settings if str.isdigit(teams_to_return_tf.value): settings['num_teams_returned'][1] = int(teams_to_return_tf.value) settings['num_teams_returned'][0] = False teams_to_return_tf.value = disabled_msg teams_to_return_tf.enabled = 0 win_ultimate_teams.become_target() teams_to_return_btn = Button(title="Max Teams to Return", font=std_tf_font_bold, width=std_tf_width, height=std_tf_height_plus, x=settings_indent - std_tf_width, y=teams_per_formation_btn.bottom + 5, action=teams_to_return_btn_func, color=title_color, just='right') display_items.append(teams_to_return_btn) teams_to_return_tf.x = teams_to_return_btn.right + radio_btn_space teams_to_return_tf.y = teams_to_return_btn.top display_items.append(teams_to_return_tf) # Disable based on settings if not settings['num_teams_returned'][0]: teams_to_return_tf.value = disabled_msg teams_to_return_tf.enabled = 0 else: teams_to_return_tf.value = str(settings['num_teams_returned'][1]) # ========== Time Limit Label ========== time_limit_tf = TextField(font=std_tf_font, width=tf_width, height=std_tf_height_plus) def time_limit_btn_func(): if not settings['time_limit'][0]: settings['time_limit'][0] = True time_limit_val = 0.0 if settings['time_limit'][2] == 'days': time_limit_val = settings['time_limit'][1] / 86400.0 elif settings['time_limit'][2] == 'hours': time_limit_val = settings['time_limit'][1] / 3600.0 if settings['time_limit'][2] == 'minutes': time_limit_val = settings['time_limit'][1] / 60.0 time_limit_tf.value = str(time_limit_val) time_limit_tf.enabled = 1 days_time_limit_radio_btn.enabled = 1 hours_time_limit_radio_btn.enabled = 1 minutes_time_limit_radio_btn.enabled = 1 time_limit_radio_group.enabled = 1 else: # Get value from text field, convert to seconds, and assign to settings try: if settings['time_limit'][2] == 'days': settings['time_limit'][1] = int(float(time_limit_tf.value) * 86400.0) elif settings['time_limit'][2] == 'hours': settings['time_limit'][1] = int(float(time_limit_tf.value) * 3600.0) elif settings['time_limit'][2] == 'minutes': settings['time_limit'][1] = int(float(time_limit_tf.value) * 60.0) except ValueError: print "Invalid time limit." settings['time_limit'][0] = False time_limit_tf.value = disabled_msg time_limit_tf.enabled = 0 days_time_limit_radio_btn.enabled = 0 hours_time_limit_radio_btn.enabled = 0 minutes_time_limit_radio_btn.enabled = 0 time_limit_radio_group.enabled = 0 win_ultimate_teams.become_target() time_limit_btn = Button(title="Time Limit", font=std_tf_font_bold, width=std_tf_width, height=std_tf_height_plus, x=settings_indent - std_tf_width, y=teams_to_return_btn.bottom + 5, action=time_limit_btn_func, color=title_color, just='right') display_items.append(time_limit_btn) def get_time_limit_rg(): # Get value from text field, convert to seconds, and assign to settings if time_limit_tf.value == '': time_limit_tf.value = '0' else: try: if settings['time_limit'][2] == 'days': settings['time_limit'][1] = int(float(time_limit_tf.value) * 86400.0) elif settings['time_limit'][2] == 'hours': settings['time_limit'][1] = int(float(time_limit_tf.value) * 3600.0) elif settings['time_limit'][2] == 'minutes': settings['time_limit'][1] = int(float(time_limit_tf.value) * 60.0) except ValueError: print "Invalid time limit." # Get new time limit units settings['time_limit'][2] = time_limit_radio_group.value time_limit_val = 0.0 if settings['time_limit'][2] == 'days': time_limit_val = settings['time_limit'][1] / 86400.0 elif settings['time_limit'][2] == 'hours': time_limit_val = settings['time_limit'][1] / 3600.0 elif settings['time_limit'][2] == 'minutes': time_limit_val = settings['time_limit'][1] / 60.0 time_limit_tf.value = str(time_limit_val) win_ultimate_teams.become_target() time_limit_radio_group = RadioGroup(action=get_time_limit_rg) # Time Limit Units Radio Buttons days_time_limit_radio_btn = RadioButton('Days', width=radio_btn_width, x=time_limit_btn.right + radio_btn_space, y=time_limit_btn.bottom + 5, group=time_limit_radio_group, value='days') display_items.append(days_time_limit_radio_btn) hours_time_limit_radio_btn = RadioButton('Hours', width=radio_btn_width, x=days_time_limit_radio_btn.right + radio_btn_space, y=days_time_limit_radio_btn.top, group=time_limit_radio_group, value='hours') display_items.append(hours_time_limit_radio_btn) minutes_time_limit_radio_btn = RadioButton('Minutes', width=radio_btn_width, x=hours_time_limit_radio_btn.right + radio_btn_space, y=days_time_limit_radio_btn.top, group=time_limit_radio_group, value='minutes') display_items.append(minutes_time_limit_radio_btn) time_limit_radio_group.value = settings['time_limit'][2] time_limit_tf.x = time_limit_btn.right + radio_btn_space time_limit_tf.y = time_limit_btn.top display_items.append(time_limit_tf) # Disable based on settings if not settings['time_limit'][0]: time_limit_tf.value = disabled_msg time_limit_tf.enabled = 0 days_time_limit_radio_btn.enabled = 0 hours_time_limit_radio_btn.enabled = 0 minutes_time_limit_radio_btn.enabled = 0 time_limit_radio_group.enabled = 0 else: time_limit_value = 0.0 if settings['time_limit'][2] == 'days': time_limit_value = settings['time_limit'][1] / 86400.0 elif settings['time_limit'][2] == 'hours': time_limit_value = settings['time_limit'][1] / 3600.0 elif settings['time_limit'][2] == 'minutes': time_limit_value = settings['time_limit'][1] / 60.0 time_limit_tf.value = str(time_limit_value) # ========== Button Declarations ========== start_btn = Button("Start") menu_btn = Button("Main Menu") back_btn = Button("Back") # ========== Button Functions ========== def save_settings(): """ Save the ultimate team creation configuration settings """ # Get the values from the text fields # New player budget if str.isdigit(budget_tf.value): settings['budget'][1] = int(budget_tf.value) # Players per position if str.isdigit(players_per_pos_tf.value): settings['players_per_position'][1] = int(players_per_pos_tf.value) # Teams per formation if str.isdigit(teams_per_formation_tf.value): settings['teams_per_formation'][1] = int(teams_per_formation_tf.value) # Number of teams returned if str.isdigit(teams_to_return_tf.value): settings['num_teams_returned'][1] = int(teams_to_return_tf.value) # Time limit if time_limit_tf.value != disabled_msg: try: if settings['time_limit'][2] == 'days': settings['time_limit'][1] = int(float(time_limit_tf.value) * 86400.0) elif settings['time_limit'][2] == 'hours': settings['time_limit'][1] = int(float(time_limit_tf.value) * 3600.0) elif settings['time_limit'][2] == 'minutes': settings['time_limit'][1] = int(float(time_limit_tf.value) * 60.0) except ValueError: print "Invalid time limit." # Load configurations from Window.AppConfig import config_filename with open(config_filename, 'r') as config_file: configurations = json.load(config_file) config_file.close() # Edit configurations configurations['ultimate_team_configs'] = settings # Save the settings with open(config_filename, 'w') as config_file: json.dump(configurations, config_file) config_file.close() def start_btn_func(): save_settings() # Assign formation(s) to use if input_formation is None or input_formation['name'] == "Generic": formations = db_dict['formation_list'][1] else: formations = FormationDB.FormationDB(input_formation) # If budget is not used, set player DB to an empty object. if budget_btn.enabled: player_db = db_dict['player_db'][1] else: player_db = PlayerDB.PlayerDB() # Open status page """StatusWindow.open_status_window(win_ultimate_teams.x, win_ultimate_teams.y, db_dict, file_name=team_list_name_tf.value, win_previous=win_ultimate_teams) win_ultimate_teams.hide()""" # Run team creation here team = Team.Team() teams = TeamDB.TeamDB(team.create_team_ultimate(db_dict['player_list'][1], player_db, formations)) if len(teams.db) > 0: teams.save(team_list_name_tf.value) else: print 'Not saved because no teams created.' # Erase file name team_list_name_tf.value = '' win_ultimate_teams.become_target() def menu_btn_func(): save_settings() StartMenu.open_start_menu(win_ultimate_teams.x, win_ultimate_teams.y, db_dict) win_ultimate_teams.hide() def back_btn_func(): save_settings() win_previous.show() win_ultimate_teams.hide() # Save the attribute lists if they were changed if player_judge_list is not None: save_settings() if team_judge_list is not None: save_settings() # ========== Buttons ========== start_btn.x = (win_width - 3*button_width - 2*button_spacing) / 2 start_btn.y = win_ultimate_teams.height - 100 start_btn.height = button_height start_btn.width = button_width start_btn.font = button_font start_btn.action = start_btn_func start_btn.style = 'default' start_btn.color = button_color start_btn.just = 'right' display_items.append(start_btn) menu_btn.x = start_btn.right + button_spacing menu_btn.y = start_btn.top menu_btn.height = button_height menu_btn.width = button_width menu_btn.font = button_font menu_btn.action = menu_btn_func menu_btn.style = 'default' menu_btn.color = button_color menu_btn.just = 'right' display_items.append(menu_btn) back_btn.x = menu_btn.right + button_spacing back_btn.y = start_btn.top back_btn.height = button_height back_btn.width = button_width back_btn.font = button_font back_btn.action = back_btn_func back_btn.style = 'default' back_btn.color = button_color back_btn.just = 'right' display_items.append(back_btn) # ========== Add components to view and add view to window ========== for item in display_items: view.add(item) win_ultimate_teams.add(view) view.become_target() win_ultimate_teams.show()