batframework 1.0.9a7__py3-none-any.whl → 1.0.9a9__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 +20 -11
- batFramework/action.py +1 -1
- batFramework/animatedSprite.py +47 -116
- batFramework/animation.py +30 -5
- batFramework/audioManager.py +8 -5
- batFramework/baseScene.py +240 -0
- batFramework/camera.py +4 -0
- batFramework/constants.py +6 -2
- batFramework/cutscene.py +221 -21
- batFramework/cutsceneManager.py +5 -2
- batFramework/drawable.py +7 -5
- batFramework/easingController.py +10 -11
- batFramework/entity.py +21 -2
- batFramework/enums.py +48 -33
- batFramework/gui/__init__.py +6 -3
- batFramework/gui/animatedLabel.py +10 -2
- batFramework/gui/button.py +4 -31
- batFramework/gui/clickableWidget.py +63 -50
- batFramework/gui/constraints/constraints.py +212 -136
- batFramework/gui/container.py +77 -58
- batFramework/gui/debugger.py +12 -17
- batFramework/gui/draggableWidget.py +21 -17
- batFramework/gui/image.py +3 -10
- batFramework/gui/indicator.py +56 -1
- batFramework/gui/interactiveWidget.py +127 -108
- batFramework/gui/label.py +73 -64
- batFramework/gui/layout.py +286 -445
- batFramework/gui/meter.py +42 -20
- batFramework/gui/radioButton.py +20 -69
- batFramework/gui/root.py +99 -29
- batFramework/gui/selector.py +250 -0
- batFramework/gui/shape.py +13 -5
- batFramework/gui/slider.py +262 -107
- batFramework/gui/syncedVar.py +49 -0
- batFramework/gui/textInput.py +46 -22
- batFramework/gui/toggle.py +70 -52
- batFramework/gui/tooltip.py +30 -0
- batFramework/gui/widget.py +222 -135
- batFramework/manager.py +7 -8
- batFramework/particle.py +4 -1
- batFramework/propertyEaser.py +79 -0
- batFramework/renderGroup.py +17 -50
- batFramework/resourceManager.py +43 -13
- batFramework/scene.py +15 -335
- batFramework/sceneLayer.py +138 -0
- batFramework/sceneManager.py +31 -36
- batFramework/scrollingSprite.py +8 -3
- batFramework/sprite.py +1 -1
- batFramework/templates/__init__.py +1 -2
- batFramework/templates/controller.py +97 -0
- batFramework/timeManager.py +76 -22
- batFramework/transition.py +37 -103
- batFramework/utils.py +125 -66
- {batframework-1.0.9a7.dist-info → batframework-1.0.9a9.dist-info}/METADATA +24 -3
- batframework-1.0.9a9.dist-info/RECORD +67 -0
- {batframework-1.0.9a7.dist-info → batframework-1.0.9a9.dist-info}/WHEEL +1 -1
- batFramework/character.py +0 -27
- batFramework/templates/character.py +0 -43
- batFramework/templates/states.py +0 -166
- batframework-1.0.9a7.dist-info/RECORD +0 -63
- /batframework-1.0.9a7.dist-info/LICENCE → /batframework-1.0.9a9.dist-info/LICENSE +0 -0
- {batframework-1.0.9a7.dist-info → batframework-1.0.9a9.dist-info}/top_level.txt +0 -0
@@ -1,10 +1,8 @@
|
|
1
|
-
from .label import Label
|
2
1
|
import batFramework as bf
|
3
2
|
from typing import Self, Callable, Any
|
4
3
|
from .interactiveWidget import InteractiveWidget
|
5
4
|
from .shape import Shape
|
6
5
|
import pygame
|
7
|
-
from math import ceil
|
8
6
|
|
9
7
|
|
10
8
|
class ClickableWidget(Shape, InteractiveWidget):
|
@@ -13,31 +11,27 @@ class ClickableWidget(Shape, InteractiveWidget):
|
|
13
11
|
def __init__(self, callback: Callable[[],Any] = None, *args, **kwargs) -> None:
|
14
12
|
super().__init__(*args, **kwargs)
|
15
13
|
self.callback = callback
|
16
|
-
self.is_pressed: bool = False
|
17
|
-
self.
|
14
|
+
self.is_pressed: bool = False # the state where the button is being held down (releasing will trigger callback)
|
15
|
+
self.is_enabled: bool = True #
|
18
16
|
self.hover_cursor = bf.const.DEFAULT_HOVER_CURSOR
|
19
17
|
self.click_cursor = bf.const.DEFAULT_CLICK_CURSOR
|
18
|
+
|
20
19
|
self.click_down_sound = None
|
21
20
|
self.click_up_sound = None
|
22
21
|
self.get_focus_sound = None
|
23
22
|
self.lose_focus_sound = None
|
24
|
-
|
25
|
-
self.
|
23
|
+
|
24
|
+
self.pressed_relief: int = 1 # Depth effect height when pressed
|
25
|
+
self.unpressed_relief: int = 2 # Depth effect height when released (default)
|
26
26
|
self.silent_focus: bool = False
|
27
27
|
self.set_debug_color("cyan")
|
28
28
|
self.set_relief(self.unpressed_relief)
|
29
29
|
|
30
|
+
|
30
31
|
def get_min_required_size(self) -> tuple[float, float]:
|
31
|
-
if not (self.autoresize_w or self.autoresize_h):
|
32
|
-
return self.rect.size
|
33
|
-
|
34
32
|
res = super().get_min_required_size()
|
35
33
|
res = res[0],res[1]+self.unpressed_relief
|
36
|
-
|
37
|
-
return res[0] if self.autoresize_w else self.rect.w, (
|
38
|
-
res[1] if self.autoresize_h else self.rect.h
|
39
|
-
)
|
40
|
-
|
34
|
+
return res
|
41
35
|
|
42
36
|
def set_unpressed_relief(self, relief: int) -> Self:
|
43
37
|
if relief == self.unpressed_relief:
|
@@ -106,18 +100,15 @@ class ClickableWidget(Shape, InteractiveWidget):
|
|
106
100
|
return True
|
107
101
|
|
108
102
|
def enable(self) -> Self:
|
109
|
-
self.
|
103
|
+
self.is_enabled = True
|
110
104
|
self.dirty_surface = True
|
111
105
|
return self
|
112
106
|
|
113
107
|
def disable(self) -> Self:
|
114
|
-
self.
|
108
|
+
self.is_enabled = False
|
115
109
|
self.dirty_surface = True
|
116
110
|
return self
|
117
111
|
|
118
|
-
def is_enabled(self) -> bool:
|
119
|
-
return self.enabled
|
120
|
-
|
121
112
|
def set_callback(self, callback: Callable[[],Any]) -> Self:
|
122
113
|
self.callback = callback
|
123
114
|
return self
|
@@ -142,31 +133,56 @@ class ClickableWidget(Shape, InteractiveWidget):
|
|
142
133
|
return f"ClickableWidget"
|
143
134
|
|
144
135
|
def click(self, force=False) -> None:
|
145
|
-
if not self.
|
146
|
-
return
|
136
|
+
if not self.is_enabled and not force:
|
137
|
+
return False
|
147
138
|
if self.callback is not None:
|
148
139
|
self.callback()
|
140
|
+
return True
|
141
|
+
return False
|
142
|
+
|
143
|
+
def on_key_down(self, key):
|
144
|
+
if key == pygame.K_SPACE:
|
145
|
+
self.on_click_down(1)
|
146
|
+
return True
|
147
|
+
return self.do_on_key_down(key)
|
148
|
+
|
149
|
+
def on_key_up(self, key):
|
150
|
+
if key == pygame.K_SPACE:
|
151
|
+
self.on_click_up(1)
|
152
|
+
return True
|
153
|
+
return self.do_on_key_down(key)
|
154
|
+
|
149
155
|
|
150
|
-
def
|
151
|
-
if
|
152
|
-
|
153
|
-
|
154
|
-
self.
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
156
|
+
def on_click_down(self, button) -> bool:
|
157
|
+
if button < 1 or button > 5 : return False
|
158
|
+
self.is_clicked_down[button-1] = True
|
159
|
+
if self.is_enabled and button == 1:
|
160
|
+
if self.get_focus():
|
161
|
+
self.is_pressed = True
|
162
|
+
if self.click_down_sound:
|
163
|
+
bf.AudioManager().play_sound(self.click_down_sound)
|
164
|
+
pygame.mouse.set_cursor(self.click_cursor)
|
165
|
+
self.set_relief(self.pressed_relief)
|
166
|
+
self.do_on_click_down(button)
|
167
|
+
return True
|
168
|
+
return False
|
169
|
+
|
170
|
+
def on_click_up(self, button):
|
171
|
+
if button < 1 or button > 5 : return False
|
172
|
+
self.is_clicked_down[button-1] = False
|
173
|
+
if self.is_enabled and button == 1 and self.is_pressed:
|
162
174
|
self.is_pressed = False
|
163
175
|
if self.click_up_sound:
|
164
176
|
bf.AudioManager().play_sound(self.click_up_sound)
|
165
177
|
self.set_relief(self.unpressed_relief)
|
166
178
|
self.click()
|
179
|
+
self.do_on_click_up(button)
|
180
|
+
return True
|
181
|
+
return False
|
182
|
+
|
167
183
|
|
168
184
|
def on_enter(self) -> None:
|
169
|
-
if not self.
|
185
|
+
if not self.is_enabled:
|
170
186
|
return
|
171
187
|
super().on_enter()
|
172
188
|
self.dirty_surface = True
|
@@ -178,22 +194,12 @@ class ClickableWidget(Shape, InteractiveWidget):
|
|
178
194
|
self.set_relief(self.unpressed_relief)
|
179
195
|
self.is_pressed = False
|
180
196
|
self.dirty_surface = True
|
181
|
-
|
182
197
|
pygame.mouse.set_cursor(bf.const.DEFAULT_CURSOR)
|
183
198
|
|
184
199
|
def on_lose_focus(self):
|
185
200
|
super().on_lose_focus()
|
186
201
|
self.on_exit()
|
187
202
|
|
188
|
-
def on_key_down(self, key):
|
189
|
-
if key == pygame.K_SPACE:
|
190
|
-
self.on_click_down(1)
|
191
|
-
super().on_key_down(key)
|
192
|
-
|
193
|
-
def on_key_up(self, key):
|
194
|
-
if key == pygame.K_SPACE:
|
195
|
-
self.on_click_up(1)
|
196
|
-
super().on_key_up(key)
|
197
203
|
|
198
204
|
def _paint_disabled(self) -> None:
|
199
205
|
self.surface.blit(
|
@@ -205,16 +211,23 @@ class ClickableWidget(Shape, InteractiveWidget):
|
|
205
211
|
self.get_surface_filter(), (0, 0), special_flags=pygame.BLEND_RGB_ADD
|
206
212
|
)
|
207
213
|
|
208
|
-
def
|
214
|
+
def get_inner_rect(self) -> pygame.FRect:
|
209
215
|
return pygame.FRect(
|
210
216
|
self.rect.x + self.padding[0],
|
211
|
-
self.rect.y
|
212
|
-
+ self.padding[1]
|
213
|
-
+ (self.unpressed_relief - self.pressed_relief if self.is_pressed else 0),
|
217
|
+
self.rect.y + self.padding[1] + (self.unpressed_relief - self.pressed_relief if self.is_pressed else 0),
|
214
218
|
self.rect.w - self.padding[2] - self.padding[0],
|
215
|
-
self.rect.h - self.unpressed_relief - self.padding[1] - self.padding[3],
|
219
|
+
self.rect.h - self.unpressed_relief - self.padding[1] - self.padding[3],
|
216
220
|
)
|
217
221
|
|
222
|
+
def get_local_inner_rect(self) -> pygame.FRect:
|
223
|
+
return pygame.FRect(
|
224
|
+
self.padding[0],
|
225
|
+
self.padding[1] + (self.unpressed_relief - self.pressed_relief if self.is_pressed else 0),
|
226
|
+
self.rect.w - self.padding[2] - self.padding[0],
|
227
|
+
self.rect.h - self.unpressed_relief - self.padding[1] - self.padding[3],
|
228
|
+
)
|
229
|
+
|
230
|
+
|
218
231
|
def _get_elevated_rect(self) -> pygame.FRect:
|
219
232
|
return pygame.FRect(
|
220
233
|
0,
|
@@ -225,7 +238,7 @@ class ClickableWidget(Shape, InteractiveWidget):
|
|
225
238
|
|
226
239
|
def paint(self) -> None:
|
227
240
|
super().paint()
|
228
|
-
if not self.
|
241
|
+
if not self.is_enabled:
|
229
242
|
self._paint_disabled()
|
230
243
|
elif self.is_hovered:
|
231
244
|
self._paint_hovered()
|