This commit is contained in:
cdaragorn 2018-07-15 13:42:19 -06:00
commit fdc2bd41a9
5 changed files with 292 additions and 209 deletions

View File

@ -99,6 +99,7 @@ namespace UIInfoSuite.Options
}
public void Dispose()
{
foreach (var item in _elementsToDispose)
@ -147,9 +148,7 @@ namespace UIInfoSuite.Options
private void SetActiveClickableMenuToModOptionsPage()
{
GameMenu menu = Game1.activeClickableMenu as GameMenu;
if (menu != null)
if (Game1.activeClickableMenu is GameMenu menu)
menu.currentTab = _modOptionsTabPageNumber;
}

View File

@ -22,8 +22,9 @@ namespace UIInfoSuite.UIElements
class ExperienceBar : IDisposable
{
private const int MaxBarWidth = 175;
private int _currentLevelIndex = 4;
private float _currentExperience = 0;
//private float _currentExperience = 0;
private int[] _currentExperience = new int[5];
private readonly List<ExperiencePointDisplay> _experiencePointDisplays = new List<ExperiencePointDisplay>();
private GameLocation _currentLocation = new GameLocation();
private readonly TimeSpan _levelUpPauseTime = TimeSpan.FromSeconds(2);
@ -92,6 +93,8 @@ namespace UIInfoSuite.UIElements
public void ToggleShowExperienceGain(bool showExperienceGain)
{
for (int i = 0; i < _currentExperience.Length; ++i)
_currentExperience[i] = Game1.player.experiencePoints[i];
_showExperienceGain = showExperienceGain;
}
@ -172,19 +175,97 @@ namespace UIInfoSuite.UIElements
{
Item currentItem = Game1.player.CurrentItem;
Rectangle rectangle1 = new Rectangle(10, 428, 10, 10);
int experienceLevel;
int experienceLevel = 0;
int currentLevelIndex = -1;
int experienceRequiredToLevel = -1;
int experienceFromPreviousLevels = -1;
int experienceEarnedThisLevel = -1;
for (int i = 0; i < _currentExperience.Length; ++i)
{
if (_currentExperience[i] != Game1.player.experiencePoints[i])
{
currentLevelIndex = i;
break;
}
}
if (currentLevelIndex > -1)
{
switch ((EventArgsLevelUp.LevelType)currentLevelIndex)
{
case EventArgsLevelUp.LevelType.Combat:
{
_experienceFillColor = new Color(204, 0, 3, 0.63f);
rectangle1.X = 120;
experienceLevel = Game1.player.combatLevel;
break;
}
case EventArgsLevelUp.LevelType.Farming:
{
_experienceFillColor = new Color(255, 251, 35, 0.38f);
rectangle1.X = 10;
experienceLevel = Game1.player.farmingLevel;
break;
}
case EventArgsLevelUp.LevelType.Fishing:
{
_experienceFillColor = new Color(17, 84, 252, 0.63f);
rectangle1.X = 20;
experienceLevel = Game1.player.fishingLevel;
break;
}
case EventArgsLevelUp.LevelType.Foraging:
{
_experienceFillColor = new Color(0, 234, 0, 0.63f);
rectangle1.X = 60;
experienceLevel = Game1.player.foragingLevel;
break;
}
case EventArgsLevelUp.LevelType.Mining:
{
_experienceFillColor = new Color(145, 104, 63, 0.63f);
rectangle1.X = 30;
experienceLevel = Game1.player.miningLevel;
break;
}
}
experienceRequiredToLevel = GetExperienceRequiredToLevel(experienceLevel);
experienceFromPreviousLevels = GetExperienceRequiredToLevel(experienceLevel - 1);
experienceEarnedThisLevel = Game1.player.experiencePoints[currentLevelIndex] - experienceFromPreviousLevels;
int experiencePreviouslyEarnedThisLevel = _currentExperience[currentLevelIndex] - experienceFromPreviousLevels;
_currentExperience[currentLevelIndex] = Game1.player.experiencePoints[currentLevelIndex];
ShowExperienceBar();
if (_showExperienceGain)
{
_experiencePointDisplays.Add(
new ExperiencePointDisplay(
experienceEarnedThisLevel - experiencePreviouslyEarnedThisLevel,
Game1.player.getLocalPosition(Game1.viewport)));
}
}
else
{
if (currentItem is FishingRod)
{
_experienceFillColor = new Color(17, 84, 252, 0.63f);
_currentLevelIndex = 1;
currentLevelIndex = 1;
rectangle1.X = 20;
experienceLevel = Game1.player.fishingLevel;
}
else if (currentItem is Pickaxe)
{
_experienceFillColor = new Color(145, 104, 63, 0.63f);
_currentLevelIndex = 3;
currentLevelIndex = 3;
rectangle1.X = 30;
experienceLevel = Game1.player.miningLevel;
}
@ -192,7 +273,7 @@ namespace UIInfoSuite.UIElements
currentItem.Name != "Scythe")
{
_experienceFillColor = new Color(204, 0, 3, 0.63f);
_currentLevelIndex = 4;
currentLevelIndex = 4;
rectangle1.X = 120;
experienceLevel = Game1.player.combatLevel;
}
@ -200,43 +281,27 @@ namespace UIInfoSuite.UIElements
!(currentItem is Axe))
{
_experienceFillColor = new Color(255, 251, 35, 0.38f);
_currentLevelIndex = 0;
currentLevelIndex = 0;
rectangle1.X = 10;
experienceLevel = Game1.player.farmingLevel;
}
else
{
_experienceFillColor = new Color(0, 234, 0, 0.63f);
_currentLevelIndex = 2;
currentLevelIndex = 2;
rectangle1.X = 60;
experienceLevel = Game1.player.foragingLevel;
}
if (experienceLevel <= 9)
{
int experienceRequiredToLevel = GetExperienceRequiredToLevel(experienceLevel);
int experienceFromPreviousLevels = GetExperienceRequiredToLevel(experienceLevel - 1);
int experienceEarnedThisLevel = Game1.player.experiencePoints[_currentLevelIndex] - experienceFromPreviousLevels;
experienceRequiredToLevel = GetExperienceRequiredToLevel(experienceLevel);
experienceFromPreviousLevels = GetExperienceRequiredToLevel(experienceLevel - 1);
experienceEarnedThisLevel = Game1.player.experiencePoints[currentLevelIndex] - experienceFromPreviousLevels;
if (_previousItem != currentItem)
{
ShowExperienceBar();
}
else if (_currentExperience != experienceEarnedThisLevel)
{
ShowExperienceBar();
if (experienceEarnedThisLevel - _currentExperience > 0 &&
_showExperienceGain)
{
_experiencePointDisplays.Add(
new ExperiencePointDisplay(
experienceEarnedThisLevel - _currentExperience,
Game1.player.getLocalPosition(Game1.viewport)));
}
}
_previousItem = currentItem;
_currentExperience = experienceEarnedThisLevel;
if (_shouldDrawLevelUp)
{
@ -279,7 +344,52 @@ namespace UIInfoSuite.UIElements
if (_experienceBarShouldBeVisible &&
_showExperienceBar)
{
int barWidth = (int)(_currentExperience / (experienceRequiredToLevel - experienceFromPreviousLevels) * MaxBarWidth);
int experienceDifferenceBetweenLevels = experienceRequiredToLevel - experienceFromPreviousLevels;
int barWidth = (int)((double)experienceEarnedThisLevel / experienceDifferenceBetweenLevels * MaxBarWidth);
DrawExperienceBar(barWidth, experienceEarnedThisLevel, experienceDifferenceBetweenLevels, experienceLevel, rectangle1);
}
}
}
private int GetExperienceRequiredToLevel(int currentLevel)
{
int amount = 0;
switch (currentLevel)
{
case 0: amount = 100; break;
case 1: amount = 380; break;
case 2: amount = 770; break;
case 3: amount = 1300; break;
case 4: amount = 2150; break;
case 5: amount = 3300; break;
case 6: amount = 4800; break;
case 7: amount = 6900; break;
case 8: amount = 10000; break;
case 9: amount = 15000; break;
}
return amount;
}
private void ShowExperienceBar()
{
if (_allowExperienceBarToFadeOut)
{
_timeToDisappear.Interval = _timeBeforeExperienceBarFades.TotalMilliseconds;
_timeToDisappear.Start();
}
else
{
_timeToDisappear.Stop();
}
_experienceBarShouldBeVisible = true;
}
private void DrawExperienceBar(int barWidth, int experienceGainedThisLevel, int experienceRequiredForNextLevel, int currentLevel, Rectangle iconPosition)
{
float leftSide = Game1.graphics.GraphicsDevice.Viewport.TitleSafeArea.Left;
if (Game1.isOutdoorMapSmallerThanViewport())
@ -349,7 +459,7 @@ namespace UIInfoSuite.UIElements
if (textureComponent.containsPoint(Game1.getMouseX(), Game1.getMouseY()))
{
Game1.drawWithBorder(
_currentExperience + "/" + (experienceRequiredToLevel - experienceFromPreviousLevels),
experienceGainedThisLevel + "/" + experienceRequiredForNextLevel,
Color.Black,
Color.Black,
new Vector2(
@ -363,7 +473,7 @@ namespace UIInfoSuite.UIElements
new Vector2(
leftSide + 54,
Game1.graphics.GraphicsDevice.Viewport.TitleSafeArea.Bottom - 62),
rectangle1,
iconPosition,
_iconColor,
0,
Vector2.Zero,
@ -372,53 +482,13 @@ namespace UIInfoSuite.UIElements
0.85f);
Game1.drawWithBorder(
experienceLevel.ToString(),
currentLevel.ToString(),
Color.Black * 0.6f,
Color.Black,
new Vector2(
leftSide + 33,
Game1.graphics.GraphicsDevice.Viewport.TitleSafeArea.Bottom - 70));
}
}
}
}
}
private int GetExperienceRequiredToLevel(int currentLevel)
{
int amount = 0;
switch (currentLevel)
{
case 0: amount = 100; break;
case 1: amount = 380; break;
case 2: amount = 770; break;
case 3: amount = 1300; break;
case 4: amount = 2150; break;
case 5: amount = 3300; break;
case 6: amount = 4800; break;
case 7: amount = 6900; break;
case 8: amount = 10000; break;
case 9: amount = 15000; break;
}
return amount;
}
private void ShowExperienceBar()
{
if (_allowExperienceBarToFadeOut)
{
_timeToDisappear.Interval = _timeBeforeExperienceBarFades.TotalMilliseconds;
_timeToDisappear.Start();
}
else
{
_timeToDisappear.Stop();
}
_experienceBarShouldBeVisible = true;
}
}

View File

@ -60,7 +60,9 @@ namespace UIInfoSuite.UIElements
List<IClickableMenu> menuList = typeof(GameMenu).GetField("pages", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(Game1.activeClickableMenu) as List<IClickableMenu>;
if (menuList[0] is InventoryPage inventory)
_heldItem = typeof(InventoryPage).GetField("heldItem", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(inventory) as Item;
{
_heldItem = typeof(InventoryPage).GetField("heldItem", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(inventory) as Item;
}
}
}

View File

@ -66,7 +66,15 @@ namespace UIInfoSuite.UIElements
if (Game1.currentLocation.terrainFeatures == null ||
!Game1.currentLocation.terrainFeatures.TryGetValue(Game1.currentCursorTile, out _terrain))
{
//if (_currentTile is IndoorPot pot &&
// pot.hoeDirt.Value != null)
//{
// _terrain = pot.hoeDirt.Value;
//}
//else
//{
_terrain = null;
//}
}
}
else
@ -139,6 +147,7 @@ namespace UIInfoSuite.UIElements
_currentTile.Name != "Heater")
{
StringBuilder hoverText = new StringBuilder();
hoverText.AppendLine(_currentTile.heldObject.DisplayName);
if (_currentTile is Cask)
{
@ -227,17 +236,20 @@ namespace UIInfoSuite.UIElements
{
FruitTree tree = _terrain as FruitTree;
var text = new StardewValley.Object(new Debris(tree.indexOfFruit, Vector2.Zero, Vector2.Zero).chunkType, 1).DisplayName;
if (tree.daysUntilMature > 0)
{
text += Environment.NewLine + tree.daysUntilMature + " " +
_helper.SafeGetString(
LanguageKeys.DaysToMature);
}
IClickableMenu.drawHoverText(
Game1.spriteBatch,
tree.daysUntilMature + " " +
_helper.SafeGetString(
LanguageKeys.DaysToMature),
text,
Game1.smallFont);
}
}
}
}
}
}

View File

@ -32,13 +32,13 @@ namespace UIInfoSuite.UIElements
public void ToggleOption(bool showWhenAnimalNeedsPet)
{
_timer.Stop();
LocationEvents.CurrentLocationChanged -= OnLocationChange;
LocationEvents.LocationsChanged -= OnLocationChange;
GraphicsEvents.OnPreRenderHudEvent -= DrawAnimalHasProduct;
if (showWhenAnimalNeedsPet)
{
_timer.Start();
LocationEvents.CurrentLocationChanged += OnLocationChange;
LocationEvents.LocationsChanged += OnLocationChange;
GraphicsEvents.OnPreRenderHudEvent += DrawAnimalHasProduct;
}
}
@ -94,10 +94,10 @@ namespace UIInfoSuite.UIElements
}
}
private void OnLocationChange(object sender, EventArgsCurrentLocationChanged e)
private void OnLocationChange(object sender, EventArgsGameLocationsChanged e)
{
if (e.NewLocation is AnimalHouse ||
e.NewLocation is Farm)
if (Game1.player.currentLocation is AnimalHouse ||
Game1.player.currentLocation is Farm)
{
_timer.Interval = 1000;
_timer.Start();