From b8fe612cd56c55f05dbb032fd2f4d519aa7092a2 Mon Sep 17 00:00:00 2001 From: Darwin Baker <51175243+DarwinBaker@users.noreply.github.com> Date: Sat, 5 Mar 2022 01:30:59 -0500 Subject: [PATCH] Fix stale reference issue and clean stuff up --- AATool/Configuration/ConfigStatic.cs | 4 +- AATool/Configuration/MainConfig.cs | 4 + AATool/Configuration/MainConfig.cs.bak | 101 --------- AATool/Configuration/TrackingConfig.cs | 6 +- AATool/Data/Categories/AdventuringTime.cs | 6 +- AATool/Data/Categories/AllAchievements.cs | 10 +- AATool/Data/Categories/AllAdvancements.cs | 10 +- AATool/Data/Categories/AllBlocks.cs | 10 +- AATool/Data/Categories/AllDeaths.cs | 10 +- AATool/Data/Categories/BalancedDiet.cs | 4 +- AATool/Data/Categories/Category.cs | 16 +- AATool/Data/Categories/HalfDeaths.cs | 4 +- AATool/Data/Categories/MonstersHunted.cs | 4 +- AATool/Data/Objectives/Block.cs | 2 +- AATool/Data/Objectives/Death.cs | 2 +- AATool/Data/Progress/WorldState.cs | 10 +- AATool/Graphics/Canvas.cs.bak | 241 ---------------------- AATool/Properties/AssemblyInfo.cs | 4 +- AATool/Saves/WorldFolder.cs | 2 +- AATool/Tracker.cs | 44 ++-- AATool/UI/Controls/UIBlockGroup.cs | 2 +- AATool/UI/Controls/UIObjectiveFrame.cs | 10 + AATool/UI/Controls/UIPlayer.cs | 2 +- AATool/UI/Screens/UIMainScreen.cs | 3 +- AATool/UI/Screens/UIOverlayScreen.cs | 2 +- 25 files changed, 95 insertions(+), 418 deletions(-) delete mode 100644 AATool/Configuration/MainConfig.cs.bak delete mode 100644 AATool/Graphics/Canvas.cs.bak diff --git a/AATool/Configuration/ConfigStatic.cs b/AATool/Configuration/ConfigStatic.cs index 0c2487e3..b9e7c922 100644 --- a/AATool/Configuration/ConfigStatic.cs +++ b/AATool/Configuration/ConfigStatic.cs @@ -88,8 +88,8 @@ public static void Save(Config config) Formatting = Newtonsoft.Json.Formatting.Indented }.Deserialize(stream, typeof(T)); - if (config is null) - throw new InvalidDataException(); + //if (config is null) + // throw new InvalidDataException(); } } catch (Exception e) diff --git a/AATool/Configuration/MainConfig.cs b/AATool/Configuration/MainConfig.cs index 547314bb..1cc5f78c 100644 --- a/AATool/Configuration/MainConfig.cs +++ b/AATool/Configuration/MainConfig.cs @@ -50,9 +50,13 @@ public class MainConfig : Config [JsonProperty] public readonly Setting TextColor = new (Hex("DCDDDE")); [JsonProperty] public readonly Setting BorderColor = new (Hex("4E5156")); + [JsonIgnore] public bool RelaxedMode => !this.CompactMode; + + [JsonIgnore] public string ViewMode => this.CompactMode ? "compact" : "relaxed"; + [JsonIgnore] public bool StyleChanged => this.FrameStyle.Changed || this.BorderColor.Changed || this.BackColor.Changed diff --git a/AATool/Configuration/MainConfig.cs.bak b/AATool/Configuration/MainConfig.cs.bak deleted file mode 100644 index 252b8c23..00000000 --- a/AATool/Configuration/MainConfig.cs.bak +++ /dev/null @@ -1,101 +0,0 @@ -using AATool.Utilities; -using Microsoft.Xna.Framework; -using Newtonsoft.Json; -using System.Collections.Generic; -using System.Reflection; -using System.Xml; - -namespace AATool.Configuration -{ - public abstract partial class Config - { - [JsonObject] - public class MainConfig : Config - { - public static readonly Dictionary Themes = new () - { - {"Dark Mode", (Hex("36393F"), Hex("DCDDDE"), Hex("4E5156"))}, - {"Light Mode", (Hex("F0F0F0"), Hex("000000"), Hex("C4C4C4"))}, - {"GitHub Dark", (Hex("0D1117"), Hex("C9D1D9"), Hex("30363D"))}, - {"Ender Pearl", (Hex("0C3730"), Hex("C6F2EA"), Hex("349988"))}, - {"Brick", (Hex("804040"), Hex("FFFFFF"), Hex("AA5A5A"))}, - {"Berry", (Hex("411126"), Hex("C9D1D9"), Hex("5E1938"))}, - {"Couri Enjoyer", (Hex("502880"), Hex("C9D1D9"), Hex("8336B6"))}, - {"90's Hacker", (Hex("001800"), Hex("00FF00"), Hex("005000"))}, - {"High Contrast", (Hex("000000"), Hex("FFFFFF"), Hex("FFFFFF"))} - }; - - private static Color Hex(string hex) => ColorHelper.TryGetHexColor(hex, out Color color) ? color : Color.White; - - [JsonProperty] public readonly Setting FpsCap = new (60); - [JsonProperty] public readonly Setting DisplayScale = new (1); - - [JsonProperty] public readonly Setting HideCompletedAdvancements = new (false); - [JsonProperty] public readonly Setting ShowBasicAdvancements = new (true); - [JsonProperty] public readonly Setting ShowCompletionGlow = new (true); - [JsonProperty] public readonly Setting ShowAmbientGlow = new (true); - [JsonProperty] public readonly Setting CompactMode = new (false); - [JsonProperty] public readonly Setting RainbowMode = new (false); - - [JsonProperty] public readonly Setting LayoutDebugMode = new (false); - [JsonProperty] public readonly Setting CacheDebugMode = new (false); - [JsonProperty] public readonly Setting HideRenderCache = new (false); - - [JsonProperty] public readonly Setting FrameStyle = new ("Modern"); - [JsonProperty] public readonly Setting ProgressBarStyle = new ("Modern"); - [JsonProperty] public readonly Setting RefreshIcon = new ("Xp Orb"); - [JsonProperty] public readonly Setting InfoPanel = new ("Leaderboard"); - - [JsonProperty] public readonly Setting BackColor = new (Hex("36393F")); - [JsonProperty] public readonly Setting TextColor = new (Hex("DCDDDE")); - [JsonProperty] public readonly Setting BorderColor = new (Hex("4E5156")); - - public bool RelaxedMode => !this.CompactMode; - public string ViewMode => this.CompactMode ? "compact" : "relaxed"; - - public bool StyleChanged => this.FrameStyle.Changed - || this.BorderColor.Changed - || this.BackColor.Changed - || this.TextColor.Changed - || this.ProgressBarStyle.Changed; - - protected override string GetId() => "main"; - protected override string GetLegacyId() => "main"; - - public MainConfig() - { - this.RegisterSetting(this.FpsCap); - this.RegisterSetting(this.ShowBasicAdvancements); - this.RegisterSetting(this.ShowCompletionGlow); - this.RegisterSetting(this.CompactMode); - this.RegisterSetting(this.RainbowMode); - this.RegisterSetting(this.LayoutDebugMode); - this.RegisterSetting(this.FrameStyle); - this.RegisterSetting(this.ProgressBarStyle); - this.RegisterSetting(this.RefreshIcon); - this.RegisterSetting(this.InfoPanel); - this.RegisterSetting(this.BackColor); - this.RegisterSetting(this.TextColor); - this.RegisterSetting(this.BorderColor); - } - - protected override void ApplyLegacySetting(string key, object value) - { - ISetting setting = key switch { - "show_basic_advancements" => this.ShowBasicAdvancements, - "fps_cap" => this.FpsCap, - "layout_debug" => this.LayoutDebugMode, - "compact_mode" => this.CompactMode, - "hide_completed" => this.HideCompletedAdvancements, - "refresh_icon" => this.RefreshIcon, - "rainbow_mode" => this.RainbowMode, - "main_back_color" => this.BackColor, - "main_border_color" => this.BorderColor, - "main_text_color" => this.TextColor, - _ => null - }; - setting?.Set(value); - } - } - } -} diff --git a/AATool/Configuration/TrackingConfig.cs b/AATool/Configuration/TrackingConfig.cs index b5282e35..b7ecd0bd 100644 --- a/AATool/Configuration/TrackingConfig.cs +++ b/AATool/Configuration/TrackingConfig.cs @@ -14,7 +14,7 @@ public class TrackingConfig : Config [JsonProperty] public readonly Setting LastSession = new (string.Empty); [JsonProperty] public readonly Setting GameCategory = new ("All Advancements"); - [JsonProperty] public readonly Setting GameVersion = new ("1.16"); + [JsonProperty] public readonly Setting GameVersion = new ("1.18"); [JsonProperty] public readonly Setting AutoDetectVersion = new (true); [JsonProperty] public readonly Setting UseSftp = new (false); @@ -30,9 +30,11 @@ public class TrackingConfig : Config protected override string GetId() => "tracking"; protected override string GetLegacyId() => "tracker"; + [JsonIgnore] public bool WatchActiveInstance => !this.UseSftp && (this.Source == TrackerSource.ActiveInstance || this.AutoDetectVersion || Tracker.Category is AllDeaths); - + + [JsonIgnore] public bool SourceChanged => this.UseSftp.Changed || this.Source.Changed || (this.Source == TrackerSource.CustomSavesPath && this.CustomSavesPath.Changed) || (this.Source == TrackerSource.SpecificWorld && this.CustomWorldPath.Changed); diff --git a/AATool/Data/Categories/AdventuringTime.cs b/AATool/Data/Categories/AdventuringTime.cs index c591384f..a2f5b2c9 100644 --- a/AATool/Data/Categories/AdventuringTime.cs +++ b/AATool/Data/Categories/AdventuringTime.cs @@ -12,7 +12,7 @@ public class AdventuringTime : SingleAdvancement }; public override IEnumerable GetSupportedVersions() => SupportedVersions; - public override IEnumerable GetOverlayObjectives() => this.Achievements.All.Values; + public override IEnumerable GetOverlayObjectives() => Tracker.Achievements.All.Values; public override int GetTargetCount() => this.Requirement?.Criteria.Count ?? 0; public override int GetCompletedCount() => this.Requirement?.Criteria.MostCompleted ?? 0; @@ -27,8 +27,8 @@ public AdventuringTime() : base() public override void LoadObjectives() { - this.Advancements.RefreshObjectives(); - this.Advancements.TryGet(Id, out Advancement adventuringTime); + Tracker.Advancements.RefreshObjectives(); + Tracker.Advancements.TryGet(Id, out Advancement adventuringTime); this.Requirement = adventuringTime; } } diff --git a/AATool/Data/Categories/AllAchievements.cs b/AATool/Data/Categories/AllAchievements.cs index 571c05f5..7a211657 100644 --- a/AATool/Data/Categories/AllAchievements.cs +++ b/AATool/Data/Categories/AllAchievements.cs @@ -11,10 +11,10 @@ public class AllAchievements : Category }; public override IEnumerable GetSupportedVersions() => SupportedVersions; - public override IEnumerable GetOverlayObjectives() => this.Achievements.All.Values; + public override IEnumerable GetOverlayObjectives() => Tracker.Achievements.All.Values; - public override int GetTargetCount() => this.Achievements.Count; - public override int GetCompletedCount() => this.Achievements.CompletedCount; + public override int GetTargetCount() => Tracker.Achievements.Count; + public override int GetCompletedCount() => Tracker.Achievements.CompletedCount; public AllAchievements() : base () { @@ -26,8 +26,8 @@ public AllAchievements() : base () public override void LoadObjectives() { - this.Achievements.RefreshObjectives(); - this.Pickups.RefreshObjectives(); + Tracker.Achievements.RefreshObjectives(); + Tracker.Pickups.RefreshObjectives(); } } } diff --git a/AATool/Data/Categories/AllAdvancements.cs b/AATool/Data/Categories/AllAdvancements.cs index be3bec37..04919e7b 100644 --- a/AATool/Data/Categories/AllAdvancements.cs +++ b/AATool/Data/Categories/AllAdvancements.cs @@ -17,10 +17,10 @@ public class AllAdvancements : Category }; public override IEnumerable GetSupportedVersions() => SupportedVersions; - public override IEnumerable GetOverlayObjectives() => this.Advancements.All.Values; + public override IEnumerable GetOverlayObjectives() => Tracker.Advancements.All.Values; - public override int GetCompletedCount() => this.Advancements.CompletedCount; - public override int GetTargetCount() => this.Advancements.Count; + public override int GetCompletedCount() => Tracker.Advancements.CompletedCount; + public override int GetTargetCount() => Tracker.Advancements.Count; public AllAdvancements() : base () { @@ -32,8 +32,8 @@ public AllAdvancements() : base () public override void LoadObjectives() { - this.Advancements.RefreshObjectives(); - this.Pickups.RefreshObjectives(); + Tracker.Advancements.RefreshObjectives(); + Tracker.Pickups.RefreshObjectives(); } } } diff --git a/AATool/Data/Categories/AllBlocks.cs b/AATool/Data/Categories/AllBlocks.cs index dffcdf86..1722d610 100644 --- a/AATool/Data/Categories/AllBlocks.cs +++ b/AATool/Data/Categories/AllBlocks.cs @@ -11,10 +11,10 @@ public class AllBlocks : Category }; public override IEnumerable GetSupportedVersions() => SupportedVersions; - public override IEnumerable GetOverlayObjectives() => this.Blocks.All.Values; + public override IEnumerable GetOverlayObjectives() => Tracker.Blocks.All.Values; - public override int GetTargetCount() => this.Blocks.Count; - public override int GetCompletedCount() => this.Blocks.PlacedCount; + public override int GetTargetCount() => Tracker.Blocks.Count; + public override int GetCompletedCount() => Tracker.Blocks.PlacedCount; public AllBlocks() : base() { @@ -28,8 +28,8 @@ public AllBlocks() : base() public override void LoadObjectives() { - this.Blocks.RefreshObjectives(); - this.Pickups.RefreshObjectives(); + Tracker.Blocks.RefreshObjectives(); + Tracker.Pickups.RefreshObjectives(); } } } diff --git a/AATool/Data/Categories/AllDeaths.cs b/AATool/Data/Categories/AllDeaths.cs index 93035d4d..a5e249e9 100644 --- a/AATool/Data/Categories/AllDeaths.cs +++ b/AATool/Data/Categories/AllDeaths.cs @@ -12,10 +12,10 @@ public class AllDeaths : Category }; public override IEnumerable GetSupportedVersions() => SupportedVersions; - public override IEnumerable GetOverlayObjectives() => this.Deaths.All.Values; + public override IEnumerable GetOverlayObjectives() => Tracker.Deaths.All.Values; - public override int GetTargetCount() => this.Deaths.Count; - public override int GetCompletedCount() => this.Deaths.TotalExperienced; + public override int GetTargetCount() => Tracker.Deaths.Count; + public override int GetCompletedCount() => Tracker.Deaths.TotalExperienced; public AllDeaths() : base() { @@ -30,8 +30,8 @@ public AllDeaths() : base() public override void LoadObjectives() { - this.Deaths.RefreshObjectives(); - this.Pickups.RefreshObjectives(); + Tracker.Deaths.RefreshObjectives(); + Tracker.Pickups.RefreshObjectives(); } } } diff --git a/AATool/Data/Categories/BalancedDiet.cs b/AATool/Data/Categories/BalancedDiet.cs index 6945b4a9..ed39ec11 100644 --- a/AATool/Data/Categories/BalancedDiet.cs +++ b/AATool/Data/Categories/BalancedDiet.cs @@ -24,8 +24,8 @@ public BalancedDiet() : base() public override void LoadObjectives() { - this.Advancements.RefreshObjectives(); - this.Advancements.TryGet(Id, out Advancement balancedDiet); + Tracker.Advancements.RefreshObjectives(); + Tracker.Advancements.TryGet(Id, out Advancement balancedDiet); this.Requirement = balancedDiet; } } diff --git a/AATool/Data/Categories/Category.cs b/AATool/Data/Categories/Category.cs index 9e483e74..8466f0b6 100644 --- a/AATool/Data/Categories/Category.cs +++ b/AATool/Data/Categories/Category.cs @@ -9,12 +9,6 @@ namespace AATool.Data.Categories { public abstract class Category : ICategory { - public readonly AdvancementManifest Advancements = new (); - public readonly AchievementManifest Achievements = new (); - public readonly PickupManifest Pickups = new (); - public readonly BlockManifest Blocks = new (); - public readonly DeathManifest Deaths = new (); - public string Name { get; protected set; } public string Acronym { get; protected set; } public string Action { get; protected set; } @@ -56,7 +50,7 @@ public bool TrySetVersion(string version) this.CurrentVersion = version; this.CurrentMajorVersion = $"{number.Major}.{number.Minor}"; Config.Tracking.GameVersion.Set(this.CurrentVersion); - this.LoadObjectives(); + Config.Tracking.Save(); return true; } return false; @@ -74,13 +68,5 @@ public float GetCompletionRatio() int clamped = Math.Min(this.GetCompletedCount(), target); return (float)clamped / this.GetTargetCount(); } - - public void SetState(WorldState state) - { - this.Advancements.SetState(state); - this.Achievements.SetState(state); - this.Blocks.SetState(state); - this.Pickups.SetState(state); - } } } diff --git a/AATool/Data/Categories/HalfDeaths.cs b/AATool/Data/Categories/HalfDeaths.cs index 10907f95..36902699 100644 --- a/AATool/Data/Categories/HalfDeaths.cs +++ b/AATool/Data/Categories/HalfDeaths.cs @@ -23,8 +23,8 @@ public HalfDeaths() : base() public override void LoadObjectives() { - this.Deaths.RefreshObjectives(); - this.Pickups.RefreshObjectives(); + Tracker.Deaths.RefreshObjectives(); + Tracker.Pickups.RefreshObjectives(); } } } diff --git a/AATool/Data/Categories/MonstersHunted.cs b/AATool/Data/Categories/MonstersHunted.cs index 13a34cf8..d3e2adf2 100644 --- a/AATool/Data/Categories/MonstersHunted.cs +++ b/AATool/Data/Categories/MonstersHunted.cs @@ -24,8 +24,8 @@ public MonstersHunted() : base() public override void LoadObjectives() { - this.Advancements.RefreshObjectives(); - this.Advancements.TryGet(Id, out Advancement monstersHunted); + Tracker.Advancements.RefreshObjectives(); + Tracker.Advancements.TryGet(Id, out Advancement monstersHunted); this.Requirement = monstersHunted; } } diff --git a/AATool/Data/Objectives/Block.cs b/AATool/Data/Objectives/Block.cs index ab90b941..6b2d6694 100644 --- a/AATool/Data/Objectives/Block.cs +++ b/AATool/Data/Objectives/Block.cs @@ -31,7 +31,7 @@ public Block(XmlNode node) : base (node) public void ToggleManualOverride() { this.ManuallyCompleted ^= true; - Tracker.Category.Blocks.UpdateTotal(); + Tracker.Blocks.UpdateTotal(); } public override void UpdateState(WorldState progress) diff --git a/AATool/Data/Objectives/Death.cs b/AATool/Data/Objectives/Death.cs index bda58eec..a07ec0aa 100644 --- a/AATool/Data/Objectives/Death.cs +++ b/AATool/Data/Objectives/Death.cs @@ -40,7 +40,7 @@ public void Clear() public void ToggleManualOverride() { this.ManuallyCompleted ^= true; - Tracker.Category.Deaths.UpdateTotal(); + Tracker.Deaths.UpdateTotal(); } public override void UpdateState(WorldState progress) diff --git a/AATool/Data/Progress/WorldState.cs b/AATool/Data/Progress/WorldState.cs index c40a394b..19b54be3 100644 --- a/AATool/Data/Progress/WorldState.cs +++ b/AATool/Data/Progress/WorldState.cs @@ -184,7 +184,7 @@ private void SyncAdvancements(WorldFolder world) foreach (Uuid id in world.GetAllUuids()) this.Players[id] = new Contribution(id); - foreach (Advancement advancement in Tracker.Category.Advancements.All.Values) + foreach (Advancement advancement in Tracker.Advancements.All.Values) { //add advancement if completed if (world.Advancements.TryGetAdvancementCompletionFor(advancement.Id, out List ids)) @@ -217,7 +217,7 @@ private void SyncAchievements(WorldFolder world) foreach (Uuid id in world.GetAllUuids()) this.Players[id] = new Contribution(id); - foreach (Achievement achievement in Tracker.Category.Achievements.All.Values) + foreach (Achievement achievement in Tracker.Achievements.All.Values) { //add advancement if completed if (world.Achievements.TryGetAchievementCompletionFor(achievement.Id, out List ids)) @@ -279,7 +279,7 @@ private void SyncStatistics(WorldFolder world) this.EnderChestsMined = world.Statistics.TimesMined("ender_chest"); //pickup counts - foreach (string item in Tracker.Category.Pickups.All.Keys) + foreach (string item in Tracker.Pickups.All.Keys) { int total = world.Statistics.TimesPickedUp(item, out Dictionary countsByPlayer); if (total > 0) @@ -298,7 +298,7 @@ private void SyncStatistics(WorldFolder world) } //block placements - foreach (Block block in Tracker.Category.Blocks.All.Values) + foreach (Block block in Tracker.Blocks.All.Values) { if (!world.Statistics.TryGetUseCount(block.Id, out List ids)) continue; @@ -317,7 +317,7 @@ public void SyncDeathMessages() if (ActiveInstance.TryGetLog(out string log) && Player.TryGetName(Tracker.GetMainPlayer(), out string name)) { log = log.ToLower(); - foreach (Death death in Tracker.Category.Deaths.All.Values) + foreach (Death death in Tracker.Deaths.All.Values) { foreach (string message in death.Messages) { diff --git a/AATool/Graphics/Canvas.cs.bak b/AATool/Graphics/Canvas.cs.bak deleted file mode 100644 index 7b98bbd5..00000000 --- a/AATool/Graphics/Canvas.cs.bak +++ /dev/null @@ -1,241 +0,0 @@ -using System; -using AATool.Configuration; -using AATool.Data.Categories; -using AATool.UI.Screens; -using AATool.Utilities; -using FontStashSharp; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; - -namespace AATool.Graphics -{ - public class Canvas - { - const string AmbientGlowTexture = "glow_ambient"; - - public static void Initialize() - { - Batches = new SpriteBatch[Enum.GetNames(typeof(Layer)).Length]; - foreach (int layer in Enum.GetValues(typeof(Layer))) - Batches[layer] = new SpriteBatch(Main.Device); - CacheBatch = new SpriteBatch(Main.Device); - - //configure graphics parameters - Main.GraphicsManager.GraphicsProfile = GraphicsProfile.Reach; - Main.GraphicsManager.SynchronizeWithVerticalRetrace = true; - Main.GraphicsManager.HardwareModeSwitch = false; - Main.GraphicsManager.ApplyChanges(); - } - - private static SpriteBatch[] Batches; - private static SpriteBatch CacheBatch; - - public static Color RainbowFast { get; private set; } - public static Color RainbowLight { get; private set; } - public static Color RainbowStrong { get; private set; } - - public static int GlobalDrawCalls { get; private set; } - - public int ScreenDrawCalls { get; private set; } - - public Canvas() - { - - } - - public static void Update(Time time) - { - //fade rainbow to next color - RainbowFast = ColorHelper.FromHSV(time.TotalFrames % 360, 0.5, 1.0); - RainbowLight = ColorHelper.FromHSV(time.TotalFrames / 4 % 360, 0.33, 1.0); - RainbowStrong = ColorHelper.FromHSV(time.TotalFrames / 8 % 360, 1.0, 1.0); - } - - private static SpriteBatch BatchOf(Layer layer) => Batches[(int)layer]; - - public void BeginDraw(UIScreen screen, BlendState blend = null) - { - //main layer - if (screen is not UIMainScreen || UIMainScreen.Invalidated) - { - UIMainScreen.RefreshingCache = screen is UIMainScreen; - BatchOf(Layer.Main).Begin(SpriteSortMode.Deferred, - blend ?? BlendState.NonPremultiplied, - SamplerState.PointClamp); - } - - if (screen is UIMainScreen) - { - //used to draw render cached to the backbuffer - CacheBatch.Begin(SpriteSortMode.Deferred, - BlendState.Opaque, - SamplerState.PointClamp); - } - - //lighting layer - BatchOf(Layer.Glow).Begin(SpriteSortMode.Deferred, - BlendState.Additive, - SamplerState.AnisotropicClamp); - - //foreground and animated sprites layer - BatchOf(Layer.Fore).Begin(SpriteSortMode.Deferred, - blend ?? BlendState.NonPremultiplied, - SamplerState.PointClamp); - - GlobalDrawCalls = 0; - this.ScreenDrawCalls = 0; - } - - public void EndDraw(UIScreen screen) - { - bool scaled = Config.Main.DisplayScale > 1; - if (screen is UIMainScreen) - { - //main screen makes use of a render cache for improved performance - if (UIMainScreen.RefreshingCache) - { - //clear cache texture to proper back color - Main.Device.SetRenderTarget(UIMainScreen.RenderCache); - Main.Device.Clear(Tracker.Category is AllBlocks - ? Config.Main.BorderColor - : Config.Main.BackColor); - - //render main layer to cache texture - BatchOf(Layer.Main).End(); - Main.Device.SetRenderTarget(null); - } - - //render cache texture to backbuffer - if (!Config.Main.HideRenderCache) - CacheBatch.Draw(UIMainScreen.RenderCache, Main.Device.Viewport.Bounds, Color.White); - CacheBatch.End(); - } - else - { - //render main layer directly to viewport - BatchOf(Layer.Main).End(); - } - - //render ambient glow effect to viewport if enabled - if (Config.Main.ShowAmbientGlow && screen is not UIOverlayScreen) - this.Draw(AmbientGlowTexture, Main.Device.Viewport.Bounds, RainbowStrong * 0.5f, Layer.Glow); - - //render lighting to viewport - BatchOf(Layer.Glow).End(); - - //render foreground/animated sprites to viewport - BatchOf(Layer.Fore).End(); - } - - public void Draw(Texture2D texture, Rectangle destination, - Color? tint = null, - Layer layer = Layer.Main) - { - if (texture is not null) - { - //draw a texture that isn't part of the main atlas - BatchOf(layer).Draw(texture, - destination, - tint ?? Color.White); - - GlobalDrawCalls++; - this.ScreenDrawCalls++; - } - } - - public void Draw(string texture, Rectangle destination, - Color? tint = null, - Layer layer = Layer.Main) - { - if (SpriteSheet.TryGet(texture, out Sprite sprite, destination.Width)) - { - //draw a portion of the texture atlas - BatchOf(layer).Draw(SpriteSheet.Atlas, - destination, - sprite.Source, - tint ?? Color.White); - - GlobalDrawCalls++; - this.ScreenDrawCalls++; - } - } - - public void Draw(string texture, Rectangle destination, Rectangle subSource, - Color? tint = null, - Layer layer = Layer.Main) - { - if (SpriteSheet.TryGet(texture, out Sprite sprite, destination.Width)) - { - var translated = new Rectangle(sprite.Offset + subSource.Location, subSource.Size); - - //draw a sub-portion of a source rectangle of the texture atlas - BatchOf(layer).Draw(SpriteSheet.Atlas, - destination, - translated, - tint ?? Color.White); - - GlobalDrawCalls++; - this.ScreenDrawCalls++; - } - } - - public void Draw(string texture, Vector2 center, float rotation, - Vector2? scale = null, - Color? tint = null, - Layer layer = Layer.Main) - { - if (SpriteSheet.TryGet(texture, out Sprite sprite)) - { - BatchOf(layer).Draw(SpriteSheet.Atlas, - center, - sprite.Source, - tint ?? Color.White, - rotation, - sprite.Origin, - scale ?? Vector2.One, - SpriteEffects.None, 0); - - GlobalDrawCalls++; - this.ScreenDrawCalls++; - } - } - - public void DrawRectangle(Rectangle rectangle, Color color, - Color? borderColor = null, - int border = 0, - Layer layer = Layer.Main) - { - SpriteBatch batch = BatchOf(layer); - borderColor ??= color; - if (border > 0 && borderColor != color) - { - //draw rectangle with border - batch.Draw(SpriteSheet.Atlas, rectangle, SpriteSheet.Pixel.Source, borderColor.Value); - var inner = new Rectangle(rectangle.X + border, rectangle.Y + border, rectangle.Width - border * 2, rectangle.Height - border * 2); - batch.Draw(SpriteSheet.Atlas, inner, SpriteSheet.Pixel.Source, color); - - //draw rounded corners - Color blended = ColorHelper.Blend(borderColor.Value, color, 0.5f); - batch.Draw(SpriteSheet.Atlas, new Rectangle(rectangle.Left + border, rectangle.Top + border, 1, 1), SpriteSheet.Pixel.Source, blended); - batch.Draw(SpriteSheet.Atlas, new Rectangle(rectangle.Right - (border + 1), rectangle.Top + border, 1, 1), SpriteSheet.Pixel.Source, blended); - batch.Draw(SpriteSheet.Atlas, new Rectangle(rectangle.Right - (border + 1), rectangle.Bottom - (border + 1), 1, 1), SpriteSheet.Pixel.Source, blended); - batch.Draw(SpriteSheet.Atlas, new Rectangle(rectangle.Left + border, rectangle.Bottom - (border + 1), 1, 1), SpriteSheet.Pixel.Source, blended); - GlobalDrawCalls += 6; - this.ScreenDrawCalls += 6; - } - else - { - batch.Draw(SpriteSheet.Atlas, rectangle, SpriteSheet.Pixel.Source, color); - GlobalDrawCalls++; - this.ScreenDrawCalls++; - } - } - - public void DrawString(DynamicSpriteFont font, string text, Vector2 location, Color color, Layer layer = Layer.Main) - { - BatchOf(layer).DrawString(font, text, location, color); - GlobalDrawCalls++; - this.ScreenDrawCalls++; - } - } -} diff --git a/AATool/Properties/AssemblyInfo.cs b/AATool/Properties/AssemblyInfo.cs index b21985b1..367c5cb6 100644 --- a/AATool/Properties/AssemblyInfo.cs +++ b/AATool/Properties/AssemblyInfo.cs @@ -33,6 +33,6 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.4.2.0")] -[assembly: AssemblyFileVersion("1.4.2.0")] +[assembly: AssemblyVersion("1.4.2.1")] +[assembly: AssemblyFileVersion("1.4.2.1")] [assembly: NeutralResourcesLanguage("en")] diff --git a/AATool/Saves/WorldFolder.cs b/AATool/Saves/WorldFolder.cs index 0d3f1156..ffd7663d 100644 --- a/AATool/Saves/WorldFolder.cs +++ b/AATool/Saves/WorldFolder.cs @@ -77,7 +77,7 @@ public void SetPath(DirectoryInfo worldFolder) if (worldFolder.FullName != this.CurrentFolder?.FullName) { ActiveInstance.SetLogStart(); - foreach (Death death in Tracker.Category.Deaths.All.Values) + foreach (Death death in Tracker.Deaths.All.Values) death.Clear(); this.CurrentFolder = worldFolder; diff --git a/AATool/Tracker.cs b/AATool/Tracker.cs index 773363a9..61950e4e 100644 --- a/AATool/Tracker.cs +++ b/AATool/Tracker.cs @@ -16,7 +16,13 @@ namespace AATool public static class Tracker { private const double RefreshInterval = 1.0; - + + public static readonly AdvancementManifest Advancements = new (); + public static readonly AchievementManifest Achievements = new (); + public static readonly PickupManifest Pickups = new (); + public static readonly BlockManifest Blocks = new (); + public static readonly DeathManifest Deaths = new (); + public static Category Category { get; private set; } public static WorldState State { get; private set; } public static Exception LastError { get; private set; } @@ -36,8 +42,8 @@ public static class Tracker public static void ToggleWorldLock() => WorldLocked ^= true; public static AdvancementManifest CurrentAdvancementSet => Category is not AllAchievements - ? Category.Advancements - : Category.Achievements; + ? Advancements + : Achievements; public static Dictionary<(string adv, string crit), Criterion> CurrentCriteriaSet => CurrentAdvancementSet.Criteria; @@ -68,16 +74,16 @@ public static bool TryGetCriterion(string adv, string crit, out Criterion criter CurrentCriteriaSet.TryGetValue((adv, crit), out criterion); public static bool TryGetAdvancementGroup(string id, out HashSet group) => - Category.Advancements.TryGet(id, out group); + Advancements.TryGet(id, out group); public static bool TryGetPickup(string id, out Pickup item) => - Category.Pickups.TryGet(id, out item); + Pickups.TryGet(id, out item); public static bool TryGetBlock(string id, out Block block) => - Category.Blocks.TryGet(id, out block); + Blocks.TryGet(id, out block); public static bool TryGetDeath(string id, out Death death) => - Category.Deaths.TryGet(id, out death); + Deaths.TryGet(id, out death); public static Uuid GetMainPlayer() => State.Players.Keys.FirstOrDefault(); @@ -154,7 +160,7 @@ public static bool TrySetCategory(string category) Category.LoadObjectives(); return true; } - catch (ArgumentException e) + catch { if (Category is null) { @@ -345,7 +351,11 @@ private static void ParseCoOpProgress(Client client) TrySetCategory(State.GameCategory); TrySetVersion(State.GameVersion); - Category.SetState(State); + //reload objectives if game version has changed + if (ObjectivesChanged) + Category.LoadObjectives(); + + SetState(State); if (Config.Tracking.BroadcastProgress) OpenTracker.BroadcastProgress(); @@ -355,8 +365,8 @@ private static void ParseCoOpProgress(Client client) private static void ReadLocalFiles() { //reload objective manifests if game version has changed - //if (ObjectivesChanged) - // RefreshObjectives(); + if (ObjectivesChanged) + Category.LoadObjectives(); //wait to refresh until sftp transer is complete if (Config.Tracking.UseSftp && SftpSave.IsDownloading) @@ -367,7 +377,7 @@ private static void ReadLocalFiles() { LastServerMessage = null; State = World.GetState(); - Category.SetState(State); + SetState(State); //broadcast changes to connected clients if server is running if (Server.TryGet(out Server server) && server.Connected()) @@ -385,9 +395,17 @@ private static void ReadLocalFiles() State.SyncDeathMessages(); if (State.DeathMessages.Count != before) { - Category.Deaths.SetState(State); + Deaths.SetState(State); } } } + + private static void SetState(WorldState state) + { + Advancements.SetState(state); + Achievements.SetState(state); + Blocks.SetState(state); + Pickups.SetState(state); + } } } diff --git a/AATool/UI/Controls/UIBlockGroup.cs b/AATool/UI/Controls/UIBlockGroup.cs index 62f4f67d..442c2bf1 100644 --- a/AATool/UI/Controls/UIBlockGroup.cs +++ b/AATool/UI/Controls/UIBlockGroup.cs @@ -35,7 +35,7 @@ public override void InitializeThis(UIScreen screen) private void Populate() { //start adding from beginning if no start id specified - if (!Tracker.Category.Blocks.TryGetGroup(this.GroupId, out this.blocks)) + if (!Tracker.Blocks.TryGetGroup(this.GroupId, out this.blocks)) return; foreach (Block block in this.blocks) diff --git a/AATool/UI/Controls/UIObjectiveFrame.cs b/AATool/UI/Controls/UIObjectiveFrame.cs index cc2f2497..c002ef14 100644 --- a/AATool/UI/Controls/UIObjectiveFrame.cs +++ b/AATool/UI/Controls/UIObjectiveFrame.cs @@ -79,6 +79,11 @@ public void SetObjective(Objective objective) public void AutoSetObjective() { + if (this.ObjectiveId is "minecraft:nether/root") + { + //this.AutoSetObjective(); + } + if (this.objectiveType == typeof(Advancement)) { if (Tracker.TryGetAdvancement(this.ObjectiveId, out Advancement objective)) @@ -213,6 +218,11 @@ private void UpdateGlowBrightness(Time time) ? 0.15f : 0; + if (this.Objective?.Id is "minecraft:nether/root") + { + //this.AutoSetObjective(); + } + if (this.ObjectiveCompleted) { target = 1; diff --git a/AATool/UI/Controls/UIPlayer.cs b/AATool/UI/Controls/UIPlayer.cs index cc9001ef..e922659e 100644 --- a/AATool/UI/Controls/UIPlayer.cs +++ b/AATool/UI/Controls/UIPlayer.cs @@ -37,7 +37,7 @@ public override void InitializeRecursive(UIScreen screen) this.flow = this.First("items"); this.itemCounts = new Dictionary(); - foreach (string item in Tracker.Category.Pickups.All.Keys) + foreach (string item in Tracker.Pickups.All.Keys) { if (this.First(item) is UITextBlock label) this.itemCounts[item] = label; diff --git a/AATool/UI/Screens/UIMainScreen.cs b/AATool/UI/Screens/UIMainScreen.cs index c0b89a6f..a35252b0 100644 --- a/AATool/UI/Screens/UIMainScreen.cs +++ b/AATool/UI/Screens/UIMainScreen.cs @@ -41,7 +41,6 @@ public UIMainScreen(Main main) : base(main, main.Window) this.Form.FormClosing += this.OnFormClosing; this.settingsCooldown = new Utilities.Timer(0.1f); //this.Form.Location = new System.Drawing.Point(0, 0); - this.ReloadView(); this.CenterWindow(); } @@ -159,7 +158,7 @@ private void Click(UIControl sender) if (sender == this.resetDeaths) { ActiveInstance.SetLogStart(); - foreach (Death death in Tracker.Category.Deaths.All.Values) + foreach (Death death in Tracker.Deaths.All.Values) death.Clear(); } } diff --git a/AATool/UI/Screens/UIOverlayScreen.cs b/AATool/UI/Screens/UIOverlayScreen.cs index 7ae83b4c..9424dcf0 100644 --- a/AATool/UI/Screens/UIOverlayScreen.cs +++ b/AATool/UI/Screens/UIOverlayScreen.cs @@ -149,7 +149,7 @@ public override void InitializeThis(UIScreen screen) if (Tracker.Category is not (AllBlocks or AllDeaths)) { //add pickup counters - foreach (Pickup pickup in Tracker.Category.Pickups.All.Values.Reverse()) + foreach (Pickup pickup in Tracker.Pickups.All.Values.Reverse()) this.counts.AddControl(new UIObjectiveFrame(pickup, 3)); }