Automatically open Workshop window when near a Fabrication Station

This commit is contained in:
Liza 2023-10-11 11:05:16 +02:00
parent c270050c3c
commit 0bf6e65bfe
Signed by: liza
GPG Key ID: 7199F8D727D55F67
4 changed files with 49 additions and 6 deletions

View File

@ -46,6 +46,7 @@ internal sealed class MainWindow : Window
Flags = ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoCollapse;
}
public EOpenReason OpenReason { get; set; } = EOpenReason.None;
public bool NearFabricationStation { get; set; }
public ButtonState State { get; set; } = ButtonState.None;
@ -200,6 +201,22 @@ internal sealed class MainWindow : Window
_pluginInterface.SavePluginConfig(_configuration);
}
public void Toggle(EOpenReason reason)
{
if (!IsOpen)
{
IsOpen = true;
OpenReason = reason;
}
else
IsOpen = false;
}
public override void OnClose()
{
OpenReason = EOpenReason.None;
}
private unsafe void CheckMaterial()
{
ImGui.Text("Items needed for all crafts in queue:");
@ -283,4 +300,12 @@ internal sealed class MainWindow : Window
Pause,
Stop,
}
public enum EOpenReason
{
None,
Command,
NearFabricationStation,
PluginInstaller,
}
}

View File

@ -39,7 +39,7 @@ partial class WorkshopPlugin
if (npcIds.Contains(GetNpcId(obj)))
{
o = obj;
return Vector3.Distance(_clientState.LocalPlayer!.Position, obj.Position);
return Vector3.Distance(_clientState.LocalPlayer!.Position, obj.Position + new Vector3(0, -2, 0));
}
}
}

View File

@ -60,7 +60,7 @@ public sealed partial class WorkshopPlugin : IDalamudPlugin
_windowSystem.AddWindow(_mainWindow);
_pluginInterface.UiBuilder.Draw += _windowSystem.Draw;
_pluginInterface.UiBuilder.OpenMainUi += _mainWindow.Toggle;
_pluginInterface.UiBuilder.OpenMainUi += OpenMainUi;
_framework.Update += FrameworkUpdate;
_commandManager.AddHandler("/ws", new CommandInfo(ProcessCommand)
{
@ -86,14 +86,28 @@ public sealed partial class WorkshopPlugin : IDalamudPlugin
if (!_clientState.IsLoggedIn ||
!WorkshopTerritories.Contains(_clientState.TerritoryType) ||
_condition[ConditionFlag.BoundByDuty] ||
GetDistanceToEventObject(FabricationStationIds, out var fabricationStation) >= 5f)
GetDistanceToEventObject(FabricationStationIds, out var fabricationStation) >= 3f)
{
_mainWindow.NearFabricationStation = false;
if (_mainWindow.IsOpen &&
_mainWindow.OpenReason == MainWindow.EOpenReason.NearFabricationStation &&
_configuration.CurrentlyCraftedItem == null &&
_configuration.ItemQueue.Count == 0)
{
_mainWindow.IsOpen = false;
}
}
else if (DateTime.Now >= _continueAt)
{
_mainWindow.NearFabricationStation = true;
if (!_mainWindow.IsOpen)
{
_mainWindow.IsOpen = true;
_mainWindow.OpenReason = MainWindow.EOpenReason.NearFabricationStation;
}
if (_mainWindow.State is MainWindow.ButtonState.Pause or MainWindow.ButtonState.Stop)
{
_mainWindow.State = MainWindow.ButtonState.None;
@ -187,13 +201,17 @@ public sealed partial class WorkshopPlugin : IDalamudPlugin
return _workshopCache.Crafts.Single(x => x.WorkshopItemId == _configuration.CurrentlyCraftedItem!.WorkshopItemId);
}
private void ProcessCommand(string command, string arguments) => _mainWindow.Toggle();
private void ProcessCommand(string command, string arguments)
=> _mainWindow.Toggle(MainWindow.EOpenReason.Command);
private void OpenMainUi()
=> _mainWindow.Toggle(MainWindow.EOpenReason.PluginInstaller);
public void Dispose()
{
_commandManager.RemoveHandler("/ws");
_pluginInterface.UiBuilder.Draw -= _windowSystem.Draw;
_pluginInterface.UiBuilder.OpenMainUi -= _mainWindow.Toggle;
_pluginInterface.UiBuilder.OpenMainUi -= OpenMainUi;
_framework.Update -= FrameworkUpdate;
RestoreYesAlready();

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework>
<Version>2.1</Version>
<Version>2.2</Version>
<LangVersion>11.0</LangVersion>
<Nullable>enable</Nullable>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>