Cleaned up Image actor

This commit is contained in:
Eric Froemling 2020-04-08 22:23:09 -07:00
parent 053247f004
commit 23436c73ce
6 changed files with 60 additions and 39 deletions

View File

@ -384,19 +384,19 @@ class Achievement:
in_main_menu = False
h_attach = Text.HAttach.CENTER
v_attach = Text.VAttach.CENTER
attach = 'center'
attach = Image.Attach.CENTER
elif style == 'in_game':
in_game_colors = True
in_main_menu = False
h_attach = Text.HAttach.LEFT
v_attach = Text.VAttach.TOP
attach = 'topLeft'
attach = Image.Attach.TOP_LEFT
elif style == 'news':
in_game_colors = True
in_main_menu = True
h_attach = Text.HAttach.CENTER
v_attach = Text.VAttach.TOP
attach = 'topCenter'
attach = Image.Attach.TOP_CENTER
else:
raise Exception('invalid style "' + style + '"')
@ -438,7 +438,7 @@ class Achievement:
color=cl1,
position=(x - 25, y + 5),
attach=attach,
transition='fade_in',
transition=Image.Transition.FADE_IN,
transition_delay=delay,
vr_depth=4,
transition_out_delay=out_delay_fin,
@ -543,7 +543,7 @@ class Achievement:
position=(x - 25, y + 5),
attach=attach,
vr_depth=4,
transition='in_right',
transition=Image.Transition.IN_RIGHT,
transition_delay=delay,
transition_out_delay=None,
scale=(40, 40)).autoretain())
@ -556,7 +556,7 @@ class Achievement:
vr_depth=8,
position=(x - 25, y + 5),
attach=attach,
transition='in_right',
transition=Image.Transition.IN_RIGHT,
transition_delay=delay,
transition_out_delay=None,
scale=(40, 40)).autoretain())
@ -726,8 +726,8 @@ class Achievement:
obj = Image(_ba.gettexture('shadow'),
position=(-30, 30 + y_offs),
front=True,
attach='bottomCenter',
transition='in_bottom',
attach=Image.Attach.BOTTOM_CENTER,
transition=Image.Transition.IN_BOTTOM,
vr_depth=base_vr_depth - 100,
transition_delay=in_time,
transition_out_delay=out_time,
@ -739,9 +739,9 @@ class Achievement:
obj = Image(_ba.gettexture('light'),
position=(-180, 60 + y_offs),
front=True,
attach='bottomCenter',
attach=Image.Attach.BOTTOM_CENTER,
vr_depth=base_vr_depth,
transition='in_bottom',
transition=Image.Transition.IN_BOTTOM,
transition_delay=in_time,
transition_out_delay=out_time,
color=(1.8, 1.8, 1.0, 0.0),
@ -776,10 +776,10 @@ class Achievement:
loop=True)
obj = Image(self.get_icon_texture(True),
position=(-180, 60 + y_offs),
attach='bottomCenter',
attach=Image.Attach.BOTTOM_CENTER,
front=True,
vr_depth=base_vr_depth - 10,
transition='in_bottom',
transition=Image.Transition.IN_BOTTOM,
transition_delay=in_time,
transition_out_delay=out_time,
scale=(100, 100)).autoretain()
@ -820,9 +820,9 @@ class Achievement:
model_transparent=_ba.getmodel('achievementOutline'),
position=(-180, 60 + y_offs),
front=True,
attach='bottomCenter',
attach=Image.Attach.BOTTOM_CENTER,
vr_depth=base_vr_depth,
transition='in_bottom',
transition=Image.Transition.IN_BOTTOM,
transition_delay=in_time,
transition_out_delay=out_time,
scale=(100, 100)).autoretain()

View File

@ -36,7 +36,8 @@ class FreeForAllVictoryScoreScreenActivity(TeamsScoreScreenActivity):
def __init__(self, settings: Dict[str, Any]):
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._cymbal_sound = ba.getsound('cymbal')
@ -44,7 +45,7 @@ class FreeForAllVictoryScoreScreenActivity(TeamsScoreScreenActivity):
# pylint: disable=too-many-locals
# pylint: disable=too-many-statements
from bastd.actor.text import Text
from bastd.actor import image
from bastd.actor.image import Image
ba.set_analytics_screen('FreeForAll Score Screen')
super().on_begin()
@ -54,8 +55,8 @@ class FreeForAllVictoryScoreScreenActivity(TeamsScoreScreenActivity):
scale = 1.2
spacing = 37.0
# 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
# 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.
player_order_prev = list(self.players)
player_order_prev.sort(
reverse=True,
@ -138,12 +139,12 @@ class FreeForAllVictoryScoreScreenActivity(TeamsScoreScreenActivity):
if order_change:
ba.timer(tdelay + delay2 + 0.1,
ba.Call(ba.playsound, self._cymbal_sound))
img = image.Image(player.get_icon(),
position=(ts_h_offs - 72.0 * scale,
y_base + (v_offs + 15.0) * scale),
scale=(30.0 * scale, 30.0 * scale),
transition='in_left',
transition_delay=tdelay).autoretain()
img = Image(player.get_icon(),
position=(ts_h_offs - 72.0 * scale,
y_base + (v_offs + 15.0) * scale),
scale=(30.0 * scale, 30.0 * scale),
transition=Image.Transition.IN_LEFT,
transition_delay=tdelay).autoretain()
ba.timer(
tdelay + delay2,
ba.WeakCall(

View File

@ -190,7 +190,7 @@ class TeamSeriesVictoryScoreScreenActivity(TeamsScoreScreenActivity):
Image(mvp.get_icon(),
position=(230, ts_height / 2 - 55 + 14 - 5),
scale=(70, 70),
transition='in_left',
transition=Image.Transition.IN_LEFT,
transition_delay=tval).autoretain()
Text(ba.Lstr(value=mvp_name),
position=(280, ts_height / 2 - 55 + 15 - 5),
@ -235,7 +235,7 @@ class TeamSeriesVictoryScoreScreenActivity(TeamsScoreScreenActivity):
Image(mvp.get_icon(),
position=(233, ts_height / 2 - 150 - 30 - 46 + 25 + v_extra),
scale=(50, 50),
transition='in_left',
transition=Image.Transition.IN_LEFT,
transition_delay=tval).autoretain()
Text(ba.Lstr(value=mvp_name),
position=(270, ts_height / 2 - 150 - 30 - 36 + v_extra + 15),
@ -279,7 +279,7 @@ class TeamSeriesVictoryScoreScreenActivity(TeamsScoreScreenActivity):
Image(mkp.get_icon(),
position=(233, ts_height / 2 - 300 - 30 - 46 + 25 + v_extra),
scale=(50, 50),
transition='in_left',
transition=Image.Transition.IN_LEFT,
transition_delay=tval).autoretain()
Text(ba.Lstr(value=mkp_name),
position=(270, ts_height / 2 - 300 - 30 - 36 + v_extra + 15),
@ -317,7 +317,7 @@ class TeamSeriesVictoryScoreScreenActivity(TeamsScoreScreenActivity):
Image(prec.get_icon(),
position=(ts_h_offs - 72, ts_height / 2 + v_offs + 15),
scale=(30, 30),
transition='in_left',
transition=Image.Transition.IN_LEFT,
transition_delay=tdelay).autoretain()
Text(ba.Lstr(value=name),
position=(ts_h_offs - 50, ts_height / 2 + v_offs + 15),

View File

@ -216,7 +216,7 @@ class TeamsScoreScreenActivity(ScoreScreenActivity):
position=(ts_h_offs - 12 * scale,
ts_v_offset + (v_offs + 15.0) * scale),
scale=(30.0 * scale, 30.0 * scale),
transition='in_left',
transition=Image.Transition.IN_LEFT,
transition_delay=tdelay).autoretain()
Text(ba.Lstr(value=playerrec.get_name(full=True)),
maxwidth=160,

View File

@ -22,6 +22,7 @@
from __future__ import annotations
from enum import Enum
from typing import TYPE_CHECKING
import ba
@ -33,12 +34,28 @@ if TYPE_CHECKING:
class Image(ba.Actor):
"""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,
texture: Union[ba.Texture, Dict[str, Any]],
position: Tuple[float, float] = (0, 0),
transition: str = None,
transition: Optional[Transition] = None,
transition_delay: float = 0.0,
attach: str = 'center',
attach: Attach = Attach.CENTER,
color: Sequence[float] = (1.0, 1.0, 1.0, 1.0),
scale: Tuple[float, float] = (100.0, 100.0),
transition_out_delay: float = None,
@ -80,7 +97,7 @@ class Image(ba.Actor):
'absolute_scale': True,
'host_only': host_only,
'front': front,
'attach': attach
'attach': attach.value
},
delegate=self)
@ -90,7 +107,7 @@ class Image(ba.Actor):
self.node.model_transparent = model_transparent
if tint2_color is not None:
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]}
if transition_out_delay is not None:
keys[transition_delay + transition_out_delay] = color[3]
@ -99,7 +116,7 @@ class Image(ba.Actor):
cmb = self.position_combine = ba.newnode('combine',
owner=self.node,
attrs={'size': 2})
if transition == 'in_right':
if transition is self.Transition.IN_RIGHT:
keys = {
transition_delay: position[0] + 1200,
transition_delay + 0.2: position[0]
@ -108,7 +125,7 @@ class Image(ba.Actor):
ba.animate(cmb, 'input0', keys)
cmb.input1 = position[1]
ba.animate(self.node, 'opacity', o_keys)
elif transition == 'in_left':
elif transition is self.Transition.IN_LEFT:
keys = {
transition_delay: position[0] - 1200,
transition_delay + 0.2: position[0]
@ -123,7 +140,7 @@ class Image(ba.Actor):
ba.animate(cmb, 'input0', keys)
cmb.input1 = position[1]
ba.animate(self.node, 'opacity', o_keys)
elif transition == 'in_bottom_slow':
elif transition is self.Transition.IN_BOTTOM_SLOW:
keys = {
transition_delay: -400,
transition_delay + 3.5: position[1]
@ -132,7 +149,7 @@ class Image(ba.Actor):
cmb.input0 = position[0]
ba.animate(cmb, 'input1', keys)
ba.animate(self.node, 'opacity', o_keys)
elif transition == 'in_bottom':
elif transition is self.Transition.IN_BOTTOM:
keys = {
transition_delay: -400,
transition_delay + 0.2: position[1]
@ -146,13 +163,16 @@ class Image(ba.Actor):
cmb.input0 = position[0]
ba.animate(cmb, 'input1', 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]}
o_keys = {transition_delay: 0.0, transition_delay + 1.0: 1.0}
cmb.input0 = position[0]
ba.animate(cmb, 'input1', keys)
ba.animate(self.node, 'opacity', o_keys)
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.input1 = position[1]
cmb.connectattr('output', self.node, 'position')

View File

@ -21,8 +21,8 @@
"""Defines Actor(s)."""
from __future__ import annotations
from enum import Enum
from enum import Enum
from typing import TYPE_CHECKING
import ba