def update_model_preview(self): custom_model_name = self.get_option_value("custom_player_model") custom_model_metadata = customizer.get_model_metadata(custom_model_name) disable_casual_clothes = custom_model_metadata.get("disable_casual_clothes", False) if self.get_option_value("player_in_casual_clothes") and not disable_casual_clothes: prefix = "casual" else: prefix = "hero" try: preview_image = customizer.get_model_preview_image(custom_model_name, prefix, self.custom_colors) except Exception as e: stack_trace = traceback.format_exc() error_message = "Failed to load model preview image for model %s.\nError:\n" % (custom_model_name) + str(e) + "\n\n" + stack_trace print(error_message) QMessageBox.critical( self, "Failed to load model preview", error_message ) return if preview_image is None: self.ui.custom_model_preview_label.hide() return self.ui.custom_model_preview_label.show() data = preview_image.tobytes('raw', 'BGRA') qimage = QImage(data, preview_image.size[0], preview_image.size[1], QImage.Format_ARGB32) scaled_pixmap = QPixmap.fromImage(qimage).scaled(225, 350, Qt.KeepAspectRatio, Qt.SmoothTransformation) self.ui.custom_model_preview_label.setPixmap(scaled_pixmap)
def reset_color_selectors_to_model_default_colors(self): custom_model_name = self.get_option_value("custom_player_model") is_casual = self.get_option_value("player_in_casual_clothes") if is_casual: prefix = "casual" else: prefix = "hero" metadata = customizer.get_model_metadata(custom_model_name) if metadata is None: return custom_colors = metadata.get(prefix + "_custom_colors", {}) any_color_changed = False for custom_color_name, default_color in custom_colors.items(): if self.custom_colors[custom_color_name] != default_color: any_color_changed = True option_name = "custom_color_" + custom_color_name self.set_color(option_name, default_color, update_preview=False) if any_color_changed: self.update_model_preview() return any_color_changed
def update_model_preview(self): custom_model_name = self.get_option_value("custom_player_model") custom_model_metadata = customizer.get_model_metadata( custom_model_name) disable_casual_clothes = custom_model_metadata.get( "disable_casual_clothes", False) if self.get_option_value( "player_in_casual_clothes") and not disable_casual_clothes: prefix = "casual" else: prefix = "hero" preview_image = customizer.get_model_preview_image( custom_model_name, prefix, self.custom_colors) if preview_image is None: self.ui.custom_model_preview_label.hide() return self.ui.custom_model_preview_label.show() data = preview_image.tobytes('raw', 'BGRA') qimage = QImage(data, preview_image.size[0], preview_image.size[1], QImage.Format_ARGB32) scaled_pixmap = QPixmap.fromImage(qimage).scaled( 225, 350, Qt.KeepAspectRatio, Qt.SmoothTransformation) self.ui.custom_model_preview_label.setPixmap(scaled_pixmap)
def disable_invalid_cosmetic_options(self): custom_model_name = self.get_option_value("custom_player_model") metadata = customizer.get_model_metadata(custom_model_name) if metadata is None: self.ui.player_in_casual_clothes.setEnabled(True) self.set_option_value("player_in_casual_clothes", False) else: disable_casual_clothes = metadata.get("disable_casual_clothes", False) if disable_casual_clothes: self.ui.player_in_casual_clothes.setEnabled(False) self.ui.player_in_casual_clothes.setChecked(False) else: self.ui.player_in_casual_clothes.setEnabled(True)
def reset_color_selectors_to_model_default_colors(self): custom_model_name = self.get_option_value("custom_player_model") is_casual = self.get_option_value("player_in_casual_clothes") if is_casual: prefix = "casual" else: prefix = "hero" metadata = customizer.get_model_metadata(custom_model_name) if metadata is None: return custom_colors = metadata.get(prefix + "_custom_colors", {}) for custom_color_name, default_color in custom_colors.items(): option_name = "custom_color_" + custom_color_name self.set_color(option_name, default_color)
def custom_model_changed(self): self.disable_invalid_cosmetic_options() while self.ui.custom_colors_layout.count(): item = self.ui.custom_colors_layout.takeAt(0) hlayout = item.layout() while hlayout.count(): item = hlayout.takeAt(0) widget = item.widget() widget.deleteLater() self.custom_color_selector_buttons = OrderedDict() custom_model_name = self.get_option_value("custom_player_model") metadata = customizer.get_model_metadata(custom_model_name) if metadata is None: return is_casual = self.get_option_value("player_in_casual_clothes") if is_casual: prefix = "casual" else: prefix = "hero" self.custom_colors = OrderedDict() custom_colors = metadata.get(prefix + "_custom_colors", {}) for custom_color_name, default_color in custom_colors.items(): option_name = "custom_color_" + custom_color_name hlayout = QHBoxLayout() label_for_color_selector = QLabel(self.ui.tab_2) label_for_color_selector.setText("Player %s Color" % custom_color_name) hlayout.addWidget(label_for_color_selector) color_selector_button = QPushButton(self.ui.tab_2) color_selector_button.setText("") color_selector_button.setObjectName(option_name) hlayout.addWidget(color_selector_button) self.custom_color_selector_buttons[ option_name] = color_selector_button color_selector_button.clicked.connect( self.open_custom_color_chooser) self.ui.custom_colors_layout.addLayout(hlayout) self.set_color(option_name, default_color)
def custom_model_changed(self): self.disable_invalid_cosmetic_options() while self.ui.custom_colors_layout.count(): item = self.ui.custom_colors_layout.takeAt(0) hlayout = item.layout() while hlayout.count(): item = hlayout.takeAt(0) widget = item.widget() if widget: widget.deleteLater() self.custom_color_selector_buttons = OrderedDict() self.custom_color_selector_hex_inputs = OrderedDict() custom_model_name = self.get_option_value("custom_player_model") metadata = customizer.get_model_metadata(custom_model_name) if metadata is None: return if "error_message" in metadata: error_message = "Syntax error when trying to read metadata.txt for custom model: %s\n\n%s" %(custom_model_name, metadata["error_message"]) print(error_message) QMessageBox.critical( self, "Failed to load model metadata", error_message ) model_author = metadata.get("author", None) model_comment = metadata.get("comment", None) comment_lines = [] if model_author: comment_lines.append("Model author: %s" % model_author) if model_comment: comment_lines.append("Model author comment: %s" % model_comment) self.ui.custom_model_comment.setText("\n".join(comment_lines)) if len(comment_lines) <= 0: self.ui.custom_model_comment.hide() else: self.ui.custom_model_comment.show() is_casual = self.get_option_value("player_in_casual_clothes") if is_casual: prefix = "casual" else: prefix = "hero" self.custom_colors = OrderedDict() custom_colors = metadata.get(prefix + "_custom_colors", {}) for custom_color_name, default_color in custom_colors.items(): option_name = "custom_color_" + custom_color_name hlayout = QHBoxLayout() label_for_color_selector = QLabel(self.ui.tab_2) label_for_color_selector.setText("Player %s Color" % custom_color_name) hlayout.addWidget(label_for_color_selector) color_hex_code_input = QLineEdit(self.ui.tab_2) color_hex_code_input.setText("") color_hex_code_input.setObjectName(option_name + "_hex_code_input") color_hex_code_input.setFixedWidth(52) hlayout.addWidget(color_hex_code_input) color_selector_button = QPushButton(self.ui.tab_2) color_selector_button.setText("Click to set color") color_selector_button.setObjectName(option_name) hlayout.addWidget(color_selector_button) self.custom_color_selector_buttons[option_name] = color_selector_button color_selector_button.clicked.connect(self.open_custom_color_chooser) self.custom_color_selector_hex_inputs[option_name] = color_hex_code_input color_hex_code_input.textEdited.connect(self.custom_color_hex_code_changed) color_hex_code_input.editingFinished.connect(self.custom_color_hex_code_finished_editing) self.ui.custom_colors_layout.addLayout(hlayout) self.set_color(option_name, default_color, update_preview=False) if len(custom_colors) == 0: # Need to push the preview over to the right even when there are no colors to do it, so add a spacer. hlayout = QHBoxLayout() hspacer = QSpacerItem(20, 40, QSizePolicy.Expanding, QSizePolicy.Minimum) hlayout.addItem(hspacer) self.ui.custom_colors_layout.addLayout(hlayout) self.update_model_preview()
def custom_model_changed(self): self.disable_invalid_cosmetic_options() while self.ui.custom_colors_layout.count(): item = self.ui.custom_colors_layout.takeAt(0) hlayout = item.layout() while hlayout.count(): item = hlayout.takeAt(0) widget = item.widget() if widget: widget.deleteLater() self.custom_color_selector_buttons = OrderedDict() self.custom_color_selector_hex_inputs = OrderedDict() custom_model_name = self.get_option_value("custom_player_model") metadata = customizer.get_model_metadata(custom_model_name) if metadata is None: return if "error_message" in metadata: error_message = "Syntax error when trying to read metadata.txt for custom model: %s\n\n%s" % ( custom_model_name, metadata["error_message"]) print(error_message) QMessageBox.critical(self, "Failed to load model metadata", error_message) model_author = metadata.get("author", None) model_comment = metadata.get("comment", None) comment_lines = [] if model_author: comment_lines.append("Model author: %s" % model_author) if model_comment: comment_lines.append("Model author comment: %s" % model_comment) self.ui.custom_model_comment.setText("\n".join(comment_lines)) if len(comment_lines) <= 0: self.ui.custom_model_comment.hide() else: self.ui.custom_model_comment.show() # Allow customizing the text of the Casual Clothes checkbox. casual_clothes_option_text = str( metadata.get("casual_clothes_option_text", "Casual Clothes")) if len(casual_clothes_option_text) > 28: # 28 character maximum length. casual_clothes_option_text = casual_clothes_option_text[:28] self.ui.player_in_casual_clothes.setText(casual_clothes_option_text) is_casual = self.get_option_value("player_in_casual_clothes") if is_casual: prefix = "casual" else: prefix = "hero" self.custom_colors = OrderedDict() custom_colors = metadata.get(prefix + "_custom_colors", {}) for custom_color_name, default_color in custom_colors.items(): option_name = "custom_color_" + custom_color_name hlayout = QHBoxLayout() label_for_color_selector = QLabel(self.ui.tab_2) label_for_color_selector.setText("Player %s Color" % custom_color_name) hlayout.addWidget(label_for_color_selector) color_hex_code_input = QLineEdit(self.ui.tab_2) color_hex_code_input.setText("") color_hex_code_input.setObjectName(option_name + "_hex_code_input") color_hex_code_input.setFixedWidth(52) hlayout.addWidget(color_hex_code_input) color_selector_button = QPushButton(self.ui.tab_2) color_selector_button.setText("Click to set color") color_selector_button.setObjectName(option_name) hlayout.addWidget(color_selector_button) self.custom_color_selector_buttons[ option_name] = color_selector_button color_selector_button.clicked.connect( self.open_custom_color_chooser) self.custom_color_selector_hex_inputs[ option_name] = color_hex_code_input color_hex_code_input.textEdited.connect( self.custom_color_hex_code_changed) color_hex_code_input.editingFinished.connect( self.custom_color_hex_code_finished_editing) self.ui.custom_colors_layout.addLayout(hlayout) self.set_color(option_name, default_color, update_preview=False) if len(custom_colors) == 0: # Need to push the preview over to the right even when there are no colors to do it, so add a spacer. hlayout = QHBoxLayout() hspacer = QSpacerItem(20, 40, QSizePolicy.Expanding, QSizePolicy.Minimum) hlayout.addItem(hspacer) self.ui.custom_colors_layout.addLayout(hlayout) self.update_model_preview() # Hide the custom voice disable option for models that don't have custom voice files. if custom_model_name == "Random" or custom_model_name == "Random (exclude Link)": self.ui.disable_custom_player_voice.show() else: custom_model_path = "./models/%s/" % custom_model_name jaiinit_aaf_path = custom_model_path + "sound/JaiInit.aaf" voice_aw_path = custom_model_path + "sound/voice_0.aw" if os.path.isfile(jaiinit_aaf_path) and os.path.isfile( voice_aw_path): self.ui.disable_custom_player_voice.show() else: self.ui.disable_custom_player_voice.hide()