3 Commits
v0.3 ... v0.3.1

Author SHA1 Message Date
c2b952ed0d README.md: Add Get started section 2023-04-05 10:07:53 +02:00
d6ae6772d5 v0.3.1 2023-04-05 10:01:12 +02:00
442cdcb2ec slightly simpler usage for NameplateChanges and NameplateProps 2023-04-05 10:01:01 +02:00
4 changed files with 109 additions and 1 deletions

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Pilz.Dalamud.Nameplates.EventArgs;
using Pilz.Dalamud.Tools.Strings;
namespace Pilz.Dalamud.Nameplates.Tools
@@ -18,6 +19,13 @@ namespace Pilz.Dalamud.Nameplates.Tools
changes.Add(NameplateElements.FreeCompany, new());
}
public NameplateChanges(AddonNamePlate_SetPlayerNameManagedEventArgs eventArgs) : this()
{
GetProps(NameplateElements.Title).Destination = eventArgs.Title;
GetProps(NameplateElements.Name).Destination = eventArgs.Name;
GetProps(NameplateElements.FreeCompany).Destination = eventArgs.FreeCompany;
}
/// <summary>
/// Gets the properties with the changes of an element of your choice where you can add your payloads to a change and setup some options.
/// </summary>

View File

@@ -12,5 +12,14 @@ namespace Pilz.Dalamud.Nameplates.Tools
/// All the changes to the nameplate that should be made.
/// </summary>
public NameplateChanges Changes { get; set; }
public NameplateChangesProps()
{
}
public NameplateChangesProps(NameplateChanges changes) : this()
{
Changes = changes;
}
}
}

View File

@@ -23,7 +23,7 @@
<PackageProjectUrl>https://github.com/Pilzinsel64/Pilz.Dalamud</PackageProjectUrl>
<RepositoryUrl>https://github.com/Pilzinsel64/Pilz.Dalamud</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<Version>0.3.0</Version>
<Version>0.3.1</Version>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
</PropertyGroup>

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:\
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
- Freel free to PR changes or new features/libraries.