Skip to content

Commit

Permalink
Finalize all blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
DarwinBaker committed Oct 14, 2022
1 parent a0ec611 commit a307857
Show file tree
Hide file tree
Showing 28 changed files with 859 additions and 595 deletions.
186 changes: 144 additions & 42 deletions AATool/AATool.csproj

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions AATool/Data/Objectives/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using AATool.Configuration;
using AATool.Data.Progress;
using AATool.Net;
using AATool.Utilities;
Expand Down Expand Up @@ -30,6 +31,11 @@ public class Block : Objective

public void ToggleHighlight() => this.Highlighted ^= true;

public override bool IsComplete()
{
return this.CompletedByAnyone();
}

public Block(XmlNode node) : base (node)
{
this.Id = $"minecraft:{node.Name}";
Expand Down
5 changes: 5 additions & 0 deletions AATool/Data/Objectives/BlockManifest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ public class BlockManifest : IManifest
public int PlacedCount { get; private set; }
public int Count => this.All.Count;

public List<Block> AllBlocksList;

public BlockManifest()
{
this.All = new();
this.Groups = new();
this.AllBlocksList = new();
}

public bool TryGet(string id, out Block block) =>
Expand All @@ -33,6 +36,7 @@ public void ClearObjectives()
this.All.Clear();
this.PlacedCount = 0;
this.ObtainedCount = 0;
this.AllBlocksList.Clear();
}

public void RefreshObjectives()
Expand All @@ -56,6 +60,7 @@ public void RefreshObjectives()
//add all blocks in group
var block = new Block(blockNode);
this.All[block.Id] = block;
this.AllBlocksList.Add(block);
group.Add(block);
}
this.Groups[groupNode.Name] = group;
Expand Down
2 changes: 1 addition & 1 deletion AATool/Data/Objectives/Objective.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public abstract class Objective : IObjective
public abstract string GetFullCaption();
public abstract string GetShortCaption();

public bool IsComplete()
public virtual bool IsComplete()
{
return Config.Tracking.Filter == ProgressFilter.Combined || Peer.IsRunning
? this.CompletedByAnyone()
Expand Down
3 changes: 2 additions & 1 deletion AATool/Graphics/Canvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ public void Draw(string texture, Vector2 center, float rotation,
rotation,
sprite.Origin,
scale ?? Vector2.One,
SpriteEffects.None, 0);
SpriteEffects.None,
0);

GlobalDrawCalls++;
this.ScreenDrawCalls++;
Expand Down
10 changes: 8 additions & 2 deletions AATool/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
using System.Globalization;
using AATool.UI.Badges;
using AATool.Data.Speedrunning;
using System.Runtime;

namespace AATool
{
Expand Down Expand Up @@ -89,12 +90,17 @@ protected override void Initialize()
FontSet.Initialize();
Leaderboard.Initialize();

//check for updates in the background
new UpdateRequest().EnqueueOnce();
//get last player's identity
if (!string.IsNullOrEmpty(Config.Tracking.LastPlayer))
Player.FetchIdentityAsync(Config.Tracking.LastPlayer);

//get solo player's identity
if (Config.Tracking.Filter == ProgressFilter.Solo)
Player.FetchIdentityAsync(Config.Tracking.SoloFilterName);

//check for updates
new UpdateRequest().EnqueueOnce();

//check build number of last aatool session
Version.TryParse(Config.Tracking.LastSession, out Version lastSession);
if (lastSession is null || lastSession < Version.Parse("1.3.2"))
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.4.8.2")]
[assembly: AssemblyFileVersion("1.4.8.2")]
[assembly: AssemblyVersion("1.5.0.0")]
[assembly: AssemblyFileVersion("1.5.0.0")]
[assembly: NeutralResourcesLanguage("en")]
9 changes: 8 additions & 1 deletion AATool/Tracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,15 @@ public static Uuid GetMainPlayer()
else
mainPlayer = State.Players.Keys.FirstOrDefault();

if (mainPlayer == Uuid.Empty)
{
if (Config.Tracking.LastUuid != Uuid.Empty)
mainPlayer = Config.Tracking.LastUuid;
else
Player.TryGetUuid(Config.Tracking.LastPlayer, out mainPlayer);
}

MainPlayerChanged |= mainPlayer != PreviousMainPlayer;
Config.Tracking.LastPlayer.Set(mainPlayer);
return PreviousMainPlayer = mainPlayer;
}

Expand Down
162 changes: 162 additions & 0 deletions AATool/UI/Controls/UIAllayTrack.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
using System.Collections.Generic;
using AATool.Data.Objectives;
using AATool.Graphics;
using AATool.Utilities.Easings;
using Microsoft.Xna.Framework;

namespace AATool.UI.Controls
{
public class UIAllayTrack : UIPanel
{
private class Allay
{
public const int HorizontalOffset = 75;
public const int AllaySize = 48;
public const int BlockSize = 32;
public const int VerticalFlyRange = 16;
public const float GlowRotationSpeed = 0.25f;

public static float GlowRotation { get; set; } = 0f;

private static int StartingIndex;

private Easing easing = new Easing(Ease.Sinusoidal, 1.25, true, false);
private UIAllayTrack track;
private Block block;
private float xOffset;
private Rectangle bounds;
private Rectangle plateBounds;
private Rectangle blockBounds;
private bool movingUp = true;

public static void UpdateGlowRotation(Time time) =>
GlowRotation += (float)(GlowRotationSpeed * time.Delta);

public Allay(UIAllayTrack track, int offset)
{
this.PickBlock();
this.track = track;
this.xOffset = track.Inner.Left + offset - HorizontalOffset;
this.bounds = new Rectangle(
(int)this.xOffset,
this.track.Inner.Center.Y,
AllaySize, AllaySize);

double timingOffset = this.easing.Duration / (StartingIndex % 2 * 4);
this.easing.TimeLeft -= timingOffset;
this.easing.TimeElapsed += timingOffset;
StartingIndex++;
}

private void PickBlock()
{
do
{
int randomBlockIndex = Main.RNG.Next(0, Tracker.Blocks.AllBlocksList.Count);
this.block = Tracker.Blocks.AllBlocksList[randomBlockIndex];
}
while (this.block.DoubleHeight);
}

public void Update(Time time)
{
this.easing.Update(time);

int offsetY = this.movingUp
? (int)(this.easing.InOut() * VerticalFlyRange)
: VerticalFlyRange - (int)(this.easing.InOut() * VerticalFlyRange);

if (this.easing.IsExpired)
{
this.movingUp ^= true;
this.easing.Reset();
}

this.xOffset += 1f;
this.bounds = new Rectangle(
(int)this.xOffset,
this.track.Top + offsetY, //* direction,
AllaySize, AllaySize);

this.plateBounds = new Rectangle(
this.bounds.Center.X - 4,
this.bounds.Center.Y + 4,
48, 24);

if (this.block.DoubleHeight)
{
this.blockBounds = new Rectangle(
this.plateBounds.Center.X - 16,
this.plateBounds.Top - 46,
32,
64);
}
else
{
this.blockBounds = new Rectangle(
this.plateBounds.Center.X - 16,
this.plateBounds.Top - 14,
BlockSize,
BlockSize);
}


if (this.bounds.Left > this.track.Right)
this.Reset();
}

private void Reset()
{
this.PickBlock();
this.xOffset = this.track.Inner.Left- HorizontalOffset;
}

public void Draw(Canvas canvas)
{
canvas.Draw(
"player_frame_diamond_glow",
this.bounds.Center.ToVector2() + new Vector2(6, 0),
GlowRotation,
new Vector2(0.65f),
Color.White * 0.75f,
Layer.Fore);

canvas.Draw("allay_fly", this.bounds, Color.White, Layer.Fore);
canvas.Draw("allay_plate", this.plateBounds, Color.White, Layer.Fore);
canvas.Draw(this.block.Icon, this.blockBounds, Color.White, Layer.Fore);
}
}

private List<Allay> allays = new List<Allay>();
private int allayCount = 6;

private void Populate()
{
this.allays.Clear();
int spacing = (this.Inner.Width + Allay.HorizontalOffset) / this.allayCount;
for (int i = 0; i < this.allayCount; i++)
{
this.allays.Add(new Allay(this, i * spacing));
}
}

public override void ResizeThis(Rectangle parent)
{
base.ResizeThis(parent);
this.Populate();
}

protected override void UpdateThis(Time time)
{
Allay.UpdateGlowRotation(time);
foreach (Allay allay in this.allays)
allay.Update(time);
}

public override void DrawThis(Canvas canvas)
{
foreach (Allay allay in this.allays)
allay.Draw(canvas);
}
}
}
19 changes: 18 additions & 1 deletion AATool/UI/Controls/UIBlockGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,21 @@ class UIBlockGrid : UIControl
private readonly Dictionary<(int row, int col), UIBlockTile> blockTiles = new ();

private UIBlockPopup popup;
private UIBlockMessage message;
private UITextInput searchInput;
private UITextBlock searchResults;
private UIControl searchShortcut;
private UIPanel loadingPanel;
private UIPanel errorPanel;
private UITextBlock errorMessage;

private int blockTileRows;
private int blockTileColumns;
private int blocksFound;
private bool clearedSelection;

public bool IsSearching => this.searchInput.State is ControlState.Pressed;
public bool IsActive => !this.message.IsPopupVisible;

public void RegisterBlockTile(UIBlockTile block)
{
Expand All @@ -64,18 +69,30 @@ public void RegisterBlockTile(UIBlockTile block)
public override void InitializeThis(UIScreen screen)
{
this.popup = this.Root().First<UIBlockPopup>();
this.message = this.Root().First<UIBlockMessage>();
this.searchInput = this.Root().First<UITextInput>("block_search");
if (this.searchInput is not null)
this.searchInput.OnTextChanged += this.BlockSearchTextChanged;
this.searchResults = this.Root().First<UITextBlock>("block_search_results");
this.searchShortcut = this.Root().First("block_search_shortcut");
this.loadingPanel = this.Root().First<UIPanel>("blocks_loading");
this.errorPanel = this.Root().First<UIPanel>("blocks_error");
this.errorMessage = this.errorPanel?.First<UITextBlock>();
}

protected override void UpdateThis(Time time)
{
if (!this.IsActive)
return;

this.UpdateShortcuts();
this.UpdateSelection();

this.loadingPanel?.SetVisibility(!AllBlocks.MainSpritesLoaded);
this.errorPanel?.SetVisibility(!Tracker.IsWorking);
if (!Tracker.IsWorking)
this.errorMessage?.SetText(Tracker.GetStatusText());

bool wasDim = this.DimScreen;
this.DimScreen = this.MakingSelection || this.SelectionMade || this.Searching;
if (this.DimScreen != wasDim)
Expand Down Expand Up @@ -116,7 +133,7 @@ private void UpdateShortcuts()
private void UpdateSelection()
{
//this function is huge and complicated for many important reasons
//and now that it works we are going to hope we don't need to touch it again
//now that it works we're going to hope we don't need to touch it again
if (Tracker.Category is not AllBlocks || UIMainScreen.ActiveTab is not UIMainScreen.TrackerTab)
return;

Expand Down
3 changes: 3 additions & 0 deletions AATool/UI/Controls/UIBlockGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public override void DrawThis(Canvas canvas)

protected override void UpdateThis(Time time)
{
if (!this.blockGrid.IsActive)
return;

Point cursor = Input.Cursor(this.Root());

//optimization, skip almost all unnecessary block hover checks
Expand Down
Loading

0 comments on commit a307857

Please sign in to comment.