-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathList.py
79 lines (60 loc) · 2.04 KB
/
List.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import pygame;
import Data;
import Graphics;
import Service;
class List:
def __init__(self, values):
self.values = values;
self.index = 0;
self.surface = pygame.Surface((128, Graphics.height - 32));
self.Redraw();
def Click(self, pos):
self.Selected((pos[1] - 32) // 16 + self.index);
def Draw(self, screen):
screen.blit(self.surface, (Graphics.width - 128, 32));
def Redraw(self):
self.surface.fill((222, 222, 222));
i = 0;
for value in self.values[self.index : self.index + Graphics.height // 16]:
text = Graphics.font.render(value, 1, (0, 0, 0));
textpos = text.get_rect().move((0, i * 16));
self.surface.blit(text, textpos);
i += 1;
def Scroll(self, direction):
self.index += direction;
if self.index < 0:
self.index = 0;
if self.index > len(self.values):
self.index = len(self.values);
self.Redraw();
def Selected(self, item):
pass;
# the stops of the selected train / service
class StopsList(List):
# train: either a Service's name or Train object
def __init__(self, train):
if train in Service.services:
self.train = None;
self.service = Service.services[train].orders;
else:
self.train = train;
self.service = train.service;
List.__init__(self, ["{}:{} {}".format(int(order[0] // 60), int(order[0] % 60), Data.Place(order[1])) for order in self.service]);
# scroll to the current order
if self.train:
self.index = self.train.order;
self.Redraw();
def Selected(self, item):
if 0 <= item < len(self.values):
station = Data.nodes[Data.places[Data.Place(self.service[item][1])]].station;
if station:
Graphics.selectedList = TrainsList(station);
# the trains at this station
class TrainsList(List):
def __init__(self, station):
self.station = station;
self.departures = list(station.DeparturesFrom(0));
List.__init__(self, [str(service) for service in self.departures]);
def Selected(self, item):
if 0 <= item < len(self.values) and self.departures[item] in Service.services:
Graphics.selectedList = StopsList(self.departures[item]);