From 03314b2ea8ab573b0035419cab2ec1c46067aa93 Mon Sep 17 00:00:00 2001 From: yangzhi <@4F!xZpJwly&KbWq> Date: Sun, 16 Feb 2020 21:20:00 +0800 Subject: [PATCH] Fix icon position for Android --- SDVModTest/UIElements/ShowAccurateHearts.cs | 141 +++++++++++++----- .../UIElements/ShowWhenAnimalNeedsPet.cs | 5 + 2 files changed, 109 insertions(+), 37 deletions(-) diff --git a/SDVModTest/UIElements/ShowAccurateHearts.cs b/SDVModTest/UIElements/ShowAccurateHearts.cs index f2c6716..bf60245 100644 --- a/SDVModTest/UIElements/ShowAccurateHearts.cs +++ b/SDVModTest/UIElements/ShowAccurateHearts.cs @@ -1,4 +1,5 @@ using Microsoft.Xna.Framework; +using StardewModdingAPI; using StardewModdingAPI.Events; using StardewValley; using StardewValley.Menus; @@ -64,45 +65,95 @@ namespace UIInfoSuite.UIElements .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 sprites = (List)_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, @@ -164,14 +215,30 @@ namespace UIInfoSuite.UIElements { 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); + } } } } diff --git a/SDVModTest/UIElements/ShowWhenAnimalNeedsPet.cs b/SDVModTest/UIElements/ShowWhenAnimalNeedsPet.cs index 219873d..dce4ead 100644 --- a/SDVModTest/UIElements/ShowWhenAnimalNeedsPet.cs +++ b/SDVModTest/UIElements/ShowWhenAnimalNeedsPet.cs @@ -221,6 +221,11 @@ namespace UIInfoSuite.UIElements private Vector2 GetPetPositionAboveAnimal(Character animal) { + if(Constants.TargetPlatform == GamePlatform.Android) + { + return new Vector2(Game1.viewport.Width <= Game1.currentLocation.map.DisplayWidth ? (animal.position.X - Game1.viewport.X + 16) * Game1.options.zoomLevel : (animal.position.X + ((Game1.viewport.Width - Game1.currentLocation.map.DisplayWidth) / 2 + 18)) * Game1.options.zoomLevel, + Game1.viewport.Height <= Game1.currentLocation.map.DisplayHeight ? (animal.position.Y - Game1.viewport.Y - 34) * Game1.options.zoomLevel : (animal.position.Y + ((Game1.viewport.Height - Game1.currentLocation.map.DisplayHeight) / 2 - 50)) * Game1.options.zoomLevel); + } return new Vector2(Game1.viewport.Width <= Game1.currentLocation.map.DisplayWidth ? animal.position.X - Game1.viewport.X + 16 : animal.position.X + ((Game1.viewport.Width - Game1.currentLocation.map.DisplayWidth) / 2 + 18), Game1.viewport.Height <= Game1.currentLocation.map.DisplayHeight ? animal.position.Y - Game1.viewport.Y - 34 : animal.position.Y + ((Game1.viewport.Height - Game1.currentLocation.map.DisplayHeight) / 2 - 50)); }