View Single Post in: OK/Cancel and User Input via Python

Deceased
Original Poster
#7 Old 22nd Apr 2015 at 7:23 AM
Default And Now the SimPicker....
Solved the last issue I was having to generate a sim picker from script. Here's the basic code....
Code:
import sims4.commands
import sims.sim_info
import services
from sims4.localization import LocalizationHelperTuning
from ui.ui_dialog_picker import SimPickerRow, UiSimPicker
import sims4.collections

@sims4.commands.Command('pickertest', command_type=sims4.commands.CommandType.Live)
def sim_picker_dialog_test(_connection=None):
    output = sims4.commands.CheatOutput(_connection)
    client = services.client_manager().get_first_client()

    def get_inputs_callback(dialog):
        if not dialog.accepted:
            output("Dialog was closed/cancelled")
            return
        output("Dialog was accepted")
        for sim_id in dialog.get_result_tags():
            output("id={}".format(sim_id))

    localized_title = lambda **_: LocalizationHelperTuning.get_raw_text("Sim Picker Dialog Test")
    localized_text = lambda **_: LocalizationHelperTuning.get_raw_text("Select up to five sims and press OK or close dialog....")
    max_selectable_immutable = sims4.collections.make_immutable_slots_class(set(['multi_select', 'number_selectable', 'max_type']))
    max_selectable = max_selectable_immutable({'multi_select':False, 'number_selectable':5, 'max_type':1})
    dialog = UiSimPicker.TunableFactory().default(client.active_sim, text=localized_text, title=localized_title, max_selectable=max_selectable, min_selectable=1, should_show_names=True, hide_row_description=False)
    for sim_info in services.sim_info_manager().get_all():
        # Set second arg below to True to have that sim preselected/highlighted....
        dialog.add_row(SimPickerRow(sim_info.sim_id, False, tag=sim_info.sim_id))
    dialog.add_listener(get_inputs_callback)
    dialog.show_dialog(icon_override=(None, sim_info))

Should be simple enough to follow if you've understood the code from the previous examples. This will generate a sim picker with all sims, allow up to five to be selected, and output the sim ids of the selected sims to the cheat console. The localized_title and text should be able to support internationalization using the same methods I used for the dialogs in SimLotto.

As always... enjoy and hope this helps out other scripters!

ETA: You'll probably want to use a different sim for the icon_override than just the last sim that got added to the picker like I did - bit of a shortcut for testing