Skip to content

Commit

Permalink
Replace SCH size checkbox with DrawRadioButtons.
Browse files Browse the repository at this point in the history
  • Loading branch information
Kurochi51 committed Mar 23, 2024
1 parent d2be882 commit b26805f
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 17 deletions.
3 changes: 1 addition & 2 deletions PetScale/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ public class Configuration : IPluginConfiguration
{
public int Version { get; set; } = 0;
public IList<PetStruct> PetData { get; set; } = [];
public bool FairyResize { get; set; } = false;

public int FairySize { get; set; } = 0;

public void Save(DalamudPluginInterface pi) => pi.SavePluginConfig(this);
}
22 changes: 14 additions & 8 deletions PetScale/PetScale.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,6 @@ private void InitSheet()
{
log.Debug("{pet} with scales {small} - {medium} - {large}", entry.Key, entry.Value.smallScale, entry.Value.mediumScale, entry.Value.largeScale);
}
foreach (var entry in ConfigWindow.petMap)
{
log.Debug("{pet} with {model}", entry.Key, entry.Value);
}
}

private void OnFrameworkUpdate(IFramework framework)
Expand Down Expand Up @@ -267,11 +263,21 @@ private unsafe void ParseDictionary(PlayerCharacter player)
#if DEBUG
DevWindow.Print(petName + ": " + pet->Character.CharacterData.ModelSkeletonId + " owned by " + characterName + " size " + pet->Character.GameObject.Scale);
#endif
if (config.FairyResize && Utilities.IsFairy(pet->Character.CharacterData.ModelCharaId))
if (config.FairySize is not 0 && Utilities.IsFairy(pet->Character.CharacterData.ModelCharaId) && utilities.PetVisible(pet))
{
utilities.SetScale(pet, 1.5f);
activePetDictionary[pair.Key] = (pair.Value.character, true);
continue;
switch (config.FairySize)
{
case 1 when character->GameObject.ObjectID == player.ObjectId:
case 2 when character->GameObject.ObjectID != player.ObjectId:
case 3:
{
utilities.SetScale(pet, 1.5f);
activePetDictionary[pair.Key] = (pair.Value.character, true);
continue;
}
default:
break;
}
}
if (ParseStruct(pet, characterName, petName, pet->Character.CharacterData.ModelCharaId, character->GameObject.ObjectID == player.ObjectId))
{
Expand Down
61 changes: 54 additions & 7 deletions PetScale/Windows/ConfigWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,17 @@ private void MiscTab()
{
return;
}
var fairyResize = config.FairyResize;
if (ImGui.Checkbox("Scale SCH fairy to match size of other fairies", ref fairyResize))
{
config.FairyResize = fairyResize;
config.Save(pluginInterface);
}
ImGuiComponents.HelpMarker("Seraph is excluded, as she's bigger by default");
DrawRadioButtons(
"Scale SCH fairy to the size of other in-game fairies",
() =>
{
ImGui.SameLine();
ImGuiComponents.HelpMarker("Seraph is excluded, as she's bigger by default");
},
config,
c => c.FairySize,
(c, value) => c.FairySize = value,
"Off", "Self", "Others", "All");
DrawBottomButtons(onlyClose: true);
}

Expand Down Expand Up @@ -509,6 +513,49 @@ private void CreateNotification(string content, string title, NotificationType t
notificationManager.AddNotification(notification);
}

/// <summary>
/// This function draws as many <see cref="ImGui.RadioButton(string, ref int, int)"/> as the number of <paramref name="buttons"/> passed,
/// with the option to add an extra element, like a <see cref="ImGuiComponents.HelpMarker(string)"/> after the intial <paramref name="label"/>.
/// </summary>
/// <param name="label">The text used for <see cref="ImGui.TextUnformatted(string)"/>.</param>
/// <param name="extra">Nullable action to be called immediately after <see cref="ImGui.TextUnformatted(string)"/>, and before the <see cref="ImGui.RadioButton(string, ref int, int)"/> are drawn.</param>
/// <param name="config">Instance of <see cref="Configuration"/> used for <paramref name="getOption"/> and <paramref name="setOption"/></param>
/// <param name="getOption">Function responsible for retrieving the desired <see cref="Configuration"/> property.</param>
/// <param name="setOption">Action responsible for setting the option from <paramref name="getOption"/> back to an instance of <see cref="Configuration"/>.</param>
/// <param name="buttons">The labels used for <see cref="ImGui.RadioButton(string, ref int, int)"/>.</param>
private void DrawRadioButtons(string label, Action? extra, in Configuration config, Func<Configuration, int> getOption, Action<Configuration, int> setOption, params string[] buttons)
{
ImGui.TextUnformatted(label);
extra?.Invoke();
var radioOption = getOption(config);
if (radioOption > buttons.Length)
{
radioOption = 0;
setOption(config, radioOption);
}
var space = ImGui.GetContentRegionAvail().X;
for (var i = 0; i < buttons.Length; i++)
{
if (ImGui.RadioButton(buttons[i], ref radioOption, i))
{
setOption(config, radioOption);
config.Save(pluginInterface);
}
space -= ImGui.CalcTextSize(buttons[i]).X + GetStyleWidth();
if (i + 1 < buttons.Length && space > ImGui.CalcTextSize(buttons[i + 1]).X + GetStyleWidth())
{
ImGui.SameLine();
}
else
{
space = ImGui.GetContentRegionAvail().X;
}
}
}

private static float GetStyleWidth()
=> (ImGui.GetStyle().FramePadding.X * 2) + (ImGui.GetStyle().ItemSpacing.X * 2) + ImGui.GetStyle().WindowPadding.X + ImGui.GetStyle().ItemInnerSpacing.X;

public void Dispose()
{
pluginInterface.UiBuilder.DefaultFontHandle.ImFontChanged -= QueueColumnWidthChange;
Expand Down

0 comments on commit b26805f

Please sign in to comment.