batframework 1.1.0__py3-none-any.whl → 2.0.0__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 +84 -51
- batFramework/action.py +280 -252
- batFramework/actionContainer.py +105 -38
- batFramework/animatedSprite.py +81 -117
- batFramework/animation.py +91 -0
- batFramework/audioManager.py +156 -85
- batFramework/baseScene.py +249 -0
- batFramework/camera.py +245 -123
- batFramework/constants.py +57 -75
- batFramework/cutscene.py +239 -119
- batFramework/cutsceneManager.py +34 -0
- batFramework/drawable.py +107 -0
- batFramework/dynamicEntity.py +30 -23
- batFramework/easingController.py +58 -0
- batFramework/entity.py +130 -123
- batFramework/enums.py +171 -0
- batFramework/fontManager.py +65 -0
- batFramework/gui/__init__.py +28 -14
- batFramework/gui/animatedLabel.py +90 -0
- batFramework/gui/button.py +18 -84
- batFramework/gui/clickableWidget.py +244 -0
- batFramework/gui/collapseContainer.py +98 -0
- batFramework/gui/constraints/__init__.py +1 -0
- batFramework/gui/constraints/constraints.py +1066 -0
- batFramework/gui/container.py +220 -49
- batFramework/gui/debugger.py +140 -47
- batFramework/gui/draggableWidget.py +63 -0
- batFramework/gui/image.py +61 -23
- batFramework/gui/indicator.py +116 -40
- batFramework/gui/interactiveWidget.py +243 -22
- batFramework/gui/label.py +147 -110
- batFramework/gui/layout.py +442 -81
- batFramework/gui/meter.py +155 -0
- batFramework/gui/radioButton.py +43 -0
- batFramework/gui/root.py +228 -60
- batFramework/gui/scrollingContainer.py +282 -0
- batFramework/gui/selector.py +232 -0
- batFramework/gui/shape.py +286 -86
- batFramework/gui/slider.py +353 -0
- batFramework/gui/style.py +10 -0
- batFramework/gui/styleManager.py +49 -0
- batFramework/gui/syncedVar.py +43 -0
- batFramework/gui/textInput.py +331 -0
- batFramework/gui/textWidget.py +308 -0
- batFramework/gui/toggle.py +140 -62
- batFramework/gui/tooltip.py +35 -0
- batFramework/gui/widget.py +546 -307
- batFramework/manager.py +131 -50
- batFramework/particle.py +118 -0
- batFramework/propertyEaser.py +79 -0
- batFramework/renderGroup.py +34 -0
- batFramework/resourceManager.py +130 -0
- batFramework/scene.py +31 -226
- batFramework/sceneLayer.py +134 -0
- batFramework/sceneManager.py +200 -165
- batFramework/scrollingSprite.py +115 -0
- batFramework/sprite.py +46 -0
- batFramework/stateMachine.py +49 -51
- batFramework/templates/__init__.py +2 -0
- batFramework/templates/character.py +15 -0
- batFramework/templates/controller.py +158 -0
- batFramework/templates/stateMachine.py +39 -0
- batFramework/tileset.py +46 -0
- batFramework/timeManager.py +213 -0
- batFramework/transition.py +162 -157
- batFramework/triggerZone.py +22 -22
- batFramework/utils.py +306 -184
- {batframework-1.1.0.dist-info → batframework-2.0.0.dist-info}/LICENSE +1 -1
- {batframework-1.1.0.dist-info → batframework-2.0.0.dist-info}/METADATA +8 -4
- batframework-2.0.0.dist-info/RECORD +72 -0
- batFramework/cutsceneBlocks.py +0 -176
- batFramework/debugger.py +0 -48
- batFramework/easing.py +0 -71
- batFramework/gui/constraints.py +0 -204
- batFramework/gui/frame.py +0 -19
- batFramework/particles.py +0 -77
- batFramework/time.py +0 -75
- batFramework/transitionManager.py +0 -0
- batframework-1.1.0.dist-info/RECORD +0 -43
- {batframework-1.1.0.dist-info → batframework-2.0.0.dist-info}/WHEEL +0 -0
- {batframework-1.1.0.dist-info → batframework-2.0.0.dist-info}/top_level.txt +0 -0
batFramework/gui/toggle.py
CHANGED
@@ -1,62 +1,140 @@
|
|
1
|
-
from .
|
2
|
-
from .
|
3
|
-
import
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
self
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
self.
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
def
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
)
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
self.
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
self.
|
62
|
-
|
1
|
+
from .widget import Widget
|
2
|
+
from .button import Button
|
3
|
+
from .indicator import Indicator, ToggleIndicator
|
4
|
+
from .shape import Shape
|
5
|
+
import batFramework as bf
|
6
|
+
from typing import Self, Callable, Any
|
7
|
+
import pygame
|
8
|
+
from .syncedVar import SyncedVar # Adjust import path
|
9
|
+
|
10
|
+
class Toggle(Button):
|
11
|
+
def __init__(
|
12
|
+
self,
|
13
|
+
text: str = "",
|
14
|
+
callback: Callable[[bool], Any] = None,
|
15
|
+
default_value: bool = False,
|
16
|
+
synced_var: SyncedVar[bool] = None,
|
17
|
+
) -> None:
|
18
|
+
# Use passed SyncedVar or create a new one
|
19
|
+
self.synced_var: SyncedVar[bool] = synced_var or SyncedVar(default_value)
|
20
|
+
|
21
|
+
# Local value synced to SyncedVar.value
|
22
|
+
self.value: bool = self.synced_var.value
|
23
|
+
|
24
|
+
self.indicator: ToggleIndicator = ToggleIndicator(self.value)
|
25
|
+
self.gap: float | int = 0
|
26
|
+
self.spacing: bf.spacing = bf.spacing.MANUAL
|
27
|
+
|
28
|
+
super().__init__(text, callback)
|
29
|
+
|
30
|
+
# Add indicator to widget
|
31
|
+
self.add(self.indicator)
|
32
|
+
self.set_clip_children(False)
|
33
|
+
|
34
|
+
# Bind this toggle’s _on_synced_var_update to synced_var updates
|
35
|
+
self.synced_var.bind(self, self._on_synced_var_update)
|
36
|
+
|
37
|
+
def _on_synced_var_update(self, new_value: bool) -> None:
|
38
|
+
# Called when SyncedVar changes externally
|
39
|
+
if self.value != new_value:
|
40
|
+
self.set_value(new_value, do_callback=False)
|
41
|
+
|
42
|
+
|
43
|
+
def set_indicator(self,indicator:Indicator):
|
44
|
+
self.remove(self.indicator)
|
45
|
+
self.synced_var.unbind(self.indicator)
|
46
|
+
self.indicator = indicator
|
47
|
+
self.add(self.indicator)
|
48
|
+
def set_visible(self, value: bool) -> Self:
|
49
|
+
self.indicator.set_visible(value)
|
50
|
+
return super().set_visible(value)
|
51
|
+
|
52
|
+
def set_value(self, value: bool, do_callback=False) -> Self:
|
53
|
+
if self.value == value:
|
54
|
+
return self # No change
|
55
|
+
|
56
|
+
self.value = value
|
57
|
+
self.indicator.set_value(value)
|
58
|
+
self.dirty_surface = True
|
59
|
+
|
60
|
+
# Update SyncedVar only if different (avoid recursion)
|
61
|
+
if self.synced_var.value != value:
|
62
|
+
self.synced_var.value = value
|
63
|
+
|
64
|
+
if do_callback and self.callback:
|
65
|
+
self.callback(self.value)
|
66
|
+
return self
|
67
|
+
|
68
|
+
def set_spacing(self, spacing: bf.spacing) -> Self:
|
69
|
+
if spacing == self.spacing:
|
70
|
+
return self
|
71
|
+
self.spacing = spacing
|
72
|
+
self.dirty_shape = True
|
73
|
+
return self
|
74
|
+
|
75
|
+
def click(self) -> None:
|
76
|
+
self.set_value(not self.value, do_callback=True)
|
77
|
+
|
78
|
+
def set_gap(self, value: int | float) -> Self:
|
79
|
+
value = max(0, value)
|
80
|
+
if value == self.gap:
|
81
|
+
return self
|
82
|
+
self.gap = value
|
83
|
+
self.dirty_shape = True
|
84
|
+
return self
|
85
|
+
|
86
|
+
def __str__(self) -> str:
|
87
|
+
return f"Toggle({self.value})"
|
88
|
+
|
89
|
+
def toggle(self) -> None:
|
90
|
+
self.set_value(not self.value, do_callback=True)
|
91
|
+
|
92
|
+
def get_min_required_size(self) -> tuple[float, float]:
|
93
|
+
left = self.text_widget.get_min_required_size()
|
94
|
+
gap = self.gap if self.text_widget.text else 0
|
95
|
+
full_rect = pygame.FRect(0, 0, left[0] + left[1] + gap, left[1])
|
96
|
+
full_rect.h += self.unpressed_relief
|
97
|
+
return self.expand_rect_with_padding((0, 0, *full_rect.size)).size
|
98
|
+
|
99
|
+
def _align_composed(self, left: Shape, right: Shape):
|
100
|
+
full_rect = self.get_inner_rect()
|
101
|
+
left_rect = left.rect
|
102
|
+
right_rect = right.rect
|
103
|
+
gap = {
|
104
|
+
bf.spacing.MIN: 0,
|
105
|
+
bf.spacing.HALF: (full_rect.width - left_rect.width - right_rect.width) // 2,
|
106
|
+
bf.spacing.MAX: full_rect.width - left_rect.width - right_rect.width,
|
107
|
+
bf.spacing.MANUAL: self.gap,
|
108
|
+
}.get(self.spacing, 0)
|
109
|
+
|
110
|
+
gap = max(0, gap)
|
111
|
+
combined_width = left_rect.width + right_rect.width + gap
|
112
|
+
|
113
|
+
group_x = {
|
114
|
+
bf.alignment.LEFT: full_rect.left,
|
115
|
+
bf.alignment.MIDLEFT: full_rect.left,
|
116
|
+
bf.alignment.RIGHT: full_rect.right - combined_width,
|
117
|
+
bf.alignment.MIDRIGHT: full_rect.right - combined_width,
|
118
|
+
bf.alignment.CENTER: full_rect.centerx - combined_width // 2,
|
119
|
+
}.get(self.alignment, full_rect.left)
|
120
|
+
|
121
|
+
# Set horizontal positions
|
122
|
+
left.set_position(x=group_x)
|
123
|
+
right.set_position(x=group_x + left_rect.width + gap)
|
124
|
+
|
125
|
+
# Set vertical positions
|
126
|
+
if self.alignment in {bf.alignment.TOP, bf.alignment.TOPLEFT, bf.alignment.TOPRIGHT}:
|
127
|
+
left.set_position(y=full_rect.top)
|
128
|
+
right.set_position(y=full_rect.top)
|
129
|
+
elif self.alignment in {bf.alignment.BOTTOM, bf.alignment.BOTTOMLEFT, bf.alignment.BOTTOMRIGHT}:
|
130
|
+
left.set_position(y=full_rect.bottom - left_rect.height)
|
131
|
+
right.set_position(y=full_rect.bottom - right_rect.height)
|
132
|
+
else:
|
133
|
+
left.set_center(y=full_rect.centery)
|
134
|
+
right.set_center(y=full_rect.centery)
|
135
|
+
|
136
|
+
def build(self) -> None:
|
137
|
+
res = super().build()
|
138
|
+
self.indicator.set_size(self.indicator.resolve_size((self.text_widget.rect.h, self.text_widget.rect.h)))
|
139
|
+
self._align_composed(self.text_widget, self.indicator)
|
140
|
+
return res
|
@@ -0,0 +1,35 @@
|
|
1
|
+
from .label import Label
|
2
|
+
import batFramework as bf
|
3
|
+
import sys
|
4
|
+
|
5
|
+
class ToolTip(Label):
|
6
|
+
def __init__(self, text = ""):
|
7
|
+
super().__init__(text)
|
8
|
+
self.fade_in_duration : float = 0.1
|
9
|
+
self.fade_out_duration : float = 0.1
|
10
|
+
self.set_render_order(sys.maxsize)
|
11
|
+
self.set_padding(2)
|
12
|
+
|
13
|
+
def __str__(self):
|
14
|
+
return f"ToolTip('{self.text_widget.text}')"
|
15
|
+
|
16
|
+
def top_at(self, x, y):
|
17
|
+
return None
|
18
|
+
|
19
|
+
def set_all_alpha(self,value:int):
|
20
|
+
self.text_widget.set_alpha(value)
|
21
|
+
return self.set_alpha(value)
|
22
|
+
|
23
|
+
def fade_in(self):
|
24
|
+
self.set_visible(True)
|
25
|
+
bf.PropertyEaser(
|
26
|
+
self.fade_in_duration,bf.easing.EASE_OUT,
|
27
|
+
0,self.parent_scene.name
|
28
|
+
).add_custom(self.get_alpha,self.set_all_alpha,255).start()
|
29
|
+
|
30
|
+
def fade_out(self):
|
31
|
+
bf.PropertyEaser(
|
32
|
+
self.fade_out_duration,bf.easing.EASE_IN,
|
33
|
+
0,self.parent_scene.name,
|
34
|
+
lambda : self.set_visible(False)
|
35
|
+
).add_custom(self.get_alpha,self.set_all_alpha,0).start()
|