batframework 1.0.8a9__py3-none-any.whl → 1.0.8a10__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 (70) hide show
  1. batFramework/__init__.py +68 -51
  2. batFramework/action.py +126 -99
  3. batFramework/actionContainer.py +53 -9
  4. batFramework/animatedSprite.py +141 -82
  5. batFramework/audioManager.py +69 -26
  6. batFramework/camera.py +259 -69
  7. batFramework/character.py +27 -0
  8. batFramework/constants.py +16 -54
  9. batFramework/cutscene.py +39 -29
  10. batFramework/cutsceneBlocks.py +36 -43
  11. batFramework/dynamicEntity.py +18 -9
  12. batFramework/easingController.py +58 -0
  13. batFramework/entity.py +48 -97
  14. batFramework/enums.py +113 -0
  15. batFramework/fontManager.py +65 -0
  16. batFramework/gui/__init__.py +10 -2
  17. batFramework/gui/button.py +9 -78
  18. batFramework/gui/clickableWidget.py +220 -0
  19. batFramework/gui/constraints/__init__.py +1 -0
  20. batFramework/gui/constraints/constraints.py +815 -0
  21. batFramework/gui/container.py +174 -32
  22. batFramework/gui/debugger.py +131 -43
  23. batFramework/gui/dialogueBox.py +99 -0
  24. batFramework/gui/draggableWidget.py +40 -0
  25. batFramework/gui/image.py +56 -20
  26. batFramework/gui/indicator.py +38 -21
  27. batFramework/gui/interactiveWidget.py +192 -13
  28. batFramework/gui/label.py +309 -74
  29. batFramework/gui/layout.py +231 -63
  30. batFramework/gui/meter.py +74 -0
  31. batFramework/gui/radioButton.py +84 -0
  32. batFramework/gui/root.py +134 -38
  33. batFramework/gui/shape.py +237 -57
  34. batFramework/gui/slider.py +240 -0
  35. batFramework/gui/style.py +10 -0
  36. batFramework/gui/styleManager.py +48 -0
  37. batFramework/gui/textInput.py +247 -0
  38. batFramework/gui/toggle.py +101 -51
  39. batFramework/gui/widget.py +358 -250
  40. batFramework/manager.py +52 -19
  41. batFramework/object.py +123 -0
  42. batFramework/particle.py +115 -0
  43. batFramework/renderGroup.py +67 -0
  44. batFramework/resourceManager.py +100 -0
  45. batFramework/scene.py +281 -123
  46. batFramework/sceneManager.py +178 -116
  47. batFramework/scrollingSprite.py +114 -0
  48. batFramework/sprite.py +51 -0
  49. batFramework/stateMachine.py +11 -8
  50. batFramework/templates/__init__.py +2 -0
  51. batFramework/templates/character.py +44 -0
  52. batFramework/templates/states.py +166 -0
  53. batFramework/tileset.py +46 -0
  54. batFramework/time.py +145 -58
  55. batFramework/transition.py +195 -124
  56. batFramework/triggerZone.py +1 -1
  57. batFramework/utils.py +112 -147
  58. batframework-1.0.8a10.dist-info/LICENCE +21 -0
  59. batframework-1.0.8a10.dist-info/METADATA +43 -0
  60. batframework-1.0.8a10.dist-info/RECORD +62 -0
  61. batFramework/debugger.py +0 -48
  62. batFramework/easing.py +0 -71
  63. batFramework/gui/constraints.py +0 -204
  64. batFramework/gui/frame.py +0 -19
  65. batFramework/particles.py +0 -77
  66. batFramework/transitionManager.py +0 -0
  67. batframework-1.0.8a9.dist-info/METADATA +0 -53
  68. batframework-1.0.8a9.dist-info/RECORD +0 -42
  69. {batframework-1.0.8a9.dist-info → batframework-1.0.8a10.dist-info}/WHEEL +0 -0
  70. {batframework-1.0.8a9.dist-info → batframework-1.0.8a10.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,220 @@
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) -> 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_pressed_relief(self, relief: int) -> Self:
40
+ if relief == self.pressed_relief:
41
+ return self
42
+ self.pressed_relief = relief
43
+ self.dirty_shape = True
44
+ if self.is_pressed:
45
+ self.set_relief(relief)
46
+ return self
47
+
48
+ def set_silent_focus(self, value: bool) -> Self:
49
+ self.silent_focus = value
50
+ return self
51
+
52
+ def set_click_down_sound(self, sound_name: str) -> Self:
53
+ self.click_down_sound = sound_name
54
+ return self
55
+
56
+ def set_click_up_sound(self, sound_name: str) -> Self:
57
+ self.click_up_sound = sound_name
58
+ return self
59
+
60
+ def set_get_focus_sound(self, sound_name: str) -> Self:
61
+ self.get_focus_sound = sound_name
62
+ return self
63
+
64
+ def set_lose_focus_sound(self, sound_name: str) -> Self:
65
+ self.lose_focus_sound = sound_name
66
+ return self
67
+
68
+ def set_hover_cursor(self, cursor: pygame.Cursor) -> Self:
69
+ self.hover_cursor = cursor
70
+ return self
71
+
72
+ def set_click_cursor(self, cursor: pygame.Cursor) -> Self:
73
+ self.click_cursor = cursor
74
+ return self
75
+
76
+ def get_surface_filter(self) -> pygame.Surface | None:
77
+ size = int(self.rect.w), int(self.rect.h)
78
+ surface_filter = ClickableWidget._cache.get((size, *self.border_radius), None)
79
+ if surface_filter is None:
80
+ # Create a mask from the original surface
81
+ mask = pygame.mask.from_surface(self.surface, threshold=0)
82
+
83
+ silhouette_surface = mask.to_surface(
84
+ setcolor=(30, 30, 30), unsetcolor=(0, 0, 0)
85
+ )
86
+
87
+ ClickableWidget._cache[(size, *self.border_radius)] = silhouette_surface
88
+
89
+ surface_filter = silhouette_surface
90
+
91
+ return surface_filter
92
+
93
+ def allow_focus_to_self(self) -> bool:
94
+ return True
95
+
96
+ def enable(self) -> Self:
97
+ self.enabled = True
98
+ self.dirty_surface = True
99
+ return self
100
+
101
+ def disable(self) -> Self:
102
+ self.enabled = False
103
+ self.dirty_surface = True
104
+ return self
105
+
106
+ def is_enabled(self) -> bool:
107
+ return self.enabled
108
+
109
+ def set_callback(self, callback: Callable) -> Self:
110
+ self.callback = callback
111
+ return self
112
+
113
+ def on_get_focus(self):
114
+ super().on_get_focus()
115
+ if self.get_focus_sound and not self.silent_focus:
116
+ if self.parent_scene and self.parent_scene.visible:
117
+ bf.AudioManager().play_sound(self.get_focus_sound)
118
+ if self.silent_focus:
119
+ self.silent_focus = False
120
+
121
+ def on_lose_focus(self):
122
+ super().on_lose_focus()
123
+ if self.lose_focus_sound and not self.silent_focus:
124
+ if self.parent_scene and self.parent_scene.visible:
125
+ bf.AudioManager().play_sound(self.lose_focus_sound)
126
+ if self.silent_focus:
127
+ self.silent_focus = False
128
+
129
+ def __str__(self) -> str:
130
+ return f"ClickableWidget"
131
+
132
+ def click(self, force=False) -> None:
133
+ if not self.enabled and not force:
134
+ return
135
+ if self.callback is not None:
136
+ self.callback()
137
+
138
+ def do_on_click_down(self, button) -> None:
139
+ if self.enabled and button == 1:
140
+ if not self.get_focus():
141
+ return
142
+ self.is_pressed = True
143
+ if self.click_down_sound:
144
+ bf.AudioManager().play_sound(self.click_down_sound)
145
+ pygame.mouse.set_cursor(self.click_cursor)
146
+ self.set_relief(self.pressed_relief)
147
+
148
+ def do_on_click_up(self, button) -> None:
149
+ if self.enabled and button == 1 and self.is_pressed:
150
+ self.is_pressed = False
151
+ if self.click_up_sound:
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()
220
+
@@ -0,0 +1 @@
1
+ from . import constraints