Example #1
0
def _KeyboardMouseOptionsPopulate(caller: unrealsdk.UObject,
                                  function: unrealsdk.UFunction,
                                  params: unrealsdk.FStruct) -> bool:
    """
    This function is called to create the kb/m settings menu. We use it to inject our own
     "MODDED KEYBINDS" menu.
    """
    # If we have no modded binds, disable the menu
    disabled = True
    for mod in ModObjects.Mods:
        if not mod.IsEnabled:
            continue
        for input in mod.Keybinds:
            if isinstance(input, Keybind) and input.IsHidden:
                continue
            disabled = False
            break
        if not disabled:
            break

    def AddListItem(caller: unrealsdk.UObject, function: unrealsdk.UFunction,
                    params: unrealsdk.FStruct) -> bool:
        """
        This function is called every time an item is added to *any* menu list - we obviously can't
         use a generic hook.
        Using it cause it simplifies the code to add our own entry.
        """
        if params.Caption != "$WillowMenu.MenuOptionDisplayNames.KeyBinds":
            return True

        # Want ours to display after the normal keybinds option
        unrealsdk.DoInjectedCallNext()
        caller.AddListItem(params.EventID, params.Caption, params.bDisabled,
                           params.bNew)

        caller.AddListItem(_MODDED_EVENT_ID, _MODDED_KEYBINDS_CAPTION,
                           disabled, False)
        return False

    unrealsdk.RunHook("WillowGame.WillowScrollingList.AddListItem",
                      "ModMenu.KeybindManager", AddListItem)

    unrealsdk.DoInjectedCallNext()
    caller.Populate(params.TheList)
    caller.AddDescription(_MODDED_EVENT_ID,
                          "$WillowMenu.MenuOptionDisplayNames.KeyBindsDesc")

    unrealsdk.RemoveHook("WillowGame.WillowScrollingList.AddListItem",
                         "ModMenu.KeybindManager")

    return False
Example #2
0
def _DataProviderOptionsBasePopulate(caller: unrealsdk.UObject,
                                     function: unrealsdk.UFunction,
                                     params: unrealsdk.FStruct) -> bool:
    """
    This function is called to fill in a few of a scrolling lists. Our custom data providers are of
     this type, so we use it to populate the lists ourselves.
    """
    if caller not in _modded_data_provider_stack:
        return True

    # If we're on the first level we need to setup the inital list
    if len(_nested_options_stack) == 0:
        all_options: List[Options.Base] = []
        for mod in MenuManager.GetOrderedModList():
            if not mod.IsEnabled:
                continue

            one_shown = False
            for option in mod.Options:
                if option.IsHidden:
                    continue
                if not one_shown:
                    one_shown = True
                    all_options.append(Options.Field(mod.Name))
                all_options.append(option)

        _nested_options_stack.append(
            Options.Nested(_MOD_OPTIONS_MENU_NAME, "", all_options))

    for idx, option in enumerate(_nested_options_stack[-1].Children):
        if option.IsHidden:
            continue

        if isinstance(option, Options.Spinner):
            spinner_idx: int
            if isinstance(option, Options.Boolean):
                spinner_idx = int(option.CurrentValue)
            else:
                spinner_idx = option.Choices.index(option.CurrentValue)

            params.TheList.AddSpinnerListItem(idx, option.Caption, False,
                                              spinner_idx, option.Choices)
        elif isinstance(option, Options.Slider):
            params.TheList.AddSliderListItem(
                idx,
                option.Caption,
                False,
                option.CurrentValue,
                option.MinValue,
                option.MaxValue,
                option.Increment,
            )
        elif isinstance(option, Options.Field):
            disabled = False
            new = False
            if isinstance(option, Options.Nested):
                disabled = not _is_anything_shown(option.Children)
                new = True
            params.TheList.AddListItem(idx, option.Caption, disabled, new)

        caller.AddDescription(idx, option.Description)

    return False