def click(self, coord, double=False): # adjust coordinates if self.game_location: game_x, game_y, game_width, game_height = self.game_location #print('game_x: %d, game_y: %d, game_width: %d, game_height: %d' % (game_x, game_y, game_width, game_height)) x, y = tools.adjust_click_position(coord['x'], coord['y'], coord['width'], coord['height'], game_x, game_y, game_width, game_height) else: x, y = (coord['x'], coord['y']) # click self.debug('Click on x: %d, y: %d, double: %s' % (x, y, double), DebugLevel.High) tools.perform_click(x, y, double)
def get_box_location(self, box_name): if self.game_location: game_x, game_y, game_width, game_height = self.game_location box_window_width, box_window_height = data.Boxes[box_name][ 'windowSize'] x, y = tools.adjust_click_position(data.Boxes[box_name]['x'], data.Boxes[box_name]['y'], box_window_width, box_window_height, game_x, game_y, game_width, game_height) width = data.Boxes[box_name]['width'] height = data.Boxes[box_name]['height'] return (x, y, width, height) else: return None
def on_simulate_resource_click_button_clicked(self, button): selected_row = self.map_data_listbox.listbox.get_selected_row() if selected_row: text = self.map_data_listbox.get_row_text(selected_row) data = maps.to_array(text) x, y, width, height, color = (data['x'], data['y'], data['width'], data['height'], data['color']) #print('x: %d, y: %d, width: %d, height: %d' % (x, y, width, height)) # adjust for game area if self.game_window and not self.game_window.is_destroyed() and self.game_window_location: game_x, game_y, game_width, game_height = self.game_window_location #print('game_x: %d, game_y: %d, game_width: %d, game_height: %d' % (game_x, game_y, game_width, game_height)) click_x, click_y = tools.adjust_click_position(x, y, width, height, game_x, game_y, game_width, game_height) else: click_x = x click_y = y # perform click self.debug('Simulate click on x: %d, y: %d' % (click_x, click_y)) tools.perform_click(click_x, click_y)
def on_simulate_click_button_clicked(self, button): # get click coordinates selected_row = self.tree_view.get_selected_row() x, y, width, height = (selected_row[1], selected_row[2], selected_row[3], selected_row[4]) #print('x: %d, y: %d, width: %d, height: %d' % (x, y, width, height)) # adjust for game area if self.parent.game_area: game_x, game_y, game_width, game_height = tools.get_widget_location( self.parent.game_area) #print('game_x: %d, game_y: %d, game_width: %d, game_height: %d' % (game_x, game_y, game_width, game_height)) click_x, click_y = tools.adjust_click_position( x, y, width, height, game_x, game_y, game_width, game_height) else: click_x = x click_y = y # perform click self.parent.debug('Click on x: %d, y: %d' % (click_x, click_y)) tools.perform_click(click_x, click_y)
def check_location_color(self, location): if location['color'] is None: return True location['color'] = parser.parse_color(location['color']) game_x, game_y, game_width, game_height = self.game_location coordones = [] x, y = tools.adjust_click_position(location['x'], location['y'], location['width'], location['height'], \ game_x, game_y, game_width, game_height) kernel = [[-1, -1], [0, -1], [1, -1], [-1, 0], [0, 0], [1, 0], [-1, 1], [0, 1], [1, 1]] for offset in kernel: coordones.append([x + offset[0], y + offset[1]]) tools.move_mouse(x + 5, y + 5) self.sleep(0.05) for coord in coordones: color = tools.get_pixel_color(coord[0], coord[1]) if tools.color_matches(color, location['color'], tolerance=10): return True return False
def check_resource_color(self, resource): # check pixel color if self.check_resources_color: game_x, game_y, game_width, game_height = self.game_location x, y = tools.adjust_click_position(resource['x'], resource['y'], resource['width'], resource['height'], game_x, game_y, game_width, game_height) color = tools.get_pixel_color(x, y) resource['color'] = parser.parse_color(resource['color']) if resource['color'] is not None and not tools.color_matches( color, resource['color'], tolerance=10): self.debug( "Ignoring non-matching resource {'x': %d, 'y': %d, 'color': %s} on pixel {'x': %d, 'y': %d, 'color': %s}" % (resource['x'], resource['y'], resource['color'], x, y, color)) # remove current resource from minimap (index = 0) self.remove_from_minimap(0) return False return True