diff --git a/pysollib/game/__init__.py b/pysollib/game/__init__.py index 83ea31b1..6cfe30dc 100644 --- a/pysollib/game/__init__.py +++ b/pysollib/game/__init__.py @@ -1455,7 +1455,7 @@ class Game(object): c0 = cards[0] dx, dy = (x - c0.x), (y - c0.y) base = float(self.app.opt.animations) - duration = base*base/25.0 + 0.05 + duration = base*base/30.0 + 0.05 for card in cards: card.animatedMove(dx, dy, duration) # self.top.waitAnimation(swallow=True, pickup=True) diff --git a/pysollib/kivy/LApp.py b/pysollib/kivy/LApp.py index 2fdc6b43..3e3af9bc 100644 --- a/pysollib/kivy/LApp.py +++ b/pysollib/kivy/LApp.py @@ -135,30 +135,28 @@ class LAnimationTask(LTask, LBase): class LAnimationMgr(object): def __init__(self, **kw): super(LAnimationMgr, self).__init__() - self.animations = [] - self.widgets = {} + self.tasks = [] self.callbacks = [] self.taskQ = LTaskQ() def checkRunning(self): - return len(self.animations) > 0 + return len(self.tasks) > 0 def addEndCallback(self, cb): self.callbacks.append(cb) - # print('len of callbacks', len(self.callbacks)) - def animEnd(self, anim, widget): - # print('LAnimationMgr: animEnd = %s.%s' % (anim, widget)) + def taskEnd(self, task, value): + if value: + print('LAnimationMgr: taskEnd = %s %s' % (task, value)) + self.tasks.remove(task) + if not self.checkRunning(): + # print('LAnimationMgr: taskEnd ->', len(self.callbacks), 'callbacks') # noqa + for cb in self.callbacks: + cb() + # print('LAnimationMgr: taskEnd -> callbacks done') + self.callbacks = [] - self.animations.remove(anim) - if not self.checkRunning(): - # print('LAnimationMgr: animEnd ->', len(self.callbacks), 'callbacks') # noqa - for cb in self.callbacks: - cb() - # print('LAnimationMgr: animEnd -> callbacks done') - self.callbacks = [] - - print('Clock.get_fps() ->', Clock.get_fps()) + print('Clock.get_fps() ->', Clock.get_fps()) def create(self, spos, widget, **kw): x = 0.0 @@ -175,16 +173,17 @@ class LAnimationMgr(object): transition = kw['transition'] anim = Animation(x=x, y=y, duration=duration, transition=transition) - anim.bind(on_complete=self.animEnd) if 'bindE' in kw: anim.bind(on_complete=kw['bindE']) if 'bindS' in kw: anim.bind(on_start=kw['bindS']) - self.animations.append(anim) offset = duration / 3.0 - animTask = LAnimationTask(anim, spos, widget, offset) - Clock.schedule_once(lambda dt: self.taskQ.taskInsert(animTask), 0.016) + task = LAnimationTask(anim, spos, widget, offset) + self.tasks.append(task) + task.bind(done=self.taskEnd) + + Clock.schedule_once(lambda dt: self.taskQ.taskInsert(task), 0.016) LAnimationManager = LAnimationMgr() diff --git a/pysollib/kivy/LTask.py b/pysollib/kivy/LTask.py index 3aa37ad2..838d27b0 100644 --- a/pysollib/kivy/LTask.py +++ b/pysollib/kivy/LTask.py @@ -21,11 +21,10 @@ from kivy.properties import BooleanProperty, ListProperty class LTask(EventDispatcher): - done = BooleanProperty(False) + done = BooleanProperty(True) def __init__(self, name): super(LTask, self).__init__() - self.done = False self.name = name self.delay = 0.01 @@ -37,10 +36,6 @@ class LTask(EventDispatcher): # print('stop of ',self.name) self.done = True - def on_done(self, instance, value): - # print ('on_done',instance,value) - pass - class LTaskQ(EventDispatcher): waitQ = ListProperty([]) diff --git a/pysollib/kivy/card.py b/pysollib/kivy/card.py index 75381938..2af77203 100644 --- a/pysollib/kivy/card.py +++ b/pysollib/kivy/card.py @@ -23,6 +23,7 @@ from pysollib.acard import AbstractCard from pysollib.kivy.LApp import LImageItem +# from pysollib.kivy.LApp import LAnimationManager from pysollib.kivy.LImage import LImage from pysollib.kivy.tkcanvas import MfxCanvasImage @@ -89,18 +90,24 @@ class _OneImageCard(_HideableCard): def showFace(self, unhide=1): # print ('card: showFace = %s' % self._face_image.source) - if not self.face_up: + def flip(): self._setImage(image=self._face_image) self.tkraise(unhide) self.face_up = 1 + if not self.face_up: + flip() + def showBack(self, unhide=1): # print ('card: showBack = %s' % self._back_image.source) - if self.face_up: + def flip(): self._setImage(image=self._back_image) self.tkraise(unhide) self.face_up = 0 + if self.face_up: + flip() + def updateCardBackground(self, image): print('card: updateCardBackground = %s' % image.source) self._back_image = LImage(texture=image.texture) diff --git a/pysollib/kivy/tkcanvas.py b/pysollib/kivy/tkcanvas.py index 0080aa6e..983f950e 100644 --- a/pysollib/kivy/tkcanvas.py +++ b/pysollib/kivy/tkcanvas.py @@ -276,8 +276,8 @@ class MfxCanvasImage(object): super(MfxCanvasImage, self).__init__() self.canvas = canvas - # animation support: - self.animation = None + # animation mode support: + self.animation = 0 self.deferred_raises = [] self.deferred_pos = [] @@ -337,9 +337,10 @@ class MfxCanvasImage(object): # print('stack[2] = ', inspect.stack()[2].frame) # print('stack[3] = ', inspect.stack()[3].frame) - if self.animation: + if self.animation > 0: # print('defer tkraise to animation', abitm) - self.deferred_raises.append(self.makeDeferredRaise(abitm)) + if len(self.deferred_raises) < self.animation: + self.deferred_raises.append(self.makeDeferredRaise(abitm)) return # print('direct tkraise', abitm) @@ -368,11 +369,12 @@ class MfxCanvasImage(object): dsize = image.coreSize dpos = (image.corePos[0] + dx, image.corePos[1] + dy) image.corePos = dpos - if not self.animation: + if self.animation == 0: image.pos, image.size = self.canvas.CoreToKivy(dpos, dsize) else: - pos, size = self.canvas.CoreToKivy(dpos, dsize) - self.deferred_pos.append(pos) + if len(self.deferred_pos) < self.animation: + pos, size = self.canvas.CoreToKivy(dpos, dsize) + self.deferred_pos.append(pos) def makeAnimStart(self): def animStart(anim, widget): @@ -399,7 +401,13 @@ class MfxCanvasImage(object): def makeAnimEnd(self, dpos, dsize): def animEnd(anim, widget): # print('MfxCanvasImage: animEnd %s' % self) - self.animation = False + if self.animation > 0: + self.animation -= 1 + + if self.animation == 0: + # just for the case, keep in sync: + self.deferred_raises = [] + self.deferred_pos = [] # print('MfxCanvasImage: animEnd moved to %s, %s' % (dpos[0], dpos[1])) # noqa return animEnd @@ -422,7 +430,7 @@ class MfxCanvasImage(object): if self.canvas.wmain.app.game.demo: transition = transition1 - self.animation = True + self.animation += 1 ssize = image.coreSize spos = (image.corePos[0], image.corePos[1]) spos, ssize = self.canvas.CoreToKivy(spos, ssize) @@ -776,16 +784,14 @@ class MfxCanvas(LImage): # print('MfxCanvas: tag_lower: to bottom') self.remove_widget(itm) k = len(self.children.index) - self.add_widget(itm,index=k) + self.add_widget(itm, index=k) else: # print('MfxCanvas: tag_lower: to specified position') self.remove_widget(itm) k = self.children.index(belowThis) k += 1 self.add_widget(itm, index=k) - # - # - # + def setInitialSize(self, width, height): self.r_width = width self.r_height = height