batframework 1.0.8a8__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.8a8.dist-info/METADATA +0 -53
  68. batframework-1.0.8a8.dist-info/RECORD +0 -42
  69. {batframework-1.0.8a8.dist-info → batframework-1.0.8a10.dist-info}/WHEEL +0 -0
  70. {batframework-1.0.8a8.dist-info → batframework-1.0.8a10.dist-info}/top_level.txt +0 -0
@@ -1,40 +1,57 @@
1
1
  from .shape import Shape
2
- from typing import Any
2
+ from typing import Any, Self
3
3
  import pygame
4
- # from .constraints import ConstraintAspectRatio
4
+ from .widget import Widget
5
+ from .interactiveWidget import InteractiveWidget
6
+ from .draggableWidget import DraggableWidget
7
+ import batFramework as bf
8
+
5
9
 
6
10
  class Indicator(Shape):
7
- def __init__(self,width:int|float= 10,height:int|float=10)->None:
8
- super().__init__(width,height)
11
+ def __init__(self, size: tuple[int | float] = (10, 10)) -> None:
12
+ super().__init__(size)
13
+ self.debug_color = "magenta"
14
+ self.set_outline_width(1)
15
+ self.set_outline_color("black")
9
16
 
10
- def to_string_id(self)->str:
17
+ def to_string_id(self) -> str:
11
18
  return "Indicator"
12
19
 
13
- def set_value(self,value:Any)->None:
20
+ def set_value(self, value: Any) -> None:
14
21
  pass
15
22
 
16
- def get_value(self)->Any:
23
+ def get_value(self) -> Any:
17
24
  pass
18
25
 
19
- def _build_indicator(self)->None:
20
- pass
21
-
22
- def build(self)->None:
23
- super().build()
24
- self._build_indicator()
26
+ def top_at(self, x, y):
27
+ return None
25
28
 
26
29
 
27
30
  class ToggleIndicator(Indicator):
28
- def __init__(self,default_value:bool)->None:
29
- self.value:bool = default_value
30
- super().__init__(20,20)
31
+ def __init__(self, default_value: bool) -> None:
32
+ self.value: bool = default_value
33
+ self.callback = lambda val: self.set_color("green" if val else "red")
34
+ super().__init__((20, 20))
35
+ self.set_value(default_value)
36
+
37
+ # TODO aspect ratio would be good right about here
31
38
  # self.add_constraint(ConstraintAspectRatio(1))
32
39
 
33
- def set_value(self,value)->None:
40
+ def set_callback(self, callback) -> Self:
41
+ self.callback = callback
42
+ return self
43
+
44
+ def set_value(self, value: bool) -> None:
34
45
  self.value = value
35
- self.set_color("green" if value else "red")
36
- self.build()
46
+ if self.callback:
47
+ self.callback(value)
48
+ self.dirty_surface = True
37
49
 
38
- def get_value(self)->bool:
50
+ def get_value(self) -> bool:
39
51
  return self.value
40
- #
52
+
53
+ def top_at(self, x: float, y: float) -> "None|Widget":
54
+ r = super().top_at(x, y)
55
+ if r is self:
56
+ return None
57
+ return r
@@ -1,22 +1,201 @@
1
1
  from .widget import Widget
2
+ from typing import Self
3
+ from typing import TYPE_CHECKING
4
+ import pygame
5
+ from math import cos
6
+
7
+ if TYPE_CHECKING:
8
+ from .container import Container
9
+ import batFramework as bf
10
+
11
+ def children_has_focus(widget):
12
+ if isinstance(widget,InteractiveWidget) and widget.is_focused:
13
+ return True
14
+ for child in widget.children:
15
+ if children_has_focus(child):
16
+ return True
17
+ return False
18
+
2
19
 
3
20
  class InteractiveWidget(Widget):
4
- def __init__(self,*args,**kwargs):
5
- super().__init__(convert_alpha = True)
21
+ def __init__(self, *args, **kwargs) -> None:
22
+ self.is_focused: bool = False
23
+ self.is_hovered: bool = False
24
+ self.is_clicked_down: bool = False
25
+ self.focused_index = 0
6
26
  self.focusable = True
7
- self.is_focused : bool = False
27
+ super().__init__(*args, **kwargs)
28
+
29
+ def set_focusable(self, value: bool) -> Self:
30
+ self.focusable = value
31
+ return self
32
+
33
+ def allow_focus_to_self(self) -> bool:
34
+ return self.visible
8
35
 
9
- def get_focus(self)->bool:
10
- if self.parent is None or not self.focusable: return False
11
- self.get_root().focus_on(self)
36
+ def get_focus(self) -> bool:
37
+ if self.focusable and ((r := self.get_root()) is not None):
38
+ r.focus_on(self)
39
+ if self.parent and isinstance(self.parent, InteractiveWidget):
40
+ self.parent.set_focused_child(self)
41
+ return True
42
+ return False
12
43
 
13
- def on_get_focus(self)->None:
44
+ def lose_focus(self) -> bool:
45
+ if self.is_focused and ((r := self.get_root()) is not None):
46
+ r.focus_on(None)
47
+ return True
48
+ return False
49
+
50
+ def set_parent(self, parent: Widget) -> Self:
51
+ if parent is None and children_has_focus(self):
52
+ self.get_root().clear_focused()
53
+ # pass focus on
54
+
55
+ return super().set_parent(parent)
56
+
57
+ def on_get_focus(self) -> None:
14
58
  self.is_focused = True
59
+ self.do_on_get_focus()
15
60
 
16
- def on_lose_focus(self)->None:
61
+ def on_lose_focus(self) -> None:
17
62
  self.is_focused = False
18
-
19
- def lose_focus(self)->bool:
20
- if self.is_focused and self.parent is not None:
21
- self.get_root().focus_on(None)
22
-
63
+ self.do_on_lose_focus()
64
+
65
+ def focus_next_tab(self, previous_widget):
66
+
67
+ if previous_widget != self and self.visible:
68
+ if (
69
+ isinstance(self, InteractiveWidget)
70
+ and not isinstance(self, bf.Container)
71
+ and self.allow_focus_to_self()
72
+ ):
73
+ self.focus_next_sibling()
74
+ return
75
+ i_children = [
76
+ c
77
+ for c in self.children
78
+ if isinstance(c, InteractiveWidget) and c.visible
79
+ ]
80
+ if i_children:
81
+ index = i_children.index(previous_widget)
82
+ if index < len(i_children) - 1:
83
+
84
+ i_children[index + 1].get_focus()
85
+ return
86
+
87
+ if self.parent:
88
+ self.parent.focus_next_tab(self)
89
+
90
+ def focus_prev_tab(self, previous_widget):
91
+ if previous_widget != self and self.visible:
92
+ if (
93
+ isinstance(self, InteractiveWidget)
94
+ and not isinstance(self, bf.Container)
95
+ and self.allow_focus_to_self()
96
+ ):
97
+ self.get_focus()
98
+ return
99
+ i_children = [
100
+ c
101
+ for c in self.children
102
+ if isinstance(c, InteractiveWidget) and c.visible
103
+ ]
104
+
105
+ if i_children:
106
+ index = i_children.index(previous_widget)
107
+ if index > 0:
108
+ i_children[index - 1].get_focus()
109
+ return
110
+
111
+ if self.parent:
112
+ self.parent.focus_prev_tab(self)
113
+
114
+ def focus_next_sibling(self) -> None:
115
+ if isinstance(self.parent, bf.Container):
116
+ self.parent.focus_next_child()
117
+
118
+ def focus_prev_sibling(self) -> None:
119
+ if isinstance(self.parent, bf.Container):
120
+ self.parent.focus_prev_child()
121
+
122
+ def on_key_down(self, key) -> bool:
123
+ if key == pygame.K_DOWN:
124
+ self.focus_next_sibling()
125
+ elif key == pygame.K_UP:
126
+ self.focus_prev_sibling()
127
+ elif key == pygame.K_TAB and self.parent:
128
+ keys = pygame.key.get_pressed()
129
+ if keys[pygame.K_LSHIFT] or keys[pygame.K_RSHIFT]:
130
+
131
+ self.focus_prev_tab(self)
132
+ else:
133
+ self.focus_next_tab(self)
134
+
135
+ else:
136
+
137
+ return self.do_on_key_down(key)
138
+
139
+ return False
140
+
141
+ def on_key_up(self, key) -> bool:
142
+ return self.do_on_key_up(key)
143
+
144
+ def do_on_key_down(self, key) -> bool:
145
+ return False
146
+
147
+ def do_on_key_up(self, key) -> bool:
148
+ return False
149
+
150
+ def do_on_get_focus(self) -> None:
151
+ pass
152
+
153
+ def do_on_lose_focus(self) -> None:
154
+ pass
155
+
156
+ def on_click_down(self, button: int) -> bool:
157
+ self.is_clicked_down = True
158
+ return self.do_on_click_down(button)
159
+
160
+ def on_click_up(self, button: int) -> bool:
161
+ self.is_clicked_down = False
162
+ return self.do_on_click_up(button)
163
+
164
+ def do_on_click_down(self, button: int) -> bool:
165
+ return False
166
+
167
+ def do_on_click_up(self, button: int) -> bool:
168
+ return False
169
+
170
+ def on_enter(self) -> None:
171
+ self.is_hovered = True
172
+ self.do_on_enter()
173
+
174
+ def on_exit(self) -> None:
175
+ self.is_hovered = False
176
+ self.is_clicked_down = False
177
+ self.do_on_exit()
178
+
179
+ def do_on_enter(self) -> None:
180
+ pass
181
+
182
+ def do_on_exit(self) -> None:
183
+ pass
184
+
185
+ def on_mouse_motion(self, x, y) -> None:
186
+ self.do_on_mouse_motion(x, y)
187
+
188
+ def do_on_mouse_motion(self, x, y) -> None:
189
+ pass
190
+
191
+ def set_focused_child(self, child: "InteractiveWidget"):
192
+ pass
193
+
194
+ def draw_focused(self, camera: bf.Camera) -> None:
195
+ delta = 4 + ((2 * cos(pygame.time.get_ticks() / 100)) // 2) * 2
196
+ pygame.draw.rect(
197
+ camera.surface,
198
+ "white",
199
+ self.rect.move(-camera.rect.x, -camera.rect.y),#.inflate(delta, delta),
200
+ 1,
201
+ )