Skip to content

Commit

Permalink
Tracker lock function
Browse files Browse the repository at this point in the history
  • Loading branch information
DarwinBaker committed Dec 1, 2021
1 parent c9f36c4 commit b706c9f
Show file tree
Hide file tree
Showing 12 changed files with 72 additions and 111 deletions.
9 changes: 3 additions & 6 deletions AATool/AATool.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,9 @@
<Content Include="assets\graphics\sprites\gui\icons\bullet_point.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="assets\graphics\sprites\gui\icons\locked.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="assets\graphics\sprites\gui\icons\prev.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down Expand Up @@ -1119,12 +1122,6 @@
<Content Include="assets\graphics\sprites\gui\icons\compass%2428.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="assets\graphics\sprites\gui\icons\compass_needle%2428.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="assets\graphics\sprites\gui\icons\compass_empty.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="assets\graphics\sprites\gui\icons\enchantment_table_closed.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Expand Down
4 changes: 2 additions & 2 deletions AATool/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("1.3.3.1")]
[assembly: AssemblyFileVersion("1.3.3.1")]
[assembly: AssemblyVersion("1.3.3.2")]
[assembly: AssemblyFileVersion("1.3.3.2")]
[assembly: NeutralResourcesLanguage("en")]
2 changes: 1 addition & 1 deletion AATool/Saves/SftpSave.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public static void Sync()
if (Server.TryGet(out Server server))
server.SendNextRefresh();

Tracker.Invalidate();
Tracker.Invalidate(true);
}
}
finally
Expand Down
19 changes: 13 additions & 6 deletions AATool/Saves/World.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ public bool TryUpdate()

if (newState is SaveFolderState.Valid)
{
if (this.CurrentFolder is null || latest.FullName != this.CurrentFolder.FullName)
bool ready = !TrackerSettings.LockWorld;
ready |= Config.Tracker.CustomPathChanged() && !Config.Tracker.UseDefaultPath;
ready |= Config.Tracker.UseDefaultPathChanged();
ready |= Config.Tracker.UseRemoteWorldChanged();
ready &= latest.FullName != this.CurrentFolder?.FullName;
if (this.CurrentFolder is null || ready)
{
//world changed
this.CurrentFolder = latest;
Expand All @@ -89,6 +94,7 @@ public bool TryUpdate()
{
//world not set
this.CurrentFolder = null;
TrackerSettings.LockWorld = false;
}

//handle states
Expand All @@ -101,8 +107,9 @@ public bool TryUpdate()

private static bool MightBeWorldFolder(DirectoryInfo folder)
{
return Directory.Exists(Path.Combine(folder.FullName, "stats"))
|| Directory.Exists(Path.Combine(folder.FullName, "advancements"));
return Directory.Exists(Path.Combine(folder.FullName, "advancements"))
|| Directory.Exists(Path.Combine(folder.FullName, "stats"))
|| File.Exists(Path.Combine(folder.FullName, "level.dat"));
}

private static DirectoryInfo MostRecentlyAccessed(DirectoryInfo a, DirectoryInfo b)
Expand All @@ -111,9 +118,9 @@ private static DirectoryInfo MostRecentlyAccessed(DirectoryInfo a, DirectoryInfo
return b;
if (b is null)
return a;
return a.LastAccessTime > b.LastAccessTime
? a
: b;
return a.LastAccessTimeUtc > b.LastAccessTimeUtc
? a
: b;
}

private SaveFolderState TryGetLatestWorld(out DirectoryInfo directory)
Expand Down
2 changes: 2 additions & 0 deletions AATool/Settings/TrackerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public class TrackerSettings : SettingsGroup
public string SftpUser { get => this.Get<string>(SFTP_USER); set => this.Set(SFTP_USER, value); }
public string SftpPass { get => this.Get<string>(SFTP_PASS); set => this.Set(SFTP_PASS, value); }

public static bool LockWorld { get; set; }

public bool GameVersionChanged() => Instance.ValueChanged(GAME_VERSION);
public bool UseRemoteWorldChanged() => Instance.ValueChanged(REMOTE_WORLD);
public bool UseDefaultPathChanged() => Instance.ValueChanged(USE_DEFAULT_PATH);
Expand Down
7 changes: 6 additions & 1 deletion AATool/Tracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ private static void Clear()
UpdateManifestProgress();
}

public static void Invalidate() => World.Invalidate();
public static void Invalidate(bool invalidateWorld = false)
{
if (invalidateWorld)
World.Invalidate();
RefreshTimer.Expire();
}

public static void Update(Time time)
{
Expand Down
132 changes: 42 additions & 90 deletions AATool/UI/Controls/UIRefreshIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ namespace AATool.UI.Controls
{
class UIRefreshIcon : UIControl
{
private UIButton syncButton;
private UIPicture syncIcon;
private UIPicture layer1;
private UIPicture layer2;
private UIButton button;
private UIPicture icon;
private UIPicture lockIcon;
private bool repeat;

private readonly Easing fade;
Expand All @@ -30,50 +29,29 @@ public UIRefreshIcon()

public override void InitializeRecursive(UIScreen screen)
{
this.syncButton = this.First<UIButton>("manual_sync");
this.syncButton.OnClick += this.OnClick;
this.syncIcon = this.syncButton.First<UIPicture>();
this.layer1 = this.First<UIPicture>("layer1");
this.layer2 = this.First<UIPicture>("layer2");

this.button = this.First<UIButton>("manual_sync");
this.button.OnClick += this.OnClick;
this.icon = this.First<UIPicture>("icon");
this.lockIcon = this.First<UIPicture>("lock");
base.InitializeRecursive(screen);
}

private void OnClick(UIControl sender)
{
if (sender == this.syncButton)
SftpSave.Sync();
}

private void SetStates(bool layer1, bool layer2)
{
if (layer1)
this.layer1.Expand();
else
this.layer1.Collapse();

if (layer2)
this.layer2.Expand();
else
this.layer2.Collapse();
}

private void SetLayers(Layer layer1, Layer layer2)
{
this.layer1.SetLayer(layer1);
this.layer2.SetLayer(layer2);
}

private void SetTextures(string layer1, string layer2)
{
this.layer1.SetTexture(layer1);
this.layer2.SetTexture(layer2);
}
if (sender == this.button)
{
if (Config.Tracker.UseRemoteWorld)
{
SftpSave.Sync();
}
else
{
TrackerSettings.LockWorld ^= true;
if (!TrackerSettings.LockWorld)
Tracker.Invalidate();
}
}

private void SetTints(Color layer1, Color layer2)
{
this.layer1.SetTint(layer1);
this.layer2.SetTint(layer2);
}

protected override void UpdateThis(Time time)
Expand All @@ -82,20 +60,21 @@ protected override void UpdateThis(Time time)

if (!Config.Tracker.UseRemoteWorld || Peer.IsClient)
{
//this.layer1.Expand();
this.layer2.Expand();
this.syncButton.Collapse();

//update style
switch (Config.Main.RefreshIcon)
{
case "xp_orb":
this.UpdateAsXpOrb();
this.icon.SetTexture("xp_orb");
break;
case "compass":
this.UpdateAsCompass();
this.icon.SetTexture("compass");
break;
}

float alpha = this.repeat
? 20 * this.fade.In()
: 1 - this.fade.Out();
this.icon.SetTint(ColorHelper.Fade(Color.White, alpha));

//update state
if (Tracker.Invalidated || Config.Main.ValueChanged(MainSettings.REFRESH_ICON))
Expand All @@ -108,59 +87,32 @@ protected override void UpdateThis(Time time)
this.fade.Reset();
this.repeat = false;
}
this.button.Enabled = Tracker.SaveState is SaveFolderState.Valid;
this.lockIcon.SetTexture(TrackerSettings.LockWorld ? "locked" : "");
this.lockIcon.SetTint(ColorHelper.Fade(Color.White, 1 - (alpha * 4)));
}
else
{
//hide refresh icon and show sync button
this.layer1.Collapse();
this.layer2.Collapse();
this.syncButton.Expand();

bool ready = SftpSave.State is SyncState.Ready;
this.syncButton.Enabled = ready;
this.syncIcon.SetTexture(ready ? "sync" : "syncing");
this.syncIcon.SetTint(Config.Main.TextColor);
this.button.Enabled = ready;
this.icon.SetTexture(ready ? "sync" : "syncing");
this.icon.SetTint(Config.Main.TextColor);
this.lockIcon.SetTexture("");
}
}

private void UpdateAsXpOrb()
{
this.SetStates(false, true);
this.SetLayers(Layer.Main, Layer.Fore);
this.SetTextures(string.Empty, "xp_orb");

float alpha = this.repeat
? 20 * this.fade.In()
: 1 - this.fade.Out();

this.SetTints(Color.White, ColorHelper.Fade(Color.White, alpha));
}

private void UpdateAsCompass()
{
this.SetStates(true, true);
this.SetLayers(Layer.Fore, Layer.Fore);
this.SetTextures("compass_empty", "compass_needle");

//always keep compass somewhat visible
float alpha = this.repeat
? (2 * this.fade.In()) + 0.5f
: (2 * (1 - this.fade.Out())) + 0.5f;

Color tint = this.repeat
? Color.White * (alpha - 0.5f) * 2
: Color.White * (alpha - 0.5f) * 8;

this.SetTints(ColorHelper.Fade(Color.White, 2.5f * alpha), tint);
}

public override void DrawThis(Display display)
{
//glow effect
if (Config.Main.RefreshIcon is "xp_orb" && !this.layer2.IsCollapsed)
if (this.icon.Texture is "xp_orb")
{
Rectangle rectangle = new (this.X - 8, this.Y - 8, this.Width + 16, this.Height + 16);
display.Draw("xp_orb_glow", rectangle, this.layer2.Tint, Layer.Glow);
var rectangle = new Rectangle(
this.X - 8,
this.Y - 8,
this.Width + 16,
this.Height + 16);

display.Draw("xp_orb_glow", rectangle, this.icon.Tint, Layer.Glow);
}
base.DrawThis(display);
}
Expand Down
2 changes: 1 addition & 1 deletion AATool/Winforms/Controls/CTrackerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private void TogglePassword()
{
//show confirmation dialog
string message = "Be careful about showing SFTP login credentials on stream! ♥\nAre you sure you want to unmask the username and password fields?";
string title = "SFTP Credentials Reaveal Confirmation";
string title = "SFTP Credentials Reveal Confirmation";
DialogResult result = MessageBox.Show(this, message, title,
MessageBoxButtons.YesNo,
MessageBoxIcon.Warning,
Expand Down
Binary file not shown.
Binary file not shown.
Binary file added AATool/assets/graphics/sprites/gui/icons/locked.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 2 additions & 4 deletions AATool/assets/ui/controls/control_refresh_icon.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<control width="32" height="32">
<button name="manual_sync">
<picture texture="sync"/>
<picture name="icon" layer="fore"/>
<picture name="lock" layer="fore"/>
</button>
<picture name="layer1" layer="fore"/>
<picture name="layer2" layer="fore"/>
<picture name="glow" layer="glow"/>
</control>

0 comments on commit b706c9f

Please sign in to comment.