def update_yaml(self): for item in self.temp: sprite = item[0] try: k = realkey(sprite.name) v = sprite.value if k and v: self.item.put(k, v) except: continue
def editorlayout(self): debug('Building editor layout') self._rmtemp() self.baselayout() col, row = 0, 0 for key in [i for i in self.template if '__Y' in i]: value = self.item.get(realkey(key),False) if value is False: self.item.put(realkey(key), self.template[key]) list1 = sorted([i for i in self.template if not i.startswith('conditional/') and not i.startswith('events/') and not '__Y' in i and not 'animations' in i and i != 'personal/portrait']) list3 = sorted([i for i in self.template if i.startswith('events/')]) list2 = sorted([i for i in self.conditional_sprites if not 'animations' in i]) if [i for i in self.template if 'equiped' in i]: list4=['inventory'] else: list4 = [] allkeys = list1 + list2 + list3 + list4 for key in allkeys: x = col * 450 + self.rect.x + 15 y = row * 35 + self.rect.y + 75 if key == 'inventory': b = Button('Iventory', self.showinventory, [], self.frontend.eventstack, self.frontend.imagecache, pos=(x ,y), layer=6, fontsize=14) self._addtemp('%s_button' % key, b) row += 1 continue if key.startswith('events/') or key.startswith('__T'): b = Button(realkey(key), self.make_event, [realkey(key)], self.frontend.eventstack, self.frontend.imagecache, pos=(x ,y), layer=6, sendself=True, fontsize=14) self._addtemp('%s_button' % key, b) else: sprites = self.handlekey(key, x,y) for sprite in sprites: self._addtemp('%s_%s' % (key,sprites.index(sprite)), sprite) row += 1 if row * 35 + self.rect.y + 75 + 128> self.rect.y + self.rect.h -75: row = 0 col += 1 for key in sorted([i for i in self.conditional_sprites if 'animations' in i])+sorted(i for i in self.template if 'animations' in i and not 'conditional' in i and i != 'personal/portrait'): keyname = realkey(key) value = self.item.get(keyname,[]) if not value: value = self.template[key] self.item.put(keyname, value) if self.item.animations: x = col * 450 + self.rect.x + 15 y = row * 35 + self.rect.y + 75 self.animation_editor(x,y) y = y + 75 for sprite in self.handlekey('personal/portrait', x,y): self._addtemp(make_hash(), sprite)
def handlekey(self,key, x,y): keyname = realkey(key) has_label = True l = Label(keyname,(x,y)) lsize = l.rect.w +10 irect = pygame.Rect(x + lsize, y, 250, 20) value = self.item.get(keyname,'') if not value: if key in self.template: value = self.template[key] else: return () if str(value).startswith('__'): value = '' if keyname == 'personal/portrait': self.item.put('personal/portrait', value) self.portrait = value d = BlitButton( self.nextportrait, [], self.frontend.eventstack, self.frontend.imagecache, self.portrait, pos=(irect.x,y), scale=128, layer=7 ) elif isinstance(value, list): d = Button('Manage list', self.listmanager, [keyname, value], self.frontend.eventstack, self.frontend.imagecache, pos=(irect.x, irect.y), layer=self._layer +1) elif (key.startswith('conditional') or keyname == key) and not '__[' in str(self.template[key]): d = TextInput( irect,18, self.frontend.eventstack, prompt=str(value), clearprompt=False, layer=6, name=keyname) elif (key.startswith('conditional') or keyname == key) and '__[' in str(self.template[key]): liststr = self.template[key] items = liststr[3:-1].split(',') if sorted([i.upper() for i in items]) == ['FALSE','TRUE']: has_label = False d = checkboxbtn(keyname, self.valuechange, [], self.frontend.eventstack, self.frontend.imagecache, pos=(x,y), fontsize=16, layer=6, name=key, sendself=True) if d.name in self.item(): d.checked = self.item.get(d.name) else: d.checked = items[0].upper() == 'TRUE' else: if not value and len(items) == 1: value = items[0] d = Dropdown( self.frontend.eventstack, self.frontend.imagecache, 16, irect, items,layer=self.lastlayer, choice=value, onselect=self.valuechange, name=keyname, sendself=True) self.lastlayer -= 1 if has_label: return [l, d] else: return [d]