How to attach a Rollback function to a UI button?

All about user interface, be it customizing built-in UIs or adding new ones.
Post Reply
Daarg
Posts: 2
Joined: 27 Jun 2022 08:29

How to attach a Rollback function to a UI button?

Post by Daarg »

Hello!

How do I do this? I've used all of the functions like Auto, Skip, etc from the control panel attached to the dialogue (or any other) printer with my customized UI buttons. But now I need a button that makes a one-step-back rewind just as when you scroll a mouse wheel up. I know how to setup Input to call a Rollback form a keyboard or a joystick. But right now I need the function to start by pressing a UI button. Is there a way to do it?

idaot
support
Posts: 262
Joined: 01 Aug 2020 08:25

Re: How to attach a Rollback function to a UI button?

Post by idaot »

You can use RollbackAsync via IStateManager, however you need to specify a suitable playback spot to rollback to; eg, to rollback to the previous spot which allows player rollback (similar to what happens when activating rollback input), use:

Code: Select all

stateManager.RollbackAsync(s => s.PlayerRollbackAllowed);
Daarg
Posts: 2
Joined: 27 Jun 2022 08:29

Re: How to attach a Rollback function to a UI button?

Post by Daarg »

Thank you very much! I took one of the functions as an example and created the following function:

namespace Naninovel.UI
{
public class ButtonRollback : ScriptableButton
{
private IStateManager stateManager;

Code: Select all

    protected override void Awake ()
    {
        base.Awake();

        stateManager = Engine.GetService<IStateManager>();
    }

    protected override void OnButtonClick () => RollbackAsync();

    private async void RollbackAsync ()
    {
        UIComponent.interactable = false;
        await stateManager.RollbackAsync(s => s.PlayerRollbackAllowed);
        UIComponent.interactable = true;           
    }

}
}

Then I just dragged this function to my UI button. Works great!

Post Reply