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/fontManager.py
CHANGED
@@ -1,65 +1,65 @@
|
|
1
|
-
from .utils import Singleton
|
2
|
-
|
3
|
-
# put font stuff here later
|
4
|
-
import pygame
|
5
|
-
import os
|
6
|
-
import batFramework as bf
|
7
|
-
|
8
|
-
|
9
|
-
class FontManager(metaclass=Singleton):
|
10
|
-
def __init__(self):
|
11
|
-
pygame.font.init()
|
12
|
-
self.DEFAULT_FONT_SIZE = 16
|
13
|
-
self.MIN_FONT_SIZE = 8
|
14
|
-
self.MAX_FONT_SIZE = 64
|
15
|
-
self.DEFAULT_ANTIALIAS = False
|
16
|
-
self.FONTS = {}
|
17
|
-
|
18
|
-
def set_default_antialias(self, value: bool):
|
19
|
-
self.DEFAULT_ANTIALIAS = value
|
20
|
-
|
21
|
-
def set_default_text_size(self, size: int):
|
22
|
-
self.DEFAULT_FONT_SIZE = size
|
23
|
-
|
24
|
-
def init_font(self, raw_path: str | None):
|
25
|
-
try:
|
26
|
-
if raw_path is not None:
|
27
|
-
self.load_font(raw_path if raw_path else None, None)
|
28
|
-
self.load_font(raw_path)
|
29
|
-
except FileNotFoundError:
|
30
|
-
self.load_sysfont(raw_path)
|
31
|
-
self.load_sysfont(raw_path, None)
|
32
|
-
|
33
|
-
def load_font(self, path: str | None, name: str | None = ""):
|
34
|
-
if path is not None:
|
35
|
-
path = bf.ResourceManager().get_path(path) # convert path if given
|
36
|
-
filename = None
|
37
|
-
if path is not None:
|
38
|
-
filename = os.path.basename(path).split(".")[0]
|
39
|
-
|
40
|
-
# get filename if path is given, else None
|
41
|
-
if name != "":
|
42
|
-
filename = name # if name is not given, name is the filename
|
43
|
-
self.FONTS[filename] = {}
|
44
|
-
# fill the dict
|
45
|
-
for size in range(self.MIN_FONT_SIZE, self.MAX_FONT_SIZE+1, 2):
|
46
|
-
self.FONTS[filename][size] = pygame.font.Font(path, size=size)
|
47
|
-
|
48
|
-
def load_sysfont(self, font_name: str | None, key: str | None = ""):
|
49
|
-
if key == "":
|
50
|
-
key = font_name
|
51
|
-
if font_name is None or pygame.font.match_font(font_name) is None:
|
52
|
-
raise FileNotFoundError(f"Requested font '{font_name}' was not found")
|
53
|
-
self.FONTS[font_name] = {}
|
54
|
-
|
55
|
-
for size in range(self.MIN_FONT_SIZE, self.MAX_FONT_SIZE+1, 2):
|
56
|
-
self.FONTS[key][size] = pygame.font.SysFont(font_name, size=size)
|
57
|
-
|
58
|
-
def get_font(
|
59
|
-
self, name: str | None = None, text_size: int = 12
|
60
|
-
) -> pygame.Font | None:
|
61
|
-
if not name in self.FONTS:
|
62
|
-
return None
|
63
|
-
if not text_size in self.FONTS[name]:
|
64
|
-
return None
|
65
|
-
return self.FONTS[name][text_size]
|
1
|
+
from .utils import Singleton
|
2
|
+
|
3
|
+
# put font stuff here later
|
4
|
+
import pygame
|
5
|
+
import os
|
6
|
+
import batFramework as bf
|
7
|
+
|
8
|
+
|
9
|
+
class FontManager(metaclass=Singleton):
|
10
|
+
def __init__(self):
|
11
|
+
pygame.font.init()
|
12
|
+
self.DEFAULT_FONT_SIZE = 16
|
13
|
+
self.MIN_FONT_SIZE = 8
|
14
|
+
self.MAX_FONT_SIZE = 64
|
15
|
+
self.DEFAULT_ANTIALIAS = False
|
16
|
+
self.FONTS = {}
|
17
|
+
|
18
|
+
def set_default_antialias(self, value: bool):
|
19
|
+
self.DEFAULT_ANTIALIAS = value
|
20
|
+
|
21
|
+
def set_default_text_size(self, size: int):
|
22
|
+
self.DEFAULT_FONT_SIZE = size
|
23
|
+
|
24
|
+
def init_font(self, raw_path: str | None):
|
25
|
+
try:
|
26
|
+
if raw_path is not None:
|
27
|
+
self.load_font(raw_path if raw_path else None, None)
|
28
|
+
self.load_font(raw_path)
|
29
|
+
except FileNotFoundError:
|
30
|
+
self.load_sysfont(raw_path)
|
31
|
+
self.load_sysfont(raw_path, None)
|
32
|
+
|
33
|
+
def load_font(self, path: str | None, name: str | None = ""):
|
34
|
+
if path is not None:
|
35
|
+
path = bf.ResourceManager().get_path(path) # convert path if given
|
36
|
+
filename = None
|
37
|
+
if path is not None:
|
38
|
+
filename = os.path.basename(path).split(".")[0]
|
39
|
+
|
40
|
+
# get filename if path is given, else None
|
41
|
+
if name != "":
|
42
|
+
filename = name # if name is not given, name is the filename
|
43
|
+
self.FONTS[filename] = {}
|
44
|
+
# fill the dict
|
45
|
+
for size in range(self.MIN_FONT_SIZE, self.MAX_FONT_SIZE+1, 2):
|
46
|
+
self.FONTS[filename][size] = pygame.font.Font(path, size=size)
|
47
|
+
|
48
|
+
def load_sysfont(self, font_name: str | None, key: str | None = ""):
|
49
|
+
if key == "":
|
50
|
+
key = font_name
|
51
|
+
if font_name is None or pygame.font.match_font(font_name) is None:
|
52
|
+
raise FileNotFoundError(f"Requested font '{font_name}' was not found")
|
53
|
+
self.FONTS[font_name] = {}
|
54
|
+
|
55
|
+
for size in range(self.MIN_FONT_SIZE, self.MAX_FONT_SIZE+1, 2):
|
56
|
+
self.FONTS[key][size] = pygame.font.SysFont(font_name, size=size)
|
57
|
+
|
58
|
+
def get_font(
|
59
|
+
self, name: str | None = None, text_size: int = 12
|
60
|
+
) -> pygame.Font | None:
|
61
|
+
if not name in self.FONTS:
|
62
|
+
return None
|
63
|
+
if not text_size in self.FONTS[name]:
|
64
|
+
return None
|
65
|
+
return self.FONTS[name][text_size]
|
batFramework/gui/__init__.py
CHANGED
@@ -1,25 +1,28 @@
|
|
1
|
-
from .widget import Widget
|
2
|
-
from .styleManager import StyleManager
|
3
|
-
from .style import Style
|
4
|
-
from .image import Image
|
5
|
-
from .interactiveWidget import InteractiveWidget
|
6
|
-
from .draggableWidget import DraggableWidget
|
7
|
-
from .clickableWidget import ClickableWidget
|
8
|
-
from .root import Root
|
9
|
-
from .shape import Shape
|
10
|
-
from .meter import BarMeter
|
11
|
-
from .
|
12
|
-
from .
|
13
|
-
from .
|
14
|
-
from .
|
15
|
-
from .
|
16
|
-
from .
|
17
|
-
from .
|
18
|
-
from .
|
19
|
-
from .
|
20
|
-
from .
|
21
|
-
from .
|
22
|
-
from .
|
23
|
-
from .
|
24
|
-
from .
|
25
|
-
|
1
|
+
from .widget import Widget
|
2
|
+
from .styleManager import StyleManager
|
3
|
+
from .style import Style
|
4
|
+
from .image import Image
|
5
|
+
from .interactiveWidget import InteractiveWidget
|
6
|
+
from .draggableWidget import DraggableWidget
|
7
|
+
from .clickableWidget import ClickableWidget
|
8
|
+
from .root import Root
|
9
|
+
from .shape import Shape
|
10
|
+
from .meter import BarMeter
|
11
|
+
from .textWidget import TextWidget
|
12
|
+
from .label import Label
|
13
|
+
from .tooltip import ToolTip
|
14
|
+
from .animatedLabel import AnimatedLabel
|
15
|
+
from .textInput import TextInput
|
16
|
+
from .button import Button
|
17
|
+
from .debugger import *
|
18
|
+
from .layout import *
|
19
|
+
from .container import Container
|
20
|
+
from .indicator import *
|
21
|
+
from .toggle import Toggle
|
22
|
+
from .syncedVar import SyncedVar
|
23
|
+
from .radioButton import RadioButton
|
24
|
+
from .slider import Slider
|
25
|
+
from .selector import Selector
|
26
|
+
from .scrollingContainer import ScrollingContainer
|
27
|
+
from .collapseContainer import CollapseContainer
|
28
|
+
import batFramework.gui.constraints as constraints
|
@@ -1,89 +1,90 @@
|
|
1
|
-
from .label import Label
|
2
|
-
import batFramework as bf
|
3
|
-
from typing import Self,Callable,Any
|
4
|
-
|
5
|
-
|
6
|
-
class AnimatedLabel(Label):
|
7
|
-
def __init__(self,text="") -> None:
|
8
|
-
self.cursor_position: float = 0.0
|
9
|
-
self.text_speed: float = 20.0
|
10
|
-
self.is_over: bool = True
|
11
|
-
self.is_paused: bool = False
|
12
|
-
self.original_text = ""
|
13
|
-
self.end_callback : Callable[[],Any]= None
|
14
|
-
self.set_autoresize(False)
|
15
|
-
self.set_alignment(bf.alignment.LEFT)
|
16
|
-
super().__init__("")
|
17
|
-
self.set_text(text)
|
18
|
-
|
19
|
-
def __str__(self) -> str:
|
20
|
-
return "AnimatedLabel"
|
21
|
-
|
22
|
-
def set_end_callback(self,callback:Callable[[],Any]):
|
23
|
-
self.end_callback = callback
|
24
|
-
|
25
|
-
def pause(self) -> Self:
|
26
|
-
self.is_paused = True
|
27
|
-
return self
|
28
|
-
|
29
|
-
def resume(self) -> Self:
|
30
|
-
self.is_paused = False
|
31
|
-
return self
|
32
|
-
|
33
|
-
def set_text_speed(self, speed: float) -> Self:
|
34
|
-
self.text_speed = speed
|
35
|
-
return self
|
36
|
-
|
37
|
-
def cut_text_to_width(self, text: str) -> list[str]:
|
38
|
-
w = self.get_inner_width()
|
39
|
-
if text == "" or not self.font_object or w < self.font_object.point_size:
|
40
|
-
return [text]
|
41
|
-
left = 0
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
res
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
self.
|
69
|
-
self.
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
self.
|
1
|
+
from .label import Label
|
2
|
+
import batFramework as bf
|
3
|
+
from typing import Self,Callable,Any
|
4
|
+
|
5
|
+
|
6
|
+
class AnimatedLabel(Label):
|
7
|
+
def __init__(self,text="") -> None:
|
8
|
+
self.cursor_position: float = 0.0
|
9
|
+
self.text_speed: float = 20.0
|
10
|
+
self.is_over: bool = True
|
11
|
+
self.is_paused: bool = False
|
12
|
+
self.original_text = ""
|
13
|
+
self.end_callback : Callable[[],Any]= None
|
14
|
+
self.set_autoresize(False)
|
15
|
+
self.set_alignment(bf.alignment.LEFT)
|
16
|
+
super().__init__("")
|
17
|
+
self.set_text(text)
|
18
|
+
|
19
|
+
def __str__(self) -> str:
|
20
|
+
return "AnimatedLabel"
|
21
|
+
|
22
|
+
def set_end_callback(self,callback:Callable[[],Any]):
|
23
|
+
self.end_callback = callback
|
24
|
+
|
25
|
+
def pause(self) -> Self:
|
26
|
+
self.is_paused = True
|
27
|
+
return self
|
28
|
+
|
29
|
+
def resume(self) -> Self:
|
30
|
+
self.is_paused = False
|
31
|
+
return self
|
32
|
+
|
33
|
+
def set_text_speed(self, speed: float) -> Self:
|
34
|
+
self.text_speed = speed
|
35
|
+
return self
|
36
|
+
|
37
|
+
def cut_text_to_width(self, text: str) -> list[str]:
|
38
|
+
w = self.get_inner_width()
|
39
|
+
if text == "" or not self.text_widget.font_object or w < self.text_widget.font_object.point_size:
|
40
|
+
return [text]
|
41
|
+
left = 0
|
42
|
+
font_object = self.text_widget.font_object
|
43
|
+
for index in range(len(text)):
|
44
|
+
width = font_object.size(text[left:index])[0]
|
45
|
+
|
46
|
+
if width > w:
|
47
|
+
cut_point_start = index - 1
|
48
|
+
cut_point_end = index - 1
|
49
|
+
last_space = text.rfind(" ", 0, cut_point_start)
|
50
|
+
last_nline = text.rfind("\n", 0, cut_point_start)
|
51
|
+
|
52
|
+
if last_space != -1 or last_nline != -1: # space was found !:
|
53
|
+
cut_point_start = max(last_space, last_nline)
|
54
|
+
cut_point_end = cut_point_start + 1
|
55
|
+
res = [text[:cut_point_start].strip()]
|
56
|
+
res.extend(self.cut_text_to_width(text[cut_point_end:].strip()))
|
57
|
+
return res
|
58
|
+
elif text[index] == "\n":
|
59
|
+
left = index
|
60
|
+
return [text]
|
61
|
+
|
62
|
+
|
63
|
+
def _set_text_internal(self,text:str)->Self:
|
64
|
+
super().set_text(text)
|
65
|
+
return self
|
66
|
+
|
67
|
+
def set_text(self,text:str)->Self:
|
68
|
+
self.original_text = text
|
69
|
+
self.is_over = False
|
70
|
+
self.cursor_position = 0
|
71
|
+
|
72
|
+
def set_size(self, size):
|
73
|
+
super().set_size(size)
|
74
|
+
self._set_text_internal('\n'.join(self.cut_text_to_width(self.original_text[: int(self.cursor_position)])))
|
75
|
+
|
76
|
+
def do_update(self, dt):
|
77
|
+
if self.is_over:
|
78
|
+
return
|
79
|
+
if not self.is_over and self.cursor_position == len(self.original_text):
|
80
|
+
if len(self.original_text) == 0:
|
81
|
+
self._set_text_internal("")
|
82
|
+
self.is_over = True
|
83
|
+
if self.end_callback is not None:
|
84
|
+
self.end_callback()
|
85
|
+
return
|
86
|
+
self.cursor_position = min(
|
87
|
+
self.cursor_position + self.text_speed * dt, len(self.original_text)
|
88
|
+
)
|
89
|
+
# self.set_text(self.original_text[: int(self.cursor_position)])
|
90
|
+
self._set_text_internal('\n'.join(self.cut_text_to_width(self.original_text[: int(self.cursor_position)])))
|
batFramework/gui/button.py
CHANGED
@@ -1,18 +1,18 @@
|
|
1
|
-
from .label import Label
|
2
|
-
import batFramework as bf
|
3
|
-
from typing import Self, Callable,Any
|
4
|
-
from .clickableWidget import ClickableWidget
|
5
|
-
|
6
|
-
|
7
|
-
class Button(Label, ClickableWidget):
|
8
|
-
def __init__(self, text: str = "", callback: Callable[[],Any] = None) -> None:
|
9
|
-
super().__init__(text=text)
|
10
|
-
self.set_callback(callback)
|
11
|
-
|
12
|
-
def __str__(self) -> str:
|
13
|
-
return f"Button('{self.text}')"
|
14
|
-
|
15
|
-
def get_min_required_size(self):
|
16
|
-
res = super().get_min_required_size()
|
17
|
-
res = res[0],res[1]+self.unpressed_relief
|
1
|
+
from .label import Label
|
2
|
+
import batFramework as bf
|
3
|
+
from typing import Self, Callable,Any
|
4
|
+
from .clickableWidget import ClickableWidget
|
5
|
+
|
6
|
+
|
7
|
+
class Button(Label, ClickableWidget):
|
8
|
+
def __init__(self, text: str = "", callback: Callable[[],Any] = None) -> None:
|
9
|
+
super().__init__(text=text)
|
10
|
+
self.set_callback(callback)
|
11
|
+
|
12
|
+
def __str__(self) -> str:
|
13
|
+
return f"Button('{self.text_widget.text}')"
|
14
|
+
|
15
|
+
def get_min_required_size(self):
|
16
|
+
res = super().get_min_required_size()
|
17
|
+
res = res[0],res[1]+self.unpressed_relief
|
18
18
|
return res
|