comparison pyink/MBScene.py @ 1120:214e1f628d63

Add tween type selector into the UI. This UI can be used to update the type attribute of the SVG.
author wycc
date Tue, 07 Dec 2010 07:52:47 +0800
parents 5ba2cab1d505
children aad659b6b625
comparison
equal deleted inserted replaced
1104:9d52dda8d49f 1120:214e1f628d63
46 self.nodes=[] 46 self.nodes=[]
47 pass 47 pass
48 pass 48 pass
49 49
50 class Scene: 50 class Scene:
51 def __init__(self, node, start,end): 51 def __init__(self, node, start,end,typ):
52 self.node = node 52 self.node = node
53 self.start = int(start) 53 self.start = int(start)
54 self.end = int(end) 54 self.end = int(end)
55 self.type = typ
55 pass 56 pass
56 pass 57 pass
57 58
58 _scenes = '{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scenes' 59 _scenes = '{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scenes'
59 _scene = '{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scene' 60 _scene = '{http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd}scene'
166 end = start 167 end = start
167 pass 168 pass
168 except: 169 except:
169 end = start 170 end = start
170 pass 171 pass
172 try:
173 typ = s.repr.attribute('type')
174 if typ == None:
175 typ = 'normal'
176 except:
177 traceback.print_exc()
178 typ = 'normal'
171 link = s.repr.attribute("ref") 179 link = s.repr.attribute("ref")
172 self.scenemap[link] = [int(start),int(end)] 180 self.scenemap[link] = [int(start),int(end),typ]
173 print "scene %d to %d" % (self.scenemap[link][0],
174 self.scenemap[link][1])
175 if cur >= start and cur <= end: 181 if cur >= start and cur <= end:
176 self.currentscene = link 182 self.currentscene = link
177 pass 183 pass
178 pass 184 pass
179 pass 185 pass
232 continue 238 continue
233 except: 239 except:
234 lyobj.current_scene.append(scene) 240 lyobj.current_scene.append(scene)
235 continue 241 continue
236 242
237 lyobj.scenes.append(Scene(scene,scmap[0],scmap[1])) 243 lyobj.scenes.append(Scene(scene,scmap[0],scmap[1],scmap[2]))
238 pass 244 pass
239 else: 245 else:
240 lyobj.current_scene.append(scene) 246 lyobj.current_scene.append(scene)
241 pass 247 pass
242 pass 248 pass
456 while i < len(frameline._keys): 462 while i < len(frameline._keys):
457 s = frameline._keys[i] 463 s = frameline._keys[i]
458 if s.right_tween is False: 464 if s.right_tween is False:
459 if nth == s.idx+1: 465 if nth == s.idx+1:
460 self.enterGroup(s.ref) 466 self.enterGroup(s.ref)
467 self.setTweenType(frameline.get_tween_type(s.idx))
461 return 468 return
462 else: 469 else:
463 pass 470 pass
464 i = i + 1 471 i = i + 1
465 continue 472 continue
466 473
467 if nth >= (s.idx+1) and nth <= (frameline._keys[i+1].idx+1): 474 if nth >= (s.idx+1) and nth <= (frameline._keys[i+1].idx+1):
468 self.enterGroup(s.ref) 475 self.enterGroup(s.ref)
476 self.setTweenType(frameline.get_tween_type(s.idx))
469 return 477 return
470 else: 478 else:
471 pass 479 pass
472 i = i + 2 480 i = i + 2
473 pass 481 pass
474 pass 482 pass
483 def setTweenType(self,typ):
484 if typ == 'normal':
485 self.tweenTypeSelector.set_active(0)
486 elif typ == 'relocate':
487 self.tweenTypeSelector.set_active(1)
488 elif typ == 'scale':
489 self.tweenTypeSelector.set_active(2)
475 490
476 491
477 492
478 def newCell(self,file): 493 def newCell(self,file):
479 img = gtk.Image() 494 img = gtk.Image()
556 frameline.label.set_text(frameline.node.label()) 571 frameline.label.set_text(frameline.node.label())
557 for scene in layer.scenes: 572 for scene in layer.scenes:
558 frameline.add_keyframe(scene.start-1,scene.node.repr) 573 frameline.add_keyframe(scene.start-1,scene.node.repr)
559 if scene.start != scene.end: 574 if scene.start != scene.end:
560 frameline.add_keyframe(scene.end-1,scene.node.repr) 575 frameline.add_keyframe(scene.end-1,scene.node.repr)
561 frameline.tween(scene.start-1) 576 frameline.tween(scene.start-1,scene.type)
562 pass 577 pass
563 pass 578 pass
564 pass 579 pass
565 580
566 def cellSelect(self, cell, data): 581 def cellSelect(self, cell, data):
660 hbox.pack_start(btn,expand=False,fill=False) 675 hbox.pack_start(btn,expand=False,fill=False)
661 btn=gtk.Button('Duplicate Key') 676 btn=gtk.Button('Duplicate Key')
662 btn.connect('clicked', self.doDuplicateKeyScene) 677 btn.connect('clicked', self.doDuplicateKeyScene)
663 hbox.pack_start(btn,expand=False,fill=False) 678 hbox.pack_start(btn,expand=False,fill=False)
664 self.addNameEditor(hbox) 679 self.addNameEditor(hbox)
665 pass 680 self.addTweenTypeSelector(hbox)
681 pass
682 def onTweenTypeChange(self,w):
683 n = self.tweenTypeSelector.get_active()
684 if self.last_line == None:
685 return
686 frameline = self.last_line
687 i = 0
688 found = -1
689 while i < len(frameline._keys):
690 s = frameline._keys[i]
691 if s.right_tween is False:
692 if self.last_frame == s.idx:
693 found = s.idx
694 break
695 else:
696 pass
697 i = i + 1
698 continue
699
700 if self.last_frame >= s.idx and self.last_frame <= frameline._keys[i+1].idx:
701 found = s.idx
702 break
703 else:
704 pass
705 i = i + 2
706 pass
707 pass
708 if found == -1: return
709 self.last_line.set_tween_type(found,self.tweenTypeSelector.get_active_text())
710 self.last_line.update()
711 self.update()
712
713 def addTweenTypeSelector(self,hbox):
714 tweenbox = gtk.HBox()
715 label = gtk.Label('Tween Type')
716 tweenbox.pack_start(label)
717
718 self.tweenTypeSelector = gtk.combo_box_new_text()
719 self.tweenTypeSelector.append_text('normal')
720 self.tweenTypeSelector.append_text('relocate')
721 self.tweenTypeSelector.append_text('scale')
722 self.tweenTypeSelector.set_active(0)
723 tweenbox.pack_start(self.tweenTypeSelector, expand=False,fill=False)
724 hbox.pack_start(tweenbox,expand=False,fill=False)
725 self.tweenTypeSelector.connect('changed', self.onTweenTypeChange)
666 726
667 def onQuit(self, event): 727 def onQuit(self, event):
668 self.OK = False 728 self.OK = False
669 gtk.main_quit() 729 gtk.main_quit()
670 pass 730 pass