def graphEditMode(events: list, screen, mapsurface: pygame.Surface, world: World, capital_pressed: int) -> int: # Log.e(type(capital_pressed)); if capital_pressed == -1: for event in events: if event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: variable_capital_id = check_capitals( world, event.pos, mapsurface) if variable_capital_id is not None: capital_pressed = variable_capital_id return capital_pressed return -1 else: # для начала рисуем линию между стартом и мышкой mouse_screen_coords = pygame.mouse.get_pos() capital_screen_coords = world.list_of_capitals[ capital_pressed].toScreenCoords(mapsurface.get_scale(), mapsurface.get_coords()) # Log.d(capital_screen_coords); pygame.draw.line(screen, pygame.Color("white"), capital_screen_coords.get_coords(), mouse_screen_coords, 5) for event in events: if event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1: variable_capital_id = check_capitals( world, event.pos, mapsurface) if variable_capital_id is not None: world.add_connection(capital_pressed, variable_capital_id) return -1 return capital_pressed
def check_capitals( world: World, event_click: tuple, mapsurface: pygame.Surface ) -> int: # id of province, whos capital has been pressed event_click_screen_coords = ScreenCoords(event_click[0], event_click[1]) event_click_map_coords = event_click_screen_coords.toMapCoords( mapsurface.get_scale(), mapsurface.get_coords()) for capital_id in range(len(world.list_of_capitals)): if optimized_myrange.get_distance(world.list_of_capitals[capital_id], event_click_map_coords) <= 20: return capital_id
def draw(self, screen: pygame.Surface, mapsurface: pygame.Surface) -> None: dots: list = [ coords.toScreenCoords(mapsurface.get_scale(), mapsurface.get_coords()).get_coords() for coords in self.polygons ] if len(dots) >= 3: # Log.d(dots) # pygame.draw.polygon(pygame.Surface (surface to draw), pygame.Color (color), list<tuple<int>> (dots), int (width)); pygame.draw.polygon(screen, self.color, dots, 5) elif len(dots) == 2: pygame.draw.line(screen, self.color, dots[0], dots[1], 5) elif len(dots) == 1: # Log.d(type(dots[0])) pygame.draw.line(screen, self.color, dots[0], dots[0], 5) else: pass if self.capital_coords is not None: screen_coords = self.capital_coords.toScreenCoords( mapsurface.get_scale(), mapsurface.get_coords()) pygame.draw.circle(screen, self.color, (screen_coords.x, screen_coords.y), 10, 0)
def provinceGeometryEdit(events: list, province: Province, mapsurface: pygame.Surface) -> None: for event in events: if event.type == pygame.MOUSEBUTTONDOWN: if event.button == 1 and mapsurface.collides( event.pos): #editing borders province.addPolygon(toScreenCoords(event.pos), mapsurface) elif event.button == 2 and mapsurface.collides( event.pos): #editing capitals # Log.d("Got it"); capital_coords = event.pos map_capital_coords = toScreenCoords( capital_coords).toMapCoords(mapsurface.get_scale(), mapsurface.get_coords()) if len(world.list_of_capitals) != len(world.list_of_province): world.add_capital(map_capital_coords, province) else: province.set_capital_coords(map_capital_coords) world.list_of_capitals[-1] = map_capital_coords
def addPolygon(self, coords: ScreenCoords, mapsurface: pygame.Surface) -> None: self.polygons.append( coords.toMapCoords(mapsurface.get_scale(), mapsurface.get_coords()))