using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.Xna.Framework;
using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewValley;
using StardewValley.Menus;
using StardewValley.Objects;
using StardewValley.Tools;
/*
TO DO:
Items
furniture
swords -
hats -
boots -
wallpapers -
carpets -
ring -
lamp-
craftables-
*/
namespace Omegasis.CustomShopsRedux
{
/// The mod entry point.
public class CustomShopsRedux : Mod
{
/*********
** Properties
*********/
/// The prices for the items to list.
private readonly Dictionary- ListPrices = new Dictionary
- ();
/// The folder path containing shop data files.
private string DataPath;
/// The configured shop options.
private readonly List Options = new List();
/// 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)
{
PlayerEvents.LoadedGame += this.PlayerEvents_LoadedGame;
ControlEvents.KeyPressed += this.ControlEvents_KeyPressed;
}
/*********
** 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)
{
this.IsGameLoaded = true;
this.LoadConfig();
this.WriteConfig();
}
/// The method invoked when the presses a keyboard button.
/// The event sender.
/// The event data.
private void ControlEvents_KeyPressed(object sender, EventArgsKeyPressed e)
{
if (!this.IsGameLoaded)
return;
if (e.KeyPressed.ToString() == this.KeyBinding) //if the key is pressed, load my cusom save function
{
this.OpenSelectFileMenu();
}
}
/// 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))
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(this.PathOnDisk, "Custom_Shop_Redux_Config.txt");
string[] text = new string[20];
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;
}
// 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);
}
/// The method called when the player chooses an option from the file list.
/// The selected file name.
private void OnChoiceSelected(string filename)
{
// read file data
string path = Path.Combine(this.DataPath, filename);
string[] text = File.ReadAllLines(path);
int lineCount = text.Length;
// validate
if (filename == "Custom_Shop_Redux_Config.txt")
{
Log.Info("Silly human. The config file is not a shop.");
return;
}
// parse data
string objType = Convert.ToString(text[4]);
int i = 6;
while (i < lineCount)
{
if (i >= lineCount || objType == "" || text[i] == "") break;
//read in a line for obj type here
Log.Info(i);
Log.Info(objType);
int objID;
int price;
if (objType == "item" || objType == "Item" || objType == "Object" || objType == "object")
{
objID = Convert.ToInt16(text[i]);
i += 2;
Log.Info(i);
bool isRecipe = Convert.ToBoolean(text[i]);
i += 2;
Log.Info(i);
price = Convert.ToInt32(text[i]);
i += 2;
Log.Info(i);
int quality = Convert.ToInt32(text[i]);
if (price == -1)
{
StardewValley.Object myobj = new StardewValley.Object(objID, int.MaxValue, isRecipe, price, quality);
price = myobj.salePrice();
}
this.ListPrices.Add(new StardewValley.Object(objID, int.MaxValue, isRecipe, price, quality), new[] { price, int.MaxValue });
i += 3;
if (i >= lineCount)
break;
}
if (objType == "Furniture" || objType == "furniture")
{
objID = Convert.ToInt32(text[i]);
i += 2;
price = Convert.ToInt32(text[i]);
this.ListPrices.Add(new Furniture(objID, Vector2.Zero), new[] { price, int.MaxValue });
i += 3;
if (i >= lineCount)
break;
}
if (objType == "Boots" || objType == "boots" || objType == "shoe" || objType == "Shoe") //just incase someone forgets it's called boots and they type shoe.
{
objID = Convert.ToInt32(text[i]);
i += 2;
price = Convert.ToInt32(text[i]);
this.ListPrices.Add(new Boots(objID), new[] { price, int.MaxValue });
i += 3;
if (i >= lineCount)
break;
}
if (objType == "WallPaper" || objType == "Wallpaper" || objType == "wallPaper" || objType == "wallpaper")
{
if (i + 3 > lineCount)
break;
objID = Convert.ToInt32(text[i]);
i += 2;
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 (objType == "Carpet" || objType == "carpet" || objType == "Floor" || objType == "floor" || objType == "Rug" || objType == "rug")
{
objID = Convert.ToInt32(text[i]);
i += 2;
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 (objType == "Ring" || objType == "ring")
{
objID = Convert.ToInt32(text[i]);
i += 2;
price = Convert.ToInt32(text[i]);
this.ListPrices.Add(new Ring(objID), new[] { price, int.MaxValue });
i += 3;
if (i >= lineCount)
break;
}
if (objType == "Lamp" || objType == "lamp" || objType == "Torch" || objType == "torch" || objType == "Craftable" || objType == "craftable" || objType == "BigCraftable" || objType == "bigcraftable")
{
objID = Convert.ToInt32(text[i]);
i += 2;
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 (objType == "Sword" || objType == "sword" || objType == "Weapon" || objType == "weapon")
{
objID = Convert.ToInt32(text[i]);
i += 2;
price = Convert.ToInt32(text[i]);
this.ListPrices.Add(new MeleeWeapon(objID), new[] { price, int.MaxValue });
i += 3;
if (i >= lineCount)
break;
}
if (objType == "Hat" || objType == "hat" || objType == "Hats" || objType == "hats")
{
objID = Convert.ToInt32(text[i]);
i += 2;
price = Convert.ToInt32(text[i]);
this.ListPrices.Add(new Hat(objID), 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;
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 = 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;
//}
}
}