batframework 1.0.8a2__py3-none-any.whl → 1.0.8a4__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 +53 -50
- batFramework/action.py +126 -99
- batFramework/actionContainer.py +53 -9
- batFramework/animatedSprite.py +117 -73
- batFramework/audioManager.py +69 -26
- batFramework/camera.py +259 -69
- batFramework/constants.py +16 -54
- batFramework/cutscene.py +39 -29
- batFramework/cutsceneBlocks.py +36 -43
- batFramework/dynamicEntity.py +17 -9
- batFramework/easingController.py +58 -0
- batFramework/entity.py +48 -97
- batFramework/enums.py +113 -0
- batFramework/fontManager.py +65 -0
- batFramework/gui/__init__.py +10 -2
- batFramework/gui/button.py +9 -78
- batFramework/gui/clickableWidget.py +221 -0
- batFramework/gui/constraints/__init__.py +1 -0
- batFramework/gui/constraints/constraints.py +730 -0
- batFramework/gui/container.py +174 -32
- batFramework/gui/debugger.py +131 -43
- batFramework/gui/dialogueBox.py +99 -0
- batFramework/gui/draggableWidget.py +40 -0
- batFramework/gui/image.py +54 -18
- batFramework/gui/indicator.py +38 -21
- batFramework/gui/interactiveWidget.py +177 -13
- batFramework/gui/label.py +292 -74
- batFramework/gui/layout.py +219 -60
- batFramework/gui/meter.py +71 -0
- batFramework/gui/radioButton.py +84 -0
- batFramework/gui/root.py +134 -38
- batFramework/gui/shape.py +259 -57
- batFramework/gui/slider.py +230 -0
- batFramework/gui/style.py +10 -0
- batFramework/gui/styleManager.py +48 -0
- batFramework/gui/textInput.py +137 -0
- batFramework/gui/toggle.py +103 -51
- batFramework/gui/widget.py +329 -254
- batFramework/manager.py +40 -19
- batFramework/object.py +114 -0
- batFramework/particle.py +101 -0
- batFramework/renderGroup.py +67 -0
- batFramework/resourceManager.py +100 -0
- batFramework/scene.py +281 -123
- batFramework/sceneManager.py +141 -108
- batFramework/scrollingSprite.py +114 -0
- batFramework/sprite.py +51 -0
- batFramework/stateMachine.py +2 -2
- batFramework/tileset.py +46 -0
- batFramework/time.py +123 -58
- batFramework/transition.py +195 -124
- batFramework/utils.py +87 -151
- batframework-1.0.8a4.dist-info/LICENCE +21 -0
- batframework-1.0.8a4.dist-info/METADATA +55 -0
- batframework-1.0.8a4.dist-info/RECORD +58 -0
- 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/transitionManager.py +0 -0
- batframework-1.0.8a2.dist-info/METADATA +0 -58
- batframework-1.0.8a2.dist-info/RECORD +0 -42
- {batframework-1.0.8a2.dist-info → batframework-1.0.8a4.dist-info}/WHEEL +0 -0
- {batframework-1.0.8a2.dist-info → batframework-1.0.8a4.dist-info}/top_level.txt +0 -0
batFramework/cutsceneBlocks.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import batFramework as bf
|
2
|
-
from .cutscene import Cutscene,CutsceneManager
|
3
|
-
|
2
|
+
from .cutscene import Cutscene, CutsceneManager
|
3
|
+
from .transition import *
|
4
|
+
from typing import Optional,Callable
|
4
5
|
|
5
6
|
# Define the base CutsceneBlock class
|
6
7
|
class CutsceneBlock:
|
@@ -17,18 +18,18 @@ class CutsceneBlock:
|
|
17
18
|
self.ended = False
|
18
19
|
self.started = False
|
19
20
|
|
20
|
-
def get_scene_at(self,index):
|
21
|
-
return bf.CutsceneManager().manager.
|
21
|
+
def get_scene_at(self, index):
|
22
|
+
return bf.CutsceneManager().manager.scenes[index]
|
23
|
+
|
24
|
+
def set_scene(self, name, index=0):
|
25
|
+
return CutsceneManager().manager.set_scene(name, index)
|
22
26
|
|
23
|
-
def set_scene(self,name,index=0):
|
24
|
-
return CutsceneManager().manager.set_scene(name,index)
|
25
|
-
|
26
27
|
def get_current_scene(self):
|
27
28
|
return CutsceneManager().manager.get_current_scene()
|
28
|
-
|
29
|
-
def get_scene(self,name):
|
29
|
+
|
30
|
+
def get_scene(self, name):
|
30
31
|
return CutsceneManager().manager.get_scene(name)
|
31
|
-
|
32
|
+
|
32
33
|
# Set the parent cutscene for this block
|
33
34
|
def set_parent_cutscene(self, parent):
|
34
35
|
"""
|
@@ -90,17 +91,13 @@ class ParallelBlock(CutsceneBlock):
|
|
90
91
|
Represents a parallel execution block for multiple Cutscene blocks.
|
91
92
|
"""
|
92
93
|
|
93
|
-
# Constructor for ParallelBlock, taking a variable number of blocks as arguments
|
94
94
|
def __init__(self, *blocks) -> None:
|
95
95
|
super().__init__()
|
96
96
|
# List of blocks to run in parallel
|
97
|
-
self.blocks: list[CutsceneBlock] = blocks
|
97
|
+
self.blocks: list[CutsceneBlock] = list(blocks)
|
98
98
|
|
99
99
|
# Start the parallel block (override the base class method)
|
100
100
|
def start(self):
|
101
|
-
"""
|
102
|
-
Start the parallel execution block.
|
103
|
-
"""
|
104
101
|
super().start()
|
105
102
|
# Start each block in parallel
|
106
103
|
for block in self.blocks:
|
@@ -108,32 +105,14 @@ class ParallelBlock(CutsceneBlock):
|
|
108
105
|
|
109
106
|
# Process an event for each block in parallel
|
110
107
|
def process_event(self, event):
|
111
|
-
"""
|
112
|
-
Process an event for each block in the parallel execution block.
|
113
|
-
|
114
|
-
Args:
|
115
|
-
event: The event to be processed.
|
116
|
-
"""
|
117
108
|
_ = [b.process_event(event) for b in self.blocks]
|
118
109
|
|
119
110
|
# Update each block in parallel
|
120
111
|
def update(self, dt):
|
121
|
-
"""
|
122
|
-
Update each block in the parallel execution block.
|
123
|
-
|
124
|
-
Args:
|
125
|
-
dt: Time elapsed since the last update.
|
126
|
-
"""
|
127
112
|
_ = [b.update(dt) for b in self.blocks]
|
128
113
|
|
129
114
|
# Check if all blocks have ended
|
130
115
|
def has_ended(self):
|
131
|
-
"""
|
132
|
-
Check if all blocks in the parallel execution block have ended.
|
133
|
-
|
134
|
-
Returns:
|
135
|
-
bool: True if all blocks have ended, False otherwise.
|
136
|
-
"""
|
137
116
|
return all(b.has_ended() for b in self.blocks)
|
138
117
|
|
139
118
|
|
@@ -144,15 +123,16 @@ class SceneTransitionBlock(CutsceneBlock):
|
|
144
123
|
"""
|
145
124
|
|
146
125
|
# Constructor for SceneTransitionBlock
|
147
|
-
def __init__(
|
126
|
+
def __init__(
|
127
|
+
self, scene, transition: Transition = Fade(0.1), index: int = 0
|
128
|
+
) -> None:
|
148
129
|
super().__init__()
|
149
130
|
# Target scene, transition type, duration, and additional keyword arguments
|
150
131
|
self.target_scene = scene
|
151
132
|
self.transition = transition
|
152
|
-
self.
|
153
|
-
self.kwargs = kwargs
|
133
|
+
self.index = index
|
154
134
|
# Timer to handle the end of the transition
|
155
|
-
self.timer = bf.Timer(
|
135
|
+
self.timer = bf.Timer(transition.duration, self.end)
|
156
136
|
|
157
137
|
# Start the scene transition block
|
158
138
|
def start(self):
|
@@ -160,17 +140,30 @@ class SceneTransitionBlock(CutsceneBlock):
|
|
160
140
|
Start the scene transition block.
|
161
141
|
"""
|
162
142
|
super().start()
|
163
|
-
print(f"transition to {scene}")
|
164
|
-
|
165
143
|
# Initiate the scene transition
|
166
|
-
if self.get_current_scene().
|
144
|
+
if self.get_current_scene().name == self.target_scene:
|
167
145
|
self.end()
|
168
146
|
return
|
169
147
|
CutsceneManager().manager.transition_to_scene(
|
170
|
-
self.target_scene, self.transition,
|
148
|
+
self.target_scene, self.transition, self.index
|
171
149
|
)
|
172
150
|
# Start the timer to handle the end of the transition
|
173
151
|
self.timer.start()
|
174
152
|
|
175
|
-
|
176
|
-
|
153
|
+
class DelayBlock(CutsceneBlock):
|
154
|
+
def __init__(self, duration) -> None:
|
155
|
+
super().__init__()
|
156
|
+
self.timer = bf.Timer(duration=duration, end_callback=self.end)
|
157
|
+
|
158
|
+
def start(self):
|
159
|
+
super().start()
|
160
|
+
self.timer.start()
|
161
|
+
|
162
|
+
class FunctionBlock(CutsceneBlock):
|
163
|
+
def __init__(self, func : Optional[Callable]) -> None:
|
164
|
+
self.function = func
|
165
|
+
|
166
|
+
def start(self):
|
167
|
+
super().start()
|
168
|
+
if self.function : self.function()
|
169
|
+
self.end()
|
batFramework/dynamicEntity.py
CHANGED
@@ -2,22 +2,30 @@ import pygame
|
|
2
2
|
import batFramework as bf
|
3
3
|
from typing import Self
|
4
4
|
|
5
|
+
|
5
6
|
class DynamicEntity(bf.Entity):
|
6
7
|
def __init__(
|
7
8
|
self,
|
8
|
-
size
|
9
|
-
|
10
|
-
|
11
|
-
convert_alpha : bool=False
|
9
|
+
size: None | tuple[int, int] = None,
|
10
|
+
surface_flags: int = 0,
|
11
|
+
convert_alpha: bool = False,*args,**kwargs
|
12
12
|
) -> None:
|
13
|
-
super().__init__(size,
|
13
|
+
super().__init__(size, surface_flags, convert_alpha,*args,**kwargs)
|
14
14
|
self.velocity = pygame.math.Vector2(0, 0)
|
15
15
|
|
16
|
-
def on_collideX(self, collider:
|
16
|
+
def on_collideX(self, collider: "DynamicEntity"):
|
17
|
+
"""
|
18
|
+
Return true if collision
|
19
|
+
"""
|
17
20
|
return False
|
18
21
|
|
19
|
-
def on_collideY(self, collider:
|
22
|
+
def on_collideY(self, collider: "DynamicEntity"):
|
23
|
+
"""
|
24
|
+
Return true if collision
|
25
|
+
"""
|
20
26
|
return False
|
21
27
|
|
22
|
-
def move_by_velocity(self)->None:
|
23
|
-
self.set_position(
|
28
|
+
def move_by_velocity(self, dt) -> None:
|
29
|
+
self.set_position(
|
30
|
+
self.rect.x + self.velocity.x * dt, self.rect.y + self.velocity.y * dt
|
31
|
+
)
|
@@ -0,0 +1,58 @@
|
|
1
|
+
import pygame
|
2
|
+
import batFramework as bf
|
3
|
+
from functools import lru_cache
|
4
|
+
from .enums import easing
|
5
|
+
|
6
|
+
|
7
|
+
@lru_cache(maxsize=None)
|
8
|
+
def process_value(progress: float, p0: float, p1: float, p2: float, p3: float) -> float:
|
9
|
+
if p0 == 0 and p1 == 0 and p2 == 1 and p3 == 1: # Linear easing control points
|
10
|
+
return progress
|
11
|
+
t = progress
|
12
|
+
t_inv = 1.0 - t
|
13
|
+
t2 = t * t
|
14
|
+
t3 = t * t2
|
15
|
+
t_inv2 = t_inv * t_inv
|
16
|
+
return 3 * t_inv2 * t * p1 + 3 * t_inv * t2 * p3 + t3
|
17
|
+
|
18
|
+
|
19
|
+
class EasingController(bf.Timer):
|
20
|
+
def __init__(
|
21
|
+
self,
|
22
|
+
easing_function: easing = easing.LINEAR,
|
23
|
+
duration: float = 1,
|
24
|
+
update_callback=None,
|
25
|
+
end_callback=None,
|
26
|
+
loop: bool = False,
|
27
|
+
) -> None:
|
28
|
+
self.easing_function = easing_function
|
29
|
+
self.update_callback = update_callback
|
30
|
+
self.value: float = 0.0
|
31
|
+
super().__init__(duration, end_callback, loop)
|
32
|
+
|
33
|
+
def get_value(self) -> float:
|
34
|
+
return self.value
|
35
|
+
|
36
|
+
def start(self, force: bool = False):
|
37
|
+
super().start(force)
|
38
|
+
self.value = 0
|
39
|
+
|
40
|
+
def update(self, dt: float) -> None:
|
41
|
+
if self.get_progression() == 1:
|
42
|
+
return
|
43
|
+
super().update(dt)
|
44
|
+
if self.get_progression() == 0:
|
45
|
+
return
|
46
|
+
if self.easing_function == easing.LINEAR:
|
47
|
+
self.value = self.get_progression()
|
48
|
+
else:
|
49
|
+
self.value = process_value(
|
50
|
+
self.get_progression(), *self.easing_function.control_points
|
51
|
+
)
|
52
|
+
if self.update_callback:
|
53
|
+
self.update_callback(self.value)
|
54
|
+
|
55
|
+
def end(self):
|
56
|
+
if self.update_callback:
|
57
|
+
self.update_callback(1)
|
58
|
+
super().end()
|
batFramework/entity.py
CHANGED
@@ -1,123 +1,74 @@
|
|
1
|
+
from typing import Any, Self
|
1
2
|
import pygame
|
2
3
|
import batFramework as bf
|
3
|
-
from
|
4
|
+
from .object import Object
|
5
|
+
|
6
|
+
|
7
|
+
class Entity(Object):
|
8
|
+
"""
|
9
|
+
Basic entity class
|
10
|
+
"""
|
4
11
|
|
5
|
-
class Entity:
|
6
|
-
instance_num = 0
|
7
12
|
def __init__(
|
8
13
|
self,
|
9
|
-
size
|
10
|
-
|
11
|
-
|
12
|
-
|
14
|
+
size: None | tuple[int, int] = None,
|
15
|
+
surface_flags: int = 0,
|
16
|
+
convert_alpha: bool = False,
|
17
|
+
*args,
|
18
|
+
**kwargs,
|
13
19
|
) -> None:
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
if convert_alpha and self.surface is not None:
|
20
|
+
super().__init__()
|
21
|
+
self.visible: bool = True
|
22
|
+
self.rect.size = (10, 10) if size is None else size
|
23
|
+
self.convert_alpha: bool = convert_alpha
|
24
|
+
self.surface_flags: int = surface_flags
|
25
|
+
self.blit_flags: int = 0
|
26
|
+
self.surface: pygame.Surface = pygame.Surface(self.rect.size, surface_flags)
|
27
|
+
if convert_alpha:
|
24
28
|
self.surface = self.surface.convert_alpha()
|
25
|
-
self.surface.fill((0,0,0,0))
|
26
|
-
|
27
|
-
self.uid: Any = Entity.instance_num
|
28
|
-
self.tags: list[str] = []
|
29
|
-
self.parent_scene: bf.Scene | None = None
|
30
|
-
self.rect = pygame.FRect(0, 0, *size)
|
31
|
-
|
32
|
-
self.visible = True
|
33
|
-
self._debug_color : tuple = bf.color.DARK_RED
|
34
|
-
self.render_order = 0
|
35
|
-
self.z_depth = 1
|
36
|
-
Entity.instance_num += 1
|
37
|
-
|
38
|
-
def get_bounding_box(self):
|
39
|
-
yield (self.rect,self._debug_color)
|
29
|
+
self.surface.fill((0, 0, 0, 0))
|
40
30
|
|
41
|
-
def
|
42
|
-
self.
|
43
|
-
|
44
|
-
def set_visible(self, value: bool):
|
45
|
-
self.visible = value
|
46
|
-
|
47
|
-
def set_parent_scene(self, scene):
|
48
|
-
self.parent_scene = scene
|
49
|
-
|
50
|
-
def do_when_added(self):
|
51
|
-
pass
|
31
|
+
def set_alpha(self, alpha: int) -> Self:
|
32
|
+
self.surface.set_alpha(min(max(0, alpha), 255))
|
33
|
+
return self
|
52
34
|
|
53
|
-
def
|
54
|
-
|
35
|
+
def get_alpha(self) -> int:
|
36
|
+
return self.surface.get_alpha()
|
55
37
|
|
56
|
-
def
|
57
|
-
self.
|
38
|
+
def set_surface_flags(self, surface_flags: int) -> Self:
|
39
|
+
self.surface_flags = surface_flags
|
58
40
|
return self
|
59
41
|
|
60
|
-
def
|
61
|
-
self.
|
42
|
+
def set_convert_alpha(self, value: bool) -> Self:
|
43
|
+
self.convert_alpha = value
|
62
44
|
return self
|
63
45
|
|
64
|
-
def
|
65
|
-
self.
|
46
|
+
def set_blit_flags(self, blit_flags: int) -> Self:
|
47
|
+
self.blit_flags = blit_flags
|
66
48
|
return self
|
67
49
|
|
68
|
-
def
|
69
|
-
self.
|
70
|
-
|
50
|
+
def get_debug_outlines(self):
|
51
|
+
if self.visible:
|
52
|
+
yield (self.rect, self.debug_color)
|
71
53
|
|
72
|
-
def
|
73
|
-
self.
|
54
|
+
def set_render_order(self, render_order: int) -> Self:
|
55
|
+
self.render_order = render_order
|
56
|
+
if self.parent_scene:
|
57
|
+
self.parent_scene.sort_entities()
|
74
58
|
return self
|
75
59
|
|
76
|
-
def
|
77
|
-
|
78
|
-
if tag not in self.tags:
|
79
|
-
self.tags.append(tag)
|
80
|
-
self.tags.sort()
|
60
|
+
def set_visible(self, value: bool) -> Self:
|
61
|
+
self.visible = value
|
81
62
|
return self
|
82
63
|
|
83
|
-
def
|
84
|
-
self.tags = [tag for tag in self.tags if tag not in tags]
|
85
|
-
self.tags.sort()
|
86
|
-
|
87
|
-
def has_tag(self, tag) -> bool:
|
88
|
-
return tag in self.tags
|
89
|
-
|
90
|
-
def process_event(self, event: pygame.Event)->bool:
|
64
|
+
def draw(self, camera: bf.Camera) -> None:
|
91
65
|
"""
|
92
|
-
|
66
|
+
Draw the entity onto the camera surface
|
93
67
|
"""
|
94
|
-
self.
|
95
|
-
|
96
|
-
self.do_reset_actions()
|
97
|
-
return res
|
98
|
-
|
99
|
-
def do_process_actions(self,event : pygame.Event)->None:
|
100
|
-
pass
|
101
|
-
|
102
|
-
def do_reset_actions(self)->None:
|
103
|
-
pass
|
104
|
-
|
105
|
-
def do_handle_event(self, event: pygame.Event) -> bool:
|
106
|
-
return False
|
107
|
-
|
108
|
-
def update(self, dt: float):
|
109
|
-
self.do_update(dt)
|
110
|
-
|
111
|
-
def do_update(self,dt:float):
|
112
|
-
pass
|
113
|
-
|
114
|
-
def draw(self, camera: bf.Camera) -> int:
|
115
|
-
if not self.visible:
|
116
|
-
return False
|
117
|
-
if not self.surface or not camera.intersects(self.rect):
|
118
|
-
return False
|
68
|
+
if not self.visible or not camera.rect.colliderect(self.rect):
|
69
|
+
return
|
119
70
|
camera.surface.blit(
|
120
71
|
self.surface,
|
121
|
-
|
72
|
+
camera.world_to_screen(self.rect),
|
73
|
+
special_flags=self.blit_flags,
|
122
74
|
)
|
123
|
-
return True
|
batFramework/enums.py
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
from enum import Enum
|
2
|
+
|
3
|
+
|
4
|
+
class color:
|
5
|
+
WHITE = (255, 255, 255)
|
6
|
+
LIGHTER_GRAY = (236, 240, 241)
|
7
|
+
LIGHT_GRAY = (189, 195, 199)
|
8
|
+
DARK_GRAY = (66, 66, 66)
|
9
|
+
DARKER_GRAY = (23, 23, 23)
|
10
|
+
BLACK = (0, 0, 0)
|
11
|
+
|
12
|
+
TURQUOISE = (26, 188, 156)
|
13
|
+
TURQUOISE_SHADE = (22, 160, 133)
|
14
|
+
|
15
|
+
GREEN = (46, 204, 113)
|
16
|
+
GREEN_SHADE = (39, 174, 96)
|
17
|
+
|
18
|
+
BLUE = (52, 152, 219)
|
19
|
+
BLUE_SHADE = (41, 128, 185)
|
20
|
+
|
21
|
+
PURPLE = (155, 89, 182)
|
22
|
+
PURPLE_SHADE = (142, 68, 173)
|
23
|
+
|
24
|
+
CHARCOAL = (52, 73, 94)
|
25
|
+
CHARCOAL_SHADE = (44, 62, 80)
|
26
|
+
|
27
|
+
GOLD = (241, 196, 15)
|
28
|
+
GOLD_SHADE = (243, 156, 18)
|
29
|
+
|
30
|
+
ORANGE = (230, 126, 34)
|
31
|
+
ORANGE_SHADE = (211, 84, 0)
|
32
|
+
|
33
|
+
RED = (231, 76, 60)
|
34
|
+
RED_SHADE = (192, 57, 43)
|
35
|
+
|
36
|
+
CLOUD = (236, 240, 241)
|
37
|
+
CLOUD_SHADE = (189, 195, 199)
|
38
|
+
|
39
|
+
CONCRETE = (149, 165, 166)
|
40
|
+
CONCRETE_SHADE = (127, 140, 141)
|
41
|
+
|
42
|
+
# GB
|
43
|
+
DARKER_GB = (27, 42, 9)
|
44
|
+
DARK_GB = (14, 69, 11)
|
45
|
+
LIGHT_GB = (73, 107, 34)
|
46
|
+
LIGHTER_GB = (154, 158, 63)
|
47
|
+
|
48
|
+
|
49
|
+
class easing(Enum):
|
50
|
+
LINEAR = (0, 0, 1, 1)
|
51
|
+
EASE_IN = (0.95, 0, 1, 0.55)
|
52
|
+
EASE_OUT = (0.5, 1, 0.5, 1)
|
53
|
+
EASE_IN_OUT = (0.55, 0, 0.45, 1)
|
54
|
+
EASE_IN_OUT_ELASTIC = (0.39, -0.55, 0.3, 1.3)
|
55
|
+
|
56
|
+
def __init__(self, *control_points):
|
57
|
+
self.control_points = control_points
|
58
|
+
|
59
|
+
|
60
|
+
class axis(Enum):
|
61
|
+
HORIZONTAL = "horizontal"
|
62
|
+
VERTICAL = "vertical"
|
63
|
+
|
64
|
+
|
65
|
+
class spacing(Enum):
|
66
|
+
MIN = "min"
|
67
|
+
HALF = "half"
|
68
|
+
MAX = "max"
|
69
|
+
MANUAL = "manual"
|
70
|
+
|
71
|
+
|
72
|
+
class alignment(Enum):
|
73
|
+
LEFT = "left"
|
74
|
+
RIGHT = "right"
|
75
|
+
CENTER = "center"
|
76
|
+
TOP = "top"
|
77
|
+
BOTTOM = "bottom"
|
78
|
+
TOPLEFT = "topleft"
|
79
|
+
TOPRIGHT = "topright"
|
80
|
+
MIDLEFT = "midleft"
|
81
|
+
MIDRIGHT = "midright"
|
82
|
+
BOTTOMLEFT = "bottomleft"
|
83
|
+
BOTTOMRIGHT = "bottomright"
|
84
|
+
|
85
|
+
|
86
|
+
class direction(Enum):
|
87
|
+
LEFT = 0
|
88
|
+
UP = 1
|
89
|
+
RIGHT = 2
|
90
|
+
DOWN = 3
|
91
|
+
|
92
|
+
|
93
|
+
class drawMode(Enum):
|
94
|
+
SOLID = 0
|
95
|
+
TEXTURED = 1
|
96
|
+
|
97
|
+
|
98
|
+
class debugMode(Enum):
|
99
|
+
HIDDEN = 0
|
100
|
+
DEBUGGER = 1
|
101
|
+
OUTLINES = 2
|
102
|
+
|
103
|
+
|
104
|
+
class actionType(Enum):
|
105
|
+
INSTANTANEOUS = 0
|
106
|
+
CONTINUOUS = 1
|
107
|
+
HOLDING = 2
|
108
|
+
|
109
|
+
|
110
|
+
class textMode(Enum):
|
111
|
+
ALPHABETICAL = 0
|
112
|
+
NUMERICAL = 1
|
113
|
+
ALPHANUMERIC = 3
|
@@ -0,0 +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_TEXT_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_antialias(self, value: bool):
|
19
|
+
self.DEFAULT_ANTIALIAS = value
|
20
|
+
|
21
|
+
def set_default_text_size(self, size: int):
|
22
|
+
self.DEFAULT_TEXT_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, 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, 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,14 +1,22 @@
|
|
1
1
|
from .constraints import *
|
2
2
|
from .widget import Widget
|
3
|
+
from .styleManager import StyleManager
|
4
|
+
from .style import Style
|
3
5
|
from .image import Image
|
4
6
|
from .interactiveWidget import InteractiveWidget
|
7
|
+
from .draggableWidget import DraggableWidget
|
8
|
+
from .clickableWidget import ClickableWidget
|
5
9
|
from .root import Root
|
6
10
|
from .shape import Shape
|
7
|
-
from .
|
11
|
+
from .meter import Meter
|
8
12
|
from .label import Label
|
13
|
+
from .dialogueBox import DialogueBox
|
14
|
+
from .textInput import TextInput
|
9
15
|
from .button import Button
|
10
|
-
from .debugger import
|
16
|
+
from .debugger import *
|
11
17
|
from .layout import *
|
12
18
|
from .container import Container
|
13
19
|
from .indicator import *
|
14
20
|
from .toggle import Toggle
|
21
|
+
from .radioButton import RadioButton, RadioVariable
|
22
|
+
from .slider import Slider
|