README.md: Add Get started section

This commit is contained in:
2023-04-05 10:07:53 +02:00
committed by GitHub
parent d6ae6772d5
commit c2b952ed0d

View File

@@ -8,6 +8,97 @@ At the moment it's far away from being complete or even good. Right now it as so
Install the latest version of `Pilz.Dalamud` via NuGet Package Manager or NuGet Console:\ Install the latest version of `Pilz.Dalamud` via NuGet Package Manager or NuGet Console:\
https://www.nuget.org/packages/Pilz.Dalamud https://www.nuget.org/packages/Pilz.Dalamud
## Get started
### Initialize Plugin Services
To be able to use most features of that lib you must initialize the Plugin Services. The best time to do this is when you initialize your own Plugin Services at your IDalamudPlugin class constructor.
```cs
public Plugin(DalamudPluginInterface pluginInterface)
{
// Initialize our own Plugin Services if we use them
PluginServices.Initialize(pluginInterface);
// Initialize Plugin Services for `Pilz.Dalamud` because the lib uses them
Pilz.Dalamud.PluginServices.Initialize(pluginInterface);
}
```
### Hook into Nameplates
To edit the nameplate, you first need to hook and listen to the Game's updates. Also don't forget to unhook and dispose on unloading the plugins!
```cs
public class NameplateFeature : IDisposable
{
public NameplateManager NameplateManager { get; init; }
/// <summary>
/// Occurs when a player nameplate is updated by the game.
/// </summary>
public event PlayerNameplateUpdatedDelegate? PlayerNameplateUpdated;
public NameplateFeature()
{
NameplateManager = new();
NameplateManager.Hooks.AddonNamePlate_SetPlayerNameManaged += Hooks_AddonNamePlate_SetPlayerNameManaged;
}
public void Dispose()
{
NameplateManager.Hooks.AddonNamePlate_SetPlayerNameManaged -= Hooks_AddonNamePlate_SetPlayerNameManaged;
NameplateManager.Dispose();
}
private void Hooks_AddonNamePlate_SetPlayerNameManaged(Pilz.Dalamud.Nameplates.EventArgs.AddonNamePlate_SetPlayerNameManagedEventArgs eventArgs)
{
}
}
```
This is an example of editing the title to "Good Player" and change the color of the name:
```cs
private void Hooks_AddonNamePlate_SetPlayerNameManaged(Pilz.Dalamud.Nameplates.EventArgs.AddonNamePlate_SetPlayerNameManagedEventArgs eventArgs)
{
try
{
// Get the referenced player object for the nameplate object
PlayerCharacter? playerCharacter = NameplateManager.GetNameplateGameObject<PlayerCharacter>(eventArgs.SafeNameplateObject);
if (playerCharacter != null && playerCharacter.StatusFlags.HasFlag(StatusFlags.Friend))
{
const string TEXT_GOOD_PLAYER = "Good Player";
// Create a new change
var nameplateChanges = new NameplateChanges(eventArgs);
// Replace the title
var titleChange = nameplateChanges.GetChange(NameplateElements.Title, StringPosition.Replace);
titleChange.Payloads.Add(new TextPayload(TEXT_GOOD_PLAYER));
// Make the name italic
var nameChangeBefore = nameplateChanges.GetChange(NameplateElements.Name, StringPosition.Before);
nameChangeBefore.Payloads.Add(new EmphasisItalicPayload(true));
var nameChangeAfter = nameplateChanges.GetChange(NameplateElements.Name, StringPosition.After);
nameChangeAfter.Payloads.Add(new EmphasisItalicPayload(false));
// Forge the title to be always above the name (this we can edit directly)
eventArgs.IsTitleAboveName = true;
// Apply the string changes!
NameplateUpdateFactory.ApplyNameplateChanges(new NameplateChangesProps(nameplateChanges));
}
}
catch (Exception ex)
{
PluginLog.Error(ex, $"SetPlayerNameplateDetour");
}
}
```
## Contribute ## Contribute
- Freel free to PR changes or new features/libraries. - Freel free to PR changes or new features/libraries.