Dem1se

1,296 bytes added ,  06:49, 12 November 2021
Add Displaying you UI subsection to Create UIs
Line 86: Line 86:  
         // draw cursor at last
 
         // draw cursor at last
 
         drawMouse(b);
 
         drawMouse(b);
 +
    }
 +
}
 +
</syntaxhighlight>
 +
 +
=== Displaying your UI ===
 +
 +
<code>Game1.activeClickableMenu</code> stores the currently active UI, and has the value <code>null</code> when no UI is active. It also can be assigned to, to display any <code>IClickableMenu</code> UI that you want.
 +
 +
# Choose what event you want to activate your UI.
 +
## This can be a simple button press on most cases, or a specfic game state like a time of the day, etc.
 +
# Add the activation logic in your <code>Mod</code> subclass, where you bind to events and define handlers.
 +
 +
<syntaxhighlight lang="c#">
 +
public class ModEntry : Mod
 +
{
 +
    public override void Entry(IModHelper helper)
 +
    {
 +
        // bind the event handler
 +
        helper.Events.Input.ButtonPressed += OnButtonPressed;
 +
        ...
 +
    }
 +
 +
    void OnButtonPressed(object sender, ButtonPressedEventArgs ev)
 +
    {
 +
        // Don't process button presses if player hasn't loaded a save,
 +
        // is in another menu, or isn't free. I'd recommended you ignore these cases too.
 +
        if (!Context.IsWorldReady) return;
 +
        if (Game1.activeClickableMenu != null || (!Context.IsPlayerFree)) return;
 +
       
 +
        // Display our UI if user presses F10
 +
        if (ev.Button == SButton.F10)
 +
            Game1.activeClickableMenu = new MyUserInterface();
 +
        ...
 
     }
 
     }
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
21

edits