batframework 1.0.9a11__py3-none-any.whl → 1.0.9a13__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 +3 -11
- 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.9a13.dist-info}/LICENSE +20 -20
- {batframework-1.0.9a11.dist-info → batframework-1.0.9a13.dist-info}/METADATA +24 -17
- batframework-1.0.9a13.dist-info/RECORD +72 -0
- batframework-1.0.9a11.dist-info/RECORD +0 -67
- {batframework-1.0.9a11.dist-info → batframework-1.0.9a13.dist-info}/WHEEL +0 -0
- {batframework-1.0.9a11.dist-info → batframework-1.0.9a13.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,282 @@
|
|
1
|
+
from typing import Self
|
2
|
+
import pygame
|
3
|
+
from .slider import Slider
|
4
|
+
import batFramework as bf
|
5
|
+
from .syncedVar import SyncedVar
|
6
|
+
from .container import Container
|
7
|
+
from .constraints.constraints import FillX, FillY
|
8
|
+
from .widget import Widget
|
9
|
+
from .shape import Shape
|
10
|
+
|
11
|
+
class ScrollBar(Slider):
|
12
|
+
def do_when_added(self):
|
13
|
+
super().do_when_added()
|
14
|
+
self.meter.add_constraints(FillX(), FillY())
|
15
|
+
self.set_clip_children(False)
|
16
|
+
self.set_pressed_relief(0).set_unpressed_relief(0)
|
17
|
+
self.meter.content.set_color(None)
|
18
|
+
|
19
|
+
def __str__(self):
|
20
|
+
return "Scrollbar"
|
21
|
+
|
22
|
+
def _on_synced_var_update(self, value):
|
23
|
+
self.dirty_shape = True # build uses synced var directly so we just trigger build via dirty shape
|
24
|
+
if self.modify_callback:
|
25
|
+
self.modify_callback(value)
|
26
|
+
|
27
|
+
def on_get_focus(self) -> None:
|
28
|
+
self.is_focused = True
|
29
|
+
self.do_on_get_focus()
|
30
|
+
|
31
|
+
def draw_focused(self, camera):
|
32
|
+
return
|
33
|
+
|
34
|
+
def paint(self) -> None:
|
35
|
+
Shape.paint(self)
|
36
|
+
|
37
|
+
|
38
|
+
class ScrollingContainer(Container):
|
39
|
+
"""
|
40
|
+
Should work for single and double axis standard layouts
|
41
|
+
"""
|
42
|
+
def __init__(self, layout=None, *children):
|
43
|
+
super().__init__(layout, *children)
|
44
|
+
self.sync_scroll_x= SyncedVar(0) # 0 to 1
|
45
|
+
self.sync_scroll_y= SyncedVar(0) # 0 to 1
|
46
|
+
|
47
|
+
self.scrollbar_size = 8
|
48
|
+
self.scrollbars_needed = [False, False] # [horizontal, vertical]
|
49
|
+
|
50
|
+
# Create scrollbars
|
51
|
+
self.y_scrollbar = (
|
52
|
+
ScrollBar("", 0, synced_var=self.sync_scroll_y)
|
53
|
+
.set_axis(bf.axis.VERTICAL)
|
54
|
+
.set_autoresize(False)
|
55
|
+
.set_padding(0)
|
56
|
+
.set_direction(bf.direction.DOWN)
|
57
|
+
.set_step(0.01)
|
58
|
+
)
|
59
|
+
self.y_scrollbar.meter.handle.set_autoresize_h(False)
|
60
|
+
|
61
|
+
self.x_scrollbar = (
|
62
|
+
ScrollBar("", 0, synced_var=self.sync_scroll_x)
|
63
|
+
.set_autoresize(False)
|
64
|
+
.set_padding(0)
|
65
|
+
.set_step(0.01)
|
66
|
+
)
|
67
|
+
|
68
|
+
self.x_scrollbar.meter.handle.set_autoresize_w(False)
|
69
|
+
|
70
|
+
self.sync_scroll_x.bind(self,lambda v : self.on_sync_update((v,self.sync_scroll_y.value)))
|
71
|
+
self.sync_scroll_y.bind(self,lambda v : self.on_sync_update((self.sync_scroll_x.value,v)))
|
72
|
+
|
73
|
+
|
74
|
+
# Add scrollbars but initially hide them
|
75
|
+
self.add(
|
76
|
+
self.y_scrollbar,
|
77
|
+
self.x_scrollbar
|
78
|
+
)
|
79
|
+
self.x_scrollbar.hide()
|
80
|
+
self.y_scrollbar.hide()
|
81
|
+
|
82
|
+
def __str__(self):
|
83
|
+
return "Scrolling"+ super().__str__()
|
84
|
+
|
85
|
+
def set_scroll(self,value):
|
86
|
+
# print("Scrolling set scroll called", value)
|
87
|
+
self.sync_scroll_x.value = self.x_scroll_scaled_to_normalized(value[0])
|
88
|
+
self.sync_scroll_y.value = self.y_scroll_scaled_to_normalized(value[1])
|
89
|
+
|
90
|
+
|
91
|
+
def on_sync_update(self,value):
|
92
|
+
# print("Scrolling on sync update called", value)
|
93
|
+
value = [self.x_scroll_normalized_to_scaled(value[0]),self.y_scroll_normalized_to_scaled(value[1])]
|
94
|
+
super().set_scroll(value)
|
95
|
+
|
96
|
+
|
97
|
+
def set_scrollbar_size(self, size:int)->Self:
|
98
|
+
self.scrollbar_size = size
|
99
|
+
self.dirty_layout= True
|
100
|
+
self.dirty_shape = True
|
101
|
+
return self
|
102
|
+
|
103
|
+
def y_scroll_normalized_to_scaled(self, value):
|
104
|
+
inner_height = self.get_inner_height()
|
105
|
+
content_height = self.layout.children_rect.h # total content height
|
106
|
+
|
107
|
+
max_scroll = max(0, content_height - inner_height)
|
108
|
+
converted_y = value * max_scroll
|
109
|
+
|
110
|
+
return converted_y
|
111
|
+
|
112
|
+
def x_scroll_normalized_to_scaled(self, value):
|
113
|
+
inner_width = self.get_inner_width()
|
114
|
+
content_width = self.layout.children_rect.w # total content width
|
115
|
+
|
116
|
+
max_scroll = max(0, content_width - inner_width)
|
117
|
+
converted_x = value * max_scroll
|
118
|
+
|
119
|
+
return converted_x
|
120
|
+
|
121
|
+
def y_scroll_scaled_to_normalized(self, value):
|
122
|
+
inner_height = self.get_inner_height()
|
123
|
+
content_height = self.layout.children_rect.h
|
124
|
+
|
125
|
+
max_scroll = max(0, content_height - inner_height)
|
126
|
+
if max_scroll == 0:
|
127
|
+
return 0
|
128
|
+
return value / max_scroll
|
129
|
+
|
130
|
+
def x_scroll_scaled_to_normalized(self, value):
|
131
|
+
inner_width = self.get_inner_width()
|
132
|
+
content_width = self.layout.children_rect.w
|
133
|
+
|
134
|
+
max_scroll = max(0, content_width - inner_width)
|
135
|
+
if max_scroll == 0:
|
136
|
+
return 0
|
137
|
+
return value / max_scroll
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
def get_layout_children(self):
|
142
|
+
return [c for c in super().get_layout_children() if c not in [self.y_scrollbar,self.x_scrollbar]]
|
143
|
+
|
144
|
+
def get_interactive_children(self):
|
145
|
+
return [c for c in super().get_interactive_children() if c not in [self.y_scrollbar,self.x_scrollbar]]
|
146
|
+
|
147
|
+
def top_at(self, x, y):
|
148
|
+
res = self.y_scrollbar.top_at(x,y)
|
149
|
+
if res: return res
|
150
|
+
res = self.x_scrollbar.top_at(x,y)
|
151
|
+
if res: return res
|
152
|
+
return super().top_at(x, y)
|
153
|
+
|
154
|
+
|
155
|
+
def get_inner_width(self):
|
156
|
+
r = super().get_inner_width()
|
157
|
+
if not self.scrollbars_needed[1]:
|
158
|
+
return r
|
159
|
+
return r - self.scrollbar_size
|
160
|
+
|
161
|
+
def get_inner_height(self):
|
162
|
+
r = super().get_inner_height()
|
163
|
+
if not self.scrollbars_needed[0]:
|
164
|
+
return r
|
165
|
+
return r - self.scrollbar_size
|
166
|
+
|
167
|
+
def get_inner_rect(self):
|
168
|
+
r = super().get_inner_rect()
|
169
|
+
if self.scrollbars_needed[1] :
|
170
|
+
r.w -= self.scrollbar_size
|
171
|
+
if self.scrollbars_needed[0] :
|
172
|
+
r.h -= self.scrollbar_size
|
173
|
+
return r
|
174
|
+
|
175
|
+
|
176
|
+
def expand_rect_with_padding(self, rect):
|
177
|
+
r = super().expand_rect_with_padding(rect)
|
178
|
+
|
179
|
+
if self.scrollbars_needed[1] :
|
180
|
+
r.w += self.scrollbar_size
|
181
|
+
if self.scrollbars_needed[0] :
|
182
|
+
r.h += self.scrollbar_size
|
183
|
+
return r
|
184
|
+
|
185
|
+
def _update_scrollbars(self):
|
186
|
+
# print("Update scrollbar")
|
187
|
+
if self.layout.children_rect.h == 0:
|
188
|
+
y_ratio = 1 # set to 1 so no need to scroll
|
189
|
+
else:
|
190
|
+
y_ratio = self.get_inner_height() / self.layout.children_rect.h
|
191
|
+
if self.layout.children_rect.w == 0:
|
192
|
+
x_ratio = 1
|
193
|
+
else:
|
194
|
+
x_ratio = self.get_inner_width() / self.layout.children_rect.w
|
195
|
+
|
196
|
+
|
197
|
+
tmp_scrollbars_needed = [
|
198
|
+
x_ratio < 1,
|
199
|
+
y_ratio < 1
|
200
|
+
]
|
201
|
+
visible_list = [self.x_scrollbar.visible,self.y_scrollbar.visible]
|
202
|
+
# print(f"{tmp_scrollbars_needed=}")
|
203
|
+
|
204
|
+
# print(f"{self.scrollbars_needed=}")
|
205
|
+
|
206
|
+
# print(f"{x_ratio=}")
|
207
|
+
# print(f"{y_ratio=}")
|
208
|
+
|
209
|
+
|
210
|
+
# check if scrollbars changed (remove or add)
|
211
|
+
if self.scrollbars_needed != tmp_scrollbars_needed :
|
212
|
+
# self.dirty_shape = True # because scrollbars change self shape
|
213
|
+
self.x_scrollbar.show() if tmp_scrollbars_needed[0] else self.x_scrollbar.hide()
|
214
|
+
self.y_scrollbar.show() if tmp_scrollbars_needed[1] else self.y_scrollbar.hide()
|
215
|
+
|
216
|
+
self.scrollbars_needed = tmp_scrollbars_needed
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
if self.x_scrollbar.visible:
|
222
|
+
self.x_scrollbar.set_size((self.rect.w-(self.scrollbar_size if tmp_scrollbars_needed[1] else 0),self.scrollbar_size))
|
223
|
+
self.x_scrollbar.set_position(self.rect.left,self.rect.bottom - self.scrollbar_size)
|
224
|
+
self.x_scrollbar.meter.handle.set_size((max(2,self.get_inner_width()*x_ratio),None))
|
225
|
+
if self.y_scrollbar.visible:
|
226
|
+
self.y_scrollbar.set_size((self.scrollbar_size,self.rect.h))
|
227
|
+
self.y_scrollbar.set_position(self.rect.right - self.scrollbar_size,self.rect.top)
|
228
|
+
self.y_scrollbar.meter.handle.set_size((None,max(self.get_inner_height()*y_ratio,2)))
|
229
|
+
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
|
236
|
+
def build(self) -> None:
|
237
|
+
if self.layout is not None:
|
238
|
+
size = list(self.layout.get_auto_size())
|
239
|
+
size[0]+=self.scrollbar_size
|
240
|
+
size[1]+=self.scrollbar_size
|
241
|
+
self.set_size(self.resolve_size(size))
|
242
|
+
return super().build()
|
243
|
+
|
244
|
+
def apply_pre_updates(self):
|
245
|
+
if self.dirty_size_constraints or self.dirty_shape:
|
246
|
+
self.resolve_constraints(size_only=True)
|
247
|
+
self.dirty_size_constraints = False
|
248
|
+
self.dirty_position_constraints = True
|
249
|
+
|
250
|
+
if self.dirty_layout:
|
251
|
+
self.layout.update_child_constraints()
|
252
|
+
self.layout.arrange()
|
253
|
+
self.dirty_layout = False
|
254
|
+
self.dirty_scroll = True
|
255
|
+
|
256
|
+
if self.dirty_scroll:
|
257
|
+
self.layout.scroll_children()
|
258
|
+
self._update_scrollbars()
|
259
|
+
self.dirty_scroll = False
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
def draw(self, camera):
|
266
|
+
bf.Drawable.draw(self,camera)
|
267
|
+
|
268
|
+
if self.clip_children:
|
269
|
+
new_clip = camera.world_to_screen(self.get_inner_rect())
|
270
|
+
old_clip = camera.surface.get_clip()
|
271
|
+
new_clip = new_clip.clip(old_clip)
|
272
|
+
camera.surface.set_clip(new_clip)
|
273
|
+
|
274
|
+
# Draw each child widget, sorted by render order
|
275
|
+
for child in self.children:
|
276
|
+
if (not self.clip_children) or (child.rect.colliderect(self.rect) or not child.rect):
|
277
|
+
child.draw(camera)
|
278
|
+
if self.clip_children:
|
279
|
+
camera.surface.set_clip(old_clip)
|
280
|
+
|
281
|
+
self.y_scrollbar.draw(camera)
|
282
|
+
self.x_scrollbar.draw(camera)
|