def update_value(self): ''' Updates the values of all the indicators ''' for i in range(5): self.bar_dict[i].update_value(model.indicators_list[i].get_value()) if not (self.value_labels[i].text == str(int(model.indicators_list[i].get_value())) + '%'): self.update_flag = True #print 'update flag is',self.update_flag,'panel flag is',threades.panel_update_flag,'total is',threades.total_update_flag if self.update_flag or threades.panel_update_flag or threades.total_update_flag: pygame.draw.line(threades.screen, self.color_grey, threades.resize_pos((900, 645)), threades.resize_pos((900, 900)), 1) for i in range(5): self.bar_dict[i].update_value( model.indicators_list[i].get_value()) if not (self.value_labels[i].text == str(int(model.indicators_list[i].get_value())) + '%'): self.value_labels[i].text = str( int(model.indicators_list[i].get_value())) + '%' self.update_flag = False
def graphics(self): logo = pygame.image.load(os.path.join('data', 'logo.png')).convert() self.ff_logo = pygame.transform.scale(logo, threades.resize_pos((1111, 250))) threades.screen.fill((0, 0, 0)) threades.screen.blit(self.ff_logo, threades.resize_pos((40, 50))) # Font type myfont = pangofont.PangoFont(size=threades.resize_pt(17)) #creating new label showing loading of level labelStyleCopy = gui.defaultLabelStyle.copy() labelStyleCopy['border-width'] = 1 labelStyleCopy['wordwrap'] = True labelStyleCopy['autosize'] = False labelStyleCopy['font'] = myfont labelStyleCopy['font-color'] = (0, 200, 0) if self.level_no == -1: text1 = _('Loading New Level...') else: text1 = _('Loading Level No:') + str(self.level_no) #creating the label label = gui.Label(position=threades.resize_pos((500, 600)), size=threades.resize_pos((250, 50)), parent=desktop_level, style=labelStyleCopy, text=text1)
def pause_screen(pause_flag = True): start = starting_intro() start.main_menu(pause_flag,threades.game_save_flag) logo = pygame.image.load(os.path.join('data', 'logo.png')).convert() ff_logo = pygame.transform.scale(logo,threades.resize_pos((1128,171))) threades.audio.play_music(False,'soundtrack') while start.run: pygame.display.set_caption('FoodForce2') threades.screen.fill((0,0,0)) threades.screen.blit(ff_logo,threades.resize_pos((40,90))) for e in gui.setEvents(pygame.event.get()): if e.type == pygame.QUIT: safe_exit() if e.type == QUIT: safe_exit() #print 'in pause screen' desktop2.update() desktop2.draw() pygame.display.update() threades.audio.play_music(True,'soundtrack') threades.total_update_flag = True
def update_value(self): ''' Updates the Manpower panel ''' list_values = (model.ppl.get_total_population(), model.ppl.get_no_of_ppl_sheltered(), model.ppl.get_no_of_ppl_educated(), model.ppl.get_no_of_ppl_healthy(), model.ppl.get_no_of_ppl_fed(), model.ppl.get_total_no_of_ppl_emp()) for i in range(6): if not (self.value_labels[i].text == str(int(list_values[i]))): self.update_flag = True if self.update_flag or threades.panel_update_flag or threades.total_update_flag: pygame.draw.line(threades.screen, self.color_grey, threades.resize_pos((900, 645)), threades.resize_pos((900, 855)), 1) pygame.draw.rect(threades.screen, self.color_grey, threades.resize_rect((0, 855, 300, 45)), 2) pygame.draw.rect(threades.screen, self.color_grey, threades.resize_rect((300, 855, 300, 45)), 2) pygame.draw.rect(threades.screen, self.color_grey, threades.resize_rect((600, 855, 300, 45)), 2) for i in range(6): if not (self.value_labels[i].text == str(int(list_values[i]))): self.value_labels[i].text = str(int(list_values[i])) self.update_flag = False
def __init__(self): ''' Draws the Facilities panel ''' self.update_flag = True myfont1 = pygame.font.Font("font.ttf", threades.resize_pt(20)) # For model.resources name and their value self.name_labels = [] self.labelstyle1 = gui.defaultLabelStyle.copy() self.labelstyle1['border-width'] = 0 self.labelstyle1['wordwrap'] = False self.labelstyle1['autosize'] = False self.labelstyle1['font'] = myfont1 self.labelstyle1['font-color'] = self.font_color #self.labelstyle1['bg-color'] = self.font_bg_color self.list_titles = model.text_file.facilities_list self.list_names = [model.text_file.num_text[0]+': '] self.list_values1 = (model.House.get_number(),model.School.get_number(),model.Hospital.get_number(),model.Workshop.get_number(),model.Farm.get_number(),model.Fountain.get_number()) self.list_values2 = (model.House.get_level(),model.School.get_level(),model.Hospital.get_level(),model.Workshop.get_level(),model.Farm.get_level(),model.Fountain.get_level()) self.value_labels = [] for i in range(6): label = gui.Label(position = threades.resize_pos((950,50+55*i)),size = threades.resize_pos((300,30)), parent = threades.desktop, text = self.list_titles[i], style = self.labelstyle1) self.name_labels.append(label) label = gui.Label(position = threades.resize_pos((950,75+55*i)),size = threades.resize_pos((300,30)), parent = threades.desktop, text = self.list_names[0]+str(int(self.list_values1[i]))+model.text_file.level_text[0]+':'+str(int(self.list_values2[i])), style = self.labelstyle1) self.name_labels.append(label) label.surf.set_alpha(200) self.value_labels.append(label)
def update(self): for i in range(len(model.facilities_list)): if not (self.list_num_fac[i] == model.facilities_list[i].get_original_number()): self.update_flag = True if self.update_flag or threades.map_update_flag or threades.total_update_flag: threades.screen.blit(self.map, threades.resize_pos((930, 390))) posn = threades.resize_pos( (930 + int(3200 / 23.22), 390 + int(2600 / 24.80))) threades.screen.blit(load_images.Map_images[6], posn) for i in range(len(model.facilities_list)): for j in range(model.facilities_list[i].get_original_number()): posn = threades.resize_pos(( 930 + int(model.facilities_list_sprites[ model.facilities_list[i].get_name()][j].position[0] / 23.22), 390 + int(model.facilities_list_sprites[ model.facilities_list[i].get_name()][j].position[1] / 24.80))) threades.screen.blit(load_images.Map_images[i], posn) rect_draw = threades.transform_obj.village_boundary_covered() rect_final = threades.resize_rect( (930 + rect_draw[0] / 23.22, 390 + rect_draw[1] / 24.80, (rect_draw[2] - rect_draw[0]) / 23.22, (rect_draw[3] - rect_draw[1]) / 24.80)) pygame.draw.rect(threades.screen, (47, 47, 255, 180), rect_final, 2) self.update_flag = False
def pause_screen(pause_flag = True): """ Pauses the screen until user takes any action """ start = starting_intro() #Initialises and creates the starting screen start.main_menu(pause_flag,threades.game_save_flag) logo = pygame.image.load(os.path.join('data', 'logo.png')).convert() ff_logo = pygame.transform.scale(logo,threades.resize_pos((1111,250))) #The loop which pauses main screen while start.run: pygame.display.set_caption('FoodForce2') threades.screen.fill((0,0,0)) threades.screen.blit(ff_logo,threades.resize_pos((40,50))) for e in gui.setEvents(pygame.event.get()): if e.type == pygame.QUIT: safe_exit() if e.type == QUIT: safe_exit() desktop2.update() desktop2.draw() pygame.display.update() threades.total_update_flag = True
def graphics(self): logo = pygame.image.load(os.path.join('data', 'logo.png')).convert() self.ff_logo = pygame.transform.scale(logo,threades.resize_pos((1111,250))) threades.screen.fill((0,0,0)) threades.screen.blit(self.ff_logo,threades.resize_pos((40,50))) # Font type myfont = pygame.font.Font("font.ttf", threades.resize_pt(17)) #creating new label showing loading of level labelStyleCopy = gui.defaultLabelStyle.copy() labelStyleCopy['border-width'] = 1 labelStyleCopy['wordwrap'] = True labelStyleCopy['autosize'] = False labelStyleCopy['font'] = myfont labelStyleCopy['font-color'] = (0,200,0) if self.level_no==-1: text1='Loading New Level...' else: text1='Loading Level No:'+str(self.level_no) #creating the label label = gui.Label(position = threades.resize_pos((500,600)), size = threades.resize_pos((250,50)), parent = desktop_level,style=labelStyleCopy,text=text1) #self.run=True
def pause_screen(pause_flag = True): start = starting_intro() start.main_menu(pause_flag) logo = pygame.image.load(os.path.join('data', 'logo.png')).convert() ff_logo = pygame.transform.scale(logo,threades.resize_pos((1111,250))) while start.run: pygame.display.set_caption('FoodForce2') threades.screen.fill((0,0,0)) threades.screen.blit(ff_logo,threades.resize_pos((40,50))) for e in gui.setEvents(pygame.event.get()): if e.type == pygame.QUIT: safe_exit() if e.type == QUIT: safe_exit() if e.type==mesh.CONNECT : game_sharing.sharing_handler(e.type,None,'') #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,None,'']).start() elif e.type==mesh.PARTICIPANT_ADD or e.type==mesh.PARTICIPANT_REMOVE : game_sharing.sharing_handler(e.type,e.handle,'') #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,e.handle,'']).start() elif e.type==mesh.MESSAGE_MULTI or e.type==mesh.MESSAGE_UNI : game_sharing.sharing_handler(e.type,e.handle,e.content) #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,e.handle,e.content]).start() desktop2.update() desktop2.draw() pygame.display.update() threades.total_update_flag = True
def graphics(self): logo = pygame.image.load(os.path.join("data", "logo.png")).convert() self.ff_logo = pygame.transform.scale(logo, threades.resize_pos((1111, 250))) threades.screen.fill((0, 0, 0)) threades.screen.blit(self.ff_logo, threades.resize_pos((40, 50))) # Font type myfont = pygame.font.Font("font.ttf", threades.resize_pt(17)) # creating new label showing loading of level labelStyleCopy = gui.defaultLabelStyle.copy() labelStyleCopy["border-width"] = 1 labelStyleCopy["wordwrap"] = True labelStyleCopy["autosize"] = False labelStyleCopy["font"] = myfont labelStyleCopy["font-color"] = (0, 200, 0) text1 = "Loading...." # creating the label label = gui.Label( position=threades.resize_pos((500, 600)), size=threades.resize_pos((250, 50)), parent=desktop_level, style=labelStyleCopy, text=text1, )
def __init__(self): ''' Draws the indicator panel on the surface ''' self.update_flag = True self.name_labels = [] myfont1 = pygame.font.Font("font.ttf", threades.resize_pt(25)) # For main heading myfont2 = pygame.font.Font("font.ttf", threades.resize_pt(20)) # For indicators name myfont3 = pygame.font.Font("font.ttf", threades.resize_pt(16)) # Creating a custom label style self.labelstyle1 = gui.defaultLabelStyle.copy() self.labelstyle1['border-width'] = 1 self.labelstyle1['wordwrap'] = True self.labelstyle1['autosize'] = False self.labelstyle1['font'] = myfont1 self.labelstyle1['font-color'] = self.font_color self.labelstyle1['border-color'] = self.color_grey # Drawing main Indicator label label = gui.Label(position = threades.resize_pos((900,600)),size = threades.resize_pos((300,45)), parent = threades.desktop, text = " "+model.text_file.indicators_text[0], style = self.labelstyle1) self.name_labels.append(label) #print " deawing indicator panel" # Creating second custom label self.labelstyle2 = gui.defaultLabelStyle.copy() self.labelstyle2['border-width'] = 0 self.labelstyle2['wordwrap'] = True self.labelstyle2['autosize'] = False self.labelstyle2['font'] = myfont2 self.labelstyle2['font-color'] = self.font_color self.labelstyle2['border-color'] = self.color_grey # Drawing all the indicators # Creating second custom label self.labelstyle3 = gui.defaultLabelStyle.copy() self.labelstyle3['border-width'] = 0 self.labelstyle3['wordwrap'] = False self.labelstyle3['autosize'] = True self.labelstyle3['font'] = myfont3 self.labelstyle3['font-color'] = self.font_color self.labelstyle3['border-color'] = self.color_grey # Empty Dictionary for bar self.bar_dict = [] name_label_size = threades.resize_pos((300,25)) self.value_labels = [] for i in range(5): label = gui.Label(position = threades.resize_pos((900,650+50*i)),size = name_label_size, parent = threades.desktop, text = model.text_file.ind_namelist[i], style = self.labelstyle2) self.name_labels.append(label) self.bar_dict.append(bar((902,677+50*i))) label = gui.Label(position = threades.resize_pos((1160,677+50*i)), parent = threades.desktop, text = str(0), style = self.labelstyle3) self.value_labels.append(label)
def update_value(self): ''' Updates the model.resources panel ''' self.money_flag = False for i in range(11): if not (self.value_labels[i].text == str( int(model.resources[i].get_vquantity()))): self.update_flag = True if self.update_flag or threades.panel_update_flag or threades.total_update_flag: pygame.draw.line(threades.screen, self.color_grey, threades.resize_pos((400, 645)), threades.resize_pos((400, 855)), 1) pygame.draw.line(threades.screen, self.color_grey, threades.resize_pos((650, 645)), threades.resize_pos((650, 855)), 1) for i in range(11): if not (self.value_labels[i].text == str( int(model.resources[i].get_vquantity()))): self.value_labels[i].text = str( int(model.resources[i].get_vquantity())) if not (self.money_label.text == model.text_file.money_text[0] + ' -: ' + str(int(model.money.get_money())) + ' '): self.money_flag = True self.money_label.text = model.text_file.money_text[ 0] + ' -: ' + str(int(model.money.get_money())) + ' ' #print 'no of days is',model.game_controller.get_days() if self.time_flag == True: #self.time_label.text='' #NOTE: Here, I am not adding as if years is not 0 , then only it will be blitted becoz if do like that the things will keep on changing, not a nice view self.time_label.text = model.text_file.time_text[ 0] + ' -: ' + model.text_file.time_text[2] + ': ' + str( model.game_controller.get_years( )) + ' ' + model.text_file.time_text[3] + ': ' + str( model.game_controller.get_months( )) + ' ' + model.text_file.time_text[4] + ': ' + str( model.game_controller.get_days()) self.time_flag = True #to update the money flag #print 'global_time is',model.game_controller.get_global_time(),'while the time_help_value is',self.time_help_value if (model.game_controller.get_global_time() > ( (model.game_controller.conversion_factor) + self.time_help_value)): self.time_flag = True self.time_help_value = model.game_controller.get_global_time() self.update_flag = False
def chatWindow(self, windowtext=None): """ Opens a new chat window """ global desktopChat global move_to_next_chatwin_flag move_to_next_chatwin_flag = False # so that the next window waits for the user to press enter # Disable other gui gui_buttons.gui_obj.disable_buttons() # Stopping the updation thread threades.pause_update_thread() # Custom Window Style win_style = gui.defaultWindowStyle.copy() win_style["bg-color"] = (0, 0, 0) # Calculating position and size of window from the size of the desktop position_win = threades.resize_pos((150.0, 50.0)) size_win = threades.resize_pos((900, 800)) # print 'size win is',size_win,'\n' # Creating window self.chatWin = gui.Window( position=position_win, size=size_win, parent=desktopChat, text="", style=win_style, closeable=False, shadeable=False, moveable=False, ) self.chatWin.surf.fill((0, 0, 0, 140)) self.chatWinFlag = True # NOTE: This part will be used once we know how to blit buttons on the chat window # self.button_skip = gui.Button(position = threades.resize_pos((500.0,10.0),(900.0,800.0),self.size_win), size = threades.resize_pos((80.0,30.0),(900.0,800.0),self.size_win), parent = self.chatWin, text = "Skip",style = self.button_style) # self.button_next = gui.Button(position = threades.resize_pos((200.0,10.0),(900.0,800.0),self.size_win), size = threades.resize_pos((80.0,30.0),(900.0,800.0),self.size_win), parent = self.chatWin, text = "Next >",style = self.button_style) # self.button_skip.onClick=self.closeChatWindow # self.button_skip.onMouseOver=self.closeChatWindow # print self.button_skip.enabled # creating label for writing the text self.label = gui.Label( position=threades.resize_pos((100.0, 760.0), (900.0, 800.0), self.chatWin.size), size=threades.resize_pos((700.0, 30.0), (900.0, 800.0), self.chatWin.size), parent=self.chatWin, text=model.text_file.proceed_text[0], style=self.labelStyleCopy, )
def __init__(self): self.update_flag = True for i in range(6): load_images.Map_images[i] = pygame.transform.scale( load_images.Map_images[i], threades.resize_pos((15, 15))) self.map = pygame.image.load(os.path.join('data', 'map.png')).convert() self.map = pygame.transform.scale(self.map, threades.resize_pos((270, 210))) self.list_num_fac = [] for i in range(len(model.facilities_list)): self.list_num_fac.append( model.facilities_list[i].get_original_number())
def chatWindow(self, windowtext=None): ''' Opens a new chat window ''' global desktopChat global move_to_next_chatwin_flag move_to_next_chatwin_flag = False #so that the next window waits for the user to press enter # Disable other gui gui_buttons.gui_obj.disable_buttons() # Stopping the updation thread threades.pause_update_thread() # Custom Window Style win_style = gui.defaultWindowStyle.copy() win_style['bg-color'] = (0, 0, 0) # Calculating position and size of window from the size of the desktop position_win = threades.resize_pos((150.0, 50.0)) size_win = threades.resize_pos((900, 800)) #print 'size win is',size_win,'\n' # Creating window self.chatWin = gui.Window(position=position_win, size=size_win, parent=desktopChat, text='', style=win_style, closeable=False, shadeable=False, moveable=False) self.chatWin.surf.fill((0, 0, 0, 140)) self.chatWinFlag = True #NOTE: This part will be used once we know how to blit buttons on the chat window #self.button_skip = gui.Button(position = threades.resize_pos((500.0,10.0),(900.0,800.0),self.size_win), size = threades.resize_pos((80.0,30.0),(900.0,800.0),self.size_win), parent = self.chatWin, text = "Skip",style = self.button_style) #self.button_next = gui.Button(position = threades.resize_pos((200.0,10.0),(900.0,800.0),self.size_win), size = threades.resize_pos((80.0,30.0),(900.0,800.0),self.size_win), parent = self.chatWin, text = "Next >",style = self.button_style) #self.button_skip.onClick=self.closeChatWindow #self.button_skip.onMouseOver=self.closeChatWindow #print self.button_skip.enabled #creating label for writing the text self.label = gui.Label(position=threades.resize_pos( (100.0, 760.0), (900.0, 800.0), self.chatWin.size), size=threades.resize_pos((700.0, 30.0), (900.0, 800.0), self.chatWin.size), parent=self.chatWin, text=model.text_file.proceed_text[0], style=self.labelStyleCopy)
def __init__(self): ''' Draws the Facilities panel ''' self.update_flag = True myfont1 = pygame.font.Font( "font.ttf", threades.resize_pt(20)) # For model.resources name and their value self.name_labels = [] self.labelstyle1 = gui.defaultLabelStyle.copy() self.labelstyle1['border-width'] = 0 self.labelstyle1['wordwrap'] = False self.labelstyle1['autosize'] = False self.labelstyle1['font'] = myfont1 self.labelstyle1['font-color'] = self.font_color #self.labelstyle1['bg-color'] = self.font_bg_color self.list_titles = model.text_file.facilities_list self.list_names = [model.text_file.num_text[0] + ': '] self.list_values1 = (model.House.get_number(), model.School.get_number(), model.Hospital.get_number(), model.Workshop.get_number(), model.Farm.get_number(), model.Fountain.get_number()) self.list_values2 = (model.House.get_level(), model.School.get_level(), model.Hospital.get_level(), model.Workshop.get_level(), model.Farm.get_level(), model.Fountain.get_level()) self.value_labels = [] for i in range(6): label = gui.Label(position=threades.resize_pos((950, 50 + 55 * i)), size=threades.resize_pos((300, 30)), parent=threades.desktop, text=self.list_titles[i], style=self.labelstyle1) self.name_labels.append(label) label = gui.Label(position=threades.resize_pos((950, 75 + 55 * i)), size=threades.resize_pos((300, 30)), parent=threades.desktop, text=self.list_names[0] + str(int(self.list_values1[i])) + model.text_file.level_text[0] + ':' + str(int(self.list_values2[i])), style=self.labelstyle1) self.name_labels.append(label) label.surf.set_alpha(200) self.value_labels.append(label)
def __init__(self): ''' Draws the manpower panel ''' self.update_flag = True myfont1 = pygame.font.Font("font.ttf", threades.resize_pt(25)) # For main heading myfont2 = pygame.font.Font("font.ttf", threades.resize_pt(20)) # For model.resources name and their value myfont3 = pygame.font.Font("font.ttf", threades.resize_pt(16)) # For model.resources name and their value # Creating a custom label style self.labelstyle1 = gui.defaultLabelStyle.copy() self.labelstyle1['border-width'] = 1 self.labelstyle1['wordwrap'] = True self.labelstyle1['autosize'] = False self.labelstyle1['font'] = myfont1 self.labelstyle1['font-color'] = self.font_color self.labelstyle1['border-color'] = self.color_grey self.name_labels = [] # Drawing main Manpower Resources rectangle label = gui.Label(position = threades.resize_pos((0,600)),size = threades.resize_pos((400,45)), parent = threades.desktop, text = " "+model.text_file.mpwr_resources_text[0], style = self.labelstyle1) self.name_labels.append(label) # Creating second label style self.labelstyle2 = gui.defaultLabelStyle.copy() self.labelstyle2['border-width'] = 0 self.labelstyle2['wordwrap'] = True self.labelstyle2['autosize'] = False self.labelstyle2['font'] = myfont2 self.labelstyle2['font-color'] = self.font_color self.labelstyle2['border-color'] = self.color_grey self.labelstyle3 = gui.defaultLabelStyle.copy() self.labelstyle3['border-width'] = 0 self.labelstyle3['wordwrap'] = False self.labelstyle3['autosize'] = True self.labelstyle3['font'] = myfont3 self.labelstyle3['font-color'] = self.font_color self.labelstyle3['border-color'] = self.color_grey # Drawing Manpower model.resources list list_names = model.text_file.mpwr_list_names list_values = (model.ppl.get_total_population(),model.ppl.get_no_of_ppl_sheltered(),model.ppl.get_no_of_ppl_educated(),model.ppl.get_no_of_ppl_healthy(),model.ppl.get_no_of_ppl_fed(),model.ppl.get_total_no_of_ppl_emp()) self.value_labels = [] for i in range(6): label = gui.Label(position = threades.resize_pos((0,645+35*i)),size = threades.resize_pos((350,35)), parent = threades.desktop, text = list_names[i], style = self.labelstyle2) self.name_labels.append(label) label = gui.Label(position = threades.resize_pos((355,649+35*i)), parent = threades.desktop, text = str(int(list_values[i])), style = self.labelstyle3) self.value_labels.append(label)
def update(self): for i in range(len(model.facilities_list)): if not (self.list_num_fac[i] == model.facilities_list[i].get_original_number()): self.update_flag = True if self.update_flag or threades.map_update_flag or threades.total_update_flag: threades.screen.blit(self.map,threades.resize_pos((930,390))) posn = threades.resize_pos((930+int(3200/33.3),390+int(2600/28.57))) threades.screen.blit(load_images.Map_images[6],posn) for i in range(len(model.facilities_list)): for j in range(model.facilities_list[i].get_original_number()): posn = threades.resize_pos((930+int(load_images.facilities_posn_list[i][j][0]/33.3),390+int(load_images.facilities_posn_list[i][j][1]/28.57))) threades.screen.blit(load_images.Map_images[i],posn) self.update_flag = False
def __init__(self): ''' Draws the Facilities panel ''' self.update_flag = True myfont1 = pangofont.PangoFont(size=threades.resize_pt( 25)) # For model.resources name and their value self.labelstyle1 = gui.defaultLabelStyle.copy() self.labelstyle1['border-width'] = 0 self.labelstyle1['wordwrap'] = False self.labelstyle1['autosize'] = False self.labelstyle1['font'] = myfont1 self.labelstyle1['font-color'] = self.font_color #self.labelstyle1['bg-color'] = self.font_bg_color self.list_titles = (_('Houses '), _('Schools '), _('Hospitals '), _('Workshops '), _('Farms '), _('Wells ')) self.list_names = (_('Number: '), _('Number: '), _('Number: '), _('Number: '), _('Number: '), _('Number: ')) self.list_values1 = (model.House.get_number(), model.School.get_number(), model.Hospital.get_number(), model.Workshop.get_number(), model.Farm.get_number(), model.Fountain.get_number()) self.list_values2 = (model.House.get_level(), model.School.get_level(), model.Hospital.get_level(), model.Workshop.get_level(), model.Farm.get_level(), model.Fountain.get_level()) self.value_labels = [] for i in range(6): label = gui.Label(position=threades.resize_pos((950, 50 + 55 * i)), size=threades.resize_pos((300, 30)), parent=threades.desktop, text=self.list_titles[i], style=self.labelstyle1) label = gui.Label(position=threades.resize_pos((950, 75 + 55 * i)), size=threades.resize_pos((300, 30)), parent=threades.desktop, text=self.list_names[i] + str(int(self.list_values1[i])) + _(' Level: ') + str(int(self.list_values2[i])), style=self.labelstyle1) label.surf.set_alpha(200) self.value_labels.append(label)
def tradingWindow(self,handle,buddyName = 'Friend',resource = 'Water', quantity = '0' ,price = '10',trade = 'sell'): '''Opens the trading window at the reciever end for trading ''' #self.font_color = (255,214,150) # Brown self.replyhandle = handle self.replymessage = ['TradeReply',resource,quantity,price,trade] color_blue = (0,0,250) myfont = pygame.font.Font("font.ttf", threades.resize_pt(17)) # Custom Window Style win_style = gui.defaultWindowStyle.copy() win_style['font'] = myfont win_style['bg-color'] = (0,0,0) win_style['font-color'] = color_blue # Calculating position and size of window from the size of the desktop position_win =threades.resize_pos((725.0,42.0)) size_win =threades.resize_pos((470.0,180.0)) # Creating custom label style for the text to be displayed as a message labelStyleCopy = gui.defaultLabelStyle.copy() labelStyleCopy['wordwrap'] = True labelStyleCopy['autosize'] = False labelStyleCopy['font'] = myfont labelStyleCopy['font-color'] = color_blue #labelStyleCopy['font-color'] = font_color self.win = gui.Window(position = position_win, size = size_win, parent = threades.desktop, text = "Trade " ,style = win_style,shadeable = False, moveable = False) # Creating label label_text = '\n'+buddyName + ' wants to ' + trade + ' ' + quantity + ' units of '+ resource + '\n at $ '+ price message_label = gui.Label(position = threades.resize_pos((5,5),(470.0,180.0),self.win.size),size = threades.resize_pos((460,120),(470.0,180.0),self.win.size), parent = self.win, text = label_text, style = labelStyleCopy) # Creating button style myfont2 = pygame.font.Font("font.ttf", threades.resize_pt(16)) button_style = gui.defaultButtonStyle.copy() button_style['font'] = myfont2 self.button_accept = gui.Button(position = threades.resize_pos((100.0,130.0),(470.0,180.0),size_win), size = threades.resize_pos((100.0,40.0),(470.0,180.0),size_win), parent = self.win, text = " Accept ",style = button_style) self.button_reject = gui.Button(position = threades.resize_pos((300.0,130.0),(470.0,180.0),size_win), size = threades.resize_pos((100.0,40.0),(470.0,180.0),size_win), parent = self.win, text = " Reject ",style = button_style) self.button_accept.onClick = self.checkTrade self.button_reject.onClick = self.closeWin sleep(6) if self.win: self.win.close()
def message_window(): ''' Thread to display the messages''' font_color = (255,214,150) myfont = pygame.font.Font("font.ttf", threades.resize_pt(17)) # Custom gui.Window Style win_style = gui.defaultWindowStyle.copy() win_style['font'] = myfont win_style['bg-color'] = (0,0,0) # Calculating position and size of window from the size of the threades.desktop position_win =threades.resize_pos((745.0,42.0)) size_win =threades.resize_pos((450.0,150.0)) # Creating custom label style for the text to be displayed as a threades.message labelStyleCopy = gui.defaultLabelStyle.copy() labelStyleCopy['wordwrap'] = True labelStyleCopy['autosize'] = False labelStyleCopy['font'] = myfont #labelStyleCopy['font-color'] = font_color while True: (text,color) = threades.message.pop_message() if text: # Creating window win_style['font-color'] = color labelStyleCopy['font-color'] = color win = gui.Window(position = position_win, size = size_win, parent = threades.desktop, text = "Message " ,style = win_style ,closeable = False ,shadeable = False,moveable = False) pygame.draw.rect(win.surf,color,threades.resize_rect((3,3,444,144)),1) #win.surf.set_alpha(160) # Creating label message_label = gui.Label(position = threades.resize_pos((5,50),(450.0,150.0),win.size),size = threades.resize_pos((440,140),(450.0,150.0),win.size), parent = win, text = text, style = labelStyleCopy) sleep(6) win.close() if threades.GAME_EXIT_FLAG: return sleep(1) if threades.GAME_EXIT_FLAG: return sleep(1) if threades.GAME_EXIT_FLAG: return
def update(self): for i in range(len(model.facilities_list)): if not (self.list_num_fac[i] == model.facilities_list[i].get_original_number()): self.update_flag = True if self.update_flag or threades.map_update_flag or threades.total_update_flag: threades.screen.blit(self.map,threades.resize_pos((930,390))) posn = threades.resize_pos((930+int(3200/23.22),390+int(2600/24.80))) threades.screen.blit(load_images.Map_images[6],posn) for i in range(len(model.facilities_list)): for j in range(model.facilities_list[i].get_original_number()): posn = threades.resize_pos((930+int(model.facilities_list_sprites[model.facilities_list[i].get_name()][j].position[0]/23.22),390+int(model.facilities_list_sprites[model.facilities_list[i].get_name()][j].position[1]/24.80))) threades.screen.blit(load_images.Map_images[i],posn) rect_draw = threades.transform_obj.village_boundary_covered() rect_final = threades.resize_rect((930+rect_draw[0]/23.22, 390 + rect_draw[1]/24.80, (rect_draw[2]-rect_draw[0])/23.22, (rect_draw[3]-rect_draw[1])/24.80)) pygame.draw.rect(threades.screen, (47, 47, 255, 180), rect_final, 2) self.update_flag = False
def __init__(self): self.update_flag = True for i in range(6): load_images.Map_images[i] = pygame.transform.scale(load_images.Map_images[i],threades.resize_pos((15,15))) self.map = pygame.image.load(os.path.join('data', 'map.png')).convert() self.map = pygame.transform.scale(self.map,threades.resize_pos((270,210))) self.list_num_fac = [] for i in range(len(model.facilities_list)): self.list_num_fac.append(model.facilities_list[i].get_original_number())
def __init__(self): pygame.sprite.Sprite.__init__(self) mask= pygame.surface.Surface(threades.resize_pos((930,600)),SRCALPHA) mask.fill((0,0,0,0)) self.clock = pygame.time.Clock() self.time = 0 #mask.set_alpha(0) self.alpha = 0 self.image = mask self.rect = self.image.get_rect() self.rect.move(threades.resize_pos((0,0))) self.counter = 0 self.prev_disp = (0,0) self.move_dir = [(-20,-20),(-20,-10),(-20,0),(-20,10),(-20,20),(-10,-20),(-10,-20),(-10,0),(-10,10),(-10,20),(0,-20),(0,-10),(0,0),(0,10),(0,20),(10,-20),(10,-20),(10,0),(10,10),(10,20),(20,-20),(20,-10),(20,0),(20,10),(20,20)] # To close all open windows if gui_buttons.gui_obj.get_child_win_flag(): gui_buttons.gui_obj.close_child_win() gui_buttons.gui_obj.close_win() elif gui_buttons.gui_obj.get_win_flag(): gui_buttons.gui_obj.close_win()
def update(self): for i in range(len(model.facilities_list)): if not (self.list_num_fac[i] == model.facilities_list[i].get_original_number()): self.update_flag = True if self.update_flag or threades.map_update_flag or threades.total_update_flag: threades.screen.blit(self.map, threades.resize_pos((930, 390))) posn = threades.resize_pos( (930 + int(3200 / 33.3), 390 + int(2600 / 28.57))) threades.screen.blit(load_images.Map_images[6], posn) for i in range(len(model.facilities_list)): for j in range(model.facilities_list[i].get_original_number()): posn = threades.resize_pos( (930 + int(load_images.facilities_posn_list[i][j][0] / 33.3), 390 + int(load_images.facilities_posn_list[i][j][1] / 28.57))) threades.screen.blit(load_images.Map_images[i], posn) self.update_flag = False
def update_value(self): ''' Updates the model.resources panel ''' self.money_flag = False for i in range(11): if not (self.value_labels[i].text == str(int(model.resources[i].get_vquantity()))): self.update_flag = True if self.update_flag or threades.panel_update_flag or threades.total_update_flag: pygame.draw.line(threades.screen,self.color_grey,threades.resize_pos((400,645)),threades.resize_pos((400,855)),1) pygame.draw.line(threades.screen,self.color_grey,threades.resize_pos((650,645)),threades.resize_pos((650,855)),1) for i in range(11): if not (self.value_labels[i].text == str(int(model.resources[i].get_vquantity()))): self.value_labels[i].text = str(int(model.resources[i].get_vquantity())) if not (self.money_label.text == model.text_file.money_text[0] +' -: '+str(int(model.money.get_money()))+' '): self.money_flag = True self.money_label.text = model.text_file.money_text[0] +' -: '+str(int(model.money.get_money()))+' ' #print 'no of days is',model.game_controller.get_days() if self.time_flag==True: #self.time_label.text='' #NOTE: Here, I am not adding as if years is not 0 , then only it will be blitted becoz if do like that the things will keep on changing, not a nice view self.time_label.text= model.text_file.time_text[0]+' -: '+model.text_file.time_text[2]+': '+str(model.game_controller.get_years())+' '+model.text_file.time_text[3]+': '+str(model.game_controller.get_months()) +' '+model.text_file.time_text[4]+': '+str(model.game_controller.get_days()) self.time_flag=True #to update the money flag #print 'global_time is',model.game_controller.get_global_time(),'while the time_help_value is',self.time_help_value if (model.game_controller.get_global_time()>((model.game_controller.conversion_factor)+self.time_help_value)): self.time_flag=True self.time_help_value=model.game_controller.get_global_time() self.update_flag = False
def graphics(self): logo = pygame.image.load(os.path.join('data', 'logo.png')).convert() self.ff_logo = pygame.transform.scale(logo, threades.resize_pos((1128, 171))) threades.screen.fill((0, 0, 0)) threades.screen.blit(self.ff_logo, threades.resize_pos((40, 50))) # Font type myfont = pygame.font.Font("font.ttf", threades.resize_pt(17)) #creating new label showing loading of level labelStyleCopy = gui.defaultLabelStyle.copy() labelStyleCopy['border-width'] = 1 labelStyleCopy['wordwrap'] = True labelStyleCopy['autosize'] = False labelStyleCopy['font'] = myfont labelStyleCopy['font-color'] = (0, 200, 0) #creating the label label = gui.Label(position=threades.resize_pos((500, 600)), size=threades.resize_pos((250, 50)), parent=desktop_level, style=labelStyleCopy, text=model.text_file.loading_text[0])
def __init__(self): ''' Constructor ''' global background_image self.chatWinFlag = False #Initialises the chat window self.position = threades.resize_pos((15,10)) self.initial_position = threades.resize_pos((15,10)) self.final_position = threades.resize_pos((15,750)) self.update_win_pos=pygame.Rect(threades.resize_pos((150.0,50.0)),threades.resize_pos((900,800))) self.imageBox = pygame.image.load(os.path.join('storyboards','storyboard1','images','chat images', 'imageBox.png')).convert_alpha() self.chatBox = pygame.image.load(os.path.join('storyboards','storyboard1','images','chat images', 'chatBox.png')).convert_alpha() #list for storing the images loaded in the chatbox self.characterImage={} if model.storyboard_file == 'storyboard1/storyboard.pkl': self.characterImage['KAMAT']=pygame.image.load(os.path.join('storyboards','storyboard1','images','character images', 'kamat.png')).convert_alpha() self.characterImage['SON']=pygame.image.load(os.path.join('storyboards','storyboard1','images','character images', 'son.png')).convert_alpha() self.characterImage['AJMAL']=pygame.image.load(os.path.join('storyboards','storyboard1','images','character images', 'ajmal.png')).convert_alpha() self.characterImage['PANCH']=pygame.image.load(os.path.join('storyboards','storyboard1','images','character images', 'panch.png')).convert_alpha() self.characterImage['PRIEST']=pygame.image.load(os.path.join('storyboards','storyboard1','images','character images', 'priest.png')).convert_alpha() self.characterImage['SUKHDEV']=pygame.image.load(os.path.join('storyboards','storyboard1','images','character images', 'sukhdev.png')).convert_alpha() self.characterImage['FARMER']=pygame.image.load(os.path.join('storyboards','storyboard1','images','character images', 'villager.png')).convert_alpha() else: self.characterImage['TONY PERALTA']=pygame.image.load(os.path.join('storyboards','storyboard2','images','character images', 'tony.png')).convert_alpha() self.characterImage['STEVENSON GORBACHEV']=pygame.image.load(os.path.join('storyboards','storyboard2','images','character images', 'stevenson.png')).convert_alpha() self.characterImage['GILBERT FERNANDEZ']=pygame.image.load(os.path.join('storyboards','storyboard2','images','character images', 'gilbert.png')).convert_alpha() self.characterImage['JOHN TREMBLAY']=pygame.image.load(os.path.join('storyboards','storyboard2','images','character images', 'john.png')).convert_alpha() self.characterImage['RAGNAR STEFANSSON']=pygame.image.load(os.path.join('storyboards','storyboard2','images','character images', 'ragnar.png')).convert_alpha() # changes made while adding skip buttons etc self.size_win =threades.resize_pos((900.0,800.0)) self.myfont = pygame.font.Font("font.ttf", threades.resize_pt(16)) self.button_style=gui.defaultButtonStyle.copy() self.button_style['font']=self.myfont #crating label textsurface #myfont = pygame.font.Font("font.ttf",10) #textColor = (0,0,0) #self.label_text=' ENTER : To show whole chat at once ESC : To skip chat ' #self.label_textsurface=gui.renderText(self.label_text,myfont,True,textColor,(700,20),False,True) #self.label_tempSurface = pygame.transform.scale(self.chatBox,(800,30)) #creating a label for the chat window self.label_text=' ENTER : To show whole chat ESC : To skip chat ' self.myfont2 = pygame.font.Font("font.ttf", threades.resize_pt(20)) self.labelStyleCopy = gui.defaultLabelStyle.copy() self.labelStyleCopy['border-width'] = 1 self.labelStyleCopy['wordwrap'] = True self.labelStyleCopy['autosize'] = False self.labelStyleCopy['font'] = self.myfont2 self.labelStyleCopy['font-color'] = (255,214,150) self.labelStyleCopy['border-color'] = (255,214,150)
def __init__(self): ''' Constructor ''' global background_image self.chatWinFlag = False self.position = threades.resize_pos((15, 10)) self.initial_position = threades.resize_pos((15, 10)) self.final_position = threades.resize_pos((15, 750)) self.update_win_pos = pygame.Rect(threades.resize_pos((150.0, 50.0)), threades.resize_pos((900, 800))) self.imageBox = pygame.image.load(os.path.join( 'art', 'imageBox.png')).convert_alpha() self.chatBox = pygame.image.load(os.path.join( 'art', 'chatBox.png')).convert_alpha() self.characterImage = {} self.characterImage['KAMAT'] = pygame.image.load( os.path.join('art', 'kamat.png')).convert_alpha() self.characterImage['SON'] = pygame.image.load( os.path.join('art', 'son.png')).convert_alpha() self.characterImage['AJMAL'] = pygame.image.load( os.path.join('art', 'ajmal.png')).convert_alpha() self.characterImage['SUKHDEV'] = pygame.image.load( os.path.join('art', 'sukhdev.png')).convert_alpha() self.characterImage['FARMER'] = pygame.image.load( os.path.join('art', 'villager.png')).convert_alpha() # changes made while adding skip buttons etc self.size_win = threades.resize_pos((900.0, 800.0)) #### TODO : This self.myfont is supposed to be replaced by pangofont when the storyboard will be translated, however, right now done like this #### as the characters doesn't appear to be coming completer otherwise, so need to solve the problem by the time we are going to localize #### the storyboard. self.myfont = pygame.font.Font("font.ttf", threades.resize_pt(16)) #self.myfont = pangofont.PangoFont(size=threades.resize_pt(16)) self.button_style = gui.defaultButtonStyle.copy() self.button_style['font'] = self.myfont #crating label textsurface #myfont = pygame.font.Font("font.ttf",10) #textColor = (0,0,0) #self.label_text=' ENTER : To show whole chat at once ESC : To skip chat ' #self.label_textsurface=gui.renderText(self.label_text,myfont,True,textColor,(700,20),False,True) #self.label_tempSurface = pygame.transform.scale(self.chatBox,(800,30)) self.label_text = ' ' + _( 'ENTER : To show whole chat') + ' ' + _( 'ESC : To skip chat') + ' ' self.myfont2 = pangofont.PangoFont(size=threades.resize_pt(25)) self.labelStyleCopy = gui.defaultLabelStyle.copy() self.labelStyleCopy['border-width'] = 1 self.labelStyleCopy['wordwrap'] = True self.labelStyleCopy['autosize'] = False self.labelStyleCopy['font'] = self.myfont2 self.labelStyleCopy['font-color'] = (255, 214, 150) self.labelStyleCopy['border-color'] = (255, 214, 150)
def new_level_stats(self,data_file,graphics_file,level_no=-1): #global total_update_flag global animation_obj threades.pause_update_thread() self.graphics() self.level_no=level_no self.data_file=data_file self.graphics_file=graphics_file self.run=True level_updater=threading.Thread(target=self.level_reinit,args=[]).start() pygame.display.set_caption('FoodForce2') threades.screen.fill((0,0,0)) threades.screen.blit(self.ff_logo,threades.resize_pos((40,50))) desktop_level.update() desktop_level.draw() pygame.display.update() while 1 : for e in gui.setEvents(pygame.event.get()): if e.type == pygame.QUIT: print 'in pygame.quit' safe_exit() if e.type == QUIT: print 'in quit' safe_exit() #if level_updater.is_alive()==False: # self.run=False GREAT THIS IS APPLICABLE ONLY WITH PYTHON 2.6, SO HAVE TO SEARCH SOME OTHER MEANS if self.run==False: break #print 'now reached here\n' self.ff_logo = 0 threades.initialize_facilities(True) threades.set_build_facility_placement_flag() threades.facility_placement_data_obj.clear_placement_data() #threades.current_level = proceduralFlow.storyboard_level threades.total_update_flag = True threades.resume_update_thread()
def new_level_stats(self, data_file, graphics_file, level_no=-1): #global total_update_flag global animation_obj threades.pause_update_thread() self.graphics() self.level_no = level_no self.data_file = data_file self.graphics_file = graphics_file self.run = True level_updater = threading.Thread(target=self.level_reinit, args=[]).start() pygame.display.set_caption('FoodForce2') threades.screen.fill((0, 0, 0)) threades.screen.blit(self.ff_logo, threades.resize_pos((40, 90))) desktop_level.update() desktop_level.draw() pygame.display.update() while 1: for e in gui.setEvents(pygame.event.get()): if e.type == pygame.QUIT: print 'in pygame.quit' #safe_exit() if e.type == QUIT: print 'in quit' #safe_exit() #if level_updater.is_alive()==False: # self.run=False GREAT THIS IS APPLICABLE ONLY WITH PYTHON 2.6, SO HAVE TO SEARCH SOME OTHER MEANS if self.run == False: break self.ff_logo = 0 threades.initialize_facilities(True) threades.set_build_facility_placement_flag() #threades.current_level = proceduralFlow.storyboard_level threades.total_update_flag = True model.POPULATION_FACTOR = 0.5 threades.resume_update_thread()
def new_level_stats(self, data_file, graphics_file, level_no=-1): #global total_update_flag global animation_obj threades.pause_update_thread() self.graphics() self.level_no = level_no self.data_file = data_file self.graphics_file = graphics_file self.run = True level_updater = threading.Thread(target=self.level_reinit, args=[]).start() pygame.display.set_caption('FoodForce2') threades.screen.fill((0, 0, 0)) threades.screen.blit(self.ff_logo, threades.resize_pos((40, 50))) desktop_level.update() desktop_level.draw() pygame.display.update() while 1: for e in gui.setEvents(pygame.event.get()): if e.type == pygame.QUIT: print 'in pygame.quit' safe_exit() if e.type == QUIT: print 'in quit' safe_exit() #if level_updater.is_alive()==False: # self.run=False GREAT THIS IS APPLICABLE ONLY WITH PYTHON 2.6, SO HAVE TO SEARCH SOME OTHER MEANS if self.run == False: break print 'now reached here\n' self.ff_logo = 0 threades.initialize_facilities() threades.total_update_flag = True threades.resume_update_thread()
def main_menu(self,pause_flag = True): ''' Display the starting menu ''' logo = pygame.image.load(os.path.join('data', 'logo.png')).convert() self.ff_logo = pygame.transform.scale(logo,threades.resize_pos((1111,250))) threades.screen.fill((0,0,0)) threades.screen.blit(self.ff_logo,threades.resize_pos((40,50))) # Font type myfont = pygame.font.Font("font.ttf", threades.resize_pt(17)) # Creating new button style buttonsurf = pygame.image.load(os.path.join('art','button_green.png')).convert_alpha() self.button_style = gui.createButtonStyle(myfont,(0,0,0), buttonsurf,4,1,4,4,1,4,4,1,4,4,1,4) self.pause_flag = pause_flag if self.pause_flag: self.start_button = gui.Button(position = threades.resize_pos((500,500)), size = threades.resize_pos((200,30)), parent = desktop2, text = "Start New Game",style = self.button_style) self.start_button.onClick = self.startup_text else: self.resume_button = gui.Button(position = threades.resize_pos((500,500)), size = threades.resize_pos((200,30)), parent = desktop2, text = "Resume Game",style = self.button_style) self.resume_button.onClick = self.resume #self.resume_button = gui.Button(position = threades.resize_pos((500,550)), size = threades.resize_pos((200,30)), parent = threades.desktop, text = "Resume Game",style = self.button_style) self.controls_button = gui.Button(position = threades.resize_pos((500,600)), size = threades.resize_pos((200,30)), parent = desktop2, text = "Controls",style = self.button_style) self.exit_button = gui.Button(position = threades.resize_pos((500,650)), size = threades.resize_pos((200,30)), parent = desktop2, text = "Exit",style = self.button_style) self.instructions_button = gui.Button(position = threades.resize_pos((500,550)), size = threades.resize_pos((200,30)), parent = desktop2, text = "Guide",style = self.button_style) self.about_us_button = gui.Button(position = threades.resize_pos((1000,20)), size = threades.resize_pos((150,30)), parent = desktop2, text = "About Us",style = self.button_style) #self.resume_button.onClick = self.resume self.controls_button.onClick = self.controls self.exit_button.onClick = safe_exit self.instructions_button.onClick = self.instructionsWindow self.about_us_button.onClick = self.aboutUsWindow self.run = True
def update_value(self): ''' Updates the Manpower panel ''' list_values = (model.ppl.get_total_population(),model.ppl.get_no_of_ppl_sheltered(),model.ppl.get_no_of_ppl_educated(),model.ppl.get_no_of_ppl_healthy(),model.ppl.get_no_of_ppl_fed(),model.ppl.get_total_no_of_ppl_emp()) for i in range(6): if not (self.value_labels[i].text == str(int(list_values[i]))): self.update_flag = True if self.update_flag or threades.panel_update_flag or threades.total_update_flag: pygame.draw.line(threades.screen,self.color_grey,threades.resize_pos((900,645)),threades.resize_pos((900,855)),1) pygame.draw.rect(threades.screen,self.color_grey,threades.resize_rect((0,855,300,45)),2) pygame.draw.rect(threades.screen,self.color_grey,threades.resize_rect((300,855,300,45)),2) pygame.draw.rect(threades.screen,self.color_grey,threades.resize_rect((600,855,300,45)),2) for i in range(6): if not (self.value_labels[i].text == str(int(list_values[i]))): self.value_labels[i].text = str(int(list_values[i])) self.update_flag = False
def update_value(self): ''' Updates the values of all the indicators ''' for i in range(5): self.bar_dict[i].update_value(model.indicators_list[i].get_value()) if not (self.value_labels[i].text == str(int(model.indicators_list[i].get_value()))+'%'): self.update_flag = True #print 'update flag is',self.update_flag,'panel flag is',threades.panel_update_flag,'total is',threades.total_update_flag if self.update_flag or threades.panel_update_flag or threades.total_update_flag: pygame.draw.line(threades.screen,self.color_grey,threades.resize_pos((900,645)),threades.resize_pos((900,900)),1) for i in range(5): self.bar_dict[i].update_value(model.indicators_list[i].get_value()) if not (self.value_labels[i].text == str(int(model.indicators_list[i].get_value()))+'%'): self.value_labels[i].text = str(int(model.indicators_list[i].get_value()))+'%' self.update_flag = False
def __init__(self): ''' Constructor ''' global background_image self.chatWinFlag = False self.position = threades.resize_pos((15,10)) self.initial_position = threades.resize_pos((15,10)) self.final_position = threades.resize_pos((15,750)) self.update_win_pos=pygame.Rect(threades.resize_pos((150.0,50.0)),threades.resize_pos((900,800))) self.imageBox = pygame.image.load(os.path.join('art', 'imageBox.png')).convert_alpha() self.chatBox = pygame.image.load(os.path.join('art', 'chatBox.png')).convert_alpha() self.characterImage={} self.characterImage['KAMAT']=pygame.image.load(os.path.join('art', 'kamat.png')).convert_alpha() self.characterImage['SON']=pygame.image.load(os.path.join('art', 'son.png')).convert_alpha() self.characterImage['AJMAL']=pygame.image.load(os.path.join('art', 'ajmal.png')).convert_alpha() self.characterImage['SUKHDEV']=pygame.image.load(os.path.join('art', 'sukhdev.png')).convert_alpha() self.characterImage['FARMER']=pygame.image.load(os.path.join('art', 'villager.png')).convert_alpha() # changes made while adding skip buttons etc self.size_win =threades.resize_pos((900.0,800.0)) self.myfont = pygame.font.Font("font.ttf", threades.resize_pt(16)) self.button_style=gui.defaultButtonStyle.copy() self.button_style['font']=self.myfont #crating label textsurface #myfont = pygame.font.Font("font.ttf",10) #textColor = (0,0,0) #self.label_text=' ENTER : To show whole chat at once ESC : To skip chat ' #self.label_textsurface=gui.renderText(self.label_text,myfont,True,textColor,(700,20),False,True) #self.label_tempSurface = pygame.transform.scale(self.chatBox,(800,30)) self.label_text=' ENTER : To show whole chat ESC : To skip chat ' self.myfont2 = pygame.font.Font("font.ttf", threades.resize_pt(20)) self.labelStyleCopy = gui.defaultLabelStyle.copy() self.labelStyleCopy['border-width'] = 1 self.labelStyleCopy['wordwrap'] = True self.labelStyleCopy['autosize'] = False self.labelStyleCopy['font'] = self.myfont2 self.labelStyleCopy['font-color'] = (255,214,150) self.labelStyleCopy['border-color'] = (255,214,150)
def __init__(self): ''' Draws the model.resources panel on the surface ''' self.update_flag = True self.money_flag = True self.time_flag = False self.time_help_value=0 myfont1 = pygame.font.Font("font.ttf", threades.resize_pt(25)) # For main heading myfont2 = pygame.font.Font("font.ttf", threades.resize_pt(20)) # For model.resources name and their value myfont3 = pygame.font.Font("font.ttf", threades.resize_pt(16)) myfont4 = pygame.font.Font("font.ttf", threades.resize_pt(18)) # For the display of model.money # Creating a custom label style self.labelstyle1 = gui.defaultLabelStyle.copy() self.labelstyle1['border-width'] = 1 self.labelstyle1['wordwrap'] = True self.labelstyle1['autosize'] = False self.labelstyle1['font'] = myfont1 self.labelstyle1['font-color'] = self.font_color self.labelstyle1['border-color'] = self.color_grey self.name_labels = [] # Drawing main Resources rectangle label = gui.Label(position = threades.resize_pos((400,600)),size = threades.resize_pos((500,45)), parent = threades.desktop, text = " "+model.text_file.resources_text[0], style = self.labelstyle1) self.name_labels.append(label) # Creating second label style self.labelstyle2 = gui.defaultLabelStyle.copy() self.labelstyle2['border-width'] = 0 self.labelstyle2['wordwrap'] = True self.labelstyle2['autosize'] = False self.labelstyle2['font'] = myfont2 self.labelstyle2['font-color'] = self.font_color self.labelstyle3 = gui.defaultLabelStyle.copy() self.labelstyle3['border-width'] = 0 self.labelstyle3['wordwrap'] = False self.labelstyle3['autosize'] = True self.labelstyle3['font'] = myfont3 self.labelstyle3['font-color'] = self.font_color self.labelstyle4 = gui.defaultLabelStyle.copy() self.labelstyle4['border-width'] = 0 self.labelstyle4['wordwrap'] = False self.labelstyle4['autosize'] = True self.labelstyle4['font'] = myfont4 self.labelstyle4['font-color'] = (160,160,160) self.money_label = gui.Label(position = threades.resize_pos((820,10)), parent = threades.desktop, text = model.text_file.money_text[0]+' -: '+str(int(model.money.get_money()))+' ', style = self.labelstyle4) self.name_labels.append(self.money_label) self.time_label= gui.Label(position = threades.resize_pos((270,10)), parent = threades.desktop, text = model.text_file.time_text[0]+' -: '+model.text_file.time_text[1]+' ', style = self.labelstyle4) self.name_labels.append(self.time_label) self.value_labels = [] # Drawing general model.resources list for i in range(5): label = gui.Label(position = threades.resize_pos((400,645+35*i)),size = threades.resize_pos((200,35)), parent = threades.desktop, text = model.text_file.list_gen_res[i], style = self.labelstyle2) self.name_labels.append(label) label = gui.Label(position = threades.resize_pos((605,649+35*i)), parent = threades.desktop, text = str(int(model.resources[i].get_vquantity())), style = self.labelstyle3) self.value_labels.append(label) # Drawing food model.resources list for i in range(6): label = gui.Label(position = threades.resize_pos((650,645+35*i)),size = threades.resize_pos((200,35)), parent = threades.desktop, text = model.text_file.list_food_res[i], style = self.labelstyle2) self.name_labels.append(label) label = gui.Label(position = threades.resize_pos((855,649+35*i)), parent = threades.desktop, text = str(int(model.resources[i+5].get_vquantity())), style = self.labelstyle3) self.value_labels.append(label)
def showCredits(self): global GAME_END_FLAG self.brown_color = (255,214,150) self.green_color = (0,250,0) self.black_color = (0,0,0) myfont1 = pygame.font.Font("font.ttf", threades.resize_pt(40)) # Custom gui.Window Style win_style = gui.defaultWindowStyle.copy() win_style['font'] = myfont1 win_style['font-color'] = self.brown_color win_style['bg-color'] = (0,0,0) win_style['border-color'] = self.brown_color win_style['border-width'] = 2 st_desktop = gui.Desktop() clock = pygame.time.Clock() clock.tick(30) # Calculating position and size of window from the size of the threades.desktop position_win =threades.resize_pos((150.0,100.0)) size_win =threades.resize_pos((900.0,500.0)) # Creating window self.win = gui.Window(position = position_win, size = size_win, parent = st_desktop, text = " Credits" , style = win_style, shadeable = False, closeable = False,moveable = False) #self.win.onClose = lambda button: self.main_menu(self.pause_flag) #self.win.surf.set_alpha(140) This seems to be redundant as translucency doesnt seems to work properly myfont2 = pygame.font.Font("font.ttf", threades.resize_pt(20)) labelStyleCopy = gui.defaultLabelStyle.copy() labelStyleCopy['border-width'] = 0 labelStyleCopy['wordwrap'] = True labelStyleCopy['autosize'] = False labelStyleCopy['font'] = myfont2 labelStyleCopy['font-color'] = self.brown_color labelStyleCopy['border-color'] = self.black_color update_rect = pygame.Rect(threades.resize_rect((150,100,900,500))) self.storyboardwin_run = True #logo = pygame.image.load(os.path.join('data', 'logo.png')).convert() #ff_logo = pygame.transform.scale(logo,threades.resize_pos((1111,250))) text = model.text_file.credits_text #self.instructions_counter = 0 label = gui.Label(position = threades.resize_pos((100.0,100.0),(900.0,500.0),self.win.size),size = threades.resize_pos((700.0,380.0),(900.0,500.0),self.win.size), parent = self.win, text = text, style = labelStyleCopy) gl_time = 0 st_desktop.update() st_desktop.draw() pygame.display.update([update_rect]) while self.storyboardwin_run: pygame.display.set_caption('FoodForce2') for e in gui.setEvents(pygame.event.get()): if e.type == MOUSEBUTTONDOWN: if e.button == 1: self.storyboardwin_run = False if e.type == KEYDOWN: if e.key == 27: # For escape key self.storyboardwin_run = False gl_time += clock.tick(30) if gl_time >= 17000: self.storyboardwin_run = False self.win.close() GAME_END_FLAG = True
def showWFPWindow(self,text): self.brown_color = (255,214,150) self.green_color = (0,250,0) self.black_color = (0,0,0) myfont1 = pygame.font.Font("font.ttf", threades.resize_pt(40)) # Custom gui.Window Style win_style = gui.defaultWindowStyle.copy() win_style['font'] = myfont1 win_style['font-color'] = self.brown_color win_style['bg-color'] = (0,0,0) win_style['border-color'] = self.brown_color win_style['border-width'] = 2 st_desktop = gui.Desktop() clock = pygame.time.Clock() clock.tick(30) # Calculating position and size of window from the size of the threades.desktop position_win =threades.resize_pos((150.0,100.0)) size_win =threades.resize_pos((700.0,600.0)) # Creating window self.win = gui.Window(position = position_win, size = size_win, parent = st_desktop, text = " Reward" , style = win_style, shadeable = False, closeable = False,moveable = False) #self.win.onClose = lambda button: self.main_menu(self.pause_flag) #self.win.surf.set_alpha(140) This seems to be redundant as translucency doesnt seems to work properly myfont2 = pygame.font.Font("font.ttf", threades.resize_pt(20)) labelStyleCopy = gui.defaultLabelStyle.copy() labelStyleCopy['border-width'] = 0 labelStyleCopy['wordwrap'] = True labelStyleCopy['autosize'] = False labelStyleCopy['font'] = myfont2 labelStyleCopy['font-color'] = self.brown_color labelStyleCopy['border-color'] = self.black_color self.storyboardwin_run = True logo = pygame.image.load(os.path.join('data', 'WFPLOGO.png')).convert() ff_logo = pygame.transform.scale(logo,threades.resize_pos((500,500))) position_blit = threades.resize_pos((100,100)) self.win.surf.blit(ff_logo,position_blit) update_rect = pygame.Rect(threades.resize_rect((150,100,700,600))) #self.instructions_counter = 0 label = gui.Label(position = threades.resize_pos((50.0,100.0),(700.0,600.0),self.win.size),size = threades.resize_pos((600.0,440.0),(700.0,600.0),self.win.size), parent = self.win, text = text, style = labelStyleCopy) gl_time = 0 while self.storyboardwin_run: pygame.display.set_caption('FoodForce2') for e in gui.setEvents(pygame.event.get()): if e.type == KEYDOWN: if e.key == 27: # For escape key self.storyboardwin_run = False gl_time += clock.tick(30) if gl_time >= 17000: self.storyboardwin_run = False st_desktop.update() st_desktop.draw() pygame.display.update([update_rect]) self.win.close() event = game_events.Event(type = game_events.ACTIONCOMPLETEEVENT, facility_name = '', res_name = '' , res_quantity = 0) game_events.EventQueue.add(event)
def __init__(self): ''' Draws the model.resources panel on the surface ''' self.update_flag = True self.money_flag = True self.time_flag = False self.time_help_value = 0 myfont1 = pygame.font.Font("font.ttf", threades.resize_pt(25)) # For main heading myfont2 = pygame.font.Font( "font.ttf", threades.resize_pt(20)) # For model.resources name and their value myfont3 = pygame.font.Font("font.ttf", threades.resize_pt(16)) myfont4 = pygame.font.Font( "font.ttf", threades.resize_pt(18)) # For the display of model.money # Creating a custom label style self.labelstyle1 = gui.defaultLabelStyle.copy() self.labelstyle1['border-width'] = 1 self.labelstyle1['wordwrap'] = True self.labelstyle1['autosize'] = False self.labelstyle1['font'] = myfont1 self.labelstyle1['font-color'] = self.font_color self.labelstyle1['border-color'] = self.color_grey self.name_labels = [] # Drawing main Resources rectangle label = gui.Label(position=threades.resize_pos((400, 600)), size=threades.resize_pos((500, 45)), parent=threades.desktop, text=" " + model.text_file.resources_text[0], style=self.labelstyle1) self.name_labels.append(label) # Creating second label style self.labelstyle2 = gui.defaultLabelStyle.copy() self.labelstyle2['border-width'] = 0 self.labelstyle2['wordwrap'] = True self.labelstyle2['autosize'] = False self.labelstyle2['font'] = myfont2 self.labelstyle2['font-color'] = self.font_color self.labelstyle3 = gui.defaultLabelStyle.copy() self.labelstyle3['border-width'] = 0 self.labelstyle3['wordwrap'] = False self.labelstyle3['autosize'] = True self.labelstyle3['font'] = myfont3 self.labelstyle3['font-color'] = self.font_color self.labelstyle4 = gui.defaultLabelStyle.copy() self.labelstyle4['border-width'] = 0 self.labelstyle4['wordwrap'] = False self.labelstyle4['autosize'] = True self.labelstyle4['font'] = myfont4 self.labelstyle4['font-color'] = (160, 160, 160) self.money_label = gui.Label( position=threades.resize_pos((820, 10)), parent=threades.desktop, text=model.text_file.money_text[0] + ' -: ' + str(int(model.money.get_money())) + ' ', style=self.labelstyle4) self.name_labels.append(self.money_label) self.time_label = gui.Label(position=threades.resize_pos((270, 10)), parent=threades.desktop, text=model.text_file.time_text[0] + ' -: ' + model.text_file.time_text[1] + ' ', style=self.labelstyle4) self.name_labels.append(self.time_label) self.value_labels = [] # Drawing general model.resources list for i in range(5): label = gui.Label(position=threades.resize_pos( (400, 645 + 35 * i)), size=threades.resize_pos((200, 35)), parent=threades.desktop, text=model.text_file.list_gen_res[i], style=self.labelstyle2) self.name_labels.append(label) label = gui.Label( position=threades.resize_pos((605, 649 + 35 * i)), parent=threades.desktop, text=str(int(model.resources[i].get_vquantity())), style=self.labelstyle3) self.value_labels.append(label) # Drawing food model.resources list for i in range(6): label = gui.Label(position=threades.resize_pos( (650, 645 + 35 * i)), size=threades.resize_pos((200, 35)), parent=threades.desktop, text=model.text_file.list_food_res[i], style=self.labelstyle2) self.name_labels.append(label) label = gui.Label(position=threades.resize_pos( (855, 649 + 35 * i)), parent=threades.desktop, text=str( int(model.resources[i + 5].get_vquantity())), style=self.labelstyle3) self.value_labels.append(label)
def controls(self,button = None): """"show controllers """ self.remove_buttons() self.lightgreen_color = (0,100,0) self.green_color = (0,150,0) self.black_color = (0,0,0) myfont1 = pygame.font.Font("font.ttf", threades.resize_pt(40)) # Custom gui.Window Style win_style = gui.defaultWindowStyle.copy() win_style['font'] = myfont1 win_style['font-color'] = self.green_color win_style['bg-color'] = (0,0,0) win_style['border-color'] = (0,150,0) # Calculating position and size of window from the size of the threades.desktop position_win =threades.resize_pos((150.0,270.0)) size_win =threades.resize_pos((900.0,600.0)) # Creating window self.win = gui.Window(position = position_win, size = size_win, parent = desktop2, text = " Controls " , style = win_style, shadeable = False, closeable = False) self.win.onClose = lambda button: self.main_menu(self.pause_flag) self.win.surf.set_alpha(140) control_text = """\n\n Setup Facility : s \n\n Upgrade Facility : u \n\n Buy/Sell : b \n\n Scroll threades.screen up : up arrow \n\n Scroll threades.screen down : down arrow \n\n Scroll threades.screen left : left arrow \n\n Scroll threades.screen right : right arrow """ myfont2 = pygame.font.Font("font.ttf", threades.resize_pt(25)) labelStyleCopy = gui.defaultLabelStyle.copy() labelStyleCopy['border-width'] = 1 labelStyleCopy['wordwrap'] = True labelStyleCopy['autosize'] = False labelStyleCopy['font'] = myfont2 labelStyleCopy['font-color'] = self.lightgreen_color labelStyleCopy['border-color'] = self.black_color self.message_label = gui.Label(position = threades.resize_pos((80,80),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "Setup Facility ", style = labelStyleCopy) self.message_label = gui.Label(position = threades.resize_pos((80,130),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "Upgrade Facility ", style = labelStyleCopy) self.message_label = gui.Label(position = threades.resize_pos((80,180),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "Buy/Sell ", style = labelStyleCopy) self.message_label = gui.Label(position = threades.resize_pos((80,230),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "Scroll Screen up ", style = labelStyleCopy) self.message_label = gui.Label(position = threades.resize_pos((80,280),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "Scroll Screen down", style = labelStyleCopy) self.message_label = gui.Label(position = threades.resize_pos((80,330),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "Scroll Screen left ", style = labelStyleCopy) self.message_label = gui.Label(position = threades.resize_pos((80,380),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "Scroll Screen right ", style = labelStyleCopy) self.message_label = gui.Label(position = threades.resize_pos((80,430),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "Focus ", style = labelStyleCopy) self.message_label = gui.Label(position = threades.resize_pos((80,480),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "De Focus ", style = labelStyleCopy) self.message_label = gui.Label(position = threades.resize_pos((330,80),(600.0,600.0),self.win.size),size = threades.resize_pos((10,70),(600.0,600.0),self.win.size), parent = self.win, text = ": ", style = labelStyleCopy) self.message_label = gui.Label(position = threades.resize_pos((330,130),(600.0,600.0),self.win.size),size = threades.resize_pos((10,70),(600.0,600.0),self.win.size), parent = self.win, text = ": ", style = labelStyleCopy) self.message_label = gui.Label(position = threades.resize_pos((330,180),(600.0,600.0),self.win.size),size = threades.resize_pos((10,70),(600.0,600.0),self.win.size), parent = self.win, text = ": ", style = labelStyleCopy) self.message_label = gui.Label(position = threades.resize_pos((330,230),(600.0,600.0),self.win.size),size = threades.resize_pos((10,70),(600.0,600.0),self.win.size), parent = self.win, text = ": ", style = labelStyleCopy) self.message_label = gui.Label(position = threades.resize_pos((330,280),(600.0,600.0),self.win.size),size = threades.resize_pos((10,70),(600.0,600.0),self.win.size), parent = self.win, text = ": ", style = labelStyleCopy) self.message_label = gui.Label(position = threades.resize_pos((330,330),(600.0,600.0),self.win.size),size = threades.resize_pos((10,70),(600.0,600.0),self.win.size), parent = self.win, text = ": ", style = labelStyleCopy) self.message_label = gui.Label(position = threades.resize_pos((330,380),(600.0,600.0),self.win.size),size = threades.resize_pos((10,70),(600.0,600.0),self.win.size), parent = self.win, text = ": ", style = labelStyleCopy) self.message_label = gui.Label(position = threades.resize_pos((330,430),(600.0,600.0),self.win.size),size = threades.resize_pos((10,70),(600.0,600.0),self.win.size), parent = self.win, text = ": ", style = labelStyleCopy) self.message_label = gui.Label(position = threades.resize_pos((330,480),(600.0,600.0),self.win.size),size = threades.resize_pos((10,70),(600.0,600.0),self.win.size), parent = self.win, text = ": ", style = labelStyleCopy) self.message_label = gui.Label(position = threades.resize_pos((350,80),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "s ", style = labelStyleCopy) self.message_label = gui.Label(position = threades.resize_pos((350,130),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "u ", style = labelStyleCopy) self.message_label = gui.Label(position = threades.resize_pos((350,180),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "b ", style = labelStyleCopy) self.message_label = gui.Label(position = threades.resize_pos((350,230),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "up arrow ", style = labelStyleCopy) self.message_label = gui.Label(position = threades.resize_pos((350,280),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "down arrow ", style = labelStyleCopy) self.message_label = gui.Label(position = threades.resize_pos((350,330),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "left arrrow ", style = labelStyleCopy) self.message_label = gui.Label(position = threades.resize_pos((350,380),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "right arrow ", style = labelStyleCopy) self.message_label = gui.Label(position = threades.resize_pos((350,430),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "f ", style = labelStyleCopy) self.message_label = gui.Label(position = threades.resize_pos((350,480),(600.0,600.0),self.win.size),size = threades.resize_pos((240,70),(600.0,600.0),self.win.size), parent = self.win, text = "d ", style = labelStyleCopy) self.win.surf.set_alpha(255) self.ok_button = gui.Button(position = threades.resize_pos((480,550),(600.0,600.0),self.win.size), size = threades.resize_pos((80,30),(600.0,600.0),self.win.size), parent = self.win, text = " OK ",style = self.button_style) self.ok_button.onClick = self.close_win self.controls_run = True logo = pygame.image.load(os.path.join('data', 'logo.png')).convert() ff_logo = pygame.transform.scale(logo,threades.resize_pos((1111,250))) while self.controls_run: pygame.display.set_caption('FoodForce2') threades.screen.fill((0,0,0)) threades.screen.blit(ff_logo,threades.resize_pos((40,50))) for e in gui.setEvents(pygame.event.get()): if e.type == KEYDOWN: if e.key == 27: # For escape key self.controls_run = False self.win.close() if e.type==mesh.CONNECT : game_sharing.sharing_handler(e.type,None,'') #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,None,'']).start() elif e.type==mesh.PARTICIPANT_ADD or e.type==mesh.PARTICIPANT_REMOVE : game_sharing.sharing_handler(e.type,e.handle,'') #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,e.handle,'']).start() elif e.type==mesh.MESSAGE_MULTI or e.type==mesh.MESSAGE_UNI : game_sharing.sharing_handler(e.type,e.handle,e.content) #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,e.handle,e.content]).start() desktop2.update() desktop2.draw() pygame.display.update()
def __init__(self): ''' Draws the indicator panel on the surface ''' self.update_flag = True self.name_labels = [] myfont1 = pygame.font.Font("font.ttf", threades.resize_pt(25)) # For main heading myfont2 = pygame.font.Font( "font.ttf", threades.resize_pt(20)) # For indicators name myfont3 = pygame.font.Font("font.ttf", threades.resize_pt(16)) # Creating a custom label style self.labelstyle1 = gui.defaultLabelStyle.copy() self.labelstyle1['border-width'] = 1 self.labelstyle1['wordwrap'] = True self.labelstyle1['autosize'] = False self.labelstyle1['font'] = myfont1 self.labelstyle1['font-color'] = self.font_color self.labelstyle1['border-color'] = self.color_grey # Drawing main Indicator label label = gui.Label(position=threades.resize_pos((900, 600)), size=threades.resize_pos((300, 45)), parent=threades.desktop, text=" " + model.text_file.indicators_text[0], style=self.labelstyle1) self.name_labels.append(label) #print " deawing indicator panel" # Creating second custom label self.labelstyle2 = gui.defaultLabelStyle.copy() self.labelstyle2['border-width'] = 0 self.labelstyle2['wordwrap'] = True self.labelstyle2['autosize'] = False self.labelstyle2['font'] = myfont2 self.labelstyle2['font-color'] = self.font_color self.labelstyle2['border-color'] = self.color_grey # Drawing all the indicators # Creating second custom label self.labelstyle3 = gui.defaultLabelStyle.copy() self.labelstyle3['border-width'] = 0 self.labelstyle3['wordwrap'] = False self.labelstyle3['autosize'] = True self.labelstyle3['font'] = myfont3 self.labelstyle3['font-color'] = self.font_color self.labelstyle3['border-color'] = self.color_grey # Empty Dictionary for bar self.bar_dict = [] name_label_size = threades.resize_pos((300, 25)) self.value_labels = [] for i in range(5): label = gui.Label(position=threades.resize_pos( (900, 650 + 50 * i)), size=name_label_size, parent=threades.desktop, text=model.text_file.ind_namelist[i], style=self.labelstyle2) self.name_labels.append(label) self.bar_dict.append(bar((902, 677 + 50 * i))) label = gui.Label(position=threades.resize_pos( (1160, 677 + 50 * i)), parent=threades.desktop, text=str(0), style=self.labelstyle3) self.value_labels.append(label)
def aboutUsWindow(self,button = None): ''' Displays the credits ''' self.remove_buttons() self.lightgreen_color = (0,100,0) self.green_color = (0,150,0) self.black_color = (0,0,0) myfont1 = pygame.font.Font("font.ttf", threades.resize_pt(40)) # Custom gui.Window Style win_style = gui.defaultWindowStyle.copy() win_style['font'] = myfont1 win_style['font-color'] = self.green_color win_style['bg-color'] = (0,0,0) win_style['border-color'] = (0,150,0) # Calculating position and size of window from the size of the threades.desktop position_win =threades.resize_pos((150.0,270.0)) size_win =threades.resize_pos((900.0,600.0)) # Creating window self.win = gui.Window(position = position_win, size = size_win, parent = desktop2, text = " About Us " , style = win_style, shadeable = False, closeable = False,moveable = False) self.win.onClose = lambda button: self.main_menu(self.pause_flag) #self.win.surf.set_alpha(140) This seems to be redundant as translucency doesnt seems to work properly self.next_button = gui.Button(position = threades.resize_pos((500,650)), size = threades.resize_pos((200,30)), parent = self.win, text = "Next ",style = self.button_style) myfont2 = pygame.font.Font("font.ttf", threades.resize_pt(20)) labelStyleCopy = gui.defaultLabelStyle.copy() labelStyleCopy['border-width'] = 1 labelStyleCopy['wordwrap'] = True labelStyleCopy['autosize'] = False labelStyleCopy['font'] = myfont2 labelStyleCopy['font-color'] = (0,200,0) labelStyleCopy['border-color'] = self.black_color self.close_button = gui.Button(position = threades.resize_pos((500,550),(900.0,600.0),self.win.size), size = threades.resize_pos((80,30),(900.0,600.0),self.win.size), parent = self.win, text = " Close ",style = self.button_style) self.close_button.onClick = self.close_win self.about_us_run = True logo = pygame.image.load(os.path.join('data', 'logo.png')).convert() ff_logo = pygame.transform.scale(logo,threades.resize_pos((1111,250))) #self.instructions_counter = 0 label = gui.Label(position = threades.resize_pos((10.0,100.0),(900.0,600.0),self.win.size),size = threades.resize_pos((880.0,440.0),(900.0,600.0),self.win.size), parent = self.win, text = '', style = labelStyleCopy) while self.about_us_run: pygame.display.set_caption('FoodForce2') threades.screen.fill((0,0,0)) threades.screen.blit(ff_logo,threades.resize_pos((40,50))) label.text = texts.about_us_text for e in gui.setEvents(pygame.event.get()): if e.type == KEYDOWN: if e.key == 27: # For escape key self.about_us_run = False self.win.close() if e.type==mesh.CONNECT : game_sharing.sharing_handler(e.type,None,'') #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,None,'']).start() elif e.type==mesh.PARTICIPANT_ADD or e.type==mesh.PARTICIPANT_REMOVE : game_sharing.sharing_handler(e.type,e.handle,'') #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,e.handle,'']).start() elif e.type==mesh.MESSAGE_MULTI or e.type==mesh.MESSAGE_UNI : game_sharing.sharing_handler(e.type,e.handle,e.content) #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,e.handle,e.content]).start() desktop2.update() desktop2.draw() pygame.display.update()
def __init__(self): ''' Draws the indicator panel on the surface ''' self.update_flag = True myfont1 = pangofont.PangoFont( size=threades.resize_pt(30)) # For main heading myfont2 = pangofont.PangoFont( size=threades.resize_pt(25)) # For indicators name myfont3 = pangofont.PangoFont(size=threades.resize_pt(16), bold=True) # Creating a custom label style self.labelstyle1 = gui.defaultLabelStyle.copy() self.labelstyle1['border-width'] = 1 self.labelstyle1['wordwrap'] = True self.labelstyle1['autosize'] = False self.labelstyle1['font'] = myfont1 self.labelstyle1['font-color'] = self.font_color self.labelstyle1['border-color'] = self.color_grey # Drawing main Indicator label label = gui.Label(position=threades.resize_pos((900, 600)), size=threades.resize_pos((300, 45)), parent=threades.desktop, text=" " + _("Indicators"), style=self.labelstyle1) #print " deawing indicator panel" # Creating second custom label self.labelstyle2 = gui.defaultLabelStyle.copy() self.labelstyle2['border-width'] = 0 self.labelstyle2['wordwrap'] = True self.labelstyle2['autosize'] = False self.labelstyle2['font'] = myfont2 self.labelstyle2['font-color'] = self.font_color self.labelstyle2['border-color'] = self.color_grey # Drawing all the indicators ind_namelist = (_(' Housing'), _(' Nutrition'), _(' Health'), _(' Education'), _(' Training')) # Creating second custom label self.labelstyle3 = gui.defaultLabelStyle.copy() self.labelstyle3['border-width'] = 0 self.labelstyle3['wordwrap'] = False self.labelstyle3['autosize'] = True self.labelstyle3['font'] = myfont3 self.labelstyle3['font-color'] = self.font_color self.labelstyle3['border-color'] = self.color_grey # Empty Dictionary for bar self.bar_dict = [] name_label_size = threades.resize_pos((300, 25)) self.value_labels = [] for i in range(5): label = gui.Label(position=threades.resize_pos( (900, 650 + 50 * i)), size=name_label_size, parent=threades.desktop, text=ind_namelist[i], style=self.labelstyle2) self.bar_dict.append(bar((902, 677 + 50 * i))) label = gui.Label(position=threades.resize_pos( (1160, 677 + 50 * i)), parent=threades.desktop, text=str(0), style=self.labelstyle3) self.value_labels.append(label)
def __init__(self): ''' Draws the model.resources panel on the surface ''' self.update_flag = True self.money_flag = True self.time_flag = False self.time_help_value = 0 myfont1 = pangofont.PangoFont( size=threades.resize_pt(30)) # For main heading myfont2 = pangofont.PangoFont(size=threades.resize_pt( 25)) # For model.resources name and their value myfont3 = pangofont.PangoFont(size=threades.resize_pt(16)) myfont4 = pangofont.PangoFont( size=threades.resize_pt(18)) # For the display of model.money # Creating a custom label style self.labelstyle1 = gui.defaultLabelStyle.copy() self.labelstyle1['border-width'] = 1 self.labelstyle1['wordwrap'] = True self.labelstyle1['autosize'] = False self.labelstyle1['font'] = myfont1 self.labelstyle1['font-color'] = self.font_color self.labelstyle1['border-color'] = self.color_grey # Drawing main Resources rectangle label = gui.Label(position=threades.resize_pos((400, 600)), size=threades.resize_pos((500, 45)), parent=threades.desktop, text=" " + _("Resources"), style=self.labelstyle1) # Creating second label style self.labelstyle2 = gui.defaultLabelStyle.copy() self.labelstyle2['border-width'] = 0 self.labelstyle2['wordwrap'] = True self.labelstyle2['autosize'] = False self.labelstyle2['font'] = myfont2 self.labelstyle2['font-color'] = self.font_color self.labelstyle3 = gui.defaultLabelStyle.copy() self.labelstyle3['border-width'] = 0 self.labelstyle3['wordwrap'] = False self.labelstyle3['autosize'] = True self.labelstyle3['font'] = myfont3 self.labelstyle3['font-color'] = self.font_color self.labelstyle4 = gui.defaultLabelStyle.copy() self.labelstyle4['border-width'] = 0 self.labelstyle4['wordwrap'] = False self.labelstyle4['autosize'] = True self.labelstyle4['font'] = myfont4 self.labelstyle4['font-color'] = (160, 160, 160) self.money_label = gui.Label(position=threades.resize_pos((850, 10)), parent=threades.desktop, text=_('Money -:') + ' ' + str(int(model.money.get_money())) + ' ', style=self.labelstyle4) self.time_label = gui.Label(position=threades.resize_pos((300, 10)), parent=threades.desktop, text=_('Time Elapsed -:') + ' ' + _('Level Just Started') + ' ', style=self.labelstyle4) self.value_labels = [] # Drawing general model.resources list list_gen_res = (_(' Water'), _(' Building Materials'), _(' Tools'), _(' Medicines'), _(' Books')) for i in range(5): label = gui.Label(position=threades.resize_pos( (400, 645 + 35 * i)), size=threades.resize_pos((200, 35)), parent=threades.desktop, text=list_gen_res[i], style=self.labelstyle2) label = gui.Label( position=threades.resize_pos((605, 649 + 35 * i)), parent=threades.desktop, text=str(int(model.resources[i].get_vquantity())), style=self.labelstyle3) self.value_labels.append(label) # Drawing food model.resources list list_food_res = (_(' Rice'), _(' Fruit & Vegatables'), _(' Beans'), _(' Sugar'), _(' Salt'), _(' Oil')) for i in range(6): label = gui.Label(position=threades.resize_pos( (650, 645 + 35 * i)), size=threades.resize_pos((200, 35)), parent=threades.desktop, text=list_food_res[i], style=self.labelstyle2) label = gui.Label(position=threades.resize_pos( (855, 649 + 35 * i)), parent=threades.desktop, text=str( int(model.resources[i + 5].get_vquantity())), style=self.labelstyle3) self.value_labels.append(label)
def tradingWindow(self, handle, buddyName='Friend', resource='Water', quantity='0', price='10', trade='sell'): '''Opens the trading window at the reciever end for trading ''' #self.font_color = (255,214,150) # Brown self.replyhandle = handle self.replymessage = ['TradeReply', resource, quantity, price, trade] color_blue = (0, 0, 250) myfont = pangofont.PangoFont(size=threades.resize_pt(17)) # Custom Window Style win_style = gui.defaultWindowStyle.copy() win_style['font'] = myfont win_style['bg-color'] = (0, 0, 0) win_style['font-color'] = color_blue # Calculating position and size of window from the size of the desktop position_win = threades.resize_pos((725.0, 42.0)) size_win = threades.resize_pos((470.0, 180.0)) # Creating custom label style for the text to be displayed as a message labelStyleCopy = gui.defaultLabelStyle.copy() labelStyleCopy['wordwrap'] = True labelStyleCopy['autosize'] = False labelStyleCopy['font'] = myfont labelStyleCopy['font-color'] = color_blue #labelStyleCopy['font-color'] = font_color self.win = gui.Window(position=position_win, size=size_win, parent=threades.desktop, text=_("Trade "), style=win_style, shadeable=False, moveable=False) # Creating label label_text = '\n' + buddyName + _( ' wants to ') + trade + ' ' + quantity + _( ' units of ') + resource + '\n at $ ' + price message_label = gui.Label(position=threades.resize_pos( (5, 5), (470.0, 180.0), self.win.size), size=threades.resize_pos((460, 120), (470.0, 180.0), self.win.size), parent=self.win, text=label_text, style=labelStyleCopy) # Creating button style myfont2 = pangofont.PangoFont(size=threades.resize_pt(16)) button_style = gui.defaultButtonStyle.copy() button_style['font'] = myfont2 self.button_accept = gui.Button(position=threades.resize_pos( (100.0, 130.0), (470.0, 180.0), size_win), size=threades.resize_pos( (100.0, 40.0), (470.0, 180.0), size_win), parent=self.win, text=_(" Accept "), style=button_style) self.button_reject = gui.Button(position=threades.resize_pos( (300.0, 130.0), (470.0, 180.0), size_win), size=threades.resize_pos( (100.0, 40.0), (470.0, 180.0), size_win), parent=self.win, text=_(" Reject "), style=button_style) self.button_accept.onClick = self.checkTrade self.button_reject.onClick = self.closeWin sleep(6) if self.win: self.win.close()
def showFailureWindow(self,text): self.brown_color = (255,214,150) self.green_color = (0,250,0) self.black_color = (0,0,0) myfont1 = pygame.font.Font("font.ttf", threades.resize_pt(40)) # Custom gui.Window Style win_style = gui.defaultWindowStyle.copy() win_style['font'] = myfont1 win_style['font-color'] = self.brown_color win_style['bg-color'] = (0,0,0) win_style['border-color'] = self.brown_color win_style['border-width'] = 2 st_desktop = gui.Desktop() clock = pygame.time.Clock() clock.tick() # Calculating position and size of window from the size of the threades.desktop position_win =threades.resize_pos((150.0,100.0)) size_win =threades.resize_pos((900.0,500.0)) # Creating window self.win = gui.Window(position = position_win, size = size_win, parent = st_desktop, text = " FoodForce2" , style = win_style, shadeable = False, closeable = False,moveable = False) #self.win.onClose = lambda button: self.main_menu(self.pause_flag) #self.win.surf.set_alpha(140) This seems to be redundant as translucency doesnt seems to work properly myfont2 = pygame.font.Font("font.ttf", threades.resize_pt(20)) labelStyleCopy = gui.defaultLabelStyle.copy() labelStyleCopy['border-width'] = 0 labelStyleCopy['wordwrap'] = True labelStyleCopy['autosize'] = False labelStyleCopy['font'] = myfont2 labelStyleCopy['font-color'] = self.brown_color labelStyleCopy['border-color'] = self.black_color self.storyboardwin_run = True #logo = pygame.image.load(os.path.join('data', 'logo.png')).convert() #ff_logo = pygame.transform.scale(logo,threades.resize_pos((1111,250))) #self.instructions_counter = 0 label = gui.Label(position = threades.resize_pos((100.0,100.0),(900.0,500.0),self.win.size),size = threades.resize_pos((700.0,340.0),(900.0,500.0),self.win.size), parent = self.win, text = text, style = labelStyleCopy) gl_time = 0 st_desktop.update() st_desktop.draw() pygame.display.update() while self.storyboardwin_run: pygame.display.set_caption('FoodForce2') for e in gui.setEvents(pygame.event.get()): if e.type == KEYDOWN: if e.key == 27: # For escape key self.storyboardwin_run = False gl_time += clock.tick() if gl_time >= 17000: self.storyboardwin_run = False event = game_events.Event(type = game_events.ACTIONCOMPLETEEVENT, facility_name = '', res_name = '' , res_quantity = 0) game_events.EventQueue.add(event)
def __init__(self): ''' Draws the model.resources panel on the surface ''' self.update_flag = True self.money_flag = True self.time_flag = False self.time_help_value=0 myfont1 = pygame.font.Font("font.ttf", threades.resize_pt(30)) # For main heading myfont2 = pygame.font.Font("font.ttf", threades.resize_pt(20)) # For model.resources name and their value myfont3 = pygame.font.Font("font.ttf", threades.resize_pt(16)) myfont4 = pygame.font.Font("font.ttf", threades.resize_pt(18)) # For the display of model.money # Creating a custom label style self.labelstyle1 = gui.defaultLabelStyle.copy() self.labelstyle1['border-width'] = 1 self.labelstyle1['wordwrap'] = True self.labelstyle1['autosize'] = False self.labelstyle1['font'] = myfont1 self.labelstyle1['font-color'] = self.font_color self.labelstyle1['border-color'] = self.color_grey # Drawing main Resources rectangle label = gui.Label(position = threades.resize_pos((400,600)),size = threades.resize_pos((500,45)), parent = threades.desktop, text = " Resources", style = self.labelstyle1) # Creating second label style self.labelstyle2 = gui.defaultLabelStyle.copy() self.labelstyle2['border-width'] = 0 self.labelstyle2['wordwrap'] = True self.labelstyle2['autosize'] = False self.labelstyle2['font'] = myfont2 self.labelstyle2['font-color'] = self.font_color self.labelstyle3 = gui.defaultLabelStyle.copy() self.labelstyle3['border-width'] = 0 self.labelstyle3['wordwrap'] = False self.labelstyle3['autosize'] = True self.labelstyle3['font'] = myfont3 self.labelstyle3['font-color'] = self.font_color self.labelstyle4 = gui.defaultLabelStyle.copy() self.labelstyle4['border-width'] = 0 self.labelstyle4['wordwrap'] = False self.labelstyle4['autosize'] = True self.labelstyle4['font'] = myfont4 self.labelstyle4['font-color'] = (160,160,160) self.money_label = gui.Label(position = threades.resize_pos((850,10)), parent = threades.desktop, text = 'Money -: '+str(int(model.money.get_money()))+' ', style = self.labelstyle4) self.time_label= gui.Label(position = threades.resize_pos((300,10)), parent = threades.desktop, text = 'Time Elapsed -: '+'Level Just Started'' ', style = self.labelstyle4) self.value_labels = [] # Drawing general model.resources list list_gen_res = (' Water',' Bricks',' Tools',' Medicines',' Books') for i in range(5): label = gui.Label(position = threades.resize_pos((400,645+35*i)),size = threades.resize_pos((200,35)), parent = threades.desktop, text = list_gen_res[i], style = self.labelstyle2) label = gui.Label(position = threades.resize_pos((605,649+35*i)), parent = threades.desktop, text = str(int(model.resources[i].get_vquantity())), style = self.labelstyle3) self.value_labels.append(label) # Drawing food model.resources list list_food_res = (' Rice',' Fruit & Vegetables',' Beans',' Sugar',' Salt',' Oil') for i in range(6): label = gui.Label(position = threades.resize_pos((650,645+35*i)),size = threades.resize_pos((200,35)), parent = threades.desktop, text = list_food_res[i], style = self.labelstyle2) label = gui.Label(position = threades.resize_pos((855,649+35*i)), parent = threades.desktop, text = str(int(model.resources[i+5].get_vquantity())), style = self.labelstyle3) self.value_labels.append(label)
def addChat(self, playerName=None, message=''): ''' Adds Chat to the chat window playerName tells the name of the character whose image to be used and message sends his mesage. ''' #TODO: Make a list of all the characters and make their pics # and load them in a dictionary with their names as keys # Assuming the dictionary to be playerCharactersImages global clock global desktopChat global move_to_next_chatwin_flag global run self.myfont = pygame.font.Font("font.ttf", 20) textColor = (0, 0, 0) #textsurface-the surface on which the text appears textSurface = gui.renderText( message, self.myfont, True, textColor, (635, 500), False, True ) #here 500(y-coordinate) doesn't make any difference , not used in gui.renderText #my_rect=pygame.Rect((0,0,500,500)) #textSurface=render_textrect(message,self.myfont, my_rect, textColor, None, justification=0) tempsize = textSurface.get_size() #print tempsize[0],tempsize[1] #tempsize2 - Variable that holds the dimensions of the textsurface that would be required to show the chat text tempsize2 = tempsize[1] + 50 #Checks that the size of the text is greater than the size of the textbox or not #it adjusts the size of the surface created according to the text length if tempsize2 > 120: tempSurface = pygame.transform.scale(self.chatBox, (720, tempsize[1] + 50)) else: tempSurface = pygame.transform.scale(self.chatBox, (720, 120)) #print 'color key is ',tempSurface.get_colorkey() tempSurface.blit(textSurface, (50, 25)) tempsize2 = tempSurface.get_size() #print (tempSurface.get_size())[0],(tempSurface.get_size())[1] dim_y = 0 ##height of the chatbox #It adjusts the size of the chat box accroding to the text length if tempsize2[1] > 120: dim_y = tempsize2[1] else: dim_y = 120 finalSurface = pygame.surface.Surface( (870, dim_y + 30)).convert_alpha() finalSurface.fill((0, 0, 0, 0)) #pos_of_image_on_finalsurface=(((dim_y)/2)-60)+15 finalSurface.blit(self.imageBox, (15, 15)) finalSurface.blit(tempSurface, (135, 15)) #finalSurface.blit(playerCharactersImages[playerName],(24,24)) finalSurface.blit(self.characterImage[str.upper(playerName)], (24, 15 + 9)) finalSurface = pygame.transform.scale( finalSurface, threades.resize_pos(finalSurface.get_size())) tempsize = finalSurface.get_size() dim_y = tempsize[1] #print 'self.position is',self.position[1] #print 'dim_y is',dim_y #print 'final position is',self.final_position[1] #Checks if the next chat needs to be blitted to next window or not if (self.position[1] + dim_y) > self.final_position[1]: #self.chatWin.size = threades.resize_pos((900,20)) #print 'its in this time' #print 'self.position is',self.position[1] #print 'dim_y is',dim_y #print 'final position is',self.final_position[1] #code to ensure that a new window is not opened until the user presses enter/next again if show_whole_chat_flag == True: while move_to_next_chatwin_flag == False: for e in gui.setEvents(pygame.event.get()): chat_event_handle(e) if background_image: threades.screen.blit(surf_bckgnd, (0, 0)) desktopChat.update() desktopChat.draw() pygame.display.update() model.iteration_time = clock.tick() model.global_time += model.iteration_time if run == False: return self.closeChatWindow() self.chatWindow() self.position = self.initial_position self.chatWin.surf.blit(finalSurface, self.position) self.position = (self.position[0], self.position[1] + dim_y) else: #x_coordinate=threades.resize_pt_x(900) #y_coordinate=self.chatWin.size[1]+dim_y #self.chatWin.size=(x_coordinate,y_coordinate) self.chatWin.surf.blit(finalSurface, self.position) # self.position[1] += dim_y self.position = (self.position[0], self.position[1] + dim_y)
def startup_text(self,button = None): ''' Displays the startup text ''' self.remove_buttons() threades.screen.fill((255,255,255)) hunger_map = pygame.image.load(os.path.join('data', 'Wfpwork.png')).convert() hunger_map = pygame.transform.scale(hunger_map,threades.new_screen_size) threades.screen.blit(hunger_map,threades.resize_pos((0,0))) color_brown = (255,214,150) # gui.Window custom style myfont = pygame.font.Font("font.ttf", threades.resize_pt(28)) win_style = gui.defaultWindowStyle.copy() win_style['font'] = myfont win_style['font-color'] = color_brown win_style['bg-color'] = (0,0,0) win_style['border-color'] = color_brown position_win =threades.resize_pos((200.0,50.0)) size_win =threades.resize_pos((800.0,600.0)) win = gui.Window(position = position_win, size = size_win, parent = desktop2, text = " FOODFORCE II : ESCAPING POVERTY " ,style = win_style,shadeable = False, closeable = False,moveable = False) self.startup_text_run = True win.surf.set_alpha(100) myfont2 = pygame.font.Font("font.ttf",threades.resize_pt(19)) labelstyle1 = gui.defaultLabelStyle.copy() labelstyle1['border-width'] = 0 labelstyle1['wordwrap'] = True labelstyle1['autosize'] = False labelstyle1['font'] = myfont2 labelstyle1['font-color'] = color_brown counter = 0 label = gui.Label(position = threades.resize_pos((10.0,130.0),(800.0,600.0),win.size),size = threades.resize_pos((780.0,460.0),(800.0,600.0),win.size), parent = win, text = '', style = labelstyle1) button_style = gui.defaultButtonStyle.copy() button_style['font'] = myfont2 self.skip_button = gui.Button(position = threades.resize_pos((600,550),(800.0,600.0),win.size), size = threades.resize_pos((150,30),(800.0,600.0),win.size), parent = win, text = " Skip ",style = button_style) self.skip_button.onClick = self.turnoff_startup_run model.global_time = 0 #One time show of the background image threades.screen.fill((255,255,255)) threades.screen.blit(hunger_map,threades.resize_pos((0,0))) pygame.display.flip() #sleep(5) first_display = True model.global_time = 0 while self.startup_text_run: label.text = texts.trailer_text[counter] for e in gui.setEvents(pygame.event.get()): if e.type == pygame.QUIT: safe_exit() if e.type == KEYDOWN: if e.key == 27: # For escape key self.startup_text_run = False if e.key == K_RETURN: counter += 1 if e.type==mesh.CONNECT : game_sharing.sharing_handler(e.type,None,'') #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,None,'']).start() elif e.type==mesh.PARTICIPANT_ADD or e.type==mesh.PARTICIPANT_REMOVE : game_sharing.sharing_handler(e.type,e.handle,'') #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,e.handle,'']).start() elif e.type==mesh.MESSAGE_MULTI or e.type==mesh.MESSAGE_UNI : game_sharing.sharing_handler(e.type,e.handle,e.content) #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,e.handle,e.content]).start() if model.global_time >= 5000: first_display = False model.global_time = 0 counter += 1 if not first_display: threades.screen.fill((255,255,255)) threades.screen.blit(hunger_map,threades.resize_pos((0,0))) desktop2.update() desktop2.draw() pygame.display.flip() if counter == len(texts.trailer_text): self.startup_text_run = False model.iteration_time = clock.tick() model.global_time += model.iteration_time win.close() self.run = False
#sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,None,'']).start() elif e.type==mesh.PARTICIPANT_ADD or e.type==mesh.PARTICIPANT_REMOVE : game_sharing.sharing_handler(e.type,e.handle,'') #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,e.handle,'']).start() elif e.type==mesh.MESSAGE_MULTI or e.type==mesh.MESSAGE_UNI : game_sharing.sharing_handler(e.type,e.handle,e.content) #sharing_thread = threading.Thread(target = game_sharing.sharing_handler, args=[e.type,e.handle,e.content]).start() desktop2.update() desktop2.draw() pygame.display.update() threades.total_update_flag = True wfp_logo = pygame.image.load(os.path.join('data', 'top.png')).convert() surface_top = pygame.transform.scale(wfp_logo,threades.resize_pos((1200,40))) def main(): global panel global chat_screen global level_setting # Displaying the WFP logo intro_thread = threading.Thread(target = load_images.load_images, args=[]) intro_thread.start() # Loading and starting the sound play GameSounds.objMusic.start_music() level_setting=level_change.change_level() pause_screen()
def __init__(self): ''' Draws the manpower panel ''' self.update_flag = True myfont1 = pygame.font.Font("font.ttf", threades.resize_pt(25)) # For main heading myfont2 = pygame.font.Font( "font.ttf", threades.resize_pt(20)) # For model.resources name and their value myfont3 = pygame.font.Font( "font.ttf", threades.resize_pt(16)) # For model.resources name and their value # Creating a custom label style self.labelstyle1 = gui.defaultLabelStyle.copy() self.labelstyle1['border-width'] = 1 self.labelstyle1['wordwrap'] = True self.labelstyle1['autosize'] = False self.labelstyle1['font'] = myfont1 self.labelstyle1['font-color'] = self.font_color self.labelstyle1['border-color'] = self.color_grey self.name_labels = [] # Drawing main Manpower Resources rectangle label = gui.Label(position=threades.resize_pos((0, 600)), size=threades.resize_pos((400, 45)), parent=threades.desktop, text=" " + model.text_file.mpwr_resources_text[0], style=self.labelstyle1) self.name_labels.append(label) # Creating second label style self.labelstyle2 = gui.defaultLabelStyle.copy() self.labelstyle2['border-width'] = 0 self.labelstyle2['wordwrap'] = True self.labelstyle2['autosize'] = False self.labelstyle2['font'] = myfont2 self.labelstyle2['font-color'] = self.font_color self.labelstyle2['border-color'] = self.color_grey self.labelstyle3 = gui.defaultLabelStyle.copy() self.labelstyle3['border-width'] = 0 self.labelstyle3['wordwrap'] = False self.labelstyle3['autosize'] = True self.labelstyle3['font'] = myfont3 self.labelstyle3['font-color'] = self.font_color self.labelstyle3['border-color'] = self.color_grey # Drawing Manpower model.resources list list_names = model.text_file.mpwr_list_names list_values = (model.ppl.get_total_population(), model.ppl.get_no_of_ppl_sheltered(), model.ppl.get_no_of_ppl_educated(), model.ppl.get_no_of_ppl_healthy(), model.ppl.get_no_of_ppl_fed(), model.ppl.get_total_no_of_ppl_emp()) self.value_labels = [] for i in range(6): label = gui.Label(position=threades.resize_pos((0, 645 + 35 * i)), size=threades.resize_pos((350, 35)), parent=threades.desktop, text=list_names[i], style=self.labelstyle2) self.name_labels.append(label) label = gui.Label(position=threades.resize_pos( (355, 649 + 35 * i)), parent=threades.desktop, text=str(int(list_values[i])), style=self.labelstyle3) self.value_labels.append(label)
def __init__(self): ''' Draws the manpower panel ''' self.update_flag = True myfont1 = pangofont.PangoFont( size=threades.resize_pt(30)) # For main heading myfont2 = pangofont.PangoFont(size=threades.resize_pt( 25)) # For model.resources name and their value myfont3 = pangofont.PangoFont(size=threades.resize_pt( 25)) # For model.resources name and their value # Creating a custom label style self.labelstyle1 = gui.defaultLabelStyle.copy() self.labelstyle1['border-width'] = 1 self.labelstyle1['wordwrap'] = True self.labelstyle1['autosize'] = False self.labelstyle1['font'] = myfont1 self.labelstyle1['font-color'] = self.font_color self.labelstyle1['border-color'] = self.color_grey # Drawing main Manpower Resources rectangle label = gui.Label(position=threades.resize_pos((0, 600)), size=threades.resize_pos((400, 45)), parent=threades.desktop, text=_(" Manpower Distribution"), style=self.labelstyle1) # Creating second label style self.labelstyle2 = gui.defaultLabelStyle.copy() self.labelstyle2['border-width'] = 0 self.labelstyle2['wordwrap'] = True self.labelstyle2['autosize'] = False self.labelstyle2['font'] = myfont2 self.labelstyle2['font-color'] = self.font_color self.labelstyle2['border-color'] = self.color_grey self.labelstyle3 = gui.defaultLabelStyle.copy() self.labelstyle3['border-width'] = 0 self.labelstyle3['wordwrap'] = False self.labelstyle3['autosize'] = True self.labelstyle3['font'] = myfont3 self.labelstyle3['font-color'] = self.font_color self.labelstyle3['border-color'] = self.color_grey # Drawing Manpower model.resources list list_names = (_(' Total Population'), _(' Sheltered People'), _(' Educated People'), _(' Healthy People'), _(' People Fed'), _(' People Employed')) list_values = (model.ppl.get_total_population(), model.ppl.get_no_of_ppl_sheltered(), model.ppl.get_no_of_ppl_educated(), model.ppl.get_no_of_ppl_healthy(), model.ppl.get_no_of_ppl_fed(), model.ppl.get_total_no_of_ppl_emp()) self.value_labels = [] for i in range(6): label = gui.Label(position=threades.resize_pos((0, 645 + 35 * i)), size=threades.resize_pos((350, 35)), parent=threades.desktop, text=list_names[i], style=self.labelstyle2) label = gui.Label(position=threades.resize_pos( (355, 649 + 35 * i)), parent=threades.desktop, text=str(int(list_values[i])), style=self.labelstyle3) self.value_labels.append(label)
def get_update_region(): # Function which returns the regions to be updated list_rects = [] if threades.total_update_flag: threades.screen.blit(surface_top,(0,0)) pygame.draw.rect(threades.screen,(0,0,0),threades.resize_rect((0,600,1200,300))) list_rects.append(pygame.Rect(threades.resize_pos((0,0)),threades.resize_pos((1200,900)))) return list_rects list_rects.append(pygame.Rect(threades.resize_pos((0,40)),threades.resize_pos((930,560)))) if (panel.ind.update_flag or panel.man.update_flag or panel.res.update_flag or threades.panel_update_flag): pygame.draw.rect(threades.screen,(0,0,0),threades.resize_rect((0,600,1200,300))) list_rects.append(pygame.Rect(threades.resize_pos((0,600)),threades.resize_pos((1200,300)))) if panel.map.update_flag or threades.map_update_flag: list_rects.append(pygame.Rect(threades.resize_pos((930,390)),threades.resize_pos((270,210)))) if panel.res.money_flag or threades.top_update_flag: threades.screen.blit(surface_top,(0,0)) list_rects.append(pygame.Rect((0,0),threades.resize_pos((1200,40)))) if panel.fac.update_flag or threades.facilities_update_flag: list_rects.append(pygame.Rect(threades.resize_pos((930,40)),threades.resize_pos((270,350)))) return list_rects
def __init__(self): ''' Constructor ''' global background_image self.chatWinFlag = False self.position = threades.resize_pos((15, 10)) self.initial_position = threades.resize_pos((15, 10)) self.final_position = threades.resize_pos((15, 750)) self.update_win_pos = pygame.Rect(threades.resize_pos((150.0, 50.0)), threades.resize_pos((900, 800))) self.imageBox = pygame.image.load(os.path.join( 'art', 'imageBox.png')).convert_alpha() self.chatBox = pygame.image.load(os.path.join( 'art', 'chatBox.png')).convert_alpha() #list for storing the images loaded in the chatbox storyboard_list_file = open('storyboard_list.pkl') pickle.load(storyboard_list_file) storyboard_name = pickle.load(storyboard_list_file) self.characterImage = {} if model.storyboard_file == storyboard_name[1]: self.characterImage['KAMAT'] = pygame.image.load( os.path.join('storyboards', model.storyboard_file, 'images', 'character images', 'kamat.png')).convert_alpha() self.characterImage['SON'] = pygame.image.load( os.path.join('storyboards', model.storyboard_file, 'images', 'character images', 'son.png')).convert_alpha() self.characterImage['AJMAL'] = pygame.image.load( os.path.join('storyboards', model.storyboard_file, 'images', 'character images', 'ajmal.png')).convert_alpha() self.characterImage['PANCH'] = pygame.image.load( os.path.join('storyboards', model.storyboard_file, 'images', 'character images', 'panch.png')).convert_alpha() self.characterImage['PRIEST'] = pygame.image.load( os.path.join('storyboards', model.storyboard_file, 'images', 'character images', 'priest.png')).convert_alpha() self.characterImage['SUKHDEV'] = pygame.image.load( os.path.join('storyboards', model.storyboard_file, 'images', 'character images', 'sukhdev.png')).convert_alpha() self.characterImage['FARMER'] = pygame.image.load( os.path.join('storyboards', model.storyboard_file, 'images', 'character images', 'villager.png')).convert_alpha() else: self.characterImage['TONY PERALTA'] = pygame.image.load( os.path.join('storyboards', model.storyboard_file, 'images', 'character images', 'tony.png')).convert_alpha() self.characterImage['STEVENSON GORBACHEV'] = pygame.image.load( os.path.join('storyboards', model.storyboard_file, 'images', 'character images', 'stevenson.png')).convert_alpha() self.characterImage['GILBERT FERNANDEZ'] = pygame.image.load( os.path.join('storyboards', model.storyboard_file, 'images', 'character images', 'gilbert.png')).convert_alpha() self.characterImage['JOHN TREMBLAY'] = pygame.image.load( os.path.join('storyboards', model.storyboard_file, 'images', 'character images', 'john.png')).convert_alpha() self.characterImage['RAGNAR STEFANSSON'] = pygame.image.load( os.path.join('storyboards', model.storyboard_file, 'images', 'character images', 'ragnar.png')).convert_alpha() # changes made while adding skip buttons etc self.size_win = threades.resize_pos((900.0, 800.0)) self.myfont = pygame.font.Font("font.ttf", threades.resize_pt(16)) self.button_style = gui.defaultButtonStyle.copy() self.button_style['font'] = self.myfont #crating label textsurface #myfont = pygame.font.Font("font.ttf",10) #textColor = (0,0,0) #self.label_text=' ENTER : To show whole chat at once ESC : To skip chat ' #self.label_textsurface=gui.renderText(self.label_text,myfont,True,textColor,(700,20),False,True) #self.label_tempSurface = pygame.transform.scale(self.chatBox,(800,30)) #creating a label for the chat window self.myfont2 = pygame.font.Font("font.ttf", threades.resize_pt(20)) self.labelStyleCopy = gui.defaultLabelStyle.copy() self.labelStyleCopy['border-width'] = 1 self.labelStyleCopy['wordwrap'] = True self.labelStyleCopy['autosize'] = False self.labelStyleCopy['font'] = self.myfont2 self.labelStyleCopy['font-color'] = (255, 214, 150) self.labelStyleCopy['border-color'] = (255, 214, 150)
def showChat(chatText, back_image=None): ''' Chat text should be a list with first the name of the character and then his dialogue, ''' global run global chatObject global show_whole_chat_flag global move_to_next_chatwin_flag global clock global background_image global surf_bckgnd background_image = back_image if back_image: surf_bckgnd = pygame.image.load(os.path.join('storyboards', back_image)).convert() surf_bckgnd = pygame.transform.scale(surf_bckgnd, threades.resize_pos((1200, 900))) chatObject = chat() chatObject.chatWindow() clock = pygame.time.Clock() show_whole_chat_flag = False move_to_next_chatwin_flag = False i = 0 i_incrementor = False run = True allowed = True global desktop2 while run: if len(chatText) == 0: break for e in gui.setEvents(pygame.event.get()): chat_event_handle(e) if back_image: threades.screen.blit(surf_bckgnd, (0, 0)) desktopChat.update() desktopChat.draw() pygame.display.update() #print chatObject.button_skip.enabled if (model.global_time >= 10000) or (i == 0 and allowed == True) or ( show_whole_chat_flag == True): if i == 0: allowed = False if i_incrementor == True: i += 2 model.global_time = 0 #pygame.display.update() chatObject.addChat(chatText[i], chatText[i + 1]) if run == False: print 'reaching here also finely' i_incrementor = True max_iterations = (len(chatText) - 2) if i == max_iterations: while (model.global_time < 10000 and show_whole_chat_flag == False) or (show_whole_chat_flag == True and move_to_next_chatwin_flag == False): model.iteration_time = clock.tick() model.global_time += model.iteration_time for e in gui.setEvents(pygame.event.get()): chat_event_handle(e) if back_image: threades.screen.blit(surf_bckgnd, (0, 0)) desktopChat.update() desktopChat.draw() pygame.display.flip() if run == False: break run = False model.iteration_time = clock.tick() model.global_time += model.iteration_time surf_bckgnd = None chatObject.closeChatWindow()