diff --git a/GeneralMods/CustomShopsRedux/Class1.cs b/GeneralMods/CustomShopsRedux/Class1.cs index 597e9bed..2a32d717 100644 --- a/GeneralMods/CustomShopsRedux/Class1.cs +++ b/GeneralMods/CustomShopsRedux/Class1.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using Microsoft.Xna.Framework; using StardewModdingAPI; +using StardewModdingAPI.Events; using StardewValley; using StardewValley.Menus; using StardewValley.Objects; @@ -24,808 +25,717 @@ craftables- */ namespace Omegasis.CustomShopsRedux { - public class Class1 : Mod + /// The mod entry point. + public class CustomShopsRedux : Mod { - public static IClickableMenu mymenu; - static int j = 0; - static Dictionary list_price = new Dictionary(); + /********* + ** Properties + *********/ + /// The prices for the items to list. + private readonly Dictionary ListPrices = new Dictionary(); - static string master_path; - List myoptions = new List(); - string key_binding = "U"; + /// The folder path containing shop data files. + private string DataPath; - bool game_loaded = false; + /// The configured shop options. + private readonly List Options = new List(); - public override void Entry(params object[] objects) + /// The key which shows the menu. + private string KeyBinding = "U"; + + /// Whether the player loaded a save. + private bool IsGameLoaded; + + + /********* + ** Public methods + *********/ + /// The mod entry point, called after the mod is first loaded. + /// The mod arguments. + public override void Entry(params object[] args) { - //set up all of my events here - StardewModdingAPI.Events.PlayerEvents.LoadedGame += PlayerEvents_LoadedGame; - StardewModdingAPI.Events.ControlEvents.KeyPressed += ControlEvents_KeyPressed; + PlayerEvents.LoadedGame += this.PlayerEvents_LoadedGame; + ControlEvents.KeyPressed += this.ControlEvents_KeyPressed; } - - public void ControlEvents_KeyPressed(object sender, StardewModdingAPI.Events.EventArgsKeyPressed e) + /********* + ** Private methods + *********/ + /// The method invoked after the player loads a save. + /// The event sender. + /// The event data. + private void PlayerEvents_LoadedGame(object sender, EventArgsLoadedGameChanged e) { - if (game_loaded == false) return; - - if (e.KeyPressed.ToString() == key_binding) //if the key is pressed, load my cusom save function - { - - my_key_call(); - - - } - //DataLoader_Settings(); //update the key if players changed it while playing. - + this.IsGameLoaded = true; + this.LoadConfig(); + this.WriteConfig(); } - public void PlayerEvents_LoadedGame(object sender, StardewModdingAPI.Events.EventArgsLoadedGameChanged e) + /// The method invoked when the presses a keyboard button. + /// The event sender. + /// The event data. + private void ControlEvents_KeyPressed(object sender, EventArgsKeyPressed e) { - game_loaded = true; - DataLoader_Settings(); - MyWritter_Settings(); - } - - - - - void DataLoader_Settings() - { - //loads the data to the variables upon loading the game. - string myname = StardewValley.Game1.player.name; - string mylocation = Path.Combine(PathOnDisk, "Custom_Shop_Redux_Config"); - string mylocation2 = mylocation; - string mylocation3 = mylocation2 + ".txt"; - master_path = PathOnDisk; - - Directory.CreateDirectory(Path.Combine(master_path, "Custom_Shops")); - - master_path = Path.Combine(master_path, "Custom_Shops"); - - - - if (!File.Exists(mylocation3)) //if not data.json exists, initialize the data variables to the ModConfig data. I.E. starting out. - { - // Console.WriteLine("Can't load custom save info since the file doesn't exist."); - - key_binding = "U"; - // Log.Info("KEY TIME"); - } - - else - { - // Console.WriteLine("HEY THERE IM LOADING DATA"); - string[] readtext = File.ReadAllLines(mylocation3); - key_binding = Convert.ToString(readtext[3]); - - - // Log.Info(key_binding); - // Log.Info(Convert.ToString(readtext[3])); - - } - } - - void MyWritter_Settings() - { - - //write all of my info to a text file. - string myname = StardewValley.Game1.player.name; - - string mylocation = Path.Combine(PathOnDisk, "Custom_Shop_Redux_Config"); - string mylocation2 = mylocation; - string mylocation3 = mylocation2 + ".txt"; - - string[] mystring3 = new string[20]; - if (!File.Exists(mylocation3)) - { - Console.WriteLine("The custom character save info doesn't exist. It will be created when the custom saving method is run. Which is now."); - - mystring3[0] = "Config: Custom_Shop_Redux. Feel free to mess with these settings."; - mystring3[1] = "===================================================================================="; - - mystring3[2] = "Key binding for saving anywhere. Press this key to save anywhere!"; - mystring3[3] = key_binding.ToString(); - - - - File.WriteAllLines(mylocation3, mystring3); - - } - - else - { - - //write out the info to a text file at the end of a day. This will run if it doesnt exist. - Console.WriteLine("The custom character save info doesn't exist. It will be created when the custom saving method is run. Which is now."); - - mystring3[0] = "Config: Custom_Shop_Redux. Feel free to mess with these settings."; - mystring3[1] = "===================================================================================="; - - mystring3[2] = "Key binding for saving anywhere. Press this key to save anywhere!"; - mystring3[3] = key_binding.ToString(); - - - - File.WriteAllLines(mylocation3, mystring3); - } - } - - - - - public void my_key_call() - { - var modpath = new Class1(); - - - DirectoryInfo d = new DirectoryInfo(master_path);//Assuming Test is your Folder - Log.Info(d); - // System.Threading.Thread.Sleep(20000); - - FileInfo[] Files = d.GetFiles("*.txt"); //Getting Text files - string str = ""; - - if (Files.Length == 0) - { - Log.Error("No shop .txt information is found. You should create one."); + if (!this.IsGameLoaded) return; - } - foreach (FileInfo file in Files) + if (e.KeyPressed.ToString() == this.KeyBinding) //if the key is pressed, load my cusom save function { - str = file.Name; - // Log.Info(str); - - myoptions.Add(str); + this.OpenSelectFileMenu(); } + } - if (myoptions.Count == 0) + /// Load the configuration settings. + private void LoadConfig() + { + this.DataPath = Path.Combine(this.PathOnDisk, "Custom_Shops"); + Directory.CreateDirectory(this.DataPath); + + string path = Path.Combine(this.PathOnDisk, "Custom_Shop_Redux_Config.txt"); + if (!File.Exists(path)) //if not data.json exists, initialize the data variables to the ModConfig data. I.E. starting out. + { + this.KeyBinding = "U"; + } + else + { + string[] text = File.ReadAllLines(path); + this.KeyBinding = Convert.ToString(text[3]); + } + } + + /// Save the configuration settings. + private void WriteConfig() + { + string path = Path.Combine(PathOnDisk, "Custom_Shop_Redux_Config.txt"); + string[] text = new string[20]; + if (!File.Exists(path)) + { + Console.WriteLine("The custom character save info doesn't exist. It will be created when the custom saving method is run. Which is now."); + + text[0] = "Config: Custom_Shop_Redux. Feel free to mess with these settings."; + text[1] = "===================================================================================="; + + text[2] = "Key binding for saving anywhere. Press this key to save anywhere!"; + text[3] = this.KeyBinding; + + File.WriteAllLines(path, text); + } + else + { + Console.WriteLine("The custom character save info doesn't exist. It will be created when the custom saving method is run. Which is now."); + + text[0] = "Config: Custom_Shop_Redux. Feel free to mess with these settings."; + text[1] = "===================================================================================="; + + text[2] = "Key binding for saving anywhere. Press this key to save anywhere!"; + text[3] = this.KeyBinding; + + File.WriteAllLines(path, text); + } + } + + /// Open the menu which lets the player choose a file. + private void OpenSelectFileMenu() + { + // get mod folder + DirectoryInfo modFolder = new DirectoryInfo(this.DataPath); + Log.Info(modFolder); + + // get text files + FileInfo[] files = modFolder.GetFiles("*.txt"); + if (!files.Any()) { Log.Error("No shop .txt information is found. You should create one."); return; } - StardewValley.Menus.ChooseFromListMenu mychoices = new StardewValley.Menus.ChooseFromListMenu(myoptions, new ChooseFromListMenu.actionOnChoosingListOption(shop_file_call), false); - - Game1.activeClickableMenu = mychoices; - - - - - - + // parse options + foreach (FileInfo file in files) + this.Options.Add(file.Name); + if (!this.Options.Any()) + { + Log.Error("No shop .txt information is found. You should create one."); + return; + } + // load menu + Game1.activeClickableMenu = new ChooseFromListMenu(this.Options, this.OnChoiceSelected); } - - - static void shop_file_call(string s) + /// The method called when the player chooses an option from the file list. + /// The selected file name. + private void OnChoiceSelected(string filename) { - List list = new List(); - + // read file data + string path = Path.Combine(this.DataPath, filename); + string[] text = File.ReadAllLines(path); + int lineCount = text.Length; - string mylocation = Path.Combine(master_path , s); - - /// Log.Info(mylocation); - - - string[] readtext = File.ReadAllLines(mylocation); - - var lineCount = File.ReadLines(mylocation).Count(); - - -// Log.Info(lineCount); - - if(s== "Custom_Shop_Redux_Config.txt") + // validate + if (filename == "Custom_Shop_Redux_Config.txt") { Log.Info("Silly human. The config file is not a shop."); return; } - int i = 4; - - int obj_id = 0; - bool is_recipe; - int price; - int quality; - - string obj_type; - - obj_type = Convert.ToString(readtext[i]); - i += 2; - - - + // parse data + string objType = Convert.ToString(text[4]); + int i = 6; while (i < lineCount) { - if (i >= lineCount) break; - if (obj_type == "") break; - if (readtext[i] == "") break; + if (i >= lineCount || objType == "" || text[i] == "") break; //read in a line for obj type here Log.Info(i); - Log.Info(obj_type); - if (obj_type == "item" || obj_type == "Item" || obj_type == "Object" || obj_type == "object") + Log.Info(objType); + int objID; + int price; + if (objType == "item" || objType == "Item" || objType == "Object" || objType == "object") { - - obj_id = Convert.ToInt16(readtext[i]); + objID = Convert.ToInt16(text[i]); i += 2; Log.Info(i); - is_recipe = Convert.ToBoolean(readtext[i]); + bool isRecipe = Convert.ToBoolean(text[i]); i += 2; Log.Info(i); - price = Convert.ToInt32(readtext[i]); + price = Convert.ToInt32(text[i]); i += 2; Log.Info(i); - quality = Convert.ToInt32(readtext[i]); - // if (quality > 2) quality = 0; - + int quality = Convert.ToInt32(text[i]); if (price == -1) { - StardewValley.Object myobj = new StardewValley.Object(obj_id, int.MaxValue, is_recipe, price, quality); - - // Log.Info("MYPRICE"); - // Log.Info(myobj.salePrice()); + StardewValley.Object myobj = new StardewValley.Object(objID, int.MaxValue, isRecipe, price, quality); price = myobj.salePrice(); - } - - // list.Add((Item)new StardewValley.Object(obj_id, int.MaxValue, is_recipe, price, quality)); - list_price.Add((Item)new StardewValley.Object(obj_id, int.MaxValue, is_recipe, price, quality), new int[2] {price, int.MaxValue}); + this.ListPrices.Add(new StardewValley.Object(objID, int.MaxValue, isRecipe, price, quality), new[] { price, int.MaxValue }); i += 3; - if (i >= lineCount) break; + if (i >= lineCount) + break; } - if (obj_type == "Furniture" || obj_type == "furniture") + + if (objType == "Furniture" || objType == "furniture") { - obj_id = Convert.ToInt32(readtext[i]); + objID = Convert.ToInt32(text[i]); i += 2; - price = Convert.ToInt32(readtext[i]); + price = Convert.ToInt32(text[i]); - // list.Add((Item)new Furniture(obj_id, Vector2.Zero)); //ADD FUNCTIONALITY TO SHOP FILES TO TEST IF FURNITURE OR NOT. - list_price.Add((Item)new Furniture(obj_id, Vector2.Zero), new int[2] { price, int.MaxValue }); + this.ListPrices.Add(new Furniture(objID, Vector2.Zero), new[] { price, int.MaxValue }); i += 3; - if (i>= lineCount) break; - - - - + if (i >= lineCount) + break; } - if (obj_type == "Boots" || obj_type == "boots" || obj_type == "shoe" || obj_type == "Shoe") //just incase someone forgets it's called boots and they type shoe. + if (objType == "Boots" || objType == "boots" || objType == "shoe" || objType == "Shoe") //just incase someone forgets it's called boots and they type shoe. { - obj_id = Convert.ToInt32(readtext[i]); + objID = Convert.ToInt32(text[i]); i += 2; - price= Convert.ToInt32(readtext[i]); - list_price.Add((Item)new StardewValley.Objects.Boots(obj_id),new int[2] { price, int.MaxValue }); + price = Convert.ToInt32(text[i]); + this.ListPrices.Add(new Boots(objID), new[] { price, int.MaxValue }); i += 3; - if (i >= lineCount) break; - + if (i >= lineCount) + break; } - if (obj_type == "WallPaper" || obj_type == "Wallpaper" || obj_type == "wallPaper" || obj_type == "wallpaper") //just incase someone forgets it's called boots and they type shoe. + if (objType == "WallPaper" || objType == "Wallpaper" || objType == "wallPaper" || objType == "wallpaper") { - if (i + 3 > lineCount) break; - obj_id = Convert.ToInt32(readtext[i]); + if (i + 3 > lineCount) + break; + objID = Convert.ToInt32(text[i]); i += 2; - price = Convert.ToInt32(readtext[i]); - list_price.Add((Item)new StardewValley.Objects.Wallpaper(obj_id, false), new int[2] { price, int.MaxValue }); //add in support for wallpapers and carpets + price = Convert.ToInt32(text[i]); + this.ListPrices.Add(new Wallpaper(objID), new[] { price, int.MaxValue }); //add in support for wallpapers and carpets i += 3; - if (i >= lineCount) break; + if (i >= lineCount) + break; } - if (obj_type == "Carpet" || obj_type == "carpet" || obj_type == "Floor" || obj_type == "floor" || obj_type == "Rug" || obj_type == "rug") + if (objType == "Carpet" || objType == "carpet" || objType == "Floor" || objType == "floor" || objType == "Rug" || objType == "rug") { - obj_id = Convert.ToInt32(readtext[i]); + objID = Convert.ToInt32(text[i]); i += 2; - price = Convert.ToInt32(readtext[i]); - list_price.Add((Item)new StardewValley.Objects.Wallpaper(obj_id, true), new int[2] { price, int.MaxValue }); //add in support for wallpapers and carpets + price = Convert.ToInt32(text[i]); + this.ListPrices.Add(new Wallpaper(objID, true), new[] { price, int.MaxValue }); //add in support for wallpapers and carpets i += 3; - if (i >= lineCount) break; + if (i >= lineCount) + break; } - if (obj_type == "Ring" || obj_type == "ring") + if (objType == "Ring" || objType == "ring") { - obj_id = Convert.ToInt32(readtext[i]); + objID = Convert.ToInt32(text[i]); i += 2; - price = Convert.ToInt32(readtext[i]); - list_price.Add((Item)new StardewValley.Objects.Ring(obj_id), new int[2] { price, int.MaxValue }); + price = Convert.ToInt32(text[i]); + this.ListPrices.Add(new Ring(objID), new[] { price, int.MaxValue }); i += 3; - if (i >= lineCount) break; + if (i >= lineCount) + break; } - if (obj_type == "Lamp" || obj_type == "lamp" || obj_type == "Torch" || obj_type == "torch" || obj_type == "Craftable" || obj_type == "craftable" || obj_type == "BigCraftable" || obj_type == "bigcraftable") + + if (objType == "Lamp" || objType == "lamp" || objType == "Torch" || objType == "torch" || objType == "Craftable" || objType == "craftable" || objType == "BigCraftable" || objType == "bigcraftable") { - obj_id = Convert.ToInt32(readtext[i]); + objID = Convert.ToInt32(text[i]); i += 2; - price = Convert.ToInt32(readtext[i]); - list_price.Add((Item)new StardewValley.Torch(Vector2.Zero, obj_id, true), new int[2] { price, int.MaxValue }); + price = Convert.ToInt32(text[i]); + this.ListPrices.Add(new Torch(Vector2.Zero, objID, true), new[] { price, int.MaxValue }); i += 3; - if (i >= lineCount) break; + if (i >= lineCount) + break; } - if (obj_type == "Sword" || obj_type == "sword" || obj_type == "Weapon" || obj_type == "weapon") + if (objType == "Sword" || objType == "sword" || objType == "Weapon" || objType == "weapon") { - obj_id = Convert.ToInt32(readtext[i]); + objID = Convert.ToInt32(text[i]); i += 2; - price = Convert.ToInt32(readtext[i]); - list_price.Add((Item)new MeleeWeapon(obj_id), new int[2] { price, int.MaxValue }); + price = Convert.ToInt32(text[i]); + this.ListPrices.Add(new MeleeWeapon(objID), new[] { price, int.MaxValue }); i += 3; - if (i >= lineCount) break; + if (i >= lineCount) + break; } - if (obj_type == "Hat" || obj_type == "hat" || obj_type == "Hats" || obj_type == "hats") + if (objType == "Hat" || objType == "hat" || objType == "Hats" || objType == "hats") { - obj_id = Convert.ToInt32(readtext[i]); + objID = Convert.ToInt32(text[i]); i += 2; - price = Convert.ToInt32(readtext[i]); - // list_price.Add((Item)new Hat(obj_id), new int[2] { price, int.MaxValue }); - list_price.Add((Item)new Hat(obj_id), new int[2] - { - price, - int.MaxValue - }); + price = Convert.ToInt32(text[i]); + this.ListPrices.Add(new Hat(objID), new[] { price, int.MaxValue }); i += 3; - if (i >= lineCount) break; + if (i >= lineCount) + break; } - //TODO: //add in support for colored objects //add in support for tools Log.Success(i); - if (i >= lineCount) break; - else { - obj_type = Convert.ToString(readtext[i]); - i += 2; - } - } + if (i >= lineCount) + break; + objType = Convert.ToString(text[i]); + i += 2; + } //NEED TO TEST ALL DATA FILES TO SEE WHAT CAN AND CANT BE ADDED //list.Add((Item)new StardewValley.Objects.ColoredObject(475,300, Color.Aqua)); - // Game1.activeClickableMenu = (IClickableMenu)new ShopMenu(list, 0, "Pierre"); - - - - - Game1.activeClickableMenu = (IClickableMenu)new ShopMenu(list_price, 0, "Pierre"); - - } //very basic shop call with choosable menu to iterate through. - - - public static void external_shop_file_call(string path, string fileName) - { - List list = new List(); - - - string mylocation = Path.Combine(path, fileName); - - /// Log.Info(mylocation); - - - string[] readtext = File.ReadAllLines(mylocation); - - var lineCount = File.ReadLines(mylocation).Count(); - - - // Log.Info(lineCount); - - int i = 4; - - int obj_id = 0; - bool is_recipe; - int price; - int quality; - - string obj_type; - - obj_type = Convert.ToString(readtext[i]); - i += 2; - - - - while (i < lineCount) - { - if (i >= lineCount) break; - if (obj_type == "") break; - if (readtext[i] == "") break; - - //read in a line for obj type here - Log.Info(i); - Log.Info(obj_type); - if (obj_type == "item" || obj_type == "Item" || obj_type == "Object" || obj_type == "object") - { - - obj_id = Convert.ToInt16(readtext[i]); - i += 2; - - Log.Info(i); - is_recipe = Convert.ToBoolean(readtext[i]); - i += 2; - Log.Info(i); - price = Convert.ToInt32(readtext[i]); - i += 2; - Log.Info(i); - - quality = Convert.ToInt32(readtext[i]); - // if (quality > 2) quality = 0; - - - if (price == -1) - { - StardewValley.Object myobj = new StardewValley.Object(obj_id, int.MaxValue, is_recipe, price, quality); - - // Log.Info("MYPRICE"); - // Log.Info(myobj.salePrice()); - price = myobj.salePrice(); - - } - - - // list.Add((Item)new StardewValley.Object(obj_id, int.MaxValue, is_recipe, price, quality)); - list_price.Add((Item)new StardewValley.Object(obj_id, int.MaxValue, is_recipe, price, quality), new int[2] { price, int.MaxValue }); - i += 3; - if (i >= lineCount) break; - } - if (obj_type == "Furniture" || obj_type == "furniture") - { - obj_id = Convert.ToInt32(readtext[i]); - i += 2; - price = Convert.ToInt32(readtext[i]); - - // list.Add((Item)new Furniture(obj_id, Vector2.Zero)); //ADD FUNCTIONALITY TO SHOP FILES TO TEST IF FURNITURE OR NOT. - list_price.Add((Item)new Furniture(obj_id, Vector2.Zero), new int[2] { price, int.MaxValue }); - i += 3; - if (i >= lineCount) break; - - - - - } - - if (obj_type == "Boots" || obj_type == "boots" || obj_type == "shoe" || obj_type == "Shoe") //just incase someone forgets it's called boots and they type shoe. - { - obj_id = Convert.ToInt32(readtext[i]); - i += 2; - price = Convert.ToInt32(readtext[i]); - list_price.Add((Item)new StardewValley.Objects.Boots(obj_id), new int[2] { price, int.MaxValue }); - i += 3; - if (i >= lineCount) break; - - } - - if (obj_type == "WallPaper" || obj_type == "Wallpaper" || obj_type == "wallPaper" || obj_type == "wallpaper") //just incase someone forgets it's called boots and they type shoe. - { - if (i + 3 > lineCount) break; - obj_id = Convert.ToInt32(readtext[i]); - i += 2; - price = Convert.ToInt32(readtext[i]); - list_price.Add((Item)new StardewValley.Objects.Wallpaper(obj_id, false), new int[2] { price, int.MaxValue }); //add in support for wallpapers and carpets - i += 3; - if (i >= lineCount) break; - - } - - if (obj_type == "Carpet" || obj_type == "carpet" || obj_type == "Floor" || obj_type == "floor" || obj_type == "Rug" || obj_type == "rug") - { - obj_id = Convert.ToInt32(readtext[i]); - i += 2; - price = Convert.ToInt32(readtext[i]); - list_price.Add((Item)new StardewValley.Objects.Wallpaper(obj_id, true), new int[2] { price, int.MaxValue }); //add in support for wallpapers and carpets - i += 3; - if (i >= lineCount) break; - } - - if (obj_type == "Ring" || obj_type == "ring") - { - obj_id = Convert.ToInt32(readtext[i]); - i += 2; - price = Convert.ToInt32(readtext[i]); - list_price.Add((Item)new StardewValley.Objects.Ring(obj_id), new int[2] { price, int.MaxValue }); - i += 3; - if (i >= lineCount) break; - } - if (obj_type == "Lamp" || obj_type == "lamp" || obj_type == "Torch" || obj_type == "torch" || obj_type == "Craftable" || obj_type == "craftable" || obj_type == "BigCraftable" || obj_type == "bigcraftable") - { - obj_id = Convert.ToInt32(readtext[i]); - i += 2; - price = Convert.ToInt32(readtext[i]); - list_price.Add((Item)new StardewValley.Torch(Vector2.Zero, obj_id, true), new int[2] { price, int.MaxValue }); - i += 3; - if (i >= lineCount) break; - } - - if (obj_type == "Sword" || obj_type == "sword" || obj_type == "Weapon" || obj_type == "weapon") - { - obj_id = Convert.ToInt32(readtext[i]); - i += 2; - price = Convert.ToInt32(readtext[i]); - list_price.Add((Item)new MeleeWeapon(obj_id), new int[2] { price, int.MaxValue }); - - i += 3; - if (i >= lineCount) break; - } - - if (obj_type == "Hat" || obj_type == "hat" || obj_type == "Hats" || obj_type == "hats") - { - obj_id = Convert.ToInt32(readtext[i]); - i += 2; - price = Convert.ToInt32(readtext[i]); - // list_price.Add((Item)new Hat(obj_id), new int[2] { price, int.MaxValue }); - list_price.Add((Item)new Hat(obj_id), new int[2] - { - price, - int.MaxValue - }); - i += 3; - if (i >= lineCount) break; - } - - - //TODO: - //add in support for colored objects - //add in support for tools - Log.Success(i); - if (i >= lineCount) break; - else { - obj_type = Convert.ToString(readtext[i]); - i += 2; - } - } - - - //NEED TO TEST ALL DATA FILES TO SEE WHAT CAN AND CANT BE ADDED - //list.Add((Item)new StardewValley.Objects.ColoredObject(475,300, Color.Aqua)); - // Game1.activeClickableMenu = (IClickableMenu)new ShopMenu(list, 0, "Pierre"); - - - mymenu = (IClickableMenu)new ShopMenu(list_price, 0, "Pierre"); - - Game1.activeClickableMenu = mymenu; //(IClickableMenu)new ShopMenu(list_price, 0, "Pierre"); - - }//basic default of Pierre - - - public static void external_shop_file_call(string path, string fileName, string shopChat, NPC my_npc ) - { - - List list = new List(); - - - string mylocation = Path.Combine(path, fileName); - - /// Log.Info(mylocation); - - - string[] readtext = File.ReadAllLines(mylocation); - - var lineCount = File.ReadLines(mylocation).Count(); - - - // Log.Info(lineCount); - - int i = 4; - - int obj_id = 0; - bool is_recipe; - int price; - int quality; - - string obj_type; - - obj_type = Convert.ToString(readtext[i]); - i += 2; - - - - while (i < lineCount) - { - if (i >= lineCount) break; - if (obj_type == "") break; - if (readtext[i] == "") break; - - //read in a line for obj type here - Log.Info(i); - Log.Info(obj_type); - if (obj_type == "item" || obj_type == "Item" || obj_type == "Object" || obj_type == "object") - { - - obj_id = Convert.ToInt16(readtext[i]); - i += 2; - - Log.Info(i); - is_recipe = Convert.ToBoolean(readtext[i]); - i += 2; - Log.Info(i); - price = Convert.ToInt32(readtext[i]); - i += 2; - Log.Info(i); - - quality = Convert.ToInt32(readtext[i]); - // if (quality > 2) quality = 0; - - - if (price == -1) - { - StardewValley.Object myobj = new StardewValley.Object(obj_id, int.MaxValue, is_recipe, price, quality); - - // Log.Info("MYPRICE"); - // Log.Info(myobj.salePrice()); - price = myobj.salePrice(); - - } - - - // list.Add((Item)new StardewValley.Object(obj_id, int.MaxValue, is_recipe, price, quality)); - list_price.Add((Item)new StardewValley.Object(obj_id, int.MaxValue, is_recipe, price, quality), new int[2] { price, int.MaxValue }); - i += 3; - if (i >= lineCount) break; - } - if (obj_type == "Furniture" || obj_type == "furniture") - { - obj_id = Convert.ToInt32(readtext[i]); - i += 2; - price = Convert.ToInt32(readtext[i]); - - // list.Add((Item)new Furniture(obj_id, Vector2.Zero)); //ADD FUNCTIONALITY TO SHOP FILES TO TEST IF FURNITURE OR NOT. - list_price.Add((Item)new Furniture(obj_id, Vector2.Zero), new int[2] { price, int.MaxValue }); - i += 3; - if (i >= lineCount) break; - - - - - } - - if (obj_type == "Boots" || obj_type == "boots" || obj_type == "shoe" || obj_type == "Shoe") //just incase someone forgets it's called boots and they type shoe. - { - obj_id = Convert.ToInt32(readtext[i]); - i += 2; - price = Convert.ToInt32(readtext[i]); - list_price.Add((Item)new StardewValley.Objects.Boots(obj_id), new int[2] { price, int.MaxValue }); - i += 3; - if (i >= lineCount) break; - - } - - if (obj_type == "WallPaper" || obj_type == "Wallpaper" || obj_type == "wallPaper" || obj_type == "wallpaper") //just incase someone forgets it's called boots and they type shoe. - { - if (i + 3 > lineCount) break; - obj_id = Convert.ToInt32(readtext[i]); - i += 2; - price = Convert.ToInt32(readtext[i]); - list_price.Add((Item)new StardewValley.Objects.Wallpaper(obj_id, false), new int[2] { price, int.MaxValue }); //add in support for wallpapers and carpets - i += 3; - if (i >= lineCount) break; - - } - - if (obj_type == "Carpet" || obj_type == "carpet" || obj_type == "Floor" || obj_type == "floor" || obj_type == "Rug" || obj_type == "rug") - { - obj_id = Convert.ToInt32(readtext[i]); - i += 2; - price = Convert.ToInt32(readtext[i]); - list_price.Add((Item)new StardewValley.Objects.Wallpaper(obj_id, true), new int[2] { price, int.MaxValue }); //add in support for wallpapers and carpets - i += 3; - if (i >= lineCount) break; - } - - if (obj_type == "Ring" || obj_type == "ring") - { - obj_id = Convert.ToInt32(readtext[i]); - i += 2; - price = Convert.ToInt32(readtext[i]); - list_price.Add((Item)new StardewValley.Objects.Ring(obj_id), new int[2] { price, int.MaxValue }); - i += 3; - if (i >= lineCount) break; - } - if (obj_type == "Lamp" || obj_type == "lamp" || obj_type == "Torch" || obj_type == "torch" || obj_type == "Craftable" || obj_type == "craftable" || obj_type == "BigCraftable" || obj_type == "bigcraftable") - { - obj_id = Convert.ToInt32(readtext[i]); - i += 2; - price = Convert.ToInt32(readtext[i]); - list_price.Add((Item)new StardewValley.Torch(Vector2.Zero, obj_id, true), new int[2] { price, int.MaxValue }); - i += 3; - if (i >= lineCount) break; - } - - if (obj_type == "Sword" || obj_type == "sword" || obj_type == "Weapon" || obj_type == "weapon") - { - obj_id = Convert.ToInt32(readtext[i]); - i += 2; - price = Convert.ToInt32(readtext[i]); - list_price.Add((Item)new MeleeWeapon(obj_id), new int[2] { price, int.MaxValue }); - - i += 3; - if (i >= lineCount) break; - } - - if (obj_type == "Hat" || obj_type == "hat" || obj_type == "Hats" || obj_type == "hats") - { - obj_id = Convert.ToInt32(readtext[i]); - i += 2; - price = Convert.ToInt32(readtext[i]); - // list_price.Add((Item)new Hat(obj_id), new int[2] { price, int.MaxValue }); - list_price.Add((Item)new Hat(obj_id), new int[2] - { - price, - int.MaxValue - }); - i += 3; - if (i >= lineCount) break; - } - - - //TODO: - //add in support for colored objects - //add in support for tools - Log.Success(i); - if (i >= lineCount) break; - else { - obj_type = Convert.ToString(readtext[i]); - i += 2; - } - } - - - //NEED TO TEST ALL DATA FILES TO SEE WHAT CAN AND CANT BE ADDED - //list.Add((Item)new StardewValley.Objects.ColoredObject(475,300, Color.Aqua)); - // Game1.activeClickableMenu = (IClickableMenu)new ShopMenu(list, 0, "Pierre"); - - var shop_menu=new ShopMenu(list_price, 0, my_npc.name); - - shop_menu.potraitPersonDialogue = Game1.parseText(shopChat, Game1.dialogueFont, Game1.tileSize * 5 - Game1.pixelZoom * 4); - shop_menu.portraitPerson = my_npc; - - mymenu = shop_menu; - - - Game1.activeClickableMenu = mymenu; //(IClickableMenu)new ShopMenu(list_price, 0, "Pierre"); - - } //uses NPCS with new dialogue and portraits - - //example of a shop that I don't use. - public static List myshop() - { - List list = new List(); - list.Add((Item)new StardewValley.Object(478, int.MaxValue, false, -1, 0)); //int parentsheet index OR object_ID/int.MaxValue, bool is recipe, price, quality - list.Add((Item)new StardewValley.Object(486, int.MaxValue, false, -1, 0)); - list.Add((Item)new StardewValley.Object(494, int.MaxValue, false, -1, 0)); //Might be able to manipulate this code to give me recipes!!!! - list.Add((Item)new StardewValley.Object(495, int.MaxValue, false, 800, 0)); //price is *2 of value shown. -1 means inherit default value - switch (Game1.dayOfMonth % 7) - { - case 0: - list.Add((Item)new StardewValley.Object(233, int.MaxValue, false, -1, 0)); - break; - case 1: - list.Add((Item)new StardewValley.Object(88, int.MaxValue, false, -1, 0)); - break; - case 2: - list.Add((Item)new StardewValley.Object(90, int.MaxValue, false, -1, 0)); - break; - case 3: - list.Add((Item)new StardewValley.Object(749, int.MaxValue, false, 500, 0)); - break; - case 4: - list.Add((Item)new StardewValley.Object(466, int.MaxValue, false, -1, 0)); - break; - case 5: - list.Add((Item)new StardewValley.Object(340, int.MaxValue, false, -1, 0)); - break; - case 6: - list.Add((Item)new StardewValley.Object(371, int.MaxValue, false, 100, 0)); - break; - } - return list; + Game1.activeClickableMenu = new ShopMenu(this.ListPrices, 0, "Pierre"); } + //basic default of Pierre + //private void external_shop_file_call(string path, string fileName) + //{ + // List list = new List(); + + // string mylocation = Path.Combine(path, fileName); + + // /// Log.Info(mylocation); + + + // string[] readtext = File.ReadAllLines(mylocation); + + // var lineCount = File.ReadLines(mylocation).Count(); + + + // // Log.Info(lineCount); + + // int i = 4; + + // int obj_id = 0; + // bool is_recipe; + // int price; + // int quality; + + // string obj_type; + + // obj_type = Convert.ToString(readtext[i]); + // i += 2; + + + + // while (i < lineCount) + // { + // if (i >= lineCount) break; + // if (obj_type == "") break; + // if (readtext[i] == "") break; + + // //read in a line for obj type here + // Log.Info(i); + // Log.Info(obj_type); + // if (obj_type == "item" || obj_type == "Item" || obj_type == "Object" || obj_type == "object") + // { + + // obj_id = Convert.ToInt16(readtext[i]); + // i += 2; + + // Log.Info(i); + // is_recipe = Convert.ToBoolean(readtext[i]); + // i += 2; + // Log.Info(i); + // price = Convert.ToInt32(readtext[i]); + // i += 2; + // Log.Info(i); + + // quality = Convert.ToInt32(readtext[i]); + // // if (quality > 2) quality = 0; + + + // if (price == -1) + // { + // StardewValley.Object myobj = new StardewValley.Object(obj_id, int.MaxValue, is_recipe, price, quality); + + // // Log.Info("MYPRICE"); + // // Log.Info(myobj.salePrice()); + // price = myobj.salePrice(); + + // } + + + // // list.Add((Item)new StardewValley.Object(obj_id, int.MaxValue, is_recipe, price, quality)); + // this.ListPrices.Add(new StardewValley.Object(obj_id, int.MaxValue, is_recipe, price, quality), new[] { price, int.MaxValue }); + // i += 3; + // if (i >= lineCount) break; + // } + // if (obj_type == "Furniture" || obj_type == "furniture") + // { + // obj_id = Convert.ToInt32(readtext[i]); + // i += 2; + // price = Convert.ToInt32(readtext[i]); + + // // list.Add((Item)new Furniture(obj_id, Vector2.Zero)); //ADD FUNCTIONALITY TO SHOP FILES TO TEST IF FURNITURE OR NOT. + // this.ListPrices.Add(new Furniture(obj_id, Vector2.Zero), new[] { price, int.MaxValue }); + // i += 3; + // if (i >= lineCount) break; + // } + + // if (obj_type == "Boots" || obj_type == "boots" || obj_type == "shoe" || obj_type == "Shoe") //just incase someone forgets it's called boots and they type shoe. + // { + // obj_id = Convert.ToInt32(readtext[i]); + // i += 2; + // price = Convert.ToInt32(readtext[i]); + // this.ListPrices.Add(new Boots(obj_id), new[] { price, int.MaxValue }); + // i += 3; + // if (i >= lineCount) break; + + // } + + // if (obj_type == "WallPaper" || obj_type == "Wallpaper" || obj_type == "wallPaper" || obj_type == "wallpaper") //just incase someone forgets it's called boots and they type shoe. + // { + // if (i + 3 > lineCount) break; + // obj_id = Convert.ToInt32(readtext[i]); + // i += 2; + // price = Convert.ToInt32(readtext[i]); + // this.ListPrices.Add(new Wallpaper(obj_id, false), new[] { price, int.MaxValue }); //add in support for wallpapers and carpets + // i += 3; + // if (i >= lineCount) break; + + // } + + // if (obj_type == "Carpet" || obj_type == "carpet" || obj_type == "Floor" || obj_type == "floor" || obj_type == "Rug" || obj_type == "rug") + // { + // obj_id = Convert.ToInt32(readtext[i]); + // i += 2; + // price = Convert.ToInt32(readtext[i]); + // this.ListPrices.Add(new Wallpaper(obj_id, true), new[] { price, int.MaxValue }); //add in support for wallpapers and carpets + // i += 3; + // if (i >= lineCount) break; + // } + + // if (obj_type == "Ring" || obj_type == "ring") + // { + // obj_id = Convert.ToInt32(readtext[i]); + // i += 2; + // price = Convert.ToInt32(readtext[i]); + // this.ListPrices.Add(new Ring(obj_id), new[] { price, int.MaxValue }); + // i += 3; + // if (i >= lineCount) break; + // } + // if (obj_type == "Lamp" || obj_type == "lamp" || obj_type == "Torch" || obj_type == "torch" || obj_type == "Craftable" || obj_type == "craftable" || obj_type == "BigCraftable" || obj_type == "bigcraftable") + // { + // obj_id = Convert.ToInt32(readtext[i]); + // i += 2; + // price = Convert.ToInt32(readtext[i]); + // this.ListPrices.Add(new Torch(Vector2.Zero, obj_id, true), new[] { price, int.MaxValue }); + // i += 3; + // if (i >= lineCount) break; + // } + + // if (obj_type == "Sword" || obj_type == "sword" || obj_type == "Weapon" || obj_type == "weapon") + // { + // obj_id = Convert.ToInt32(readtext[i]); + // i += 2; + // price = Convert.ToInt32(readtext[i]); + // this.ListPrices.Add(new MeleeWeapon(obj_id), new[] { price, int.MaxValue }); + + // i += 3; + // if (i >= lineCount) break; + // } + + // if (obj_type == "Hat" || obj_type == "hat" || obj_type == "Hats" || obj_type == "hats") + // { + // obj_id = Convert.ToInt32(readtext[i]); + // i += 2; + // price = Convert.ToInt32(readtext[i]); + // // list_price.Add((Item)new Hat(obj_id), new[] { price, int.MaxValue }); + // this.ListPrices.Add(new Hat(obj_id), new[] { price, int.MaxValue }); + // i += 3; + // if (i >= lineCount) break; + // } + + + // //TODO: + // //add in support for colored objects + // //add in support for tools + // Log.Success(i); + // if (i >= lineCount) break; + // else + // { + // obj_type = Convert.ToString(readtext[i]); + // i += 2; + // } + // } + + + // //NEED TO TEST ALL DATA FILES TO SEE WHAT CAN AND CANT BE ADDED + // //list.Add((Item)new StardewValley.Objects.ColoredObject(475,300, Color.Aqua)); + // // Game1.activeClickableMenu = (IClickableMenu)new ShopMenu(list, 0, "Pierre"); + + // this.Menu = new ShopMenu(this.ListPrices, 0, "Pierre"); + // Game1.activeClickableMenu = this.Menu; + //} + + + //uses NPCS with new dialogue and portraits + //private void external_shop_file_call(string path, string fileName, string shopChat, NPC my_npc) + //{ + + // List list = new List(); + + + // string mylocation = Path.Combine(path, fileName); + + // /// Log.Info(mylocation); + + + // string[] readtext = File.ReadAllLines(mylocation); + + // var lineCount = File.ReadLines(mylocation).Count(); + + + // // Log.Info(lineCount); + + // int i = 4; + + // int obj_id = 0; + // bool is_recipe; + // int price; + // int quality; + + // string obj_type; + + // obj_type = Convert.ToString(readtext[i]); + // i += 2; + + + + // while (i < lineCount) + // { + // if (i >= lineCount) break; + // if (obj_type == "") break; + // if (readtext[i] == "") break; + + // //read in a line for obj type here + // Log.Info(i); + // Log.Info(obj_type); + // if (obj_type == "item" || obj_type == "Item" || obj_type == "Object" || obj_type == "object") + // { + + // obj_id = Convert.ToInt16(readtext[i]); + // i += 2; + + // Log.Info(i); + // is_recipe = Convert.ToBoolean(readtext[i]); + // i += 2; + // Log.Info(i); + // price = Convert.ToInt32(readtext[i]); + // i += 2; + // Log.Info(i); + + // quality = Convert.ToInt32(readtext[i]); + // // if (quality > 2) quality = 0; + + + // if (price == -1) + // { + // StardewValley.Object myobj = new StardewValley.Object(obj_id, int.MaxValue, is_recipe, price, quality); + + // // Log.Info("MYPRICE"); + // // Log.Info(myobj.salePrice()); + // price = myobj.salePrice(); + + // } + + + // // list.Add((Item)new StardewValley.Object(obj_id, int.MaxValue, is_recipe, price, quality)); + // this.ListPrices.Add(new StardewValley.Object(obj_id, int.MaxValue, is_recipe, price, quality), new[] { price, int.MaxValue }); + // i += 3; + // if (i >= lineCount) break; + // } + // if (obj_type == "Furniture" || obj_type == "furniture") + // { + // obj_id = Convert.ToInt32(readtext[i]); + // i += 2; + // price = Convert.ToInt32(readtext[i]); + + // // list.Add((Item)new Furniture(obj_id, Vector2.Zero)); //ADD FUNCTIONALITY TO SHOP FILES TO TEST IF FURNITURE OR NOT. + // this.ListPrices.Add(new Furniture(obj_id, Vector2.Zero), new[] { price, int.MaxValue }); + // i += 3; + // if (i >= lineCount) break; + + + + + // } + + // if (obj_type == "Boots" || obj_type == "boots" || obj_type == "shoe" || obj_type == "Shoe") //just incase someone forgets it's called boots and they type shoe. + // { + // obj_id = Convert.ToInt32(readtext[i]); + // i += 2; + // price = Convert.ToInt32(readtext[i]); + // this.ListPrices.Add(new Boots(obj_id), new[] { price, int.MaxValue }); + // i += 3; + // if (i >= lineCount) break; + + // } + + // if (obj_type == "WallPaper" || obj_type == "Wallpaper" || obj_type == "wallPaper" || obj_type == "wallpaper") //just incase someone forgets it's called boots and they type shoe. + // { + // if (i + 3 > lineCount) break; + // obj_id = Convert.ToInt32(readtext[i]); + // i += 2; + // price = Convert.ToInt32(readtext[i]); + // this.ListPrices.Add(new Wallpaper(obj_id, false), new[] { price, int.MaxValue }); //add in support for wallpapers and carpets + // i += 3; + // if (i >= lineCount) break; + + // } + + // if (obj_type == "Carpet" || obj_type == "carpet" || obj_type == "Floor" || obj_type == "floor" || obj_type == "Rug" || obj_type == "rug") + // { + // obj_id = Convert.ToInt32(readtext[i]); + // i += 2; + // price = Convert.ToInt32(readtext[i]); + // this.ListPrices.Add(new Wallpaper(obj_id, true), new[] { price, int.MaxValue }); //add in support for wallpapers and carpets + // i += 3; + // if (i >= lineCount) break; + // } + + // if (obj_type == "Ring" || obj_type == "ring") + // { + // obj_id = Convert.ToInt32(readtext[i]); + // i += 2; + // price = Convert.ToInt32(readtext[i]); + // this.ListPrices.Add(new Ring(obj_id), new[] { price, int.MaxValue }); + // i += 3; + // if (i >= lineCount) break; + // } + // if (obj_type == "Lamp" || obj_type == "lamp" || obj_type == "Torch" || obj_type == "torch" || obj_type == "Craftable" || obj_type == "craftable" || obj_type == "BigCraftable" || obj_type == "bigcraftable") + // { + // obj_id = Convert.ToInt32(readtext[i]); + // i += 2; + // price = Convert.ToInt32(readtext[i]); + // this.ListPrices.Add(new Torch(Vector2.Zero, obj_id, true), new[] { price, int.MaxValue }); + // i += 3; + // if (i >= lineCount) break; + // } + + // if (obj_type == "Sword" || obj_type == "sword" || obj_type == "Weapon" || obj_type == "weapon") + // { + // obj_id = Convert.ToInt32(readtext[i]); + // i += 2; + // price = Convert.ToInt32(readtext[i]); + // this.ListPrices.Add(new MeleeWeapon(obj_id), new[] { price, int.MaxValue }); + + // i += 3; + // if (i >= lineCount) break; + // } + + // if (obj_type == "Hat" || obj_type == "hat" || obj_type == "Hats" || obj_type == "hats") + // { + // obj_id = Convert.ToInt32(readtext[i]); + // i += 2; + // price = Convert.ToInt32(readtext[i]); + // // list_price.Add((Item)new Hat(obj_id), new[] { price, int.MaxValue }); + // this.ListPrices.Add(new Hat(obj_id), new[] { price, int.MaxValue }); + // i += 3; + // if (i >= lineCount) break; + // } + + + // //TODO: + // //add in support for colored objects + // //add in support for tools + // Log.Success(i); + // if (i >= lineCount) break; + // else + // { + // obj_type = Convert.ToString(readtext[i]); + // i += 2; + // } + // } + + + // //NEED TO TEST ALL DATA FILES TO SEE WHAT CAN AND CANT BE ADDED + // //list.Add((Item)new StardewValley.Objects.ColoredObject(475,300, Color.Aqua)); + // // Game1.activeClickableMenu = (IClickableMenu)new ShopMenu(list, 0, "Pierre"); + + // this.Menu = new ShopMenu(this.ListPrices, 0, my_npc.name) + // { + // potraitPersonDialogue = Game1.parseText(shopChat, Game1.dialogueFont, Game1.tileSize * 5 - Game1.pixelZoom * 4), + // portraitPerson = my_npc + // }; + // Game1.activeClickableMenu = this.Menu; + //} + + //example of a shop that I don't use. + //private List MyShop() + //{ + // List list = new List(); + // list.Add(new StardewValley.Object(478, int.MaxValue, false, -1, 0)); //int parentsheet index OR object_ID/int.MaxValue, bool is recipe, price, quality + // list.Add(new StardewValley.Object(486, int.MaxValue, false, -1, 0)); + // list.Add(new StardewValley.Object(494, int.MaxValue, false, -1, 0)); //Might be able to manipulate this code to give me recipes!!!! + // list.Add(new StardewValley.Object(495, int.MaxValue, false, 800, 0)); //price is *2 of value shown. -1 means inherit default value + // switch (Game1.dayOfMonth % 7) + // { + // case 0: + // list.Add(new StardewValley.Object(233, int.MaxValue, false, -1, 0)); + // break; + // case 1: + // list.Add(new StardewValley.Object(88, int.MaxValue, false, -1, 0)); + // break; + // case 2: + // list.Add(new StardewValley.Object(90, int.MaxValue, false, -1, 0)); + // break; + // case 3: + // list.Add(new StardewValley.Object(749, int.MaxValue, false, 500, 0)); + // break; + // case 4: + // list.Add(new StardewValley.Object(466, int.MaxValue, false, -1, 0)); + // break; + // case 5: + // list.Add(new StardewValley.Object(340, int.MaxValue, false, -1, 0)); + // break; + // case 6: + // list.Add(new StardewValley.Object(371, int.MaxValue, false, 100, 0)); + // break; + // } + // return list; + //} } } -//end class \ No newline at end of file diff --git a/GeneralMods/CustomShopsRedux/manifest.json b/GeneralMods/CustomShopsRedux/manifest.json index 6b75feeb..2d8a6d2a 100644 --- a/GeneralMods/CustomShopsRedux/manifest.json +++ b/GeneralMods/CustomShopsRedux/manifest.json @@ -11,4 +11,4 @@ "UniqueID": "4be88c18-b6f3-49b0-ba96-f94b1a5be890", "PerSaveConfigs": false, "EntryDll": "CustomShopsRedux.dll" -} \ No newline at end of file +}