batframework 1.0.8a1__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 +50 -53
- batFramework/action.py +105 -116
- batFramework/actionContainer.py +11 -53
- batFramework/animatedSprite.py +65 -115
- batFramework/audioManager.py +26 -70
- batFramework/camera.py +68 -253
- batFramework/constants.py +54 -16
- batFramework/cutscene.py +25 -34
- batFramework/cutsceneBlocks.py +42 -37
- batFramework/debugger.py +48 -0
- batFramework/dynamicEntity.py +7 -9
- batFramework/easing.py +71 -0
- batFramework/entity.py +98 -42
- batFramework/gui/__init__.py +2 -8
- batFramework/gui/button.py +79 -7
- batFramework/gui/constraints.py +204 -0
- batFramework/gui/container.py +31 -155
- batFramework/gui/debugger.py +43 -124
- batFramework/gui/frame.py +19 -0
- batFramework/gui/image.py +17 -41
- batFramework/gui/indicator.py +21 -41
- batFramework/gui/interactiveWidget.py +13 -116
- batFramework/gui/label.py +73 -278
- batFramework/gui/layout.py +61 -148
- batFramework/gui/root.py +37 -102
- batFramework/gui/shape.py +57 -258
- batFramework/gui/toggle.py +46 -97
- batFramework/gui/widget.py +254 -268
- batFramework/manager.py +19 -40
- batFramework/particles.py +77 -0
- batFramework/scene.py +107 -214
- batFramework/sceneManager.py +107 -150
- batFramework/stateMachine.py +0 -1
- batFramework/time.py +57 -117
- batFramework/transition.py +126 -184
- batFramework/transitionManager.py +0 -0
- batFramework/utils.py +161 -34
- batframework-1.0.8a2.dist-info/METADATA +58 -0
- batframework-1.0.8a2.dist-info/RECORD +42 -0
- {batframework-1.0.8a1.dist-info → batframework-1.0.8a2.dist-info}/WHEEL +1 -1
- batFramework/easingController.py +0 -58
- batFramework/enums.py +0 -104
- batFramework/fontManager.py +0 -65
- batFramework/gui/clickableWidget.py +0 -206
- batFramework/gui/constraints/__init__.py +0 -1
- batFramework/gui/constraints/constraints.py +0 -378
- batFramework/gui/dialogueBox.py +0 -96
- batFramework/gui/draggableWidget.py +0 -38
- batFramework/gui/meter.py +0 -76
- batFramework/gui/radioButton.py +0 -62
- batFramework/gui/slider.py +0 -220
- batFramework/gui/textInput.py +0 -134
- batFramework/object.py +0 -115
- batFramework/particle.py +0 -101
- batFramework/renderGroup.py +0 -62
- batFramework/resourceManager.py +0 -84
- batFramework/scrollingSprite.py +0 -113
- batFramework/sprite.py +0 -45
- batFramework/tileset.py +0 -46
- batframework-1.0.8a1.dist-info/LICENCE +0 -21
- batframework-1.0.8a1.dist-info/METADATA +0 -55
- batframework-1.0.8a1.dist-info/RECORD +0 -56
- {batframework-1.0.8a1.dist-info → batframework-1.0.8a2.dist-info}/top_level.txt +0 -0
batFramework/gui/layout.py
CHANGED
@@ -1,168 +1,81 @@
|
|
1
1
|
import batFramework as bf
|
2
2
|
from .widget import Widget
|
3
|
-
from .constraints
|
4
|
-
from typing import Self
|
5
|
-
import pygame
|
6
|
-
|
7
|
-
if TYPE_CHECKING:
|
8
|
-
from .container import Container
|
3
|
+
from .constraints import *
|
4
|
+
from typing import Self
|
9
5
|
|
10
6
|
class Layout:
|
11
|
-
def __init__(self, parent:
|
7
|
+
def __init__(self, parent: Widget=None):
|
12
8
|
self.parent = parent
|
13
|
-
self.child_constraints: list[Constraint] = []
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
self.
|
18
|
-
self.notify_parent()
|
9
|
+
self.child_constraints : list[Constraint] = []
|
10
|
+
|
11
|
+
def set_child_constraints(self,*constraints)->Self:
|
12
|
+
self.child_constraints = constraints
|
13
|
+
self.arrange()
|
19
14
|
return self
|
20
|
-
|
21
|
-
def set_parent(self,
|
15
|
+
|
16
|
+
def set_parent(self,parent:Widget):
|
22
17
|
self.parent = parent
|
23
|
-
self.
|
24
|
-
|
25
|
-
def notify_parent(self) -> None:
|
26
|
-
if self.parent:self.parent.dirty_children = True
|
27
|
-
|
28
|
-
def arrange(self) -> None:
|
29
|
-
return
|
30
|
-
|
31
|
-
def clamp_scroll(self)->None:
|
32
|
-
return
|
33
|
-
|
34
|
-
def get_raw_size(self)->tuple[float,float]:
|
35
|
-
return self.parent.rect.size if self.parent else 0,0
|
36
|
-
|
37
|
-
def get_auto_size(self)->tuple[float,float]:
|
38
|
-
return self.parent.rect.size if self.parent else 0,0
|
39
|
-
|
40
|
-
def focus_next_child(self)->None:
|
41
|
-
l = self.parent.get_interactive_children()
|
42
|
-
self.parent.focused_index = min(self.parent.focused_index + 1, len(l) - 1)
|
43
|
-
focused = l[self.parent.focused_index]
|
44
|
-
focused.get_focus()
|
45
|
-
self.scroll_to_widget(focused)
|
46
|
-
|
47
|
-
def focus_prev_child(self)->None:
|
48
|
-
l = self.parent.get_interactive_children()
|
49
|
-
self.parent.focused_index = max(self.parent.focused_index - 1, 0)
|
50
|
-
focused = l[self.parent.focused_index]
|
51
|
-
focused.get_focus()
|
52
|
-
self.scroll_to_widget(focused)
|
53
|
-
|
54
|
-
def scroll_to_widget(self,widget:Widget)->None:
|
55
|
-
padded = self.parent.get_padded_rect()
|
56
|
-
r = widget.rect
|
57
|
-
if padded.contains(r):return
|
58
|
-
clamped = r.clamp(padded)
|
59
|
-
dx,dy = clamped.move(-r.x,-r.y).topleft
|
60
|
-
self.parent.scroll_by((-dx,-dy))
|
61
|
-
|
18
|
+
self.arrange()
|
62
19
|
|
20
|
+
def arrange(self)->None:
|
21
|
+
raise NotImplementedError("Subclasses must implement arrange method")
|
63
22
|
|
64
23
|
class Column(Layout):
|
65
|
-
def __init__(self,
|
24
|
+
def __init__(self,gap:int=0,shrink:bool=False):
|
66
25
|
super().__init__()
|
67
26
|
self.gap = gap
|
68
|
-
self.
|
69
|
-
|
70
|
-
def
|
71
|
-
self.
|
72
|
-
self.
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
if self.gap:
|
86
|
-
parent_height += (len_children - 1) * self.gap
|
87
|
-
target_rect = self.parent.inflate_rect_by_padding((0,0,parent_width,parent_height))
|
88
|
-
return target_rect.size
|
89
|
-
|
90
|
-
def get_auto_size(self)-> tuple[float,float]:
|
91
|
-
target_size = list(self.get_raw_size())
|
92
|
-
if not self.parent.autoresize_w : target_size[0] = self.parent.rect.w
|
93
|
-
if not self.parent.autoresize_h : target_size[1] = self.parent.rect.h
|
94
|
-
return target_size
|
95
|
-
|
96
|
-
def arrange(self) -> None:
|
97
|
-
if not self.parent or not self.parent.children:
|
98
|
-
return
|
99
|
-
if self.child_constraints :
|
100
|
-
for child in self.parent.children : child.add_constraints(*self.child_constraints)
|
101
|
-
self.child_rect = self.parent.get_padded_rect()
|
102
|
-
|
103
|
-
if self.parent.autoresize_w or self.parent.autoresize_h:
|
104
|
-
width,height = self.get_auto_size()
|
105
|
-
if self.parent.rect.size != (width,height):
|
106
|
-
self.parent.set_size((width,height))
|
107
|
-
self.parent.build()
|
108
|
-
self.arrange()
|
109
|
-
return
|
110
|
-
self.child_rect.move_ip(-self.parent.scroll.x,-self.parent.scroll.y)
|
111
|
-
y = self.child_rect.top
|
112
|
-
for child in self.parent.children :
|
113
|
-
child.set_position(self.child_rect.x,y)
|
114
|
-
y+= child.get_min_required_size()[1] + self.gap
|
27
|
+
self.shrink :bool = shrink
|
28
|
+
|
29
|
+
def arrange(self)->None:
|
30
|
+
if not self.parent or not self.parent.children : return
|
31
|
+
if self.shrink:
|
32
|
+
len_children = len(self.parent.children)
|
33
|
+
parent_height = sum(c.rect.h for c in self.parent.children)
|
34
|
+
parent_width = max(c.rect.w for c in self.parent.children)
|
35
|
+
if self.gap : parent_height += (len_children-1) * self.gap
|
36
|
+
# print(self.parent.to_string(),len_children,parent_height)
|
37
|
+
c = self.parent.get_constraint("height")
|
38
|
+
if not c or c.height != parent_height :
|
39
|
+
self.parent.add_constraint(ConstraintHeight(parent_height))
|
40
|
+
c = self.parent.get_constraint("width")
|
41
|
+
if not c or c.width != parent_width :
|
42
|
+
self.parent.add_constraint(ConstraintWidth(parent_width))
|
43
|
+
current_y = self.parent.rect.top
|
115
44
|
|
45
|
+
for child in self.parent.children:
|
46
|
+
child.set_position(self.parent.rect.x,current_y)
|
47
|
+
current_y += child.rect.h + self.gap
|
48
|
+
for c in self.child_constraints:
|
49
|
+
if not child.has_constraint(c.name):
|
50
|
+
child.add_constraint(c)
|
51
|
+
|
116
52
|
class Row(Layout):
|
117
|
-
def __init__(self, gap: int = 0,
|
53
|
+
def __init__(self, gap: int = 0, shrink: bool = False):
|
118
54
|
super().__init__()
|
119
55
|
self.gap = gap
|
120
|
-
self.
|
121
|
-
|
122
|
-
def set_gap(self, value: float) -> Self:
|
123
|
-
self.gap = value
|
124
|
-
self.notify_parent()
|
125
|
-
return self
|
126
|
-
|
127
|
-
def set_spacing(self,spacing: bf.spacing)->Self:
|
128
|
-
self.spacing = spacing
|
129
|
-
self.notify_parent()
|
130
|
-
return self
|
131
|
-
|
132
|
-
|
133
|
-
def get_raw_size(self) -> tuple[float, float]:
|
134
|
-
len_children = len(self.parent.children)
|
135
|
-
if not len_children: return self.parent.rect.size
|
136
|
-
parent_width = sum(c.get_min_required_size()[0] for c in self.parent.children)
|
137
|
-
parent_height = max(c.get_min_required_size()[1] for c in self.parent.children)
|
138
|
-
if self.gap:
|
139
|
-
parent_width += (len_children - 1) * self.gap
|
140
|
-
target_rect = self.parent.inflate_rect_by_padding((0, 0, parent_width, parent_height))
|
141
|
-
|
142
|
-
return target_rect.size
|
143
|
-
|
144
|
-
def get_auto_size(self) -> tuple[float, float]:
|
145
|
-
target_size = list(self.get_raw_size())
|
146
|
-
if not self.parent.autoresize_w: target_size[0] = self.parent.rect.w
|
147
|
-
if not self.parent.autoresize_h: target_size[1] = self.parent.rect.h
|
148
|
-
return target_size
|
56
|
+
self.shrink = shrink
|
149
57
|
|
150
58
|
def arrange(self) -> None:
|
151
|
-
if not self.parent
|
59
|
+
if not self.parent:
|
152
60
|
return
|
153
|
-
if self.
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
self.
|
163
|
-
|
164
|
-
|
165
|
-
|
61
|
+
if self.shrink and self.parent.children:
|
62
|
+
len_children = len(self.parent.children)
|
63
|
+
parent_width = sum(c.rect.w for c in self.parent.children)
|
64
|
+
parent_height = max(c.rect.h for c in self.parent.children)
|
65
|
+
if self.gap:
|
66
|
+
parent_width += (len_children - 1) * self.gap
|
67
|
+
|
68
|
+
c = self.parent.get_constraint("width")
|
69
|
+
if not c or c.width != parent_width:
|
70
|
+
self.parent.add_constraint(ConstraintWidth(parent_width))
|
71
|
+
c = self.parent.get_constraint("height")
|
72
|
+
if not c or c.height != parent_height:
|
73
|
+
self.parent.add_constraint(ConstraintHeight(parent_height))
|
74
|
+
|
75
|
+
current_x = self.parent.rect.left
|
166
76
|
for child in self.parent.children:
|
167
|
-
child.set_position(
|
168
|
-
|
77
|
+
child.set_position(current_x,self.parent.rect.y)
|
78
|
+
current_x += child.rect.w + self.gap
|
79
|
+
for c in self.child_constraints:
|
80
|
+
if not child.has_constraint(c.name):
|
81
|
+
child.add_constraint(c)
|
batFramework/gui/root.py
CHANGED
@@ -3,123 +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.
|
11
|
-
self.
|
12
|
-
self.visible = False
|
9
|
+
self.surface = None
|
10
|
+
self.set_root()
|
13
11
|
self.rect.size = pygame.display.get_surface().get_size()
|
14
|
-
self.focused: InteractiveWidget
|
15
|
-
self.hovered: Widget
|
16
|
-
self.set_debug_color("
|
17
|
-
self.set_render_order(999)
|
18
|
-
self.clip_children = False
|
12
|
+
self.focused : InteractiveWidget = self
|
13
|
+
self.hovered : Widget|None = self
|
14
|
+
self.set_debug_color("purple")
|
19
15
|
|
20
|
-
def
|
21
|
-
|
16
|
+
def to_string(self)->str:
|
17
|
+
return "ROOT"
|
22
18
|
|
23
|
-
def get_focused(self)
|
19
|
+
def get_focused(self)->Widget|None:
|
24
20
|
return self.focused
|
25
21
|
|
26
|
-
def get_hovered(self)
|
22
|
+
def get_hovered(self)->Widget|None:
|
27
23
|
return self.hovered
|
24
|
+
|
25
|
+
def to_string_id(self)->str:
|
26
|
+
return "ROOT"
|
28
27
|
|
29
|
-
def
|
30
|
-
self.
|
31
|
-
|
32
|
-
def clear_hovered(self) -> None:
|
33
|
-
if isinstance(self.hovered, InteractiveWidget):
|
34
|
-
self.hovered.on_exit()
|
35
|
-
self.hovered = None
|
36
|
-
|
37
|
-
def focus_on(self, widget: InteractiveWidget | None) -> None:
|
38
|
-
if widget == self.focused : return
|
39
|
-
if widget and not widget.allow_focus_to_self():
|
40
|
-
return
|
41
|
-
if self.focused is not None:
|
28
|
+
def focus_on(self,widget:InteractiveWidget)->None:
|
29
|
+
if self.focused is not None:
|
42
30
|
self.focused.on_lose_focus()
|
43
|
-
if widget is None:
|
31
|
+
if widget is None :
|
44
32
|
self.focused = self
|
45
33
|
return
|
46
|
-
self.focused
|
34
|
+
self.focused= widget
|
47
35
|
self.focused.on_get_focus()
|
48
36
|
|
49
|
-
def
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
if any(t in w.tags for t in tags):
|
54
|
-
res.append(w)
|
55
|
-
self.visit(getter)
|
56
|
-
return res
|
57
|
-
|
58
|
-
def get_by_uid(self,uid:int)->Widget:
|
59
|
-
def helper(w: Widget,uid):
|
60
|
-
if w.uid == uid:
|
61
|
-
return w
|
62
|
-
for child in w.children:
|
63
|
-
res = helper(child,uid)
|
64
|
-
if res :
|
65
|
-
return child
|
66
|
-
|
67
|
-
return None
|
68
|
-
return helper(self,uid)
|
69
|
-
|
70
|
-
def set_size(self, size: tuple[float, float], force: bool = False) -> "Root":
|
71
|
-
if not force:
|
72
|
-
return self
|
73
|
-
self.rect.size = size
|
74
|
-
# self.build(resolve_constraints=True)
|
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
|
40
|
+
self.build(apply_constraints=True)
|
75
41
|
return self
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
if event.type == pygame.MOUSEBUTTONDOWN:
|
90
|
-
self.hovered.on_click_down(event.button)
|
91
|
-
elif event.type == pygame.MOUSEBUTTONUP:
|
92
|
-
self.hovered.on_click_up(event.button)
|
93
|
-
|
94
|
-
|
95
|
-
def do_on_click_down(self, button: int) -> None:
|
96
|
-
if button == 1:
|
97
|
-
self.clear_focused()
|
98
|
-
|
99
|
-
def top_at(self, x: float | int, y: float | int) -> "None|Widget":
|
100
|
-
if self.children:
|
101
|
-
for child in reversed(self.children):
|
102
|
-
r = child.top_at(x, y)
|
103
|
-
if r is not None:
|
104
|
-
return r
|
105
|
-
return self if self.rect.collidepoint(x, y) else None
|
106
|
-
|
107
|
-
def update(self, dt: float) -> None:
|
42
|
+
|
43
|
+
def build(self,apply_constraints:bool=False)->None:
|
44
|
+
if apply_constraints : self.apply_all_constraints()
|
45
|
+
for child in self.children :
|
46
|
+
child.build()
|
47
|
+
|
48
|
+
def do_handle_event(self,event):
|
49
|
+
if event.type == pygame.VIDEORESIZE:
|
50
|
+
self.set_size(event.w,event.h,force=True)
|
51
|
+
return True
|
52
|
+
return False
|
53
|
+
|
54
|
+
def update(self,dt:float)->None:
|
108
55
|
super().update(dt)
|
109
|
-
|
110
|
-
|
111
|
-
self.hovered = self.top_at(*transposed) if self.top_at(*transposed) else None
|
112
|
-
if old == self.hovered and isinstance(self.hovered, InteractiveWidget):
|
113
|
-
self.hovered.on_mouse_motion(*transposed)
|
114
|
-
return
|
115
|
-
if old and isinstance(old, InteractiveWidget):
|
116
|
-
old.on_exit()
|
117
|
-
if self.hovered and isinstance(self.hovered, InteractiveWidget):
|
118
|
-
self.hovered.on_enter()
|
119
|
-
|
120
|
-
def draw(self, camera: bf.Camera) -> int:
|
121
|
-
super().draw(camera)
|
122
|
-
if self.focused and self.focused!=self:
|
123
|
-
self.focused.draw_focused(camera)
|
56
|
+
self.hovered = self.top_at(*pygame.mouse.get_pos()) if self.top_at(*pygame.mouse.get_pos()) else None
|
57
|
+
|
124
58
|
|
125
59
|
|
60
|
+
|