def __init__(self, position, title_text, animation_types): BuilderContainer.__init__(self) self.moveset = None self.position = position self.title = MovesetBuilderLabel(position, title_text, (255,255,255), 22) self.add_child(self.title) button_list = [] for type_tuple in animation_types: button_list.append(MoveTypeButton(type_tuple[0], type_tuple[1], 20)) self.buttons = button_list self.layout_buttons() self.add_children(button_list) self.buttons[0].handle_selected() navigator_position = (position[0] + 15, position[1] + self.height + 15) animation_navigator = AttackNavigator(navigator_position, 221, 250) animation_navigator.load_data(navigator_position, self.buttons[0].move_type) self.animation_navigator = animation_navigator self.add_child(animation_navigator) self.validation_tree = InputTree()
class AttackSelectContainer(AnimationSelectContainer): def __init__(self, position, title_text, animation_types): BuilderContainer.__init__(self) self.moveset = None self.position = position self.title = MovesetBuilderLabel(position, title_text, (255,255,255), 22) self.add_child(self.title) button_list = [] for type_tuple in animation_types: button_list.append(MoveTypeButton(type_tuple[0], type_tuple[1], 20)) self.buttons = button_list self.layout_buttons() self.add_children(button_list) self.buttons[0].handle_selected() navigator_position = (position[0] + 15, position[1] + self.height + 15) animation_navigator = AttackNavigator(navigator_position, 221, 250) animation_navigator.load_data(navigator_position, self.buttons[0].move_type) self.animation_navigator = animation_navigator self.add_child(animation_navigator) self.validation_tree = InputTree() def init_validation_tree(self): for attack_name, key_combination in self.moveset.attack_key_combinations.iteritems(): self.validation_tree.add_branches(key_combination, attack_name) def selected_animation(self): return self.animation_navigator.selected_animation def get_thumbnail(self, animation_name): if animation_name in self.animation_navigator.animation_thumbnails: return self.animation_navigator.animation_thumbnails[animation_name] def get_attack_label(self, animation_name): if animation_name in self.animation_navigator.attack_label_dictionary: return self.animation_navigator.attack_label_dictionary[animation_name] def get_key_combination(self, animation_name): if animation_name in self.animation_navigator.attack_label_dictionary: return self.animation_navigator.attack_label_dictionary[animation_name].key_combination def set_key_combination(self, animation_name, key_combination): label = self.get_attack_label(animation_name) self.validation_tree.delete_value(label.key_combination) label.set_key_combination(key_combination) self.validation_tree.add_branches(key_combination, animation_name) def is_valid_command(self, key_combination): """check if the given key combination is allowed. An empty key combination is allowed to remove an attack from a moveset. Any other key combination must contain an attack key""" if len(key_combination) == 0: return True for action_type in InputActionTypes.ATTACKS: if action_type in key_combination: return True return False def command_in_use(self, key_combination): """Check if a key combination is in use by another attack""" if self.validation_tree.get_value(key_combination) != None: return True else: return False def set_moveset(self, moveset): self.moveset = moveset self.sync_to_moveset() self.init_validation_tree() def sync_to_moveset(self): for label in self.animation_navigator.attack_labels: if label.attack_name in self.moveset.attack_key_combinations: label.set_key_combination( self.moveset.attack_key_combinations[label.attack_name] ) def save_to_moveset(self): for label in self.animation_navigator.attack_labels: if len(label.key_combination) > 0: self.moveset.save_attack_animation( self.animation_navigator.get_animation(label.attack_name) ) self.moveset.save_attack_key_combination( label.attack_name, label.key_combination ) self.moveset.save_attack_type( label.attack_name, self.animation_navigator.animation_type ) elif label.attack_name in self.moveset.attack_key_combinations: self.moveset.delete_attack(label.attack_name) def handle_events(self): reload_indicator = self.animation_navigator.reload_indicator self.animation_navigator.handle_events() if reload_indicator: self.sync_to_moveset() if pygame.MOUSEBUTTONDOWN in wotsuievents.event_types: for button in self.buttons: if button.contains(wotsuievents.mouse_pos): for other_button in self.buttons: if other_button.selected and other_button != button: other_button.handle_deselected() button.handle_selected() self.save_to_moveset() self.animation_navigator.animation_type = button.move_type self.animation_navigator.load_animation_data() self.animation_navigator.selected_animation = None self.sync_to_moveset()