batframework 1.0.7__py3-none-any.whl → 1.0.8a2__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 +47 -41
- batFramework/action.py +20 -42
- batFramework/actionContainer.py +4 -43
- batFramework/animatedSprite.py +65 -98
- batFramework/audioManager.py +25 -39
- batFramework/camera.py +56 -226
- batFramework/constants.py +48 -32
- batFramework/cutscene.py +24 -32
- batFramework/cutsceneBlocks.py +33 -30
- batFramework/debugger.py +48 -0
- batFramework/dynamicEntity.py +7 -8
- batFramework/easing.py +23 -28
- batFramework/entity.py +52 -89
- batFramework/gui/__init__.py +1 -3
- batFramework/gui/button.py +58 -124
- batFramework/gui/constraints.py +90 -163
- batFramework/gui/container.py +18 -29
- batFramework/gui/debugger.py +42 -106
- batFramework/gui/frame.py +9 -15
- batFramework/gui/image.py +17 -36
- batFramework/gui/indicator.py +14 -20
- batFramework/gui/interactiveWidget.py +12 -63
- batFramework/gui/label.py +50 -113
- batFramework/gui/layout.py +51 -66
- batFramework/gui/root.py +29 -70
- batFramework/gui/shape.py +41 -34
- batFramework/gui/toggle.py +29 -37
- batFramework/gui/widget.py +131 -174
- batFramework/manager.py +14 -21
- batFramework/particles.py +20 -41
- batFramework/scene.py +72 -173
- batFramework/sceneManager.py +80 -40
- batFramework/stateMachine.py +0 -1
- batFramework/time.py +51 -62
- batFramework/transition.py +154 -0
- batFramework/utils.py +150 -3
- batframework-1.0.8a2.dist-info/METADATA +58 -0
- batframework-1.0.8a2.dist-info/RECORD +42 -0
- {batframework-1.0.7.dist-info → batframework-1.0.8a2.dist-info}/WHEEL +1 -1
- batFramework/enums.py +0 -14
- batFramework/fontManager.py +0 -57
- batFramework/gui/dialogueBox.py +0 -70
- batFramework/gui/slider.py +0 -5
- batFramework/gui/textInput.py +0 -88
- batFramework/resourceManager.py +0 -72
- batFramework/sprite.py +0 -33
- batFramework/tileset.py +0 -64
- batframework-1.0.7.dist-info/LICENCE +0 -21
- batframework-1.0.7.dist-info/METADATA +0 -55
- batframework-1.0.7.dist-info/RECORD +0 -50
- {batframework-1.0.7.dist-info → batframework-1.0.8a2.dist-info}/top_level.txt +0 -0
batFramework/gui/root.py
CHANGED
@@ -3,99 +3,58 @@ from .interactiveWidget import InteractiveWidget
|
|
3
3
|
from .widget import Widget
|
4
4
|
import pygame
|
5
5
|
|
6
|
-
|
7
6
|
class Root(InteractiveWidget):
|
8
|
-
def __init__(self
|
7
|
+
def __init__(self):
|
9
8
|
super().__init__()
|
10
|
-
self.drawing_camera = camera
|
11
9
|
self.surface = None
|
12
10
|
self.set_root()
|
13
11
|
self.rect.size = pygame.display.get_surface().get_size()
|
14
|
-
self.focused: InteractiveWidget
|
15
|
-
self.hovered: Widget
|
12
|
+
self.focused : InteractiveWidget = self
|
13
|
+
self.hovered : Widget|None = self
|
16
14
|
self.set_debug_color("purple")
|
17
15
|
|
18
|
-
def to_string(self)
|
19
|
-
|
16
|
+
def to_string(self)->str:
|
17
|
+
return "ROOT"
|
20
18
|
|
21
|
-
def
|
22
|
-
return "ROOT"
|
23
|
-
|
24
|
-
def get_focused(self) -> Widget | None:
|
19
|
+
def get_focused(self)->Widget|None:
|
25
20
|
return self.focused
|
26
21
|
|
27
|
-
def get_hovered(self)
|
22
|
+
def get_hovered(self)->Widget|None:
|
28
23
|
return self.hovered
|
24
|
+
|
25
|
+
def to_string_id(self)->str:
|
26
|
+
return "ROOT"
|
29
27
|
|
30
|
-
def
|
31
|
-
self.
|
32
|
-
|
33
|
-
def clear_hovered(self)->None:
|
34
|
-
if isinstance(self.hovered,InteractiveWidget): self.hovered.on_exit()
|
35
|
-
self.hovered = None
|
36
|
-
|
37
|
-
def focus_on(self, widget: InteractiveWidget|None) -> None:
|
38
|
-
if self.focused is not None:
|
28
|
+
def focus_on(self,widget:InteractiveWidget)->None:
|
29
|
+
if self.focused is not None:
|
39
30
|
self.focused.on_lose_focus()
|
40
|
-
if widget is None:
|
31
|
+
if widget is None :
|
41
32
|
self.focused = self
|
42
33
|
return
|
43
|
-
self.focused
|
34
|
+
self.focused= widget
|
44
35
|
self.focused.on_get_focus()
|
45
36
|
|
46
|
-
def set_size(self,
|
47
|
-
if not force:
|
48
|
-
|
49
|
-
self.rect.size = width, height
|
37
|
+
def set_size(self,width:float,height:float,force:bool=False)->"Root":
|
38
|
+
if not force : return self
|
39
|
+
self.rect.size = width,height
|
50
40
|
self.build(apply_constraints=True)
|
51
41
|
return self
|
52
|
-
|
53
|
-
def build(self,
|
54
|
-
if apply_constraints:
|
55
|
-
|
56
|
-
for child in self.children:
|
42
|
+
|
43
|
+
def build(self,apply_constraints:bool=False)->None:
|
44
|
+
if apply_constraints : self.apply_all_constraints()
|
45
|
+
for child in self.children :
|
57
46
|
child.build()
|
58
|
-
|
59
|
-
def do_handle_event(self,
|
47
|
+
|
48
|
+
def do_handle_event(self,event):
|
60
49
|
if event.type == pygame.VIDEORESIZE:
|
61
|
-
self.set_size(event.w,
|
50
|
+
self.set_size(event.w,event.h,force=True)
|
62
51
|
return True
|
63
|
-
if event.type == pygame.MOUSEBUTTONDOWN:
|
64
|
-
if self.hovered and isinstance(self.hovered,InteractiveWidget) :
|
65
|
-
self.hovered.on_click_down(event.button)
|
66
|
-
if event.type == pygame.MOUSEBUTTONUP:
|
67
|
-
if self.hovered and isinstance(self.hovered,InteractiveWidget) :
|
68
|
-
self.hovered.on_click_up(event.button)
|
69
|
-
|
70
52
|
return False
|
71
53
|
|
72
|
-
def
|
73
|
-
return self
|
74
|
-
|
75
|
-
def do_on_click_down(self,button:int)->None:
|
76
|
-
if button == 1 : self.clear_focused()
|
77
|
-
|
78
|
-
def top_at(self, x: float|int, y: float|int) -> "None|Widget":
|
79
|
-
if self.children:
|
80
|
-
for child in reversed(self.children):
|
81
|
-
r = child.top_at(x, y)
|
82
|
-
if r is not None:
|
83
|
-
return r
|
84
|
-
return self if self.rect.collidepoint(x,y) else None
|
85
|
-
|
86
|
-
def update(self, dt: float) -> None:
|
54
|
+
def update(self,dt:float)->None:
|
87
55
|
super().update(dt)
|
88
|
-
|
89
|
-
|
90
|
-
self.hovered = (
|
91
|
-
self.top_at(*transposed)
|
92
|
-
if self.top_at(*transposed)
|
93
|
-
else None
|
94
|
-
)
|
95
|
-
if old == self.hovered:
|
96
|
-
return
|
97
|
-
if old and isinstance(old,InteractiveWidget):
|
98
|
-
old.on_exit()
|
99
|
-
if self.hovered and isinstance(self.hovered,InteractiveWidget) :
|
100
|
-
self.hovered.on_enter()
|
56
|
+
self.hovered = self.top_at(*pygame.mouse.get_pos()) if self.top_at(*pygame.mouse.get_pos()) else None
|
57
|
+
|
101
58
|
|
59
|
+
|
60
|
+
|
batFramework/gui/shape.py
CHANGED
@@ -4,76 +4,83 @@ import pygame
|
|
4
4
|
|
5
5
|
|
6
6
|
class Shape(Widget):
|
7
|
-
def __init__(self,
|
8
|
-
self._color = (0,
|
9
|
-
self._border_radius:
|
10
|
-
self._outline: int = 0
|
11
|
-
self._outline_color: tuple[int,
|
12
|
-
super().__init__(convert_alpha=True)
|
13
|
-
self.set_size(width,
|
7
|
+
def __init__(self,width:float,height:float):
|
8
|
+
self._color = (0,0,0,0)
|
9
|
+
self._border_radius:list[int] = [0]
|
10
|
+
self._outline : int = 0
|
11
|
+
self._outline_color : tuple[int,int,int] | str = (0,0,0,0)
|
12
|
+
super().__init__(convert_alpha = True)
|
13
|
+
self.set_size(width,height)
|
14
14
|
|
15
|
-
|
15
|
+
|
16
|
+
def to_string_id(self)->str:
|
16
17
|
return "Shape"
|
17
18
|
|
18
|
-
def set_color(self,
|
19
|
+
def set_color(self,color:tuple[int,int,int]|str) -> "Frame":
|
19
20
|
self._color = color
|
20
21
|
self.build()
|
21
22
|
return self
|
22
23
|
|
23
|
-
def set_outline_color(self,
|
24
|
+
def set_outline_color(self,color:tuple[int,int,int]|str) -> "Frame":
|
24
25
|
self._outline_color = color
|
25
26
|
self.build()
|
26
27
|
return self
|
27
28
|
|
28
|
-
def set_border_radius(self,
|
29
|
-
if isinstance(value,
|
29
|
+
def set_border_radius(self,value:int|list[int]) -> "Frame":
|
30
|
+
if isinstance(value,int):
|
30
31
|
self._border_radius = [value]
|
31
32
|
else:
|
32
33
|
self._border_radius = value
|
33
34
|
self.build()
|
34
35
|
return self
|
35
|
-
|
36
|
-
def set_outline_width(self,
|
36
|
+
|
37
|
+
def set_outline_width(self,value:int) -> "Frame":
|
37
38
|
self._outline = value
|
38
39
|
self.build()
|
39
40
|
return self
|
40
|
-
|
41
|
-
def build(self)
|
41
|
+
|
42
|
+
def build(self)->None:
|
42
43
|
if self.surface.get_size() != self.get_size_int():
|
43
44
|
self.surface = pygame.Surface(self.get_size_int())
|
44
|
-
if self.convert_alpha:
|
45
|
+
if self.convert_alpha :
|
45
46
|
self.surface = self.surface.convert_alpha()
|
46
|
-
self.surface.fill((0,
|
47
|
-
if self.parent:
|
47
|
+
self.surface.fill((0,0,0,0))
|
48
|
+
if self.parent :
|
48
49
|
self.parent.children_modified()
|
49
50
|
if self._border_radius == [0]:
|
50
|
-
self._build_shape()
|
51
|
-
if self._outline:
|
52
|
-
self._build_outline()
|
51
|
+
self._build_shape()
|
52
|
+
if self._outline : self._build_outline()
|
53
53
|
else:
|
54
54
|
self._build_rounded_shape()
|
55
|
-
if self._outline:
|
56
|
-
|
55
|
+
if self._outline : self._build_rounded_outline()
|
56
|
+
|
57
57
|
|
58
|
-
def _build_shape(self)
|
58
|
+
def _build_shape(self)->None:
|
59
59
|
self.surface.fill(self._color)
|
60
60
|
|
61
|
-
def _build_rounded_shape(self)
|
62
|
-
self.surface.fill((0,
|
61
|
+
def _build_rounded_shape(self)->None:
|
62
|
+
self.surface.fill((0,0,0,0))
|
63
63
|
pygame.draw.rect(
|
64
|
-
self.surface,
|
64
|
+
self.surface,
|
65
|
+
self._color,
|
66
|
+
(0,0,*self.rect.size),
|
67
|
+
0,
|
68
|
+
*self._border_radius
|
65
69
|
)
|
66
70
|
|
67
|
-
def _build_outline(self)
|
71
|
+
def _build_outline(self)->None:
|
68
72
|
pygame.draw.rect(
|
69
|
-
self.surface,
|
73
|
+
self.surface,
|
74
|
+
self._outline_color,
|
75
|
+
(0,0,*self.rect.size),
|
76
|
+
self._outline
|
70
77
|
)
|
71
|
-
|
72
|
-
def _build_rounded_outline(self)
|
78
|
+
|
79
|
+
def _build_rounded_outline(self)->None:
|
73
80
|
pygame.draw.rect(
|
74
81
|
self.surface,
|
75
82
|
self._outline_color,
|
76
|
-
(0,
|
83
|
+
(0,0,*self.rect.size),
|
77
84
|
self._outline,
|
78
|
-
*self._border_radius
|
85
|
+
*self._border_radius
|
79
86
|
)
|
batFramework/gui/toggle.py
CHANGED
@@ -1,61 +1,52 @@
|
|
1
1
|
from .button import Button
|
2
|
-
from .indicator import Indicator,
|
2
|
+
from .indicator import Indicator,ToggleIndicator
|
3
3
|
import pygame
|
4
4
|
import batFramework as bf
|
5
5
|
from typing import Self
|
6
6
|
|
7
|
-
|
8
|
-
|
9
7
|
class Toggle(Button):
|
10
|
-
def __init__(self,
|
11
|
-
self.value:
|
8
|
+
def __init__(self,text:str,default_value : bool = False)->None:
|
9
|
+
self.value :bool= default_value
|
12
10
|
self.on_toggle = None
|
13
|
-
self.indicator: Indicator
|
14
|
-
self.gap:
|
15
|
-
super().__init__(text,
|
11
|
+
self.indicator : Indicator=ToggleIndicator(default_value)
|
12
|
+
self.gap :float|int = 0
|
13
|
+
super().__init__(text,self.toggle)
|
16
14
|
self.add_child(self.indicator)
|
17
|
-
self.set_gap(int(max(4,
|
18
|
-
self.
|
19
|
-
|
20
|
-
def set_value(self,value:bool,do_callback=False)->Self:
|
21
|
-
self.value = value
|
22
|
-
self.build()
|
15
|
+
self.set_gap(int(max(4,self.get_content_width()/3)))
|
16
|
+
# self.set_gap()
|
17
|
+
# self.set_gap(20)
|
23
18
|
|
24
|
-
|
25
|
-
return self
|
26
|
-
def set_gap(self, value: int | float) -> Self:
|
27
|
-
if value < 0:
|
28
|
-
return self
|
19
|
+
def set_gap(self,value:int|float)->Self:
|
20
|
+
if value < 0 : return self
|
29
21
|
self.gap = value
|
30
22
|
self.build()
|
31
|
-
if self.parent:
|
32
|
-
self.parent.children_modified()
|
23
|
+
if self.parent : self.parent.children_modified()
|
33
24
|
return self
|
34
|
-
|
35
|
-
def to_string_id(self) -> str:
|
25
|
+
def to_string_id(self)->str:
|
36
26
|
return f"Toggle({self.value})"
|
27
|
+
|
28
|
+
def toggle(self)->None:
|
29
|
+
self.value = not self.value
|
30
|
+
self.build()
|
31
|
+
if self.on_toggle : self.on_toggle(self.value)
|
37
32
|
|
38
|
-
def
|
39
|
-
self.set_value(not self.value,do_callback = True)
|
40
|
-
|
41
|
-
|
42
|
-
def set_toggle_callback(self, callback) -> Self:
|
33
|
+
def set_toggle_callback(self,callback)->Self:
|
43
34
|
self.on_toggle = callback
|
44
35
|
return self
|
45
36
|
|
46
|
-
def _build_layout(self)
|
37
|
+
def _build_layout(self)->None:
|
47
38
|
self.indicator.set_value(self.value)
|
48
|
-
|
39
|
+
|
49
40
|
size = (
|
50
41
|
0,
|
51
42
|
0,
|
52
43
|
self._text_rect.w + self.indicator.rect.w + self.gap,
|
53
|
-
max(self._text_rect.h, self.indicator.rect.h)
|
44
|
+
max(self._text_rect.h, self.indicator.rect.h)
|
54
45
|
)
|
55
|
-
|
46
|
+
|
56
47
|
required_rect = self.inflate_rect_by_padding(size)
|
57
|
-
|
58
|
-
if self.autoresize and (self.rect.size != required_rect.size):
|
48
|
+
|
49
|
+
if self.autoresize and (self.rect.size != required_rect.size) :
|
59
50
|
self.set_size(*required_rect.size)
|
60
51
|
return
|
61
52
|
|
@@ -64,7 +55,8 @@ class Toggle(Button):
|
|
64
55
|
|
65
56
|
self._text_rect.midleft = required_rect_rel.midleft
|
66
57
|
r = self.indicator.rect.copy()
|
67
|
-
r.midleft = required_rect.move(self._text_rect.w
|
58
|
+
r.midleft = required_rect.move(self._text_rect.w+self.gap,0).midleft
|
68
59
|
self.indicator.set_position(*r.topleft)
|
69
|
-
|
70
|
-
self.surface.blit(self._text_surface,
|
60
|
+
|
61
|
+
self.surface.blit(self._text_surface,self._text_rect)
|
62
|
+
|