batframework 1.0.9a10__py3-none-any.whl → 1.0.9a12__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 +2 -0
- batFramework/action.py +280 -279
- batFramework/actionContainer.py +105 -82
- batFramework/animatedSprite.py +80 -58
- batFramework/animation.py +91 -77
- batFramework/audioManager.py +156 -131
- batFramework/baseScene.py +249 -240
- batFramework/camera.py +245 -317
- batFramework/constants.py +57 -51
- batFramework/cutscene.py +239 -253
- batFramework/cutsceneManager.py +34 -34
- batFramework/drawable.py +107 -77
- batFramework/dynamicEntity.py +30 -30
- batFramework/easingController.py +58 -58
- batFramework/entity.py +130 -130
- batFramework/enums.py +171 -135
- batFramework/fontManager.py +65 -65
- batFramework/gui/__init__.py +28 -25
- batFramework/gui/animatedLabel.py +90 -89
- batFramework/gui/button.py +17 -17
- batFramework/gui/clickableWidget.py +244 -245
- batFramework/gui/collapseContainer.py +98 -0
- batFramework/gui/constraints/__init__.py +1 -1
- batFramework/gui/constraints/constraints.py +1066 -980
- batFramework/gui/container.py +220 -201
- batFramework/gui/debugger.py +140 -130
- batFramework/gui/draggableWidget.py +63 -44
- batFramework/gui/image.py +61 -58
- batFramework/gui/indicator.py +116 -113
- batFramework/gui/interactiveWidget.py +243 -239
- batFramework/gui/label.py +147 -344
- batFramework/gui/layout.py +442 -426
- batFramework/gui/meter.py +155 -96
- batFramework/gui/radioButton.py +43 -35
- batFramework/gui/root.py +228 -228
- batFramework/gui/scrollingContainer.py +282 -0
- batFramework/gui/selector.py +232 -250
- batFramework/gui/shape.py +286 -276
- batFramework/gui/slider.py +353 -397
- batFramework/gui/style.py +10 -10
- batFramework/gui/styleManager.py +49 -54
- batFramework/gui/syncedVar.py +43 -49
- batFramework/gui/textInput.py +331 -306
- batFramework/gui/textWidget.py +308 -0
- batFramework/gui/toggle.py +140 -128
- batFramework/gui/tooltip.py +35 -30
- batFramework/gui/widget.py +546 -521
- batFramework/manager.py +131 -134
- batFramework/particle.py +118 -118
- batFramework/propertyEaser.py +79 -79
- batFramework/renderGroup.py +34 -34
- batFramework/resourceManager.py +130 -130
- batFramework/scene.py +31 -31
- batFramework/sceneLayer.py +134 -138
- batFramework/sceneManager.py +200 -197
- batFramework/scrollingSprite.py +115 -115
- batFramework/sprite.py +46 -51
- batFramework/stateMachine.py +49 -54
- batFramework/templates/__init__.py +2 -1
- batFramework/templates/character.py +15 -0
- batFramework/templates/controller.py +158 -97
- batFramework/templates/stateMachine.py +39 -0
- batFramework/tileset.py +46 -46
- batFramework/timeManager.py +213 -213
- batFramework/transition.py +162 -162
- batFramework/triggerZone.py +22 -22
- batFramework/utils.py +306 -306
- {batframework-1.0.9a10.dist-info → batframework-1.0.9a12.dist-info}/LICENSE +20 -20
- {batframework-1.0.9a10.dist-info → batframework-1.0.9a12.dist-info}/METADATA +24 -17
- batframework-1.0.9a12.dist-info/RECORD +72 -0
- batframework-1.0.9a10.dist-info/RECORD +0 -67
- {batframework-1.0.9a10.dist-info → batframework-1.0.9a12.dist-info}/WHEEL +0 -0
- {batframework-1.0.9a10.dist-info → batframework-1.0.9a12.dist-info}/top_level.txt +0 -0
batFramework/gui/root.py
CHANGED
@@ -1,228 +1,228 @@
|
|
1
|
-
import batFramework as bf
|
2
|
-
from .interactiveWidget import InteractiveWidget
|
3
|
-
from .widget import Widget
|
4
|
-
import pygame
|
5
|
-
from typing import Self
|
6
|
-
import sys
|
7
|
-
|
8
|
-
|
9
|
-
class Root(InteractiveWidget):
|
10
|
-
def __init__(self, camera) -> None:
|
11
|
-
super().__init__()
|
12
|
-
self.is_root = True
|
13
|
-
self.drawing_camera: bf.Camera = camera
|
14
|
-
self.visible = False
|
15
|
-
self.rect.size = pygame.display.get_surface().get_size()
|
16
|
-
self.focused: InteractiveWidget | None = self
|
17
|
-
self.hovered: Widget | None = self
|
18
|
-
self.clip_children = False
|
19
|
-
self.set_debug_color("yellow")
|
20
|
-
|
21
|
-
self.show_tooltip : bool = True
|
22
|
-
self.tooltip = bf.gui.ToolTip("").set_visible(False)
|
23
|
-
self.add(self.tooltip)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
self.focused
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
self.
|
108
|
-
self.
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
if not event.consumed :
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
if self.hovered and self.hovered.tooltip_text:
|
159
|
-
self.tooltip.set_text(self.hovered.tooltip_text)
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
#
|
200
|
-
self.apply_updates("
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
if
|
217
|
-
self.
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
1
|
+
import batFramework as bf
|
2
|
+
from .interactiveWidget import InteractiveWidget
|
3
|
+
from .widget import Widget
|
4
|
+
import pygame
|
5
|
+
from typing import Self
|
6
|
+
import sys
|
7
|
+
|
8
|
+
|
9
|
+
class Root(InteractiveWidget):
|
10
|
+
def __init__(self, camera) -> None:
|
11
|
+
super().__init__()
|
12
|
+
self.is_root = True
|
13
|
+
self.drawing_camera: bf.Camera = camera
|
14
|
+
self.visible = False
|
15
|
+
self.rect.size = pygame.display.get_surface().get_size()
|
16
|
+
self.focused: InteractiveWidget | None = self
|
17
|
+
self.hovered: Widget | None = self
|
18
|
+
self.clip_children = False
|
19
|
+
self.set_debug_color("yellow")
|
20
|
+
|
21
|
+
self.show_tooltip : bool = True
|
22
|
+
self.tooltip = bf.gui.ToolTip("").set_visible(False)
|
23
|
+
self.add(self.tooltip)
|
24
|
+
self.set_click_pass_through(True)
|
25
|
+
|
26
|
+
def set_show_tooltip(self,value:bool)->Self:
|
27
|
+
self.show_tooltip = value
|
28
|
+
return self
|
29
|
+
|
30
|
+
def __str__(self) -> str:
|
31
|
+
return "Root"
|
32
|
+
|
33
|
+
def to_ascii_tree(self) -> str:
|
34
|
+
def f(w:Widget, depth):
|
35
|
+
prefix = " " * (depth * 4) + ("L__ " if depth > 0 else "")
|
36
|
+
children = "\n".join(f(c, depth + 1) for c in w.children) if w.children else ""
|
37
|
+
return f"{prefix}{str(w)}\n{children}"
|
38
|
+
return f(self, 0)
|
39
|
+
|
40
|
+
def set_parent_scene(self, parent_scene: bf.Scene) -> Self:
|
41
|
+
return super().set_parent_scene(parent_scene)
|
42
|
+
|
43
|
+
def get_focused(self) -> Widget | None:
|
44
|
+
return self.focused
|
45
|
+
|
46
|
+
def get_hovered(self) -> Widget | None:
|
47
|
+
return self.hovered
|
48
|
+
|
49
|
+
def clear_focused(self) -> None:
|
50
|
+
self.focus_on(None)
|
51
|
+
|
52
|
+
def clear_hovered(self) -> None:
|
53
|
+
if isinstance(self.hovered, InteractiveWidget):
|
54
|
+
self.hovered.on_exit()
|
55
|
+
self.hovered = None
|
56
|
+
|
57
|
+
def get_debug_outlines(self):
|
58
|
+
yield (self.rect, self.debug_color)
|
59
|
+
for child in self.children:
|
60
|
+
yield from child.get_debug_outlines()
|
61
|
+
|
62
|
+
def focus_on(self, widget: InteractiveWidget | None) -> None:
|
63
|
+
if widget == self.focused:
|
64
|
+
return
|
65
|
+
if widget and not widget.allow_focus_to_self():
|
66
|
+
return
|
67
|
+
if self.focused is not None:
|
68
|
+
self.focused.on_lose_focus()
|
69
|
+
if widget is None:
|
70
|
+
self.focused = self
|
71
|
+
return
|
72
|
+
self.focused = widget
|
73
|
+
self.focused.on_get_focus()
|
74
|
+
|
75
|
+
def get_by_tags(self, *tags) -> list[Widget]:
|
76
|
+
res = []
|
77
|
+
|
78
|
+
def getter(w: Widget):
|
79
|
+
nonlocal res
|
80
|
+
if any(t in w.tags for t in tags):
|
81
|
+
res.append(w)
|
82
|
+
|
83
|
+
self.visit(getter)
|
84
|
+
return res
|
85
|
+
|
86
|
+
def focus_next_tab(self, widget):
|
87
|
+
return
|
88
|
+
|
89
|
+
def focus_prev_tab(self, widget):
|
90
|
+
return
|
91
|
+
|
92
|
+
def get_by_uid(self, uid: int) -> "Widget":
|
93
|
+
def helper(w: "Widget", uid: int) -> "Widget":
|
94
|
+
if w.uid == uid:
|
95
|
+
return w
|
96
|
+
for child in w.children:
|
97
|
+
res = helper(child, uid)
|
98
|
+
if res is not None:
|
99
|
+
return res
|
100
|
+
return None
|
101
|
+
|
102
|
+
return helper(self, uid)
|
103
|
+
|
104
|
+
def set_size(self, size: tuple[float, float], force: bool = False) -> "Root":
|
105
|
+
if not force:
|
106
|
+
return self
|
107
|
+
self.rect.size = size
|
108
|
+
self.dirty_shape = True
|
109
|
+
self.dirty_size_constraints = True
|
110
|
+
return self
|
111
|
+
|
112
|
+
def process_event(self,event):
|
113
|
+
if not event.consumed : self.handle_event_early(event)
|
114
|
+
super().process_event(event)
|
115
|
+
|
116
|
+
def handle_event_early(self, event):
|
117
|
+
if event.type == pygame.VIDEORESIZE and not pygame.SCALED & bf.const.FLAGS:
|
118
|
+
self.set_size((event.w,event.h),force=True)
|
119
|
+
return
|
120
|
+
|
121
|
+
def handle_event(self, event):
|
122
|
+
super().handle_event(event)
|
123
|
+
if not event.consumed :
|
124
|
+
if event.type == pygame.KEYDOWN and event.key==pygame.K_TAB:
|
125
|
+
self.tab_focus(event)
|
126
|
+
|
127
|
+
def tab_focus(self,event=None):
|
128
|
+
if self.focused is None:
|
129
|
+
return
|
130
|
+
keys = pygame.key.get_pressed()
|
131
|
+
if keys[pygame.K_LSHIFT] or keys[pygame.K_RSHIFT]:
|
132
|
+
self.focused.focus_prev_tab(self.focused)
|
133
|
+
else:
|
134
|
+
self.focused.focus_next_tab(self.focused)
|
135
|
+
if event :event.consumed = True
|
136
|
+
|
137
|
+
|
138
|
+
def on_click_down(self, button: int,event) -> None:
|
139
|
+
if button == 1:
|
140
|
+
self.clear_focused()
|
141
|
+
super().on_click_down(button,event)
|
142
|
+
|
143
|
+
def top_at(self, x: float | int, y: float | int) -> "None|Widget":
|
144
|
+
for child in reversed(self.children):
|
145
|
+
r = child.top_at(x, y)
|
146
|
+
if r is not None:
|
147
|
+
return r
|
148
|
+
return self if self.rect.collidepoint(x, y) else None
|
149
|
+
|
150
|
+
def update(self, dt: float) -> None:
|
151
|
+
super().update(dt)
|
152
|
+
self.update_tree()
|
153
|
+
|
154
|
+
mouse_world = self.drawing_camera.get_mouse_pos()
|
155
|
+
prev_hovered = self.hovered
|
156
|
+
self.hovered = self.top_at(*mouse_world)
|
157
|
+
|
158
|
+
if (self.hovered and self.hovered.tooltip_text and self.show_tooltip):
|
159
|
+
self.tooltip.set_text(self.hovered.tooltip_text)
|
160
|
+
self.tooltip.fade_in()
|
161
|
+
else:
|
162
|
+
self.tooltip.fade_out()
|
163
|
+
|
164
|
+
# Tooltip logic
|
165
|
+
if self.tooltip.visible:
|
166
|
+
|
167
|
+
tooltip_size = self.tooltip.get_min_required_size()
|
168
|
+
# screen_w, screen_h = self.drawing_camera.rect.size
|
169
|
+
screen_w, screen_h = bf.const.RESOLUTION
|
170
|
+
|
171
|
+
tooltip_x, tooltip_y = mouse_world
|
172
|
+
tooltip_x+=4
|
173
|
+
tooltip_y+=4
|
174
|
+
tooltip_x = min(tooltip_x, screen_w - tooltip_size[0])
|
175
|
+
tooltip_y = min(tooltip_y, screen_h - tooltip_size[1])
|
176
|
+
tooltip_x = max(0, tooltip_x)
|
177
|
+
tooltip_y = max(0, tooltip_y)
|
178
|
+
|
179
|
+
self.tooltip.set_position(tooltip_x, tooltip_y)
|
180
|
+
|
181
|
+
if self.hovered == prev_hovered:
|
182
|
+
if isinstance(self.hovered, InteractiveWidget):
|
183
|
+
self.hovered.on_mouse_motion(*mouse_world)
|
184
|
+
return
|
185
|
+
|
186
|
+
if isinstance(prev_hovered, InteractiveWidget):
|
187
|
+
prev_hovered.on_exit()
|
188
|
+
if isinstance(self.hovered, InteractiveWidget):
|
189
|
+
self.hovered.on_enter()
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
|
194
|
+
def update_tree(self):
|
195
|
+
# 1st pass
|
196
|
+
self.apply_updates("pre")
|
197
|
+
self.apply_updates("post")
|
198
|
+
# 2nd pass
|
199
|
+
# self.apply_updates("pre")
|
200
|
+
# self.apply_updates("post")
|
201
|
+
|
202
|
+
|
203
|
+
def apply_pre_updates(self):
|
204
|
+
return
|
205
|
+
|
206
|
+
def apply_post_updates(self, skip_draw = False):
|
207
|
+
return
|
208
|
+
|
209
|
+
def draw(self, camera: bf.Camera) -> None:
|
210
|
+
if self.clip_children:
|
211
|
+
new_clip = camera.world_to_screen(self.get_inner_rect())
|
212
|
+
old_clip = camera.surface.get_clip()
|
213
|
+
camera.surface.set_clip(new_clip)
|
214
|
+
|
215
|
+
# Draw each child widget, sorted by render order
|
216
|
+
for child in [c for c in self.children if c != self.tooltip]:
|
217
|
+
if (not self.clip_children) or (child.rect.colliderect(self.rect) or not child.rect):
|
218
|
+
child.draw(camera)
|
219
|
+
if self.clip_children:
|
220
|
+
camera.surface.set_clip(old_clip)
|
221
|
+
|
222
|
+
if self.focused != self and (not self.focused is None) :
|
223
|
+
old_clip = camera.surface.get_clip()
|
224
|
+
camera.surface.set_clip(self.focused.parent.get_inner_rect())
|
225
|
+
self.focused.draw_focused(camera)
|
226
|
+
camera.surface.set_clip(old_clip)
|
227
|
+
|
228
|
+
self.tooltip.draw(camera)
|