Skip to content

Commit

Permalink
0.21.8
Browse files Browse the repository at this point in the history
  • Loading branch information
valkyrienyanko committed Aug 21, 2023
1 parent c3a11d2 commit 3ce86bb
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 187 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.vs/
obj/
obj/
bin/
3 changes: 2 additions & 1 deletion Merchants/Shop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace MerchantsPlus.Merchants;

internal abstract class Shop
{
public int CycleIndex { get; set; }
public List<string> Shops;
public List<string> Quests;

Expand All @@ -26,7 +27,7 @@ public Shop(params string[] shops)
}

/// <summary>
/// Initalizes the merchants particular shop.
/// Opens the merchants shop.
/// </summary>
/// <param name="shop">The current shop we are in.</param>
/// <param name="nextSlot">The nextSlot of the item to sell.</param>
Expand Down
133 changes: 56 additions & 77 deletions UI/ShopUI.cs
Original file line number Diff line number Diff line change
@@ -1,91 +1,54 @@
using MerchantsPlus.Merchants;
using Terraria.GameContent.UI.Elements;
using Terraria.ID;

namespace MerchantsPlus.UI;

// This UI will appear when a new dialog is opened with a merchant
internal class ShopUI : UIState
{
public const int ANGLER = 0;
public const int ARMSDEALER = 1;
public const int CLOTHIER = 2;
public const int CYBORG = 3;
public const int DEMOLITIONIST = 4;
public const int DRYAD = 5;
public const int DYETRADER = 6;
public const int GOBLINTINKERER = 7;
public const int GUIDE = 8;
public const int MECHANIC = 9;
public const int MERCHANT = 10;
public const int NURSE = 11;
public const int PAINTER = 12;
public const int PARTYGIRL = 13;
public const int PIRATE = 14;
public const int SANTACLAUS = 15;
public const int SKELETONMERCHANT = 16;
public const int STEAMPUNKER = 17;
public const int STYLIST = 18;
public const int TAVERNKEEP = 19;
public const int TAXCOLLECTOR = 20;
public const int TRAVELLINGMERCHANT = 21;
public const int TRUFFLE = 22;
public const int WITCHDOCTOR = 23;
public const int WIZARD = 24;

static readonly Dictionary<int, Shop> shops = new() {
// DO NOT CHANGE THESE NAMES WITHOUT CHECKING THAT THEY MATCH
// CORRECTLY INSIDE THEIR RESPECTIVE SHOP CLASSES!
{ ANGLER, new ShopAngler("Bait", "Buffs", "Crates") },
{ ARMSDEALER, new ShopArmsDealer("Guns") },
{ CLOTHIER, new ShopClothier("Clothing", "Boss Masks", "Vanity I", "Vanity II", "Vanity III", "Vanity IV") },
{ CYBORG, new ShopCyborg("Robotics", "Buffs") },
{ DEMOLITIONIST, new ShopDemolitionist("Explosives", "Potions") },
{ DRYAD, new ShopDryad("Seeds", "Potions") },
{ DYETRADER, new ShopDyeTrader("Basic", "Bright", "Gradient", "Compound", "Strange", "Lunar") },
{ GOBLINTINKERER, new ShopGoblinTinkerer("Movement", "Informational", "Combat", "Health and Mana",
{ NPCID.Angler, new ShopAngler("Bait", "Buffs", "Crates") },
{ NPCID.ArmsDealer, new ShopArmsDealer("Guns") },
{ NPCID.Clothier, new ShopClothier("Clothing", "Boss Masks", "Vanity I", "Vanity II", "Vanity III", "Vanity IV") },
{ NPCID.Cyborg, new ShopCyborg("Robotics", "Buffs") },
{ NPCID.Demolitionist, new ShopDemolitionist("Explosives", "Potions") },
{ NPCID.Dryad, new ShopDryad("Seeds", "Potions") },
{ NPCID.DyeTrader, new ShopDyeTrader("Basic", "Bright", "Gradient", "Compound", "Strange", "Lunar") },
{ NPCID.GoblinTinkerer, new ShopGoblinTinkerer("Movement", "Informational", "Combat", "Health and Mana",
"Immunity", "Defensive", "Special", "Miscellaneous") },
{ MECHANIC, new ShopMechanic("Mechanics", "Materials") },
{ MERCHANT, new ShopMerchant("Gear", "Ores", "Pets", "Mounts") },
{ NURSE, new ShopNurse("Potions") },
{ PAINTER, new ShopPainter("Tools", "Paint", "Wallpaper", "Paintings I", "Paintings II") },
{ PARTYGIRL, new ShopPartyGirl("Party Stuff") },
{ PIRATE, new ShopPirate("Arrr", "Potions") },
{ SANTACLAUS, new ShopSantaClaus("Decor", "Bulbs", "Lights", "Potions") },
{ SKELETONMERCHANT, new ShopSkeletonMerchant("Gear", "Music Boxes") },
{ STEAMPUNKER, new ShopSteampunker("Gear", "Solutions", "Logic") },
{ STYLIST, new ShopStylist("Hair Dyes", "Overworld", "Underworld", "Desert", "Snow", "Jungle", "Ocean",
{ NPCID.Mechanic, new ShopMechanic("Mechanics", "Materials") },
{ NPCID.Merchant, new ShopMerchant("Gear", "Ores", "Pets", "Mounts") },
{ NPCID.Nurse, new ShopNurse("Potions") },
{ NPCID.Painter, new ShopPainter("Tools", "Paint", "Wallpaper", "Paintings I", "Paintings II") },
{ NPCID.PartyGirl, new ShopPartyGirl("Party Stuff") },
{ NPCID.Pirate, new ShopPirate("Arrr", "Potions") },
{ NPCID.SantaClaus, new ShopSantaClaus("Decor", "Bulbs", "Lights", "Potions") },
{ NPCID.SkeletonMerchant, new ShopSkeletonMerchant("Gear", "Music Boxes") },
{ NPCID.Steampunker, new ShopSteampunker("Gear", "Solutions", "Logic") },
{ NPCID.Stylist, new ShopStylist("Hair Dyes", "Overworld", "Underworld", "Desert", "Snow", "Jungle", "Ocean",
"Corruption", "Crimson", "Hallow", "Space", "Mushroom", "Dungeon", "Bloodmoon", "Eclipse", "Goblin Army",
"Old Ones Army", "Frost Legion", "Pumpkin Moon", "Frost Moon", "Pirate Invasion", "Martian Madness",
"Solar Zone", "Vortex Zone", "Nebula Zone", "Stardust Zone") },
{ TAVERNKEEP, new ShopTavernkeep("Gear") },
{ TAXCOLLECTOR, new ShopTaxCollector() },
{ TRAVELLINGMERCHANT, new ShopTravellingMerchant("Gear") },
{ TRUFFLE, new ShopTruffle("Gear") },
{ WITCHDOCTOR, new ShopWitchDoctor("Gear", "Flasks", "Wings") },
{ WIZARD, new ShopWizard("Gear") },
{ GUIDE, new ShopGuide("Gear") }
{ NPCID.DD2Bartender, new ShopTavernkeep("Gear") },
{ NPCID.TaxCollector, new ShopTaxCollector() },
{ NPCID.TravellingMerchant, new ShopTravellingMerchant("Gear") },
{ NPCID.Truffle, new ShopTruffle("Gear") },
{ NPCID.WitchDoctor, new ShopWitchDoctor("Gear", "Flasks", "Wings") },
{ NPCID.Wizard, new ShopWizard("Gear") },
{ NPCID.Guide, new ShopGuide("Gear") }
};

public static bool Visible { get; set; }
public static int CurrentShopIndex { get; set; }
public static int[] ShopCycleIndexes { get; private set; }
public static int CurrentMerchantID { get; set; }

string[] shopNames;
UIText currentShopName;
UIPanel shopPanel;

public override void OnInitialize()
{
ShopCycleIndexes = new int[shops.Count];
shopNames = new string[shops.Count];

// This is the first shop name the player will see (for all shops)
// before pressing cycle shop button
for (int i = 0; i < shops.Count; i++)
shopNames[i] = shops[i].ToString();

//for (int i = 0; i < ShopNames.Length; i++)
// ShopNames[i] = "Shop";

shopPanel = new UIPanel();
shopPanel.SetPadding(0);
shopPanel.Left.Set(200f, 0f);
Expand All @@ -94,7 +57,7 @@ public override void OnInitialize()
shopPanel.Height.Set(35f, 0f);
shopPanel.BackgroundColor = new Color(0, 0, 0, 0.6f);

currentShopName = new UIText(shopNames[CurrentShopIndex], 0.9f);
currentShopName = new UIText("Shop Name", 0.9f);
currentShopName.Left.Set(10, 0f);
currentShopName.Top.Set(8, 0f);
currentShopName.OnLeftClick += new MouseEvent(ShopButtonClicked);
Expand All @@ -109,33 +72,49 @@ public override void OnInitialize()
Append(shopPanel);
}

public void UpdateShopName() =>
currentShopName.SetText(shopNames[CurrentShopIndex]);
public void UpdateShopName()
{
if (shops[CurrentMerchantID].Shops.Count == 0)
{
currentShopName.SetText("Shop");
return;
}

int shopIndex = shops[CurrentMerchantID].CycleIndex;

currentShopName.SetText(shops[CurrentMerchantID].Shops[shopIndex]);
}

void CycleShopButtonClicked(UIMouseEvent evt, UIElement listeningElement)
{
ShiftShop();
UpdateShopName();
OpenShop();
OpenShop(shops[CurrentMerchantID].CycleIndex);
}

void ShiftShop()
{
if (shops[CurrentShopIndex].Shops.Count == 0) return; // Safe Guard
if (ShopCycleIndexes[CurrentShopIndex] >= shops[CurrentShopIndex].Shops.Count - 1)
if (shops[CurrentMerchantID].Shops.Count == 0) return; // Safe Guard
if (shops[CurrentMerchantID].CycleIndex >= shops[CurrentMerchantID].Shops.Count - 1)
{
shopNames[CurrentShopIndex] = shops[CurrentShopIndex].Shops[0];
ShopCycleIndexes[CurrentShopIndex] = 0;
shops[CurrentMerchantID].CycleIndex = 0;
}
else
{
shopNames[CurrentShopIndex] = shops[CurrentShopIndex].Shops[++ShopCycleIndexes[CurrentShopIndex]];
shops[CurrentMerchantID].CycleIndex++;
}
}

void ShopButtonClicked(UIMouseEvent evt, UIElement listeningElement) =>
OpenShop();
OpenShop(0);

void OpenShop() =>
shops[CurrentShopIndex].OpenShop(shopNames[CurrentShopIndex]);
void OpenShop(int shopIndex)
{
string shopToOpen = "";

if (shops[CurrentMerchantID].Shops.Count != 0)
shopToOpen = shops[CurrentMerchantID].Shops[shopIndex];

shops[CurrentMerchantID].OpenShop(shopToOpen);
}
}
116 changes: 9 additions & 107 deletions UI/UIEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,26 @@ namespace MerchantsPlus.UI;

internal class UIEvents : GlobalNPC
{
static NPC currentNPC;
static NPC currentNPC = null;

public override void GetChat(NPC npc, ref string chat)
{
// Do not change shop if the player is talking to the same NPC
bool sameNPC = npc.type == currentNPC?.type;

// Do not change shop if not talking to a NPC
bool notTalkingToNPC = !Utils.TalkingToNPC();

// Do not change shop if this is not a shop NPC
if (npc == currentNPC || !Utils.TalkingToNPC() || !IsShopNPC(npc))
bool notShopNPC = !IsShopNPC(npc);

if (sameNPC || notTalkingToNPC || notShopNPC)
return;

currentNPC = npc;
SetShopIndex(npc);
//Main.NewText("Showing shop ui for " + npc.FullName);
ModContent.GetInstance<ModifyUI>().ShowShopUI();

// Reset shop category index
ShopUI.ShopCycleIndexes[ShopUI.CurrentShopIndex] = 0;
}

static bool IsShopNPC(NPC npc) => npc.type switch
Expand Down Expand Up @@ -55,107 +58,6 @@ NPCID.WitchDoctor or

static void SetShopIndex(NPC npc)
{
switch (npc.type)
{
case NPCID.Angler:
ShopUI.CurrentShopIndex = ShopUI.ANGLER;
break;

case NPCID.ArmsDealer:
ShopUI.CurrentShopIndex = ShopUI.ARMSDEALER;
break;

case NPCID.Clothier:
ShopUI.CurrentShopIndex = ShopUI.CLOTHIER;
break;

case NPCID.Cyborg:
ShopUI.CurrentShopIndex = ShopUI.CYBORG;
break;

case NPCID.Demolitionist:
ShopUI.CurrentShopIndex = ShopUI.DEMOLITIONIST;
break;

case NPCID.Dryad:
ShopUI.CurrentShopIndex = ShopUI.DRYAD;
break;

case NPCID.DyeTrader:
ShopUI.CurrentShopIndex = ShopUI.DYETRADER;
break;

case NPCID.GoblinTinkerer:
ShopUI.CurrentShopIndex = ShopUI.GOBLINTINKERER;
break;

case NPCID.Guide:
ShopUI.CurrentShopIndex = ShopUI.GUIDE;
break;

case NPCID.Mechanic:
ShopUI.CurrentShopIndex = ShopUI.MECHANIC;
break;

case NPCID.Merchant:
ShopUI.CurrentShopIndex = ShopUI.MERCHANT;
break;

case NPCID.Nurse:
ShopUI.CurrentShopIndex = ShopUI.NURSE;
break;

case NPCID.Painter:
ShopUI.CurrentShopIndex = ShopUI.PAINTER;
break;

case NPCID.PartyGirl:
ShopUI.CurrentShopIndex = ShopUI.PARTYGIRL;
break;

case NPCID.Pirate:
ShopUI.CurrentShopIndex = ShopUI.PIRATE;
break;

case NPCID.SantaClaus:
ShopUI.CurrentShopIndex = ShopUI.SANTACLAUS;
break;

case NPCID.SkeletonMerchant:
ShopUI.CurrentShopIndex = ShopUI.SKELETONMERCHANT;
break;

case NPCID.Steampunker:
ShopUI.CurrentShopIndex = ShopUI.STEAMPUNKER;
break;

case NPCID.Stylist:
ShopUI.CurrentShopIndex = ShopUI.STYLIST;
break;

case NPCID.DD2Bartender:
ShopUI.CurrentShopIndex = ShopUI.TAVERNKEEP;
break;

case NPCID.TaxCollector:
ShopUI.CurrentShopIndex = ShopUI.TAXCOLLECTOR;
break;

case NPCID.TravellingMerchant:
ShopUI.CurrentShopIndex = ShopUI.TRAVELLINGMERCHANT;
break;

case NPCID.Truffle:
ShopUI.CurrentShopIndex = ShopUI.TRUFFLE;
break;

case NPCID.WitchDoctor:
ShopUI.CurrentShopIndex = ShopUI.WITCHDOCTOR;
break;

case NPCID.Wizard:
ShopUI.CurrentShopIndex = ShopUI.WIZARD;
break;
}
ShopUI.CurrentMerchantID = npc.type;
}
}
2 changes: 1 addition & 1 deletion build.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
author = valkyrienyanko
version = 0.21.7
version = 0.21.8
displayName = MerchantsPlus
homepage = https://discord.gg/866cg8yfxZ
buildIgnore = *.csproj, *.user, obj\*, bin\*, .vs\*

0 comments on commit 3ce86bb

Please sign in to comment.