Skip to content

Commit

Permalink
[EchoStorySelection] Modernize Tweak (#637)
Browse files Browse the repository at this point in the history
* [`EchoStorySelection`] Modernize Tweak

* [`EchoStorySelection`] Use AutoConfig Attribute
  • Loading branch information
MidoriKami authored Oct 18, 2023
1 parent f775475 commit b87f37a
Showing 1 changed file with 29 additions and 75 deletions.
104 changes: 29 additions & 75 deletions Tweaks/Chat/EchoStorySelection.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using Dalamud.Game.Addon.Lifecycle.AddonArgTypes;
using Dalamud.Game.ClientState.Conditions;
using Dalamud.Game.Text;
Expand All @@ -14,49 +13,25 @@

namespace SimpleTweaksPlugin.Tweaks.Chat;

public unsafe class EchoStorySelection : ChatTweaks.SubTweak
{
public override string Name => "Echo Story Selection";
public override string Description => "When given multiple choices during quests, print the selected option to chat.";
protected override string Author => "MidoriKami";

[TweakName("Echo Story Selection")]
[TweakDescription("When given multiple choices during quests, print the selected option to chat.")]
[TweakAuthor("MidoriKami")]
[TweakReleaseVersion("1.8.3.2")]
[TweakAutoConfig]
public unsafe class EchoStorySelection : ChatTweaks.SubTweak {
private readonly List<string> options = new();

public class Config : TweakConfig
{
public class Config : TweakConfig {
[TweakConfigOption("Display Character Name")]
public bool DisplayCharacterName = false;
}

public Config TweakConfig { get; private set; } = null!;

public override bool UseAutoConfig => true;

public override void Setup()
{
if (Ready) return;
AddChangelogNewTweak("1.8.3.2");

base.Setup();
}

protected override void Enable()
{
TweakConfig = LoadConfig<Config>() ?? new Config();
base.Enable();
}

protected override void Disable()
{
SaveConfig(TweakConfig);
base.Disable();
}

[AddonPostSetup("CutSceneSelectString", "SelectString")]
private void OnAddonSetup(AddonSetupArgs obj)
{
switch (obj)
{
private void OnAddonSetup(AddonSetupArgs obj) {
switch (obj) {
case { AddonName: "CutSceneSelectString", Addon: not 0 }:
GetAddonStrings(((AddonCutSceneSelectString*) obj.Addon)->OptionList);
break;
Expand All @@ -68,10 +43,8 @@ private void OnAddonSetup(AddonSetupArgs obj)
}

[AddonFinalize("CutSceneSelectString", "SelectString")]
private void OnAddonFinalize(AddonFinalizeArgs obj)
{
switch (obj)
{
private void OnAddonFinalize(AddonFinalizeArgs obj) {
switch (obj) {
case { AddonName: "CutSceneSelectString", Addon: not 0 }:
PrintSelectedString(((AddonCutSceneSelectString*) obj.Addon)->OptionList);
break;
Expand All @@ -82,14 +55,12 @@ private void OnAddonFinalize(AddonFinalizeArgs obj)
}
}

private void GetAddonStrings(AtkComponentList* list)
{
private void GetAddonStrings(AtkComponentList* list) {
if(list is null) return;

options.Clear();

foreach (var index in Enumerable.Range(0, list->ListLength))
{
foreach (var index in Enumerable.Range(0, list->ListLength)) {
var listItemRenderer = list->ItemRendererList[index].AtkComponentListItemRenderer;
if (listItemRenderer is null) continue;

Expand All @@ -102,43 +73,26 @@ private void GetAddonStrings(AtkComponentList* list)
}
}

private void PrintSelectedString(AtkComponentList* list)
{
private void PrintSelectedString(AtkComponentList* list) {
if (list is null) return;

var selectedItem = list->SelectedItemIndex;
if (selectedItem >= 0 && selectedItem < options.Count)
{
var selectedString = options[selectedItem];

var message = new SeStringBuilder()
.AddText(selectedString)
.Build();

var playerName = Common.ReadString(PlayerState.Instance()->CharacterName);

var name = new SeStringBuilder()
.AddUiForeground(TweakConfig.DisplayCharacterName ? playerName : "Story Selection", 62)
.Build();
if (selectedItem < 0 || selectedItem >= options.Count) return;

var entry = new XivChatEntry
{
Type = XivChatType.NPCDialogue,
Message = message,
Name = name,
};

Service.Chat.Print(entry);
}
}

// Temp until ClientStructs update
[StructLayout(LayoutKind.Explicit, Size = 0x248)]
public struct AddonCutSceneSelectString
{
[FieldOffset(0x00)] public AtkUnitBase AtkUnitBase;
var message = new SeStringBuilder()
.AddText(options[selectedItem])
.Build();

[FieldOffset(0x230)] public AtkComponentList* OptionList;
[FieldOffset(0x238)] public AtkComponentTextNineGrid* TextLabel;
var playerName = Common.ReadString(PlayerState.Instance()->CharacterName);

var name = new SeStringBuilder()
.AddUiForeground(TweakConfig.DisplayCharacterName ? playerName : "Story Selection", 62)
.Build();

Service.Chat.Print(new XivChatEntry {
Type = XivChatType.NPCDialogue,
Message = message,
Name = name,
});
}
}

0 comments on commit b87f37a

Please sign in to comment.