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 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 update_value(self,value): '''Updates the value of the bar ''' max_value = 100.0 max_pixel = 246.0 colour = (177,135,73) pygame.draw.rect(threades.screen,self.color_bar,threades.resize_rect((self.x,self.y,250,18)),2) pygame.draw.rect(threades.screen,colour,threades.resize_rect((self.x+2,self.y+2,value/max_value*max_pixel,14))) pygame.draw.rect(threades.screen,(255,255,255),threades.resize_rect((self.x+2+value/max_value*max_pixel,self.y+2,max_pixel-value/max_value*max_pixel,14)))
def update_value(self,value): '''Updates the value of the bar The rect's are drawn again and again here, what could if we do to just possibly update them in a a less expensive manner. ''' max_value = 100.0 max_pixel = 246.0 colour = (177,135,73) t = value/max_value*max_pixel #pygame.draw.rect(threades.screen,self.color_bar,threades.resize_rect((self.x,self.y,250,18)),2) pygame.draw.rect(threades.screen,colour,threades.resize_rect((self.x+2,self.y+2,t,14))) pygame.draw.rect(threades.screen,(255,255,255),threades.resize_rect((self.x+2+t,self.y+2,max_pixel-t,14)))
class bar: color_bar = (47, 47, 255) def __init__(self, (x_value, y_value)): ''' Draws a bar on the surface at posn x,y ''' self.x = x_value self.y = y_value pygame.draw.rect(threades.screen, self.color_bar, threades.resize_rect((self.x, self.y, 250, 18)), 2) pygame.draw.rect( threades.screen, (255, 255, 255), threades.resize_rect((self.x + 2, self.y + 2, 246, 14)))
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 event_handling(e): if e.type == pygame.QUIT: safe_exit() if e.type == QUIT: safe_exit() if e.type == KEYDOWN: if e.key == 27: # For escape key escape() if e.key == K_UP: threades.transform_obj.start_move('up') if e.key == K_DOWN: threades.transform_obj.start_move('down') if e.key == K_LEFT: threades.transform_obj.start_move('left') if e.key == K_RIGHT: threades.transform_obj.start_move('right') if e.key == K_f or e.key == 61: threades.transform_obj.focus() if e.key == K_d or e.key == 45: threades.transform_obj.defocus() if e.key == K_RETURN: gui_buttons.gui_obj.press_enter() win_flag = gui_buttons.gui_obj.get_win_flag() if not win_flag: if e.key == K_s: gui_buttons.gui_obj.setup_obj.setup() if e.key == K_u: gui_buttons.gui_obj.upgrade_obj.upgrade() if e.key == K_b: gui_buttons.gui_obj.buysell_obj.buysell() if e.type == KEYUP: if e.key == K_UP: threades.transform_obj.stop_move('up') if e.key == K_DOWN: threades.transform_obj.stop_move('down') if e.key == K_LEFT: threades.transform_obj.stop_move('left') if e.key == K_RIGHT: threades.transform_obj.stop_move('right') x,y = pygame.mouse.get_pos() r = pygame.Rect(threades.resize_rect((0,40,930,560))) if gui_buttons.gui_obj.buysell_obj.get_win_flag(): gui_buttons.gui_obj.buysell_obj.drawPriceChart() if r.collidepoint(x,y): if e.type == MOUSEBUTTONDOWN: if e.button == 1 and gui_buttons.gui_obj.get_child_win_flag(): gui_buttons.gui_obj.setup_obj.bardisplay.updateChart((x,y)) if e.button == 1 and gui_buttons.gui_obj.buysell_obj.get_win_flag(): gui_buttons.gui_obj.buysell_obj.barObject.updateChart((x,y)) if e.button == 4: threades.transform_obj.focus() if e.button == 5: threades.transform_obj.defocus()
def update_value(self, value): '''Updates the value of the bar The rect's are drawn again and again here, what could if we do to just possibly update them in a a less expensive manner. ''' max_value = 100.0 max_pixel = 246.0 colour = (177, 135, 73) t = value / max_value * max_pixel #pygame.draw.rect(threades.screen,self.color_bar,threades.resize_rect((self.x,self.y,250,18)),2) pygame.draw.rect(threades.screen, colour, threades.resize_rect((self.x + 2, self.y + 2, t, 14))) pygame.draw.rect( threades.screen, (255, 255, 255), threades.resize_rect( (self.x + 2 + t, self.y + 2, max_pixel - t, 14)))
def update_value(self, value): '''Updates the value of the bar ''' max_value = 100.0 max_pixel = 246.0 colour = (177, 135, 73) pygame.draw.rect(threades.screen, self.color_bar, threades.resize_rect((self.x, self.y, 250, 18)), 2) pygame.draw.rect( threades.screen, colour, threades.resize_rect( (self.x + 2, self.y + 2, value / max_value * max_pixel, 14))) pygame.draw.rect( threades.screen, (255, 255, 255), threades.resize_rect( (self.x + 2 + value / max_value * max_pixel, self.y + 2, max_pixel - value / max_value * max_pixel, 14)))
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 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 update_value(self): ''' Updates the Facilities panel ''' for i in range(6): if not (self.value_labels[i].text == self.list_names[0]+str(int(self.list_values1[i]))+' '+model.text_file.level_text[0]+': '+str(int(self.list_values2[i]))): self.update_flag = False if self.update_flag or threades.facilities_update_flag or threades.total_update_flag: self.list_values1 = (model.House.get_original_number(),model.School.get_original_number(),model.Hospital.get_original_number(),model.Workshop.get_original_number(),model.Farm.get_original_number(),model.Fountain.get_original_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()) pygame.draw.rect(threades.screen,(0,0,0),threades.resize_rect((930,40,270,350))) for i in range(6): if not (self.value_labels[i].text == model.text_file.num_text[0]+':'+str(int(self.list_values1[i]))+' '+model.text_file.level_text[0]+': '+str(int(self.list_values2[i]))): self.value_labels[i].text = model.text_file.num_text[0]+':'+str(int(self.list_values1[i]))+' '+model.text_file.level_text[0]+': '+str(int(self.list_values2[i])) self.update_flag = False
def update_value(self): ''' Updates the Facilities panel ''' for i in range(6): if not (self.value_labels[i].text == self.list_names[0] + str(int(self.list_values1[i])) + ' ' + model.text_file.level_text[0] + ': ' + str(int(self.list_values2[i]))): self.update_flag = False if self.update_flag or threades.facilities_update_flag or threades.total_update_flag: self.list_values1 = (model.House.get_original_number(), model.School.get_original_number(), model.Hospital.get_original_number(), model.Workshop.get_original_number(), model.Farm.get_original_number(), model.Fountain.get_original_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()) pygame.draw.rect(threades.screen, (0, 0, 0), threades.resize_rect((930, 40, 270, 350))) for i in range(6): if not (self.value_labels[i].text == model.text_file.num_text[0] + ':' + str(int(self.list_values1[i])) + ' ' + model.text_file.level_text[0] + ': ' + str(int(self.list_values2[i]))): self.value_labels[ i].text = model.text_file.num_text[0] + ':' + str( int(self.list_values1[i]) ) + ' ' + model.text_file.level_text[0] + ': ' + str( int(self.list_values2[i])) self.update_flag = False
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 event_handling(e): if e.type == pygame.QUIT: safe_exit() if e.type == QUIT: safe_exit() if e.type == KEYDOWN: if e.key == 27: # For escape key escape() if e.key == K_UP: threades.transform_obj.start_move('up') if e.key == K_DOWN: threades.transform_obj.start_move('down') if e.key == K_LEFT: threades.transform_obj.start_move('left') if e.key == K_RIGHT: threades.transform_obj.start_move('right') if e.key == K_f or e.key == 61: threades.transform_obj.focus() if e.key == K_d or e.key == 45: threades.transform_obj.defocus() if e.key == K_RETURN: gui_buttons.gui_obj.press_enter() win_flag = gui_buttons.gui_obj.get_win_flag() if not win_flag: if e.key == K_s: gui_buttons.gui_obj.setup_obj.setup() if e.key == K_u: gui_buttons.gui_obj.upgrade_obj.upgrade() if e.key == K_b: gui_buttons.gui_obj.buysell_obj.buysell() if e.type == KEYUP: if e.key == K_UP: threades.transform_obj.stop_move('up') if e.key == K_DOWN: threades.transform_obj.stop_move('down') if e.key == K_LEFT: threades.transform_obj.stop_move('left') if e.key == K_RIGHT: threades.transform_obj.stop_move('right') x,y = pygame.mouse.get_pos() r = pygame.Rect(threades.resize_rect((0,40,930,560))) if gui_buttons.gui_obj.buysell_obj.get_win_flag(): gui_buttons.gui_obj.buysell_obj.drawPriceChart() if r.collidepoint(x,y): if e.type == MOUSEBUTTONDOWN: if e.button == 1 and gui_buttons.gui_obj.get_child_win_flag(): gui_buttons.gui_obj.setup_obj.bardisplay.updateChart((x,y)) if e.button == 1 and gui_buttons.gui_obj.buysell_obj.get_win_flag(): gui_buttons.gui_obj.buysell_obj.barObject.updateChart((x,y)) if e.button == 4: threades.transform_obj.focus() if e.button == 5: threades.transform_obj.defocus() 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)
def showStoryboardWindow(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 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))) #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([update_rect]) 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 self.win.close() event = game_events.Event(type = game_events.ACTIONCOMPLETEEVENT, facility_name = '', res_name = '' , res_quantity = 0) game_events.EventQueue.add(event)
def event_handling(e): #For the safe exit of the game if e.type == pygame.QUIT: safe_exit() if e.type == QUIT: safe_exit() #Updates the region if e.type == KEYDOWN: if e.key == 27: # For escape key escape() if e.key == K_UP: threades.transform_obj.start_move('up') if e.key == K_DOWN: threades.transform_obj.start_move('down') if e.key == K_LEFT: threades.transform_obj.start_move('left') if e.key == K_RIGHT: threades.transform_obj.start_move('right') if e.key == K_f or e.key == 61: threades.transform_obj.focus() if e.key == K_d or e.key == 45: threades.transform_obj.defocus() if e.key == K_RETURN: gui_buttons.gui_obj.press_enter() #Tackles the cases of setting up a facility,upgrading a facility,buying and selling of resources win_flag = gui_buttons.gui_obj.get_win_flag() if not win_flag: if e.key == K_s and gui_buttons.gui_obj.setup_button.enabled: gui_buttons.gui_obj.setup_obj.setup() if e.key == K_u and gui_buttons.gui_obj.upgrade_button.enabled: gui_buttons.gui_obj.upgrade_obj.upgrade() if e.key == K_b and gui_buttons.gui_obj.buysell_button.enabled: gui_buttons.gui_obj.buysell_obj.buysell() #Resetting the game if proceduralFlow.GAME_END_FLAG: threades.PLACING_LIST_TEMP = [] proceduralFlow.GAME_END_FLAG = False proceduralFlow.closeStoryBoardFile() proceduralFlow.openStoryBoardFile() threades.delete_saved_game() proceduralFlow.storyboard_level = 1 data_file = os.path.join('storyboards',str(model.storyboard_file),'data','data1.pkl') proceduralFlow.load_level_obj.new_level_stats(data_file,'graphics_layout.pkl') event = game_events.Event(type = game_events.ACTIONCOMPLETEEVENT, facility_name = '', res_name = '' , res_quantity = 0) game_events.EventQueue.add(event) model.game_controller.reset_time() pause_screen() if e.type == KEYUP: if e.key == K_UP: threades.transform_obj.stop_move('up') if e.key == K_DOWN: threades.transform_obj.stop_move('down') if e.key == K_LEFT: threades.transform_obj.stop_move('left') if e.key == K_RIGHT: threades.transform_obj.stop_move('right') x,y = pygame.mouse.get_pos() r = pygame.Rect(threades.resize_rect((0,40,930,560))) if gui_buttons.gui_obj.buysell_obj.get_win_flag(): gui_buttons.gui_obj.buysell_obj.drawPriceChart() if r.collidepoint(x,y): if e.type == MOUSEBUTTONDOWN: if e.button == 1 and gui_buttons.gui_obj.get_child_win_flag(): gui_buttons.gui_obj.setup_obj.bardisplay.updateChart((x,y)) if e.button == 1 and gui_buttons.gui_obj.buysell_obj.get_win_flag(): gui_buttons.gui_obj.buysell_obj.barObject.updateChart((x,y)) if e.button == 4: threades.transform_obj.focus() if e.button == 5: threades.transform_obj.defocus() if model.FLAG_XO: if e.type==mesh.CONNECT : game_sharing.sharing_handler(e.type,None,'') elif e.type==mesh.PARTICIPANT_ADD or e.type==mesh.PARTICIPANT_REMOVE : game_sharing.sharing_handler(e.type,e.handle,'') elif e.type==mesh.MESSAGE_MULTI or e.type==mesh.MESSAGE_UNI : game_sharing.sharing_handler(e.type,e.handle,e.content)
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)