batframework 1.0.9a10__py3-none-any.whl → 1.1.0__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 +52 -76
- batFramework/action.py +99 -126
- batFramework/actionContainer.py +9 -53
- batFramework/animatedSprite.py +114 -56
- batFramework/audioManager.py +36 -82
- batFramework/camera.py +69 -263
- batFramework/constants.py +53 -29
- batFramework/cutscene.py +109 -243
- batFramework/cutsceneBlocks.py +176 -0
- batFramework/debugger.py +48 -0
- batFramework/dynamicEntity.py +9 -16
- batFramework/easing.py +71 -0
- batFramework/entity.py +85 -92
- batFramework/gui/__init__.py +3 -14
- batFramework/gui/button.py +78 -12
- batFramework/gui/constraints.py +204 -0
- batFramework/gui/container.py +31 -183
- batFramework/gui/debugger.py +43 -126
- batFramework/gui/frame.py +19 -0
- batFramework/gui/image.py +20 -55
- batFramework/gui/indicator.py +22 -95
- batFramework/gui/interactiveWidget.py +12 -229
- batFramework/gui/label.py +77 -311
- batFramework/gui/layout.py +66 -411
- batFramework/gui/root.py +35 -203
- batFramework/gui/shape.py +57 -247
- batFramework/gui/toggle.py +48 -114
- batFramework/gui/widget.py +243 -457
- batFramework/manager.py +29 -113
- batFramework/particles.py +77 -0
- batFramework/scene.py +217 -22
- batFramework/sceneManager.py +129 -161
- batFramework/stateMachine.py +8 -11
- batFramework/time.py +75 -0
- batFramework/transition.py +124 -129
- batFramework/transitionManager.py +0 -0
- batFramework/triggerZone.py +4 -4
- batFramework/utils.py +144 -266
- {batframework-1.0.9a10.dist-info → batframework-1.1.0.dist-info}/METADATA +24 -22
- batframework-1.1.0.dist-info/RECORD +43 -0
- batFramework/animation.py +0 -77
- batFramework/baseScene.py +0 -240
- batFramework/cutsceneManager.py +0 -34
- batFramework/drawable.py +0 -77
- batFramework/easingController.py +0 -58
- batFramework/enums.py +0 -135
- batFramework/fontManager.py +0 -65
- batFramework/gui/animatedLabel.py +0 -89
- batFramework/gui/clickableWidget.py +0 -245
- batFramework/gui/constraints/__init__.py +0 -1
- batFramework/gui/constraints/constraints.py +0 -980
- batFramework/gui/draggableWidget.py +0 -44
- batFramework/gui/meter.py +0 -96
- batFramework/gui/radioButton.py +0 -35
- batFramework/gui/selector.py +0 -250
- batFramework/gui/slider.py +0 -397
- batFramework/gui/style.py +0 -10
- batFramework/gui/styleManager.py +0 -54
- batFramework/gui/syncedVar.py +0 -49
- batFramework/gui/textInput.py +0 -306
- batFramework/gui/tooltip.py +0 -30
- batFramework/particle.py +0 -118
- batFramework/propertyEaser.py +0 -79
- batFramework/renderGroup.py +0 -34
- batFramework/resourceManager.py +0 -130
- batFramework/sceneLayer.py +0 -138
- batFramework/scrollingSprite.py +0 -115
- batFramework/sprite.py +0 -51
- batFramework/templates/__init__.py +0 -1
- batFramework/templates/controller.py +0 -97
- batFramework/tileset.py +0 -46
- batFramework/timeManager.py +0 -213
- batframework-1.0.9a10.dist-info/RECORD +0 -67
- {batframework-1.0.9a10.dist-info → batframework-1.1.0.dist-info}/LICENSE +0 -0
- {batframework-1.0.9a10.dist-info → batframework-1.1.0.dist-info}/WHEEL +0 -0
- {batframework-1.0.9a10.dist-info → batframework-1.1.0.dist-info}/top_level.txt +0 -0
@@ -1,245 +0,0 @@
|
|
1
|
-
import batFramework as bf
|
2
|
-
from typing import Self, Callable, Any
|
3
|
-
from .interactiveWidget import InteractiveWidget
|
4
|
-
from .shape import Shape
|
5
|
-
import pygame
|
6
|
-
|
7
|
-
|
8
|
-
class ClickableWidget(Shape, InteractiveWidget):
|
9
|
-
_cache: dict = {}
|
10
|
-
|
11
|
-
def __init__(self, callback: Callable[[],Any] = None, *args, **kwargs) -> None:
|
12
|
-
super().__init__(*args, **kwargs)
|
13
|
-
self.callback = callback
|
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 #
|
16
|
-
self.hover_cursor = bf.const.DEFAULT_HOVER_CURSOR
|
17
|
-
self.click_cursor = bf.const.DEFAULT_CLICK_CURSOR
|
18
|
-
|
19
|
-
self.click_down_sound = None
|
20
|
-
self.click_up_sound = None
|
21
|
-
self.get_focus_sound = None
|
22
|
-
self.lose_focus_sound = None
|
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
|
-
self.silent_focus: bool = False
|
27
|
-
self.set_debug_color("cyan")
|
28
|
-
self.set_relief(self.unpressed_relief)
|
29
|
-
|
30
|
-
|
31
|
-
def get_min_required_size(self) -> tuple[float, float]:
|
32
|
-
res = super().get_min_required_size()
|
33
|
-
res = res[0],res[1]+self.unpressed_relief
|
34
|
-
return res
|
35
|
-
|
36
|
-
def set_unpressed_relief(self, relief: int) -> Self:
|
37
|
-
if relief == self.unpressed_relief:
|
38
|
-
return self
|
39
|
-
self.unpressed_relief = relief
|
40
|
-
self.dirty_shape = True
|
41
|
-
if not self.is_pressed:
|
42
|
-
self.set_relief(relief)
|
43
|
-
return self
|
44
|
-
|
45
|
-
def set_pressed_relief(self, relief: int) -> Self:
|
46
|
-
if relief == self.pressed_relief:
|
47
|
-
return self
|
48
|
-
self.pressed_relief = relief
|
49
|
-
self.dirty_shape = True
|
50
|
-
if self.is_pressed:
|
51
|
-
self.set_relief(relief)
|
52
|
-
return self
|
53
|
-
|
54
|
-
def set_silent_focus(self, value: bool) -> Self:
|
55
|
-
self.silent_focus = value
|
56
|
-
return self
|
57
|
-
|
58
|
-
def set_click_down_sound(self, sound_name: str) -> Self:
|
59
|
-
self.click_down_sound = sound_name
|
60
|
-
return self
|
61
|
-
|
62
|
-
def set_click_up_sound(self, sound_name: str) -> Self:
|
63
|
-
self.click_up_sound = sound_name
|
64
|
-
return self
|
65
|
-
|
66
|
-
def set_get_focus_sound(self, sound_name: str) -> Self:
|
67
|
-
self.get_focus_sound = sound_name
|
68
|
-
return self
|
69
|
-
|
70
|
-
def set_lose_focus_sound(self, sound_name: str) -> Self:
|
71
|
-
self.lose_focus_sound = sound_name
|
72
|
-
return self
|
73
|
-
|
74
|
-
def set_hover_cursor(self, cursor: pygame.Cursor) -> Self:
|
75
|
-
self.hover_cursor = cursor
|
76
|
-
return self
|
77
|
-
|
78
|
-
def set_click_cursor(self, cursor: pygame.Cursor) -> Self:
|
79
|
-
self.click_cursor = cursor
|
80
|
-
return self
|
81
|
-
|
82
|
-
def get_surface_filter(self) -> pygame.Surface | None:
|
83
|
-
size = int(self.rect.w), int(self.rect.h)
|
84
|
-
surface_filter = ClickableWidget._cache.get((size, *self.border_radius), None)
|
85
|
-
if surface_filter is None:
|
86
|
-
# Create a mask from the original surface
|
87
|
-
mask = pygame.mask.from_surface(self.surface, threshold=0)
|
88
|
-
|
89
|
-
silhouette_surface = mask.to_surface(
|
90
|
-
setcolor=(30, 30, 30), unsetcolor=(0, 0, 0)
|
91
|
-
)
|
92
|
-
|
93
|
-
ClickableWidget._cache[(size, *self.border_radius)] = silhouette_surface
|
94
|
-
|
95
|
-
surface_filter = silhouette_surface
|
96
|
-
|
97
|
-
return surface_filter
|
98
|
-
|
99
|
-
def allow_focus_to_self(self) -> bool:
|
100
|
-
return True
|
101
|
-
|
102
|
-
def enable(self) -> Self:
|
103
|
-
self.is_enabled = True
|
104
|
-
self.dirty_surface = True
|
105
|
-
return self
|
106
|
-
|
107
|
-
def disable(self) -> Self:
|
108
|
-
self.is_enabled = False
|
109
|
-
self.dirty_surface = True
|
110
|
-
return self
|
111
|
-
|
112
|
-
def set_callback(self, callback: Callable[[],Any]) -> Self:
|
113
|
-
self.callback = callback
|
114
|
-
return self
|
115
|
-
|
116
|
-
def on_get_focus(self):
|
117
|
-
super().on_get_focus()
|
118
|
-
if self.get_focus_sound and not self.silent_focus:
|
119
|
-
if self.parent_scene and self.parent_scene.visible:
|
120
|
-
bf.AudioManager().play_sound(self.get_focus_sound)
|
121
|
-
if self.silent_focus:
|
122
|
-
self.silent_focus = False
|
123
|
-
|
124
|
-
def on_lose_focus(self):
|
125
|
-
super().on_lose_focus()
|
126
|
-
if self.lose_focus_sound and not self.silent_focus:
|
127
|
-
if self.parent_scene and self.parent_scene.visible:
|
128
|
-
bf.AudioManager().play_sound(self.lose_focus_sound)
|
129
|
-
if self.silent_focus:
|
130
|
-
self.silent_focus = False
|
131
|
-
|
132
|
-
def __str__(self) -> str:
|
133
|
-
return f"ClickableWidget"
|
134
|
-
|
135
|
-
def click(self, force=False) -> None:
|
136
|
-
if not self.is_enabled and not force:
|
137
|
-
return False
|
138
|
-
if self.callback is not None:
|
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
|
-
|
155
|
-
|
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:
|
174
|
-
self.is_pressed = False
|
175
|
-
if self.click_up_sound:
|
176
|
-
bf.AudioManager().play_sound(self.click_up_sound)
|
177
|
-
self.set_relief(self.unpressed_relief)
|
178
|
-
self.click()
|
179
|
-
self.do_on_click_up(button)
|
180
|
-
return True
|
181
|
-
return False
|
182
|
-
|
183
|
-
|
184
|
-
def on_enter(self) -> None:
|
185
|
-
if not self.is_enabled:
|
186
|
-
return
|
187
|
-
super().on_enter()
|
188
|
-
self.dirty_surface = True
|
189
|
-
pygame.mouse.set_cursor(self.hover_cursor)
|
190
|
-
|
191
|
-
def on_exit(self) -> None:
|
192
|
-
super().on_exit()
|
193
|
-
if self.is_pressed:
|
194
|
-
self.set_relief(self.unpressed_relief)
|
195
|
-
self.is_pressed = False
|
196
|
-
self.dirty_surface = True
|
197
|
-
pygame.mouse.set_cursor(bf.const.DEFAULT_CURSOR)
|
198
|
-
|
199
|
-
def on_lose_focus(self):
|
200
|
-
super().on_lose_focus()
|
201
|
-
self.on_exit()
|
202
|
-
|
203
|
-
|
204
|
-
def _paint_disabled(self) -> None:
|
205
|
-
self.surface.blit(
|
206
|
-
self.get_surface_filter(), (0, 0), special_flags=pygame.BLEND_RGB_SUB
|
207
|
-
)
|
208
|
-
|
209
|
-
def _paint_hovered(self) -> None:
|
210
|
-
self.surface.blit(
|
211
|
-
self.get_surface_filter(), (0, 0), special_flags=pygame.BLEND_RGB_ADD
|
212
|
-
)
|
213
|
-
|
214
|
-
def get_inner_rect(self) -> pygame.FRect:
|
215
|
-
return pygame.FRect(
|
216
|
-
self.rect.x + self.padding[0],
|
217
|
-
self.rect.y + self.padding[1] + (self.unpressed_relief - self.pressed_relief if self.is_pressed else 0),
|
218
|
-
self.rect.w - self.padding[2] - self.padding[0],
|
219
|
-
self.rect.h - self.unpressed_relief - self.padding[1] - self.padding[3],
|
220
|
-
)
|
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
|
-
|
231
|
-
def _get_elevated_rect(self) -> pygame.FRect:
|
232
|
-
return pygame.FRect(
|
233
|
-
0,
|
234
|
-
self.unpressed_relief - self.pressed_relief if self.is_pressed else 0,
|
235
|
-
self.rect.w,
|
236
|
-
self.rect.h - self.unpressed_relief,
|
237
|
-
)
|
238
|
-
|
239
|
-
def paint(self) -> None:
|
240
|
-
super().paint()
|
241
|
-
if not self.is_enabled:
|
242
|
-
self._paint_disabled()
|
243
|
-
elif self.is_hovered:
|
244
|
-
self._paint_hovered()
|
245
|
-
|
@@ -1 +0,0 @@
|
|
1
|
-
from . import constraints
|