Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
dit-zy committed Nov 21, 2023
1 parent 97f835c commit 0ebceba
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 10 deletions.
Binary file added ScoutHelper/Images/toggle-body-active.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ScoutHelper/Images/toggle-body-inactive.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ScoutHelper/Images/toggle-cap-active.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ScoutHelper/Images/toggle-cap-inactive.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion ScoutHelper/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Plugin() {
Conf.Initialize(PluginInterface);

HuntHelperManager = new HuntHelperManager();
BearManager = new BearManager(Utils.DataFilePath("Bear.json"));
BearManager = new BearManager(Utils.PluginFilePath(@"Data\Bear.json"));

ConfigWindow = new ConfigWindow();
MainWindow = new MainWindow(HuntHelperManager, BearManager);
Expand Down
16 changes: 16 additions & 0 deletions ScoutHelper/ScoutHelper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,22 @@
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Strings.Designer.cs</LastGenOutput>
</EmbeddedResource>
<None Remove="Images\toggle-body-active.png" />
<EmbeddedResource Include="Images\toggle-body-active.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<None Remove="Images\toggle-body-inactive.png" />
<EmbeddedResource Include="Images\toggle-body-inactive.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<None Remove="Images\toggle-cap-active.png" />
<EmbeddedResource Include="Images\toggle-cap-active.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<None Remove="Images\toggle-cap-inactive.png" />
<EmbeddedResource Include="Images\toggle-cap-inactive.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>

<ItemGroup>
Expand Down
29 changes: 20 additions & 9 deletions ScoutHelper/Utils.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
using Dalamud.Plugin.Services;
using ImGuiNET;
using System;
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using Dalamud.Plugin.Services;
using FFXIVClientStructs.FFXIV.Common.Math;
using ImGuiNET;
using ScoutHelper.Models;

namespace ScoutHelper;

public static class Utils {
public static string WorldName => Plugin.ClientState.LocalPlayer?.CurrentWorld?.GameData?.Name.ToString() ?? "Not Found";
public static string WorldName =>
Plugin.ClientState.LocalPlayer?.CurrentWorld?.GameData?.Name.ToString() ?? "Not Found";

public static string DataFilePath(string dataFilename) => Path.Combine(
public static string PluginFilePath(string dataFilename) => Path.Combine(
Plugin.PluginInterface.AssemblyLocation.Directory?.FullName!,
"Data",
dataFilename
);

public static void CreateTooltip(string text, float width = 12f) {
ImGui.BeginTooltip();
ImGui.PushTextWrapPos(ImGui.GetFontSize() * width);
Expand All @@ -28,15 +29,21 @@ public static void CreateTooltip(string text, float width = 12f) {
ImGui.EndTooltip();
}

public static Vector2 V2(float x, float y) => new(x, y);

public static string FormatTemplate(string textTemplate, IList<TrainMob> trainList, string bear, string url) {

var regex = new Regex(@"\\?\{[^}]+\\?\}", RegexOptions.Compiled | RegexOptions.IgnoreCase);
var matches = regex.Matches(textTemplate);

if (matches.Count == 0) {
return textTemplate;
}

var variables = new Dictionary<string, string>() {
{ "#", trainList.Count.ToString() },
{ "#available", trainList.Count.ToString() },
}.AsReadOnly();

var s = new StringBuilder(textTemplate.Length);
var i = 0;
foreach (Match match in matches) {
Expand All @@ -56,6 +63,7 @@ public static string FormatTemplate(string textTemplate, IList<TrainMob> trainLi
}

#region extensions

public static void TaggedPrint(this IChatGui chatGui, string message) {
chatGui.Print(message, Plugin.Name);
}
Expand All @@ -64,12 +72,15 @@ public static void TaggedPrintError(this IChatGui chatGui, string message) {
chatGui.PrintError(message, Plugin.Name);
}

public static IReadOnlyDictionary<K, V> VerifyEnumDictionary<K, V>(this IDictionary<K, V> enumDict) where K : struct, Enum {
public static IReadOnlyDictionary<K, V> VerifyEnumDictionary<K, V>(this IDictionary<K, V> enumDict)
where K : struct, Enum {
var allEnumsAreInDict = (Enum.GetValuesAsUnderlyingType<K>() as K[])!.All(enumDict.ContainsKey);
if (!allEnumsAreInDict) {
throw new Exception($"All values of enum [{typeof(K).Name}] must be in the dictionary.");
}

return enumDict.ToImmutableDictionary();
}

#endregion
}
5 changes: 5 additions & 0 deletions ScoutHelper/Windows/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using Dalamud.Interface.Utility.Raii;

namespace ScoutHelper.Windows;

Expand Down Expand Up @@ -74,6 +75,8 @@ private unsafe void DrawModeButtons() {
var modeLinkColor = modeLink ? activeColor : inactiveColor;
var modeFullColor = modeFull ? activeColor : inactiveColor;

using var rounding = ImRaii.PushStyle(ImGuiStyleVar.FrameRounding, 0f);

ImGui.PushStyleColor(ImGuiCol.Button, modeLinkColor);
ImGui.PushStyleColor(ImGuiCol.ButtonHovered, modeLinkColor);
ImGui.PushStyleColor(ImGuiCol.ButtonActive, modeLinkColor*0.9f);
Expand All @@ -92,6 +95,8 @@ private unsafe void DrawModeButtons() {
_copyFormattedText = !_copyFormattedText;
}
ImGui.PopStyleColor(3);

ToggleButton.Draw(_buttonSize);
}

private void DrawGeneratorButtons() {
Expand Down
23 changes: 23 additions & 0 deletions ScoutHelper/Windows/ToggleButton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System.Numerics;
using Dalamud.Interface.Internal;
using ImGuiNET;

namespace ScoutHelper.Windows;

public static class ToggleButton {

private static IDalamudTextureWrap _imCapActive =
Plugin.PluginInterface.UiBuilder.LoadImage(Utils.PluginFilePath(@"Images\toggle-cap-active"));
private static IDalamudTextureWrap _imCapInactive =
Plugin.PluginInterface.UiBuilder.LoadImage(Utils.PluginFilePath(@"Images\toggle-cap-inactive"));
private static IDalamudTextureWrap _imBodyActive =
Plugin.PluginInterface.UiBuilder.LoadImage(Utils.PluginFilePath(@"Images\toggle-body-active"));
private static IDalamudTextureWrap _imBodyInactive =
Plugin.PluginInterface.UiBuilder.LoadImage(Utils.PluginFilePath(@"Images\toggle-body-inactive"));

public static void Draw(Vector2 size) {

ImGui.InvisibleButton("abc", size);
ImGui.Image(_imCapActive.ImGuiHandle, new Vector2(size.Y/2, size.Y));
}
}

0 comments on commit 0ebceba

Please sign in to comment.