Beispiel #1
0
    def choose_linked_map_entry(self):
        if not issubclass(self.field_type, MapEntry):
            return  # option shouldn't even appear
        names = self.master.linker.get_map_entry_type_names(
            self.field_type)  # adds suffix for Characters
        selected_name = NameSelectionBox(self.master, names).go()
        if selected_name is not None:
            selected_name = selected_name.split("  {")[0]  # remove suffix
            self.field_links = self.master.linker.soulstruct_link(
                self.field_type, selected_name)
            if not self.field_links[0].name:
                display_name = selected_name + "  {BROKEN LINK}"
                self.link_missing = True
                self.master.CustomDialog(
                    title="Map Link Error",
                    message=
                    "Map link was broken after selecting map entry from list. This should not happen; "
                    "please try restarting Soulstruct, and inform Grimrukh if the problem persists.",
                )
            else:
                if self.field_type in (CharacterModel, PlayerModel):
                    model_id = int(selected_name[1:])  # ignore 'c' prefix
                    try:
                        display_name = selected_name + f"  {{{self.master.character_models[model_id]}}}"
                    except KeyError:
                        display_name = selected_name + "  {UNKNOWN}"
                else:
                    display_name = selected_name
                self.link_missing = False

            self.master.change_field_value(self.field_name, selected_name)
            self.value_label.var.set(display_name)
            self.build_field_context_menu()
Beispiel #2
0
    def choose_character_model(self):
        if not issubclass(self.field_type, CharacterModel):
            return  # option shouldn't even appear
        names = [
            f"c{model_id:04d}  {{{model_name}}}"
            for model_id, model_name in self.master.character_models.items()
        ]
        selected_name = NameSelectionBox(self.master, names).go()
        if selected_name is not None:
            selected_name = selected_name.split("  {")[0]  # remove suffix
            self.field_links = self.master.linker.soulstruct_link(
                self.field_type, selected_name)
            if not self.field_links[0].name:
                self.master.add_models(self.field_type, selected_name)
                self.field_links = self.master.linker.soulstruct_link(
                    self.field_type, selected_name)
            if self.field_links[0].name:
                model_id = int(selected_name[1:])  # ignore 'c' prefix
                try:
                    display_name = selected_name + f"  {{{self.master.character_models[model_id]}}}"
                except KeyError:
                    display_name = selected_name + "  {UNKNOWN}"
                if self.link_missing:
                    self.link_missing = False
                    self._update_colors()
            else:
                display_name = selected_name + "  {BROKEN LINK}"
                if not self.link_missing:
                    self.link_missing = True
                    self._update_colors()

            self.master.change_field_value(self.field_name, selected_name)
            self.value_label.var.set(display_name)
            self.build_field_context_menu()
Beispiel #3
0
    def find_all_param_references(self, param_id):
        """Iterates over all ParamTables to find references to this param ID, and presents them in a floating list."""
        category = self.active_category
        param_type = self.params.PARAM_TYPES[category]
        linking_fields = []
        links = {}

        # Find all (param_name, field) pairs that could possibly reference this category.
        for param_name in self.params.PARAM_TYPES:
            param = self.params.get_param(param_name)
            for field_info in param.param_info["fields"]:
                if isinstance(field_info, DynamicFieldDisplayInfo):
                    # Field type will be checked below (per entry).
                    if param_type in field_info.POSSIBLE_TYPES:
                        linking_fields.append((param_name, field_info))
                elif field_info.field_type == param_type:
                    linking_fields.append((param_name, field_info))

        if not linking_fields:
            self.CustomDialog(
                "No References",
                "Could not find any fields in any Params that could possibly reference this entry type.\n"
                "There may still be references elsewhere (e.g. maps, events, animation TAE).",
            )
            return

        for param_name, field_info in linking_fields:
            for row_id, row in self.params.get_param(param_name).items():
                row_field_info = field_info(row)
                if row_field_info.field_type == param_type and row[
                        row_field_info.name] == param_id:
                    link_text = f"{param_name}[{row_id}] {row_field_info.nickname}"
                    links[link_text] = (param_name, row_id,
                                        row_field_info.name)

        if not links:
            self.CustomDialog(
                "No References",
                "Could not find any references to this row in Params.\nThere may still be references elsewhere.",
            )
            return

        name_box = NameSelectionBox(
            self.master,
            names=links,
            list_name=f"Param References to {category}[{param_id}]")
        selected_link = name_box.go()
        if selected_link is not None:
            param_name, row_id, field_name = links[selected_link]
            self.select_category(param_name, auto_scroll=True)
            self.select_entry_id(row_id, edit_if_already_selected=False)
            self.select_field_name(field_name)