BenMakesGames.PlayPlayMini.UI 0.9.0

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package BenMakesGames.PlayPlayMini.UI --version 0.9.0                
NuGet\Install-Package BenMakesGames.PlayPlayMini.UI -Version 0.9.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BenMakesGames.PlayPlayMini.UI" Version="0.9.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BenMakesGames.PlayPlayMini.UI --version 0.9.0                
#r "nuget: BenMakesGames.PlayPlayMini.UI, 0.9.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install BenMakesGames.PlayPlayMini.UI as a Cake Addin
#addin nuget:?package=BenMakesGames.PlayPlayMini.UI&version=0.9.0

// Install BenMakesGames.PlayPlayMini.UI as a Cake Tool
#tool nuget:?package=BenMakesGames.PlayPlayMini.UI&version=0.9.0                

What Is It?

PlayPlayMini.UI is an extension for PlayPlayMini, adding a skinnable, object-oriented UI framework.

Documentation; How to Use PlayPlayMini.UI

This documentation assumes you already have a project that uses the PlayPlayMini framework. If not, check out the PlayPlayMini framework documentation to get started with it!

Load Required Resources

PlayPlayMini.UI requires a couple spritesheets, an image, and a font to be loaded. These are used for rendering buttons, checkbox, and the mouse cursor.

var gsmBuilder = new GameStateManagerBuilder()
	.AddPictures(new PictureMeta[] {
		...
		new PictureMeta("Cursor", "Graphics/Cursor"),
	})
	.AddSpriteSheets(new SpriteSheetMeta[] {
		...
		new SpriteSheetMeta("Button", "Graphics/Button", 4, 16),
		new SpriteSheetMeta("Checkbox", "Graphics/Checkbox", 10, 8),
	})
	.AddFonts(new FontMeta[] {
		new FontMeta("Font", "Graphics/Font", 6, 8),
	})
	...
;

At the time of this writing, PlayPlayMini.UI is not as flexible as it could be with the size of the UI elements it renders. For the best effect, use a font close to 8 pixels in height.

Configure UI Framework

In the PlayPlayMini, it is best-practice to have a Startup GameState which displays a loading message to the player while your deferred resources load.

One of the primary reasons for using PlayPlayMini.UI is for a mouse-driven UI. If you're not already doing so, you should configure the MouseManager in your Startup GameState. For example:

class Startup : IGameState
{
	private MouseManager Mouse { get; }

	public Startup(MouseManager mouse, ...)
	{
		Mouse = mouse;
		...

		Mouse.PictureName = "Cursor";
		Mouse.Hotspot = (3, 1);
	}
}

In a GameState, Request an Instance of UIService, and Configure It

Each instance of UIService that's requested is a new instance. A UIService instance contains UI components, such as buttons, and is responsible for handling mouse events that take place within it, including hovers & clicks, and notifying the appropriate component(s) of these events.

Example:

class PauseMenu: IGameState
{
	private UIService UI { get; }
	...

	public PauseMenu(UIService ui, ...)
	{
		UI = ui;
		...

		InitUI();
	}

	// it's not required to create a dedicated method for building the UI
	// (you'll only ever call it once), but it helps keep the constructor tidy.
	private void InitUI()
	{
		// Window is a UI component provided by PlayPlayMini.UI
		var window = new Window(
			UI,			// instance of the UIService
			20, 20,		// x, y coordinate to position the window
			150, 100,	// width, height of the window
			"Paused"	// title
		);

		var resume = new Button(UI, 4, 16, "Resume", ResumeGameHandler);
		var settings = new Button(UI, 4, 33, "Settings", SettingsHandler);
		var saveAndQuit = new Button(UI, 4, 50, "Save & Quit", SaveAndQuitHandler);

		// add the buttons to the window:
		window.AddUIElements(resume, settings, saveAndQuit);

		// and the window to the UI canvas:
		UI.Canvas.AddUIElements(window);
	}

	private void ResumeGameHandler(int x, int y)
	{
		// x, y coordinates that click took place, relative to the button's position
		// do something
	}

	private void SettingsHandler(int x, int y)
	{
		// do something
	}

	private void SaveAndQuitHandler(int x, int y)
	{
		// do something
	}

	public void ActiveUpdate(GameTime gameTime)
	{
		UI.ActiveUpdate(gameTime);
	}

	public void AlwaysDraw(GameTime gameTime)
	{
		UI.AlwaysDraw(gameTime);
	}

	public void ActiveDraw(GameTime gameTime)
	{
		UI.ActiveDraw(gameTime);
		// note: there is no need to manually update or draw the mouse cursor;
		// if you're using a UIService, it will handle the mouse for you.
	}
}
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
5.0.0 152 8/17/2024
4.7.1 114 5/28/2024
4.7.0 116 5/24/2024
4.5.0 135 3/23/2024
4.4.0 133 3/2/2024
4.3.0 124 2/25/2024
4.2.0 127 2/22/2024
4.1.0 132 2/12/2024
4.0.1 243 11/25/2023
4.0.0 119 11/25/2023
3.4.0 139 9/18/2023
3.3.0 144 9/17/2023
3.2.1 177 6/30/2023
3.2.0 207 4/16/2023
3.1.0 252 3/12/2023
3.0.3 237 3/11/2023
3.0.2 327 1/8/2023
3.0.1 292 1/7/2023
3.0.0 350 11/16/2022
2.0.1 402 10/9/2022
2.0.0 453 9/24/2022
1.0.0 494 9/18/2022
0.10.0 439 5/12/2022
0.9.0 456 1/15/2022