batframework 1.0.8a2__py3-none-any.whl → 1.0.8a3__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.
Files changed (65) hide show
  1. batFramework/__init__.py +53 -50
  2. batFramework/action.py +126 -99
  3. batFramework/actionContainer.py +53 -9
  4. batFramework/animatedSprite.py +115 -65
  5. batFramework/audioManager.py +69 -26
  6. batFramework/camera.py +259 -69
  7. batFramework/constants.py +16 -54
  8. batFramework/cutscene.py +36 -29
  9. batFramework/cutsceneBlocks.py +37 -42
  10. batFramework/dynamicEntity.py +9 -7
  11. batFramework/easingController.py +58 -0
  12. batFramework/entity.py +48 -97
  13. batFramework/enums.py +113 -0
  14. batFramework/fontManager.py +65 -0
  15. batFramework/gui/__init__.py +10 -2
  16. batFramework/gui/button.py +9 -78
  17. batFramework/gui/clickableWidget.py +219 -0
  18. batFramework/gui/constraints/__init__.py +1 -0
  19. batFramework/gui/constraints/constraints.py +590 -0
  20. batFramework/gui/container.py +174 -32
  21. batFramework/gui/debugger.py +131 -43
  22. batFramework/gui/dialogueBox.py +99 -0
  23. batFramework/gui/draggableWidget.py +40 -0
  24. batFramework/gui/image.py +54 -18
  25. batFramework/gui/indicator.py +38 -21
  26. batFramework/gui/interactiveWidget.py +177 -13
  27. batFramework/gui/label.py +288 -74
  28. batFramework/gui/layout.py +219 -60
  29. batFramework/gui/meter.py +71 -0
  30. batFramework/gui/radioButton.py +84 -0
  31. batFramework/gui/root.py +128 -38
  32. batFramework/gui/shape.py +253 -57
  33. batFramework/gui/slider.py +246 -0
  34. batFramework/gui/style.py +10 -0
  35. batFramework/gui/styleManager.py +48 -0
  36. batFramework/gui/textInput.py +137 -0
  37. batFramework/gui/toggle.py +115 -51
  38. batFramework/gui/widget.py +329 -254
  39. batFramework/manager.py +40 -19
  40. batFramework/object.py +114 -0
  41. batFramework/particle.py +101 -0
  42. batFramework/renderGroup.py +67 -0
  43. batFramework/resourceManager.py +84 -0
  44. batFramework/scene.py +242 -114
  45. batFramework/sceneManager.py +145 -107
  46. batFramework/scrollingSprite.py +115 -0
  47. batFramework/sprite.py +51 -0
  48. batFramework/stateMachine.py +2 -2
  49. batFramework/tileset.py +46 -0
  50. batFramework/time.py +117 -57
  51. batFramework/transition.py +184 -126
  52. batFramework/utils.py +31 -156
  53. batframework-1.0.8a3.dist-info/LICENCE +21 -0
  54. batframework-1.0.8a3.dist-info/METADATA +55 -0
  55. batframework-1.0.8a3.dist-info/RECORD +58 -0
  56. batFramework/debugger.py +0 -48
  57. batFramework/easing.py +0 -71
  58. batFramework/gui/constraints.py +0 -204
  59. batFramework/gui/frame.py +0 -19
  60. batFramework/particles.py +0 -77
  61. batFramework/transitionManager.py +0 -0
  62. batframework-1.0.8a2.dist-info/METADATA +0 -58
  63. batframework-1.0.8a2.dist-info/RECORD +0 -42
  64. {batframework-1.0.8a2.dist-info → batframework-1.0.8a3.dist-info}/WHEEL +0 -0
  65. {batframework-1.0.8a2.dist-info → batframework-1.0.8a3.dist-info}/top_level.txt +0 -0
@@ -1,84 +1,15 @@
1
1
  from .label import Label
2
2
  import batFramework as bf
3
- from types import FunctionType
4
- from typing import Self
5
- from .interactiveWidget import InteractiveWidget
3
+ from typing import Self, Callable
4
+ from .clickableWidget import ClickableWidget
6
5
  import pygame
6
+ from math import ceil
7
7
 
8
- class Button(Label,InteractiveWidget):
9
- _cache = {}
10
-
11
- def __init__(self, text: str, callback : FunctionType =None) -> None:
12
- # Label.__init__(self,text)
13
- self.callback = callback
14
- self.click_action = bf.Action("click").add_mouse_control(1)
15
- self.hover_action = bf.Action("hover").add_mouse_control(pygame.MOUSEMOTION)
16
- self.is_hovered : bool = False
17
- self.is_clicking : bool = False
18
- super().__init__(text=text)
19
- self.set_debug_color("cyan")
20
-
21
-
22
- def set_callback(self,callback : FunctionType = None)->Self:
23
- self.callback = callback
24
- return self
25
-
26
- def on_get_focus(self):
27
- super().on_get_focus()
28
- self.build()
29
-
30
- def on_lose_focus(self):
31
- super().on_lose_focus()
32
- self.build()
33
-
34
- def to_string_id(self)->str:
35
- return f"Button({self._text})"
36
-
37
- def click(self)->None:
38
- if self.callback and not self.is_clicking:
39
- self.is_clicking = True
40
- self.callback()
41
- self.is_clicking = False
42
-
43
-
44
- def do_process_actions(self,event):
45
- self.click_action.process_event(event)
46
- self.hover_action.process_event(event)
47
-
48
- def do_reset_actions(self):
49
- self.click_action.reset()
50
- self.hover_action.reset()
51
-
52
- def do_handle_event(self,event)->None:
53
- res = False
54
- if self.click_action.is_active():
55
- root = self.get_root()
56
- if root.hovered == self:
57
- if not self.is_focused : self.get_focus()
58
- self.click()
59
- elif self.hover_action.is_active():
60
- root = self.get_root()
61
- if root:
62
- if self.is_hovered and root.hovered != self:
63
- self.is_hovered = False
64
- self.build()
65
- if not self.is_hovered and root.hovered == self:
66
- self.is_hovered = True
67
- self.build()
68
- return res
69
-
70
-
71
-
72
- def build(self)->None:
73
- super().build()
74
- if self.is_hovered:
75
- hover_surf = Button._cache.get(self.surface.get_size(),None)
76
- if hover_surf is None:
77
- hover_surf = pygame.Surface(self.surface.get_size()).convert_alpha()
78
- hover_surf.fill((30,30,30,0))
79
- Button._cache[self.surface.get_size()] = hover_surf
80
- self.surface.blit(hover_surf,(0,0),special_flags = pygame.BLEND_ADD)
81
8
 
9
+ class Button(Label, ClickableWidget):
10
+ def __init__(self, text: str = "", callback: None | Callable = None) -> None:
11
+ super().__init__(text=text)
12
+ self.set_callback(callback)
82
13
 
83
- def apply_contraints(self)->None:
84
- super().apply_contraints()
14
+ def __str__(self) -> str:
15
+ return f"Button({self.text})"
@@ -0,0 +1,219 @@
1
+ from .label import Label
2
+ import batFramework as bf
3
+ from typing import Self, Callable
4
+ from .interactiveWidget import InteractiveWidget
5
+ from .shape import Shape
6
+ import pygame
7
+ from math import ceil
8
+
9
+
10
+ class ClickableWidget(Shape, InteractiveWidget):
11
+ _cache: dict = {}
12
+
13
+ def __init__(self, callback: None | Callable = None, *args, **kwargs) -> None:
14
+ super().__init__(*args, **kwargs)
15
+ self.callback = callback
16
+ self.is_pressed: bool = False
17
+ self.enabled: bool = True
18
+ self.hover_cursor = bf.const.DEFAULT_HOVER_CURSOR
19
+ self.click_cursor = bf.const.DEFAULT_CLICK_CURSOR
20
+ self.click_down_sound = None
21
+ self.click_up_sound = None
22
+ self.get_focus_sound = None
23
+ self.lose_focus_sound = None
24
+ self.pressed_relief: int = 1
25
+ self.unpressed_relief: int = 2
26
+ self.silent_focus: bool = False
27
+ self.set_debug_color("cyan")
28
+ self.set_relief(self.unpressed_relief)
29
+
30
+ def set_unpressed_relief(self, relief: int = 0) -> Self:
31
+ if relief == self.unpressed_relief:
32
+ return self
33
+ self.unpressed_relief = relief
34
+ self.dirty_shape = True
35
+ if not self.is_pressed:
36
+ self.set_relief(relief)
37
+ return self
38
+
39
+ def set_silent_focus(self, value: bool) -> Self:
40
+ self.silent_focus = value
41
+ return self
42
+
43
+ def set_pressed_relief(self, relief: int = 0) -> Self:
44
+ if relief == self.pressed_relief:
45
+ return self
46
+ self.pressed_relief = relief
47
+ self.dirty_shape = True
48
+ if self.is_pressed:
49
+ self.set_relief(relief)
50
+
51
+ return self
52
+
53
+ def set_click_down_sound(self, sound_name: str) -> Self:
54
+ self.click_down_sound = sound_name
55
+ return self
56
+
57
+ def set_click_up_sound(self, sound_name: str) -> Self:
58
+ self.click_up_sound = sound_name
59
+ return self
60
+
61
+ def set_get_focus_sound(self, sound_name: str) -> Self:
62
+ self.get_focus_sound = sound_name
63
+ return self
64
+
65
+ def set_lose_focus_sound(self, sound_name: str) -> Self:
66
+ self.lose_focus_sound = sound_name
67
+ return self
68
+
69
+ def set_hover_cursor(self, cursor: pygame.Cursor) -> Self:
70
+ self.hover_cursor = cursor
71
+ return self
72
+
73
+ def set_click_cursor(self, cursor: pygame.Cursor) -> Self:
74
+ self.click_cursor = cursor
75
+ return self
76
+
77
+ def get_surface_filter(self) -> pygame.Surface | None:
78
+ size = int(self.rect.w), int(self.rect.h)
79
+ surface_filter = ClickableWidget._cache.get((size, *self.border_radius), None)
80
+ if surface_filter is None:
81
+ # Create a mask from the original surface
82
+ mask = pygame.mask.from_surface(self.surface, threshold=0)
83
+
84
+ silhouette_surface = mask.to_surface(
85
+ setcolor=(30, 30, 30), unsetcolor=(0, 0, 0)
86
+ )
87
+
88
+ ClickableWidget._cache[(size, *self.border_radius)] = silhouette_surface
89
+
90
+ surface_filter = silhouette_surface
91
+
92
+ return surface_filter
93
+
94
+ def allow_focus_to_self(self) -> bool:
95
+ return True
96
+
97
+ def enable(self) -> Self:
98
+ self.enabled = True
99
+ self.dirty_surface = True
100
+ return self
101
+
102
+ def disable(self) -> Self:
103
+ self.enabled = False
104
+ self.dirty_surface = True
105
+ return self
106
+
107
+ def is_enabled(self) -> bool:
108
+ return self.enabled
109
+
110
+ def set_callback(self, callback: Callable) -> Self:
111
+ self.callback = callback
112
+ return self
113
+
114
+ def on_get_focus(self):
115
+ super().on_get_focus()
116
+ if self.get_focus_sound and not self.silent_focus:
117
+ if self.parent_scene and self.parent_scene.visible:
118
+ bf.AudioManager().play_sound(self.get_focus_sound)
119
+ if self.silent_focus:
120
+ self.silent_focus = False
121
+
122
+ def on_lose_focus(self):
123
+ super().on_lose_focus()
124
+ if self.lose_focus_sound and not self.silent_focus:
125
+ if self.parent_scene and self.parent_scene.visible:
126
+ bf.AudioManager().play_sound(self.lose_focus_sound)
127
+ if self.silent_focus:
128
+ self.silent_focus = False
129
+
130
+ def __str__(self) -> str:
131
+ return f"ClickableWidget"
132
+
133
+ def click(self, force=False) -> None:
134
+ if not self.enabled and not force:
135
+ return
136
+ if self.callback is not None:
137
+ self.callback()
138
+
139
+ def do_on_click_down(self, button) -> None:
140
+ if self.enabled and button == 1:
141
+ if not self.get_focus():
142
+ return
143
+ self.is_pressed = True
144
+ bf.AudioManager().play_sound(self.click_down_sound)
145
+
146
+ pygame.mouse.set_cursor(self.click_cursor)
147
+ self.set_relief(self.pressed_relief)
148
+
149
+ def do_on_click_up(self, button) -> None:
150
+ if self.enabled and button == 1 and self.is_pressed:
151
+ self.is_pressed = False
152
+ bf.AudioManager().play_sound(self.click_up_sound)
153
+ self.set_relief(self.unpressed_relief)
154
+ self.click()
155
+
156
+ def on_enter(self) -> None:
157
+ if not self.enabled:
158
+ return
159
+ super().on_enter()
160
+ self.dirty_surface = True
161
+ pygame.mouse.set_cursor(self.hover_cursor)
162
+
163
+ def on_exit(self) -> None:
164
+ super().on_exit()
165
+ if self.is_pressed:
166
+ self.set_relief(self.unpressed_relief)
167
+ self.is_pressed = False
168
+ self.dirty_surface = True
169
+
170
+ pygame.mouse.set_cursor(bf.const.DEFAULT_CURSOR)
171
+
172
+ def on_lose_focus(self):
173
+ super().on_lose_focus()
174
+ self.on_exit()
175
+
176
+ def on_key_down(self, key):
177
+ if key == pygame.K_SPACE:
178
+ self.on_click_down(1)
179
+ super().on_key_down(key)
180
+
181
+ def on_key_up(self, key):
182
+ if key == pygame.K_SPACE:
183
+ self.on_click_up(1)
184
+ super().on_key_up(key)
185
+
186
+ def _paint_disabled(self) -> None:
187
+ self.surface.blit(
188
+ self.get_surface_filter(), (0, 0), special_flags=pygame.BLEND_RGB_SUB
189
+ )
190
+
191
+ def _paint_hovered(self) -> None:
192
+ self.surface.blit(
193
+ self.get_surface_filter(), (0, 0), special_flags=pygame.BLEND_RGB_ADD
194
+ )
195
+
196
+ def get_padded_rect(self) -> pygame.FRect:
197
+ return pygame.FRect(
198
+ self.rect.x + self.padding[0],
199
+ self.rect.y
200
+ + self.padding[1]
201
+ + (self.unpressed_relief - self.pressed_relief if self.is_pressed else 0),
202
+ self.rect.w - self.padding[2] - self.padding[0],
203
+ self.rect.h - self.unpressed_relief - self.padding[1] - self.padding[3], #
204
+ )
205
+
206
+ def _get_elevated_rect(self) -> pygame.FRect:
207
+ return pygame.FRect(
208
+ 0,
209
+ self.unpressed_relief - self.pressed_relief if self.is_pressed else 0,
210
+ self.rect.w,
211
+ self.rect.h - self.unpressed_relief,
212
+ )
213
+
214
+ def paint(self) -> None:
215
+ super().paint()
216
+ if not self.enabled:
217
+ self._paint_disabled()
218
+ elif self.is_hovered:
219
+ self._paint_hovered()
@@ -0,0 +1 @@
1
+ from . import constraints