1- import pypboy
2- import pypboy .data
31import pygame
4- import threading
5- import game
2+ import pypboy
63import config
74
5+ from pypboy .modules .data import entities
6+
87
98class Module (pypboy .SubModule ):
109
1110 label = "Local Map"
1211
1312 def __init__ (self , * args , ** kwargs ):
1413 super (Module , self ).__init__ (* args , ** kwargs )
15- mapgrid = MapGrid ((- 5.9302032 , 54.5966701 ), (config .WIDTH - 8 , config .HEIGHT - 80 ))
14+ #mapgrid = entities.MapGrid((-5.9302032, 54.5966701), (config.WIDTH - 8, config.HEIGHT - 80))
15+ mapgrid = entities .Map (config .WIDTH , pygame .Rect (4 , (config .WIDTH - config .HEIGHT ) / 2 , config .WIDTH - 8 , config .HEIGHT - 80 ))
16+ mapgrid .fetch_map (config .MAP_FOCUS , 0.003 )
1617 self .add (mapgrid )
1718 mapgrid .rect [0 ] = 4
1819 mapgrid .rect [1 ] = 40
1920
2021 def handle_resume (self ):
2122 self .parent .pypboy .header .headline = "DATA"
22- self .parent .pypboy .header .title = "Farset's Mouth"
23- super (Module , self ).handle_resume ()
24-
25-
26- class MapSquare (game .Entity ):
27- _mapper = None
28- _size = 0
29- _fetching = None
30- _map_surface = None
31- map_position = (0 , 0 )
32-
33- def __init__ (self , size , map_position , parent , * args , ** kwargs ):
34- self ._mapper = pypboy .data .Maps ()
35- self ._size = size
36- self .parent = parent
37- self ._map_surface = pygame .Surface ((size * 2 , size * 2 ))
38- self .map_position = map_position
39- self .tags = {}
40- super (MapSquare , self ).__init__ ((size , size ), * args , ** kwargs )
41-
42- def fetch_map (self ):
43- self ._fetching = threading .Thread (target = self ._internal_fetch_map )
44- self ._fetching .start ()
45-
46- def _internal_fetch_map (self ):
47- self ._mapper .fetch_grid (self .map_position )
48- self .redraw_map ()
49- self .parent .redraw_map ()
50-
51- def redraw_map (self , coef = 1 ):
52- self ._map_surface .fill ((0 , 0 , 0 ))
53- for way in self ._mapper .transpose_ways ((self ._size , self ._size ), (self ._size / 2 , self ._size / 2 )):
54- pygame .draw .lines (
55- self ._map_surface ,
56- (85 , 251 , 167 ),
57- False ,
58- way ,
59- 1
60- )
61- for tag in self ._mapper .transpose_tags ((self ._size , self ._size ), (self ._size / 2 , self ._size / 2 )):
62- self .tags [tag [0 ]] = (tag [1 ] + self .position [0 ], tag [2 ] + self .position [1 ], tag [3 ])
63- self .image .fill ((0 , 0 , 0 ))
64- self .image .blit (self ._map_surface , (- self ._size / 2 , - self ._size / 2 ))
65-
66-
67- class MapGrid (game .Entity ):
68-
69- _grid = None
70- _delta = 0.002
71- _starting_position = (0 , 0 )
72-
73- def __init__ (self , starting_position , dimensions , * args , ** kwargs ):
74- self ._grid = []
75- self ._starting_position = starting_position
76- self .dimensions = dimensions
77- self ._tag_surface = pygame .Surface (dimensions )
78- super (MapGrid , self ).__init__ (dimensions , * args , ** kwargs )
79- self .tags = {}
80- self .fetch_outwards ()
81-
82- def test_fetch (self ):
83- for x in range (10 ):
84- for y in range (5 ):
85- square = MapSquare (
86- 100 ,
87- (
88- self ._starting_position [0 ] + (self ._delta * x ),
89- self ._starting_position [1 ] - (self ._delta * y )
90- )
91- )
92- square .fetch_map ()
93- square .position = (100 * x , 100 * y )
94- self ._grid .append (square )
95-
96- def fetch_outwards (self ):
97- for x in range (- 4 , 4 ):
98- for y in range (- 2 , 2 ):
99- square = MapSquare (
100- 86 ,
101- (
102- self ._starting_position [0 ] + (self ._delta * x ),
103- self ._starting_position [1 ] - (self ._delta * y )
104- ),
105- self
106- )
107- square .fetch_map ()
108- square .position = ((86 * x ) + (self .dimensions [0 ] / 2 ) - 43 , (86 * y ) + (self .dimensions [1 ] / 2 ) - 43 )
109- self ._grid .append (square )
110-
111-
112- def draw_tags (self ):
113- self .tags = {}
114- for square in self ._grid :
115- self .tags .update (square .tags )
116- self ._tag_surface .fill ((0 , 0 , 0 ))
117- for name in self .tags :
118- if self .tags [name ][2 ] in config .AMENITIES :
119- image = config .AMENITIES [self .tags [name ][2 ]]
120- else :
121- print "Unknown amenity: %s" % self .tags [name ][2 ]
122- image = config .MAP_ICONS ['misc' ]
123- pygame .transform .scale (image , (10 , 10 ))
124- self .image .blit (image , (self .tags [name ][0 ], self .tags [name ][1 ]))
125- # try:
126- basicFont = pygame .font .SysFont (None , 12 )
127- text = basicFont .render (name , True , (95 , 255 , 177 ), (0 , 0 , 0 ))
128- # text_width = text.get_size()[0]
129- # pygame.draw.rect(
130- # self,
131- # (0, 0, 0),
132- # (self.tags[name][0], self.tags[name][1], text_width + 4, 15),
133- # 0
134- # )
135- self .image .blit (text , (self .tags [name ][0 ] + 17 , self .tags [name ][1 ] + 4 ))
136- # pygame.draw.rect(
137- # self,
138- # (95, 255, 177),
139- # (self.tags[name][0], self.tags[name][1], text_width + 4, 15),
140- # 1
141- # )
142- # except Exception, e:
143- # print(e)
144- # pass
145-
146- def redraw_map (self , * args , ** kwargs ):
147- self .image .fill ((0 , 0 , 0 ))
148- for square in self ._grid :
149- self .image .blit (square ._map_surface , square .position )
150- self .draw_tags ()
23+ self .parent .pypboy .header .title = "City Centre"
24+ super (Module , self ).handle_resume ()
0 commit comments