Skip to content

Commit

Permalink
Main program changes
Browse files Browse the repository at this point in the history
  • Loading branch information
DarwinBaker committed Jan 25, 2022
1 parent 546984a commit c7fb657
Show file tree
Hide file tree
Showing 9 changed files with 1,080 additions and 955 deletions.
1,722 changes: 899 additions & 823 deletions AATool/AATool.csproj

Large diffs are not rendered by default.

38 changes: 16 additions & 22 deletions AATool/Enums.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
namespace AATool
{
//data structures
public enum FrameType { Normal, Goal, Challenge }

public enum SaveFolderState
//used for save reading
public enum SaveState
{
Valid,
NoWorlds,
NonExistentPath,
EmptyPath,
InvalidPath,
PathNonExistent,
PathEmpty,
PathInvalid,
PathTooLong,
PermissionError
PermissionError,
}

//used for sftp
public enum SyncState
{
Ready,
Expand All @@ -24,19 +23,14 @@ public enum SyncState
Statistics,
}

//ui
//ui and rendering
public enum HorizontalAlign { Center, Left, Right }
public enum VerticalAlign { Center, Top, Bottom }
public enum FlowDirection { LeftToRight, RightToLeft, TopToBottom, BottomToTop }
public enum SizeMode { Absolute, Relative }
public enum DrawMode { All, ThisOnly, ChildrenOnly, None }
public enum UIButtonState { Released, Hovered, Pressed, Disabled }
public enum UIRefreshStyle { Compass, Xp }

//graphics
public enum Layer { Main, Glow, Fore }

//misc
public enum Ease { Back, Bounce, Circular, Cubic, Elastic, Exponential, Quadratic, Quartic, Quintic, Sinusoidal }
public enum SupportTier { Developer, BetaTester, PatreonGold, PatreonDiamond, PatreonNetherite }
public enum VerticalAlign { Center, Top, Bottom }
public enum FlowDirection { LeftToRight, RightToLeft, TopToBottom, BottomToTop }
public enum SizeMode { Absolute, Relative }
public enum DrawMode { All, ThisOnly, ChildrenOnly, None }
public enum ButtonState { Released, Hovered, Pressed, Disabled }
public enum FrameType { Normal, Goal, Challenge, Statistic }
public enum Layer { Main, Glow, Fore }
public enum Ease { Back, Bounce, Circular, Cubic, Elastic, Exponential, Quadratic, Quartic, Quintic, Sinusoidal }
}
89 changes: 44 additions & 45 deletions AATool/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Reflection;
using AATool.Graphics;
using AATool.UI.Screens;
using AATool.Settings;
using AATool.Configuration;
using System.Diagnostics;
using AATool.Utilities;
using System.IO;
Expand Down Expand Up @@ -37,9 +37,6 @@ public class Main : Game
|| ||
====================================================HDWGH?*/


public static readonly bool IsBeta = false;

public static bool IsClosing { get; set; }
public static string FullTitle { get; private set; }
public static string ShortTitle { get; private set; }
Expand All @@ -52,32 +49,25 @@ public class Main : Game

public readonly Time Time;

private Display display;
private Canvas canvas;
private FNotes notesWindow;

private bool announceUpdate;

public static bool IsBeta => FullTitle.ToLower().Contains("beta");
public static bool IsModded => !string.IsNullOrEmpty(ModderName);

private void AddScreen(UIScreen screen)
{
if (SecondaryScreens.TryGetValue(screen.GetType(), out UIScreen old))
old.Dispose();
SecondaryScreens[screen.GetType()] = screen;
}

public Main()
{
this.UpdateTitle();

Version = Assembly.GetExecutingAssembly().GetName().Version;
Graphics = new GraphicsDeviceManager(this);
RNG = new Random();

if (Config.Main.FpsCap is 0)
this.TargetElapsedTime = TimeSpan.FromSeconds(1.0 / 60);
else
this.TargetElapsedTime = TimeSpan.FromSeconds(1.0 / Config.Main.FpsCap);
Config.Initialize();

this.TargetElapsedTime = Config.Main.FpsCap == 0
? TimeSpan.FromSeconds(1.0 / 60)
: TimeSpan.FromSeconds(1.0 / Config.Main.FpsCap);
this.InactiveSleepTime = TimeSpan.Zero;
this.IsFixedTimeStep = true;
this.IsMouseVisible = true;
Expand All @@ -86,19 +76,22 @@ public Main()

protected override void Initialize()
{
this.display = new Display(Graphics);
this.canvas = new Canvas(Graphics);

//load assets
Tracker.Initialize();
SpriteSheet.Initialize(this.GraphicsDevice);
FontSet.Initialize(this.GraphicsDevice);
NetRequest.Enqueue(new UpdateRequest());

Version.TryParse(Config.Tracker.LastAAToolRun, out Version lastVersion);
if (lastVersion is null || lastVersion < Version.Parse("1.3.2"))
//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"))
this.announceUpdate = true;
Config.Tracker.LastAAToolRun = Version.ToString();
Config.Tracker.Save();
Config.Tracking.LastSession.Set(Version.ToString());
Config.Tracking.Save();

this.UpdateTitle();

//instantiate screens
SecondaryScreens = new ();
Expand All @@ -112,11 +105,11 @@ protected override void Initialize()
protected override void Update(GameTime gameTime)
{
this.Time.Update(gameTime);
this.display.Update(this.Time);
this.canvas.Update(this.Time);

//check minecraft version
GameVersionDetector.Update();
Tracker.Update(this.Time);
Tracker.TryUpdate(this.Time);
SftpSave.Update(this.Time);

//update visibilty of update popup
Expand All @@ -132,7 +125,7 @@ protected override void Update(GameTime gameTime)
screen.UpdateRecursive(this.Time);

//update notes screen
if (NotesSettings.Instance.Enabled)
if (Config.Notes.Enabled)
{
if (this.notesWindow is null || this.notesWindow.IsDisposed)
{
Expand All @@ -149,20 +142,20 @@ protected override void Update(GameTime gameTime)
this.notesWindow.Close();
}

if (Config.Main.FpsCapChanged())
if (Config.Main.FpsCap.Changed)
{
this.TargetElapsedTime = TimeSpan.FromSeconds(1.0 / Config.Main.FpsCap);
this.UpdateTitle();
}
else if (Config.Tracker.GameVersionChanged() || Tracker.InGameTimeChanged)
else if (Tracker.ObjectivesChanged || Tracker.InGameTimeChanged)
{
this.UpdateTitle();
}

NetRequest.Update(this.Time);
SpriteSheet.Update(this.Time);
base.Update(gameTime);
Config.ClearFlags();
Config.ClearAllFlags();
Tracker.ClearFlags();
Peer.ClearFlags();
}
Expand All @@ -174,19 +167,26 @@ protected override void Draw(GameTime gameTime)
//render each secondary screen to its respective viewport
foreach (UIScreen screen in SecondaryScreens.Values)
{
screen.Prepare(this.display);
screen.DrawRecursive(this.display);
screen.Present(this.display);
screen.Prepare(this.canvas);
screen.DrawRecursive(this.canvas);
screen.Present(this.canvas);
}

//render main screen to default backbuffer
PrimaryScreen.Prepare(this.display);
PrimaryScreen.DrawRecursive(this.display);
PrimaryScreen.Present(this.display);
PrimaryScreen.Prepare(this.canvas);
PrimaryScreen.DrawRecursive(this.canvas);
PrimaryScreen.Present(this.canvas);
base.Draw(gameTime);
}
}

private void AddScreen(UIScreen screen)
{
if (SecondaryScreens.TryGetValue(screen.GetType(), out UIScreen old))
old.Dispose();
SecondaryScreens[screen.GetType()] = screen;
}

private void ShowUpdateScreen()
{
this.AddScreen(new UIUpdateScreen(this, this.announceUpdate));
Expand All @@ -196,29 +196,28 @@ private void ShowUpdateScreen()

private void UpdateTitle()
{
Version = Assembly.GetExecutingAssembly().GetName().Version;
string name = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyTitleAttribute>().Title;
string extra = Assembly.GetExecutingAssembly()
.GetCustomAttributes(typeof(AssemblyDescriptionAttribute), false)
.OfType<AssemblyDescriptionAttribute>()
.FirstOrDefault()?.Description ?? string.Empty;

ShortTitle = $"{name} {Version}";
FullTitle = ShortTitle;

if (!string.IsNullOrWhiteSpace(extra))
FullTitle += $" {extra}";
ShortTitle += $" {extra}";

FullTitle = ShortTitle;
if (!string.IsNullOrWhiteSpace(ModderName))
FullTitle += $" - UNOFFICIALLY MODIFIED BY: {ModderName}";

FullTitle += $" | Minecraft {Config.Tracker.GameVersion}";
if (Config.Main.FpsCap < 60)
FullTitle += $" | {Config.Main.FpsCap} FPS Cap";
FullTitle += $" | {Tracker.Category.CurrentVersion} {Tracker.Category.Name}";
if (Tracker.InGameTime > TimeSpan.Zero)
FullTitle += $" | { Tracker.InGameTime} IGT";
FullTitle += $" | { Tracker.InGameTime:hh':'mm':'ss} IGT";
if (Config.Main.FpsCap < 60)
FullTitle += $" | {Config.Main.FpsCap.Value} FPS Cap";
if (PrimaryScreen is not null)
PrimaryScreen.Form.Text = " " + FullTitle;

}

public static void QuitBecause(string reason, Exception exception = null)
Expand All @@ -241,7 +240,7 @@ public static void QuitBecause(string reason, Exception exception = null)
message += $"\n\n{exception.GetType()}:{exception.StackTrace}";
DialogResult result = MessageBox.Show(message, caption, MessageBoxButtons.YesNo, MessageBoxIcon.Error);
if (result is DialogResult.Yes)
_ = Process.Start(Paths.URL_GITHUB_LATEST);
_ = Process.Start(Paths.Web.LatestRelease);
}
}
}
Expand Down
Loading

0 comments on commit c7fb657

Please sign in to comment.