Browse Source

manager can be nested in itself

Thomas Buck 1 year ago
parent
commit
89a4491139
2 changed files with 20 additions and 4 deletions
  1. 19
    3
      manager.py
  2. 1
    1
      test.py

+ 19
- 3
manager.py View File

13
     def __init__(self, g):
13
     def __init__(self, g):
14
         self.gui = g
14
         self.gui = g
15
         self.screens = []
15
         self.screens = []
16
-        self.index = 0
17
         self.restart()
16
         self.restart()
18
 
17
 
19
     def restart(self):
18
     def restart(self):
19
+        self.index = 0
20
+        self.done = False
20
         self.lastTime = time.time()
21
         self.lastTime = time.time()
22
+        if len(self.screens) > 0:
23
+            self.screens[0][0].restart()
24
+
25
+    def finished(self):
26
+        return self.done
21
 
27
 
22
     def add(self, s, d = None):
28
     def add(self, s, d = None):
23
         v = (s, d)
29
         v = (s, d)
24
         self.screens.append(v)
30
         self.screens.append(v)
25
 
31
 
26
-    def loop(self):
32
+    def draw(self):
27
         self.screens[self.index][0].draw()
33
         self.screens[self.index][0].draw()
28
 
34
 
29
         if self.screens[self.index][1] == None:
35
         if self.screens[self.index][1] == None:
31
             if self.screens[self.index][0].finished():
37
             if self.screens[self.index][0].finished():
32
                 self.lastTime = time.time()
38
                 self.lastTime = time.time()
33
                 self.index = (self.index + 1) % len(self.screens)
39
                 self.index = (self.index + 1) % len(self.screens)
40
+                self.done = (self.index == 0)
34
                 self.screens[self.index][0].restart()
41
                 self.screens[self.index][0].restart()
35
         else:
42
         else:
36
             # use given timeout
43
             # use given timeout
37
             if (time.time() - self.lastTime) > self.screens[self.index][1]:
44
             if (time.time() - self.lastTime) > self.screens[self.index][1]:
38
                 self.lastTime = time.time()
45
                 self.lastTime = time.time()
39
                 self.index = (self.index + 1) % len(self.screens)
46
                 self.index = (self.index + 1) % len(self.screens)
47
+                self.done = (self.index == 0)
40
                 self.screens[self.index][0].restart()
48
                 self.screens[self.index][0].restart()
41
 
49
 
42
 if __name__ == "__main__":
50
 if __name__ == "__main__":
68
     m.add(GameOfLife(t, 20, (0, 255, 0), (0, 0, 0), 20.0, True))
76
     m.add(GameOfLife(t, 20, (0, 255, 0), (0, 0, 0), 20.0, True))
69
     m.add(Solid(t, 1.0))
77
     m.add(Solid(t, 1.0))
70
 
78
 
79
+    sub = Manager(t)
80
+    sub.add(ScrollText(t, "Hello"))
81
+    sub.add(Solid(t, 1.0, (0, 255, 0)))
82
+    sub.add(ScrollText(t, "World"))
83
+    sub.add(Solid(t, 1.0, (0, 0, 255)))
84
+    m.add(sub)
85
+    m.add(Solid(t, 1.0))
86
+
71
     m.restart()
87
     m.restart()
72
-    t.debug_loop(m.loop)
88
+    t.debug_loop(m.draw)

+ 1
- 1
test.py View File

33
 
33
 
34
     def loop_end(self):
34
     def loop_end(self):
35
         pygame.display.flip()
35
         pygame.display.flip()
36
-        self.clock.tick(60)
36
+        self.clock.tick(30)
37
 
37
 
38
     def debug_loop(self, func = None):
38
     def debug_loop(self, func = None):
39
         while True:
39
         while True:

Loading…
Cancel
Save