2021-11-19 17:55:07 +00:00
using System ;
using Dalamud.Interface ;
2023-09-29 01:07:21 +00:00
using Dalamud.Plugin.Services ;
2021-11-19 17:55:07 +00:00
using FFXIVClientStructs.FFXIV.Component.GUI ;
using ImGuiNET ;
using Lumina.Excel.GeneratedSheets ;
namespace Glamaholic {
internal static class Util {
internal const string PlateAddon = "MiragePrismMiragePlate" ;
private const string BoxAddon = "MiragePrismPrismBox" ;
private const string ArmoireAddon = "CabinetWithdraw" ;
2021-11-23 04:20:18 +00:00
2021-11-23 21:09:52 +00:00
internal const uint HqItemOffset = 1_000_000 ;
2021-11-19 17:55:07 +00:00
private static unsafe bool IsOpen ( AtkUnitBase * addon ) {
return addon ! = null & & addon - > IsVisible ;
}
2023-09-29 01:07:21 +00:00
private static unsafe bool IsOpen ( IGameGui gui , string name ) {
2021-11-19 17:55:07 +00:00
var addon = ( AtkUnitBase * ) gui . GetAddonByName ( name , 1 ) ;
return IsOpen ( addon ) ;
}
2021-11-23 04:20:18 +00:00
2023-09-29 01:07:21 +00:00
internal static bool IsEditingPlate ( IGameGui gui ) {
2021-11-19 17:55:07 +00:00
var plateOpen = IsOpen ( gui , PlateAddon ) ;
var boxOpen = IsOpen ( gui , BoxAddon ) ;
var armoireOpen = IsOpen ( gui , ArmoireAddon ) ;
return plateOpen & & ( boxOpen | | armoireOpen ) ;
}
2021-11-23 04:20:18 +00:00
2021-11-19 17:55:07 +00:00
internal static bool DrawTextInput ( string id , ref string input , uint max = 512 , string message = "Press Enter to save." , ImGuiInputTextFlags flags = ImGuiInputTextFlags . None ) {
ImGui . SetNextItemWidth ( - 1 ) ;
var ret = ImGui . InputText ( $"##{id}" , ref input , max , ImGuiInputTextFlags . EnterReturnsTrue | flags ) ;
ImGui . TextUnformatted ( message ) ;
return ret & & input . Length > 0 ;
}
2021-11-23 04:20:18 +00:00
2021-11-19 17:55:07 +00:00
internal static bool IconButton ( FontAwesomeIcon icon , string? id = null , string? tooltip = null , bool small = false ) {
var label = icon . ToIconString ( ) ;
if ( id ! = null ) {
label + = $"##{id}" ;
}
ImGui . PushFont ( UiBuilder . IconFont ) ;
var ret = small
? ImGui . SmallButton ( label )
: ImGui . Button ( label ) ;
ImGui . PopFont ( ) ;
if ( tooltip ! = null & & ImGui . IsItemHovered ( ) ) {
ImGui . BeginTooltip ( ) ;
ImGui . TextUnformatted ( tooltip ) ;
ImGui . EndTooltip ( ) ;
}
return ret ;
}
2021-11-23 04:20:18 +00:00
2021-11-19 17:55:07 +00:00
internal static void TextUnformattedWrapped ( string text ) {
ImGui . PushTextWrapPos ( ) ;
ImGui . TextUnformatted ( text ) ;
ImGui . PopTextWrapPos ( ) ;
}
2021-12-07 22:06:14 +00:00
internal static PlateSlot ? GetSlot ( Item item ) {
var category = item . EquipSlotCategory . Value ;
if ( category = = null ) {
return null ;
}
if ( category . MainHand > 0 ) {
return PlateSlot . MainHand ;
}
if ( category . OffHand > 0 ) {
return PlateSlot . OffHand ;
}
if ( category . Head > 0 ) {
return PlateSlot . Head ;
}
if ( category . Body > 0 ) {
return PlateSlot . Body ;
}
if ( category . Gloves > 0 ) {
return PlateSlot . Hands ;
}
if ( category . Legs > 0 ) {
return PlateSlot . Legs ;
}
if ( category . Feet > 0 ) {
return PlateSlot . Feet ;
}
if ( category . Ears > 0 ) {
return PlateSlot . Ears ;
}
if ( category . Neck > 0 ) {
return PlateSlot . Neck ;
}
if ( category . Wrists > 0 ) {
return PlateSlot . Wrists ;
}
if ( category . FingerR > 0 ) {
return PlateSlot . RightRing ;
}
if ( category . FingerL > 0 ) {
return PlateSlot . LeftRing ;
}
2021-12-09 06:19:31 +00:00
2021-12-07 22:06:14 +00:00
return null ;
}
2021-11-19 17:55:07 +00:00
internal static bool MatchesSlot ( EquipSlotCategory category , PlateSlot slot ) {
return slot switch {
PlateSlot . MainHand = > category . MainHand > 0 ,
PlateSlot . OffHand = > category . OffHand > 0 ,
PlateSlot . Head = > category . Head > 0 ,
PlateSlot . Body = > category . Body > 0 ,
PlateSlot . Hands = > category . Gloves > 0 ,
PlateSlot . Legs = > category . Legs > 0 ,
PlateSlot . Feet = > category . Feet > 0 ,
PlateSlot . Ears = > category . Ears > 0 ,
PlateSlot . Neck = > category . Neck > 0 ,
PlateSlot . Wrists = > category . Wrists > 0 ,
PlateSlot . RightRing = > category . FingerR > 0 ,
PlateSlot . LeftRing = > category . FingerL > 0 ,
_ = > throw new ArgumentOutOfRangeException ( nameof ( slot ) , slot , null ) ,
} ;
}
2021-11-23 04:23:37 +00:00
2021-11-23 04:23:56 +00:00
internal static bool IsItemMiddleOrCtrlClicked ( ) {
if ( ImGui . IsItemClicked ( ImGuiMouseButton . Middle ) ) {
return true ;
}
return ImGui . GetIO ( ) . KeyCtrl & & ImGui . IsItemClicked ( ImGuiMouseButton . Left ) ;
}
2021-11-23 04:23:37 +00:00
// https://github.com/ufx/GarlandTools/blob/5b2ec54dc792175a1d565fddb6c6b975b9a9ff64/Garland.Data/Hacks.cs#L89
internal static bool IsItemSkipped ( Item item ) {
var name = item . Name . RawString ;
return item . RowId switch {
// Dated Radz-at-Han Coin
17557 = > false ,
// Wrapped Present (no icon)
22357 = > true ,
_ = > name . Length = = 0 | | name . StartsWith ( "Dated" ) ,
} ;
}
2021-12-09 09:07:58 +00:00
internal static void TextIcon ( FontAwesomeIcon icon ) {
ImGui . PushFont ( UiBuilder . IconFont ) ;
ImGui . TextUnformatted ( icon . ToIconString ( ) ) ;
ImGui . PopFont ( ) ;
}
2021-12-13 10:35:23 +00:00
internal static string GetClipboardText ( ) {
try {
return ImGui . GetClipboardText ( ) ;
} catch ( Exception ) {
return string . Empty ;
}
}
2021-11-19 17:55:07 +00:00
}
}