batframework 1.0.9a11__py3-none-any.whl → 1.0.9a12__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- batFramework/__init__.py +2 -0
- batFramework/action.py +280 -279
- batFramework/actionContainer.py +105 -82
- batFramework/animatedSprite.py +80 -58
- batFramework/animation.py +91 -77
- batFramework/audioManager.py +156 -131
- batFramework/baseScene.py +249 -240
- batFramework/camera.py +245 -317
- batFramework/constants.py +57 -51
- batFramework/cutscene.py +239 -253
- batFramework/cutsceneManager.py +34 -34
- batFramework/drawable.py +107 -77
- batFramework/dynamicEntity.py +30 -30
- batFramework/easingController.py +58 -58
- batFramework/entity.py +130 -130
- batFramework/enums.py +171 -135
- batFramework/fontManager.py +65 -65
- batFramework/gui/__init__.py +28 -25
- batFramework/gui/animatedLabel.py +90 -89
- batFramework/gui/button.py +17 -17
- batFramework/gui/clickableWidget.py +244 -244
- batFramework/gui/collapseContainer.py +98 -0
- batFramework/gui/constraints/__init__.py +1 -1
- batFramework/gui/constraints/constraints.py +1066 -980
- batFramework/gui/container.py +220 -206
- batFramework/gui/debugger.py +140 -130
- batFramework/gui/draggableWidget.py +63 -44
- batFramework/gui/image.py +61 -58
- batFramework/gui/indicator.py +116 -113
- batFramework/gui/interactiveWidget.py +243 -239
- batFramework/gui/label.py +147 -344
- batFramework/gui/layout.py +442 -429
- batFramework/gui/meter.py +155 -96
- batFramework/gui/radioButton.py +43 -35
- batFramework/gui/root.py +228 -228
- batFramework/gui/scrollingContainer.py +282 -0
- batFramework/gui/selector.py +232 -250
- batFramework/gui/shape.py +286 -276
- batFramework/gui/slider.py +353 -397
- batFramework/gui/style.py +10 -10
- batFramework/gui/styleManager.py +49 -54
- batFramework/gui/syncedVar.py +43 -49
- batFramework/gui/textInput.py +331 -306
- batFramework/gui/textWidget.py +308 -0
- batFramework/gui/toggle.py +140 -128
- batFramework/gui/tooltip.py +35 -30
- batFramework/gui/widget.py +546 -521
- batFramework/manager.py +131 -134
- batFramework/particle.py +118 -118
- batFramework/propertyEaser.py +79 -79
- batFramework/renderGroup.py +34 -34
- batFramework/resourceManager.py +130 -130
- batFramework/scene.py +31 -31
- batFramework/sceneLayer.py +134 -138
- batFramework/sceneManager.py +200 -197
- batFramework/scrollingSprite.py +115 -115
- batFramework/sprite.py +46 -51
- batFramework/stateMachine.py +49 -54
- batFramework/templates/__init__.py +2 -1
- batFramework/templates/character.py +15 -0
- batFramework/templates/controller.py +158 -97
- batFramework/templates/stateMachine.py +39 -0
- batFramework/tileset.py +46 -46
- batFramework/timeManager.py +213 -213
- batFramework/transition.py +162 -162
- batFramework/triggerZone.py +22 -22
- batFramework/utils.py +306 -306
- {batframework-1.0.9a11.dist-info → batframework-1.0.9a12.dist-info}/LICENSE +20 -20
- {batframework-1.0.9a11.dist-info → batframework-1.0.9a12.dist-info}/METADATA +24 -17
- batframework-1.0.9a12.dist-info/RECORD +72 -0
- batframework-1.0.9a11.dist-info/RECORD +0 -67
- {batframework-1.0.9a11.dist-info → batframework-1.0.9a12.dist-info}/WHEEL +0 -0
- {batframework-1.0.9a11.dist-info → batframework-1.0.9a12.dist-info}/top_level.txt +0 -0
batFramework/gui/container.py
CHANGED
@@ -1,206 +1,220 @@
|
|
1
|
-
import pygame
|
2
|
-
import batFramework as bf
|
3
|
-
from .widget import Widget
|
4
|
-
from .shape import Shape
|
5
|
-
from .interactiveWidget import InteractiveWidget
|
6
|
-
from .layout import Layout, Column
|
7
|
-
from typing import Self
|
8
|
-
from pygame.math import Vector2
|
9
|
-
|
10
|
-
|
11
|
-
class Container(Shape, InteractiveWidget):
|
12
|
-
def __init__(self, layout: Layout = None, *children: Widget) -> None:
|
13
|
-
super().__init__()
|
14
|
-
self.dirty_layout: bool = False
|
15
|
-
self.
|
16
|
-
self.layout
|
17
|
-
self.
|
18
|
-
self.
|
19
|
-
self.
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
self.scroll
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
self.scroll
|
38
|
-
|
39
|
-
self.
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
self.
|
46
|
-
return self
|
47
|
-
|
48
|
-
def
|
49
|
-
if
|
50
|
-
return self
|
51
|
-
self.set_scroll((self.scroll.x, self.scroll.y
|
52
|
-
return self
|
53
|
-
|
54
|
-
def
|
55
|
-
if
|
56
|
-
return self
|
57
|
-
self.set_scroll((self.scroll.x
|
58
|
-
return self
|
59
|
-
|
60
|
-
def
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
return self
|
93
|
-
|
94
|
-
def
|
95
|
-
self.
|
96
|
-
self.
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
return self
|
103
|
-
|
104
|
-
def
|
105
|
-
|
106
|
-
self.
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
def
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
if
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
return
|
153
|
-
|
154
|
-
def
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
def
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
self.
|
183
|
-
self.
|
184
|
-
self.
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
self.
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
self.
|
204
|
-
|
205
|
-
|
206
|
-
|
1
|
+
import pygame
|
2
|
+
import batFramework as bf
|
3
|
+
from .widget import Widget
|
4
|
+
from .shape import Shape
|
5
|
+
from .interactiveWidget import InteractiveWidget
|
6
|
+
from .layout import Layout, Column
|
7
|
+
from typing import Self
|
8
|
+
from pygame.math import Vector2
|
9
|
+
|
10
|
+
|
11
|
+
class Container(Shape, InteractiveWidget):
|
12
|
+
def __init__(self, layout: Layout = None, *children: Widget) -> None:
|
13
|
+
super().__init__()
|
14
|
+
self.dirty_layout: bool = False
|
15
|
+
self.layout = layout if layout else Column()
|
16
|
+
self.layout.set_parent(self)
|
17
|
+
self.scroll = Vector2(0, 0)
|
18
|
+
self.dirty_scroll = False
|
19
|
+
self.set_debug_color("green")
|
20
|
+
self.add(*children)
|
21
|
+
|
22
|
+
|
23
|
+
def __str__(self) -> str:
|
24
|
+
return f"Container({self.uid},{len(self.children)})"
|
25
|
+
|
26
|
+
def get_min_required_size(self):
|
27
|
+
return self.layout.get_auto_size() if self.layout else self.rect.size
|
28
|
+
|
29
|
+
def reset_scroll(self) -> Self:
|
30
|
+
if self.scroll == (0,0):
|
31
|
+
return self
|
32
|
+
self.set_scroll((0, 0))
|
33
|
+
return self
|
34
|
+
|
35
|
+
def set_scroll(self, value: tuple[float]) -> Self:
|
36
|
+
# print("Trying to set scroll to ",value)
|
37
|
+
# print("Current scroll is : ",self.scroll)
|
38
|
+
|
39
|
+
if (self.scroll.x,self.scroll.y) == value:
|
40
|
+
return self
|
41
|
+
self.scroll.update(value)
|
42
|
+
# print("Scroll updated to", value)
|
43
|
+
self.clamp_scroll()
|
44
|
+
self.dirty_scroll = True
|
45
|
+
# self.dirty_layout = True
|
46
|
+
return self
|
47
|
+
|
48
|
+
def scrollX_by(self, x: float) -> Self:
|
49
|
+
if x == 0:
|
50
|
+
return self
|
51
|
+
self.set_scroll((self.scroll.x + x, self.scroll.y))
|
52
|
+
return self
|
53
|
+
|
54
|
+
def scrollY_by(self, y: float) -> Self:
|
55
|
+
if y == 0:
|
56
|
+
return self
|
57
|
+
self.set_scroll((self.scroll.x, self.scroll.y + y))
|
58
|
+
return self
|
59
|
+
|
60
|
+
def scroll_by(self, value: tuple[float]) -> Self:
|
61
|
+
self.set_scroll((self.scroll.x + value[0], self.scroll.y + value[1]))
|
62
|
+
return self
|
63
|
+
|
64
|
+
def clamp_scroll(self) -> Self:
|
65
|
+
if not self.children:
|
66
|
+
return self
|
67
|
+
r = self.get_inner_rect()
|
68
|
+
|
69
|
+
if self.layout:
|
70
|
+
# self.layout.update_children_rect()
|
71
|
+
children_rect = self.layout.children_rect
|
72
|
+
else:
|
73
|
+
l = self.get_layout_children()
|
74
|
+
if l:
|
75
|
+
children_rect = l[0].rect.unionall(
|
76
|
+
[c.rect for c in l[1:]]
|
77
|
+
) if len(l) > 1 else l
|
78
|
+
else:
|
79
|
+
children_rect = pygame.Rect(0,0,0,0)
|
80
|
+
|
81
|
+
max_scroll_x = max(0, children_rect.width - r.width)
|
82
|
+
max_scroll_y = max(0, children_rect.height - r.height)
|
83
|
+
|
84
|
+
sx = min(max(self.scroll.x, 0), max_scroll_x)
|
85
|
+
sy = min(max(self.scroll.y, 0), max_scroll_y)
|
86
|
+
# print("_"*20)
|
87
|
+
# print("Clamping scroll, children rect is :",children_rect)
|
88
|
+
# print("scroll to,",(sx,sy), "while current scroll is",self.scroll)
|
89
|
+
|
90
|
+
self.set_scroll((sx,sy))
|
91
|
+
|
92
|
+
return self
|
93
|
+
|
94
|
+
def set_layout(self, layout: Layout) -> Self:
|
95
|
+
tmp = self.layout
|
96
|
+
self.layout = layout
|
97
|
+
if self.layout != tmp:
|
98
|
+
tmp.set_parent(None)
|
99
|
+
self.layout.set_parent(self)
|
100
|
+
self.reset_scroll()
|
101
|
+
self.dirty_layout = True
|
102
|
+
return self
|
103
|
+
|
104
|
+
def get_interactive_children(self) -> list[InteractiveWidget]:
|
105
|
+
"""Return all children that can be cycled through with focus"""
|
106
|
+
return [child for child in self.get_layout_children() \
|
107
|
+
if isinstance(child, InteractiveWidget) and not\
|
108
|
+
isinstance(child,Container) and child.allow_focus_to_self()]
|
109
|
+
|
110
|
+
def get_layout_children(self)->list[Widget]:
|
111
|
+
"""Returns all children affected by layout"""
|
112
|
+
return self.children
|
113
|
+
|
114
|
+
def clear_children(self) -> None:
|
115
|
+
for child in self.children:
|
116
|
+
child.set_parent(None)
|
117
|
+
self.children.clear()
|
118
|
+
self.dirty_layout = True
|
119
|
+
|
120
|
+
def add(self, *child: Widget) -> Self:
|
121
|
+
super().add(*child)
|
122
|
+
self.dirty_shape = True
|
123
|
+
self.dirty_layout = True
|
124
|
+
return self
|
125
|
+
|
126
|
+
def remove(self, *child: Widget) -> Self:
|
127
|
+
super().remove(*child)
|
128
|
+
self.dirty_shape = True
|
129
|
+
self.dirty_layout = True
|
130
|
+
return self
|
131
|
+
|
132
|
+
def top_at(self, x: float | int, y: float | int) -> "None|Widget":
|
133
|
+
if self.rect.collidepoint(x, y):
|
134
|
+
for child in reversed(self.children):
|
135
|
+
result = child.top_at(x, y)
|
136
|
+
if result is not None:
|
137
|
+
return result
|
138
|
+
return self
|
139
|
+
return None
|
140
|
+
|
141
|
+
def get_focus(self) -> bool:
|
142
|
+
if not super().get_focus():
|
143
|
+
return False
|
144
|
+
interactive_children = self.get_interactive_children()
|
145
|
+
if not interactive_children:
|
146
|
+
return True
|
147
|
+
self.focused_index = min(self.focused_index, len(interactive_children) - 1)
|
148
|
+
return interactive_children[self.focused_index].get_focus()
|
149
|
+
|
150
|
+
def children_has_focus(self)->bool:
|
151
|
+
"""Return true if any direct children is focused"""
|
152
|
+
return any(child.is_focused for child in self.get_interactive_children())
|
153
|
+
|
154
|
+
def handle_event(self, event) -> None:
|
155
|
+
super().handle_event(event)
|
156
|
+
self.layout.handle_event(event)
|
157
|
+
|
158
|
+
def set_focused_child(self, child: InteractiveWidget) -> bool:
|
159
|
+
interactive_children = self.get_interactive_children()
|
160
|
+
try:
|
161
|
+
index = interactive_children.index(child)
|
162
|
+
self.focused_index = index
|
163
|
+
if self.layout :
|
164
|
+
self.layout.scroll_to_widget(child)
|
165
|
+
return True
|
166
|
+
except ValueError:
|
167
|
+
return False
|
168
|
+
|
169
|
+
def allow_focus_to_self(self) -> bool:
|
170
|
+
"""Return whether the container can get focused"""
|
171
|
+
return bool(self.get_interactive_children()) and self.visible
|
172
|
+
|
173
|
+
def build(self) -> None:
|
174
|
+
if self.layout is not None:
|
175
|
+
size = self.layout.get_auto_size()
|
176
|
+
self.set_size(self.resolve_size(size))
|
177
|
+
super().build()
|
178
|
+
|
179
|
+
|
180
|
+
def apply_pre_updates(self):
|
181
|
+
if self.dirty_size_constraints or self.dirty_shape:
|
182
|
+
self.resolve_constraints(size_only=True)
|
183
|
+
self.dirty_size_constraints = False
|
184
|
+
self.dirty_position_constraints = True
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
if self.dirty_layout:
|
189
|
+
self.layout.update_child_constraints()
|
190
|
+
self.layout.arrange()
|
191
|
+
self.dirty_layout = False
|
192
|
+
|
193
|
+
if self.dirty_scroll:
|
194
|
+
self.layout.scroll_children()
|
195
|
+
self.dirty_scroll = False
|
196
|
+
|
197
|
+
def apply_post_updates(self,skip_draw:bool=False):
|
198
|
+
if self.dirty_shape:
|
199
|
+
self.layout.update_child_constraints()
|
200
|
+
self.build()
|
201
|
+
self.dirty_size_constraints = True
|
202
|
+
self.dirty_position_constraints = True
|
203
|
+
self.dirty_layout = True
|
204
|
+
from .container import Container
|
205
|
+
if self.parent and isinstance(self.parent, Container):
|
206
|
+
self.parent.dirty_layout = True
|
207
|
+
self.parent.dirty_shape = True
|
208
|
+
self.dirty_shape = False
|
209
|
+
self.dirty_surface = True
|
210
|
+
|
211
|
+
if self.dirty_position_constraints:
|
212
|
+
self.resolve_constraints(position_only=True)
|
213
|
+
self.dirty_position_constraints= False
|
214
|
+
|
215
|
+
|
216
|
+
if self.dirty_surface and not skip_draw:
|
217
|
+
self.paint()
|
218
|
+
self.dirty_surface = False
|
219
|
+
|
220
|
+
|