-
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
using System.Collections.Generic; | ||
using FFXIVClientStructs.FFXIV.Client.UI.Agent; | ||
using FFXIVClientStructs.FFXIV.Component.GUI; | ||
using SimpleTweaksPlugin.Events; | ||
using SimpleTweaksPlugin.TweakSystem; | ||
using SimpleTweaksPlugin.Utility; | ||
|
||
namespace SimpleTweaksPlugin.Tweaks; | ||
|
||
[TweakName("Remember Selected World")] | ||
[TweakDescription("Remembers which world was selected for each datacentre.")] | ||
[TweakReleaseVersion(UnreleasedVersion)] | ||
public unsafe class RememberSelectedWorld : Tweak { | ||
private class Configs : TweakConfig { | ||
public Dictionary<uint, short> DataCenterWorldSelect = new(); | ||
} | ||
|
||
private Configs? Config { get; set; } | ||
private short setting = -1; | ||
private bool isSetting; | ||
|
||
[AddonPreSetup("CharaSelect")] | ||
private void AddonSetup() { | ||
isSetting = true; | ||
setting = -1; | ||
} | ||
|
||
[AddonPostUpdate("CharaSelect")] | ||
public void AddonUpdate(AtkUnitBase* unitBase) { | ||
var lobby = AgentLobby.Instance(); | ||
if (lobby == null || lobby->WorldId == 0 || lobby->WorldIndex < 0) return; | ||
Config ??= LoadConfig<Configs>() ?? new Configs(); | ||
|
||
if (isSetting) { | ||
if (setting == -1) { | ||
if (Config.DataCenterWorldSelect.TryGetValue(lobby->DataCenter, out setting)) return; | ||
isSetting = false; | ||
return; | ||
} | ||
|
||
if (setting == lobby->WorldIndex) { | ||
isSetting = false; | ||
return; | ||
} | ||
SimpleLog.Verbose($"Setting selected world to Index#{setting}"); | ||
Common.GenerateCallback(unitBase, 10, 0, (int) setting); | ||
Common.GenerateCallback(unitBase, 6, 0, 0); | ||
setting = -1; | ||
return; | ||
} | ||
|
||
if (Config.DataCenterWorldSelect.TryGetValue(lobby->DataCenter, out var worldIndex) && worldIndex == lobby->WorldIndex) return; | ||
Config.DataCenterWorldSelect[lobby->DataCenter] = lobby->WorldIndex; | ||
SaveConfig(Config); | ||
} | ||
} |