batframework 1.0.8a7__py3-none-any.whl → 1.0.8a8__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 +51 -68
- batFramework/action.py +99 -126
- batFramework/actionContainer.py +9 -53
- batFramework/animatedSprite.py +82 -141
- batFramework/audioManager.py +26 -69
- batFramework/camera.py +69 -259
- batFramework/constants.py +54 -16
- batFramework/cutscene.py +29 -39
- batFramework/cutsceneBlocks.py +43 -36
- batFramework/debugger.py +48 -0
- batFramework/dynamicEntity.py +9 -18
- batFramework/easing.py +71 -0
- batFramework/entity.py +97 -48
- batFramework/gui/__init__.py +2 -10
- batFramework/gui/button.py +78 -9
- batFramework/gui/constraints.py +204 -0
- batFramework/gui/container.py +32 -174
- batFramework/gui/debugger.py +43 -131
- batFramework/gui/frame.py +19 -0
- batFramework/gui/image.py +20 -56
- batFramework/gui/indicator.py +21 -38
- batFramework/gui/interactiveWidget.py +13 -192
- batFramework/gui/label.py +74 -309
- batFramework/gui/layout.py +63 -231
- batFramework/gui/root.py +38 -134
- batFramework/gui/shape.py +57 -237
- batFramework/gui/toggle.py +51 -101
- batFramework/gui/widget.py +250 -358
- batFramework/manager.py +19 -52
- batFramework/particles.py +77 -0
- batFramework/scene.py +123 -281
- batFramework/sceneManager.py +116 -178
- batFramework/stateMachine.py +8 -11
- batFramework/time.py +58 -145
- batFramework/transition.py +124 -195
- batFramework/transitionManager.py +0 -0
- batFramework/triggerZone.py +1 -1
- batFramework/utils.py +147 -112
- batframework-1.0.8a8.dist-info/METADATA +53 -0
- batframework-1.0.8a8.dist-info/RECORD +42 -0
- {batframework-1.0.8a7.dist-info → batframework-1.0.8a8.dist-info}/WHEEL +1 -1
- batFramework/character.py +0 -27
- batFramework/easingController.py +0 -58
- batFramework/enums.py +0 -113
- batFramework/fontManager.py +0 -65
- batFramework/gui/clickableWidget.py +0 -220
- batFramework/gui/constraints/__init__.py +0 -1
- batFramework/gui/constraints/constraints.py +0 -815
- batFramework/gui/dialogueBox.py +0 -99
- batFramework/gui/draggableWidget.py +0 -40
- batFramework/gui/meter.py +0 -74
- batFramework/gui/radioButton.py +0 -84
- batFramework/gui/slider.py +0 -240
- batFramework/gui/style.py +0 -10
- batFramework/gui/styleManager.py +0 -48
- batFramework/gui/textInput.py +0 -247
- batFramework/object.py +0 -123
- batFramework/particle.py +0 -115
- batFramework/renderGroup.py +0 -67
- batFramework/resourceManager.py +0 -100
- batFramework/scrollingSprite.py +0 -114
- batFramework/sprite.py +0 -51
- batFramework/templates/__init__.py +0 -2
- batFramework/templates/character.py +0 -44
- batFramework/templates/states.py +0 -166
- batFramework/tileset.py +0 -46
- batframework-1.0.8a7.dist-info/LICENCE +0 -21
- batframework-1.0.8a7.dist-info/METADATA +0 -43
- batframework-1.0.8a7.dist-info/RECORD +0 -62
- {batframework-1.0.8a7.dist-info → batframework-1.0.8a8.dist-info}/top_level.txt +0 -0
batFramework/gui/image.py
CHANGED
@@ -1,59 +1,23 @@
|
|
1
1
|
import batFramework as bf
|
2
2
|
from .widget import Widget
|
3
|
-
from .shape import Shape
|
4
3
|
import pygame
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
return
|
26
|
-
padded = self.get_padded_rect().move(-self.rect.x,-self.rect.y)
|
27
|
-
target_size = padded.size
|
28
|
-
if self.original_surface.get_size() != target_size:
|
29
|
-
self.surface.blit(pygame.transform.scale(self.original_surface, target_size), padded.topleft)
|
30
|
-
else:
|
31
|
-
self.surface.blit(self.original_surface, padded.topleft)
|
32
|
-
|
33
|
-
def build(self) -> None:
|
34
|
-
if self.original_surface is not None:
|
35
|
-
self.set_size_if_autoresize(
|
36
|
-
self.inflate_rect_by_padding((0,0,*self.original_surface.get_size())).size
|
37
|
-
)
|
38
|
-
super().build()
|
39
|
-
|
40
|
-
|
41
|
-
def from_path(self, path: str) -> Self:
|
42
|
-
tmp = bf.ResourceManager().get_image(path, self.convert_alpha)
|
43
|
-
if tmp is None:
|
44
|
-
return self
|
45
|
-
self.original_surface = tmp
|
46
|
-
size = self.original_surface.get_size()
|
47
|
-
self.set_size(size)
|
48
|
-
self.dirty_surface = True
|
49
|
-
return self
|
50
|
-
|
51
|
-
def from_surface(self, surface: pygame.Surface) -> Self:
|
52
|
-
if surface is None:
|
53
|
-
return self
|
54
|
-
self.original_surface = surface
|
55
|
-
size = self.original_surface.get_size()
|
56
|
-
self.set_size(size)
|
57
|
-
|
58
|
-
self.dirty_surface = True
|
59
|
-
return self
|
4
|
+
class Image(Widget):
|
5
|
+
def __init__(self,data:pygame.Surface|str,size:None|tuple[int,int]=None,convert_alpha=True):
|
6
|
+
super().__init__(False)
|
7
|
+
self.surface = None
|
8
|
+
if isinstance(data,str):
|
9
|
+
path = bf.utils.get_path(data)
|
10
|
+
self.original_surface=pygame.image.load(path)
|
11
|
+
elif isinstance(data,pygame.Surface):
|
12
|
+
self.original_surface = data
|
13
|
+
|
14
|
+
if convert_alpha: self.original_surface = self.original_surface.convert_alpha()
|
15
|
+
if not size : size = self.original_surface.get_size()
|
16
|
+
self.set_size(*size)
|
17
|
+
|
18
|
+
|
19
|
+
def build(self)->None:
|
20
|
+
if not self.surface or self.surface.get_size() != self.get_size_int():
|
21
|
+
self.surface = pygame.transform.scale(self.original_surface,self.get_size_int())
|
22
|
+
|
23
|
+
|
batFramework/gui/indicator.py
CHANGED
@@ -1,57 +1,40 @@
|
|
1
1
|
from .shape import Shape
|
2
|
-
from typing import Any
|
2
|
+
from typing import Any
|
3
3
|
import pygame
|
4
|
-
from .
|
5
|
-
from .interactiveWidget import InteractiveWidget
|
6
|
-
from .draggableWidget import DraggableWidget
|
7
|
-
import batFramework as bf
|
8
|
-
|
4
|
+
# from .constraints import ConstraintAspectRatio
|
9
5
|
|
10
6
|
class Indicator(Shape):
|
11
|
-
def __init__(self,
|
12
|
-
super().__init__(
|
13
|
-
self.debug_color = "magenta"
|
14
|
-
self.set_outline_width(1)
|
15
|
-
self.set_outline_color("black")
|
7
|
+
def __init__(self,width:int|float= 10,height:int|float=10)->None:
|
8
|
+
super().__init__(width,height)
|
16
9
|
|
17
|
-
def to_string_id(self)
|
10
|
+
def to_string_id(self)->str:
|
18
11
|
return "Indicator"
|
19
12
|
|
20
|
-
def set_value(self,
|
13
|
+
def set_value(self,value:Any)->None:
|
21
14
|
pass
|
22
15
|
|
23
|
-
def get_value(self)
|
16
|
+
def get_value(self)->Any:
|
24
17
|
pass
|
25
18
|
|
26
|
-
def
|
27
|
-
|
19
|
+
def _build_indicator(self)->None:
|
20
|
+
pass
|
21
|
+
|
22
|
+
def build(self)->None:
|
23
|
+
super().build()
|
24
|
+
self._build_indicator()
|
28
25
|
|
29
26
|
|
30
27
|
class ToggleIndicator(Indicator):
|
31
|
-
def __init__(self,
|
32
|
-
self.value:
|
33
|
-
|
34
|
-
super().__init__((20, 20))
|
35
|
-
self.set_value(default_value)
|
36
|
-
|
37
|
-
# TODO aspect ratio would be good right about here
|
28
|
+
def __init__(self,default_value:bool)->None:
|
29
|
+
self.value:bool = default_value
|
30
|
+
super().__init__(20,20)
|
38
31
|
# self.add_constraint(ConstraintAspectRatio(1))
|
39
32
|
|
40
|
-
def
|
41
|
-
self.callback = callback
|
42
|
-
return self
|
43
|
-
|
44
|
-
def set_value(self, value: bool) -> None:
|
33
|
+
def set_value(self,value)->None:
|
45
34
|
self.value = value
|
46
|
-
if
|
47
|
-
|
48
|
-
self.dirty_surface = True
|
35
|
+
self.set_color("green" if value else "red")
|
36
|
+
self.build()
|
49
37
|
|
50
|
-
def get_value(self)
|
38
|
+
def get_value(self)->bool:
|
51
39
|
return self.value
|
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
|
40
|
+
#
|
@@ -1,201 +1,22 @@
|
|
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
|
-
|
19
2
|
|
20
3
|
class InteractiveWidget(Widget):
|
21
|
-
def __init__(self
|
22
|
-
|
23
|
-
self.is_hovered: bool = False
|
24
|
-
self.is_clicked_down: bool = False
|
25
|
-
self.focused_index = 0
|
4
|
+
def __init__(self,*args,**kwargs):
|
5
|
+
super().__init__(convert_alpha = True)
|
26
6
|
self.focusable = True
|
27
|
-
|
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
|
7
|
+
self.is_focused : bool = False
|
35
8
|
|
36
|
-
def get_focus(self)
|
37
|
-
if self.
|
38
|
-
|
39
|
-
if self.parent and isinstance(self.parent, InteractiveWidget):
|
40
|
-
self.parent.set_focused_child(self)
|
41
|
-
return True
|
42
|
-
return False
|
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)
|
43
12
|
|
44
|
-
def
|
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:
|
13
|
+
def on_get_focus(self)->None:
|
58
14
|
self.is_focused = True
|
59
|
-
self.do_on_get_focus()
|
60
15
|
|
61
|
-
def on_lose_focus(self)
|
16
|
+
def on_lose_focus(self)->None:
|
62
17
|
self.is_focused = False
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
-
)
|
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
|
+
|