-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit bf59be4
Showing
12 changed files
with
655 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,27 @@ | ||
|
||
# user-specific files | ||
*.suo | ||
*.user | ||
*.userosscache | ||
*.sln.docstates | ||
|
||
# build results | ||
[Dd]ebug/ | ||
[Rr]elease/ | ||
[Bb]in/ | ||
[Oo]bj/ | ||
_releases/ | ||
|
||
# Visual Studio cache/options | ||
.vs/ | ||
|
||
# ReSharper | ||
_ReSharper*/ | ||
*.[Rr]e[Ss]harper | ||
*.DotSettings.user | ||
|
||
# NuGet packages | ||
*.nupkg | ||
**/packages/* | ||
*.nuget.props | ||
*.nuget.targets |
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,25 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.30804.86 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SpeedrunPractice", "SpeedrunPractice\SpeedrunPractice.csproj", "{DB5337FB-B148-4A01-A603-C7664418B04E}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{DB5337FB-B148-4A01-A603-C7664418B04E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{DB5337FB-B148-4A01-A603-C7664418B04E}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{DB5337FB-B148-4A01-A603-C7664418B04E}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{DB5337FB-B148-4A01-A603-C7664418B04E}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {FCAAF1A5-A8BC-49C1-B6B4-0E2F195C27C5} | ||
EndGlobalSection | ||
EndGlobal |
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,26 @@ | ||
using StardewModdingAPI; | ||
using StardewValley; | ||
|
||
class Alerts | ||
{ | ||
public static void Success(string message) | ||
{ | ||
HUDMessage hudMessage = new HUDMessage(message, HUDMessage.achievement_type); | ||
hudMessage.timeLeft = 1500f; | ||
Game1.addHUDMessage(hudMessage); | ||
} | ||
|
||
public static void Failure(string message) | ||
{ | ||
HUDMessage hudMessage = new HUDMessage(message, HUDMessage.error_type); | ||
hudMessage.timeLeft = 1500f; | ||
Game1.addHUDMessage(hudMessage); | ||
} | ||
|
||
public static void Info(string message) | ||
{ | ||
HUDMessage hudMessage = new HUDMessage(message, HUDMessage.newQuest_type); | ||
hudMessage.timeLeft = 1500f; | ||
Game1.addHUDMessage(hudMessage); | ||
} | ||
} |
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,103 @@ | ||
using Microsoft.Xna.Framework; | ||
using Microsoft.Xna.Framework.Graphics; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using StardewModdingAPI; | ||
using StardewValley; | ||
using StardewValley.Tools; | ||
//using Rectangle = xTile.Dimensions.Rectangle; | ||
|
||
|
||
namespace SpeedrunPractice.Framework | ||
{ | ||
public class AnimationCancelHelper | ||
{ | ||
private bool isCancellableSwing; | ||
private const int FadeCounterMax = 60; | ||
private int fadeCounter; | ||
private Color TooEarlyColor = Color.Red; | ||
private Color ValidColor = Color.Green; | ||
private int CurrentFrame; | ||
private List<int> AnimationFrames; | ||
private List<Color> AnimationColors; | ||
private TimeSpan FrameTimeSpan = new TimeSpan(166667); | ||
private List<int> ValidAnimationTypes; | ||
|
||
public AnimationCancelHelper() | ||
{ | ||
ValidAnimationTypes = new List<int>() | ||
{ | ||
FarmerSprite.toolUp, | ||
FarmerSprite.toolRight, | ||
FarmerSprite.toolDown, | ||
FarmerSprite.toolLeft, | ||
180, 172, 164, 188 // watering can based | ||
}; | ||
} | ||
|
||
public void Update(IMonitor monitor, IModHelper helper) | ||
{ | ||
if (PlayerInfo.UsingTool && !(PlayerInfo.CurrentTool is MeleeWeapon) && PlayerInfo.CurrentSprite != null) | ||
{ | ||
int animationType = PlayerInfo.AnimationType; | ||
if (!isCancellableSwing) | ||
CurrentFrame = 1; | ||
else | ||
CurrentFrame++; | ||
isCancellableSwing = ValidAnimationTypes.Contains(animationType); | ||
fadeCounter = FadeCounterMax; | ||
GetAnimationCancelDetails(PlayerInfo.CurrentSprite, out AnimationFrames, out AnimationColors); | ||
|
||
} | ||
else | ||
{ | ||
isCancellableSwing = false; | ||
if (fadeCounter > 0) | ||
{ | ||
fadeCounter--; | ||
} | ||
if (fadeCounter <= 0) | ||
{ | ||
AnimationFrames = null; | ||
AnimationColors = null; | ||
CurrentFrame = -1; | ||
} | ||
} | ||
|
||
} | ||
|
||
public void Draw(SpriteBatch spriteBatch) | ||
{ | ||
// draw centered quarter screen | ||
// draw 1/3 down from top | ||
// draw rectangle | ||
Vector2 playerTile = Game1.player.getTileLocation(); | ||
Rectangle progressRectGlobal = new Rectangle((int)(playerTile.X - 3 + 0.5) * Game1.tileSize, (int)(playerTile.Y - 2) * Game1.tileSize, Game1.tileSize * 6, Game1.tileSize / 2); | ||
Rectangle progressRect = Game1.GlobalToLocal(Game1.viewport, progressRectGlobal); | ||
if (fadeCounter > 0) | ||
{ | ||
DrawHelper.DrawProgressBar(spriteBatch, progressRect, AnimationFrames, AnimationColors, CurrentFrame, Color.LightYellow); | ||
} | ||
} | ||
|
||
private void GetAnimationCancelDetails(FarmerSprite sprite, out List<int> animationFrames, out List<Color> animationState) | ||
{ | ||
animationFrames = new List<int>(); | ||
animationState = new List<Color>(); | ||
bool canAnimCancel = false; | ||
for(int i = 0; i < sprite.CurrentAnimation.Count; i++) | ||
{ | ||
int frames = Math.Max(1, (int)((sprite.CurrentAnimation[i].milliseconds + FrameTimeSpan.Milliseconds - 1) / FrameTimeSpan.TotalMilliseconds)); | ||
animationFrames.Add(frames); | ||
if (sprite.CurrentAnimation[i].frameStartBehavior != null && sprite.CurrentAnimation[i].frameStartBehavior.Method.Name.Equals("useTool")) | ||
canAnimCancel = true; | ||
if (i > 0 && sprite.CurrentAnimation[i-1].frameEndBehavior != null && sprite.CurrentAnimation[i-1].frameEndBehavior.Method.Name.Equals("useTool")) | ||
canAnimCancel = true; | ||
animationState.Add(canAnimCancel ? ValidColor : TooEarlyColor); | ||
} | ||
} | ||
} | ||
} |
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,83 @@ | ||
using Microsoft.Xna.Framework; | ||
using Microsoft.Xna.Framework.Graphics; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using StardewValley; | ||
|
||
namespace SpeedrunPractice.Framework | ||
{ | ||
class DrawHelper | ||
{ | ||
private static Texture2D SolidColor; | ||
private const int OutlineWidth = 1; | ||
private static Color OutlineColor = Color.Black; | ||
static DrawHelper() | ||
{ | ||
SolidColor = new Texture2D(Game1.graphics.GraphicsDevice, 1, 1, false, SurfaceFormat.Color); | ||
Color[] data = new Color[1] { new Color(255, 255, 255, 255) }; | ||
SolidColor.SetData(data); | ||
} | ||
|
||
|
||
public static void DrawProgressBar(SpriteBatch spriteBatch, Rectangle region, List<int> zoneCounts, List<Color> zoneColors) | ||
{ | ||
// determine number of blocks | ||
int numZones = zoneCounts.Sum(); | ||
if (numZones == 0) | ||
return; | ||
// normalize for weird float issues | ||
int zoneWidth = region.Width / numZones; | ||
region.Width = zoneWidth * numZones; | ||
// draw the base rectangle | ||
DrawOutlinedRect(spriteBatch, region, OutlineWidth, Color.White, Color.Black); | ||
|
||
// draw the different zones | ||
Rectangle zoneRegion = new Rectangle(region.X, region.Y, zoneWidth, region.Height); | ||
for (int i = 0; i < zoneCounts.Count; ++i) | ||
{ | ||
for (int j = 0; j < zoneCounts[i]; j++) | ||
{ | ||
DrawOutlinedRect(spriteBatch, zoneRegion, OutlineWidth, zoneColors[i], Color.Black); | ||
zoneRegion.X += zoneWidth; | ||
} | ||
} | ||
} | ||
|
||
public static void DrawProgressBar(SpriteBatch spriteBatch, Rectangle region, List<int> zoneCounts, List<Color> zoneColors, int highlightZone, Color highlightColor) | ||
{ | ||
// determine number of blocks | ||
int numZones = zoneCounts.Sum(); | ||
if (numZones == 0) | ||
return; | ||
// normalize for weird float issues | ||
int zoneWidth = region.Width / numZones; | ||
region.Width = zoneWidth * numZones; | ||
// draw the base rectangle | ||
DrawOutlinedRect(spriteBatch, region, OutlineWidth, Color.White, OutlineColor); | ||
|
||
// draw the different zones | ||
Rectangle zoneRegion = new Rectangle(region.X, region.Y, zoneWidth, region.Height); | ||
for (int i = 0; i < zoneCounts.Count; ++i) | ||
{ | ||
for (int j = 0; j < zoneCounts[i]; j++) | ||
{ | ||
DrawOutlinedRect(spriteBatch, zoneRegion, OutlineWidth, zoneColors[i], OutlineColor); | ||
zoneRegion.X += zoneWidth; | ||
} | ||
} | ||
|
||
// draw the highlight | ||
zoneRegion.X = region.X + zoneWidth * highlightZone; | ||
DrawOutlinedRect(spriteBatch, zoneRegion, OutlineWidth, highlightColor, OutlineColor); | ||
} | ||
|
||
public static void DrawOutlinedRect(SpriteBatch spriteBatch, Rectangle region, int lineWidth, Color interiorColor, Color outlineColor) | ||
{ | ||
spriteBatch.Draw(SolidColor, region, outlineColor); | ||
spriteBatch.Draw(SolidColor, new Rectangle(region.X + lineWidth, region.Y + lineWidth, region.Width - 2 * lineWidth, region.Height - 2 * lineWidth), interiorColor); | ||
} | ||
} | ||
} |
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,53 @@ | ||
using Microsoft.Xna.Framework; | ||
using StardewModdingAPI; | ||
using StardewValley; | ||
using StardewValley.Tools; | ||
using System; | ||
|
||
namespace SpeedrunPractice.Framework | ||
{ | ||
public class PlayerInfo | ||
{ | ||
public static bool Active { get { return Game1.player != null; } } | ||
|
||
public static bool CanMove { get { return Active && Game1.player.CanMove; } } | ||
|
||
public static bool UsingTool { get { return Active && Game1.player.UsingTool; } } | ||
|
||
public static Tool CurrentTool { get { return Game1.player?.CurrentTool; } } | ||
|
||
|
||
public static int FacingDirection { get { return Active ? Game1.player.FacingDirection : -1; } } | ||
|
||
public static FarmerSprite CurrentSprite { get { return Game1.player?.FarmerSprite; } } | ||
|
||
public static int GetMouseFacingDirection(Vector2 position, bool worldCoordinates=true) | ||
{ | ||
if (Active) | ||
{ | ||
if (!worldCoordinates) | ||
{ | ||
position.X += Game1.viewport.X; | ||
position.Y += Game1.viewport.Y; | ||
} | ||
if (Utility.withinRadiusOfPlayer((int)position.X, (int)position.Y, 1, Game1.player) && | ||
(Math.Abs(position.X - (float)Game1.player.getStandingX()) >= 32f || Math.Abs(position.Y - (float)Game1.player.getStandingY()) >= 32f)) | ||
{ | ||
return Game1.player.getGeneralDirectionTowards(position, 0, false); | ||
} | ||
} | ||
return FacingDirection; | ||
} | ||
|
||
public static int AnimationType | ||
{ | ||
get | ||
{ | ||
if (CurrentSprite == null) | ||
return -1; | ||
|
||
return (int)Reflector.GetValue(CurrentSprite, "currentSingleAnimation"); ; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.