From 6c2555d7484ef05c8225fd3814bb427a5a1773dd Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sat, 29 Jul 2017 14:18:46 -0400 Subject: [PATCH] refactor BuyBackCollectables This commit formats/documents/simplifies code, standardises naming conventions, removes unused code, etc. --- .../BuyBackCollectables.csproj | 1 - GeneralMods/BuyBackCollectables/Class1.cs | 149 +++--- .../Collections_Buy_Back.cs | 445 ------------------ .../BuyBackCollectables/UpdatedCollections.cs | 444 ++++++++--------- GeneralMods/BuyBackCollectables/manifest.json | 2 +- 5 files changed, 262 insertions(+), 779 deletions(-) delete mode 100644 GeneralMods/BuyBackCollectables/Collections_Buy_Back.cs diff --git a/GeneralMods/BuyBackCollectables/BuyBackCollectables.csproj b/GeneralMods/BuyBackCollectables/BuyBackCollectables.csproj index cc67c9d4..f52a98e8 100644 --- a/GeneralMods/BuyBackCollectables/BuyBackCollectables.csproj +++ b/GeneralMods/BuyBackCollectables/BuyBackCollectables.csproj @@ -35,7 +35,6 @@ - diff --git a/GeneralMods/BuyBackCollectables/Class1.cs b/GeneralMods/BuyBackCollectables/Class1.cs index f63114f0..641b5574 100644 --- a/GeneralMods/BuyBackCollectables/Class1.cs +++ b/GeneralMods/BuyBackCollectables/Class1.cs @@ -1,122 +1,111 @@ using System; -using System.Collections.Generic; using System.IO; using StardewModdingAPI; +using StardewModdingAPI.Events; using StardewValley; -using StardewValley.Menus; namespace Omegasis.BuyBackCollectables { - public class Class1 : Mod + /// The mod entry point. + public class BuyBackCollectables : Mod { - string key_binding = "B"; - public static double cost = 3.0; - bool game_loaded = false; + /********* + ** Properties + *********/ + /// The key which shows the menu. + private string KeyBinding = "B"; + + /// The multiplier applied to the cost of buying back a collectable. + private double CostMultiplier = 3.0; + + /// Whether the player loaded a save. + private bool IsGameLoaded; - public static List debugList; - + /********* + ** Public methods + *********/ + /// The mod entry point, called after the mod is first loaded. + /// Provides simplified APIs for writing mods. public override void Entry(IModHelper helper) { - //set up all of my events here - StardewModdingAPI.Events.SaveEvents.AfterLoad+= PlayerEvents_LoadedGame; - StardewModdingAPI.Events.ControlEvents.KeyPressed += ControlEvents_KeyPressed; - StardewModdingAPI.Events.GameEvents.OneSecondTick += GameEvents_OneSecondTick; - debugList = new List(); + SaveEvents.AfterLoad += this.SaveEvents_AfterLoad; + ControlEvents.KeyPressed += this.ControlEvents_KeyPressed; } - private void GameEvents_OneSecondTick(object sender, EventArgs e) + + /********* + ** Private methods + *********/ + /// The method invoked after the player loads a save. + /// The event sender. + /// The event data. + public void SaveEvents_AfterLoad(object sender, EventArgs e) { - if (debugList.Count == 0) return; - foreach(var v in debugList) - { - this.Monitor.Log(v); - } - debugList.Clear(); + this.IsGameLoaded = true; + this.LoadConfig(); + this.WriteConfig(); } - public void ControlEvents_KeyPressed(object sender, StardewModdingAPI.Events.EventArgsKeyPressed e) + /// The method invoked when the presses a keyboard button. + /// The event sender. + /// The event data. + public void ControlEvents_KeyPressed(object sender, EventArgsKeyPressed e) { - if (Game1.player == null) return; - if (Game1.player.currentLocation == null) return; - if (game_loaded == false) return; + if (Game1.player == null || Game1.player.currentLocation == null || !this.IsGameLoaded || Game1.activeClickableMenu != null) + return; - if (e.KeyPressed.ToString() == key_binding) //if the key is pressed, load my cusom save function - { - if (Game1.activeClickableMenu != null) return; - else - { - Game1.activeClickableMenu = new UpdatedCollectionsPage(Game1.viewport.Width / 2 - (800 + IClickableMenu.borderWidth * 2) / 2, Game1.viewport.Height / 2 - (600 + IClickableMenu.borderWidth * 2) / 2, 800 + IClickableMenu.borderWidth * 2, 600 + IClickableMenu.borderWidth * 2); - } - } + if (e.KeyPressed.ToString() == this.KeyBinding) + Game1.activeClickableMenu = new BuyBackMenu(this.CostMultiplier); } - public void PlayerEvents_LoadedGame(object sender, EventArgs e) - { - game_loaded = true; - DataLoader_Settings(); - MyWritter_Settings(); - } - - void DataLoader_Settings() + /// Load the configuration settings. + private void LoadConfig() { //loads the data to the variables upon loading the game. - string myname = StardewValley.Game1.player.name; - string mylocation = Path.Combine(Helper.DirectoryPath, "BuyBack_Config"); - string mylocation2 = mylocation; - string mylocation3 = mylocation2 + ".txt"; - if (!File.Exists(mylocation3)) //if not data.json exists, initialize the data variables to the ModConfig data. I.E. starting out. + string path = Path.Combine(Helper.DirectoryPath, "BuyBack_Config.txt"); + if (!File.Exists(path)) //if not data.json exists, initialize the data variables to the ModConfig data. I.E. starting out. { - key_binding = "B"; - cost = 3.0; + this.KeyBinding = "B"; + this.CostMultiplier = 3.0; } - else { - string[] readtext = File.ReadAllLines(mylocation3); - key_binding = Convert.ToString(readtext[3]); - cost = Convert.ToDouble(readtext[5]); + string[] text = File.ReadAllLines(path); + this.KeyBinding = Convert.ToString(text[3]); + this.CostMultiplier = Convert.ToDouble(text[5]); } } - void MyWritter_Settings() + /// Save the configuration settings. + private void WriteConfig() { //write all of my info to a text file. - string myname = StardewValley.Game1.player.name; - string mylocation = Path.Combine(Helper.DirectoryPath, "BuyBack_Config"); - string mylocation2 = mylocation; - string mylocation3 = mylocation2 + ".txt"; - string[] mystring3 = new string[20]; - if (!File.Exists(mylocation3)) + string path = Path.Combine(Helper.DirectoryPath, "BuyBack_Config.txt"); + string[] text = new string[20]; + if (!File.Exists(path)) { - Monitor.Log("BuyBack Collections: Config not found. Creating it now."); + this.Monitor.Log("BuyBack Collections: Config not found. Creating it now."); - mystring3[0] = "Config: Buy Back Collections. Feel free to mess with these settings."; - mystring3[1] = "===================================================================================="; - mystring3[2] = "Key binding"; - mystring3[3] = key_binding.ToString(); - mystring3[4] = "Collectables Multiplier Cost: Sell Value * value listed below"; - mystring3[5] = cost.ToString(); - File.WriteAllLines(mylocation3, mystring3); + text[0] = "Config: Buy Back Collections. Feel free to mess with these settings."; + text[1] = "===================================================================================="; + text[2] = "Key binding"; + text[3] = this.KeyBinding; + text[4] = "Collectables Multiplier Cost: Sell Value * value listed below"; + text[5] = this.CostMultiplier.ToString(); + File.WriteAllLines(path, text); } else { //write out the info to a text file at the end of a day. This will run if it doesnt exist. - mystring3[0] = "Config: Buy Back Collections. Feel free to mess with these settings."; - mystring3[1] = "===================================================================================="; - mystring3[2] = "Key binding"; - mystring3[3] = key_binding.ToString(); - mystring3[4] = "Collectables Multiplier Cost: Sell Value * value listed below"; - mystring3[5] = cost.ToString(); - File.WriteAllLines(mylocation3, mystring3); + text[0] = "Config: Buy Back Collections. Feel free to mess with these settings."; + text[1] = "===================================================================================="; + text[2] = "Key binding"; + text[3] = this.KeyBinding; + text[4] = "Collectables Multiplier Cost: Sell Value * value listed below"; + text[5] = this.CostMultiplier.ToString(); + File.WriteAllLines(path, text); } } - - public void debugMessage(string s) - { - this.Monitor.Log(s); - } - } } -//end class \ No newline at end of file diff --git a/GeneralMods/BuyBackCollectables/Collections_Buy_Back.cs b/GeneralMods/BuyBackCollectables/Collections_Buy_Back.cs deleted file mode 100644 index 5fbbd2fb..00000000 --- a/GeneralMods/BuyBackCollectables/Collections_Buy_Back.cs +++ /dev/null @@ -1,445 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using StardewModdingAPI; -using StardewValley; -using StardewValley.Menus; -using Object = StardewValley.Object; - -namespace Omegasis.BuyBackCollectables -{ - public class Collections_Buy_Back : IClickableMenu - { - public const int organicsTab = 0; - - public const int fishTab = 1; - - public const int archaeologyTab = 2; - - public const int mineralsTab = 3; - - public const int cookingTab = 4; - - public const int achievementsTab = 5; - - public const int distanceFromMenuBottomBeforeNewPage = 128; - - public static int widthToMoveActiveTab = Game1.tileSize / 8; - - public string descriptionText = ""; - - public string hoverText = ""; - - public ClickableTextureComponent backButton; - - public ClickableTextureComponent forwardButton; - - public List sideTabs = new List(); - - public int currentTab; - - public int currentPage; - - public Dictionary>> collections = new Dictionary>>(); - - public int value; - - public Item new_item; - - public Collections_Buy_Back(int x, int y, int width, int height) : base(x, y, width, height, false) - { - this.sideTabs.Add(new ClickableTextureComponent("",new Rectangle(this.xPositionOnScreen - Game1.tileSize * 3 / 4 + CollectionsPage.widthToMoveActiveTab, this.yPositionOnScreen + Game1.tileSize * 2, Game1.tileSize, Game1.tileSize), "", "Items Shipped (Farm & Forage)", Game1.mouseCursors, new Rectangle(640, 80, 16, 16), (float)Game1.pixelZoom)); - this.collections.Add(0, new List>()); - this.sideTabs.Add(new ClickableTextureComponent("",new Rectangle(this.xPositionOnScreen - Game1.tileSize * 3 / 4, this.yPositionOnScreen + Game1.tileSize * 3, Game1.tileSize, Game1.tileSize), "", "Fish", Game1.mouseCursors, new Rectangle(640, 64, 16, 16), (float)Game1.pixelZoom)); - this.collections.Add(1, new List>()); - this.sideTabs.Add(new ClickableTextureComponent("",new Rectangle(this.xPositionOnScreen - Game1.tileSize * 3 / 4, this.yPositionOnScreen + Game1.tileSize * 4, Game1.tileSize, Game1.tileSize), "", "Artifacts", Game1.mouseCursors, new Rectangle(656, 64, 16, 16), (float)Game1.pixelZoom)); - this.collections.Add(2, new List>()); - this.sideTabs.Add(new ClickableTextureComponent("",new Rectangle(this.xPositionOnScreen - Game1.tileSize * 3 / 4, this.yPositionOnScreen + Game1.tileSize * 5, Game1.tileSize, Game1.tileSize), "", "Minerals", Game1.mouseCursors, new Rectangle(672, 64, 16, 16), (float)Game1.pixelZoom)); - this.collections.Add(3, new List>()); - this.sideTabs.Add(new ClickableTextureComponent("",new Rectangle(this.xPositionOnScreen - Game1.tileSize * 3 / 4, this.yPositionOnScreen + Game1.tileSize * 6, Game1.tileSize, Game1.tileSize), "", "Cooking", Game1.mouseCursors, new Rectangle(688, 64, 16, 16), (float)Game1.pixelZoom)); - this.collections.Add(4, new List>()); - this.sideTabs.Add(new ClickableTextureComponent("",new Rectangle(this.xPositionOnScreen - Game1.tileSize * 3 / 4, this.yPositionOnScreen + Game1.tileSize * 7, Game1.tileSize, Game1.tileSize), "", "Achievements", Game1.mouseCursors, new Rectangle(656, 80, 16, 16), (float)Game1.pixelZoom)); - this.collections.Add(5, new List>()); - Collections_Buy_Back.widthToMoveActiveTab = Game1.tileSize / 8; - this.backButton = new ClickableTextureComponent("",new Rectangle(this.xPositionOnScreen + Game1.tileSize * 3 / 4, this.yPositionOnScreen + height - 20 * Game1.pixelZoom, 12 * Game1.pixelZoom, 11 * Game1.pixelZoom), "", "", Game1.mouseCursors, new Rectangle(352, 495, 12, 11), (float)Game1.pixelZoom, false); - this.forwardButton = new ClickableTextureComponent("",new Rectangle(this.xPositionOnScreen + width - Game1.tileSize / 2 - 15 * Game1.pixelZoom, this.yPositionOnScreen + height - 20 * Game1.pixelZoom, 12 * Game1.pixelZoom, 11 * Game1.pixelZoom), "", "", Game1.mouseCursors, new Rectangle(365, 495, 12, 11), (float)Game1.pixelZoom, false); - int[] array = new int[this.sideTabs.Count()]; - int num = this.xPositionOnScreen + IClickableMenu.borderWidth + IClickableMenu.spaceToClearSideBorder; - int num2 = this.yPositionOnScreen + IClickableMenu.borderWidth + IClickableMenu.spaceToClearTopBorder - Game1.tileSize / 4; - int num3 = 10; - foreach (KeyValuePair current in Game1.objectInformation) - { - string text = current.Value.Split(new char[] - { - '/' - })[3]; - bool flag = false; - int num4; - if (text.Contains("Arch")) - { - num4 = 2; - if (Game1.player.archaeologyFound.ContainsKey(current.Key)) - { - flag = true; - } - } - else if (text.Contains("Fish")) - { - if (current.Key >= 167 && current.Key < 173) - { - continue; - } - num4 = 1; - if (Game1.player.fishCaught.ContainsKey(current.Key)) - { - flag = true; - } - } - else if (text.Contains("Mineral") || text.Substring(text.Count() - 3).Equals("-2")) - { - num4 = 3; - if (Game1.player.mineralsFound.ContainsKey(current.Key)) - { - flag = true; - } - } - else if (text.Contains("Cooking") || text.Substring(text.Count() - 3).Equals("-7")) - { - num4 = 4; - if (Game1.player.recipesCooked.ContainsKey(current.Key)) - { - flag = true; - } - if (current.Key == 217 || current.Key == 772) - { - continue; - } - if (current.Key == 773) - { - continue; - } - } - else - { - if (!StardewValley.Object.isPotentialBasicShippedCategory(current.Key, text.Substring(text.Count() - 3))) - { - continue; - } - num4 = 0; - if (Game1.player.basicShipped.ContainsKey(current.Key)) - { - flag = true; - } - } - int x2 = num + array[num4] % num3 * (Game1.tileSize + 4); - int num5 = num2 + array[num4] / num3 * (Game1.tileSize + 4); - if (num5 > this.yPositionOnScreen + height - 128) - { - this.collections[num4].Add(new List()); - array[num4] = 0; - x2 = num; - num5 = num2; - } - if (this.collections[num4].Count>() == 0) - { - this.collections[num4].Add(new List()); - } - this.collections[num4].Last>().Add(new ClickableTextureComponent("",new Rectangle(x2, num5, Game1.tileSize, Game1.tileSize), current.Key + " " + flag, "", Game1.objectSpriteSheet, Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, current.Key, 16, 16), (float)Game1.pixelZoom, false)); - array[num4]++; - } - if (this.collections[5].Count>() == 0) - { - this.collections[5].Add(new List()); - } - foreach (KeyValuePair current2 in Game1.achievements) - { - bool flag2 = Game1.player.achievements.Contains(current2.Key); - string[] array2 = current2.Value.Split(new char[] - { - '^' - }); - if (flag2 || (array2[2].Equals("true") && (array2[3].Equals("-1") || this.farmerHasAchievements(array2[3])))) - { - int x3 = num + array[5] % num3 * (Game1.tileSize + 4); - int y2 = num2 + array[5] / num3 * (Game1.tileSize + 4); - this.collections[5][0].Add(new ClickableTextureComponent("",new Rectangle(x3, y2, Game1.tileSize, Game1.tileSize), current2.Key + " " + flag2, "", Game1.mouseCursors, Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, 25, -1, -1), 1f, false)); - array[5]++; - } - } - } - - public virtual bool farmerHasAchievements(string listOfAchievementNumbers) - { - string[] array = listOfAchievementNumbers.Split(new char[] - { - ' ' - }); - string[] array2 = array; - for (int i = 0; i < array2.Length; i++) - { - string text = array2[i]; - if (!Game1.player.achievements.Contains(Convert.ToInt32(text))) - { - return false; - } - } - return true; - } - - public override void receiveLeftClick(int x, int y, bool playSound = true) - { - for (int i = 0; i < this.sideTabs.Count; i++) - { - if (this.sideTabs[i].containsPoint(x, y) && this.currentTab != i) - { - Game1.playSound("smallSelect"); - ClickableTextureComponent expr_45_cp_0 = this.sideTabs[this.currentTab]; - expr_45_cp_0.bounds.X = expr_45_cp_0.bounds.X - CollectionsPage.widthToMoveActiveTab; - this.currentTab = i; - this.currentPage = 0; - ClickableTextureComponent expr_75_cp_0 = this.sideTabs[i]; - expr_75_cp_0.bounds.X = expr_75_cp_0.bounds.X + CollectionsPage.widthToMoveActiveTab; - } - } - if (this.currentPage > 0 && this.backButton.containsPoint(x, y)) - { - this.currentPage--; - Game1.playSound("shwip"); - this.backButton.scale = this.backButton.baseScale; - this.new_item = null; - } - if (this.currentPage < this.collections[this.currentTab].Count>() - 1 && this.forwardButton.containsPoint(x, y)) - { - this.currentPage++; - Game1.playSound("shwip"); - this.forwardButton.scale = this.forwardButton.baseScale; - this.new_item = null; - } - - - foreach (ClickableTextureComponent current2 in this.collections[this.currentTab][this.currentPage]) - { - if (current2.containsPoint(x, y)) - { - if (new_item != null) - { - if (Game1.player.money > new_item.salePrice() * Class1.cost) - { - Game1.player.money -= value; - Game1.player.addItemByMenuIfNecessary(new_item); - } - - } - } - } - - - - } - - public override void receiveRightClick(int x, int y, bool playSound = true) - { - if (new_item != null) - { - if (Game1.player.money > new_item.salePrice() * Class1.cost) - { - - Game1.player.money -= value; - Game1.player.addItemByMenuIfNecessary(new_item); - } - - } - } - - - public override void performHoverAction(int x, int y) - { - this.descriptionText = ""; - this.hoverText = ""; - this.value = -1; - - try { - foreach (ClickableTextureComponent current in this.sideTabs) - { - if (current.containsPoint(x, y)) - { - this.hoverText = current.hoverText; - return; - } - } - } - catch (Exception e) - { - Class1.debugList.Add(e.ToString()); - } - try { - foreach (ClickableTextureComponent current2 in this.collections[this.currentTab][this.currentPage]) - { - if (current2.containsPoint(x, y)) - { - current2.scale = Math.Min(current2.scale + 0.02f, current2.baseScale + 0.1f); - if (Convert.ToBoolean(current2.name.Split(new char[] - { - ' ' - })[1]) || this.currentTab == 5) - { - this.hoverText = this.createDescription(Convert.ToInt32(current2.name.Split(new char[] - { - ' ' - })[0])); - } - else - { - this.hoverText = "???"; - this.new_item = null; - } - } - else - { - current2.scale = Math.Max(current2.scale - 0.02f, current2.baseScale); - } - } - } - catch(Exception e) - { - Log.AsyncM(this.currentTab); - Log.AsyncM(this.currentPage); - Log.AsyncM(e); - } - this.forwardButton.tryHover(x, y, 0.5f); - this.backButton.tryHover(x, y, 0.5f); - } - - public virtual string createDescription(int index) - { - string text = ""; - if (this.currentTab == 5) - { - string[] array = Game1.achievements[index].Split(new char[] - { - '^' - }); - text = text + array[0] + Environment.NewLine + Environment.NewLine; - text += array[1]; - new_item = null; - } - else - { - string[] array2 = Game1.objectInformation[index].Split(new char[] - { - '/' - }); - - string text2 = text; - foreach(KeyValuePair meh in Game1.objectInformation) - { - string[] array3 = meh.Value.Split(new char[] - { - '/' - }); - if (array3[0] == array2[0]) - { - new_item = (Item)new Object(Convert.ToInt32(meh.Key), 1, false, -1, 0); - if (new_item.Name == "Stone" || new_item.Name=="stone") new_item = (Item)new Object(390, 1, false, -1, 0); - } - } - text = string.Concat(new string[] - { - text2, - array2[0], - Environment.NewLine, - Environment.NewLine, - Game1.parseText(array2[4], Game1.smallFont, Game1.tileSize * 4), - Environment.NewLine, - Environment.NewLine - }); - if (array2[3].Contains("Arch")) - { - text += (Game1.player.archaeologyFound.ContainsKey(index) ? ("Total Found: " + Game1.player.archaeologyFound[index][0]) : ""); - } - else if (array2[3].Contains("Cooking")) - { - text += (Game1.player.recipesCooked.ContainsKey(index) ? ("Times Cooked: " + Game1.player.recipesCooked[index]) : ""); - } - else if (array2[3].Contains("Fish")) - { - text = text + "Number Caught: " + (Game1.player.fishCaught.ContainsKey(index) ? Game1.player.fishCaught[index][0] : 0); - if (Game1.player.fishCaught.ContainsKey(index) && Game1.player.fishCaught[index][1] > 0) - { - object obj = text; - text = string.Concat(new object[] - { - obj, - Environment.NewLine, - "Biggest Catch: ", - Game1.player.fishCaught[index][1], - " in." - }); - } - } - else if (array2[3].Contains("Minerals") || array2[3].Substring(array2[3].Count() - 3).Equals("-2")) - { - text = text + "Number Found: " + (Game1.player.mineralsFound.ContainsKey(index) ? Game1.player.mineralsFound[index] : 0); - } - else - { - text = text + "Number Shipped: " + (Game1.player.basicShipped.ContainsKey(index) ? Game1.player.basicShipped[index] : 0); - } - this.value = Convert.ToInt32(array2[1]); - this.value =(int)(this.value * Class1.cost); - } - return text; - } - - public override void draw(SpriteBatch b) - { - - foreach (ClickableTextureComponent current in this.sideTabs) - { - current.draw(b); - } - if (this.currentPage > 0) - { - this.backButton.draw(b); - } - if (this.currentPage < this.collections[this.currentTab].Count>() - 1) - { - this.forwardButton.draw(b); - } - b.End(); - b.Begin(SpriteSortMode.FrontToBack, BlendState.NonPremultiplied, SamplerState.PointClamp, null, null); - try - { - foreach (ClickableTextureComponent current2 in this.collections[1][0]) - { - bool flag = Convert.ToBoolean(current2.name.Split(new char[] - { - ' ' - })[1]); - current2.draw(b, flag ? Color.White : (Color.Black * 0.2f), 0.86f); - if (this.currentTab == 5 && flag) - { - int num = new Random(Convert.ToInt32(current2.name.Split(new char[] - { - ' ' - })[0])).Next(12); - b.Draw(Game1.mouseCursors, new Vector2((float)(current2.bounds.X + 16 + Game1.tileSize / 4), (float)(current2.bounds.Y + 20 + Game1.tileSize / 4)), new Rectangle?(new Rectangle(256 + num % 6 * Game1.tileSize / 2, 128 + num / 6 * Game1.tileSize / 2, Game1.tileSize / 2, Game1.tileSize / 2)), Color.White, 0f, new Vector2((float)(Game1.tileSize / 4), (float)(Game1.tileSize / 4)), current2.scale, SpriteEffects.None, 0.88f); - } - } - b.End(); - b.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); - if (!this.hoverText.Equals("")) - { - IClickableMenu.drawHoverText(b, this.hoverText, Game1.smallFont, 0, 0, this.value, null, -1, null, null, 0, -1, -1, -1, -1, 1f, null); - } - b.Draw(Game1.mouseCursors, new Vector2((float)Game1.getOldMouseX(), (float)Game1.getOldMouseY()), new Rectangle?(Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, Game1.options.gamepadControls ? 44 : 0, 16, 16)), Color.White, 0f, Vector2.Zero, (float)Game1.pixelZoom + Game1.dialogueButtonScale / 150f, SpriteEffects.None, 1f); - } - catch(Exception e) - { - Log.AsyncY(e); - } - } - } -} diff --git a/GeneralMods/BuyBackCollectables/UpdatedCollections.cs b/GeneralMods/BuyBackCollectables/UpdatedCollections.cs index 724470ae..06f5cc13 100644 --- a/GeneralMods/BuyBackCollectables/UpdatedCollections.cs +++ b/GeneralMods/BuyBackCollectables/UpdatedCollections.cs @@ -9,421 +9,361 @@ using Object = StardewValley.Object; namespace Omegasis.BuyBackCollectables { - public class UpdatedCollectionsPage : IClickableMenu + /// The clickable menu which lets the player buy back collectables. + internal class BuyBackMenu : IClickableMenu { - public static int widthToMoveActiveTab = Game1.tileSize / 8; + /********* + ** Properties + *********/ + /// The organics tab ID. + private const int OrganicsTab = 0; - public const int organicsTab = 0; + /// The fish tab ID. + private const int FishTab = 1; - public const int fishTab = 1; + /// The archaeology tab ID. + private const int ArchaeologyTab = 2; - public const int archaeologyTab = 2; + /// The minerals tab ID. + private const int MineralsTab = 3; - public const int mineralsTab = 3; + /// The cooking tab ID. + private const int CookingTab = 4; - public const int cookingTab = 4; + /// The achievements tab ID. + private const int AchievementsTab = 5; - public const int achievementsTab = 5; + /// The offset to apply to the selected tab. + private readonly int WidthToMoveActiveTab = Game1.tileSize / 8; - public const int distanceFromMenuBottomBeforeNewPage = 128; + /// The multiplier applied to the cost of buying back a collectable. + private readonly double CostMultiplier; - private string descriptionText = ""; + /// The back button. + private readonly ClickableTextureComponent BackButton; - private string hoverText = ""; + /// The forward button. + private readonly ClickableTextureComponent ForwardButton; - private ClickableTextureComponent backButton; + /// The category tabs shown along the side. + private readonly List SideTabs = new List(); - private ClickableTextureComponent forwardButton; + /// The text to display in a hover tooltip. + private string HoverText = ""; - private List sideTabs = new List(); + /// The selected tab. + private int CurrentTab; - private int currentTab; + /// The selected page. + private int CurrentPage; - private int currentPage; + /// The buttons to show for each tab. + private readonly Dictionary>> Collections = new Dictionary>>(); - private Dictionary>> collections = new Dictionary>>(); + /// The cost to buy back the selected item. + private int Value; - private int value; + /// The selected item. + public Item NewItem; - public Item new_item; - public int newItemValue; + /// The cost to buy back the selected item. + public int NewItemValue; - public UpdatedCollectionsPage(int x, int y, int width, int height) : base(x, y, width, height, false) + + /********* + ** Public methods + *********/ + /// Construct an instance. + /// The multiplier applied to the cost of buying back a collectable. + public BuyBackMenu(double costMultiplier) + : base(Game1.viewport.Width / 2 - (800 + IClickableMenu.borderWidth * 2) / 2, Game1.viewport.Height / 2 - (600 + IClickableMenu.borderWidth * 2) / 2, 800 + IClickableMenu.borderWidth * 2, 600 + IClickableMenu.borderWidth * 2) { - this.sideTabs.Add(new ClickableTextureComponent("", new Rectangle(this.xPositionOnScreen - Game1.tileSize * 3 / 4 + UpdatedCollectionsPage.widthToMoveActiveTab, this.yPositionOnScreen + Game1.tileSize * 2, Game1.tileSize, Game1.tileSize), "", Game1.content.LoadString("Strings\\UI:Collections_Shipped", new object[0]), Game1.mouseCursors, new Rectangle(640, 80, 16, 16), (float)Game1.pixelZoom, false)); - this.collections.Add(0, new List>()); - this.sideTabs.Add(new ClickableTextureComponent("", new Rectangle(this.xPositionOnScreen - Game1.tileSize * 3 / 4, this.yPositionOnScreen + Game1.tileSize * 3, Game1.tileSize, Game1.tileSize), "", Game1.content.LoadString("Strings\\UI:Collections_Fish", new object[0]), Game1.mouseCursors, new Rectangle(640, 64, 16, 16), (float)Game1.pixelZoom, false)); - this.collections.Add(1, new List>()); - this.sideTabs.Add(new ClickableTextureComponent("", new Rectangle(this.xPositionOnScreen - Game1.tileSize * 3 / 4, this.yPositionOnScreen + Game1.tileSize * 4, Game1.tileSize, Game1.tileSize), "", Game1.content.LoadString("Strings\\UI:Collections_Artifacts", new object[0]), Game1.mouseCursors, new Rectangle(656, 64, 16, 16), (float)Game1.pixelZoom, false)); - this.collections.Add(2, new List>()); - this.sideTabs.Add(new ClickableTextureComponent("", new Rectangle(this.xPositionOnScreen - Game1.tileSize * 3 / 4, this.yPositionOnScreen + Game1.tileSize * 5, Game1.tileSize, Game1.tileSize), "", Game1.content.LoadString("Strings\\UI:Collections_Minerals", new object[0]), Game1.mouseCursors, new Rectangle(672, 64, 16, 16), (float)Game1.pixelZoom, false)); - this.collections.Add(3, new List>()); - this.sideTabs.Add(new ClickableTextureComponent("", new Rectangle(this.xPositionOnScreen - Game1.tileSize * 3 / 4, this.yPositionOnScreen + Game1.tileSize * 6, Game1.tileSize, Game1.tileSize), "", Game1.content.LoadString("Strings\\UI:Collections_Cooking", new object[0]), Game1.mouseCursors, new Rectangle(688, 64, 16, 16), (float)Game1.pixelZoom, false)); - this.collections.Add(4, new List>()); - this.sideTabs.Add(new ClickableTextureComponent("", new Rectangle(this.xPositionOnScreen - Game1.tileSize * 3 / 4, this.yPositionOnScreen + Game1.tileSize * 7, Game1.tileSize, Game1.tileSize), "", Game1.content.LoadString("Strings\\UI:Collections_Achievements", new object[0]), Game1.mouseCursors, new Rectangle(656, 80, 16, 16), (float)Game1.pixelZoom, false)); - this.collections.Add(5, new List>()); - UpdatedCollectionsPage.widthToMoveActiveTab = Game1.tileSize / 8; - this.backButton = new ClickableTextureComponent(new Rectangle(this.xPositionOnScreen + Game1.tileSize * 3 / 4, this.yPositionOnScreen + height - 20 * Game1.pixelZoom, 12 * Game1.pixelZoom, 11 * Game1.pixelZoom), Game1.mouseCursors, new Rectangle(352, 495, 12, 11), (float)Game1.pixelZoom, false); - this.forwardButton = new ClickableTextureComponent(new Rectangle(this.xPositionOnScreen + width - Game1.tileSize / 2 - 15 * Game1.pixelZoom, this.yPositionOnScreen + height - 20 * Game1.pixelZoom, 12 * Game1.pixelZoom, 11 * Game1.pixelZoom), Game1.mouseCursors, new Rectangle(365, 495, 12, 11), (float)Game1.pixelZoom, false); - int[] array = new int[this.sideTabs.Count]; + // initialise + this.CostMultiplier = costMultiplier; + + // create components + this.SideTabs.Add(new ClickableTextureComponent("", new Rectangle(this.xPositionOnScreen - Game1.tileSize * 3 / 4 + this.WidthToMoveActiveTab, this.yPositionOnScreen + Game1.tileSize * 2, Game1.tileSize, Game1.tileSize), "", Game1.content.LoadString("Strings\\UI:Collections_Shipped"), Game1.mouseCursors, new Rectangle(640, 80, 16, 16), Game1.pixelZoom)); + this.Collections.Add(BuyBackMenu.OrganicsTab, new List>()); + this.SideTabs.Add(new ClickableTextureComponent("", new Rectangle(this.xPositionOnScreen - Game1.tileSize * 3 / 4, this.yPositionOnScreen + Game1.tileSize * 3, Game1.tileSize, Game1.tileSize), "", Game1.content.LoadString("Strings\\UI:Collections_Fish"), Game1.mouseCursors, new Rectangle(640, 64, 16, 16), Game1.pixelZoom)); + this.Collections.Add(BuyBackMenu.FishTab, new List>()); + this.SideTabs.Add(new ClickableTextureComponent("", new Rectangle(this.xPositionOnScreen - Game1.tileSize * 3 / 4, this.yPositionOnScreen + Game1.tileSize * 4, Game1.tileSize, Game1.tileSize), "", Game1.content.LoadString("Strings\\UI:Collections_Artifacts"), Game1.mouseCursors, new Rectangle(656, 64, 16, 16), Game1.pixelZoom)); + this.Collections.Add(BuyBackMenu.ArchaeologyTab, new List>()); + this.SideTabs.Add(new ClickableTextureComponent("", new Rectangle(this.xPositionOnScreen - Game1.tileSize * 3 / 4, this.yPositionOnScreen + Game1.tileSize * 5, Game1.tileSize, Game1.tileSize), "", Game1.content.LoadString("Strings\\UI:Collections_Minerals"), Game1.mouseCursors, new Rectangle(672, 64, 16, 16), Game1.pixelZoom)); + this.Collections.Add(BuyBackMenu.MineralsTab, new List>()); + this.SideTabs.Add(new ClickableTextureComponent("", new Rectangle(this.xPositionOnScreen - Game1.tileSize * 3 / 4, this.yPositionOnScreen + Game1.tileSize * 6, Game1.tileSize, Game1.tileSize), "", Game1.content.LoadString("Strings\\UI:Collections_Cooking"), Game1.mouseCursors, new Rectangle(688, 64, 16, 16), Game1.pixelZoom)); + this.Collections.Add(BuyBackMenu.CookingTab, new List>()); + this.SideTabs.Add(new ClickableTextureComponent("", new Rectangle(this.xPositionOnScreen - Game1.tileSize * 3 / 4, this.yPositionOnScreen + Game1.tileSize * 7, Game1.tileSize, Game1.tileSize), "", Game1.content.LoadString("Strings\\UI:Collections_Achievements"), Game1.mouseCursors, new Rectangle(656, 80, 16, 16), Game1.pixelZoom)); + this.Collections.Add(BuyBackMenu.AchievementsTab, new List>()); + this.BackButton = new ClickableTextureComponent(new Rectangle(this.xPositionOnScreen + Game1.tileSize * 3 / 4, this.yPositionOnScreen + height - 20 * Game1.pixelZoom, 12 * Game1.pixelZoom, 11 * Game1.pixelZoom), Game1.mouseCursors, new Rectangle(352, 495, 12, 11), Game1.pixelZoom); + this.ForwardButton = new ClickableTextureComponent(new Rectangle(this.xPositionOnScreen + width - Game1.tileSize / 2 - 15 * Game1.pixelZoom, this.yPositionOnScreen + height - 20 * Game1.pixelZoom, 12 * Game1.pixelZoom, 11 * Game1.pixelZoom), Game1.mouseCursors, new Rectangle(365, 495, 12, 11), Game1.pixelZoom); + int[] array = new int[this.SideTabs.Count]; int num = this.xPositionOnScreen + IClickableMenu.borderWidth + IClickableMenu.spaceToClearSideBorder; int num2 = this.yPositionOnScreen + IClickableMenu.borderWidth + IClickableMenu.spaceToClearTopBorder - Game1.tileSize / 4; int num3 = 10; - foreach (KeyValuePair current in Game1.objectInformation) + foreach (KeyValuePair entry in Game1.objectInformation) { - string text = current.Value.Split(new char[] - { - '/' - })[3]; + string fields = entry.Value.Split('/')[3]; bool drawShadow = false; - int num4; - if (text.Contains("Arch")) + int selectedTab; + if (fields.Contains("Arch")) { - num4 = 2; - if (Game1.player.archaeologyFound.ContainsKey(current.Key)) - { + selectedTab = BuyBackMenu.ArchaeologyTab; + if (Game1.player.archaeologyFound.ContainsKey(entry.Key)) drawShadow = true; - } } - else if (text.Contains("Fish")) + else if (fields.Contains("Fish")) { - if (current.Key >= 167 && current.Key < 173) - { + if (entry.Key >= 167 && entry.Key < 173) continue; - } - num4 = 1; - if (Game1.player.fishCaught.ContainsKey(current.Key)) - { + selectedTab = BuyBackMenu.FishTab; + if (Game1.player.fishCaught.ContainsKey(entry.Key)) drawShadow = true; - } } - else if (text.Contains("Mineral") || text.Substring(text.Length - 3).Equals("-2")) + else if (fields.Contains("Mineral") || fields.Substring(fields.Length - 3).Equals("-2")) { - num4 = 3; - if (Game1.player.mineralsFound.ContainsKey(current.Key)) - { + selectedTab = BuyBackMenu.MineralsTab; + if (Game1.player.mineralsFound.ContainsKey(entry.Key)) drawShadow = true; - } } - else if (text.Contains("Cooking") || text.Substring(text.Length - 3).Equals("-7")) + else if (fields.Contains("Cooking") || fields.Substring(fields.Length - 3).Equals("-7")) { - num4 = 4; - if (Game1.player.recipesCooked.ContainsKey(current.Key)) - { + selectedTab = BuyBackMenu.CookingTab; + if (Game1.player.recipesCooked.ContainsKey(entry.Key)) drawShadow = true; - } - if (current.Key == 217 || current.Key == 772) - { + if (entry.Key == 217 || entry.Key == 772 || entry.Key == 773) continue; - } - if (current.Key == 773) - { - continue; - } } else { - if (!StardewValley.Object.isPotentialBasicShippedCategory(current.Key, text.Substring(text.Length - 3))) - { + if (!Object.isPotentialBasicShippedCategory(entry.Key, fields.Substring(fields.Length - 3))) continue; - } - num4 = 0; - if (Game1.player.basicShipped.ContainsKey(current.Key)) - { + selectedTab = BuyBackMenu.OrganicsTab; + if (Game1.player.basicShipped.ContainsKey(entry.Key)) drawShadow = true; - } } - int x2 = num + array[num4] % num3 * (Game1.tileSize + 4); - int num5 = num2 + array[num4] / num3 * (Game1.tileSize + 4); + int x2 = num + array[selectedTab] % num3 * (Game1.tileSize + 4); + int num5 = num2 + array[selectedTab] / num3 * (Game1.tileSize + 4); if (num5 > this.yPositionOnScreen + height - 128) { - this.collections[num4].Add(new List()); - array[num4] = 0; + this.Collections[selectedTab].Add(new List()); + array[selectedTab] = 0; x2 = num; num5 = num2; } - if (this.collections[num4].Count == 0) - { - this.collections[num4].Add(new List()); - } - this.collections[num4].Last>().Add(new ClickableTextureComponent(current.Key + " " + drawShadow.ToString(), new Rectangle(x2, num5, Game1.tileSize, Game1.tileSize), null, "", Game1.objectSpriteSheet, Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, current.Key, 16, 16), (float)Game1.pixelZoom, drawShadow)); - array[num4]++; - } - if (this.collections[5].Count == 0) - { - this.collections[5].Add(new List()); + if (this.Collections[selectedTab].Count == 0) + this.Collections[selectedTab].Add(new List()); + this.Collections[selectedTab].Last().Add(new ClickableTextureComponent(entry.Key + " " + drawShadow, new Rectangle(x2, num5, Game1.tileSize, Game1.tileSize), null, "", Game1.objectSpriteSheet, Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, entry.Key, 16, 16), Game1.pixelZoom, drawShadow)); + array[selectedTab]++; } + if (this.Collections[5].Count == 0) + this.Collections[5].Add(new List()); foreach (KeyValuePair current2 in Game1.achievements) { bool flag = Game1.player.achievements.Contains(current2.Key); - string[] array2 = current2.Value.Split(new char[] - { - '^' - }); - if (flag || (array2[2].Equals("true") && (array2[3].Equals("-1") || this.farmerHasAchievements(array2[3])))) + string[] array2 = current2.Value.Split('^'); + if (flag || (array2[2].Equals("true") && (array2[3].Equals("-1") || this.FarmerHasAchievements(array2[3])))) { int x3 = num + array[5] % num3 * (Game1.tileSize + 4); int y2 = num2 + array[5] / num3 * (Game1.tileSize + 4); - this.collections[5][0].Add(new ClickableTextureComponent(current2.Key + " " + flag.ToString(), new Rectangle(x3, y2, Game1.tileSize, Game1.tileSize), null, "", Game1.mouseCursors, Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, 25, -1, -1), 1f, false)); + this.Collections[5][0].Add(new ClickableTextureComponent(current2.Key + " " + flag, new Rectangle(x3, y2, Game1.tileSize, Game1.tileSize), null, "", Game1.mouseCursors, Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, 25), 1f)); array[5]++; } } } - private bool farmerHasAchievements(string listOfAchievementNumbers) + + /********* + ** Private methods + *********/ + /// Get whether the farmer has the given achievements. + /// The achievement IDs as a space-separated list. + private bool FarmerHasAchievements(string listOfAchievementNumbers) { - string[] array = listOfAchievementNumbers.Split(new char[] + string[] array = listOfAchievementNumbers.Split(' '); + foreach (string text in array) { - ' ' - }); - for (int i = 0; i < array.Length; i++) - { - string text = array[i]; if (!Game1.player.achievements.Contains(Convert.ToInt32(text))) - { return false; - } } return true; } + /// The method invoked when the player left-clicks on the menu. + /// The X-position of the cursor. + /// The Y-position of the cursor. + /// Whether to enable sound. public override void receiveLeftClick(int x, int y, bool playSound = true) { - for (int i = 0; i < this.sideTabs.Count; i++) + for (int i = 0; i < this.SideTabs.Count; i++) { - if (this.sideTabs[i].containsPoint(x, y) && this.currentTab != i) + if (this.SideTabs[i].containsPoint(x, y) && this.CurrentTab != i) { Game1.playSound("smallSelect"); - ClickableTextureComponent expr_47_cp_0_cp_0 = this.sideTabs[this.currentTab]; - expr_47_cp_0_cp_0.bounds.X = expr_47_cp_0_cp_0.bounds.X - UpdatedCollectionsPage.widthToMoveActiveTab; - this.currentTab = i; - this.currentPage = 0; - ClickableTextureComponent expr_74_cp_0_cp_0 = this.sideTabs[i]; - expr_74_cp_0_cp_0.bounds.X = expr_74_cp_0_cp_0.bounds.X + UpdatedCollectionsPage.widthToMoveActiveTab; + ClickableTextureComponent curTab = this.SideTabs[this.CurrentTab]; + curTab.bounds.X = curTab.bounds.X - this.WidthToMoveActiveTab; + this.CurrentTab = i; + this.CurrentPage = 0; + ClickableTextureComponent newTab = this.SideTabs[i]; + newTab.bounds.X = newTab.bounds.X + this.WidthToMoveActiveTab; } } - if (this.currentPage > 0 && this.backButton.containsPoint(x, y)) + if (this.CurrentPage > 0 && this.BackButton.containsPoint(x, y)) { - this.currentPage--; + this.CurrentPage--; Game1.playSound("shwip"); - this.backButton.scale = this.backButton.baseScale; + this.BackButton.scale = this.BackButton.baseScale; } - if (this.currentPage < this.collections[this.currentTab].Count - 1 && this.forwardButton.containsPoint(x, y)) + if (this.CurrentPage < this.Collections[this.CurrentTab].Count - 1 && this.ForwardButton.containsPoint(x, y)) { - this.currentPage++; + this.CurrentPage++; Game1.playSound("shwip"); - this.forwardButton.scale = this.forwardButton.baseScale; + this.ForwardButton.scale = this.ForwardButton.baseScale; } - foreach (ClickableTextureComponent current2 in this.collections[this.currentTab][this.currentPage]) + foreach (ClickableTextureComponent current2 in this.Collections[this.CurrentTab][this.CurrentPage]) { - if (current2.containsPoint(x, y)) + if (current2.containsPoint(x, y) && this.NewItem != null && Game1.player.money >= this.Value) { - if (new_item != null) - { - if (Game1.player.money >= value) - { - Game1.player.money -= value; - Game1.player.addItemByMenuIfNecessary(new_item); - } - - } + Game1.player.money -= this.Value; + Game1.player.addItemByMenuIfNecessary(this.NewItem); } } } + /// The method invoked when the player right-clicks on the lookup UI. + /// The X-position of the cursor. + /// The Y-position of the cursor. + /// Whether to enable sound. public override void receiveRightClick(int x, int y, bool playSound = true) { - if (new_item != null) + if (this.NewItem != null && Game1.player.money >= this.Value) { - if (Game1.player.money >= value) - { - - Game1.player.money -= value; - Game1.player.addItemByMenuIfNecessary(new_item); - } - + Game1.player.money -= this.Value; + Game1.player.addItemByMenuIfNecessary(this.NewItem); } } + /// The method invoked when the player hovers the cursor over the menu. + /// The X-position of the cursor. + /// The Y-position of the cursor. public override void performHoverAction(int x, int y) { - this.descriptionText = ""; - this.hoverText = ""; - this.value = -1; - foreach (ClickableTextureComponent current in this.sideTabs) + this.HoverText = ""; + this.Value = -1; + foreach (ClickableTextureComponent current in this.SideTabs) { if (current.containsPoint(x, y)) { - this.hoverText = current.hoverText; + this.HoverText = current.hoverText; return; } } - foreach (ClickableTextureComponent current2 in this.collections[this.currentTab][this.currentPage]) + foreach (ClickableTextureComponent current2 in this.Collections[this.CurrentTab][this.CurrentPage]) { if (current2.containsPoint(x, y)) { current2.scale = Math.Min(current2.scale + 0.02f, current2.baseScale + 0.1f); - if (Convert.ToBoolean(current2.name.Split(new char[] - { - ' ' - })[1]) || this.currentTab == 5) - { - this.hoverText = this.createDescription(Convert.ToInt32(current2.name.Split(new char[] - { - ' ' - })[0])); - } + if (Convert.ToBoolean(current2.name.Split(' ')[1]) || this.CurrentTab == 5) + this.HoverText = this.CreateDescription(Convert.ToInt32(current2.name.Split(' ')[0])); else - { - this.hoverText = "???"; - } + this.HoverText = "???"; } else { current2.scale = Math.Max(current2.scale - 0.02f, current2.baseScale); } } - this.forwardButton.tryHover(x, y, 0.5f); - this.backButton.tryHover(x, y, 0.5f); + this.ForwardButton.tryHover(x, y, 0.5f); + this.BackButton.tryHover(x, y, 0.5f); } - public string createDescription(int index) + /// Generate the item description for an item ID. + /// The item ID. + private string CreateDescription(int index) { string text = ""; - if (this.currentTab == 5) + if (this.CurrentTab == 5) { - string[] array = Game1.achievements[index].Split(new char[] - { - '^' - }); + string[] array = Game1.achievements[index].Split('^'); text = text + array[0] + Environment.NewLine + Environment.NewLine; text += array[1]; - new_item = null; + this.NewItem = null; } else { - string[] array2 = Game1.objectInformation[index].Split(new char[] - { - '/' - }); + string[] array2 = Game1.objectInformation[index].Split('/'); foreach (KeyValuePair meh in Game1.objectInformation) { - string[] array3 = meh.Value.Split(new char[] - { - '/' - }); + string[] array3 = meh.Value.Split('/'); if (array3[0] == array2[0]) { - new_item = (Item)new Object(Convert.ToInt32(meh.Key), 1, false, -1, 0); - if (new_item.Name == "Stone" || new_item.Name == "stone") new_item = (Item)new Object(390, 1, false, -1, 0); + this.NewItem = new Object(Convert.ToInt32(meh.Key), 1); + if (this.NewItem.Name == "Stone" || this.NewItem.Name == "stone") this.NewItem = new Object(390, 1); } } - text = string.Concat(new string[] - { - text, - array2[0], - Environment.NewLine, - Environment.NewLine, - Game1.parseText(array2[4], Game1.smallFont, Game1.tileSize * 4), - Environment.NewLine, - Environment.NewLine - }); + text = string.Concat(text, array2[0], Environment.NewLine, Environment.NewLine, Game1.parseText(array2[4], Game1.smallFont, Game1.tileSize * 4), Environment.NewLine, Environment.NewLine); if (array2[3].Contains("Arch")) { - text += (Game1.player.archaeologyFound.ContainsKey(index) ? Game1.content.LoadString("Strings\\UI:Collections_Description_ArtifactsFound", new object[] - { - Game1.player.archaeologyFound[index][0] - }) : ""); + text += (Game1.player.archaeologyFound.ContainsKey(index) ? Game1.content.LoadString("Strings\\UI:Collections_Description_ArtifactsFound", Game1.player.archaeologyFound[index][0]) : ""); } else if (array2[3].Contains("Cooking")) { - text += (Game1.player.recipesCooked.ContainsKey(index) ? Game1.content.LoadString("Strings\\UI:Collections_Description_RecipesCooked", new object[] - { - Game1.player.recipesCooked[index] - }) : ""); + text += (Game1.player.recipesCooked.ContainsKey(index) ? Game1.content.LoadString("Strings\\UI:Collections_Description_RecipesCooked", Game1.player.recipesCooked[index]) : ""); } else if (array2[3].Contains("Fish")) { - text += Game1.content.LoadString("Strings\\UI:Collections_Description_FishCaught", new object[] - { - Game1.player.fishCaught.ContainsKey(index) ? Game1.player.fishCaught[index][0] : 0 - }); + text += Game1.content.LoadString("Strings\\UI:Collections_Description_FishCaught", Game1.player.fishCaught.ContainsKey(index) ? Game1.player.fishCaught[index][0] : 0); if (Game1.player.fishCaught.ContainsKey(index) && Game1.player.fishCaught[index][1] > 0) { - text = text + Environment.NewLine + Game1.content.LoadString("Strings\\UI:Collections_Description_BiggestCatch", new object[] - { - Game1.player.fishCaught[index][1] - }); + text = text + Environment.NewLine + Game1.content.LoadString("Strings\\UI:Collections_Description_BiggestCatch", Game1.player.fishCaught[index][1]); } } else if (array2[3].Contains("Minerals") || array2[3].Substring(array2[3].Length - 3).Equals("-2")) { - text += Game1.content.LoadString("Strings\\UI:Collections_Description_MineralsFound", new object[] - { - Game1.player.mineralsFound.ContainsKey(index) ? Game1.player.mineralsFound[index] : 0 - }); + text += Game1.content.LoadString("Strings\\UI:Collections_Description_MineralsFound", Game1.player.mineralsFound.ContainsKey(index) ? Game1.player.mineralsFound[index] : 0); } else { - text += Game1.content.LoadString("Strings\\UI:Collections_Description_NumberShipped", new object[] - { - Game1.player.basicShipped.ContainsKey(index) ? Game1.player.basicShipped[index] : 0 - }); + text += Game1.content.LoadString("Strings\\UI:Collections_Description_NumberShipped", Game1.player.basicShipped.ContainsKey(index) ? Game1.player.basicShipped[index] : 0); } - this.value = Convert.ToInt32(array2[1]); - this.value = (int)(this.value * Class1.cost); - newItemValue = this.value; + this.Value = Convert.ToInt32(array2[1]); + this.Value = (int)(this.Value * this.CostMultiplier); + this.NewItemValue = this.Value; } return text; } + /// Draw the menu to the screen. + /// The sprite batch. public override void draw(SpriteBatch b) { - Game1.drawDialogueBox(this.xPositionOnScreen, this.yPositionOnScreen, this.width, this.height, false, true, null, false); - using (List.Enumerator enumerator = this.sideTabs.GetEnumerator()) - { - while (enumerator.MoveNext()) - { - enumerator.Current.draw(b); - } - } - if (this.currentPage > 0) - { - this.backButton.draw(b); - } - if (this.currentPage < this.collections[this.currentTab].Count - 1) - { - this.forwardButton.draw(b); - } + Game1.drawDialogueBox(this.xPositionOnScreen, this.yPositionOnScreen, this.width, this.height, false, true); + + foreach (var tab in this.SideTabs) + tab.draw(b); + + if (this.CurrentPage > 0) + this.BackButton.draw(b); + if (this.CurrentPage < this.Collections[this.CurrentTab].Count - 1) + this.ForwardButton.draw(b); b.End(); b.Begin(SpriteSortMode.FrontToBack, BlendState.NonPremultiplied, SamplerState.PointClamp, null, null); - foreach (ClickableTextureComponent current in this.collections[this.currentTab][this.currentPage]) + foreach (ClickableTextureComponent current in this.Collections[this.CurrentTab][this.CurrentPage]) { - bool flag = Convert.ToBoolean(current.name.Split(new char[] - { - ' ' - })[1]); + bool flag = Convert.ToBoolean(current.name.Split(' ')[1]); current.draw(b, flag ? Color.White : (Color.Black * 0.2f), 0.86f); - if (this.currentTab == 5 & flag) + if (this.CurrentTab == 5 & flag) { - int num = new Random(Convert.ToInt32(current.name.Split(new char[] - { - ' ' - })[0])).Next(12); - b.Draw(Game1.mouseCursors, new Vector2((float)(current.bounds.X + 16 + Game1.tileSize / 4), (float)(current.bounds.Y + 20 + Game1.tileSize / 4)), new Rectangle?(new Rectangle(256 + num % 6 * Game1.tileSize / 2, 128 + num / 6 * Game1.tileSize / 2, Game1.tileSize / 2, Game1.tileSize / 2)), Color.White, 0f, new Vector2((float)(Game1.tileSize / 4), (float)(Game1.tileSize / 4)), current.scale, SpriteEffects.None, 0.88f); + int num = new Random(Convert.ToInt32(current.name.Split(' ')[0])).Next(12); + b.Draw(Game1.mouseCursors, new Vector2(current.bounds.X + 16 + Game1.tileSize / 4, current.bounds.Y + 20 + Game1.tileSize / 4), new Rectangle(256 + num % 6 * Game1.tileSize / 2, 128 + num / 6 * Game1.tileSize / 2, Game1.tileSize / 2, Game1.tileSize / 2), Color.White, 0f, new Vector2(Game1.tileSize / 4, Game1.tileSize / 4), current.scale, SpriteEffects.None, 0.88f); } } b.End(); b.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); - if (!this.hoverText.Equals("")) - { - IClickableMenu.drawHoverText(b, this.hoverText, Game1.smallFont, 0, 0, this.value, null, -1, null, null, 0, -1, -1, -1, -1, 1f, null); - } + if (!this.HoverText.Equals("")) + IClickableMenu.drawHoverText(b, this.HoverText, Game1.smallFont, 0, 0, this.Value); if (!Game1.options.hardwareCursor) - { - b.Draw(Game1.mouseCursors, new Vector2((float)Game1.getMouseX(), (float)Game1.getMouseY()), new Rectangle?(Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, 0, 16, 16)), Color.White * Game1.mouseCursorTransparency, 0f, Vector2.Zero, (float)Game1.pixelZoom + Game1.dialogueButtonScale / 150f, SpriteEffects.None, 1f); - } - + b.Draw(Game1.mouseCursors, new Vector2(Game1.getMouseX(), Game1.getMouseY()), Game1.getSourceRectForStandardTileSheet(Game1.mouseCursors, 0, 16, 16), Color.White * Game1.mouseCursorTransparency, 0f, Vector2.Zero, Game1.pixelZoom + Game1.dialogueButtonScale / 150f, SpriteEffects.None, 1f); + } } } diff --git a/GeneralMods/BuyBackCollectables/manifest.json b/GeneralMods/BuyBackCollectables/manifest.json index 3fcf78f4..75dc7c6e 100644 --- a/GeneralMods/BuyBackCollectables/manifest.json +++ b/GeneralMods/BuyBackCollectables/manifest.json @@ -11,4 +11,4 @@ "UniqueID": "BuyBackCollectables", "PerSaveConfigs": false, "EntryDll": "BuyBackCollectables.dll" -} \ No newline at end of file +}