def open(self, **__) -> None:
        """ Open the dialog. """
        def _reopen() -> None:
            self.open(**__)

        def _on_close() -> None:
            if self._on_close is not None:
                self._on_close()

        def _on_previous() -> None:
            if any(__):
                self.open()
                return
            if self._on_previous is not None:
                self._on_previous()

        option_dialog = CommonChooseButtonOptionDialog(
            self.mod_identity,
            self.title,
            self.description,
            include_previous_button=self.include_previous_button,
            on_previous=_on_previous,
            on_close=_on_close
        )

        if not self._setup_dialog(option_dialog, _on_close, _on_previous, _reopen, **__):
            _on_previous()
            return

        if not option_dialog.has_options():
            _on_previous()
            return

        option_dialog.show(
            sim_info=self._sim_info
        )
    def run_with_sims(self,
                      sim_info: SimInfo,
                      chosen_sim_info: SimInfo,
                      on_completed: Callable[[bool],
                                             None] = CommonFunctionUtils.noop):
        def _on_none_chosen(_: Any, __: Any):
            try:
                CommonSimGenealogyUtils.remove_family_relations_with(
                    sim_info, chosen_sim_info)
                CommonSimGenealogyUtils.remove_family_relations_with(
                    chosen_sim_info, sim_info)
            except Exception as ex:
                self.log.error('Failed to remove family relations',
                               exception=ex)
            self.run_with_sims(sim_info,
                               chosen_sim_info,
                               on_completed=on_completed)

        def _on_bit_chosen(
                _: Any,
                chosen_operation: S4CMSetSimAAsRelationToSimBOperation):
            if _ is None or chosen_operation is None:
                return
            if chosen_operation.has_relation(sim_info, chosen_sim_info):
                self.run_with_sims(sim_info,
                                   chosen_sim_info,
                                   on_completed=on_completed)
                return

            def _on_yes_selected(_: Any):
                if chosen_operation is None:
                    self.run_with_sims(sim_info,
                                       chosen_sim_info,
                                       on_completed=on_completed)
                    return

                def _on_completed(___: bool):
                    self.run_with_sims(sim_info,
                                       chosen_sim_info,
                                       on_completed=on_completed)

                chosen_operation.run(sim_info,
                                     chosen_sim_info,
                                     on_completed=_on_completed)

            def _on_no_selected(_: Any):
                self.run_with_sims(sim_info,
                                   chosen_sim_info,
                                   on_completed=on_completed)

            confirmation = CommonOkCancelDialog(
                S4CMStringId.CONFIRMATION,
                S4CMSimControlMenuStringId.
                SIM_WILL_BECOME_RELATIONSHIP_TO_SIM_CONFIRMATION_TEXT,
                description_tokens=(sim_info,
                                    chosen_operation.get_display_name(
                                        chosen_sim_info,
                                        sim_info), chosen_sim_info),
                ok_text_identifier=S4CMStringId.YES,
                cancel_text_identifier=S4CMStringId.NO)
            confirmation.show(on_ok_selected=_on_yes_selected,
                              on_cancel_selected=_on_no_selected)
            return True

        option_dialog = CommonChooseButtonOptionDialog(
            ModInfo.get_identity(),
            S4CMSimControlMenuStringId.CHOOSE_FAMILY_RELATION,
            S4CMSimControlMenuStringId.CHOOSE_WHAT_SIM_WILL_BECOME_TO_SIM,
            description_tokens=(sim_info, chosen_sim_info),
            include_previous_button=True,
            on_previous=lambda: on_completed(False),
            on_close=lambda: on_completed(False))

        options = list()
        has_a_relation = False
        for relationship_operation in self._relation_operations:
            relationship_operation: S4CMSetSimAAsRelationToSimBOperation = relationship_operation
            display_name = relationship_operation.get_display_name(
                chosen_sim_info, sim_info)
            has_relation = relationship_operation.has_relation(
                sim_info, chosen_sim_info)
            if has_relation:
                has_a_relation = True
            options.append(
                CommonDialogButtonOption(
                    str(relationship_operation.relationship_bit_id),
                    relationship_operation,
                    CommonDialogResponseOptionContext(
                        CommonLocalizationUtils.colorize(
                            display_name, CommonLocalizedStringColor.GREEN)
                        if has_relation else display_name,
                        disabled_text_identifier=relationship_operation.
                        get_disabled_text(sim_info, chosen_sim_info)),
                    on_chosen=_on_bit_chosen))

        option_dialog.add_option(
            CommonDialogButtonOption(
                'None',
                None,
                CommonDialogResponseOptionContext(
                    CommonLocalizationUtils.colorize(
                        S4CMStringId.NONE, CommonLocalizedStringColor.GREEN)
                    if not has_a_relation else S4CMStringId.NONE, ),
                on_chosen=_on_none_chosen))

        for option in options:
            option_dialog.add_option(option)

        if not option_dialog.has_options():
            on_completed(False)
            return

        option_dialog.show(sim_info=sim_info)
Ejemplo n.º 3
0
    def run(
        self,
        grandchild_sim_info: SimInfo,
        grandparent_sim_info: SimInfo,
        on_completed: Callable[[bool],
                               None] = CommonFunctionUtils.noop) -> bool:
        def _on_bit_chosen(
                _: Any,
                chosen_operation: S4CMSetSimAAsRelationToSimBOperation):
            if _ is None or chosen_operation is None:
                return
            if chosen_operation.has_relation(grandparent_sim_info,
                                             grandchild_sim_info):
                on_completed(True)
                return

            def _on_yes_selected(_: Any):
                chosen_operation.run(grandparent_sim_info,
                                     grandchild_sim_info,
                                     on_completed=on_completed)

            def _on_no_selected(_: Any):
                self.run(grandchild_sim_info,
                         grandparent_sim_info,
                         on_completed=on_completed)

            confirmation = CommonOkCancelDialog(
                S4CMStringId.CONFIRMATION,
                S4CMSimControlMenuStringId.
                SIM_WILL_BECOME_RELATIONSHIP_TO_SIM_CONFIRMATION_TEXT,
                description_tokens=(grandparent_sim_info,
                                    chosen_operation.get_display_name(
                                        grandchild_sim_info,
                                        grandparent_sim_info),
                                    grandchild_sim_info),
                ok_text_identifier=S4CMStringId.YES,
                cancel_text_identifier=S4CMStringId.NO)
            confirmation.show(on_ok_selected=_on_yes_selected,
                              on_cancel_selected=_on_no_selected)
            return True

        option_dialog = CommonChooseButtonOptionDialog(
            self.mod_identity,
            S4CMSimControlMenuStringId.CHOOSE_FAMILY_RELATION,
            S4CMSimControlMenuStringId.CHOOSE_WHAT_SIM_WILL_BECOME_TO_SIM,
            description_tokens=(grandparent_sim_info, grandchild_sim_info),
            include_previous_button=True,
            on_previous=lambda: on_completed(False),
            on_close=lambda: on_completed(False))

        from sims4controlmenu.dialogs.modify_sim_data.modify_relationships.operations.family_relationship_operations.grandfather_on_fathers_side import \
            S4CMSetSimAAsGrandfatherOnFathersSideToSimBOp
        from sims4controlmenu.dialogs.modify_sim_data.modify_relationships.operations.family_relationship_operations.grandfather_on_mothers_side import \
            S4CMSetSimAAsGrandfatherOnMothersSideToSimBOp
        from sims4controlmenu.dialogs.modify_sim_data.modify_relationships.operations.family_relationship_operations.grandmother_on_fathers_side import \
            S4CMSetSimAAsGrandmotherOnFathersSideToSimBOp
        from sims4controlmenu.dialogs.modify_sim_data.modify_relationships.operations.family_relationship_operations.grandmother_on_mothers_side import \
            S4CMSetSimAAsGrandmotherOnMothersSideToSimBOp

        relationship_operations = (
            S4CMSetSimAAsGrandfatherOnFathersSideToSimBOp(),
            S4CMSetSimAAsGrandfatherOnMothersSideToSimBOp(),
            S4CMSetSimAAsGrandmotherOnFathersSideToSimBOp(),
            S4CMSetSimAAsGrandmotherOnMothersSideToSimBOp())

        for relationship_operation in relationship_operations:
            relationship_operation: S4CMSetSimAAsRelationToSimBOperation = relationship_operation
            display_name = relationship_operation.get_display_name(
                grandchild_sim_info, grandparent_sim_info)
            has_relation = relationship_operation.has_relation(
                grandparent_sim_info, grandchild_sim_info)
            option_dialog.add_option(
                CommonDialogButtonOption(
                    str(relationship_operation.relationship_bit_id),
                    relationship_operation,
                    CommonDialogResponseOptionContext(
                        CommonLocalizationUtils.colorize(
                            display_name, CommonLocalizedStringColor.GREEN)
                        if has_relation else display_name,
                        disabled_text_identifier=relationship_operation.
                        get_disabled_text(grandparent_sim_info,
                                          grandchild_sim_info)),
                    on_chosen=_on_bit_chosen))

        if not option_dialog.has_options():
            on_completed(False)
            return False

        option_dialog.show(sim_info=grandparent_sim_info)
        return True
Ejemplo n.º 4
0
    def run_with_sims(self,
                      sim_info_a: SimInfo,
                      sim_info_b: SimInfo,
                      on_completed: Callable[[bool],
                                             None] = CommonFunctionUtils.noop):
        relationship_track_id = self._determine_relationship_track(
            sim_info_a, sim_info_b)
        if relationship_track_id == -1:
            self.log.format_with_message(
                'No relationship track id found between Sims.',
                sim=sim_info_a,
                chosen_sim=sim_info_b)
            on_completed(False)
            return
        relationship_track = CommonResourceUtils.load_instance(
            Types.STATISTIC, relationship_track_id)
        if relationship_track is None:
            self.log.format_with_message('No relationship track found.',
                                         sim=sim_info_a,
                                         chosen_sim=sim_info_b)
            on_completed(False)
            return
        relationship_options = self._load_relationship_options(
            relationship_track)
        if not relationship_options:
            self.log.format_with_message('No relationship options found.',
                                         sim=sim_info_a,
                                         chosen_sim=sim_info_b)
            on_completed(False)
            return

        def _on_bit_chosen(_: Any, chosen_option: S4CMRelationshipOption):
            if _ is None or chosen_option is None:
                on_completed(False)
                return
            self.log.format_with_message(
                'Chose relationship bit.',
                sim=sim_info_a,
                chosen_sim=sim_info_b,
                chosen_option=chosen_option,
                required_minimum=chosen_option.required_minimum)
            CommonRelationshipUtils.add_relationship_bit(
                sim_info_a, sim_info_b, CommonRelationshipBitId.HAS_MET)
            CommonRelationshipUtils.set_relationship_level_of_sims(
                sim_info_a, sim_info_b, relationship_track_id,
                chosen_option.required_minimum)
            on_completed(True)

        option_dialog = CommonChooseButtonOptionDialog(
            ModInfo.get_identity(),
            S4CMSimControlMenuStringId.CHOOSE_LEVEL,
            0,
            include_previous_button=True,
            on_previous=lambda: on_completed(False),
            on_close=lambda: on_completed(False))
        for relationship_option in relationship_options:
            option_dialog.add_option(
                CommonDialogButtonOption(relationship_option,
                                         relationship_option,
                                         CommonDialogResponseOptionContext(
                                             relationship_option.display_name),
                                         on_chosen=_on_bit_chosen))

        if not option_dialog.has_options():
            on_completed(False)
            return

        option_dialog.show(sim_info=sim_info_a)