|
@@ -42,50 +42,51 @@ class Manager:
|
42
|
42
|
keys = self.input.get()
|
43
|
43
|
|
44
|
44
|
if keys["l"] and (not self.old_keys["l"]):
|
45
|
|
- c = self.screens[self.index][0]
|
46
|
|
- if hasattr(c, "switch_to") and hasattr(c, "child_count"):
|
47
|
|
- if c.child_count(-1):
|
48
|
|
- self.switch_to(-1, False)
|
49
|
|
- else:
|
50
|
|
- c.switch_to(-1, False)
|
51
|
|
- else:
|
52
|
|
- self.switch_to(-1, False)
|
|
45
|
+ self.switch_to(-1, False)
|
53
|
46
|
elif keys["r"] and (not self.old_keys["r"]):
|
54
|
|
- c = self.screens[self.index][0]
|
55
|
|
- if hasattr(c, "switch_to") and hasattr(c, "child_count"):
|
56
|
|
- if c.child_count(1):
|
57
|
|
- self.switch_to(1, False)
|
58
|
|
- else:
|
59
|
|
- c.switch_to(1, False)
|
60
|
|
- else:
|
61
|
|
- self.switch_to(1, False)
|
|
47
|
+ self.switch_to(1, False)
|
62
|
48
|
|
63
|
49
|
self.old_keys = keys.copy()
|
64
|
50
|
|
65
|
|
- def child_count(self, i):
|
|
51
|
+ def child_count(self, i, update_flag):
|
66
|
52
|
if i > 0:
|
67
|
|
- index = int(self.index / self.step_size)
|
68
|
|
- l = int(len(self.screens) / self.step_size)
|
|
53
|
+ if update_flag:
|
|
54
|
+ index = self.index
|
|
55
|
+ l = len(self.screens)
|
|
56
|
+ else:
|
|
57
|
+ index = int(self.index / self.step_size)
|
|
58
|
+ l = int(len(self.screens) / self.step_size)
|
|
59
|
+ #print(self.index, len(self.screens), index, l, (index >= (l - 1)))
|
69
|
60
|
return index >= (l - 1)
|
70
|
61
|
else:
|
71
|
62
|
return self.index <= 0
|
72
|
63
|
|
73
|
|
- def switch_to(self, i, update_flag):
|
|
64
|
+ def switch_this_to(self, i, update_flag):
|
74
|
65
|
self.lastTime = time.time()
|
75
|
66
|
|
76
|
67
|
if update_flag:
|
77
|
|
- self.done = (self.index == 0)
|
78
|
|
-
|
79
|
68
|
# go through all for normal operation
|
80
|
69
|
self.index = (self.index + i) % len(self.screens)
|
81
|
70
|
else:
|
82
|
71
|
# use step_size for button presses
|
83
|
72
|
self.index = int((int(self.index / self.step_size) + i) * self.step_size) % len(self.screens)
|
84
|
73
|
|
|
74
|
+ self.done = self.child_count(i, update_flag)
|
|
75
|
+
|
85
|
76
|
#print("Manager ", len(self.screens), " switch to ", self.index, update_flag)
|
86
|
77
|
|
87
|
78
|
self.screens[self.index][0].restart()
|
88
|
79
|
|
|
80
|
+ def switch_to(self, i, update_flag):
|
|
81
|
+ c = self.screens[self.index][0]
|
|
82
|
+ if hasattr(c, "switch_to") and hasattr(c, "child_count"):
|
|
83
|
+ if c.child_count(i, update_flag):
|
|
84
|
+ self.switch_this_to(i, update_flag)
|
|
85
|
+ else:
|
|
86
|
+ c.switch_to(i, update_flag)
|
|
87
|
+ else:
|
|
88
|
+ self.switch_this_to(i, update_flag)
|
|
89
|
+
|
89
|
90
|
def draw(self):
|
90
|
91
|
if self.input != None:
|
91
|
92
|
self.buttons()
|
|
@@ -117,15 +118,15 @@ if __name__ == "__main__":
|
117
|
118
|
splash.draw()
|
118
|
119
|
t.loop_end()
|
119
|
120
|
|
120
|
|
- m = Manager(t, i)
|
121
|
|
-
|
122
|
121
|
sub = Manager(t)
|
123
|
122
|
sub.add(ScrollText(t, "Hello", "ib8x8u"))
|
124
|
123
|
sub.add(Solid(t, 1.0, (0, 255, 0)))
|
125
|
124
|
sub.add(ScrollText(t, "World", "ib8x8u"))
|
126
|
125
|
sub.add(Solid(t, 1.0, (0, 0, 255)))
|
|
126
|
+
|
|
127
|
+ m = Manager(t, i)
|
127
|
128
|
m.add(sub)
|
128
|
|
- m.add(Solid(t, 1.0))
|
|
129
|
+ m.add(Solid(t, 1.0, (255, 255, 0)))
|
129
|
130
|
|
130
|
131
|
m.add(ScrollText(t, "This appears once", "ib8x8u"))
|
131
|
132
|
m.add(Solid(t, 1.0))
|