Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Android platform #48

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion SDVModTest/IconHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public Point GetNewIconPosition()
int xPosition = (int)Tools.GetWidthInPlayArea() - 70 - 48 * _amountOfVisibleIcons;
if (Game1.player.questLog.Any())
{
x -= 65;
xPosition -= 65;
}
++_amountOfVisibleIcons;
return new Point(xPosition, yPos);
Expand Down
49 changes: 37 additions & 12 deletions SDVModTest/Tools.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using StardewModdingAPI;
using StardewValley;
using StardewValley.Menus;
using System;
Expand Down Expand Up @@ -90,27 +91,51 @@ public static void DrawMouseCursor()
public static Item GetHoveredItem()
{
Item hoverItem = null;

for (int i = 0; i < Game1.onScreenMenus.Count; ++i)
if (Game1.onScreenMenus != null)
{
Toolbar onScreenMenu = Game1.onScreenMenus[i] as Toolbar;
if (onScreenMenu != null)
for (int i = 0; i < Game1.onScreenMenus.Count; ++i)
{
FieldInfo hoverItemField = typeof(Toolbar).GetField("hoverItem", BindingFlags.Instance | BindingFlags.NonPublic);
hoverItem = hoverItemField.GetValue(onScreenMenu) as Item;
//hoverItemField.SetValue(onScreenMenu, null);
Toolbar onScreenMenu = Game1.onScreenMenus[i] as Toolbar;
if (onScreenMenu != null)
{
FieldInfo hoverItemField = typeof(Toolbar).GetField("hoverItem", BindingFlags.Instance | BindingFlags.NonPublic);
hoverItem = hoverItemField.GetValue(onScreenMenu) as Item;
//hoverItemField.SetValue(onScreenMenu, null);
}
}
}

if (Game1.activeClickableMenu is GameMenu gameMenu)
{
foreach (var menu in gameMenu.pages)
if (Constants.TargetPlatform != GamePlatform.Android)
{
foreach (var menu in gameMenu.pages)
{
if (menu is InventoryPage inventory)
{
FieldInfo hoveredItemField = typeof(InventoryPage).GetField("hoveredItem", BindingFlags.Instance | BindingFlags.NonPublic);
hoverItem = hoveredItemField.GetValue(inventory) as Item;
//typeof(InventoryPage).GetField("hoverText", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(menu, "");
}
}
}
else
{
if (menu is InventoryPage inventory)
if (gameMenu.pages[gameMenu.currentTab] is InventoryPage inventory)
{
FieldInfo hoveredItemField = typeof(InventoryPage).GetField("hoveredItem", BindingFlags.Instance | BindingFlags.NonPublic);
hoverItem = hoveredItemField.GetValue(inventory) as Item;
//typeof(InventoryPage).GetField("hoverText", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(menu, "");
FieldInfo heldItemField = typeof(InventoryPage).GetField("heldItem", BindingFlags.Instance | BindingFlags.NonPublic);
Item heldItem = heldItemField.GetValue(inventory) as Item;
int x = Game1.getMousePosition().X;
int y = Game1.getMousePosition().Y;
foreach (ClickableComponent component in inventory.inventory.inventory)
{
int num = Convert.ToInt32(component.name);
if (component.containsPoint(x, y) && (num < inventory.inventory.actualInventory.Count) && (inventory.inventory.actualInventory[num] != null))
{
hoverItem = inventory.inventory.actualInventory[num];
break;
}
}
}
}
}
Expand Down
16 changes: 12 additions & 4 deletions SDVModTest/UIElements/ExperienceBar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Media;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
Expand Down Expand Up @@ -46,7 +45,7 @@ public interface LevelExtenderEvents
private bool _showLevelUpAnimation = true;
private bool _showExperienceBar = true;
private readonly IModHelper _helper;
private SoundPlayer _player;
private object _player;

private LevelExtenderInterface _levelExtenderAPI;

Expand All @@ -62,7 +61,7 @@ public ExperienceBar(IModHelper helper)
try
{
path = Path.Combine(_helper.DirectoryPath, "LevelUp.wav");
_player = new SoundPlayer(path);
_player = Type.GetType("System.Media.SoundPlayer")?.GetConstructor(new Type[] { }).Invoke(new object[] { });
//path = path.Replace(Environment.CurrentDirectory, "");
//path = path.TrimStart(Path.DirectorySeparatorChar);
//_soundEffect = SoundEffect.FromStream(TitleContainer.OpenStream(path)).CreateInstance();
Expand Down Expand Up @@ -209,7 +208,7 @@ private void OnLevelChanged(object sender, LevelChangedEventArgs e)
Task.Factory.StartNew(() =>
{
Thread.Sleep(100);
_player.Play();
Type.GetType("System.Media.SoundPlayer")?.GetMethod("Play").Invoke(this._player, new object[] { });
});

Task.Factory.StartNew(() =>
Expand Down Expand Up @@ -520,6 +519,15 @@ private void DrawExperienceBar(int barWidth, int experienceGainedThisLevel, int
{
float leftSide = Game1.graphics.GraphicsDevice.Viewport.TitleSafeArea.Left;

if(Constants.TargetPlatform == GamePlatform.Android)
{
if (this._helper.Reflection.GetField<bool>(Game1.options, "verticalToolbar", true).GetValue())
{
Toolbar toolbar = this._helper.Reflection.GetField<Toolbar>(typeof(Game1), "toolbar", true).GetValue();
leftSide += this._helper.Reflection.GetField<int>(typeof(Game1), "toolbarPaddingX", true).GetValue() + this._helper.Reflection.GetProperty<int>(toolbar, "itemSlotSize", true).GetValue();
}
}

if (Game1.isOutdoorMapSmallerThanViewport())
{
int num3 = Game1.currentLocation.map.Layers[0].LayerWidth * Game1.tileSize;
Expand Down
13 changes: 13 additions & 0 deletions SDVModTest/UIElements/ExperiencePointDisplay.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using StardewModdingAPI;
using StardewValley;
using System;
using System.Collections.Generic;
Expand All @@ -24,6 +25,18 @@ public void Draw()
{
_position.Y -= 0.5f;
--_alpha;
if(Constants.TargetPlatform == GamePlatform.Android)
{
Game1.drawWithBorder(
"Exp " + _experiencePoints,
Color.DarkSlateGray * ((float)_alpha / 100f),
Color.PaleTurquoise * ((float)_alpha / 100f),
new Vector2(_position.X - 28, _position.Y - 130) * Game1.options.zoomLevel,
0.0f,
0.8f,
0.0f);
return;
}
Game1.drawWithBorder(
"Exp " + _experiencePoints,
Color.DarkSlateGray * ((float)_alpha / 100f),
Expand Down
2 changes: 1 addition & 1 deletion SDVModTest/UIElements/LocationOfTownsfolk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private void OnRenderedActiveMenu_DrawNPCLocationsOnMap(object sender, RenderedA
{
if (Game1.activeClickableMenu is GameMenu gameMenu)
{
if (gameMenu.currentTab == 3)
if (gameMenu.currentTab == (Constants.TargetPlatform == GamePlatform.Android ? 4 : 3))
{
List<String> namesToShow = new List<string>();
foreach (var character in _townsfolk)
Expand Down
6 changes: 6 additions & 0 deletions SDVModTest/UIElements/LuckOfDay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ private void OnUpdateTicked(object sender, UpdateTickedEventArgs e)
private void OnRenderedHud(object sender, RenderedHudEventArgs e)
{
// draw hover text
if (Constants.TargetPlatform == GamePlatform.Android)
{
if (_icon.containsPoint((int)(Game1.getMouseX() * Game1.options.zoomLevel), (int)(Game1.getMouseY() * Game1.options.zoomLevel)))
IClickableMenu.drawHoverText(Game1.spriteBatch, _hoverText, Game1.dialogueFont);
return;
}
if (_icon.containsPoint(Game1.getMouseX(), Game1.getMouseY()))
IClickableMenu.drawHoverText(Game1.spriteBatch, _hoverText, Game1.dialogueFont);
}
Expand Down
2 changes: 1 addition & 1 deletion SDVModTest/UIElements/ShopHarvestPrices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private void OnRenderedActiveMenu(object sender, RenderedActiveMenuEventArgs e)
1);
text = " " + temp.Price;
}

var heldItem = menu.heldItem as Item;
if (heldItem == null)
{
Expand Down
141 changes: 104 additions & 37 deletions SDVModTest/UIElements/ShowAccurateHearts.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Xna.Framework;
using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewValley;
using StardewValley.Menus;
Expand Down Expand Up @@ -64,45 +65,95 @@ private void OnRenderedActiveMenu(object sender, RenderedActiveMenuEventArgs e)
.GetValue(_socialPage);
int yOffset = 0;

for (int i = slotPosition; i < slotPosition + 5 && i < _friendNames.Length; ++i)
if (Constants.TargetPlatform != GamePlatform.Android)
{
int yPosition = Game1.activeClickableMenu.yPositionOnScreen + 130 + yOffset;
yOffset += 112;
Friendship friendshipValues;
String nextName = _friendNames[i];
if (Game1.player.friendshipData.TryGetValue(nextName, out friendshipValues))
for (int i = slotPosition; i < slotPosition + 5 && i < _friendNames.Length; ++i)
{
int friendshipRawValue = friendshipValues.Points;

if (friendshipRawValue > 0)
int yPosition = Game1.activeClickableMenu.yPositionOnScreen + 130 + yOffset;
yOffset += 112;
Friendship friendshipValues;
String nextName = _friendNames[i];
if (Game1.player.friendshipData.TryGetValue(nextName, out friendshipValues))
{
int pointsToNextHeart = friendshipRawValue % 250;
int numHearts = friendshipRawValue / 250;
int friendshipRawValue = friendshipValues.Points;

if (friendshipRawValue < 3000 &&
_friendNames[i] == Game1.player.spouse ||
friendshipRawValue < 2500)
if (friendshipRawValue > 0)
{
DrawEachIndividualSquare(numHearts, pointsToNextHeart, yPosition);
//if (!Game1.options.hardwareCursor)
// Game1.spriteBatch.Draw(
// Game1.mouseCursors,
// new Vector2(Game1.getMouseX(), Game1.getMouseY()),
// Game1.getSourceRectForStandardTileSheet(
// Game1.mouseCursors, Game1.mouseCursor,
// 16,
// 16),
// Color.White,
// 0.0f,
// Vector2.Zero,
// Game1.pixelZoom + (float)(Game1.dialogueButtonScale / 150.0),
// SpriteEffects.None,
// 1f);
int pointsToNextHeart = friendshipRawValue % 250;
int numHearts = friendshipRawValue / 250;

if (friendshipRawValue < 3000 &&
_friendNames[i] == Game1.player.spouse ||
friendshipRawValue < 2500)
{
DrawEachIndividualSquare(numHearts, pointsToNextHeart, yPosition);
//if (!Game1.options.hardwareCursor)
// Game1.spriteBatch.Draw(
// Game1.mouseCursors,
// new Vector2(Game1.getMouseX(), Game1.getMouseY()),
// Game1.getSourceRectForStandardTileSheet(
// Game1.mouseCursors, Game1.mouseCursor,
// 16,
// 16),
// Color.White,
// 0.0f,
// Vector2.Zero,
// Game1.pixelZoom + (float)(Game1.dialogueButtonScale / 150.0),
// SpriteEffects.None,
// 1f);
}
}
}
}
}
else
{
List<ClickableTextureComponent> sprites = (List<ClickableTextureComponent>)_socialPage.GetType().GetField("sprites", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(_socialPage);
for (int i = 0; i < _friendNames.Length; ++i)
{
if(sprites[i].bounds.Y < 40)
{
continue;
}
if(sprites[i].bounds.Y > _socialPage.height)
{
break;
}
Friendship friendshipValues;
String nextName = _friendNames[i];
if (Game1.player.friendshipData.TryGetValue(nextName, out friendshipValues))
{
int friendshipRawValue = friendshipValues.Points;

if (friendshipRawValue > 0)
{
int pointsToNextHeart = friendshipRawValue % 250;
int numHearts = friendshipRawValue / 250;

if (friendshipRawValue < 3000 &&
_friendNames[i] == Game1.player.spouse ||
friendshipRawValue < 2500)
{
DrawEachIndividualSquare(numHearts, pointsToNextHeart, sprites[i].bounds.Y + 40);
//if (!Game1.options.hardwareCursor)
// Game1.spriteBatch.Draw(
// Game1.mouseCursors,
// new Vector2(Game1.getMouseX(), Game1.getMouseY()),
// Game1.getSourceRectForStandardTileSheet(
// Game1.mouseCursors, Game1.mouseCursor,
// 16,
// 16),
// Color.White,
// 0.0f,
// Vector2.Zero,
// Game1.pixelZoom + (float)(Game1.dialogueButtonScale / 150.0),
// SpriteEffects.None,
// 1f);
}
}
}
}
}
String hoverText = gameMenu.hoverText;
IClickableMenu.drawHoverText(
Game1.spriteBatch,
Expand Down Expand Up @@ -164,14 +215,30 @@ private void DrawEachIndividualSquare(int friendshipLevel, int friendshipPoints,
{
if (_numArray[i][j] == 1)
{
Game1.spriteBatch.Draw(
Game1.staminaRect,
new Rectangle(
Game1.activeClickableMenu.xPositionOnScreen + 316 + num2 + j * 4,
yPosition + 14 + i * 4,
4,
4),
Color.Crimson);
if(Constants.TargetPlatform != GamePlatform.Android)
{
Game1.spriteBatch.Draw(
Game1.staminaRect,
new Rectangle(
Game1.activeClickableMenu.xPositionOnScreen + 316 + num2 + j * 4,
yPosition + 14 + i * 4,
4,
4),
Color.Crimson);
}
else
{
int heartsX = (int)_socialPage.GetType().GetField("heartsX", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(_socialPage);
float widthMod = (float)_socialPage.GetType().GetField("widthMod", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(_socialPage);
Game1.spriteBatch.Draw(
Game1.staminaRect,
new Rectangle(
Game1.activeClickableMenu.xPositionOnScreen + heartsX + (int)(num2 * widthMod) + 24 + j * 4,
yPosition + i * 4,
4,
4),
Color.Crimson);
}
}
}
}
Expand Down
Loading