mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-02-06 15:47:06 +08:00
Cleaned up Image actor
This commit is contained in:
parent
053247f004
commit
23436c73ce
@ -384,19 +384,19 @@ class Achievement:
|
|||||||
in_main_menu = False
|
in_main_menu = False
|
||||||
h_attach = Text.HAttach.CENTER
|
h_attach = Text.HAttach.CENTER
|
||||||
v_attach = Text.VAttach.CENTER
|
v_attach = Text.VAttach.CENTER
|
||||||
attach = 'center'
|
attach = Image.Attach.CENTER
|
||||||
elif style == 'in_game':
|
elif style == 'in_game':
|
||||||
in_game_colors = True
|
in_game_colors = True
|
||||||
in_main_menu = False
|
in_main_menu = False
|
||||||
h_attach = Text.HAttach.LEFT
|
h_attach = Text.HAttach.LEFT
|
||||||
v_attach = Text.VAttach.TOP
|
v_attach = Text.VAttach.TOP
|
||||||
attach = 'topLeft'
|
attach = Image.Attach.TOP_LEFT
|
||||||
elif style == 'news':
|
elif style == 'news':
|
||||||
in_game_colors = True
|
in_game_colors = True
|
||||||
in_main_menu = True
|
in_main_menu = True
|
||||||
h_attach = Text.HAttach.CENTER
|
h_attach = Text.HAttach.CENTER
|
||||||
v_attach = Text.VAttach.TOP
|
v_attach = Text.VAttach.TOP
|
||||||
attach = 'topCenter'
|
attach = Image.Attach.TOP_CENTER
|
||||||
else:
|
else:
|
||||||
raise Exception('invalid style "' + style + '"')
|
raise Exception('invalid style "' + style + '"')
|
||||||
|
|
||||||
@ -438,7 +438,7 @@ class Achievement:
|
|||||||
color=cl1,
|
color=cl1,
|
||||||
position=(x - 25, y + 5),
|
position=(x - 25, y + 5),
|
||||||
attach=attach,
|
attach=attach,
|
||||||
transition='fade_in',
|
transition=Image.Transition.FADE_IN,
|
||||||
transition_delay=delay,
|
transition_delay=delay,
|
||||||
vr_depth=4,
|
vr_depth=4,
|
||||||
transition_out_delay=out_delay_fin,
|
transition_out_delay=out_delay_fin,
|
||||||
@ -543,7 +543,7 @@ class Achievement:
|
|||||||
position=(x - 25, y + 5),
|
position=(x - 25, y + 5),
|
||||||
attach=attach,
|
attach=attach,
|
||||||
vr_depth=4,
|
vr_depth=4,
|
||||||
transition='in_right',
|
transition=Image.Transition.IN_RIGHT,
|
||||||
transition_delay=delay,
|
transition_delay=delay,
|
||||||
transition_out_delay=None,
|
transition_out_delay=None,
|
||||||
scale=(40, 40)).autoretain())
|
scale=(40, 40)).autoretain())
|
||||||
@ -556,7 +556,7 @@ class Achievement:
|
|||||||
vr_depth=8,
|
vr_depth=8,
|
||||||
position=(x - 25, y + 5),
|
position=(x - 25, y + 5),
|
||||||
attach=attach,
|
attach=attach,
|
||||||
transition='in_right',
|
transition=Image.Transition.IN_RIGHT,
|
||||||
transition_delay=delay,
|
transition_delay=delay,
|
||||||
transition_out_delay=None,
|
transition_out_delay=None,
|
||||||
scale=(40, 40)).autoretain())
|
scale=(40, 40)).autoretain())
|
||||||
@ -726,8 +726,8 @@ class Achievement:
|
|||||||
obj = Image(_ba.gettexture('shadow'),
|
obj = Image(_ba.gettexture('shadow'),
|
||||||
position=(-30, 30 + y_offs),
|
position=(-30, 30 + y_offs),
|
||||||
front=True,
|
front=True,
|
||||||
attach='bottomCenter',
|
attach=Image.Attach.BOTTOM_CENTER,
|
||||||
transition='in_bottom',
|
transition=Image.Transition.IN_BOTTOM,
|
||||||
vr_depth=base_vr_depth - 100,
|
vr_depth=base_vr_depth - 100,
|
||||||
transition_delay=in_time,
|
transition_delay=in_time,
|
||||||
transition_out_delay=out_time,
|
transition_out_delay=out_time,
|
||||||
@ -739,9 +739,9 @@ class Achievement:
|
|||||||
obj = Image(_ba.gettexture('light'),
|
obj = Image(_ba.gettexture('light'),
|
||||||
position=(-180, 60 + y_offs),
|
position=(-180, 60 + y_offs),
|
||||||
front=True,
|
front=True,
|
||||||
attach='bottomCenter',
|
attach=Image.Attach.BOTTOM_CENTER,
|
||||||
vr_depth=base_vr_depth,
|
vr_depth=base_vr_depth,
|
||||||
transition='in_bottom',
|
transition=Image.Transition.IN_BOTTOM,
|
||||||
transition_delay=in_time,
|
transition_delay=in_time,
|
||||||
transition_out_delay=out_time,
|
transition_out_delay=out_time,
|
||||||
color=(1.8, 1.8, 1.0, 0.0),
|
color=(1.8, 1.8, 1.0, 0.0),
|
||||||
@ -776,10 +776,10 @@ class Achievement:
|
|||||||
loop=True)
|
loop=True)
|
||||||
obj = Image(self.get_icon_texture(True),
|
obj = Image(self.get_icon_texture(True),
|
||||||
position=(-180, 60 + y_offs),
|
position=(-180, 60 + y_offs),
|
||||||
attach='bottomCenter',
|
attach=Image.Attach.BOTTOM_CENTER,
|
||||||
front=True,
|
front=True,
|
||||||
vr_depth=base_vr_depth - 10,
|
vr_depth=base_vr_depth - 10,
|
||||||
transition='in_bottom',
|
transition=Image.Transition.IN_BOTTOM,
|
||||||
transition_delay=in_time,
|
transition_delay=in_time,
|
||||||
transition_out_delay=out_time,
|
transition_out_delay=out_time,
|
||||||
scale=(100, 100)).autoretain()
|
scale=(100, 100)).autoretain()
|
||||||
@ -820,9 +820,9 @@ class Achievement:
|
|||||||
model_transparent=_ba.getmodel('achievementOutline'),
|
model_transparent=_ba.getmodel('achievementOutline'),
|
||||||
position=(-180, 60 + y_offs),
|
position=(-180, 60 + y_offs),
|
||||||
front=True,
|
front=True,
|
||||||
attach='bottomCenter',
|
attach=Image.Attach.BOTTOM_CENTER,
|
||||||
vr_depth=base_vr_depth,
|
vr_depth=base_vr_depth,
|
||||||
transition='in_bottom',
|
transition=Image.Transition.IN_BOTTOM,
|
||||||
transition_delay=in_time,
|
transition_delay=in_time,
|
||||||
transition_out_delay=out_time,
|
transition_out_delay=out_time,
|
||||||
scale=(100, 100)).autoretain()
|
scale=(100, 100)).autoretain()
|
||||||
|
|||||||
@ -36,7 +36,8 @@ class FreeForAllVictoryScoreScreenActivity(TeamsScoreScreenActivity):
|
|||||||
|
|
||||||
def __init__(self, settings: Dict[str, Any]):
|
def __init__(self, settings: Dict[str, Any]):
|
||||||
super().__init__(settings=settings)
|
super().__init__(settings=settings)
|
||||||
# keeps prev activity alive while we fade in
|
|
||||||
|
# Keep prev activity alive while we fade in.
|
||||||
self.transition_time = 0.5
|
self.transition_time = 0.5
|
||||||
self._cymbal_sound = ba.getsound('cymbal')
|
self._cymbal_sound = ba.getsound('cymbal')
|
||||||
|
|
||||||
@ -44,7 +45,7 @@ class FreeForAllVictoryScoreScreenActivity(TeamsScoreScreenActivity):
|
|||||||
# pylint: disable=too-many-locals
|
# pylint: disable=too-many-locals
|
||||||
# pylint: disable=too-many-statements
|
# pylint: disable=too-many-statements
|
||||||
from bastd.actor.text import Text
|
from bastd.actor.text import Text
|
||||||
from bastd.actor import image
|
from bastd.actor.image import Image
|
||||||
ba.set_analytics_screen('FreeForAll Score Screen')
|
ba.set_analytics_screen('FreeForAll Score Screen')
|
||||||
super().on_begin()
|
super().on_begin()
|
||||||
|
|
||||||
@ -54,8 +55,8 @@ class FreeForAllVictoryScoreScreenActivity(TeamsScoreScreenActivity):
|
|||||||
scale = 1.2
|
scale = 1.2
|
||||||
spacing = 37.0
|
spacing = 37.0
|
||||||
|
|
||||||
# we include name and previous score in the sort to reduce the amount
|
# We include name and previous score in the sort to reduce the amount
|
||||||
# of random jumping around the list we do in cases of ties
|
# of random jumping around the list we do in cases of ties.
|
||||||
player_order_prev = list(self.players)
|
player_order_prev = list(self.players)
|
||||||
player_order_prev.sort(
|
player_order_prev.sort(
|
||||||
reverse=True,
|
reverse=True,
|
||||||
@ -138,12 +139,12 @@ class FreeForAllVictoryScoreScreenActivity(TeamsScoreScreenActivity):
|
|||||||
if order_change:
|
if order_change:
|
||||||
ba.timer(tdelay + delay2 + 0.1,
|
ba.timer(tdelay + delay2 + 0.1,
|
||||||
ba.Call(ba.playsound, self._cymbal_sound))
|
ba.Call(ba.playsound, self._cymbal_sound))
|
||||||
img = image.Image(player.get_icon(),
|
img = Image(player.get_icon(),
|
||||||
position=(ts_h_offs - 72.0 * scale,
|
position=(ts_h_offs - 72.0 * scale,
|
||||||
y_base + (v_offs + 15.0) * scale),
|
y_base + (v_offs + 15.0) * scale),
|
||||||
scale=(30.0 * scale, 30.0 * scale),
|
scale=(30.0 * scale, 30.0 * scale),
|
||||||
transition='in_left',
|
transition=Image.Transition.IN_LEFT,
|
||||||
transition_delay=tdelay).autoretain()
|
transition_delay=tdelay).autoretain()
|
||||||
ba.timer(
|
ba.timer(
|
||||||
tdelay + delay2,
|
tdelay + delay2,
|
||||||
ba.WeakCall(
|
ba.WeakCall(
|
||||||
|
|||||||
@ -190,7 +190,7 @@ class TeamSeriesVictoryScoreScreenActivity(TeamsScoreScreenActivity):
|
|||||||
Image(mvp.get_icon(),
|
Image(mvp.get_icon(),
|
||||||
position=(230, ts_height / 2 - 55 + 14 - 5),
|
position=(230, ts_height / 2 - 55 + 14 - 5),
|
||||||
scale=(70, 70),
|
scale=(70, 70),
|
||||||
transition='in_left',
|
transition=Image.Transition.IN_LEFT,
|
||||||
transition_delay=tval).autoretain()
|
transition_delay=tval).autoretain()
|
||||||
Text(ba.Lstr(value=mvp_name),
|
Text(ba.Lstr(value=mvp_name),
|
||||||
position=(280, ts_height / 2 - 55 + 15 - 5),
|
position=(280, ts_height / 2 - 55 + 15 - 5),
|
||||||
@ -235,7 +235,7 @@ class TeamSeriesVictoryScoreScreenActivity(TeamsScoreScreenActivity):
|
|||||||
Image(mvp.get_icon(),
|
Image(mvp.get_icon(),
|
||||||
position=(233, ts_height / 2 - 150 - 30 - 46 + 25 + v_extra),
|
position=(233, ts_height / 2 - 150 - 30 - 46 + 25 + v_extra),
|
||||||
scale=(50, 50),
|
scale=(50, 50),
|
||||||
transition='in_left',
|
transition=Image.Transition.IN_LEFT,
|
||||||
transition_delay=tval).autoretain()
|
transition_delay=tval).autoretain()
|
||||||
Text(ba.Lstr(value=mvp_name),
|
Text(ba.Lstr(value=mvp_name),
|
||||||
position=(270, ts_height / 2 - 150 - 30 - 36 + v_extra + 15),
|
position=(270, ts_height / 2 - 150 - 30 - 36 + v_extra + 15),
|
||||||
@ -279,7 +279,7 @@ class TeamSeriesVictoryScoreScreenActivity(TeamsScoreScreenActivity):
|
|||||||
Image(mkp.get_icon(),
|
Image(mkp.get_icon(),
|
||||||
position=(233, ts_height / 2 - 300 - 30 - 46 + 25 + v_extra),
|
position=(233, ts_height / 2 - 300 - 30 - 46 + 25 + v_extra),
|
||||||
scale=(50, 50),
|
scale=(50, 50),
|
||||||
transition='in_left',
|
transition=Image.Transition.IN_LEFT,
|
||||||
transition_delay=tval).autoretain()
|
transition_delay=tval).autoretain()
|
||||||
Text(ba.Lstr(value=mkp_name),
|
Text(ba.Lstr(value=mkp_name),
|
||||||
position=(270, ts_height / 2 - 300 - 30 - 36 + v_extra + 15),
|
position=(270, ts_height / 2 - 300 - 30 - 36 + v_extra + 15),
|
||||||
@ -317,7 +317,7 @@ class TeamSeriesVictoryScoreScreenActivity(TeamsScoreScreenActivity):
|
|||||||
Image(prec.get_icon(),
|
Image(prec.get_icon(),
|
||||||
position=(ts_h_offs - 72, ts_height / 2 + v_offs + 15),
|
position=(ts_h_offs - 72, ts_height / 2 + v_offs + 15),
|
||||||
scale=(30, 30),
|
scale=(30, 30),
|
||||||
transition='in_left',
|
transition=Image.Transition.IN_LEFT,
|
||||||
transition_delay=tdelay).autoretain()
|
transition_delay=tdelay).autoretain()
|
||||||
Text(ba.Lstr(value=name),
|
Text(ba.Lstr(value=name),
|
||||||
position=(ts_h_offs - 50, ts_height / 2 + v_offs + 15),
|
position=(ts_h_offs - 50, ts_height / 2 + v_offs + 15),
|
||||||
|
|||||||
@ -216,7 +216,7 @@ class TeamsScoreScreenActivity(ScoreScreenActivity):
|
|||||||
position=(ts_h_offs - 12 * scale,
|
position=(ts_h_offs - 12 * scale,
|
||||||
ts_v_offset + (v_offs + 15.0) * scale),
|
ts_v_offset + (v_offs + 15.0) * scale),
|
||||||
scale=(30.0 * scale, 30.0 * scale),
|
scale=(30.0 * scale, 30.0 * scale),
|
||||||
transition='in_left',
|
transition=Image.Transition.IN_LEFT,
|
||||||
transition_delay=tdelay).autoretain()
|
transition_delay=tdelay).autoretain()
|
||||||
Text(ba.Lstr(value=playerrec.get_name(full=True)),
|
Text(ba.Lstr(value=playerrec.get_name(full=True)),
|
||||||
maxwidth=160,
|
maxwidth=160,
|
||||||
|
|||||||
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from enum import Enum
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
import ba
|
import ba
|
||||||
@ -33,12 +34,28 @@ if TYPE_CHECKING:
|
|||||||
class Image(ba.Actor):
|
class Image(ba.Actor):
|
||||||
"""Just a wrapped up image node with a few tricks up its sleeve."""
|
"""Just a wrapped up image node with a few tricks up its sleeve."""
|
||||||
|
|
||||||
|
class Transition(Enum):
|
||||||
|
"""Transition types we support."""
|
||||||
|
FADE_IN = 'fade_in'
|
||||||
|
IN_RIGHT = 'in_right'
|
||||||
|
IN_LEFT = 'in_left'
|
||||||
|
IN_BOTTOM = 'in_bottom'
|
||||||
|
IN_BOTTOM_SLOW = 'in_bottom_slow'
|
||||||
|
IN_TOP_SLOW = 'in_top_slow'
|
||||||
|
|
||||||
|
class Attach(Enum):
|
||||||
|
"""Attach types we support."""
|
||||||
|
CENTER = 'center'
|
||||||
|
TOP_CENTER = 'topCenter'
|
||||||
|
TOP_LEFT = 'topLeft'
|
||||||
|
BOTTOM_CENTER = 'bottomCenter'
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
texture: Union[ba.Texture, Dict[str, Any]],
|
texture: Union[ba.Texture, Dict[str, Any]],
|
||||||
position: Tuple[float, float] = (0, 0),
|
position: Tuple[float, float] = (0, 0),
|
||||||
transition: str = None,
|
transition: Optional[Transition] = None,
|
||||||
transition_delay: float = 0.0,
|
transition_delay: float = 0.0,
|
||||||
attach: str = 'center',
|
attach: Attach = Attach.CENTER,
|
||||||
color: Sequence[float] = (1.0, 1.0, 1.0, 1.0),
|
color: Sequence[float] = (1.0, 1.0, 1.0, 1.0),
|
||||||
scale: Tuple[float, float] = (100.0, 100.0),
|
scale: Tuple[float, float] = (100.0, 100.0),
|
||||||
transition_out_delay: float = None,
|
transition_out_delay: float = None,
|
||||||
@ -80,7 +97,7 @@ class Image(ba.Actor):
|
|||||||
'absolute_scale': True,
|
'absolute_scale': True,
|
||||||
'host_only': host_only,
|
'host_only': host_only,
|
||||||
'front': front,
|
'front': front,
|
||||||
'attach': attach
|
'attach': attach.value
|
||||||
},
|
},
|
||||||
delegate=self)
|
delegate=self)
|
||||||
|
|
||||||
@ -90,7 +107,7 @@ class Image(ba.Actor):
|
|||||||
self.node.model_transparent = model_transparent
|
self.node.model_transparent = model_transparent
|
||||||
if tint2_color is not None:
|
if tint2_color is not None:
|
||||||
self.node.tint2_color = tint2_color
|
self.node.tint2_color = tint2_color
|
||||||
if transition == 'fade_in':
|
if transition is self.Transition.FADE_IN:
|
||||||
keys = {transition_delay: 0, transition_delay + 0.5: color[3]}
|
keys = {transition_delay: 0, transition_delay + 0.5: color[3]}
|
||||||
if transition_out_delay is not None:
|
if transition_out_delay is not None:
|
||||||
keys[transition_delay + transition_out_delay] = color[3]
|
keys[transition_delay + transition_out_delay] = color[3]
|
||||||
@ -99,7 +116,7 @@ class Image(ba.Actor):
|
|||||||
cmb = self.position_combine = ba.newnode('combine',
|
cmb = self.position_combine = ba.newnode('combine',
|
||||||
owner=self.node,
|
owner=self.node,
|
||||||
attrs={'size': 2})
|
attrs={'size': 2})
|
||||||
if transition == 'in_right':
|
if transition is self.Transition.IN_RIGHT:
|
||||||
keys = {
|
keys = {
|
||||||
transition_delay: position[0] + 1200,
|
transition_delay: position[0] + 1200,
|
||||||
transition_delay + 0.2: position[0]
|
transition_delay + 0.2: position[0]
|
||||||
@ -108,7 +125,7 @@ class Image(ba.Actor):
|
|||||||
ba.animate(cmb, 'input0', keys)
|
ba.animate(cmb, 'input0', keys)
|
||||||
cmb.input1 = position[1]
|
cmb.input1 = position[1]
|
||||||
ba.animate(self.node, 'opacity', o_keys)
|
ba.animate(self.node, 'opacity', o_keys)
|
||||||
elif transition == 'in_left':
|
elif transition is self.Transition.IN_LEFT:
|
||||||
keys = {
|
keys = {
|
||||||
transition_delay: position[0] - 1200,
|
transition_delay: position[0] - 1200,
|
||||||
transition_delay + 0.2: position[0]
|
transition_delay + 0.2: position[0]
|
||||||
@ -123,7 +140,7 @@ class Image(ba.Actor):
|
|||||||
ba.animate(cmb, 'input0', keys)
|
ba.animate(cmb, 'input0', keys)
|
||||||
cmb.input1 = position[1]
|
cmb.input1 = position[1]
|
||||||
ba.animate(self.node, 'opacity', o_keys)
|
ba.animate(self.node, 'opacity', o_keys)
|
||||||
elif transition == 'in_bottom_slow':
|
elif transition is self.Transition.IN_BOTTOM_SLOW:
|
||||||
keys = {
|
keys = {
|
||||||
transition_delay: -400,
|
transition_delay: -400,
|
||||||
transition_delay + 3.5: position[1]
|
transition_delay + 3.5: position[1]
|
||||||
@ -132,7 +149,7 @@ class Image(ba.Actor):
|
|||||||
cmb.input0 = position[0]
|
cmb.input0 = position[0]
|
||||||
ba.animate(cmb, 'input1', keys)
|
ba.animate(cmb, 'input1', keys)
|
||||||
ba.animate(self.node, 'opacity', o_keys)
|
ba.animate(self.node, 'opacity', o_keys)
|
||||||
elif transition == 'in_bottom':
|
elif transition is self.Transition.IN_BOTTOM:
|
||||||
keys = {
|
keys = {
|
||||||
transition_delay: -400,
|
transition_delay: -400,
|
||||||
transition_delay + 0.2: position[1]
|
transition_delay + 0.2: position[1]
|
||||||
@ -146,13 +163,16 @@ class Image(ba.Actor):
|
|||||||
cmb.input0 = position[0]
|
cmb.input0 = position[0]
|
||||||
ba.animate(cmb, 'input1', keys)
|
ba.animate(cmb, 'input1', keys)
|
||||||
ba.animate(self.node, 'opacity', o_keys)
|
ba.animate(self.node, 'opacity', o_keys)
|
||||||
elif transition == 'in_top_slow':
|
elif transition is self.Transition.IN_TOP_SLOW:
|
||||||
keys = {transition_delay: 400, transition_delay + 3.5: position[1]}
|
keys = {transition_delay: 400, transition_delay + 3.5: position[1]}
|
||||||
o_keys = {transition_delay: 0.0, transition_delay + 1.0: 1.0}
|
o_keys = {transition_delay: 0.0, transition_delay + 1.0: 1.0}
|
||||||
cmb.input0 = position[0]
|
cmb.input0 = position[0]
|
||||||
ba.animate(cmb, 'input1', keys)
|
ba.animate(cmb, 'input1', keys)
|
||||||
ba.animate(self.node, 'opacity', o_keys)
|
ba.animate(self.node, 'opacity', o_keys)
|
||||||
else:
|
else:
|
||||||
|
if (transition is not self.Transition.FADE_IN
|
||||||
|
and transition is not None):
|
||||||
|
ba.print_error(f'Invalid transition: "{transition}"')
|
||||||
cmb.input0 = position[0]
|
cmb.input0 = position[0]
|
||||||
cmb.input1 = position[1]
|
cmb.input1 = position[1]
|
||||||
cmb.connectattr('output', self.node, 'position')
|
cmb.connectattr('output', self.node, 'position')
|
||||||
|
|||||||
@ -21,8 +21,8 @@
|
|||||||
"""Defines Actor(s)."""
|
"""Defines Actor(s)."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
from enum import Enum
|
|
||||||
|
|
||||||
|
from enum import Enum
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
import ba
|
import ba
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user