batframework 1.0.8a1__py3-none-any.whl → 1.0.8a2__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 +50 -53
- batFramework/action.py +105 -116
- batFramework/actionContainer.py +11 -53
- batFramework/animatedSprite.py +65 -115
- batFramework/audioManager.py +26 -70
- batFramework/camera.py +68 -253
- batFramework/constants.py +54 -16
- batFramework/cutscene.py +25 -34
- batFramework/cutsceneBlocks.py +42 -37
- batFramework/debugger.py +48 -0
- batFramework/dynamicEntity.py +7 -9
- batFramework/easing.py +71 -0
- batFramework/entity.py +98 -42
- batFramework/gui/__init__.py +2 -8
- batFramework/gui/button.py +79 -7
- batFramework/gui/constraints.py +204 -0
- batFramework/gui/container.py +31 -155
- batFramework/gui/debugger.py +43 -124
- batFramework/gui/frame.py +19 -0
- batFramework/gui/image.py +17 -41
- batFramework/gui/indicator.py +21 -41
- batFramework/gui/interactiveWidget.py +13 -116
- batFramework/gui/label.py +73 -278
- batFramework/gui/layout.py +61 -148
- batFramework/gui/root.py +37 -102
- batFramework/gui/shape.py +57 -258
- batFramework/gui/toggle.py +46 -97
- batFramework/gui/widget.py +254 -268
- batFramework/manager.py +19 -40
- batFramework/particles.py +77 -0
- batFramework/scene.py +107 -214
- batFramework/sceneManager.py +107 -150
- batFramework/stateMachine.py +0 -1
- batFramework/time.py +57 -117
- batFramework/transition.py +126 -184
- batFramework/transitionManager.py +0 -0
- batFramework/utils.py +161 -34
- batframework-1.0.8a2.dist-info/METADATA +58 -0
- batframework-1.0.8a2.dist-info/RECORD +42 -0
- {batframework-1.0.8a1.dist-info → batframework-1.0.8a2.dist-info}/WHEEL +1 -1
- batFramework/easingController.py +0 -58
- batFramework/enums.py +0 -104
- batFramework/fontManager.py +0 -65
- batFramework/gui/clickableWidget.py +0 -206
- batFramework/gui/constraints/__init__.py +0 -1
- batFramework/gui/constraints/constraints.py +0 -378
- batFramework/gui/dialogueBox.py +0 -96
- batFramework/gui/draggableWidget.py +0 -38
- batFramework/gui/meter.py +0 -76
- batFramework/gui/radioButton.py +0 -62
- batFramework/gui/slider.py +0 -220
- batFramework/gui/textInput.py +0 -134
- batFramework/object.py +0 -115
- batFramework/particle.py +0 -101
- batFramework/renderGroup.py +0 -62
- batFramework/resourceManager.py +0 -84
- batFramework/scrollingSprite.py +0 -113
- batFramework/sprite.py +0 -45
- batFramework/tileset.py +0 -46
- batframework-1.0.8a1.dist-info/LICENCE +0 -21
- batframework-1.0.8a1.dist-info/METADATA +0 -55
- batframework-1.0.8a1.dist-info/RECORD +0 -56
- {batframework-1.0.8a1.dist-info → batframework-1.0.8a2.dist-info}/top_level.txt +0 -0
@@ -1,378 +0,0 @@
|
|
1
|
-
from ..widget import Widget
|
2
|
-
import batFramework as bf
|
3
|
-
import pygame
|
4
|
-
|
5
|
-
|
6
|
-
class Constraint:
|
7
|
-
def __init__(self, name="Constraint", priority=0):
|
8
|
-
self.priority = priority
|
9
|
-
self.name = name
|
10
|
-
|
11
|
-
def set_priority(self, priority) -> "Constraint":
|
12
|
-
self.priority = priority
|
13
|
-
return self
|
14
|
-
|
15
|
-
def __str__(self) -> str:
|
16
|
-
return f"{self.name.upper()}"
|
17
|
-
|
18
|
-
def evaluate(self, parent_widget: Widget, child_widget: Widget) -> bool:
|
19
|
-
raise NotImplementedError("Subclasses must implement evaluate method")
|
20
|
-
|
21
|
-
def apply(self, parent_widget: Widget, child_widget: Widget = None) -> bool:
|
22
|
-
if not self.evaluate(parent_widget, child_widget):
|
23
|
-
self.apply_constraint(parent_widget, child_widget)
|
24
|
-
return False
|
25
|
-
return True
|
26
|
-
|
27
|
-
def apply_constraint(self, parent_widget: Widget, child_widget: Widget):
|
28
|
-
raise NotImplementedError("Subclasses must implement apply_constraint method")
|
29
|
-
|
30
|
-
|
31
|
-
class MinWidth(Constraint):
|
32
|
-
def __init__(self, width: float):
|
33
|
-
super().__init__(name="min_width")
|
34
|
-
self.min_width = width
|
35
|
-
|
36
|
-
def evaluate(self, parent_widget, child_widget):
|
37
|
-
return child_widget.rect.width >= self.min_width
|
38
|
-
|
39
|
-
def apply_constraint(self, parent_widget, child_widget):
|
40
|
-
child_widget.set_size((self.min_width,None))
|
41
|
-
|
42
|
-
|
43
|
-
class MinHeight(Constraint):
|
44
|
-
def __init__(self, height: float):
|
45
|
-
super().__init__(name="min_height")
|
46
|
-
self.min_height = height
|
47
|
-
|
48
|
-
def evaluate(self, parent_widget, child_widget):
|
49
|
-
return child_widget.rect.h >= self.min_height
|
50
|
-
|
51
|
-
def apply_constraint(self, parent_widget, child_widget):
|
52
|
-
child_widget.set_size((None, self.min_height))
|
53
|
-
|
54
|
-
|
55
|
-
class CenterX(Constraint):
|
56
|
-
def __init__(self):
|
57
|
-
super().__init__(name="centerx")
|
58
|
-
|
59
|
-
def evaluate(self, parent_widget, child_widget):
|
60
|
-
return int(child_widget.rect.centerx - parent_widget.get_padded_center()[0]) == 0
|
61
|
-
|
62
|
-
def apply_constraint(self, parent_widget, child_widget):
|
63
|
-
child_widget.set_center(
|
64
|
-
parent_widget.get_padded_center()[0], child_widget.rect.centery
|
65
|
-
)
|
66
|
-
|
67
|
-
|
68
|
-
class CenterY(Constraint):
|
69
|
-
def __init__(self):
|
70
|
-
super().__init__(name="centery")
|
71
|
-
|
72
|
-
def evaluate(self, parent_widget, child_widget):
|
73
|
-
return int(child_widget.rect.centery - parent_widget.get_padded_center()[1]) == 0
|
74
|
-
|
75
|
-
def apply_constraint(self, parent_widget, child_widget):
|
76
|
-
child_widget.set_center(
|
77
|
-
child_widget.rect.centerx, parent_widget.get_padded_center()[1]
|
78
|
-
)
|
79
|
-
|
80
|
-
|
81
|
-
class Center(Constraint):
|
82
|
-
def __init__(self):
|
83
|
-
super().__init__(name="center")
|
84
|
-
|
85
|
-
def evaluate(self, parent_widget, child_widget):
|
86
|
-
return int(child_widget.rect.centerx - parent_widget.get_padded_center()[0]) == 0 and \
|
87
|
-
int(child_widget.rect.centery - parent_widget.get_padded_center()[1]) == 0
|
88
|
-
|
89
|
-
def apply_constraint(self, parent_widget, child_widget):
|
90
|
-
child_widget.set_center(*parent_widget.get_padded_center())
|
91
|
-
|
92
|
-
|
93
|
-
class PercentageWidth(Constraint):
|
94
|
-
def __init__(self, percentage: float, keep_autoresize: bool = False):
|
95
|
-
super().__init__(name="percentage_width")
|
96
|
-
self.percentage: float = percentage
|
97
|
-
self.keep_autoresize: bool = keep_autoresize
|
98
|
-
|
99
|
-
def __str__(self) -> str:
|
100
|
-
return f"{super().__str__()}.[{self.percentage*100}%,keep_autoresize={self.keep_autoresize}]"
|
101
|
-
|
102
|
-
def evaluate(self, parent_widget, child_widget):
|
103
|
-
return child_widget.rect.width == round(
|
104
|
-
parent_widget.get_padded_width() * self.percentage
|
105
|
-
)
|
106
|
-
|
107
|
-
def apply_constraint(self, parent_widget, child_widget):
|
108
|
-
if child_widget.autoresize_w:
|
109
|
-
if self.keep_autoresize:
|
110
|
-
print(
|
111
|
-
f"WARNING: Constraint on {child_widget.__str__()} can't resize, autoresize set to True"
|
112
|
-
)
|
113
|
-
return
|
114
|
-
child_widget.set_autoresize_w(False)
|
115
|
-
|
116
|
-
child_widget.set_size(
|
117
|
-
(
|
118
|
-
round(parent_widget.get_padded_width() * self.percentage),None)
|
119
|
-
)
|
120
|
-
|
121
|
-
class PercentageHeight(Constraint):
|
122
|
-
def __init__(self, percentage: float, keep_autoresize: bool = False):
|
123
|
-
super().__init__(name="percentage_height")
|
124
|
-
self.percentage: float = percentage
|
125
|
-
self.keep_autoresize: bool = keep_autoresize
|
126
|
-
|
127
|
-
def evaluate(self, parent_widget, child_widget):
|
128
|
-
return child_widget.rect.height == round(parent_widget.get_padded_height() * self.percentage)
|
129
|
-
|
130
|
-
def __str__(self) -> str:
|
131
|
-
return f"{super().__str__()}.[{self.percentage*100}%,keep_autoresize={self.keep_autoresize}]"
|
132
|
-
|
133
|
-
def apply_constraint(self, parent_widget, child_widget):
|
134
|
-
if child_widget.autoresize_h:
|
135
|
-
if self.keep_autoresize:
|
136
|
-
print(f"WARNING: Constraint on {child_widget} can't resize, autoresize set to True")
|
137
|
-
return
|
138
|
-
child_widget.set_autoresize_h(False)
|
139
|
-
child_widget.set_size((None,round(parent_widget.get_padded_height() * self.percentage)))
|
140
|
-
|
141
|
-
class FillX(PercentageWidth):
|
142
|
-
def __init__(self, keep_autoresize: bool = False):
|
143
|
-
super().__init__(1,keep_autoresize)
|
144
|
-
self.name = "fill_x"
|
145
|
-
|
146
|
-
class FillY(PercentageHeight):
|
147
|
-
def __init__(self, keep_autoresize: bool = False):
|
148
|
-
super().__init__(1,keep_autoresize)
|
149
|
-
self.name = "fill_y"
|
150
|
-
|
151
|
-
|
152
|
-
class Height(Constraint):
|
153
|
-
def __init__(self, height: float, keep_autoresize: bool = False):
|
154
|
-
if height < 0:
|
155
|
-
raise ValueError("height can't be negative")
|
156
|
-
super().__init__(name="height")
|
157
|
-
self.height = height
|
158
|
-
self.keep_autoresize: bool = keep_autoresize
|
159
|
-
|
160
|
-
def __str__(self) -> str:
|
161
|
-
return f"{super().__str__()}.(height={self.height})"
|
162
|
-
|
163
|
-
def evaluate(self, parent_widget, child_widget):
|
164
|
-
return child_widget.rect.height == self.height
|
165
|
-
|
166
|
-
def apply_constraint(self, parent_widget, child_widget):
|
167
|
-
if child_widget.autoresize_h:
|
168
|
-
if self.keep_autoresize:
|
169
|
-
print(f"WARNING: Constraint on {child_widget.__str__()} can't resize, autoresize set to True")
|
170
|
-
return
|
171
|
-
child_widget.set_autoresize_h(False)
|
172
|
-
child_widget.set_size((None, self.height))
|
173
|
-
|
174
|
-
|
175
|
-
class Width(Constraint):
|
176
|
-
def __init__(self, width: float, keep_autoresize: bool = False):
|
177
|
-
if width < 0:
|
178
|
-
raise ValueError("width can't be negative")
|
179
|
-
super().__init__(name="width")
|
180
|
-
self.width = width
|
181
|
-
self.keep_autoresize: bool = keep_autoresize
|
182
|
-
|
183
|
-
def __str__(self) -> str:
|
184
|
-
return f"{super().__str__()}.(width={self.width})"
|
185
|
-
|
186
|
-
def evaluate(self, parent_widget, child_widget):
|
187
|
-
return child_widget.rect.width == self.width
|
188
|
-
|
189
|
-
def apply_constraint(self, parent_widget, child_widget):
|
190
|
-
if child_widget.autoresize_w:
|
191
|
-
if self.keep_autoresize:
|
192
|
-
print(
|
193
|
-
f"WARNING: Constraint on {child_widget.__str__()} can't resize, autoresize set to True"
|
194
|
-
)
|
195
|
-
return
|
196
|
-
child_widget.set_autoresize_w(False)
|
197
|
-
child_widget.set_size((self.width, None))
|
198
|
-
|
199
|
-
|
200
|
-
class AspectRatio(Constraint):
|
201
|
-
def __init__(
|
202
|
-
self,
|
203
|
-
ratio: int | float | pygame.rect.FRectType = 1,
|
204
|
-
reference_axis: bf.axis = bf.axis.HORIZONTAL,
|
205
|
-
keep_autoresize=False,
|
206
|
-
):
|
207
|
-
super().__init__(name="aspect_ratio")
|
208
|
-
self.ref_axis : bf.axis = reference_axis
|
209
|
-
self.keep_autoresize: bool = keep_autoresize
|
210
|
-
|
211
|
-
if isinstance(ratio, float | int):
|
212
|
-
self.ratio = ratio
|
213
|
-
elif isinstance(ratio, pygame.rect.FRect):
|
214
|
-
self.ratio = (ratio.w / ratio.h) if reference_axis == bf.axis.HORIZONTAL else (ratio.h / ratio.w)
|
215
|
-
else:
|
216
|
-
raise TypeError(f"Ratio must be float or FRect")
|
217
|
-
|
218
|
-
def evaluate(self, parent_widget, child_widget):
|
219
|
-
if self.ref_axis == bf.axis.HORIZONTAL:
|
220
|
-
return self.ratio == child_widget.rect.w / child_widget.rect.h
|
221
|
-
if self.ref_axis == bf.axis.VERTICAL:
|
222
|
-
return self.ratio == child_widget.rect.h / child_widget.rect.w
|
223
|
-
|
224
|
-
def apply_constraint(self, parent_widget, child_widget):
|
225
|
-
|
226
|
-
if self.ref_axis == bf.axis.VERTICAL:
|
227
|
-
if child_widget.autoresize_w :
|
228
|
-
if self.keep_autoresize:
|
229
|
-
print(
|
230
|
-
f"WARNING: Constraint on {child_widget.__str__()} can't resize, autoresize set to True"
|
231
|
-
)
|
232
|
-
return
|
233
|
-
child_widget.set_autoresize_w(False)
|
234
|
-
child_widget.set_size((child_widget.rect.h * self.ratio,None))
|
235
|
-
|
236
|
-
if self.ref_axis == bf.axis.HORIZONTAL:
|
237
|
-
if child_widget.autoresize_h :
|
238
|
-
if self.keep_autoresize:
|
239
|
-
print(
|
240
|
-
f"WARNING: Constraint on {child_widget.__str__()} can't resize, autoresize set to True"
|
241
|
-
)
|
242
|
-
return
|
243
|
-
child_widget.set_autoresize_h(False)
|
244
|
-
print("HERE")
|
245
|
-
child_widget.set_size((None,child_widget.rect.w * self.ratio))
|
246
|
-
|
247
|
-
class AnchorBottom(Constraint):
|
248
|
-
def __init__(self):
|
249
|
-
super().__init__(name="anchor_bottom")
|
250
|
-
|
251
|
-
def evaluate(self, parent_widget, child_widget):
|
252
|
-
return child_widget.rect.top == parent_widget.get_padded_bottom() - child_widget.rect.h
|
253
|
-
|
254
|
-
def apply_constraint(self, parent_widget, child_widget):
|
255
|
-
child_widget.set_position(child_widget.rect.x,parent_widget.get_padded_bottom() - child_widget.rect.h)
|
256
|
-
|
257
|
-
class AnchorBottom(Constraint):
|
258
|
-
def __init__(self):
|
259
|
-
super().__init__(name="anchor_bottom")
|
260
|
-
|
261
|
-
def evaluate(self, parent_widget, child_widget):
|
262
|
-
return child_widget.rect.top == parent_widget.get_padded_bottom() - child_widget.rect.h
|
263
|
-
|
264
|
-
def apply_constraint(self, parent_widget, child_widget):
|
265
|
-
child_widget.set_position(child_widget.rect.x,parent_widget.get_padded_bottom() - child_widget.rect.h)
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
class AnchorTopRight(Constraint):
|
270
|
-
def __init__(self):
|
271
|
-
super().__init__(name="anchor_topright")
|
272
|
-
|
273
|
-
def evaluate(self, parent_widget, child_widget):
|
274
|
-
return child_widget.rect.topright == parent_widget.get_padded_rect().topright
|
275
|
-
|
276
|
-
def apply_constraint(self, parent_widget, child_widget):
|
277
|
-
child_widget.set_position(
|
278
|
-
parent_widget.get_padded_right() - child_widget.rect.w,
|
279
|
-
parent_widget.get_padded_top(),
|
280
|
-
)
|
281
|
-
|
282
|
-
|
283
|
-
class AnchorBottomRight(Constraint):
|
284
|
-
def __init__(self):
|
285
|
-
super().__init__(name="anchor_bottomright")
|
286
|
-
|
287
|
-
def evaluate(self, parent_widget, child_widget):
|
288
|
-
return (
|
289
|
-
child_widget.rect.bottomright == parent_widget.get_padded_rect().bottomright
|
290
|
-
)
|
291
|
-
|
292
|
-
def apply_constraint(self, parent_widget, child_widget):
|
293
|
-
child_widget.set_position(
|
294
|
-
parent_widget.get_padded_right() - child_widget.rect.w,
|
295
|
-
parent_widget.get_padded_bottom() - child_widget.rect.h,
|
296
|
-
)
|
297
|
-
|
298
|
-
|
299
|
-
class AnchorRight(Constraint):
|
300
|
-
def __init__(self):
|
301
|
-
super().__init__(name="anchor_right")
|
302
|
-
|
303
|
-
def evaluate(self, parent_widget, child_widget):
|
304
|
-
return child_widget.rect.right == parent_widget.get_padded_right()
|
305
|
-
|
306
|
-
def apply_constraint(self, parent_widget, child_widget):
|
307
|
-
child_widget.set_position(
|
308
|
-
parent_widget.get_padded_right() - child_widget.rect.w,
|
309
|
-
child_widget.rect.top,
|
310
|
-
)
|
311
|
-
|
312
|
-
|
313
|
-
class AnchorLeft(Constraint):
|
314
|
-
def __init__(self):
|
315
|
-
super().__init__(name="anchor_left")
|
316
|
-
|
317
|
-
def evaluate(self, parent_widget, child_widget):
|
318
|
-
return child_widget.rect.left == parent_widget.get_padded_left()
|
319
|
-
|
320
|
-
def apply_constraint(self, parent_widget, child_widget):
|
321
|
-
child_widget.set_position(
|
322
|
-
parent_widget.get_padded_left(), child_widget.rect.top
|
323
|
-
)
|
324
|
-
|
325
|
-
|
326
|
-
class MarginBottom(Constraint):
|
327
|
-
def __init__(self, margin: float):
|
328
|
-
super().__init__(name="margin_bottom")
|
329
|
-
self.margin = margin
|
330
|
-
|
331
|
-
def evaluate(self, parent_widget, child_widget):
|
332
|
-
return (
|
333
|
-
child_widget.rect.bottom == parent_widget.get_padded_bottom() - self.margin
|
334
|
-
)
|
335
|
-
|
336
|
-
def apply_constraint(self, parent_widget, child_widget):
|
337
|
-
child_widget.set_position(child_widget.rect.x,
|
338
|
-
parent_widget.get_padded_bottom() - child_widget.rect.h - self.margin
|
339
|
-
)
|
340
|
-
|
341
|
-
class MarginTop(Constraint):
|
342
|
-
def __init__(self, margin: float):
|
343
|
-
super().__init__(name="margin_top")
|
344
|
-
self.margin = margin
|
345
|
-
|
346
|
-
def evaluate(self, parent_widget, child_widget):
|
347
|
-
return child_widget.rect.top == parent_widget.get_padded_top() + self.margin
|
348
|
-
|
349
|
-
def apply_constraint(self, parent_widget, child_widget):
|
350
|
-
child_widget.set_position(child_widget.rect.x,parent_widget.get_padded_top() + self.margin)
|
351
|
-
|
352
|
-
|
353
|
-
class MarginLeft(Constraint):
|
354
|
-
def __init__(self, margin: float):
|
355
|
-
super().__init__(name="margin_left")
|
356
|
-
self.margin = margin
|
357
|
-
|
358
|
-
def evaluate(self, parent_widget, child_widget):
|
359
|
-
return child_widget.rect.left == parent_widget.get_padded_left() + self.margin
|
360
|
-
|
361
|
-
def apply_constraint(self, parent_widget, child_widget):
|
362
|
-
if not self.evaluate(parent_widget, child_widget):
|
363
|
-
child_widget.set_position(parent_widget.get_padded_left() + self.margin,child_widget.rect.y)
|
364
|
-
|
365
|
-
|
366
|
-
class MarginRight(Constraint):
|
367
|
-
def __init__(self, margin: float):
|
368
|
-
super().__init__(name="margin_right")
|
369
|
-
self.margin = margin
|
370
|
-
|
371
|
-
def evaluate(self, parent_widget, child_widget):
|
372
|
-
return child_widget.rect.right == parent_widget.get_padded_right() - self.margin
|
373
|
-
|
374
|
-
def apply_constraint(self, parent_widget, child_widget):
|
375
|
-
child_widget.set_position(
|
376
|
-
parent_widget.get_padded_right() - child_widget.rect.w - self.margin,
|
377
|
-
child_widget.rect.y
|
378
|
-
)
|
batFramework/gui/dialogueBox.py
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
from .label import Label
|
2
|
-
import batFramework as bf
|
3
|
-
from typing import Self
|
4
|
-
|
5
|
-
|
6
|
-
class DialogueBox(Label):
|
7
|
-
def __init__(self) -> None:
|
8
|
-
self.cursor_position: float = 0.0
|
9
|
-
self.text_speed: float = 20.0
|
10
|
-
self.message_queue: list[str] = []
|
11
|
-
self.is_over: bool = True
|
12
|
-
self.is_paused: bool = False
|
13
|
-
self.set_autoresize(False)
|
14
|
-
self.set_alignment(bf.alignment.LEFT)
|
15
|
-
super().__init__("")
|
16
|
-
|
17
|
-
def pause(self)->Self:
|
18
|
-
self.is_paused = True
|
19
|
-
return self
|
20
|
-
|
21
|
-
def resume(self)->Self:
|
22
|
-
self.is_paused = False
|
23
|
-
return self
|
24
|
-
|
25
|
-
def set_text_speed(self, speed: float) -> Self:
|
26
|
-
self.text_speed = speed
|
27
|
-
return self
|
28
|
-
|
29
|
-
def cut_text_to_width(self, text: str) -> list[str]:
|
30
|
-
w = self.get_padded_width()
|
31
|
-
if text == "" or not self.font_object or w < self.font_object.point_size:
|
32
|
-
return [text]
|
33
|
-
left = 0
|
34
|
-
for index in range(len(text)):
|
35
|
-
width = self.font_object.size(text[left:index])[0]
|
36
|
-
|
37
|
-
if width > w:
|
38
|
-
cut_point_start = index - 1
|
39
|
-
cut_point_end = index - 1
|
40
|
-
last_space = text.rfind(' ', 0, cut_point_start)
|
41
|
-
last_nline = text.rfind('\n', 0, cut_point_start)
|
42
|
-
|
43
|
-
if last_space != -1 or last_nline!= -1: # space was found !:
|
44
|
-
cut_point_start = max(last_space,last_nline)
|
45
|
-
cut_point_end = cut_point_start + 1
|
46
|
-
res = [text[:cut_point_start].strip()]
|
47
|
-
res.extend(self.cut_text_to_width(text[cut_point_end:].strip()))
|
48
|
-
return res
|
49
|
-
elif text[index] == '\n':
|
50
|
-
left = index
|
51
|
-
return [text]
|
52
|
-
|
53
|
-
def paint(self)->None:
|
54
|
-
if self.font_object and self.message_queue :
|
55
|
-
message = self.message_queue.pop(0)
|
56
|
-
message = "\n".join(self.cut_text_to_width(message))
|
57
|
-
self.message_queue.insert(0,message)
|
58
|
-
super().paint()
|
59
|
-
|
60
|
-
def say(self, message: str) ->Self:
|
61
|
-
self.message_queue.append(message)
|
62
|
-
self.is_over = False
|
63
|
-
return self
|
64
|
-
|
65
|
-
def is_queue_empty(self) -> bool:
|
66
|
-
return not self.message_queue
|
67
|
-
|
68
|
-
def is_current_message_over(self) -> bool:
|
69
|
-
return self.is_over
|
70
|
-
|
71
|
-
def clear_queue(self) -> Self:
|
72
|
-
self.message_queue.clear()
|
73
|
-
self.next_message()
|
74
|
-
return self
|
75
|
-
|
76
|
-
def next_message(self) -> Self:
|
77
|
-
if self.message_queue:
|
78
|
-
self.message_queue.pop(0)
|
79
|
-
self.cursor_position = 0
|
80
|
-
self.set_text("")
|
81
|
-
return self
|
82
|
-
|
83
|
-
def skip_current_message(self)->Self:
|
84
|
-
self.cursor_position = len(self.message_queue[0])
|
85
|
-
self.dirty_shape = True
|
86
|
-
|
87
|
-
def do_update(self, dt):
|
88
|
-
if not self.message_queue or self.is_paused:
|
89
|
-
return
|
90
|
-
if not self.is_over and self.cursor_position == len(self.message_queue[0]):
|
91
|
-
self.is_over = True
|
92
|
-
return
|
93
|
-
self.cursor_position = min(
|
94
|
-
self.cursor_position + self.text_speed * dt, len(self.message_queue[0])
|
95
|
-
)
|
96
|
-
self.set_text(self.message_queue[0][: int(self.cursor_position)])
|
@@ -1,38 +0,0 @@
|
|
1
|
-
from .interactiveWidget import InteractiveWidget
|
2
|
-
import batFramework as bf
|
3
|
-
import pygame
|
4
|
-
|
5
|
-
|
6
|
-
class DraggableWidget(InteractiveWidget):
|
7
|
-
def __init__(self, *args, **kwargs) -> None:
|
8
|
-
self.drag_action = bf.Action("dragging").add_mouse_control(1).set_holding()
|
9
|
-
|
10
|
-
self.drag_start = None
|
11
|
-
self.offset = None
|
12
|
-
super().__init__(*args, **kwargs)
|
13
|
-
|
14
|
-
def do_process_actions(self, event: pygame.Event) -> None:
|
15
|
-
self.drag_action.process_event(event)
|
16
|
-
|
17
|
-
def do_reset_actions(self) -> None:
|
18
|
-
self.drag_action.reset()
|
19
|
-
|
20
|
-
def do_on_drag(self,drag_start:tuple[float,float],drag_end: tuple[float,float])->None:
|
21
|
-
self.set_position(drag_end[0]-self.offset[0],drag_end[1]-self.offset[1])
|
22
|
-
|
23
|
-
def update(self, dt: float):
|
24
|
-
if self.drag_action.active and self.is_clicked_down:
|
25
|
-
r = self.get_root()
|
26
|
-
x, y = r.drawing_camera.screen_to_world(pygame.mouse.get_pos())
|
27
|
-
if self.drag_start == None and self.drag_action.active:
|
28
|
-
self.offset = x-self.rect.x,y-self.rect.y
|
29
|
-
self.drag_start = x,y
|
30
|
-
return
|
31
|
-
else:
|
32
|
-
self.do_on_drag(self.drag_start,(x,y))
|
33
|
-
return
|
34
|
-
else:
|
35
|
-
self.drag_start = None
|
36
|
-
self.offset = None
|
37
|
-
self.is_clicked_down = False
|
38
|
-
super().update(dt)
|
batFramework/gui/meter.py
DELETED
@@ -1,76 +0,0 @@
|
|
1
|
-
import batFramework as bf
|
2
|
-
from .shape import Shape
|
3
|
-
from typing import Self
|
4
|
-
|
5
|
-
|
6
|
-
def custom_top_at(self, x, y):
|
7
|
-
if Shape.top_at(self, x, y) == self:
|
8
|
-
return self.parent
|
9
|
-
return None
|
10
|
-
|
11
|
-
|
12
|
-
class Meter(Shape):
|
13
|
-
def __init__(
|
14
|
-
self,
|
15
|
-
min_value: float = 0,
|
16
|
-
max_value: float = 1,
|
17
|
-
step: float = 0.1
|
18
|
-
):
|
19
|
-
super().__init__()
|
20
|
-
self.min_value, self.max_value = min_value,max_value
|
21
|
-
self.step = step
|
22
|
-
self.snap: bool = False
|
23
|
-
self.value = self.max_value
|
24
|
-
self.content = Shape((0, 0)).set_color(bf.color.BLUE)
|
25
|
-
self.content.top_at = lambda x, y: custom_top_at(self.content, x, y)
|
26
|
-
self.add(self.content)
|
27
|
-
self.set_padding(1)
|
28
|
-
self.set_outline_width(1)
|
29
|
-
self.set_outline_color(bf.color.BLACK)
|
30
|
-
self.set_debug_color("pink")
|
31
|
-
|
32
|
-
def __str__(self) -> str:
|
33
|
-
return "Meter"
|
34
|
-
|
35
|
-
def set_step(self, step: float) -> Self:
|
36
|
-
self.step = step
|
37
|
-
self.set_value(self.value)
|
38
|
-
return self
|
39
|
-
|
40
|
-
def set_range(self, range_min: float, range_max: float) -> Self:
|
41
|
-
if range_min >= range_max:
|
42
|
-
print(
|
43
|
-
f"[Warning] : minimum value {range_min} is greater than or equal to maximum value {range_max}"
|
44
|
-
)
|
45
|
-
return self
|
46
|
-
self.min_value, self.max_value = range_min, range_max
|
47
|
-
self.dirty_shape = True
|
48
|
-
|
49
|
-
def get_debug_outlines(self):
|
50
|
-
yield from super().get_debug_outlines()
|
51
|
-
yield from self.content.get_debug_outlines()
|
52
|
-
|
53
|
-
def set_value(self, value: float) -> Self:
|
54
|
-
value = max(self.min_value, min(self.max_value, value))
|
55
|
-
value = round(value / self.step) * self.step
|
56
|
-
self.value = value
|
57
|
-
self.dirty_surface = True
|
58
|
-
return self
|
59
|
-
|
60
|
-
def get_value(self) -> float:
|
61
|
-
return self.value
|
62
|
-
|
63
|
-
def get_range(self) -> float:
|
64
|
-
return self.max_value - self.min_value
|
65
|
-
|
66
|
-
def get_ratio(self) -> float:
|
67
|
-
return self.value / (self.max_value - self.min_value)
|
68
|
-
|
69
|
-
def _build_content(self) -> None:
|
70
|
-
width = (self.get_padded_width() * self.get_ratio())
|
71
|
-
self.content.set_size((width, self.get_padded_height()))
|
72
|
-
self.content.set_position(*self.get_padded_rect().topleft)
|
73
|
-
|
74
|
-
def build(self) -> None:
|
75
|
-
super().build()
|
76
|
-
self._build_content()
|
batFramework/gui/radioButton.py
DELETED
@@ -1,62 +0,0 @@
|
|
1
|
-
import batFramework as bf
|
2
|
-
from typing import Self,Any,Callable
|
3
|
-
from .toggle import Toggle
|
4
|
-
|
5
|
-
class RadioVariable:...
|
6
|
-
|
7
|
-
class RadioButton(Toggle):
|
8
|
-
def __init__(self, text: str, radio_value:Any = None) -> None:
|
9
|
-
super().__init__(text,None, False)
|
10
|
-
self.radio_value : Any = radio_value if radio_value is not None else text if text else None
|
11
|
-
self.radio_variable : RadioVariable = None
|
12
|
-
|
13
|
-
def set_radio_value(self,value:Any)->Self:
|
14
|
-
self.radio_value = value
|
15
|
-
self.update_radio()
|
16
|
-
return self
|
17
|
-
|
18
|
-
def set_text(self, text: str) -> Self:
|
19
|
-
flag = False
|
20
|
-
if self.value == self.text or self.value is None: flag = True
|
21
|
-
super().set_text(text)
|
22
|
-
if flag:
|
23
|
-
self.set_radio_value(self.text)
|
24
|
-
return self
|
25
|
-
|
26
|
-
def click(self) -> None:
|
27
|
-
if self.radio_variable is None: return
|
28
|
-
self.radio_variable.set_value(self.radio_value)
|
29
|
-
|
30
|
-
class RadioVariable:
|
31
|
-
def __init__(self)->None:
|
32
|
-
self.buttons : list[RadioButton] = []
|
33
|
-
self.value = None
|
34
|
-
self.modify_callback : Callable[[Any],] = None
|
35
|
-
|
36
|
-
def link(self,*buttons:RadioButton)->Self:
|
37
|
-
if not buttons : return self
|
38
|
-
for b in buttons :
|
39
|
-
b.radio_variable = self
|
40
|
-
self.buttons.extend(buttons)
|
41
|
-
|
42
|
-
if self.value is None:
|
43
|
-
self.set_value(buttons[0].radio_value)
|
44
|
-
else:
|
45
|
-
self.update_buttons()
|
46
|
-
return self
|
47
|
-
|
48
|
-
def unlink(self,*buttons)->Self:
|
49
|
-
for b in self.buttons:
|
50
|
-
if b in buttons:
|
51
|
-
b.radio_variable = None
|
52
|
-
self.buttons = [b for b in self.buttons if b not in buttons]
|
53
|
-
return self
|
54
|
-
|
55
|
-
def set_value(self,value:Any):
|
56
|
-
if value == self.value: return
|
57
|
-
self.value = value
|
58
|
-
if self.modify_callback :self.modify_callback(value)
|
59
|
-
self.update_buttons()
|
60
|
-
|
61
|
-
def update_buttons(self):
|
62
|
-
_ = [b.set_value(b.radio_value == self.value,False) for b in self.buttons]
|