def _setup_dialog(self, option_dialog: CommonChooseButtonOptionDialog,
                      on_close: Callable[[],
                                         None], on_previous: Callable[[],
                                                                      None],
                      reopen: Callable[[], None], **__) -> bool:
        def _operation_run(operation: S4CMSingleSimOperation):
            def _on_operation_complete(_: bool) -> None:
                reopen()

            operation.run(self._sim_info, on_completed=_on_operation_complete)

        if S4CMSetPersonalityTraitsSimOp().can_run_with_sim(self._sim_info):
            option_dialog.add_option(
                CommonDialogButtonOption(
                    'AddTraits',
                    None,
                    CommonDialogResponseOptionContext(
                        S4CMSimControlMenuStringId.SET_PERSONALITY_TRAITS),
                    on_chosen=lambda *_, **__: _operation_run(
                        S4CMSetPersonalityTraitsSimOp())))

        if S4CMRemoveTraitsSimOp().can_run_with_sim(self._sim_info):
            option_dialog.add_option(
                CommonDialogButtonOption(
                    'RemoveTraits',
                    None,
                    CommonDialogResponseOptionContext(
                        S4CMSimControlMenuStringId.REMOVE_TRAITS),
                    on_chosen=lambda *_, **__: _operation_run(
                        S4CMRemoveTraitsSimOp())))
        return True
 def _setup_dialog(self, option_dialog: CommonChooseButtonOptionDialog,
                   on_close: Callable[[],
                                      None], on_previous: Callable[[],
                                                                   None],
                   reopen: Callable[[], None], **__) -> bool:
     option_dialog.add_option(
         CommonDialogButtonOption(
             'SetAge',
             None,
             CommonDialogResponseOptionContext(
                 S4CMSimControlMenuStringId.SET_AGE),
             on_chosen=lambda *_, **__: S4CMSetAgeDialog(
                 self._sim_info, on_previous=reopen).open()))
     return True
예제 #3
0
    def run(
        self,
        sim_info_a: SimInfo,
        sim_info_b: SimInfo,
        on_completed: Callable[[bool],
                               None] = CommonFunctionUtils.noop) -> bool:
        if not self._should_update_family_tree:
            self._add_relationship_bits(sim_info_a, sim_info_b)
            on_completed(True)
            return True

        def _on_yes_selected(_: str, __: Any):
            def _on_family_tree_updated(result: bool):
                if result:
                    self._add_relationship_bits(sim_info_a, sim_info_b)
                on_completed(result)

            self._update_family_tree(sim_info_a,
                                     sim_info_b,
                                     on_completed=_on_family_tree_updated)

        def _on_no_selected(_: str, __: Any):
            self._add_relationship_bits(sim_info_a, sim_info_b)
            on_completed(True)

        option_dialog = CommonChooseButtonOptionDialog(
            self.mod_identity,
            S4CMSimControlMenuStringId.UPDATE_FAMILY_TREE_TITLE,
            S4CMSimControlMenuStringId.UPDATE_FAMILY_TREE_DESCRIPTION,
            previous_button_text=S4CMStringId.CANCEL,
            include_previous_button=True,
            on_previous=lambda: on_completed(False),
            on_close=lambda: on_completed(False))

        option_dialog.add_option(
            CommonDialogButtonOption('Yes',
                                     'YES',
                                     CommonDialogResponseOptionContext(
                                         S4CMStringId.YES),
                                     on_chosen=_on_yes_selected))

        option_dialog.add_option(
            CommonDialogButtonOption('No',
                                     'NO',
                                     CommonDialogResponseOptionContext(
                                         S4CMStringId.NO),
                                     on_chosen=_on_no_selected))

        option_dialog.show()
        return True
    def _setup_dialog(self, option_dialog: CommonChooseButtonOptionDialog,
                      on_close: Callable[[],
                                         None], on_previous: Callable[[],
                                                                      None],
                      reopen: Callable[[], None], **__) -> bool:
        def _operation_run(operation: S4CMSingleSimOperation):
            def _on_operation_complete(_: bool) -> None:
                reopen()

            operation.run(self._sim_info, on_completed=_on_operation_complete)

        is_pregnant = CommonSimPregnancyUtils.is_pregnant(self._sim_info)

        can_produce_pregnancy = S4CMSimPregnancyUtils.can_create_pregnancy(
            self._sim_info)

        create_pregnancy_disabled_text = None
        if is_pregnant:
            create_pregnancy_disabled_text = S4CMSimControlMenuStringId.SIM_IS_ALREADY_PREGNANT
        elif not can_produce_pregnancy:
            create_pregnancy_disabled_text = S4CMSimControlMenuStringId.SIM_IS_UNABLE_TO_CREATE_PREGNANCY
        elif not CommonHouseholdUtils.has_free_household_slots(self._sim_info):
            create_pregnancy_disabled_text = S4CMSimControlMenuStringId.TOO_MANY_SIMS_IN_HOUSEHOLD_ALREADY

        option_dialog.add_option(
            CommonDialogButtonOption(
                'CreatePregnancy',
                None,
                CommonDialogResponseOptionContext(
                    S4CMSimControlMenuStringId.CREATE_PREGNANCY,
                    disabled_text_identifier=create_pregnancy_disabled_text,
                    disabled_text_tokens=(self._sim_info, )),
                on_chosen=lambda *_, **__: _operation_run(
                    S4CMCreatePregnancyOp())))

        option_dialog.add_option(
            CommonDialogButtonOption(
                'InduceLabor',
                None,
                CommonDialogResponseOptionContext(
                    S4CMSimControlMenuStringId.INDUCE_LABOR,
                    disabled_text_identifier=S4CMSimControlMenuStringId.
                    SIM_IS_NOT_PREGNANT if not is_pregnant else None,
                    disabled_text_tokens=(self._sim_info, )),
                on_chosen=lambda *_, **__: _operation_run(S4CMInduceLaborOp()))
        )

        option_dialog.add_option(
            CommonDialogButtonOption(
                'ClearPregnancy',
                None,
                CommonDialogResponseOptionContext(
                    S4CMSimControlMenuStringId.CLEAR_PREGNANCY,
                    disabled_text_identifier=S4CMSimControlMenuStringId.
                    SIM_IS_NOT_PREGNANT if not is_pregnant else None,
                    disabled_text_tokens=(self._sim_info, )),
                on_chosen=lambda *_, **__: _operation_run(S4CMClearPregnancyOp(
                ))))
        return True
 def _setup_dialog(self, option_dialog: CommonChooseButtonOptionDialog,
                   on_close: Callable[[],
                                      None], on_previous: Callable[[],
                                                                   None],
                   reopen: Callable[[], None], **__) -> bool:
     option_dialog.add_option(
         CommonDialogButtonOption(
             'ModifySimData',
             None,
             CommonDialogResponseOptionContext(
                 S4CMStringId.MODIFY_SIM_DATA),
             on_chosen=lambda *_, **__: S4CMModifySimDataDialog(
                 self._sim_info, on_previous=reopen).open()))
     option_dialog.add_option(
         CommonDialogButtonOption(
             'ModifyGameWorldData',
             None,
             CommonDialogResponseOptionContext(
                 S4CMStringId.MODIFY_GAME_WORLD_DATA),
             on_chosen=lambda *_, **__: S4CMModifyGameWorldDataDialog(
                 self._sim_info, on_previous=reopen).open()))
     return True
    def _setup_dialog(self, option_dialog: CommonChooseButtonOptionDialog,
                      on_close: Callable[[],
                                         None], on_previous: Callable[[],
                                                                      None],
                      reopen: Callable[[], None], **__) -> bool:
        def _operation_run(operation: S4CMSingleSimOperation):
            def _on_operation_complete(_: bool) -> None:
                reopen()

            operation.run(self._sim_info, on_completed=_on_operation_complete)

        if S4CMSetSkillLevelsSimOp().can_run_with_sim(self._sim_info):
            option_dialog.add_option(
                CommonDialogButtonOption(
                    'SetSkillLevels',
                    None,
                    CommonDialogResponseOptionContext(
                        S4CMSimModifySkillsStringId.SET_SKILL_LEVELS),
                    on_chosen=lambda *_, **__: _operation_run(
                        S4CMSetSkillLevelsSimOp())))

            option_dialog.add_option(
                CommonDialogButtonOption(
                    'MaxAllSkills',
                    None,
                    CommonDialogResponseOptionContext(
                        S4CMSimModifySkillsStringId.MAX_ALL_SKILLS),
                    on_chosen=lambda *_, **__: _operation_run(
                        S4CMMaxAllSkillsSimOp())))

            option_dialog.add_option(
                CommonDialogButtonOption(
                    'RandomizeAllSkills',
                    None,
                    CommonDialogResponseOptionContext(
                        S4CMSimModifySkillsStringId.
                        RANDOMIZE_SKILL_LEVELS_TITLE),
                    on_chosen=lambda *_, **__: _operation_run(
                        S4CMRandomizeAllSkillsSimOp())))

            option_dialog.add_option(
                CommonDialogButtonOption(
                    'RemoveAllSkills',
                    None,
                    CommonDialogResponseOptionContext(
                        S4CMSimModifySkillsStringId.REMOVE_ALL_SKILLS),
                    on_chosen=lambda *_, **__: _operation_run(
                        S4CMRemoveAllSkillsSimOp())))
        return True
 def _setup_dialog(self, option_dialog: CommonChooseButtonOptionDialog,
                   on_close: Callable[[],
                                      None], on_previous: Callable[[],
                                                                   None],
                   reopen: Callable[[], None], **__) -> bool:
     option_dialog.add_option(
         CommonDialogButtonOption(
             'SetClockSpeed',
             None,
             CommonDialogResponseOptionContext(
                 S4CMGameWorldControlMenuStringId.SET_CLOCK_SPEED, ),
             on_chosen=lambda *_, **__: None if S4CMSetClockSpeedOp().run(
                 on_completed=lambda *_, **__: reopen()) else None))
     option_dialog.add_option(
         CommonDialogButtonOption(
             'SetClockSpeedScale',
             None,
             CommonDialogResponseOptionContext(
                 S4CMGameWorldControlMenuStringId.SET_CLOCK_SPEED_SCALE, ),
             on_chosen=lambda *_, **__: None
             if S4CMSetClockSpeedScaleMultiplierOp().run(
                 on_completed=lambda *_, **__: reopen()) else None))
     return True
    def _setup_dialog(
        self,
        option_dialog: CommonChooseButtonOptionDialog,
        on_close: Callable[[], None],
        on_previous: Callable[[], None],
        reopen: Callable[[], None],
        **__
    ) -> bool:
        def _operation_run(operation: S4CMSingleSimOperation):
            def _on_operation_complete(_: bool) -> None:
                reopen()

            operation.run(self._sim_info, on_completed=_on_operation_complete)

        option_dialog.add_option(
            CommonDialogButtonOption(
                'AddSimoleons',
                None,
                CommonDialogResponseOptionContext(
                    S4CMSimControlMenuStringId.ADD_SIMOLEONS
                ),
                on_chosen=lambda *_, **__: _operation_run(S4CMAddSimoleonsOp())
            )
        )

        option_dialog.add_option(
            CommonDialogButtonOption(
                'RemoveSimoleons',
                None,
                CommonDialogResponseOptionContext(
                    S4CMSimControlMenuStringId.REMOVE_SIMOLEONS
                ),
                on_chosen=lambda *_, **__: _operation_run(S4CMRemoveSimoleonsOp())
            )
        )
        return True
    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
        )
예제 #10
0
    def _update_family_tree(
        self,
        step_sibling_sim_info_a: SimInfo,
        step_sibling_sim_info_b: SimInfo,
        on_completed: Callable[[bool],
                               None] = CommonFunctionUtils.noop) -> bool:
        def _on_selected(_: str, operation: Any):
            if operation is None:
                on_completed(False)
                return
            operation(step_sibling_sim_info_a,
                      step_sibling_sim_info_b,
                      on_completed=on_completed)

        option_dialog = CommonChooseButtonOptionDialog(
            self.mod_identity,
            S4CMSimControlMenuStringId.WHICH_PARENT_IS_SHARED,
            S4CMSimControlMenuStringId.WHICH_PARENT_IS_SHARED_DESCRIPTION,
            description_tokens=(step_sibling_sim_info_b,
                                step_sibling_sim_info_a),
            include_previous_button=True)

        option_dialog.add_option(
            CommonDialogButtonOption('Mother',
                                     self._share_mother,
                                     CommonDialogResponseOptionContext(
                                         S4CMSimControlMenuStringId.MOTHER),
                                     on_chosen=_on_selected))

        option_dialog.add_option(
            CommonDialogButtonOption('Father',
                                     self._share_father,
                                     CommonDialogResponseOptionContext(
                                         S4CMSimControlMenuStringId.FATHER),
                                     on_chosen=_on_selected))

        option_dialog.show()
        return True
예제 #11
0
    def run(
        self,
        sim_info_a: SimInfo,
        new_parent_sim_info: SimInfo,
        on_completed: Callable[[bool],
                               None] = CommonFunctionUtils.noop) -> bool:
        def _on_selected(_: str, operation: Any):
            if operation is None:
                on_completed(False)
                return
            operation(sim_info_a,
                      new_parent_sim_info,
                      on_completed=on_completed)

        option_dialog = CommonChooseButtonOptionDialog(
            self.mod_identity,
            S4CMSimControlMenuStringId.CHOOSE_FAMILY_RELATION,
            S4CMSimControlMenuStringId.CHOOSE_WHAT_SIM_WILL_BECOME_TO_SIM,
            description_tokens=(new_parent_sim_info, sim_info_a),
            include_previous_button=True)

        option_dialog.add_option(
            CommonDialogButtonOption('Mother',
                                     self._as_mother,
                                     CommonDialogResponseOptionContext(
                                         S4CMSimControlMenuStringId.MOTHER),
                                     on_chosen=_on_selected))

        option_dialog.add_option(
            CommonDialogButtonOption('Father',
                                     self._as_father,
                                     CommonDialogResponseOptionContext(
                                         S4CMSimControlMenuStringId.FATHER),
                                     on_chosen=_on_selected))

        option_dialog.show()
        return True
    def _setup_dialog(self, option_dialog: CommonChooseButtonOptionDialog,
                      on_close: Callable[[],
                                         None], on_previous: Callable[[],
                                                                      None],
                      reopen: Callable[[], None], **__) -> bool:
        option_dialog.add_option(
            CommonDialogButtonOption(
                'ModifyAge',
                None,
                CommonDialogResponseOptionContext(
                    S4CMSimControlMenuStringId.MODIFY_AGE, ),
                on_chosen=lambda *_, **__: S4CMModifyAgeDialog(
                    self._sim_info, on_previous=reopen).open()))

        option_dialog.add_option(
            CommonDialogButtonOption(
                'ModifyTraits',
                None,
                CommonDialogResponseOptionContext(
                    S4CMSimControlMenuStringId.MODIFY_TRAITS, ),
                on_chosen=lambda *_, **__: S4CMModifyTraitsDialog(
                    self._sim_info, on_previous=reopen).open()))

        option_dialog.add_option(
            CommonDialogButtonOption(
                'ModifyBuffs',
                None,
                CommonDialogResponseOptionContext(
                    S4CMSimControlMenuStringId.MODIFY_BUFFS, ),
                on_chosen=lambda *_, **__: S4CMModifyBuffsDialog(
                    self._sim_info, on_previous=reopen).open()))

        option_dialog.add_option(
            CommonDialogButtonOption(
                'ModifyCurrency',
                None,
                CommonDialogResponseOptionContext(
                    S4CMSimControlMenuStringId.MODIFY_CURRENCY, ),
                on_chosen=lambda *_, **__: S4CMModifyCurrencyDialog(
                    self._sim_info, on_previous=reopen).open()))

        option_dialog.add_option(
            CommonDialogButtonOption(
                'ModifyOccult',
                None,
                CommonDialogResponseOptionContext(
                    S4CMSimControlMenuStringId.MODIFY_OCCULT, ),
                on_chosen=lambda *_, **__: S4CMModifyOccultDialog(
                    self._sim_info, on_previous=reopen).open()))

        option_dialog.add_option(
            CommonDialogButtonOption(
                'ModifyRelationships',
                None,
                CommonDialogResponseOptionContext(
                    S4CMSimControlMenuStringId.MODIFY_RELATIONSHIPS, ),
                on_chosen=lambda *_, **__: S4CMModifyRelationshipsDialog(
                    self._sim_info, on_previous=reopen).open()))

        option_dialog.add_option(
            CommonDialogButtonOption(
                'ModifySkills',
                None,
                CommonDialogResponseOptionContext(
                    S4CMSimModifySkillsStringId.MODIFY_SKILLS, ),
                on_chosen=lambda *_, **__: S4CMModifySkillsDialog(
                    self._sim_info, on_previous=reopen).open()))

        if S4CMSettingUtils.is_sim_allowed_to_perform_adult_sim_operations(
                self._sim_info):
            option_dialog.add_option(
                CommonDialogButtonOption(
                    'Pregnancy',
                    None,
                    CommonDialogResponseOptionContext(
                        S4CMSimControlMenuStringId.PREGNANCY, ),
                    on_chosen=lambda *_, **__: S4CMPregnancyDialog(
                        self._sim_info, on_previous=reopen).open()))
        return True
    def _setup_dialog(
        self,
        option_dialog: CommonChooseButtonOptionDialog,
        on_close: Callable[[], None],
        on_previous: Callable[[], None],
        reopen: Callable[[], None],
        **__
    ) -> bool:
        def _operation_run(operation: S4CMSingleSimOperation):
            def _on_operation_complete(_: bool) -> None:
                reopen()

            operation.run(self._sim_info, on_completed=_on_operation_complete)

        option_dialog.add_option(
            CommonDialogButtonOption(
                'RemoveAllOccults',
                CommonOccultType.NON_OCCULT,
                CommonDialogResponseOptionContext(
                    S4CMSimControlMenuStringId.REMOVE_ALL_OCCULTS
                ),
                on_chosen=lambda *_, **__: _operation_run(S4CMRemoveAllOccultsOp())
            )
        )

        option_dialog.add_option(
            CommonDialogButtonOption(
                'AlienAdd',
                CommonOccultType.ALIEN,
                CommonDialogResponseOptionContext(
                    S4CMSimControlMenuStringId.BECOME_ALIEN
                ),
                on_chosen=lambda *_, **__: _operation_run(S4CMAlienAddOp())
            )
        )

        option_dialog.add_option(
            CommonDialogButtonOption(
                'MermaidAdd',
                CommonOccultType.MERMAID,
                CommonDialogResponseOptionContext(
                    S4CMSimControlMenuStringId.BECOME_MERMAID
                ),
                on_chosen=lambda *_, **__: _operation_run(S4CMMermaidAddOp())
            )
        )

        option_dialog.add_option(
            CommonDialogButtonOption(
                'PlantSimAdd',
                CommonOccultType.PLANT_SIM,
                CommonDialogResponseOptionContext(
                    S4CMSimControlMenuStringId.BECOME_PLANT_SIM
                ),
                on_chosen=lambda *_, **__: _operation_run(S4CMPlantSimAddOp())
            )
        )

        option_dialog.add_option(
            CommonDialogButtonOption(
                'ServoAdd',
                None,
                CommonDialogResponseOptionContext(
                    S4CMSimControlMenuStringId.BECOME_SERVO
                ),
                on_chosen=lambda *_, **__: _operation_run(S4CMServoAddOp())
            )
        )

        option_dialog.add_option(
            CommonDialogButtonOption(
                'SkeletonAdd',
                CommonOccultType.SKELETON,
                CommonDialogResponseOptionContext(
                    S4CMSimControlMenuStringId.BECOME_SKELETON
                ),
                on_chosen=lambda *_, **__: _operation_run(S4CMSkeletonAddOp())
            )
        )

        option_dialog.add_option(
            CommonDialogButtonOption(
                'VampireAdd',
                CommonOccultType.VAMPIRE,
                CommonDialogResponseOptionContext(
                    S4CMSimControlMenuStringId.BECOME_VAMPIRE
                ),
                on_chosen=lambda *_, **__: _operation_run(S4CMVampireAddOp())
            )
        )

        option_dialog.add_option(
            CommonDialogButtonOption(
                'WitchAdd',
                CommonOccultType.WITCH,
                CommonDialogResponseOptionContext(
                    S4CMSimControlMenuStringId.BECOME_WITCH
                ),
                on_chosen=lambda *_, **__: _operation_run(S4CMWitchAddOp())
            )
        )
        return True
예제 #14
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)
예제 #15
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
    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)
예제 #17
0
    def _setup_dialog(
        self,
        option_dialog: CommonChooseButtonOptionDialog,
        on_close: Callable[[], None],
        on_previous: Callable[[], None],
        reopen: Callable[[], None],
        target_sim_info: SimInfo=None,
        **__
    ) -> bool:
        def _operation_run(operation: S4CMSingleSimOperation):
            def _on_operation_complete(_: bool) -> None:
                reopen()

            if target_sim_info is not None:
                operation.run_with_sims(self._sim_info, target_sim_info, on_completed=_on_operation_complete)
            else:
                operation.run(self._sim_info, on_completed=_on_operation_complete)

        if target_sim_info is None:
            active_sim_info = CommonSimUtils.get_active_sim_info()
            if active_sim_info is not None and self._sim_info is not active_sim_info:
                option_dialog.add_option(
                    CommonDialogButtonOption(
                        'WithSelf',
                        None,
                        CommonDialogResponseOptionContext(
                            S4CMSimControlMenuStringId.SET_RELATIONSHIPS_WITH_SIM,
                            text_tokens=(active_sim_info, )
                        ),
                        on_chosen=lambda *_, **__: None if self.open(target_sim_info=active_sim_info) else None
                    )
                )

        if (target_sim_info is None and S4CMSetFriendshipLevelOp().can_run_with_sim(self._sim_info)) or S4CMSetFriendshipLevelOp().can_run_with_sims(self._sim_info, target_sim_info):
            option_dialog.add_option(
                CommonDialogButtonOption(
                    'FriendshipLevel',
                    None,
                    CommonDialogResponseOptionContext(
                        S4CMSimControlMenuStringId.SET_FRIENDSHIP_LEVEL
                    ),
                    on_chosen=lambda *_, **__: _operation_run(S4CMSetFriendshipLevelOp())
                )
            )

        if (target_sim_info is None and S4CMSetRomanceLevelOp().can_run_with_sim(self._sim_info)) or S4CMSetRomanceLevelOp().can_run_with_sims(self._sim_info, target_sim_info):
            if S4CMSettingUtils.is_allowed_romantic_relationship(self._sim_info):
                option_dialog.add_option(
                    CommonDialogButtonOption(
                        'RomanceLevel',
                        None,
                        CommonDialogResponseOptionContext(
                            S4CMSimControlMenuStringId.SET_ROMANCE_LEVEL
                        ),
                        on_chosen=lambda *_, **__: _operation_run(S4CMSetRomanceLevelOp())
                    )
                )

        if (target_sim_info is None and S4CMAddHasMetSimsOp().can_run_with_sim(self._sim_info)) or S4CMAddHasMetSimsOp().can_run_with_sims(self._sim_info, target_sim_info):
            option_dialog.add_option(
                CommonDialogButtonOption(
                    'AddHasMet',
                    None,
                    CommonDialogResponseOptionContext(
                        S4CMSimControlMenuStringId.ADD_HAS_MET,
                    ),
                    on_chosen=lambda *_, **__: _operation_run(S4CMAddHasMetSimsOp())
                )
            )

        if (target_sim_info is None and S4CMRemoveHasMetSimsOp().can_run_with_sim(self._sim_info)) or S4CMRemoveHasMetSimsOp().can_run_with_sims(self._sim_info, target_sim_info):
            option_dialog.add_option(
                CommonDialogButtonOption(
                    'RemoveHasMet',
                    None,
                    CommonDialogResponseOptionContext(
                        S4CMSimControlMenuStringId.REMOVE_HAS_MET,
                    ),
                    on_chosen=lambda *_, **__: _operation_run(S4CMRemoveHasMetSimsOp())
                )
            )

        if (target_sim_info is None and S4CMSetFamilyRelationsBitOp().can_run_with_sim(self._sim_info)) or S4CMSetFamilyRelationsBitOp().can_run_with_sims(self._sim_info, target_sim_info):
            option_dialog.add_option(
                CommonDialogButtonOption(
                    'FamilyRelations',
                    None,
                    CommonDialogResponseOptionContext(
                        S4CMSimControlMenuStringId.SET_FAMILY_RELATIONS
                    ),
                    on_chosen=lambda *_, **__: _operation_run(S4CMSetFamilyRelationsBitOp())
                )
            )

        if (target_sim_info is None and S4CMForgetSimsOp().can_run_with_sim(self._sim_info)) or S4CMForgetSimsOp().can_run_with_sims(self._sim_info, target_sim_info):
            option_dialog.add_option(
                CommonDialogButtonOption(
                    'ForgetSims',
                    None,
                    CommonDialogResponseOptionContext(
                        S4CMSimControlMenuStringId.FORGET_SIMS,
                    ),
                    on_chosen=lambda *_, **__: _operation_run(S4CMForgetSimsOp())
                )
            )
        return True
    def _setup_dialog(self, option_dialog: CommonChooseButtonOptionDialog,
                      on_close: Callable[[],
                                         None], on_previous: Callable[[],
                                                                      None],
                      reopen: Callable[[], None], **__) -> bool:
        def _operation_run(operation: S4CMSingleSimOperation):
            def _on_operation_complete(_: bool) -> None:
                reopen()

            operation.run(self._sim_info, on_completed=_on_operation_complete)

        if CommonAgeUtils.is_age_available_for_sim(self._sim_info,
                                                   CommonAge.TODDLER):
            option_dialog.add_option(
                CommonDialogButtonOption(
                    'Toddler',
                    CommonAge.TODDLER,
                    CommonDialogResponseOptionContext(CommonStringId.TODDLER),
                    on_chosen=lambda *_, **__: _operation_run(
                        S4CMSetAgeToddlerOp())))

        if CommonAgeUtils.is_age_available_for_sim(self._sim_info,
                                                   CommonAge.CHILD):
            option_dialog.add_option(
                CommonDialogButtonOption(
                    'Child',
                    CommonAge.CHILD,
                    CommonDialogResponseOptionContext(CommonStringId.CHILD),
                    on_chosen=lambda *_, **__: _operation_run(
                        S4CMSetAgeChildOp())))

        if CommonAgeUtils.is_age_available_for_sim(self._sim_info,
                                                   CommonAge.TEEN):
            option_dialog.add_option(
                CommonDialogButtonOption(
                    'Teen',
                    CommonAge.TEEN,
                    CommonDialogResponseOptionContext(CommonStringId.TEEN),
                    on_chosen=lambda *_, **__: _operation_run(S4CMSetAgeTeenOp(
                    ))))

        if CommonAgeUtils.is_age_available_for_sim(self._sim_info,
                                                   CommonAge.YOUNGADULT):
            option_dialog.add_option(
                CommonDialogButtonOption(
                    'YoungAdult',
                    CommonAge.YOUNGADULT,
                    CommonDialogResponseOptionContext(
                        CommonStringId.YOUNG_ADULT),
                    on_chosen=lambda *_, **__: _operation_run(
                        S4CMSetAgeYoungAdultOp())))

        if CommonAgeUtils.is_age_available_for_sim(self._sim_info,
                                                   CommonAge.ADULT):
            option_dialog.add_option(
                CommonDialogButtonOption(
                    'Adult',
                    CommonAge.ADULT,
                    CommonDialogResponseOptionContext(CommonStringId.ADULT),
                    on_chosen=lambda *_, **__: _operation_run(
                        S4CMSetAgeAdultOp())))

        if CommonAgeUtils.is_age_available_for_sim(self._sim_info,
                                                   CommonAge.ELDER):
            option_dialog.add_option(
                CommonDialogButtonOption(
                    'Elder',
                    CommonAge.ELDER,
                    CommonDialogResponseOptionContext(CommonStringId.ELDER),
                    on_chosen=lambda *_, **__: _operation_run(
                        S4CMSetAgeElderOp())))
        return True